Commit 5f91a2f8 authored by François Degros's avatar François Degros Committed by Commit Bot

[Files app] ES6 class for app_state_controller.js

Bug: 778674
Change-Id: I59a4674bc7e0675686271308795e07866b3eef96
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1609722
Auto-Submit: François Degros <fdegros@chromium.org>
Commit-Queue: Luciano Pacheco <lucmult@chromium.org>
Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Cr-Commit-Position: refs/heads/master@{#659375}
parent dd4bd386
......@@ -2,31 +2,22 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @param {DialogType} dialogType
* @constructor
* @struct
*/
function AppStateController(dialogType) {
class AppStateController {
/**
* @const {string}
* @private
* @param {DialogType} dialogType
*/
constructor(dialogType) {
/** @private @const {string} */
this.viewOptionStorageKey_ = 'file-manager-' + dialogType;
/** @private {DirectoryModel} */
/** @private {?DirectoryModel} */
this.directoryModel_ = null;
/**
* @type {FileManagerUI}
* @private
*/
/** @private {?FileManagerUI} */
this.ui_ = null;
/**
* @type {*}
* @private
*/
/** @private {*} */
this.viewOptions_ = null;
/**
......@@ -42,24 +33,12 @@ function AppStateController(dialogType) {
* @private {string}
*/
this.fileListSortDirection_ = AppStateController.DEFAULT_SORT_DIRECTION;
}
/**
* Default sort field of the file list.
* @const {string}
*/
AppStateController.DEFAULT_SORT_FIELD = 'modificationTime';
/**
* Default sort direction of the file list.
* @const {string}
*/
AppStateController.DEFAULT_SORT_DIRECTION = 'desc';
}
/**
/**
* @return {Promise}
*/
AppStateController.prototype.loadInitialViewOptions = function() {
loadInitialViewOptions() {
// Load initial view option.
return new Promise((fulfill, reject) => {
chrome.storage.local.get(this.viewOptionStorageKey_, values => {
......@@ -98,13 +77,13 @@ AppStateController.prototype.loadInitialViewOptions = function() {
this.viewOptions_ = {};
console.error(error);
});
};
}
/**
/**
* @param {!FileManagerUI} ui
* @param {!DirectoryModel} directoryModel
*/
AppStateController.prototype.initialize = function(ui, directoryModel) {
initialize(ui, directoryModel) {
assert(this.viewOptions_);
this.ui_ = ui;
......@@ -138,12 +117,12 @@ AppStateController.prototype.initialize = function(ui, directoryModel) {
this.ui_.listContainer.table.columnModel.restoreColumnConfig(
this.viewOptions_.columnConfig);
}
};
}
/**
/**
* Saves current view option.
*/
AppStateController.prototype.saveViewOptions = function() {
saveViewOptions() {
const prefs = {
sortField: this.fileListSortField_,
sortDirection: this.fileListSortDirection_,
......@@ -169,12 +148,12 @@ AppStateController.prototype.saveViewOptions = function() {
window.appState.viewOptions = prefs;
appUtil.saveAppState();
}
};
}
/**
/**
* @private
*/
AppStateController.prototype.onFileListSorted_ = function() {
onFileListSorted_() {
const currentDirectory = this.directoryModel_.getCurrentDirEntry();
if (!currentDirectory) {
return;
......@@ -188,12 +167,12 @@ AppStateController.prototype.onFileListSorted_ = function() {
this.fileListSortDirection_ = currentSortStatus.direction;
}
this.saveViewOptions();
};
}
/**
/**
* @private
*/
AppStateController.prototype.onFileFilterChanged_ = function() {
onFileFilterChanged_() {
const isAllAndroidFoldersVisible =
this.directoryModel_.getFileFilter().isAllAndroidFoldersVisible();
if (this.viewOptions_.isAllAndroidFoldersVisible !==
......@@ -201,13 +180,13 @@ AppStateController.prototype.onFileFilterChanged_ = function() {
this.viewOptions_.isAllAndroidFoldersVisible = isAllAndroidFoldersVisible;
this.saveViewOptions();
}
};
}
/**
/**
* @param {Event} event
* @private
*/
AppStateController.prototype.onDirectoryChanged_ = function(event) {
onDirectoryChanged_(event) {
if (!event.newDirEntry) {
return;
}
......@@ -235,4 +214,17 @@ AppStateController.prototype.onDirectoryChanged_ = function(event) {
this.directoryModel_.getCurrentDirEntry().toURL() :
'',
'' /* selectionURL */, '' /* opt_param */);
};
}
}
/**
* Default sort field of the file list.
* @const {string}
*/
AppStateController.DEFAULT_SORT_FIELD = 'modificationTime';
/**
* Default sort direction of the file list.
* @const {string}
*/
AppStateController.DEFAULT_SORT_DIRECTION = 'desc';
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