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 @@ ...@@ -2,31 +2,22 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
/**
* @param {DialogType} dialogType class AppStateController {
* @constructor
* @struct
*/
function AppStateController(dialogType) {
/** /**
* @const {string} * @param {DialogType} dialogType
* @private
*/ */
constructor(dialogType) {
/** @private @const {string} */
this.viewOptionStorageKey_ = 'file-manager-' + dialogType; this.viewOptionStorageKey_ = 'file-manager-' + dialogType;
/** @private {DirectoryModel} */ /** @private {?DirectoryModel} */
this.directoryModel_ = null; this.directoryModel_ = null;
/** /** @private {?FileManagerUI} */
* @type {FileManagerUI}
* @private
*/
this.ui_ = null; this.ui_ = null;
/** /** @private {*} */
* @type {*}
* @private
*/
this.viewOptions_ = null; this.viewOptions_ = null;
/** /**
...@@ -42,24 +33,12 @@ function AppStateController(dialogType) { ...@@ -42,24 +33,12 @@ function AppStateController(dialogType) {
* @private {string} * @private {string}
*/ */
this.fileListSortDirection_ = AppStateController.DEFAULT_SORT_DIRECTION; 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} * @return {Promise}
*/ */
AppStateController.prototype.loadInitialViewOptions = function() { loadInitialViewOptions() {
// Load initial view option. // Load initial view option.
return new Promise((fulfill, reject) => { return new Promise((fulfill, reject) => {
chrome.storage.local.get(this.viewOptionStorageKey_, values => { chrome.storage.local.get(this.viewOptionStorageKey_, values => {
...@@ -98,13 +77,13 @@ AppStateController.prototype.loadInitialViewOptions = function() { ...@@ -98,13 +77,13 @@ AppStateController.prototype.loadInitialViewOptions = function() {
this.viewOptions_ = {}; this.viewOptions_ = {};
console.error(error); console.error(error);
}); });
}; }
/** /**
* @param {!FileManagerUI} ui * @param {!FileManagerUI} ui
* @param {!DirectoryModel} directoryModel * @param {!DirectoryModel} directoryModel
*/ */
AppStateController.prototype.initialize = function(ui, directoryModel) { initialize(ui, directoryModel) {
assert(this.viewOptions_); assert(this.viewOptions_);
this.ui_ = ui; this.ui_ = ui;
...@@ -138,12 +117,12 @@ AppStateController.prototype.initialize = function(ui, directoryModel) { ...@@ -138,12 +117,12 @@ AppStateController.prototype.initialize = function(ui, directoryModel) {
this.ui_.listContainer.table.columnModel.restoreColumnConfig( this.ui_.listContainer.table.columnModel.restoreColumnConfig(
this.viewOptions_.columnConfig); this.viewOptions_.columnConfig);
} }
}; }
/** /**
* Saves current view option. * Saves current view option.
*/ */
AppStateController.prototype.saveViewOptions = function() { saveViewOptions() {
const prefs = { const prefs = {
sortField: this.fileListSortField_, sortField: this.fileListSortField_,
sortDirection: this.fileListSortDirection_, sortDirection: this.fileListSortDirection_,
...@@ -169,12 +148,12 @@ AppStateController.prototype.saveViewOptions = function() { ...@@ -169,12 +148,12 @@ AppStateController.prototype.saveViewOptions = function() {
window.appState.viewOptions = prefs; window.appState.viewOptions = prefs;
appUtil.saveAppState(); appUtil.saveAppState();
} }
}; }
/** /**
* @private * @private
*/ */
AppStateController.prototype.onFileListSorted_ = function() { onFileListSorted_() {
const currentDirectory = this.directoryModel_.getCurrentDirEntry(); const currentDirectory = this.directoryModel_.getCurrentDirEntry();
if (!currentDirectory) { if (!currentDirectory) {
return; return;
...@@ -188,12 +167,12 @@ AppStateController.prototype.onFileListSorted_ = function() { ...@@ -188,12 +167,12 @@ AppStateController.prototype.onFileListSorted_ = function() {
this.fileListSortDirection_ = currentSortStatus.direction; this.fileListSortDirection_ = currentSortStatus.direction;
} }
this.saveViewOptions(); this.saveViewOptions();
}; }
/** /**
* @private * @private
*/ */
AppStateController.prototype.onFileFilterChanged_ = function() { onFileFilterChanged_() {
const isAllAndroidFoldersVisible = const isAllAndroidFoldersVisible =
this.directoryModel_.getFileFilter().isAllAndroidFoldersVisible(); this.directoryModel_.getFileFilter().isAllAndroidFoldersVisible();
if (this.viewOptions_.isAllAndroidFoldersVisible !== if (this.viewOptions_.isAllAndroidFoldersVisible !==
...@@ -201,13 +180,13 @@ AppStateController.prototype.onFileFilterChanged_ = function() { ...@@ -201,13 +180,13 @@ AppStateController.prototype.onFileFilterChanged_ = function() {
this.viewOptions_.isAllAndroidFoldersVisible = isAllAndroidFoldersVisible; this.viewOptions_.isAllAndroidFoldersVisible = isAllAndroidFoldersVisible;
this.saveViewOptions(); this.saveViewOptions();
} }
}; }
/** /**
* @param {Event} event * @param {Event} event
* @private * @private
*/ */
AppStateController.prototype.onDirectoryChanged_ = function(event) { onDirectoryChanged_(event) {
if (!event.newDirEntry) { if (!event.newDirEntry) {
return; return;
} }
...@@ -235,4 +214,17 @@ AppStateController.prototype.onDirectoryChanged_ = function(event) { ...@@ -235,4 +214,17 @@ AppStateController.prototype.onDirectoryChanged_ = function(event) {
this.directoryModel_.getCurrentDirEntry().toURL() : this.directoryModel_.getCurrentDirEntry().toURL() :
'', '',
'' /* selectionURL */, '' /* opt_param */); '' /* 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