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

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

Issue 840863004: Files.app: Add a new column in table view to reflect cloud import status. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync to master. Created 5 years, 11 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 * Namespace for utility functions. 6 * Namespace for utility functions.
7 */ 7 */
8 var filelist = {}; 8 var filelist = {};
9 9
10 /** 10 /**
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 }; 110 };
111 111
112 /** 112 /**
113 * Initialize columnPos_ which is used in setWidthAndKeepTotal(). 113 * Initialize columnPos_ which is used in setWidthAndKeepTotal().
114 */ 114 */
115 FileTableColumnModel.prototype.initializeColumnPos = function() { 115 FileTableColumnModel.prototype.initializeColumnPos = function() {
116 this.columnPos_ = [0]; 116 this.columnPos_ = [0];
117 for (var i = 0; i < this.columns_.length; i++) { 117 for (var i = 0; i < this.columns_.length; i++) {
118 this.columnPos_[i + 1] = this.columns_[i].width + this.columnPos_[i]; 118 this.columnPos_[i + 1] = this.columns_[i].width + this.columnPos_[i];
119 } 119 }
120 } 120 };
121 121
122 /** 122 /**
123 * Destroy columnPos_ which is used in setWidthAndKeepTotal(). 123 * Destroy columnPos_ which is used in setWidthAndKeepTotal().
124 */ 124 */
125 FileTableColumnModel.prototype.destroyColumnPos = function() { 125 FileTableColumnModel.prototype.destroyColumnPos = function() {
126 this.columnPos_ = null; 126 this.columnPos_ = null;
127 } 127 };
128 128
129 /** 129 /**
130 * Sets the width of column with keeping the total width of table. 130 * Sets the width of column with keeping the total width of table.
131 * Before and after calling this method, you must initialize and destroy 131 * Before and after calling this method, you must initialize and destroy
132 * columnPos with initializeColumnPos() and destroyColumnPos(). 132 * columnPos with initializeColumnPos() and destroyColumnPos().
133 * @param {number} columnIndex Index of column that is resized. 133 * @param {number} columnIndex Index of column that is resized.
134 * @param {number} columnWidth New width of the column. 134 * @param {number} columnWidth New width of the column.
135 */ 135 */
136 FileTableColumnModel.prototype.setWidthAndKeepTotal = function( 136 FileTableColumnModel.prototype.setWidthAndKeepTotal = function(
137 columnIndex, columnWidth) { 137 columnIndex, columnWidth) {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 /** 234 /**
235 * Inherits from cr.ui.Table. 235 * Inherits from cr.ui.Table.
236 */ 236 */
237 FileTable.prototype.__proto__ = cr.ui.Table.prototype; 237 FileTable.prototype.__proto__ = cr.ui.Table.prototype;
238 238
239 /** 239 /**
240 * Decorates the element. 240 * Decorates the element.
241 * @param {!Element} self Table to decorate. 241 * @param {!Element} self Table to decorate.
242 * @param {MetadataCache} metadataCache To retrieve metadata. 242 * @param {MetadataCache} metadataCache To retrieve metadata.
243 * @param {VolumeManagerWrapper} volumeManager To retrieve volume info. 243 * @param {VolumeManagerWrapper} volumeManager To retrieve volume info.
244 * @param {!importer.HistoryLoader} historyLoader
244 * @param {boolean} fullPage True if it's full page File Manager, 245 * @param {boolean} fullPage True if it's full page File Manager,
245 * False if a file open/save dialog. 246 * False if a file open/save dialog.
246 */ 247 */
247 FileTable.decorate = function(self, metadataCache, volumeManager, fullPage) { 248 FileTable.decorate =
249 function(self, metadataCache, volumeManager, historyLoader, fullPage) {
248 cr.ui.Table.decorate(self); 250 cr.ui.Table.decorate(self);
249 self.__proto__ = FileTable.prototype; 251 self.__proto__ = FileTable.prototype;
250 self.metadataCache_ = metadataCache; 252 self.metadataCache_ = metadataCache;
251 self.volumeManager_ = volumeManager; 253 self.volumeManager_ = volumeManager;
254 self.historyLoader_ = historyLoader;
255
256 var nameColumn = new cr.ui.table.TableColumn(
257 'name', str('NAME_COLUMN_LABEL'), fullPage ? 386 : 324);
258 nameColumn.renderFunction = self.renderName_.bind(self);
259
260 var sizeColumn = new cr.ui.table.TableColumn(
261 'size', str('SIZE_COLUMN_LABEL'), 110, true);
262 sizeColumn.renderFunction = self.renderSize_.bind(self);
263 sizeColumn.defaultOrder = 'desc';
264
265 var statusColumn = new cr.ui.table.TableColumn(
266 'status', str('STATUS_COLUMN_LABEL'), 50, true);
267 statusColumn.renderFunction = self.renderStatus_.bind(self);
268
269 var typeColumn = new cr.ui.table.TableColumn(
270 'type', str('TYPE_COLUMN_LABEL'), fullPage ? 110 : 110);
271 typeColumn.renderFunction = self.renderType_.bind(self);
272
273 var modTimeColumn = new cr.ui.table.TableColumn(
274 'modificationTime', str('DATE_COLUMN_LABEL'), fullPage ? 150 : 210);
275 modTimeColumn.renderFunction = self.renderDate_.bind(self);
276 modTimeColumn.defaultOrder = 'desc';
252 277
253 var columns = [ 278 var columns = [
254 new cr.ui.table.TableColumn('name', str('NAME_COLUMN_LABEL'), 279 nameColumn,
255 fullPage ? 386 : 324), 280 sizeColumn,
256 new cr.ui.table.TableColumn('size', str('SIZE_COLUMN_LABEL'), 281 typeColumn,
257 110, true), 282 modTimeColumn
258 new cr.ui.table.TableColumn('type', str('TYPE_COLUMN_LABEL'),
259 fullPage ? 110 : 110),
260 new cr.ui.table.TableColumn('modificationTime',
261 str('DATE_COLUMN_LABEL'),
262 fullPage ? 150 : 210)
263 ]; 283 ];
264 284 // Display the status column only if cloud imports are enabled.
265 columns[0].renderFunction = self.renderName_.bind(self); 285 if (self.importEnabled) {
266 columns[1].renderFunction = self.renderSize_.bind(self); 286 columns.splice(2, 0, statusColumn);
267 columns[1].defaultOrder = 'desc'; 287 }
268 columns[2].renderFunction = self.renderType_.bind(self);
269 columns[3].renderFunction = self.renderDate_.bind(self);
270 columns[3].defaultOrder = 'desc';
271 288
272 var columnModel = new FileTableColumnModel(columns); 289 var columnModel = new FileTableColumnModel(columns);
273 290
274 self.columnModel = columnModel; 291 self.columnModel = columnModel;
275 self.setDateTimeFormat(true); 292 self.setDateTimeFormat(true);
276 self.setRenderFunction(self.renderTableRow_.bind(self, 293 self.setRenderFunction(self.renderTableRow_.bind(self,
277 self.getRenderFunction())); 294 self.getRenderFunction()));
278 295
279 self.scrollBar_ = new MainPanelScrollBar(); 296 self.scrollBar_ = new MainPanelScrollBar();
280 self.scrollBar_.initialize(self, self.list); 297 self.scrollBar_.initialize(self, self.list);
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 } else if (externalProps.hosted) { 527 } else if (externalProps.hosted) {
511 div.textContent = '--'; 528 div.textContent = '--';
512 return; 529 return;
513 } 530 }
514 } 531 }
515 532
516 div.textContent = util.bytesToString(filesystemProps.size); 533 div.textContent = util.bytesToString(filesystemProps.size);
517 }; 534 };
518 535
519 /** 536 /**
537 * Render the Status column of the detail table.
538 *
539 * @param {Entry} entry The Entry object to render.
540 * @param {string} columnId The id of the column to be rendered.
541 * @param {cr.ui.Table} table The table doing the rendering.
542 * @return {!HTMLDivElement} Created element.
543 * @private
544 */
545 FileTable.prototype.renderStatus_ = function(entry, columnId, table) {
546 var div = /** @type {!HTMLDivElement} */ (
547 this.ownerDocument.createElement('div'));
548 div.className = 'status status-icon';
549 if (entry) {
550 this.updateStatus_(div, entry);
551 }
552
553 return div;
554 };
555
556 /**
557 * Returns the status of the entry w.r.t. the given import destination.
558 * @param {Entry} entry
559 * @param {!importer.Destination} destination
560 * @return {!Promise<string>} The import status - will be 'imported', 'copied',
561 * or 'unknown'.
562 */
563 FileTable.prototype.getImportStatus_ = function(entry, destination) {
564 if (!entry.isFile) {
565 // Our import history doesn't deal with directories.
566 // TODO(kenobi): May need to revisit this if the above assumption changes.
567 return Promise.resolve('unknown');
568 }
569 // For the compiler.
570 var fileEntry = /** @type {!FileEntry} */ (entry);
571
572 return this.historyLoader_.getHistory()
573 .then(
574 /** @param {!importer.ImportHistory} history */
575 function(history) {
576 return Promise.all([
577 history.wasImported(fileEntry, destination),
578 history.wasCopied(fileEntry, destination)
579 ]);
580 })
581 .then(
582 /** @param {!Array<boolean>} status */
583 function(status) {
584 if (status[0]) {
585 return 'imported';
586 } else if (status[1]) {
587 return 'copied';
588 } else {
589 return 'unknown';
590 }
591 });
592 };
593
594 /**
595 * Render the status icon of the detail table.
596 *
597 * @param {HTMLDivElement} div
598 * @param {Entry} entry The Entry object to render.
599 * @private
600 */
601 FileTable.prototype.updateStatus_ = function(div, entry) {
602 this.getImportStatus_(entry, importer.Destination.GOOGLE_DRIVE).then(
603 /** @param {string} status */
604 function(status) {
605 div.setAttribute('file-status-icon', status);
606 });
607 };
608
609 /**
520 * Render the Type column of the detail table. 610 * Render the Type column of the detail table.
521 * 611 *
522 * @param {Entry} entry The Entry object to render. 612 * @param {Entry} entry The Entry object to render.
523 * @param {string} columnId The id of the column to be rendered. 613 * @param {string} columnId The id of the column to be rendered.
524 * @param {cr.ui.Table} table The table doing the rendering. 614 * @param {cr.ui.Table} table The table doing the rendering.
525 * @return {!HTMLDivElement} Created element. 615 * @return {!HTMLDivElement} Created element.
526 * @private 616 * @private
527 */ 617 */
528 FileTable.prototype.renderType_ = function(entry, columnId, table) { 618 FileTable.prototype.renderType_ = function(entry, columnId, table) {
529 var div = /** @type {!HTMLDivElement} */ 619 var div = /** @type {!HTMLDivElement} */
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 * Updates the file metadata in the table item. 685 * Updates the file metadata in the table item.
596 * 686 *
597 * @param {Element} item Table item. 687 * @param {Element} item Table item.
598 * @param {Entry} entry File entry. 688 * @param {Entry} entry File entry.
599 */ 689 */
600 FileTable.prototype.updateFileMetadata = function(item, entry) { 690 FileTable.prototype.updateFileMetadata = function(item, entry) {
601 this.updateDate_( 691 this.updateDate_(
602 /** @type {!HTMLDivElement} */ (item.querySelector('.date')), entry); 692 /** @type {!HTMLDivElement} */ (item.querySelector('.date')), entry);
603 this.updateSize_( 693 this.updateSize_(
604 /** @type {!HTMLDivElement} */ (item.querySelector('.size')), entry); 694 /** @type {!HTMLDivElement} */ (item.querySelector('.size')), entry);
695 this.updateStatus_(
696 /** @type {!HTMLDivElement} */ (item.querySelector('.status')), entry);
605 }; 697 };
606 698
607 /** 699 /**
608 * Updates list items 'in place' on metadata change. 700 * Updates list items 'in place' on metadata change.
609 * @param {string} type Type of metadata change. 701 * @param {string} type Type of metadata change.
610 * @param {Array.<Entry>} entries Entries to update. 702 * @param {Array.<Entry>} entries Entries to update.
611 */ 703 */
612 FileTable.prototype.updateListItemsMetadata = function(type, entries) { 704 FileTable.prototype.updateListItemsMetadata = function(type, entries) {
613 var urls = util.entriesToURLs(entries); 705 var urls = util.entriesToURLs(entries);
614 var forEachCell = function(selector, callback) { 706 var forEachCell = function(selector, callback) {
(...skipping 12 matching lines...) Expand all
627 }); 719 });
628 forEachCell('.table-row-cell > .size', function(item, entry, unused) { 720 forEachCell('.table-row-cell > .size', function(item, entry, unused) {
629 this.updateSize_(item, entry); 721 this.updateSize_(item, entry);
630 }); 722 });
631 } else if (type === 'external') { 723 } else if (type === 'external') {
632 // The cell name does not matter as the entire list item is needed. 724 // The cell name does not matter as the entire list item is needed.
633 forEachCell('.table-row-cell > .date', function(item, entry, listItem) { 725 forEachCell('.table-row-cell > .date', function(item, entry, listItem) {
634 var props = this.metadataCache_.getCached(entry, 'external'); 726 var props = this.metadataCache_.getCached(entry, 'external');
635 filelist.updateListItemExternalProps(listItem, props); 727 filelist.updateListItemExternalProps(listItem, props);
636 }); 728 });
729 } else if (type === 'import-history') {
730 forEachCell('.table-row-cell > .status', function(item, entry, unused) {
731 this.updateStatus_(item, entry);
732 });
637 } 733 }
638 }; 734 };
639 735
640 /** 736 /**
641 * Renders table row. 737 * Renders table row.
642 * @param {function(Entry, cr.ui.Table)} baseRenderFunction Base renderer. 738 * @param {function(Entry, cr.ui.Table)} baseRenderFunction Base renderer.
643 * @param {Entry} entry Corresponding entry. 739 * @param {Entry} entry Corresponding entry.
644 * @return {HTMLLIElement} Created element. 740 * @return {HTMLLIElement} Created element.
645 * @private 741 * @private
646 */ 742 */
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 return; 872 return;
777 873
778 if (externalProps.customIconUrl) 874 if (externalProps.customIconUrl)
779 iconDiv.style.backgroundImage = 'url(' + externalProps.customIconUrl + ')'; 875 iconDiv.style.backgroundImage = 'url(' + externalProps.customIconUrl + ')';
780 else 876 else
781 iconDiv.style.backgroundImage = ''; // Back to the default image. 877 iconDiv.style.backgroundImage = ''; // Back to the default image.
782 878
783 if (li.classList.contains('directory')) 879 if (li.classList.contains('directory'))
784 iconDiv.classList.toggle('shared', externalProps.shared); 880 iconDiv.classList.toggle('shared', externalProps.shared);
785 }; 881 };
OLDNEW
« no previous file with comments | « ui/file_manager/file_manager/foreground/js/file_manager.js ('k') | ui/file_manager/file_manager/main.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698