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

Side by Side Diff: chrome/browser/resources/file_manager/js/file_manager.js

Issue 10332272: Change modification date to include time and 'today' and 'yesterday' for appropriate dates. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 7 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 | Annotate | Revision Log
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 * FileManager constructor. 6 * FileManager constructor.
7 * 7 *
8 * FileManager objects encapsulate the functionality of the file selector 8 * FileManager objects encapsulate the functionality of the file selector
9 * dialogs, as well as the full screen file manager application (though the 9 * dialogs, as well as the full screen file manager application (though the
10 * latter is not yet implemented). 10 * latter is not yet implemented).
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 var IMAGE_HOVER_PREVIEW_SIZE = 200; 114 var IMAGE_HOVER_PREVIEW_SIZE = 200;
115 115
116 /** 116 /**
117 * The minimum about of time to display the butter bar for, in ms. 117 * The minimum about of time to display the butter bar for, in ms.
118 * Justification is 1000ms for minimum display time plus 300ms for transition 118 * Justification is 1000ms for minimum display time plus 300ms for transition
119 * duration. 119 * duration.
120 */ 120 */
121 var MINIMUM_BUTTER_DISPLAY_TIME_MS = 1300; 121 var MINIMUM_BUTTER_DISPLAY_TIME_MS = 1300;
122 122
123 /** 123 /**
124 * Number of milliseconds in a day.
125 */
126 var MILLISECONDS_IN_DAY = 24 * 60 * 60 * 1000;
127
128 /**
124 * Item for the Grid View. 129 * Item for the Grid View.
125 * @constructor 130 * @constructor
126 */ 131 */
127 function GridItem(fileManager, entry) { 132 function GridItem(fileManager, entry) {
128 var li = fileManager.document_.createElement('li'); 133 var li = fileManager.document_.createElement('li');
129 GridItem.decorate(li, fileManager, entry); 134 GridItem.decorate(li, fileManager, entry);
130 return li; 135 return li;
131 } 136 }
132 137
133 GridItem.prototype = { 138 GridItem.prototype = {
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 326
322 /** 327 /**
323 * Continue initializing the file manager after resolving roots. 328 * Continue initializing the file manager after resolving roots.
324 */ 329 */
325 FileManager.prototype.init_ = function() { 330 FileManager.prototype.init_ = function() {
326 metrics.startInterval('Load.DOM'); 331 metrics.startInterval('Load.DOM');
327 this.initCommands_(); 332 this.initCommands_();
328 333
329 this.metadataCache_ = MetadataCache.createFull(); 334 this.metadataCache_ = MetadataCache.createFull();
330 335
331 this.shortDateFormatter_ = 336 this.dateFormatter_ = v8Intl.DateTimeFormat(
332 this.locale_.createDateTimeFormat({'dateType': 'medium'}); 337 {} /* default locale */,
338 {year: 'numeric', month: 'short', day: 'numeric',
339 hour: 'numeric', minute: 'numeric'});
340 this.timeFormatter_ = v8Intl.DateTimeFormat(
341 {} /* default locale */,
342 {hour: 'numeric', minute: 'numeric'});
333 343
334 this.collator_ = this.locale_.createCollator({ 344 this.collator_ = this.locale_.createCollator({
335 'numeric': true, 'ignoreCase': true, 'ignoreAccents': true}); 345 'numeric': true, 'ignoreCase': true, 'ignoreAccents': true});
336 346
337 // Optional list of file types. 347 // Optional list of file types.
338 this.fileTypes_ = this.params_.typeList; 348 this.fileTypes_ = this.params_.typeList;
339 349
340 this.showCheckboxes_ = 350 this.showCheckboxes_ =
341 (this.dialogType_ == FileManager.DialogType.FULL_PAGE || 351 (this.dialogType_ == FileManager.DialogType.FULL_PAGE ||
342 this.dialogType_ == FileManager.DialogType.SELECT_OPEN_MULTI_FILE); 352 this.dialogType_ == FileManager.DialogType.SELECT_OPEN_MULTI_FILE);
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 this.initGrid_(); 678 this.initGrid_();
669 this.initRootsList_(); 679 this.initRootsList_();
670 680
671 var listType = FileManager.ListType.DETAIL; 681 var listType = FileManager.ListType.DETAIL;
672 if (FileManager.DialogType.isModal(this.dialogType_)) 682 if (FileManager.DialogType.isModal(this.dialogType_))
673 listType = window.localStorage['listType-' + this.dialogType_] || 683 listType = window.localStorage['listType-' + this.dialogType_] ||
674 FileManager.ListType.DETAIL; 684 FileManager.ListType.DETAIL;
675 this.setListType(listType); 685 this.setListType(listType);
676 686
677 this.textSearchState_ = {text: '', date: new Date()}; 687 this.textSearchState_ = {text: '', date: new Date()};
688
689 // Update metadata to change 'Today' and 'Yesterday' dates.
690 var today = new Date();
691 today.setHours(0);
692 today.setMinutes(0);
693 today.setSeconds(0);
694 today.setMilliseconds(0);
695 setTimeout(this.dailyUpdateModificationTime_.bind(this),
696 today.getTime() + MILLISECONDS_IN_DAY - Date.now() + 1000);
678 }; 697 };
679 698
680 FileManager.prototype.initRootsList_ = function() { 699 FileManager.prototype.initRootsList_ = function() {
681 this.rootsList_ = this.dialogDom_.querySelector('#roots-list'); 700 this.rootsList_ = this.dialogDom_.querySelector('#roots-list');
682 cr.ui.List.decorate(this.rootsList_); 701 cr.ui.List.decorate(this.rootsList_);
683 this.rootsList_.startBatchUpdates(); 702 this.rootsList_.startBatchUpdates();
684 703
685 var self = this; 704 var self = this;
686 this.rootsList_.itemConstructor = function(entry) { 705 this.rootsList_.itemConstructor = function(entry) {
687 return self.renderRoot_(entry); 706 return self.renderRoot_(entry);
(...skipping 1304 matching lines...) Expand 10 before | Expand all | Expand 10 after
1992 div.className = 'date'; 2011 div.className = 'date';
1993 2012
1994 this.updateDate_(div, 2013 this.updateDate_(div,
1995 this.metadataCache_.getCached(entry, 'filesystem')); 2014 this.metadataCache_.getCached(entry, 'filesystem'));
1996 return div; 2015 return div;
1997 }; 2016 };
1998 2017
1999 FileManager.prototype.updateDate_ = function(div, filesystemProps) { 2018 FileManager.prototype.updateDate_ = function(div, filesystemProps) {
2000 if (!filesystemProps) { 2019 if (!filesystemProps) {
2001 div.textContent = '...'; 2020 div.textContent = '...';
2021 return;
2022 }
2023
2024 var modTime = filesystemProps.modificationTime;
2025 var today = new Date();
2026 today.setHours(0);
2027 today.setMinutes(0);
2028 today.setSeconds(0);
2029 today.setMilliseconds(0);
2030
2031 if (modTime >= today &&
2032 modTime < today.getTime() + MILLISECONDS_IN_DAY) {
2033 div.textContent = strf('TIME_TODAY', this.timeFormatter_.format(modTime));
2034 } else if (modTime >= today - MILLISECONDS_IN_DAY && modTime < today) {
2035 div.textContent = strf('TIME_YESTERDAY',
2036 this.timeFormatter_.format(modTime));
2002 } else { 2037 } else {
2003 div.textContent = 2038 div.textContent =
2004 this.shortDateFormatter_.format(filesystemProps.modificationTime); 2039 this.dateFormatter_.format(filesystemProps.modificationTime);
2005 } 2040 }
2006 }; 2041 };
2007 2042
2008 FileManager.prototype.renderOffline_ = function(entry, columnId, table) { 2043 FileManager.prototype.renderOffline_ = function(entry, columnId, table) {
2009 var doc = this.document_; 2044 var doc = this.document_;
2010 var div = doc.createElement('div'); 2045 var div = doc.createElement('div');
2011 div.className = 'offline'; 2046 div.className = 'offline';
2012 2047
2013 if (entry.isDirectory) 2048 if (entry.isDirectory)
2014 return div; 2049 return div;
(...skipping 27 matching lines...) Expand all
2042 // observer registered to update the UI. 2077 // observer registered to update the UI.
2043 2078
2044 this.metadataCache_.clear(entries, 'filesystem'); 2079 this.metadataCache_.clear(entries, 'filesystem');
2045 this.metadataCache_.get(entries, 'filesystem', null); 2080 this.metadataCache_.get(entries, 'filesystem', null);
2046 if (this.isOnGData()) { 2081 if (this.isOnGData()) {
2047 this.metadataCache_.clear(entries, 'gdata'); 2082 this.metadataCache_.clear(entries, 'gdata');
2048 this.metadataCache_.get(entries, 'gdata', null); 2083 this.metadataCache_.get(entries, 'gdata', null);
2049 } 2084 }
2050 }; 2085 };
2051 2086
2087 FileManager.prototype.dailyUpdateModificationTime_ = function() {
2088 var fileList = this.directoryModel_.getFileList();
2089 var urls = [];
2090 for (var i = 0; i < fileList.length; i++) {
2091 urls.push(fileList.item(i).toURL());
2092 }
2093 this.metadataCache_.get(
2094 fileList.slice(), 'filesystem',
2095 this.updateMetadataInUI_.bind(this, 'filesystem', urls));
2096
2097 setTimeout(this.dailyUpdateModificationTime_.bind(this),
2098 MILLISECONDS_IN_DAY);
2099 };
2100
2052 FileManager.prototype.updateMetadataInUI_ = function( 2101 FileManager.prototype.updateMetadataInUI_ = function(
2053 type, urls, properties) { 2102 type, urls, properties) {
2054 if (this.listType_ != FileManager.ListType.DETAIL) return; 2103 if (this.listType_ != FileManager.ListType.DETAIL) return;
2055 2104
2056 var items = {}; 2105 var items = {};
2057 var entries = {}; 2106 var entries = {};
2058 var dm = this.directoryModel_.getFileList(); 2107 var dm = this.directoryModel_.getFileList();
2059 for (var index = 0; index < dm.length; index++) { 2108 for (var index = 0; index < dm.length; index++) {
2060 var listItem = this.currentList_.getListItemByIndex(index); 2109 var listItem = this.currentList_.getListItemByIndex(index);
2061 if (!listItem) continue; 2110 if (!listItem) continue;
(...skipping 2636 matching lines...) Expand 10 before | Expand all | Expand 10 after
4698 4747
4699 function closeBanner() { 4748 function closeBanner() {
4700 self.cleanupGDataWelcome_(); 4749 self.cleanupGDataWelcome_();
4701 // Stop showing the welcome banner. 4750 // Stop showing the welcome banner.
4702 localStorage[WELCOME_HEADER_COUNTER_KEY] = WELCOME_HEADER_COUNTER_LIMIT; 4751 localStorage[WELCOME_HEADER_COUNTER_KEY] = WELCOME_HEADER_COUNTER_LIMIT;
4703 } 4752 }
4704 4753
4705 return maybeShowBanner; 4754 return maybeShowBanner;
4706 }; 4755 };
4707 })(); 4756 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698