Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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; | |
| 252 | 255 |
| 253 var columns = [ | 256 var columns = [ |
| 254 new cr.ui.table.TableColumn('name', str('NAME_COLUMN_LABEL'), | 257 new cr.ui.table.TableColumn('name', str('NAME_COLUMN_LABEL'), |
| 255 fullPage ? 386 : 324), | 258 fullPage ? 386 : 324), |
| 256 new cr.ui.table.TableColumn('size', str('SIZE_COLUMN_LABEL'), | 259 new cr.ui.table.TableColumn('size', str('SIZE_COLUMN_LABEL'), |
| 257 110, true), | 260 110, true), |
| 261 new cr.ui.table.TableColumn('status', str('STATUS_COLUMN_LABEL'), | |
|
Steve McKay
2015/01/14 20:30:16
Will this be visible to everyone in all contexts?
Ben Kwa
2015/01/15 16:36:56
Partially done - fixed to only show this column wh
| |
| 262 20, true), | |
| 258 new cr.ui.table.TableColumn('type', str('TYPE_COLUMN_LABEL'), | 263 new cr.ui.table.TableColumn('type', str('TYPE_COLUMN_LABEL'), |
| 259 fullPage ? 110 : 110), | 264 fullPage ? 110 : 110), |
| 260 new cr.ui.table.TableColumn('modificationTime', | 265 new cr.ui.table.TableColumn('modificationTime', |
| 261 str('DATE_COLUMN_LABEL'), | 266 str('DATE_COLUMN_LABEL'), |
| 262 fullPage ? 150 : 210) | 267 fullPage ? 150 : 210) |
| 263 ]; | 268 ]; |
| 264 | 269 |
| 265 columns[0].renderFunction = self.renderName_.bind(self); | 270 columns[0].renderFunction = self.renderName_.bind(self); |
| 266 columns[1].renderFunction = self.renderSize_.bind(self); | 271 columns[1].renderFunction = self.renderSize_.bind(self); |
| 267 columns[1].defaultOrder = 'desc'; | 272 columns[1].defaultOrder = 'desc'; |
| 268 columns[2].renderFunction = self.renderType_.bind(self); | 273 columns[2].renderFunction = self.renderStatus_.bind(self); |
| 269 columns[3].renderFunction = self.renderDate_.bind(self); | 274 columns[3].renderFunction = self.renderType_.bind(self); |
| 270 columns[3].defaultOrder = 'desc'; | 275 columns[4].renderFunction = self.renderDate_.bind(self); |
| 276 columns[4].defaultOrder = 'desc'; | |
| 271 | 277 |
| 272 var columnModel = new FileTableColumnModel(columns); | 278 var columnModel = new FileTableColumnModel(columns); |
| 273 | 279 |
| 274 self.columnModel = columnModel; | 280 self.columnModel = columnModel; |
| 275 self.setDateTimeFormat(true); | 281 self.setDateTimeFormat(true); |
| 276 self.setRenderFunction(self.renderTableRow_.bind(self, | 282 self.setRenderFunction(self.renderTableRow_.bind(self, |
| 277 self.getRenderFunction())); | 283 self.getRenderFunction())); |
| 278 | 284 |
| 279 self.scrollBar_ = new MainPanelScrollBar(); | 285 self.scrollBar_ = new MainPanelScrollBar(); |
| 280 self.scrollBar_.initialize(self, self.list); | 286 self.scrollBar_.initialize(self, self.list); |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 510 } else if (externalProps.hosted) { | 516 } else if (externalProps.hosted) { |
| 511 div.textContent = '--'; | 517 div.textContent = '--'; |
| 512 return; | 518 return; |
| 513 } | 519 } |
| 514 } | 520 } |
| 515 | 521 |
| 516 div.textContent = util.bytesToString(filesystemProps.size); | 522 div.textContent = util.bytesToString(filesystemProps.size); |
| 517 }; | 523 }; |
| 518 | 524 |
| 519 /** | 525 /** |
| 526 * Render the Status column of the detail table. | |
| 527 * | |
| 528 * @param {Entry} entry The Entry object to render. | |
| 529 * @param {string} columnId The id of the column to be rendered. | |
| 530 * @param {cr.ui.Table} table The table doing the rendering. | |
| 531 * @return {!HTMLDivElement} Created element. | |
| 532 * @private | |
| 533 */ | |
| 534 FileTable.prototype.renderStatus_ = function(entry, columnId, table) { | |
| 535 var div = /** @type {!HTMLDivElement} */ ( | |
| 536 this.ownerDocument.createElement('div')); | |
| 537 div.className = 'status status-icon'; | |
| 538 if (entry) { | |
| 539 this.updateStatus_(div, entry); | |
| 540 } | |
| 541 | |
| 542 return div; | |
| 543 }; | |
| 544 | |
| 545 /** | |
| 546 * Returns the status of the entry w.r.t. the given import destination. | |
| 547 * @param {Entry} entry | |
| 548 * @param {!importer.Destination} destination | |
| 549 * @return {!Promise<string>} The import status - will be 'imported', 'copied', | |
| 550 * or 'unknown'. | |
| 551 */ | |
| 552 FileTable.prototype.getImportStatus_ = function(entry, destination) { | |
| 553 if (!entry.isFile) { | |
| 554 // Our import history doesn't deal with directories. | |
| 555 // TODO(kenobi): May need to revisit this if the above assumption changes. | |
| 556 return Promise.resolve('unknown'); | |
| 557 } | |
| 558 // For the compiler. | |
| 559 var fileEntry = /** @type {!FileEntry} */ (entry); | |
| 560 | |
| 561 return this.historyLoader_.getHistory() | |
| 562 .then( | |
| 563 /** @param {!importer.ImportHistory} history */ | |
| 564 function(history) { | |
| 565 return Promise.all([ | |
| 566 history.wasImported(fileEntry, destination), | |
| 567 history.wasCopied(fileEntry, destination) | |
| 568 ]); | |
| 569 }) | |
| 570 .then( | |
| 571 /** @param {!Array<boolean>} status */ | |
| 572 function(status) { | |
| 573 if (status[0]) { | |
| 574 return 'imported'; | |
| 575 } else if (status[1]) { | |
| 576 return 'copied'; | |
| 577 } else { | |
| 578 return 'unknown'; | |
| 579 } | |
| 580 }); | |
| 581 }; | |
| 582 | |
| 583 /** | |
| 584 * Render the status icon of the detail table. | |
| 585 * | |
| 586 * @param {HTMLDivElement} div | |
| 587 * @param {Entry} entry The Entry object to render. | |
| 588 * @private | |
| 589 */ | |
| 590 FileTable.prototype.updateStatus_ = function(div, entry) { | |
| 591 this.getImportStatus_(entry, importer.Destination.GOOGLE_DRIVE).then( | |
| 592 /** @param {string} status */ | |
| 593 function(status) { | |
| 594 div.setAttribute('file-status-icon', status); | |
| 595 }); | |
| 596 }; | |
| 597 | |
| 598 /** | |
| 520 * Render the Type column of the detail table. | 599 * Render the Type column of the detail table. |
| 521 * | 600 * |
| 522 * @param {Entry} entry The Entry object to render. | 601 * @param {Entry} entry The Entry object to render. |
| 523 * @param {string} columnId The id of the column to be rendered. | 602 * @param {string} columnId The id of the column to be rendered. |
| 524 * @param {cr.ui.Table} table The table doing the rendering. | 603 * @param {cr.ui.Table} table The table doing the rendering. |
| 525 * @return {!HTMLDivElement} Created element. | 604 * @return {!HTMLDivElement} Created element. |
| 526 * @private | 605 * @private |
| 527 */ | 606 */ |
| 528 FileTable.prototype.renderType_ = function(entry, columnId, table) { | 607 FileTable.prototype.renderType_ = function(entry, columnId, table) { |
| 529 var div = /** @type {!HTMLDivElement} */ | 608 var div = /** @type {!HTMLDivElement} */ |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 595 * Updates the file metadata in the table item. | 674 * Updates the file metadata in the table item. |
| 596 * | 675 * |
| 597 * @param {Element} item Table item. | 676 * @param {Element} item Table item. |
| 598 * @param {Entry} entry File entry. | 677 * @param {Entry} entry File entry. |
| 599 */ | 678 */ |
| 600 FileTable.prototype.updateFileMetadata = function(item, entry) { | 679 FileTable.prototype.updateFileMetadata = function(item, entry) { |
| 601 this.updateDate_( | 680 this.updateDate_( |
| 602 /** @type {!HTMLDivElement} */ (item.querySelector('.date')), entry); | 681 /** @type {!HTMLDivElement} */ (item.querySelector('.date')), entry); |
| 603 this.updateSize_( | 682 this.updateSize_( |
| 604 /** @type {!HTMLDivElement} */ (item.querySelector('.size')), entry); | 683 /** @type {!HTMLDivElement} */ (item.querySelector('.size')), entry); |
| 684 this.updateStatus_( | |
| 685 /** @type {!HTMLDivElement} */ (item.querySelector('.status')), entry); | |
| 605 }; | 686 }; |
| 606 | 687 |
| 607 /** | 688 /** |
| 608 * Updates list items 'in place' on metadata change. | 689 * Updates list items 'in place' on metadata change. |
| 609 * @param {string} type Type of metadata change. | 690 * @param {string} type Type of metadata change. |
| 610 * @param {Array.<Entry>} entries Entries to update. | 691 * @param {Array.<Entry>} entries Entries to update. |
| 611 */ | 692 */ |
| 612 FileTable.prototype.updateListItemsMetadata = function(type, entries) { | 693 FileTable.prototype.updateListItemsMetadata = function(type, entries) { |
| 613 var urls = util.entriesToURLs(entries); | 694 var urls = util.entriesToURLs(entries); |
| 614 var forEachCell = function(selector, callback) { | 695 var forEachCell = function(selector, callback) { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 627 }); | 708 }); |
| 628 forEachCell('.table-row-cell > .size', function(item, entry, unused) { | 709 forEachCell('.table-row-cell > .size', function(item, entry, unused) { |
| 629 this.updateSize_(item, entry); | 710 this.updateSize_(item, entry); |
| 630 }); | 711 }); |
| 631 } else if (type === 'external') { | 712 } else if (type === 'external') { |
| 632 // The cell name does not matter as the entire list item is needed. | 713 // The cell name does not matter as the entire list item is needed. |
| 633 forEachCell('.table-row-cell > .date', function(item, entry, listItem) { | 714 forEachCell('.table-row-cell > .date', function(item, entry, listItem) { |
| 634 var props = this.metadataCache_.getCached(entry, 'external'); | 715 var props = this.metadataCache_.getCached(entry, 'external'); |
| 635 filelist.updateListItemExternalProps(listItem, props); | 716 filelist.updateListItemExternalProps(listItem, props); |
| 636 }); | 717 }); |
| 718 } else if (type === 'import-history') { | |
| 719 forEachCell('.table-row-cell > .status', function(item, entry, unused) { | |
| 720 this.updateStatus_(item, entry); | |
| 721 }); | |
| 637 } | 722 } |
| 638 }; | 723 }; |
| 639 | 724 |
| 640 /** | 725 /** |
| 641 * Renders table row. | 726 * Renders table row. |
| 642 * @param {function(Entry, cr.ui.Table)} baseRenderFunction Base renderer. | 727 * @param {function(Entry, cr.ui.Table)} baseRenderFunction Base renderer. |
| 643 * @param {Entry} entry Corresponding entry. | 728 * @param {Entry} entry Corresponding entry. |
| 644 * @return {HTMLLIElement} Created element. | 729 * @return {HTMLLIElement} Created element. |
| 645 * @private | 730 * @private |
| 646 */ | 731 */ |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 776 return; | 861 return; |
| 777 | 862 |
| 778 if (externalProps.customIconUrl) | 863 if (externalProps.customIconUrl) |
| 779 iconDiv.style.backgroundImage = 'url(' + externalProps.customIconUrl + ')'; | 864 iconDiv.style.backgroundImage = 'url(' + externalProps.customIconUrl + ')'; |
| 780 else | 865 else |
| 781 iconDiv.style.backgroundImage = ''; // Back to the default image. | 866 iconDiv.style.backgroundImage = ''; // Back to the default image. |
| 782 | 867 |
| 783 if (li.classList.contains('directory')) | 868 if (li.classList.contains('directory')) |
| 784 iconDiv.classList.toggle('shared', externalProps.shared); | 869 iconDiv.classList.toggle('shared', externalProps.shared); |
| 785 }; | 870 }; |
| OLD | NEW |