Skip to content

Commit

Permalink
Files app: ES6 class empty_folder_controller.js, navigation_uma.js an…
Browse files Browse the repository at this point in the history
…d launch_param.js

Bug: 778674
Change-Id: Iab56d84cf26975f9c476680d74037a9088ec1c78
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1760837
Auto-Submit: Luciano Pacheco <lucmult@chromium.org>
Commit-Queue: Noel Gordon <noel@chromium.org>
Reviewed-by: Noel Gordon <noel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#688487}
  • Loading branch information
Luciano Pacheco authored and Commit Bot committed Aug 20, 2019
1 parent 20c5841 commit b0685e1
Show file tree
Hide file tree
Showing 3 changed files with 187 additions and 181 deletions.
176 changes: 89 additions & 87 deletions ui/file_manager/file_manager/foreground/js/empty_folder_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,111 +4,113 @@

/**
* Empty folder controller.
* @param {!EmptyFolder} emptyFolder Empty folder ui.
* @param {!DirectoryModel} directoryModel Directory model.
* @param {!FilesAlertDialog} alertDialog Alert dialog.
* @constructor
* @struct
*/
function EmptyFolderController(emptyFolder, directoryModel, alertDialog) {
class EmptyFolderController {
/**
* @private {!EmptyFolder}
* @param {!EmptyFolder} emptyFolder Empty folder ui.
* @param {!DirectoryModel} directoryModel Directory model.
* @param {!FilesAlertDialog} alertDialog Alert dialog.
*/
this.emptyFolder_ = emptyFolder;
constructor(emptyFolder, directoryModel, alertDialog) {
/**
* @private {!EmptyFolder}
*/
this.emptyFolder_ = emptyFolder;

/**
* @private {!DirectoryModel}
*/
this.directoryModel_ = directoryModel;

/**
* @private {!FilesAlertDialog}
*/
this.alertDialog_ = alertDialog;

/**
* @private {!FileListModel}
*/
this.dataModel_ = assert(this.directoryModel_.getFileList());

/**
* @private {boolean}
*/
this.isScanning_ = false;

this.directoryModel_.addEventListener(
'scan-started', this.onScanStarted_.bind(this));
this.directoryModel_.addEventListener(
'scan-failed', this.onScanFailed_.bind(this));
this.directoryModel_.addEventListener(
'scan-cancelled', this.onScanFinished_.bind(this));
this.directoryModel_.addEventListener(
'scan-completed', this.onScanFinished_.bind(this));
this.directoryModel_.addEventListener(
'rescan-completed', this.onScanFinished_.bind(this));

this.dataModel_.addEventListener('splice', this.onSplice_.bind(this));
}

/**
* @private {!DirectoryModel}
* Handles splice event.
* @private
*/
this.directoryModel_ = directoryModel;
onSplice_() {
this.update_();
}

/**
* @private {!FilesAlertDialog}
* Handles scan start.
* @private
*/
this.alertDialog_ = alertDialog;
onScanStarted_() {
this.isScanning_ = true;
this.update_();
}

/**
* @private {!FileListModel}
* Handles scan fail.
* @param {Event} event Event may contain error field containing DOMError for
* alert.
* @private
*/
this.dataModel_ = assert(this.directoryModel_.getFileList());
onScanFailed_(event) {
this.isScanning_ = false;
// Show alert for crostini connection error.
if (event.error.name == DirectoryModel.CROSTINI_CONNECT_ERR) {
this.alertDialog_.showWithTitle(
str('ERROR_LINUX_FILES_CONNECTION'), event.error.message);
}
this.update_();
}

/**
* @private {boolean}
* Handles scan finish.
* @private
*/
this.isScanning_ = false;

this.directoryModel_.addEventListener(
'scan-started', this.onScanStarted_.bind(this));
this.directoryModel_.addEventListener(
'scan-failed', this.onScanFailed_.bind(this));
this.directoryModel_.addEventListener(
'scan-cancelled', this.onScanFinished_.bind(this));
this.directoryModel_.addEventListener(
'scan-completed', this.onScanFinished_.bind(this));
this.directoryModel_.addEventListener(
'rescan-completed', this.onScanFinished_.bind(this));

this.dataModel_.addEventListener('splice', this.onSplice_.bind(this));
}

/**
* Handles splice event.
* @private
*/
EmptyFolderController.prototype.onSplice_ = function() {
this.update_();
};

/**
* Handles scan start.
* @private
*/
EmptyFolderController.prototype.onScanStarted_ = function() {
this.isScanning_ = true;
this.update_();
};

/**
* Handles scan fail.
* @param {Event} event Event may contain error field containing DOMError for
* alert.
* @private
*/
EmptyFolderController.prototype.onScanFailed_ = function(event) {
this.isScanning_ = false;
// Show alert for crostini connection error.
if (event.error.name == DirectoryModel.CROSTINI_CONNECT_ERR) {
this.alertDialog_.showWithTitle(
str('ERROR_LINUX_FILES_CONNECTION'), event.error.message);
onScanFinished_() {
this.isScanning_ = false;
this.update_();
}
this.update_();
};

/**
* Handles scan finish.
* @private
*/
EmptyFolderController.prototype.onScanFinished_ = function() {
this.isScanning_ = false;
this.update_();
};
/**
* Updates visibility of empty folder UI.
* @private
*/
update_() {
if (!this.isScanning_ && this.dataModel_.length === 0) {
const query = this.directoryModel_.getLastSearchQuery();
let html = '';
if (query) {
html = strf('SEARCH_NO_MATCHING_FILES_HTML', util.htmlEscape(query));
} else {
html = str('EMPTY_FOLDER');
}

/**
* Updates visibility of empty folder UI.
* @private
*/
EmptyFolderController.prototype.update_ = function() {
if (!this.isScanning_ && this.dataModel_.length === 0) {
const query = this.directoryModel_.getLastSearchQuery();
let html = '';
if (query) {
html = strf('SEARCH_NO_MATCHING_FILES_HTML', util.htmlEscape(query));
this.emptyFolder_.setMessage(html);
this.emptyFolder_.show();
} else {
html = str('EMPTY_FOLDER');
this.emptyFolder_.hide();
}

this.emptyFolder_.setMessage(html);
this.emptyFolder_.show();
} else {
this.emptyFolder_.hide();
}
};
}
129 changes: 65 additions & 64 deletions ui/file_manager/file_manager/foreground/js/launch_param.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,79 +10,80 @@
*/
let SuggestAppDialogState;

/**
* @param {!Object} unformatted Unformatted option.
* @constructor
* @struct
*/
function LaunchParam(unformatted) {
class LaunchParam {
/**
* @type {DialogType}
* @const
* @param {!Object} unformatted Unformatted option.
*/
this.type = unformatted['type'] || DialogType.FULL_PAGE;
constructor(unformatted) {
/**
* @type {DialogType}
* @const
*/
this.type = unformatted['type'] || DialogType.FULL_PAGE;

/**
* @type {string}
* @const
*/
this.action = unformatted['action'] ? unformatted['action'] : '';
/**
* @type {string}
* @const
*/
this.action = unformatted['action'] ? unformatted['action'] : '';

/**
* @type {string}
* @const
*/
this.currentDirectoryURL = unformatted['currentDirectoryURL'] ?
unformatted['currentDirectoryURL'] :
'';
/**
* @type {string}
* @const
*/
this.currentDirectoryURL = unformatted['currentDirectoryURL'] ?
unformatted['currentDirectoryURL'] :
'';

/**
* @type {string}
* @const
*/
this.selectionURL =
unformatted['selectionURL'] ? unformatted['selectionURL'] : '';
/**
* @type {string}
* @const
*/
this.selectionURL =
unformatted['selectionURL'] ? unformatted['selectionURL'] : '';

/**
* @type {string}
* @const
*/
this.targetName = unformatted['targetName'] ? unformatted['targetName'] : '';
/**
* @type {string}
* @const
*/
this.targetName =
unformatted['targetName'] ? unformatted['targetName'] : '';

/**
* @type {!Array<!Object>}
* @const
*/
this.typeList = unformatted['typeList'] ? unformatted['typeList'] : [];
/**
* @type {!Array<!Object>}
* @const
*/
this.typeList = unformatted['typeList'] ? unformatted['typeList'] : [];

/**
* @type {boolean}
* @const
*/
this.includeAllFiles = !!unformatted['includeAllFiles'];
/**
* @type {boolean}
* @const
*/
this.includeAllFiles = !!unformatted['includeAllFiles'];

/**
* @type {!AllowedPaths}
* @const
*/
this.allowedPaths = unformatted['allowedPaths'] ?
unformatted['allowedPaths'] :
AllowedPaths.ANY_PATH_OR_URL;
/**
* @type {!AllowedPaths}
* @const
*/
this.allowedPaths = unformatted['allowedPaths'] ?
unformatted['allowedPaths'] :
AllowedPaths.ANY_PATH_OR_URL;

/**
* @type {!SuggestAppDialogState}
* @const
*/
this.suggestAppsDialogState = unformatted['suggestAppsDialogState'] ?
unformatted['suggestAppsDialogState'] :
{
overrideCwsContainerUrlForTest: '',
overrideCwsContainerOriginForTest: ''
};
/**
* @type {!SuggestAppDialogState}
* @const
*/
this.suggestAppsDialogState = unformatted['suggestAppsDialogState'] ?
unformatted['suggestAppsDialogState'] :
{
overrideCwsContainerUrlForTest: '',
overrideCwsContainerOriginForTest: ''
};

/**
* @type {boolean}
* @const
*/
this.showAndroidPickerApps = !!unformatted['showAndroidPickerApps'];
/**
* @type {boolean}
* @const
*/
this.showAndroidPickerApps = !!unformatted['showAndroidPickerApps'];
}
}
Loading

0 comments on commit b0685e1

Please sign in to comment.