Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(342)

Side by Side Diff: ui/file_manager/file_manager/foreground/js/metadata_box_controller.js

Issue 2313763003: Show a local folder's size in QuickView. (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * Controller of metadata box. 6 * Controller of metadata box.
7 * 7 *
8 * @param{!MetadataModel} metadataModel 8 * @param{!MetadataModel} metadataModel
9 * @param{!FilesMetadataBox} metadataBox 9 * @param{!FilesMetadataBox} metadataBox
10 * @param{!FilesQuickView} quickView 10 * @param{!FilesQuickView} quickView
(...skipping 22 matching lines...) Expand all
33 * @private 33 * @private
34 */ 34 */
35 this.quickView_ = quickView; 35 this.quickView_ = quickView;
36 36
37 /** 37 /**
38 * @type {!FileMetadataFormatter} 38 * @type {!FileMetadataFormatter}
39 * @private 39 * @private
40 */ 40 */
41 this.fileMetadataFormatter_ = fileMetadataFormatter; 41 this.fileMetadataFormatter_ = fileMetadataFormatter;
42 42
43 /**
44 * @type {Promise.<number>}
fukino 2016/09/06 09:12:45 We don't need '.'. Use Promise<number>
harukam 2016/09/06 11:25:24 Acknowledged.
45 * @private
46 */
47 this.directorySizePromise_ = null;
48
43 // TODO(oka): Add storage to persist the value of 49 // TODO(oka): Add storage to persist the value of
44 // quickViewModel_.metadataBoxActive. 50 // quickViewModel_.metadataBoxActive.
45 /** 51 /**
46 * @type {!QuickViewModel} 52 * @type {!QuickViewModel}
47 * @private 53 * @private
48 */ 54 */
49 this.quickViewModel_ = quickViewModel; 55 this.quickViewModel_ = quickViewModel;
50 56
51 fileMetadataFormatter.addEventListener( 57 fileMetadataFormatter.addEventListener(
52 'date-time-format-changed', this.updateView_.bind(this)); 58 'date-time-format-changed', this.updateView_.bind(this));
(...skipping 30 matching lines...) Expand all
83 .get( 89 .get(
84 [entry], MetadataBoxController.GENERAL_METADATA_NAME.concat( 90 [entry], MetadataBoxController.GENERAL_METADATA_NAME.concat(
85 ['hosted', 'externalFileUrl'])) 91 ['hosted', 'externalFileUrl']))
86 .then(this.onGeneralMetadataLoaded_.bind(this, entry)); 92 .then(this.onGeneralMetadataLoaded_.bind(this, entry));
87 }; 93 };
88 94
89 /** 95 /**
90 * Update metadata box with general file information. 96 * Update metadata box with general file information.
91 * Then retrieve file specific metadata if any. 97 * Then retrieve file specific metadata if any.
92 * 98 *
93 * @param {!FileEntry} entry 99 * @param {!Entry} entry
94 * @param {!Array<!MetadataItem>} items 100 * @param {!Array<!MetadataItem>} items
95 * 101 *
96 * @private 102 * @private
97 */ 103 */
98 MetadataBoxController.prototype.onGeneralMetadataLoaded_ = function( 104 MetadataBoxController.prototype.onGeneralMetadataLoaded_ = function(
99 entry, items) { 105 entry, items) {
100 var type = FileType.getType(entry).type; 106 var type = FileType.getType(entry).type;
101 var item = items[0]; 107 var item = items[0];
102 108
103 this.metadataBox_.type = type; 109 this.metadataBox_.type = type;
104 if (item.size) { 110 if (item.size) {
105 this.metadataBox_.size = 111 this.metadataBox_.size =
106 this.fileMetadataFormatter_.formatSize(item.size, item.hosted); 112 this.fileMetadataFormatter_.formatSize(item.size, item.hosted);
107 } 113 }
114 if (entry.isDirectory) {
115 this.setDirectorySize_(new Promise(function(resolve, reject) {
fukino 2016/09/06 09:12:45 I think it is better to simply call this.setDirect
harukam 2016/09/06 11:25:24 OK. Thanks.
116 chrome.fileManagerPrivate.getDirectorySize(
117 /** @type {!DirectoryEntry} */ (entry),
118 function(size) {
119 if(chrome.runtime.lastError)
120 reject();
121 else
122 resolve(size);
123 });
124 }));
125 }
108 if (item.modificationTime) { 126 if (item.modificationTime) {
109 this.metadataBox_.modificationTime = 127 this.metadataBox_.modificationTime =
110 this.fileMetadataFormatter_.formatModDate(item.modificationTime); 128 this.fileMetadataFormatter_.formatModDate(item.modificationTime);
111 } 129 }
112 130
113 if (item.externalFileUrl) { 131 if (item.externalFileUrl) {
114 this.metadataModel_.get([entry], ['contentMimeType']).then(function(items) { 132 this.metadataModel_.get([entry], ['contentMimeType']).then(function(items) {
115 var item = items[0]; 133 var item = items[0];
116 this.metadataBox_.mediaMimeType = item.contentMimeType; 134 this.metadataBox_.mediaMimeType = item.contentMimeType;
117 }.bind(this)); 135 }.bind(this));
(...skipping 22 matching lines...) Expand all
140 .then(function(items) { 158 .then(function(items) {
141 var item = items[0]; 159 var item = items[0];
142 this.metadataBox_.imageHeight = item.imageHeight; 160 this.metadataBox_.imageHeight = item.imageHeight;
143 this.metadataBox_.imageWidth = item.imageWidth; 161 this.metadataBox_.imageWidth = item.imageWidth;
144 this.metadataBox_.mediaArtist = item.mediaArtist; 162 this.metadataBox_.mediaArtist = item.mediaArtist;
145 this.metadataBox_.mediaTitle = item.mediaTitle; 163 this.metadataBox_.mediaTitle = item.mediaTitle;
146 }.bind(this)); 164 }.bind(this));
147 } 165 }
148 } 166 }
149 }; 167 };
168
169 /**
170 * Set a directory size in metadata box.
171 *
172 * @param {Promise.<number>} directorySizePromise
173 *
174 * @private
175 */
176 MetadataBoxController.prototype.setDirectorySize_ = function(
177 directorySizePromise) {
178 this.directorySizePromise_ = directorySizePromise;
fukino 2016/09/06 09:12:45 If you avoid showing the size of the wrong entry,
harukam 2016/09/06 11:25:24 Acknowledged.
179 if (!directorySizePromise)
180 return;
181
182 this.metadataBox_.setLoading(true);
183 directorySizePromise.then(function(size) {
184 if(this.directorySizePromise_ != directorySizePromise)
185 return;
186 this.metadataBox_.setLoading(false);
187 this.metadataBox_.size =
188 this.fileMetadataFormatter_.formatSize(size, true);
189 }.bind(this)).catch(function(error) {
190 if(this.directorySizePromise_ != directorySizePromise)
191 return;
192 this.metadataBox_.setLoading(false);
193 }.bind(this));
194 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698