Best JavaScript code snippet using ladle
ember-file-manager.js
Source:ember-file-manager.js
1import ContextMenuMixin from 'ember-context-menu';2import Component from 'ember-component';3import computed from 'ember-computed';4import fetch from 'fetch';5import getOwner from 'ember-getowner-polyfill';6import layout from '../templates/components/ember-file-manager';7import RSVP from 'rsvp';8import service from 'ember-service/inject';9import set from 'ember-metal/set';10import TreeMixin from '../mixins/tree';11const SIZE_UNITS = ['b', 'kb', 'mb', 'gb'];12const SORT = { asc: 'asc', desc: 'desc' };13const TRANSITIONS = { back: 'back', forward: 'forward' };14export default Component.extend(ContextMenuMixin, TreeMixin, {15 layout,16 fetchService: service('base-service'),17 youtubeVideosEnabled: true,18 fetchingDirectory: true,19 column: 'mime',20 backHistory: [],21 forwardHistory: [],22 selectedFiles: [],23 cutFiles: [],24 filePickerOpen: false,25 getInfoOpen: false,26 defaultDisplay: true,27 sort: SORT.asc,28 searchText: '',29 contextMenu(e) {30 this.computeContextItems(e.target);31 this._super(...arguments);32 },33 didInsertElement() {34 return this.$().focus().attr({ tabindex: 1 });35 },36 keyDown(e) {37 let dir;38 if (e.keyCode === 38) {39 dir = -1;40 } else if (e.keyCode === 40) {41 dir = 1;42 } else if (e.keyCode === 13) {43 let selectedFiles = this.get('selectedFiles');44 if (selectedFiles.length === 1 && selectedFiles[0].mime === this.get('config').mimes.directory.name) {45 this.send('changeCWD', selectedFiles[0].hash);46 }47 }48 if (dir) {49 this.changeFileSelection({50 direction: dir,51 shiftKey: e.shiftKey,52 ctrKey: e.ctrlKey || e.metaKey,53 });54 }55 },56 config: computed(function() {57 return getOwner(this).resolveRegistration('config:environment');58 }),59 rootAPI: computed('config', function() {60 return this.get('config').rootAPI;61 }),62 fileItemsClassNames: computed('formattedFiles', 'selectedFiles', 'cutFiles', function() {63 let formattedFiles = this.get('formattedFiles');64 let selectedFiles = this.get('selectedFiles');65 let cutFiles = this.get('cutFiles');66 let fileItemsClassNames = [];67 formattedFiles.forEach((file) => {68 let classes = file.hash.replace(new RegExp(' ', 'g'), '%space%') + ' ';69 let fileFound = this.findObject(selectedFiles, file.hash, 'hash');70 if (fileFound.name !== 'None') {71 classes += 'selected';72 }73 fileFound = this.findObject(cutFiles, file.hash, 'hash');74 if (fileFound.name !== 'None') {75 classes += `${classes ? ' ' : ''}cut`;76 }77 fileItemsClassNames.push(classes);78 });79 return fileItemsClassNames;80 }),81 //list of current directory's files82 directoryFiles: computed('model', function() {83 let model = this.get('model');84 let _this = this;85 if (model) {86 return this.initializeDirectory(model);87 } else {88 this.get('fetchService').fetch(`${this.get('rootAPI')}file?cmd=open&target=${this.get('homeDir')}`, { method: 'GET' }).then((model) => {89 this.set('directoryFiles', this.initializeDirectory(model));90 }, function(error) {91 _this.get('flashMessages').warning('Error fetching files.');92 _this.set('fetchingDirectory', false);93 });94 }95 }),96 //list of current directory's files which are sorted or formatted in some way97 formattedFiles: computed('directoryFiles', function() {98 return this.get('directoryFiles');99 }),100 selectedFilesInfo: computed('selectedFiles', function() {101 let selectedFiles = this.get('selectedFiles');102 let selectedFilesInfo = { kind: '', size: 0, multiple: true, length: selectedFiles.length, sizeUnknown: false };103 if (selectedFiles.length > 1) {104 let kinds = { folders: 0, files: 0 };105 selectedFiles.forEach((file) => {106 if (file.mime !== this.get('config').mimes.directory.name) {107 selectedFilesInfo.size += file.size;108 kinds.files++;109 } else {110 selectedFilesInfo.sizeUnknown = true;111 kinds.folders++;112 }113 });114 this.setFileSizeString(selectedFilesInfo);115 if (kinds.folders) {116 selectedFilesInfo.kind = `${kinds.folders} Folders`;117 }118 if (kinds.files) {119 if (kinds.folders) {120 selectedFilesInfo.kind += ', ';121 }122 selectedFilesInfo.kind += `${kinds.files} Files`;123 }124 } else if (selectedFiles.length === 1) {125 selectedFilesInfo = selectedFiles[0];126 }127 return selectedFilesInfo;128 }),129 //TODO: Add icons to context-menu options when they are enabled on the 'ember-context-menu' addon130 computeContextItems(targetElement) {131 let _this = this;132 let cwd = this.get('cwd');133 this.set('getInfoOpen', false);134 if (!targetElement) {135 targetElement = document.activeElement;136 }137 let selectedFiles = this.get('selectedFiles').slice();138 let contextItems = [139 {140 label: 'Reload',141 action() {142 _this.send('refresh');143 },144 },145 ];146 if (this.get('cutFiles').length && cwd.write) {147 contextItems.push({148 label: 'Paste',149 action() {150 _this.pasteFiles();151 },152 });153 }154 let directoryTreeFile;155 while (targetElement &&156 !targetElement.classList.contains('file-item') && !targetElement.classList.contains('file-item-block')) {157 if (targetElement.classList.contains('directory-item')) {158 directoryTreeFile = this.findInTree(this.get('directoryTree'), targetElement.classList[0], 'hash');159 break;160 }161 if (targetElement.parentElement) {162 targetElement = targetElement.parentElement;163 } else {164 targetElement = null;165 }166 }167 let clickedFile = directoryTreeFile;168 if (!clickedFile && targetElement) {169 clickedFile = this.get('formattedFiles').find((file) => {170 return (file.hash === targetElement.classList[2].replace(new RegExp('%space%', 'g'), ' '));171 });172 if (!selectedFiles.includes(clickedFile)) {173 selectedFiles = [clickedFile];174 }175 }176 contextItems.push({177 label: 'Get Info',178 action() {179 _this.send('toggleInfo', { clickedFile });180 },181 });182 let canModify = true;183 let canDelete = true;184 selectedFiles.forEach((file) => {185 if (!file.rm) {186 canDelete = false;187 }188 if (!file.write) {189 canModify = false;190 }191 });192 if (clickedFile) {193 if (canDelete) {194 contextItems.push({195 label: 'Cut',196 action() {197 let cutFiles = selectedFiles;198 cutFiles.src = _this.get('cwd').hash;199 _this.set('cutFiles', cutFiles);200 },201 }, {202 label: 'Delete',203 action() {204 _this.deleteFiles();205 },206 });207 }208 if (canModify) {209 if (selectedFiles.length === 1) {210 if (selectedFiles[0].write) {211 contextItems.push({212 label: 'Rename',213 action() {214 _this.renameFileStart();215 },216 });217 }218 if (selectedFiles[0].read) {219 contextItems.push({220 label: 'Download',221 action() {222 _this.send('download', { clickedFile });223 },224 });225 }226 }227 }228 }229 this.setProperties({ selectedFiles, contextItems });230 },231 initializeDirectory(model) {232 if (!model.files.length) {233 return {};234 }235 let [directoryFiles, cwdChildren] = this.separateFiles(model);236 model.cwd.children = cwdChildren;237 model.cwd.expanded = true;238 this.setProperties({239 directoryTree: model.cwd,240 cwd: model.cwd,241 });242 this.set('fetchingDirectory', false);243 return directoryFiles;244 },245 //separates the files based on the type and sets all the necessary properties246 separateFiles(model, search=false) {247 let directoryFiles = [];248 let cwdChildren = [];249 let parentPath = '';250 directoryFiles.size = 0;251 if (!search) {252 //finds the path through the directory tree and returns it as an array (ex: Media/Body Parts)253 let path = this.findPathInTree(this.get('directoryTree') || model.cwd, model.cwd.hash, 'hash');254 path.forEach((node) => {255 parentPath += node.name + '/';256 });257 }258 model.files.forEach((file) => {259 if (file.mime && (search || file.phash === model.cwd.hash)) {260 let config = this.get('config');261 if (!file.size) {262 file.size = 0;263 }264 directoryFiles.size += file.size;265 this.setFileSizeString(file);266 this.setFilePermissionString(file);267 this.setFileKind(file);268 set(file, 'pathString', parentPath + file.name);269 if (file.mime === config.mimes.directory.name) {270 cwdChildren.push(file);271 } else if (!config.mimes.video || file.mime !== config.mimes.video.name) {272 set(file, 'link', `${config.linkBaseURL}${file.hash}`);273 } else if (config.mimes.video && file.mime === config.mimes.video.name) {274 let id = file.tmb.split('vi/')[1].split('/')[0];275 set(file, 'link', `${config.youtubeBaseURL}${id}`);276 }277 directoryFiles.push(file);278 }279 });280 let sortedDirectoryFiles = directoryFiles.sortBy(this.get('column'));281 sortedDirectoryFiles.size = directoryFiles.size;282 this.setFileSizeString(sortedDirectoryFiles);283 this.set('cwdPath', parentPath.substring(0, parentPath.length - 1));284 return [sortedDirectoryFiles, cwdChildren];285 },286 //sets the permission string (ex: 'Read and Write')287 setFilePermissionString(file) {288 let string = '';289 if (file.read) {290 string = 'Read';291 if (file.write) {292 string += ' and Write';293 }294 } else if (file.write) {295 string = 'Write';296 }297 set(file, 'permissionString', string);298 },299 //sets the size string (ex: '000 kb')300 setFileSizeString(file) {301 let unitIndex = 0;302 while (file.size >= 1000 && unitIndex < 3) {303 file.size /= 1000;304 unitIndex++;305 }306 set(file, 'sizeString', `${parseInt(file.size || 0)} ${SIZE_UNITS[unitIndex]}`);307 },308 //sets the type of file (ex: 'Video Media')309 setFileKind(file) {310 let config = this.get('config');311 Object.keys(config.mimes).forEach((key) => {312 if (file.mime === config.mimes[key].name) {313 set(file, 'kind', config.mimes[key].kind);314 }315 });316 },317 setInfoPopup({ clickedFile=null }={}) {318 let selectedFiles = this.get('selectedFiles');319 let filesInfo = this.get('selectedFilesInfo');320 if (clickedFile) {321 if (!selectedFiles.contains(clickedFile)) {322 filesInfo = clickedFile;323 }324 } else if (!selectedFiles.length) {325 filesInfo = this.get('cwd');326 }327 this.setProperties({ filesInfo });328 },329 //rename action to enable input330 renameFileStart() {331 let selectedFile = this.get('selectedFiles')[0];332 if (selectedFile.write) {333 this.setProperties({334 renaming: true,335 renamingId: selectedFile.hash,336 newName: selectedFile.name,337 });338 } else {339 this.get('flashMessages').warning('No permission to edit this file');340 }341 },342 pasteFiles() {343 let flashMessages = this.get('flashMessages');344 let cwd = this.get('cwd');345 let cutFiles = this.get('cutFiles');346 let targets = '';347 cutFiles.forEach((file) => {348 if (!file.rm) {349 flashMessages.warning('No permission to remove a file');350 return;351 }352 });353 if (cwd.write) {354 cutFiles.forEach((file) => {355 targets += `&targets%5B%5D=${file.hash}`;356 });357 if (targets) {358 let params = `cmd=paste&dst=${cwd.hash}${targets}&cut=1&src=${cutFiles.src}`;359 this.get('fetchService').fetch(`${this.get('rootAPI')}file?${params}`, { method: 'GET' }).then(() => {360 let directoryTree = this.get('directoryTree');361 //deleting folder rows from the directory tree view362 cutFiles.forEach((file) => {363 if (file.mime === this.get('config').mimes.directory.name) {364 let parent = this.findInTree(directoryTree, file.phash, 'hash');365 if (parent) {366 let children = parent.children.slice();367 children.splice(children.indexOf(file), 1);368 set(parent, 'children', children);369 }370 }371 });372 this.set('cutFiles', []);373 this.send('refresh');374 });375 }376 } else {377 flashMessages.warning('No permission to edit this directory');378 }379 },380 //opens confirm delete dialog and sets files up for deletion381 deleteFiles() {382 let selectedFiles = this.get('selectedFiles');383 let names = '';384 selectedFiles.forEach((file) => {385 if (!file.rm) {386 this.get('flashMessages').warning(`No permission to delete ${selectedFiles.length > 1 ? 'these' : 'this'} file`);387 this.set('showDeleteDialog', false);388 return;389 }390 names += `, ${file.name}`;391 });392 this.get('cutFiles').forEach((file, index) => {393 if (names.includes(file.name)) {394 let cutFiles = this.get('cutFiles').slice();395 cutFiles.splice(index, 1);396 this.set('cutFiles', cutFiles);397 }398 });399 this.set('filesToDeleteNames', names.substring(2));400 this.set('showDeleteDialog', true);401 },402 //select files with up and down arrow keys403 changeFileSelection({ direction, shiftKey, ctrKey }) {404 let selectedFiles = this.get('selectedFiles').slice();405 let formattedFiles = this.get('formattedFiles');406 let nextFileIndex = formattedFiles.indexOf(selectedFiles[selectedFiles.length - 1]) + direction;407 let initialIndex = formattedFiles.indexOf(selectedFiles[0]);408 if (!selectedFiles.length) {409 selectedFiles = [formattedFiles[direction === 1 ? 0 : formattedFiles.length - 1]];410 } else {411 if (nextFileIndex >= 0 && nextFileIndex < formattedFiles.length) {412 if (ctrKey) {413 if (direction === -1) {414 selectedFiles = formattedFiles.slice(0, initialIndex + 1);415 selectedFiles.reverse();416 } else {417 selectedFiles = formattedFiles.slice(initialIndex, formattedFiles.length);418 }419 } else if (shiftKey) {420 if (initialIndex > nextFileIndex) {421 selectedFiles = formattedFiles.slice(nextFileIndex, initialIndex + 1);422 selectedFiles.reverse();423 } else {424 selectedFiles = formattedFiles.slice(initialIndex, nextFileIndex + 1);425 }426 } else {427 selectedFiles = [formattedFiles[initialIndex + direction]];428 }429 } else if (!(initialIndex === 0 && direction === -1) && !ctrKey && !shiftKey &&430 !(initialIndex === formattedFiles.length - 1 && direction === 1)) {431 selectedFiles = [formattedFiles[initialIndex + direction]];432 }433 }434 this.set('selectedFiles', selectedFiles);435 if (this.get('getInfoOpen')) {436 this.setInfoPopup();437 }438 },439 actions: {440 toggleInfo({ clickedFile=null }) {441 if (!this.get('getInfoOpen')) {442 this.setInfoPopup({ clickedFile });443 }444 this.set('filePickerOpen', false);445 this.toggleProperty('getInfoOpen');446 },447 setFilePickerVar(value) {448 this.set('filePickerOpen', value);449 },450 //searches for a file through all directories451 onSearchKeydown(e) {452 if (e.keyCode === 13) {453 this.set('fetchingDirectory', true);454 this.get('fetchService').fetch(`${this.get('rootAPI')}file?cmd=search&q=${this.get('searchText')}`,455 { method: 'GET' }).then((result) => {456 this.setProperties({457 directoryFiles: this.separateFiles(result, true)[0],458 fetchingDirectory: false,459 });460 });461 }462 },463 //selects files on click464 onClickFile(file, e) {465 let previouslySelectedFiles = this.get('selectedFiles');466 let selectedFiles = [file];467 if (e.shiftKey && previouslySelectedFiles.length > 0) {468 let formattedFiles = this.get('formattedFiles');469 let firstFileIndex = formattedFiles.indexOf(previouslySelectedFiles[0]);470 let clickedFileIndex = formattedFiles.indexOf(file);471 let begin = clickedFileIndex;472 let end = firstFileIndex;473 if (firstFileIndex < clickedFileIndex) {474 begin = firstFileIndex + 1;475 end = clickedFileIndex + 1;476 }477 selectedFiles = [previouslySelectedFiles[0], ...formattedFiles.slice(begin, end)];478 } else if (e.ctrlKey || e.metaKey) {479 let index = previouslySelectedFiles.indexOf(file);480 if (index >= 0) {481 selectedFiles = previouslySelectedFiles.slice();482 selectedFiles.splice(index, 1);483 } else {484 selectedFiles = [...previouslySelectedFiles, file];485 }486 }487 this.setProperties({ selectedFiles });488 },489 //double click any file490 onDblClickFile(file) {491 if (file.read) {492 if (!this.get('renaming')) {493 if (file.mime === this.get('config').mimes.directory.name) {494 this.send('changeCWD', file.hash, { expand: true });495 } else {496 window.open(file.link);497 }498 }499 } else {500 this.get('flashMessages').warning('No permission to access this file');501 }502 },503 //deselect files504 deselect(data) {505 data = data.target;506 while (data.offsetParent !== null && !data.offsetParent.classList.contains('directory-container')) {507 if (data.classList.contains('no-deselect-area')) {508 return;509 }510 data = data.offsetParent;511 }512 this.set('selectedFiles', []);513 },514 changeDisplayType() {515 this.toggleProperty('defaultDisplay');516 },517 //change cwd (reload from db)518 changeCWD(targetHash, options={}) {519 this.set('fetchingDirectory', true);520 this.get('fetchService').fetch(`${this.get('rootAPI')}file?cmd=open&target=${targetHash}`, { method: 'GET' }).then((result) => {521 let [directoryFiles, cwdChildren] = this.separateFiles(result);522 let cwd = this.findInTree(this.get('directoryTree'), targetHash, 'hash');523 if (!cwd || !cwd.children || options.refresh) {524 set(cwd, 'children', cwdChildren);525 }526 if (options.expand) {527 set(cwd, 'expanded', true);528 }529 let backHistory = this.get('backHistory').slice();530 let forwardHistory = this.get('forwardHistory').slice();531 let oldCwd = this.get('cwd');532 if (options.transitionType !== TRANSITIONS.back) {533 if (cwd.hash !== oldCwd.hash) {534 backHistory.push(oldCwd);535 }536 if (options.transitionType !== TRANSITIONS.forward) {537 forwardHistory = [];538 }539 } else {540 forwardHistory.push(oldCwd);541 backHistory.splice(backHistory.length - 1, 1);542 }543 if (options.transitionType === TRANSITIONS.forward) {544 forwardHistory.splice(forwardHistory.length - 1, 1);545 }546 this.setProperties({547 backHistory,548 forwardHistory,549 directoryFiles,550 cwd: cwd,551 selectedFiles: [],552 fetchingDirectory: false,553 });554 });555 },556 //go back or forward in the browsed history557 backOrForward(label) {558 let history = this.get(`${label}History`);559 if (history.length > 0) {560 this.send('changeCWD', history.slice(-1)[0].hash, { transitionType: label, expand: true });561 }562 },563 //refresh cwd564 refresh() {565 this.send('changeCWD', this.get('cwd').hash, { refresh: true });566 },567 home() {568 this.send('changeCWD', this.get('homeDir'), { refresh: true });569 },570 columnHeaderClicked(property) {571 let formattedFiles = this.get('formattedFiles').slice();572 let sort = SORT.asc;573 if (this.get('column') === property) {574 sort = (this.get('sort') === SORT.asc) ? SORT.desc : SORT.asc;575 }576 formattedFiles = this.get('directoryFiles').sortBy(property);577 if (sort === SORT.desc) {578 formattedFiles.reverse();579 }580 this.setProperties({581 column: property,582 sort,583 formattedFiles,584 });585 },586 resetSearch() {587 this.set('searchText', '');588 this.send('refresh');589 },590 //TODO: add support for multiple files when ember-file-picker is able to support it591 //called when file selected with file-picker is finished loading592 fileLoaded(file) {593 this.set('filePickerOpen', false);594 const formData = new FormData();595 formData.append('cmd', 'upload');596 formData.append('target', this.get('cwd').hash);597 formData.append('upload[]', file, file.name);598 return new RSVP.Promise((resolve, reject) => {599 fetch(`${this.get('rootAPI')}file`, {600 method: 'POST',601 body: formData,602 credentials: 'same-origin',603 }).then(() => {604 this.send('refresh');605 }).catch((error) => {606 reject({ errorMessage: error });607 });608 });609 },610 //updates the file name in the db if it was changed611 renameFile(file) {612 let newName = this.get('newName');613 this.set('renaming', false);614 if (newName === file.name) {615 return;616 }617 set(file, 'name', newName);618 this.get('fetchService').fetch(`${this.get('rootAPI')}file?cmd=rename&target=${file.hash}&name=${newName}`, { method: 'GET' })619 .then(() => {620 this.send('refresh');621 });622 },623 //calls action 'renameFile' if enter is pressed624 onRenameInputKeydown(actionName, file, e) {625 if (e.keyCode === 13) {626 this.send(actionName, file);627 }628 },629 //if dialog is confirmed, delete the files selected for deletion630 confirmDelete() {631 let targetHashes = '';632 this.get('selectedFiles').forEach((file) => {633 targetHashes += `&targets%5B%5D=${file.hash}`;634 });635 if (targetHashes) {636 this.get('fetchService').fetch(`${this.get('rootAPI')}file?cmd=rm${targetHashes}`, { method: 'GET' }).then((result) => {637 if (result.removed.length) {638 this.set('deleteSuccessful', true);639 } else {640 this.set('deleteError', 'Failed to delete files.');641 }642 });643 }644 },645 //opens video input dialog when button is clicked646 openVideoDialog() {647 this.set('videoDialogOpen', true);648 },649 //closes video input dialog650 closeVideoDialog() {651 this.setProperties({652 videoUrl: '',653 videoName: '',654 videoDialogOpen: false,655 videoUrlError: '',656 });657 this.send('refresh');658 },659 //adds video to db based on input from video dialog660 addVideo() {661 let url = this.get('videoUrl');662 let name = this.get('videoName');663 let valid = /^(https?\:\/\/)?((www\.)?youtube\.com)\/watch\?v\=.+$/;664 if (!valid.test(url)) {665 this.set('videoUrlError', 'Invalid link.');666 return;667 }668 if (!name) {669 this.set('videoUrlError', 'No name entered.');670 return;671 }672 let newVideo = {673 url,674 name,675 directory: this.get('cwd').hash,676 };677 this.set('videoDialogOpen', false);678 this.get('fetchService').fetch(`${this.get('rootAPI')}file/youtube`, { method: 'POST' }, newVideo).then(() => {679 this.send('closeVideoDialog');680 });681 },682 //opens image preview dialog when button is clicked683 openPreviewDialog() {684 this.set('previewOpen', true);685 },686 //image-preview component action to select previous or next image687 previousOrNextPreview(next=true) {688 let mod = (!next) ? -1 : 1;689 let config = this.get('config');690 let formattedFiles = this.get('formattedFiles');691 let index = formattedFiles.indexOf(this.get('selectedFiles')[0]) + mod;692 while (!formattedFiles[index] || formattedFiles[index].mime === config.mimes.directory.name ||693 formattedFiles[index].mime === config.mimes.video.name) {694 index = index + mod;695 if (index > formattedFiles.length - 1) {696 index = 0;697 } else if (index < 0) {698 index = formattedFiles.length - 1;699 }700 }701 this.set('selectedFiles', [formattedFiles[index]]);702 },703 download({ clickedFile=null }) {704 let file = clickedFile || this.get('selectedFiles')[0];705 window.open(`${this.get('rootAPI')}file?cmd=file&target=${file.hash.replace(new RegExp(' ', 'g'), '%20')}&download=1`);706 },707 },...
files.js
Source:files.js
1// (C) Copyright 2015 Martin Dougiamas2//3// Licensed under the Apache License, Version 2.0 (the "License");4// you may not use this file except in compliance with the License.5// You may obtain a copy of the License at6//7// http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// distributed under the License is distributed on an "AS IS" BASIS,11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12// See the License for the specific language governing permissions and13// limitations under the License.14angular.module('mm.addons.files')15.factory('$mmaFiles', function($mmSite, $mmFS, $q, $log, $mmSitesManager, md5) {16 $log = $log.getInstance('$mmaFiles');17 var self = {},18 defaultParams = {19 "contextid": 0,20 "component": "",21 "filearea": "",22 "itemid": 0,23 "filepath": "",24 "filename": ""25 };26 /**27 * Check if core_files_get_files WS call is available.28 *29 * @module mm.addons.files30 * @ngdoc method31 * @name $mmaFiles#canAccessFiles32 * @return {Boolean} True if WS is available, false otherwise.33 */34 self.canAccessFiles = function() {35 return $mmSite.wsAvailable('core_files_get_files');36 };37 /**38 * Check if core_user_get_private_files_info WS call is available.39 *40 * @module mm.addons.files41 * @ngdoc method42 * @name $mmaFiles#canGetPrivateFilesInfo43 * @return {Boolean} True if WS is available, false otherwise.44 */45 self.canGetPrivateFilesInfo = function() {46 return $mmSite.wsAvailable('core_user_get_private_files_info');47 };48 /**49 * Check if core_user_add_user_private_files WS call is available.50 *51 * @module mm.addons.files52 * @ngdoc method53 * @name $mmaFiles#canMoveFromDraftToPrivate54 * @param {String} [siteId] Id of the site to check. If not defined, use current site.55 * @return {Promise} Promise resolved with true if WS is available, false otherwise.56 */57 self.canMoveFromDraftToPrivate = function(siteId) {58 siteId = siteId || $mmSite.getId();59 return $mmSitesManager.getSite(siteId).then(function(site) {60 return site.wsAvailable('core_user_add_user_private_files');61 });62 };63 /**64 * Get the list of files.65 *66 * @module mm.addons.files67 * @ngdoc method68 * @name $mmaFiles#getFiles69 * @param {Object} params A list of parameters accepted by the Web service.70 * @return {Object} An object containing the files in the key 'entries', and 'count'.71 * Additional properties is added to the entries, such as:72 * - imgpath: The path to the icon.73 * - link: The JSON string of params to get to the file.74 * - linkId: A hash of the file parameters.75 */76 self.getFiles = function(params) {77 var options = {};78 options.cacheKey = getFilesListCacheKey(params);79 return $mmSite.read('core_files_get_files', params, options).then(function(result) {80 var data = {81 entries: [],82 count: 083 };84 if (typeof result.files == 'undefined') {85 return $q.reject();86 }87 angular.forEach(result.files, function(entry) {88 entry.link = {};89 entry.link.contextid = (entry.contextid) ? entry.contextid : "";90 entry.link.component = (entry.component) ? entry.component : "";91 entry.link.filearea = (entry.filearea) ? entry.filearea : "";92 entry.link.itemid = (entry.itemid) ? entry.itemid : 0;93 entry.link.filepath = (entry.filepath) ? entry.filepath : "";94 entry.link.filename = (entry.filename) ? entry.filename : "";95 if (entry.component && entry.isdir) {96 // Delete unused elements that may break the request.97 entry.link.filename = "";98 }99 if (entry.isdir) {100 entry.imgpath = $mmFS.getFolderIcon();101 } else {102 entry.imgpath = $mmFS.getFileIcon(entry.filename);103 }104 entry.link = JSON.stringify(entry.link);105 entry.linkId = md5.createHash(entry.link);106 data.count += 1;107 data.entries.push(entry);108 });109 return data;110 });111 };112 /**113 * Get cache key for file list WS calls.114 *115 * @param {Object} params Params of the directory to get.116 * @return {String} Cache key.117 */118 function getFilesListCacheKey(params) {119 var root = params.component === '' ? 'site' : 'my';120 return 'mmaFiles:list:' + root + ':' + params.contextid + ':' + params.filepath;121 }122 /**123 * Get the private files of the current user.124 *125 * @module mm.addons.files126 * @ngdoc method127 * @name $mmaFiles#getMyFiles128 * @return {Object} See $mmaFiles#getFiles129 */130 self.getMyFiles = function() {131 var params = getMyFilesRootParams();132 return self.getFiles(params);133 };134 /**135 * Get the common part of the cache keys for private files WS calls.136 *137 * @return {String} Cache key.138 */139 function getMyFilesListCommonCacheKey() {140 return 'mmaFiles:list:my';141 }142 /**143 * Get params to get root private files directory.144 *145 * @return {Object} Params.146 */147 function getMyFilesRootParams() {148 var params = angular.copy(defaultParams, {});149 params.component = "user";150 params.filearea = "private";151 params.contextid = -1;152 params.contextlevel = "user";153 params.instanceid = $mmSite.getUserId();154 return params;155 }156 /**157 * Get the cache key for private files info WS calls.158 *159 * @param {Number} userId User ID.160 * @return {String} Cache key.161 */162 function getPrivateFilesInfoCacheKey(userId) {163 return getPrivateFilesInfoCommonCacheKey() + ':' + userId;164 }165 /**166 * Get the common part of the cache keys for private files info WS calls.167 *168 * @return {String} Cache key.169 */170 function getPrivateFilesInfoCommonCacheKey() {171 return 'mmaFiles:privateInfo';172 }173 /**174 * Get private files info.175 *176 * @module mm.addons.files177 * @ngdoc method178 * @name $mmaFiles#getPrivateFilesInfo179 * @param {Number} [userId] User ID. If not defined, current user in the site.180 * @param {String} [siteId] Site ID. If not defined, use current site.181 * @return {Promise} Promise resolved with the info.182 */183 self.getPrivateFilesInfo = function(userId, siteId) {184 return $mmSitesManager.getSite(siteId).then(function(site) {185 userId = userId || site.getUserId();186 var params = {187 userid: userId188 },189 preSets = {190 cacheKey: getPrivateFilesInfoCacheKey(userId)191 };192 return site.read('core_user_get_private_files_info', params, preSets);193 });194 };195 /**196 * Get the site files.197 *198 * @module mm.addons.files199 * @ngdoc method200 * @name $mmaFiles#getSiteFiles201 * @return {Object} See $mmaFiles#getFiles202 */203 self.getSiteFiles = function() {204 var params = angular.copy(defaultParams, {});205 return self.getFiles(params);206 };207 /**208 * Get the common part of the cache keys for site files WS calls.209 *210 * @return {String} Cache key.211 */212 function getSiteFilesListCommonCacheKey() {213 return 'mmaFiles:list:site';214 }215 /**216 * Invalidates list of files in a certain directory.217 *218 * @module mm.addons.files219 * @ngdoc method220 * @name $mmaFiles#invalidateDirectory221 * @param {String} root Root of the directory ('my' for private files, 'site' for site files).222 * @param {String} path Path to the directory.223 * @param {String} [siteid] Id of the site to invalidate. If not defined, use current site.224 * @return {Promise} Promise resolved when the list is invalidated.225 */226 self.invalidateDirectory = function(root, path, siteid) {227 siteid = siteid || $mmSite.getId();228 var params = {};229 if (!path) {230 if (root === 'site') {231 params = angular.copy(defaultParams, {});232 } else if (root === 'my') {233 params = getMyFilesRootParams();234 }235 } else {236 params = JSON.parse(path);237 }238 return $mmSitesManager.getSite(siteid).then(function(site) {239 return site.invalidateWsCacheForKey(getFilesListCacheKey(params));240 });241 };242 /**243 * Invalidates list of private files.244 *245 * @module mm.addons.files246 * @ngdoc method247 * @name $mmaFiles#invalidateMyFiles248 * @return {Promise} Promise resolved when the list is invalidated.249 */250 self.invalidateMyFiles = function() {251 return $mmSite.invalidateWsCacheForKeyStartingWith(getMyFilesListCommonCacheKey());252 };253 /**254 * Invalidates private files info for all users.255 *256 * @module mm.addons.files257 * @ngdoc method258 * @name $mmaFiles#invalidatePrivateFilesInfo259 * @param {String} [siteId] Site ID. If not defined, use current site.260 * @return {Promise} Promise resolved when the data is invalidated.261 */262 self.invalidatePrivateFilesInfo = function(siteId) {263 return $mmSitesManager.getSite(siteId).then(function(site) {264 return site.invalidateWsCacheForKeyStartingWith(getPrivateFilesInfoCommonCacheKey());265 });266 };267 /**268 * Invalidates private files info for a certain user.269 *270 * @module mm.addons.files271 * @ngdoc method272 * @name $mmaFiles#invalidatePrivateFilesInfoForUser273 * @param {Number} [userId] User ID. If not defined, current user in the site.274 * @param {String} [siteId] Site ID. If not defined, use current site.275 * @return {Promise} Promise resolved when the data is invalidated.276 */277 self.invalidatePrivateFilesInfoForUser = function(userId, siteId) {278 return $mmSitesManager.getSite(siteId).then(function(site) {279 userId = userId || site.getUserId();280 return site.invalidateWsCacheForKey(getPrivateFilesInfoCacheKey(userId));281 });282 };283 /**284 * Invalidates list of site files.285 *286 * @module mm.addons.files287 * @ngdoc method288 * @name $mmaFiles#invalidateSiteFiles289 * @return {Promise} Promise resolved when the list is invalidated.290 */291 self.invalidateSiteFiles = function() {292 return $mmSite.invalidateWsCacheForKeyStartingWith(getSiteFilesListCommonCacheKey());293 };294 /**295 * Check if Files is disabled in a certain site.296 *297 * @module mm.addons.files298 * @ngdoc method299 * @name $mmaFiles#isDisabled300 * @param {String} [siteId] Site Id. If not defined, use current site.301 * @return {Promise} Promise resolved with true if disabled, rejected or resolved with false otherwise.302 */303 self.isDisabled = function(siteId) {304 return $mmSitesManager.getSite(siteId).then(function(site) {305 return self.isDisabledInSite(site);306 });307 };308 /**309 * Check if Files is disabled in a certain site.310 *311 * @module mm.addons.files312 * @ngdoc method313 * @name $mmaFiles#isDisabledInSite314 * @param {Object} [site] Site. If not defined, use current site.315 * @return {Boolean} True if disabled, false otherwise.316 */317 self.isDisabledInSite = function(site) {318 site = site || $mmSite;319 return site.isFeatureDisabled('$mmSideMenuDelegate_mmaFiles');320 };321 /**322 * Return whether or not the plugin is enabled.323 * Plugin is enabled if user can see private files, can see site files or can upload private files.324 *325 * @module mm.addons.files326 * @ngdoc method327 * @name $mmaFiles#isPluginEnabled328 * @return {Boolean} True if enabled, false otherwise.329 */330 self.isPluginEnabled = function() {331 var canAccessMyFiles = $mmSite.canAccessMyFiles(),332 canViewMyFiles = self.canAccessFiles() && canAccessMyFiles && !self.isPrivateFilesDisabledInSite(),333 canViewSiteFiles = !self.isSiteFilesDisabledInSite(),334 canUploadFiles = canAccessMyFiles && $mmSite.canUploadFiles() && !self.isUploadDisabledInSite();335 return canViewMyFiles || canViewSiteFiles ||Â canUploadFiles;336 };337 /**338 * Check if private files is disabled in a certain site.339 *340 * @module mm.addons.files341 * @ngdoc method342 * @name $mmaFiles#isPrivateFilesDisabled343 * @param {String} [siteId] Site Id. If not defined, use current site.344 * @return {Promise} Promise resolved with true if disabled, rejected or resolved with false otherwise.345 */346 self.isPrivateFilesDisabled = function(siteId) {347 return $mmSitesManager.getSite(siteId).then(function(site) {348 return self.isPrivateFilesDisabledInSite(site);349 });350 };351 /**352 * Check if private files is disabled in a certain site.353 *354 * @module mm.addons.files355 * @ngdoc method356 * @name $mmaFiles#isPrivateFilesDisabledInSite357 * @param {Object} [site] Site. If not defined, use current site.358 * @return {Boolean} True if disabled, false otherwise.359 */360 self.isPrivateFilesDisabledInSite = function(site) {361 site = site || $mmSite;362 return site.isFeatureDisabled('files_privatefiles');363 };364 /**365 * Check if site files is disabled in a certain site.366 *367 * @module mm.addons.files368 * @ngdoc method369 * @name $mmaFiles#isSiteFilesDisabled370 * @param {String} [siteId] Site Id. If not defined, use current site.371 * @return {Promise} Promise resolved with true if disabled, rejected or resolved with false otherwise.372 */373 self.isSiteFilesDisabled = function(siteId) {374 return $mmSitesManager.getSite(siteId).then(function(site) {375 return self.isSiteFilesDisabledInSite(site);376 });377 };378 /**379 * Check if site files is disabled in a certain site.380 *381 * @module mm.addons.files382 * @ngdoc method383 * @name $mmaFiles#isSiteFilesDisabledInSite384 * @param {Object} [site] Site. If not defined, use current site.385 * @return {Boolean} True if disabled, false otherwise.386 */387 self.isSiteFilesDisabledInSite = function(site) {388 site = site || $mmSite;389 return site.isFeatureDisabled('files_sitefiles');390 };391 /**392 * Check if upload files is disabled in a certain site.393 *394 * @module mm.addons.files395 * @ngdoc method396 * @name $mmaFiles#isUploadDisabled397 * @param {String} [siteId] Site Id. If not defined, use current site.398 * @return {Promise} Promise resolved with true if disabled, rejected or resolved with false otherwise.399 */400 self.isUploadDisabled = function(siteId) {401 return $mmSitesManager.getSite(siteId).then(function(site) {402 return self.isUploadDisabledInSite(site);403 });404 };405 /**406 * Check if upload files is disabled in a certain site.407 *408 * @module mm.addons.files409 * @ngdoc method410 * @name $mmaFiles#isUploadDisabledInSite411 * @param {Object} [site] Site. If not defined, use current site.412 * @return {Boolean} True if disabled, false otherwise.413 */414 self.isUploadDisabledInSite = function(site) {415 site = site || $mmSite;416 return site.isFeatureDisabled('files_upload');417 };418 /**419 * Move a file from draft area to private files.420 *421 * @module mm.addons.files422 * @ngdoc method423 * @name $mmaFiles#moveFromDraftToPrivate424 * @param {Number} draftId The draft area ID of the file.425 * @param {String} [siteid] ID of the site. If not defined, use current site.426 * @return {Promise} Promise resolved in success, rejected otherwise.427 */428 self.moveFromDraftToPrivate = function(draftId, siteId) {429 siteId = siteId || $mmSite.getId();430 var params = {431 draftid: draftId432 },433 preSets = {434 responseExpected: false435 };436 return $mmSitesManager.getSite(siteId).then(function(site) {437 return site.write('core_user_add_user_private_files', params, preSets);438 });439 };440 /**441 * Check the Moodle version in order to check if file should be moved from draft to private files.442 *443 * @module mm.addons.files444 * @ngdoc method445 * @name $mmaFiles#shouldMoveFromDraftToPrivate446 * @param {String} [siteId] Id of the site to check. If not defined, use current site.447 * @return {Promise} Resolved with true if should be moved, false otherwise.448 */449 self.shouldMoveFromDraftToPrivate = function(siteId) {450 siteId = siteId || $mmSite.getId();451 return $mmSitesManager.getSite(siteId).then(function(site) {452 return site.isVersionGreaterEqualThan('3.1.0');453 });454 };455 /**456 * Check the Moodle version in order to check if upload files is working.457 *458 * @module mm.addons.files459 * @ngdoc method460 * @name $mmaFiles#versionCanUploadFiles461 * @param {String} [siteId] Id of the site to check. If not defined, use current site.462 * @return {Promise} Resolved with true if WS is working, false otherwise.463 */464 self.versionCanUploadFiles = function(siteId) {465 siteId = siteId || $mmSite.getId();466 return $mmSitesManager.getSite(siteId).then(function(site) {467 if (site.isVersionGreaterEqualThan('3.1.1')) {468 // In Moodle 3.1.1 or higher we need a WS to move to private files.469 return self.canMoveFromDraftToPrivate(siteId);470 } else if (site.isVersionGreaterEqualThan('3.1.0')) {471 // Upload private files doesn't work for Moodle 3.1.0 due to a bug.472 return false;473 }474 return true;475 });476 };477 return self;...
moz.build
Source:moz.build
1# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-2# vim: set filetype=python:3# This Source Code Form is subject to the terms of the Mozilla Public4# License, v. 2.0. If a copy of the MPL was not distributed with this5# file, You can obtain one at http://mozilla.org/MPL/2.0/.6TEST_HARNESS_FILES.testing.mochitest.tests.fonts.math += [7 'fonts/math/axis-height-1.otf',8 'fonts/math/axis-height-2.otf',9 'fonts/math/fraction-1.otf',10 'fonts/math/fraction-2.otf',11 'fonts/math/fraction-3.otf',12 'fonts/math/fraction-4.otf',13 'fonts/math/fraction-5.otf',14 'fonts/math/fraction-6.otf',15 'fonts/math/fraction-7.otf',16 'fonts/math/fraction-8.otf',17 'fonts/math/fraction-9.otf',18 'fonts/math/limits-1.otf',19 'fonts/math/limits-2.otf',20 'fonts/math/limits-3.otf',21 'fonts/math/limits-4.otf',22 'fonts/math/limits-5.otf',23 'fonts/math/radical-1.otf',24 'fonts/math/radical-2.otf',25 'fonts/math/radical-3.otf',26 'fonts/math/radical-4.otf',27 'fonts/math/radical-5.otf',28 'fonts/math/radical-6.otf',29 'fonts/math/radical-7.otf',30 'fonts/math/scripts-1.otf',31 'fonts/math/scripts-2.otf',32 'fonts/math/scripts-3.otf',33 'fonts/math/scripts-4.otf',34 'fonts/math/scripts-5.otf',35 'fonts/math/scripts-6.otf',36 'fonts/math/scripts-7.otf',37 'fonts/math/scripts-8.otf',38 'fonts/math/scripts-9.otf',39 'fonts/math/stack-1.otf',40 'fonts/math/stack-2.otf',41 'fonts/math/stack-3.otf',42 'fonts/math/stack-4.otf',43 'fonts/math/stack-5.otf',44 'fonts/math/stack-6.otf',45]46TEST_HARNESS_FILES.testing.mochitest.tests.fonts.mplus += [47 'fonts/mplus/mplus-1p-regular.ttf',48]49TEST_HARNESS_FILES.testing.mochitest.tests.fonts += [50 'fonts/Ahem.ttf',51]52REFTEST_MANIFESTS += ['reftest.list']53with Files('abs-pos/**'):54 BUG_COMPONENT = ('Core', 'Layout: R & A Pos')55with Files('async-scrolling/**'):56 BUG_COMPONENT = ('Core', 'Layout')57with Files('backgrounds/**'):58 BUG_COMPONENT = ('Core', 'Layout')59with Files('bidi/**'):60 BUG_COMPONENT = ('Core', 'Layout: Text')61with Files('border-image/**'):62 BUG_COMPONENT = ('Core', 'Layout')63with Files('border-radius/**'):64 BUG_COMPONENT = ('Core', 'Layout')65with Files('box/**'):66 BUG_COMPONENT = ('Core', 'XP Toolkit/Widgets: XUL')67with Files('box-ordinal/**'):68 BUG_COMPONENT = ('Core', 'XP Toolkit/Widgets: XUL')69with Files('box-properties/**'):70 BUG_COMPONENT = ('Core', 'Layout')71with Files('box-shadow/**'):72 BUG_COMPONENT = ('Core', 'Layout')73with Files('box-sizing/**'):74 BUG_COMPONENT = ('Core', 'Layout')75with Files('bugs/**'):76 BUG_COMPONENT = ('Core', 'Layout')77with Files('canvas/**'):78 BUG_COMPONENT = ('Core', 'Layout: Images')79with Files('columns/**'):80 BUG_COMPONENT = ('Core', 'Layout: Block and Inline')81with Files('counter-style/**'):82 BUG_COMPONENT = ('Core', 'CSS Parsing and Computation')83with Files('counters/**'):84 BUG_COMPONENT = ('Core', 'Layout')85with Files('css-animations/**'):86 BUG_COMPONENT = ('Core', 'CSS Parsing and Computation')87with Files('css-blending/**'):88 BUG_COMPONENT = ('Core', 'Layout')89with Files('css-break/**'):90 BUG_COMPONENT = ('Core', 'Layout: Block and Inline')91with Files('css-calc/**'):92 BUG_COMPONENT = ('Core', 'CSS Parsing and Computation')93with Files('css-charset/**'):94 BUG_COMPONENT = ('Core', 'CSS Parsing and Computation')95with Files('css-default/**'):96 BUG_COMPONENT = ('Core', 'Layout: Form Controls')97with Files('css-disabled/**'):98 BUG_COMPONENT = ('Core', 'Layout: Form Controls')99with Files('css-display/**'):100 BUG_COMPONENT = ('Core', 'Layout')101with Files('css-enabled/**'):102 BUG_COMPONENT = ('Core', 'Layout: Form Controls')103with Files('css-gradients/**'):104 BUG_COMPONENT = ('Core', 'Layout')105with Files('css-grid/**'):106 BUG_COMPONENT = ('Core', 'Layout')107with Files('css-import/**'):108 BUG_COMPONENT = ('Core', 'CSS Parsing and Computation')109with Files('css-invalid/**'):110 BUG_COMPONENT = ('Core', 'Layout: Form Controls')111with Files('css-mediaqueries/**'):112 BUG_COMPONENT = ('Core', 'CSS Parsing and Computation')113with Files('css-optional/**'):114 BUG_COMPONENT = ('Core', 'Layout: Form Controls')115with Files('css-parsing/**'):116 BUG_COMPONENT = ('Core', 'CSS Parsing and Computation')117with Files('css-placeholder/**'):118 BUG_COMPONENT = ('Core', 'Layout: Form Controls')119with Files('css-required/**'):120 BUG_COMPONENT = ('Core', 'Layout: Form Controls')121with Files('css-ruby/**'):122 BUG_COMPONENT = ('Core', 'Layout: Block and Inline')123with Files('css-selectors/**'):124 BUG_COMPONENT = ('Core', 'CSS Parsing and Computation')125with Files('css-submit-invalid/**'):126 BUG_COMPONENT = ('Core', 'Layout: Form Controls')127with Files('css-transitions/**'):128 BUG_COMPONENT = ('Core', 'CSS Parsing and Computation')129with Files('css-ui-invalid/**'):130 BUG_COMPONENT = ('Core', 'Layout: Form Controls')131with Files('css-ui-valid/**'):132 BUG_COMPONENT = ('Core', 'Layout: Form Controls')133with Files('css-valid/**'):134 BUG_COMPONENT = ('Core', 'Layout: Form Controls')135with Files('css-valuesandunits/**'):136 BUG_COMPONENT = ('Core', 'CSS Parsing and Computation')137with Files('css-variables/**'):138 BUG_COMPONENT = ('Core', 'CSS Parsing and Computation')139with Files('css-visited/**'):140 BUG_COMPONENT = ('Core', 'CSS Parsing and Computation')141with Files('cssom/**'):142 BUG_COMPONENT = ('Core', 'DOM: CSS Object Model')143with Files('datalist/**'):144 BUG_COMPONENT = ('Core', 'DOM: Core & HTML')145with Files('dom/**'):146 BUG_COMPONENT = ('Core', 'DOM: Core & HTML')147with Files('filters.svg'):148 BUG_COMPONENT = ('Core', 'SVG')149with Files('first-letter/**'):150 BUG_COMPONENT = ('Core', 'Layout: Block and Inline')151with Files('first-line/**'):152 BUG_COMPONENT = ('Core', 'Layout: Block and Inline')153with Files('flexbox/**'):154 BUG_COMPONENT = ('Core', 'Layout')155with Files('floats/**'):156 BUG_COMPONENT = ('Core', 'Layout: Floats')157with Files('font-face/**'):158 BUG_COMPONENT = ('Core', 'CSS Parsing and Computation')159with Files('font-features/**'):160 BUG_COMPONENT = ('Core', 'Layout: Text')161with Files('font-inflation/**'):162 BUG_COMPONENT = ('Core', 'Layout: Text')163with Files('font-loading-api/**'):164 BUG_COMPONENT = ('Core', 'CSS Parsing and Computation')165with Files('font-matching/**'):166 BUG_COMPONENT = ('Core', 'Layout: Text')167with Files('fonts/**'):168 BUG_COMPONENT = ('Core', 'Layout: Text')169with Files('forms/**'):170 BUG_COMPONENT = ('Core', 'Layout: Form Controls')171with Files('generated-content/**'):172 BUG_COMPONENT = ('Core', 'Layout')173with Files('ib-split/**'):174 BUG_COMPONENT = ('Core', 'Layout: Block and Inline')175with Files('image/**'):176 BUG_COMPONENT = ('Core', 'Layout: Images')177with Files('image-element/**'):178 BUG_COMPONENT = ('Core', 'Layout: Images')179with Files('image-rect/**'):180 BUG_COMPONENT = ('Core', 'Layout')181with Files('image-region/**'):182 BUG_COMPONENT = ('Core', 'Layout: Images')183with Files('indic-shaping/**'):184 BUG_COMPONENT = ('Core', 'Layout: Text')185with Files('inline/**'):186 BUG_COMPONENT = ('Core', 'Layout: Block and Inline')187with Files('inline-borderpadding/**'):188 BUG_COMPONENT = ('Core', 'Layout: Block and Inline')189with Files('invalidation/**'):190 BUG_COMPONENT = ('Core', 'Layout')191with Files('layers/**'):192 BUG_COMPONENT = ('Core', 'Graphics: Layers')193with Files('line-breaking/**'):194 BUG_COMPONENT = ('Core', 'Layout: Block and Inline')195with Files('list-item/**'):196 BUG_COMPONENT = ('Core', 'Layout: Block and Inline')197with Files('margin-collapsing/**'):198 BUG_COMPONENT = ('Core', 'Layout: Block and Inline')199with Files('marquee/**'):200 BUG_COMPONENT = ('Core', 'CSS Parsing and Computation')201with Files('mathml/**'):202 BUG_COMPONENT = ('Core', 'MathML')203with Files('native-theme/**'):204 BUG_COMPONENT = ('Core', 'Layout')205with Files('object/**'):206 BUG_COMPONENT = ('Core', 'DOM')207with Files('ogg-video/**'):208 BUG_COMPONENT = ('Core', 'Audio/Video')209with Files('outline/**'):210 BUG_COMPONENT = ('Core', 'Layout')211with Files('pagination/**'):212 BUG_COMPONENT = ('Core', 'Layout')213with Files('percent-overflow-sizing/**'):214 BUG_COMPONENT = ('Core', 'Layout')215with Files('pixel-rounding/**'):216 BUG_COMPONENT = ('Core', 'Layout')217with Files('position-dynamic-changes/**'):218 BUG_COMPONENT = ('Core', 'Layout: R & A Pos')219with Files('position-relative/**'):220 BUG_COMPONENT = ('Core', 'Layout: R & A Pos')221with Files('position-sticky/**'):222 BUG_COMPONENT = ('Core', 'Layout: R & A Pos')223with Files('printing/**'):224 BUG_COMPONENT = ('Core', 'Printing: Output')225with Files('reftest-sanity/**'):226 BUG_COMPONENT = ('Testing', 'Reftest')227with Files('scoped-style/**'):228 BUG_COMPONENT = ('Core', 'CSS Parsing and Computation')229with Files('scrolling/**'):230 BUG_COMPONENT = ('Core', 'Layout')231with Files('selection/**'):232 BUG_COMPONENT = ('Core', 'Selection')233with Files('svg/**'):234 BUG_COMPONENT = ('Core', 'SVG')235with Files('tab-size/**'):236 BUG_COMPONENT = ('Core', 'Layout: Text')237with Files('table-anonymous-boxes/**'):238 BUG_COMPONENT = ('Core', 'Layout: Tables')239with Files('table-background/**'):240 BUG_COMPONENT = ('Core', 'Layout: Tables')241with Files('table-bordercollapse/**'):242 BUG_COMPONENT = ('Core', 'Layout: Tables')243with Files('table-dom/**'):244 BUG_COMPONENT = ('Core', 'Layout: Tables')245with Files('table-overflow/**'):246 BUG_COMPONENT = ('Core', 'Layout: Tables')247with Files('table-width/**'):248 BUG_COMPONENT = ('Core', 'Layout: Tables')249with Files('text/**'):250 BUG_COMPONENT = ('Core', 'Layout: Text')251with Files('text-decoration/**'):252 BUG_COMPONENT = ('Core', 'Layout: Block and Inline')253with Files('text-indent/**'):254 BUG_COMPONENT = ('Core', 'Layout: Block and Inline')255with Files('text-overflow/**'):256 BUG_COMPONENT = ('Core', 'Layout: Text')257with Files('text-shadow/**'):258 BUG_COMPONENT = ('Core', 'Layout: Text')259with Files('text-svgglyphs/**'):260 BUG_COMPONENT = ('Core', 'SVG')261with Files('text-transform/**'):262 BUG_COMPONENT = ('Core', 'Layout: Text')263with Files('transform/**'):264 BUG_COMPONENT = ('Core', 'Layout')265with Files('transform-3d/**'):266 BUG_COMPONENT = ('Core', 'Layout')267with Files('unicode/**'):268 BUG_COMPONENT = ('Core', 'CSS Parsing and Computation')269with Files('view-source/**'):270 BUG_COMPONENT = ('Core', 'HTML: Parser')271with Files('w3c-css/**'):272 BUG_COMPONENT = ('Core', 'Layout')273with Files('w3c-css/received/css-conditional-3/**'):274 BUG_COMPONENT = ('Core', 'CSS Parsing and Computation')275with Files('w3c-css/received/css-namespaces-3/**'):276 BUG_COMPONENT = ('Core', 'CSS Parsing and Computation')277with Files('w3c-css/received/css-values-3/**'):278 BUG_COMPONENT = ('Core', 'CSS Parsing and Computation')279with Files('w3c-css/submitted/conditional3/**'):280 BUG_COMPONENT = ('Core', 'CSS Parsing and Computation')281with Files('w3c-css/submitted/css21/**'):282 BUG_COMPONENT = ('Core', 'Layout')283with Files('w3c-css/submitted/flexbox/**'):284 BUG_COMPONENT = ('Core', 'Layout')285with Files('w3c-css/submitted/fonts3/**'):286 BUG_COMPONENT = ('Core', 'Layout: Text')287with Files('w3c-css/submitted/images3/**'):288 BUG_COMPONENT = ('Core', 'Layout')289with Files('w3c-css/submitted/lists-3/**'):290 BUG_COMPONENT = ('Core', 'Layout: Block and Inline')291with Files('w3c-css/submitted/multicol3/**'):292 BUG_COMPONENT = ('Core', 'Layout')293with Files('w3c-css/submitted/ruby/**'):294 BUG_COMPONENT = ('Core', 'Layout: Block and Inline')295with Files('w3c-css/submitted/text-decor-3/**'):296 BUG_COMPONENT = ('Core', 'Layout: Block and Inline')297with Files('w3c-css/submitted/ui3/**'):298 BUG_COMPONENT = ('Core', 'Layout')299with Files('w3c-css/submitted/values3/**'):300 BUG_COMPONENT = ('Core', 'CSS Parsing and Computation')301with Files('w3c-css/submitted/variables/**'):302 BUG_COMPONENT = ('Core', 'CSS Parsing and Computation')303with Files('webcomponents/**'):304 BUG_COMPONENT = ('Core', 'DOM')305with Files('webm-video/**'):306 BUG_COMPONENT = ('Core', 'Audio/Video')307with Files('writing-mode/**'):308 BUG_COMPONENT = ('Core', 'Layout: Block and Inline')309with Files('xul/**'):310 BUG_COMPONENT = ('Core', 'XP Toolkit/Widgets: XUL')311with Files('xul-document-load/**'):312 BUG_COMPONENT = ('Core', 'XP Toolkit/Widgets: XUL')313with Files('z-index/**'):...
list.ts
Source:list.ts
1// (C) Copyright 2015 Moodle Pty Ltd.2//3// Licensed under the Apache License, Version 2.0 (the "License");4// you may not use this file except in compliance with the License.5// You may obtain a copy of the License at6//7// http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// distributed under the License is distributed on an "AS IS" BASIS,11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12// See the License for the specific language governing permissions and13// limitations under the License.14import { Component, OnDestroy } from '@angular/core';15import { IonicPage, NavParams } from 'ionic-angular';16import { TranslateService } from '@ngx-translate/core';17import { CoreAppProvider } from '@providers/app';18import { CoreEventsProvider } from '@providers/events';19import { CoreSitesProvider } from '@providers/sites';20import { CoreDomUtilsProvider } from '@providers/utils/dom';21import { CoreTextUtilsProvider } from '@providers/utils/text';22import { AddonFilesProvider, AddonFilesFile, AddonFilesGetUserPrivateFilesInfoResult } from '../../providers/files';23import { AddonFilesHelperProvider } from '../../providers/helper';24/**25 * Page that displays the list of files.26 */27@IonicPage({ segment: 'addon-files-list' })28@Component({29 selector: 'page-addon-files-list',30 templateUrl: 'list.html',31})32export class AddonFilesListPage implements OnDestroy {33 title: string; // Page title.34 showPrivateFiles: boolean; // Whether the user can view private files.35 showSiteFiles: boolean; // Whether the user can view site files.36 showUpload: boolean; // Whether the user can upload files.37 root: string; // The root of the files loaded: 'my' or 'site'.38 path: string; // The path of the directory being loaded. If empty path it means the root is being loaded.39 userQuota: number; // The user quota (in bytes).40 filesInfo: AddonFilesGetUserPrivateFilesInfoResult; // Info about private files (size, number of files, etc.).41 spaceUsed: string; // Space used in a readable format.42 userQuotaReadable: string; // User quota in a readable format.43 files: AddonFilesFile[]; // List of files.44 component: string; // Component to link the file downloads to.45 filesLoaded: boolean; // Whether the files are loaded.46 protected updateSiteObserver;47 constructor(navParams: NavParams, eventsProvider: CoreEventsProvider, private sitesProvider: CoreSitesProvider,48 private domUtils: CoreDomUtilsProvider, private translate: TranslateService, private appProvider: CoreAppProvider,49 private filesProvider: AddonFilesProvider, private filesHelper: AddonFilesHelperProvider,50 private textUtils: CoreTextUtilsProvider) {51 this.title = navParams.get('title') || this.translate.instant('addon.files.files');52 this.root = navParams.get('root');53 this.path = navParams.get('path');54 // Update visibility if current site info is updated.55 this.updateSiteObserver = eventsProvider.on(CoreEventsProvider.SITE_UPDATED, () => {56 this.setVisibility();57 }, sitesProvider.getCurrentSiteId());58 }59 /**60 * View loaded.61 */62 ionViewDidLoad(): void {63 this.setVisibility();64 this.userQuota = this.sitesProvider.getCurrentSite().getInfo().userquota;65 if (!this.root) {66 // Load private files by default.67 if (this.showPrivateFiles) {68 this.root = 'my';69 } else if (this.showSiteFiles) {70 this.root = 'site';71 }72 }73 if (this.root) {74 this.rootChanged();75 } else {76 this.filesLoaded = true;77 }78 }79 /**80 * Refresh the data.81 *82 * @param refresher Refresher.83 */84 refreshData(refresher: any): void {85 this.refreshFiles().finally(() => {86 refresher.complete();87 });88 }89 /**90 * Function called when the root has changed.91 */92 rootChanged(): void {93 this.filesLoaded = false;94 this.component = this.root == 'my' ? AddonFilesProvider.PRIVATE_FILES_COMPONENT : AddonFilesProvider.SITE_FILES_COMPONENT;95 this.fetchFiles().finally(() => {96 this.filesLoaded = true;97 });98 }99 /**100 * Upload a new file.101 */102 uploadFile(): void {103 this.filesProvider.versionCanUploadFiles().then((canUpload) => {104 if (!canUpload) {105 this.domUtils.showAlertTranslated('core.notice', 'addon.files.erroruploadnotworking');106 } else if (!this.appProvider.isOnline()) {107 this.domUtils.showErrorModal('core.fileuploader.errormustbeonlinetoupload', true);108 } else {109 this.filesHelper.uploadPrivateFile(this.filesInfo).then(() => {110 // File uploaded, refresh the list.111 this.filesLoaded = false;112 this.refreshFiles().finally(() => {113 this.filesLoaded = true;114 });115 }).catch(() => {116 // Ignore errors, they're handled inside the function.117 });118 }119 });120 }121 /**122 * Set visibility of some items based on site data.123 */124 protected setVisibility(): void {125 this.showPrivateFiles = this.filesProvider.canViewPrivateFiles();126 this.showSiteFiles = this.filesProvider.canViewSiteFiles();127 this.showUpload = this.filesProvider.canUploadFiles();128 }129 /**130 * Fetch the files.131 *132 * @return Promise resolved when done.133 */134 protected fetchFiles(): Promise<any> {135 let promise: Promise<AddonFilesFile[]>;136 if (!this.path) {137 // The path is unknown, the user must be requesting a root.138 if (this.root == 'site') {139 this.title = this.translate.instant('addon.files.sitefiles');140 promise = this.filesProvider.getSiteFiles();141 } else if (this.root == 'my') {142 this.title = this.translate.instant('addon.files.files');143 promise = this.filesProvider.getPrivateFiles().then((files) => {144 if (this.showUpload && this.filesProvider.canGetPrivateFilesInfo() && this.userQuota > 0) {145 // Get the info to calculate the available size.146 return this.filesProvider.getPrivateFilesInfo().then((info) => {147 this.filesInfo = info;148 this.spaceUsed = this.textUtils.bytesToSize(info.filesizewithoutreferences, 1);149 this.userQuotaReadable = this.textUtils.bytesToSize(this.userQuota, 1);150 return files;151 });152 } else {153 // User quota isn't useful, delete it.154 delete this.userQuota;155 }156 return files;157 });158 } else {159 // Unknown root.160 promise = Promise.reject(null);161 }162 } else {163 // Path is set, serve the files the user requested.164 promise = this.filesProvider.getFiles(this.path);165 }166 return promise.then((files) => {167 this.files = files;168 }).catch((error) => {169 this.domUtils.showErrorModalDefault(error, 'addon.files.couldnotloadfiles', true);170 });171 }172 /**173 * Refresh the displayed files.174 *175 * @return Promise resolved when done.176 */177 protected refreshFiles(): Promise<any> {178 const promises = [];179 promises.push(this.filesProvider.invalidateDirectory(this.root, this.path));180 promises.push(this.filesProvider.invalidatePrivateFilesInfoForUser());181 return Promise.all(promises).finally(() => {182 return this.fetchFiles();183 });184 }185 /**186 * Page destroyed.187 */188 ngOnDestroy(): void {189 this.updateSiteObserver && this.updateSiteObserver.off();190 }...
list.js
Source:list.js
1// (C) Copyright 2015 Martin Dougiamas2//3// Licensed under the Apache License, Version 2.0 (the "License");4// you may not use this file except in compliance with the License.5// You may obtain a copy of the License at6//7// http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// distributed under the License is distributed on an "AS IS" BASIS,11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12// See the License for the specific language governing permissions and13// limitations under the License.14angular.module('mm.addons.files')15.controller('mmaFilesListController', function($q, $scope, $stateParams, $mmaFiles, $mmSite, $translate, $mmUtil, $mmText,16 $mmaFilesHelper, $mmApp, mmaFilesMyComponent, mmaFilesSiteComponent) {17 var path = $stateParams.path,18 root = $stateParams.root,19 isMyFiles = root === 'my',20 isSiteFiles = root === 'site',21 userQuota = $mmSite.getInfo().userquota,22 promise;23 // We're loading the files.24 $scope.count = -1;25 $scope.component = isMyFiles ? mmaFilesMyComponent : mmaFilesSiteComponent;26 $scope.showUpload = isMyFiles && !path && $mmSite.canUploadFiles() && !$mmaFiles.isUploadDisabledInSite();27 // Convenience function that fetches the files and updates the scope.28 function fetchFiles() {29 if (!path) {30 // The path is unknown, the user must be requesting a root.31 if (isSiteFiles) {32 promise = $mmaFiles.getSiteFiles();33 $scope.title = $translate.instant('mma.files.sitefiles');34 } else if (isMyFiles) {35 promise = $mmaFiles.getMyFiles().then(function(files) {36 if ($scope.showUpload && $mmaFiles.canGetPrivateFilesInfo() && userQuota > 0) {37 // Get the info to calculate the available size.38 return $mmaFiles.getPrivateFilesInfo().then(function(info) {39 $scope.filesInfo = info;40 $scope.spaceUsed = $mmText.bytesToSize(info.filesizewithoutreferences, 1);41 $scope.userQuota = $mmText.bytesToSize(userQuota, 1);42 return files;43 });44 } else {45 delete $scope.userQuota;46 }47 return files;48 });49 $scope.title = $translate.instant('mma.files.files');50 } else {51 // Upon error we create a fake promise that is rejected.52 promise = $q.reject();53 }54 } else {55 // Serve the files the user requested.56 pathdata = JSON.parse(path);57 promise = $mmaFiles.getFiles(pathdata);58 $scope.title = $stateParams.title;59 }60 return promise.then(function(files) {61 $scope.files = files.entries;62 $scope.count = files.count;63 }).catch(function(error) {64 $mmUtil.showErrorModalDefault(error, 'mma.files.couldnotloadfiles', true);65 return $q.reject();66 });67 }68 // Function to refresh files list.69 function refreshFiles() {70 var promises = [];71 promises.push($mmaFiles.invalidateDirectory(root, path));72 promises.push($mmaFiles.invalidatePrivateFilesInfoForUser());73 return $q.all(promises).finally(function() {74 return fetchFiles();75 });76 }77 fetchFiles().finally(function() {78 $scope.filesLoaded = true;79 });80 $scope.refreshFiles = function() {81 refreshFiles().finally(function() {82 $scope.$broadcast('scroll.refreshComplete');83 });84 };85 // When we are in the root of the private files we can add more files.86 $scope.add = function() {87 $mmaFiles.versionCanUploadFiles().then(function(canUpload) {88 if (!canUpload) {89 $mmUtil.showModal('mm.core.notice', 'mma.files.erroruploadnotworking');90 } else if (!$mmApp.isOnline()) {91 $mmUtil.showErrorModal('mm.fileuploader.errormustbeonlinetoupload', true);92 } else {93 $mmaFilesHelper.selectAndUploadFile($scope.filesInfo).then(function() {94 $scope.filesLoaded = false;95 refreshFiles().finally(function() {96 $scope.filesLoaded = true;97 });98 });99 }100 });101 };...
Using AI Code Generation
1var ladle = require("ladle");2var files = ladle.files;3files.read("test.txt", function (err, data) {4 if (err) {5 throw err;6 }7 console.log(data);8});9files.write("test.txt", "Hello World", function (err) {10 if (err) {11 throw err;12 }13 console.log("done");14});15files.append("test.txt", "Hello World", function (err) {16 if (err) {17 throw err;18 }19 console.log("done");20});21files.read("test.txt", function (err, data) {22 if (err) {23 throw err;24 }25 console.log(data);26});27files.remove("test.txt", function (err) {28 if (err) {29 throw err;30 }31 console.log("done");32});33files.read("test.txt", function (err, data) {34 if (err) {35 throw err;36 }37 console.log(data);38});39files.exists("test.txt", function (err, exists) {40 if (err) {41 throw err;42 }43 console.log(exists);44});45files.copy("test.txt", "test2.txt", function (err) {46 if (err) {47 throw err;48 }49 console.log("done");50});51files.move("test2.txt", "test3.txt", function (err) {52 if (err) {53 throw err;54 }55 console.log("done");56});57files.rename("test3.txt", "test4.txt", function (err) {58 if (err) {59 throw err;60 }61 console.log("done");62});63files.exists("test4.txt", function (err, exists) {64 if (err) {65 throw err;66 }67 console.log(exists);68});69files.remove("test4.txt", function (err) {70 if (err) {71 throw err;72 }73 console.log("done");74});75files.exists("test4.txt", function (err, exists) {76 if (err) {77 throw err;78 }79 console.log(exists);80});81files.read("test.txt", function (err, data) {82 if (err) {83 throw err;84 }85 console.log(data);86});87files.read("test2.txt", function (err, data) {88 if (err) {89 throw err;
Using AI Code Generation
1var ladle = require('ladle');2var files = ladle.files;3files.createFile('test.txt', 'hello world', function(err) {4 if (err) {5 console.log(err);6 } else {7 console.log('File created');8 }9});10var ladle = require('ladle');11var folders = ladle.folders;12folders.createFolder('test', function(err) {13 if (err) {14 console.log(err);15 } else {16 console.log('Folder created');17 }18});19var ladle = require('ladle');20var files = ladle.files;21files.createFile('test.txt', 'hello world', function(err) {22 if (err) {23 console.log(err);24 } else {25 console.log('File created');26 }27});28var ladle = require('ladle');29var folders = ladle.folders;30folders.createFolder('test', function(err) {31 if (err) {32 console.log(err);33 } else {34 console.log('Folder created');35 }36});37var ladle = require('ladle');38var files = ladle.files;39files.createFile('test.txt', 'hello world', function(err) {40 if (err) {41 console.log(err);42 } else {43 console.log('File created');44 }45});46var ladle = require('ladle');47var folders = ladle.folders;48folders.createFolder('test', function(err) {49 if (err) {50 console.log(err);51 } else {52 console.log('Folder created');53 }54});55var ladle = require('ladle');56var files = ladle.files;57files.createFile('test.txt', 'hello world', function(err) {58 if (err) {59 console.log(err);60 } else {61 console.log('File created');62 }63});64var ladle = require('ladle');65var folders = ladle.folders;66folders.createFolder('test', function(err) {67 if (err) {68 console.log(err);69 } else {70 console.log('Folder created
Using AI Code Generation
1var ladle = require('ladle');2var files = ladle.files;3var path = require('path');4files(path.join(__dirname, 'test.js'), function (err, data) {5 console.log(data);6});7var ladle = require('ladle');8var files = ladle.files;9var path = require('path');10files(path.join(__dirname, 'test.js'), function (err, data) {11 console.log(data);12});13var ladle = require('ladle');14var files = ladle.files;15var path = require('path');16files(path.join(__dirname, 'test.js'), function (err, data) {17 console.log(data);18});19var ladle = require('ladle');20var files = ladle.files;21var path = require('path');22files(path.join(__dirname, 'test.js'), function (err, data) {23 console.log(data);24});25var ladle = require('ladle');26var files = ladle.files;27var path = require('path');28files(path.join(__dirname, 'test.js'), function (err, data) {29 console.log(data);30});31var ladle = require('ladle');32var files = ladle.files;33var path = require('path');34files(path.join(__dirname, 'test.js'), function (err, data) {35 console.log(data);36});37var ladle = require('ladle');38var files = ladle.files;39var path = require('path');40files(path.join(__dirname, 'test.js'), function (err, data) {41 console.log(data);42});43var ladle = require('ladle');44var files = ladle.files;45var path = require('path');46files(path.join(__dirname, 'test.js'), function (err, data) {47 console.log(data);48});
Using AI Code Generation
1const ladle = require('ladle');2const files = ladle.files;3files.write('test.txt', 'Hello World!');4files.read('test.txt');5files.delete('test.txt');6files.append('test.txt', 'Hello World!');7files.rename('test.txt', 'test2.txt');8files.copy('test.txt', 'test2.txt');9files.move('test.txt', 'test2.txt');10files.exists('test.txt');11files.size('test.txt');12files.type('test.txt');13files.extension('test.txt');14files.name('test.txt');15files.directory('test.txt');16files.create('test.txt');17files.create('test.txt', 'Hello World!');18files.create('test.txt', 'Hello World!', true);19files.create('test.txt', 'Hello World!', false);20files.create('test.txt', 'Hello World!', true, true);21files.create('test.txt', 'Hello World!', false, true);22files.create('test.txt', 'Hello World!', true, false);23files.create('test.txt', 'Hello World!', false, false);24files.create('test.txt', 'Hello World!', true, true, true);25files.create('test.txt', 'Hello World!', false, true, true);26files.create('test.txt', 'Hello World!',
Using AI Code Generation
1const ladle = require('ladle');2const fs = require('fs');3const ladleInstance = ladle.createLadle();4const file = fs.createWriteStream('test.txt');5file.write('hello world');6file.end();7ladleInstance.files('test.txt');8ladleInstance.end();9const ladle = require('ladle');10const fs = require('fs');11const ladleInstance = ladle.createLadle();12const file = fs.createWriteStream('test.txt');13file.write('hello world');14file.end();15ladleInstance.files('test.txt');16ladleInstance.end();17const ladle = require('ladle');18const fs = require('fs');19const ladleInstance = ladle.createLadle();20const file = fs.createWriteStream('test.txt');21file.write('hello world');22file.end();23ladleInstance.files('test.txt');24ladleInstance.end();25const ladle = require('ladle');26const fs = require('fs');27const ladleInstance = ladle.createLadle();28const file = fs.createWriteStream('test.txt');29file.write('hello world');30file.end();31ladleInstance.files('test.txt');32ladleInstance.end();
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!