Commit b0685e16 authored by Luciano Pacheco's avatar Luciano Pacheco Committed by Commit Bot

Files app: ES6 class empty_folder_controller.js, navigation_uma.js and 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: default avatarNoel Gordon <noel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#688487}
parent 20c58415
...@@ -4,111 +4,113 @@ ...@@ -4,111 +4,113 @@
/** /**
* Empty folder controller. * 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; onScanFinished_() {
this.isScanning_ = false;
this.directoryModel_.addEventListener( this.update_();
'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);
} }
this.update_();
};
/** /**
* Handles scan finish. * Updates visibility of empty folder UI.
* @private * @private
*/ */
EmptyFolderController.prototype.onScanFinished_ = function() { update_() {
this.isScanning_ = false; if (!this.isScanning_ && this.dataModel_.length === 0) {
this.update_(); const query = this.directoryModel_.getLastSearchQuery();
}; let html = '';
if (query) {
html = strf('SEARCH_NO_MATCHING_FILES_HTML', util.htmlEscape(query));
} else {
html = str('EMPTY_FOLDER');
}
/** this.emptyFolder_.setMessage(html);
* Updates visibility of empty folder UI. this.emptyFolder_.show();
* @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));
} else { } else {
html = str('EMPTY_FOLDER'); this.emptyFolder_.hide();
} }
this.emptyFolder_.setMessage(html);
this.emptyFolder_.show();
} else {
this.emptyFolder_.hide();
} }
}; }
...@@ -10,79 +10,80 @@ ...@@ -10,79 +10,80 @@
*/ */
let SuggestAppDialogState; let SuggestAppDialogState;
/** class LaunchParam {
* @param {!Object} unformatted Unformatted option.
* @constructor
* @struct
*/
function LaunchParam(unformatted) {
/** /**
* @type {DialogType} * @param {!Object} unformatted Unformatted option.
* @const
*/ */
this.type = unformatted['type'] || DialogType.FULL_PAGE; constructor(unformatted) {
/**
* @type {DialogType}
* @const
*/
this.type = unformatted['type'] || DialogType.FULL_PAGE;
/** /**
* @type {string} * @type {string}
* @const * @const
*/ */
this.action = unformatted['action'] ? unformatted['action'] : ''; this.action = unformatted['action'] ? unformatted['action'] : '';
/** /**
* @type {string} * @type {string}
* @const * @const
*/ */
this.currentDirectoryURL = unformatted['currentDirectoryURL'] ? this.currentDirectoryURL = unformatted['currentDirectoryURL'] ?
unformatted['currentDirectoryURL'] : unformatted['currentDirectoryURL'] :
''; '';
/** /**
* @type {string} * @type {string}
* @const * @const
*/ */
this.selectionURL = this.selectionURL =
unformatted['selectionURL'] ? unformatted['selectionURL'] : ''; unformatted['selectionURL'] ? unformatted['selectionURL'] : '';
/** /**
* @type {string} * @type {string}
* @const * @const
*/ */
this.targetName = unformatted['targetName'] ? unformatted['targetName'] : ''; this.targetName =
unformatted['targetName'] ? unformatted['targetName'] : '';
/** /**
* @type {!Array<!Object>} * @type {!Array<!Object>}
* @const * @const
*/ */
this.typeList = unformatted['typeList'] ? unformatted['typeList'] : []; this.typeList = unformatted['typeList'] ? unformatted['typeList'] : [];
/** /**
* @type {boolean} * @type {boolean}
* @const * @const
*/ */
this.includeAllFiles = !!unformatted['includeAllFiles']; this.includeAllFiles = !!unformatted['includeAllFiles'];
/** /**
* @type {!AllowedPaths} * @type {!AllowedPaths}
* @const * @const
*/ */
this.allowedPaths = unformatted['allowedPaths'] ? this.allowedPaths = unformatted['allowedPaths'] ?
unformatted['allowedPaths'] : unformatted['allowedPaths'] :
AllowedPaths.ANY_PATH_OR_URL; AllowedPaths.ANY_PATH_OR_URL;
/** /**
* @type {!SuggestAppDialogState} * @type {!SuggestAppDialogState}
* @const * @const
*/ */
this.suggestAppsDialogState = unformatted['suggestAppsDialogState'] ? this.suggestAppsDialogState = unformatted['suggestAppsDialogState'] ?
unformatted['suggestAppsDialogState'] : unformatted['suggestAppsDialogState'] :
{ {
overrideCwsContainerUrlForTest: '', overrideCwsContainerUrlForTest: '',
overrideCwsContainerOriginForTest: '' overrideCwsContainerOriginForTest: ''
}; };
/** /**
* @type {boolean} * @type {boolean}
* @const * @const
*/ */
this.showAndroidPickerApps = !!unformatted['showAndroidPickerApps']; this.showAndroidPickerApps = !!unformatted['showAndroidPickerApps'];
}
} }
...@@ -5,39 +5,42 @@ ...@@ -5,39 +5,42 @@
/** /**
* UMA exporter for navigation in the Files app. * UMA exporter for navigation in the Files app.
* *
* @param {!VolumeManager} volumeManager
*
* @constructor
*/ */
function NavigationUma(volumeManager) { class NavigationUma {
/** /**
* @type {!VolumeManager} * @param {!VolumeManager} volumeManager
* @private *
*/ */
this.volumeManager_ = volumeManager; constructor(volumeManager) {
} /**
* @type {!VolumeManager}
* @private
*/
this.volumeManager_ = volumeManager;
}
/** /**
* Exports file type metric with the given |name|. * Exports file type metric with the given |name|.
* *
* @param {!FileEntry} entry * @param {!FileEntry} entry
* @param {string} name The histogram name. * @param {string} name The histogram name.
* *
* @private * @private
*/ */
NavigationUma.prototype.exportRootType_ = function(entry, name) { exportRootType_(entry, name) {
const locationInfo = this.volumeManager_.getLocationInfo(entry); const locationInfo = this.volumeManager_.getLocationInfo(entry);
if (locationInfo) { if (locationInfo) {
metrics.recordEnum( metrics.recordEnum(
name, locationInfo.rootType, VolumeManagerCommon.RootTypesForUMA); name, locationInfo.rootType, VolumeManagerCommon.RootTypesForUMA);
}
} }
};
/** /**
* Exports UMA based on the entry that has became new current directory. * Exports UMA based on the entry that has became new current directory.
* *
* @param {!FileEntry} entry the new directory * @param {!FileEntry} entry the new directory
*/ */
NavigationUma.prototype.onDirectoryChanged = function(entry) { onDirectoryChanged(entry) {
this.exportRootType_(entry, 'ChangeDirectory.RootType'); this.exportRootType_(entry, 'ChangeDirectory.RootType');
}; }
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment