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

Side by Side Diff: chrome/browser/resources/md_history/history_card_manager.js

Issue 1643693003: MD History: Implement search functionality. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@patch_to_be_uploaded
Patch Set: Fix time-gap-separator insertion. Created 4 years, 10 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 Polymer({ 5 Polymer({
6 is: 'history-card-manager', 6 is: 'history-card-manager',
7 7
8 properties: { 8 properties: {
9 // An array of objects sorted in reverse chronological order. 9 // An array of objects sorted in reverse chronological order.
10 // Each object has a date and the history items belonging to that date. 10 // Each object has a date and the history items belonging to that date.
(...skipping 10 matching lines...) Expand all
21 21
22 menuOpen: { 22 menuOpen: {
23 type: Boolean, 23 type: Boolean,
24 value: false, 24 value: false,
25 reflectToAttribute: true 25 reflectToAttribute: true
26 }, 26 },
27 27
28 menuIdentifier: { 28 menuIdentifier: {
29 type: Number, 29 type: Number,
30 value: 0 30 value: 0
31 },
32
33 searchTerm: {
34 type: String,
35 value: ''
36 },
37
38 // Page waits until results have finished loading before displaying message.
39 loading: {
40 type: Boolean,
41 value: false
tsergeant 2016/02/12 00:03:52 Can you change to `value: true` instead of your ch
hsampson 2016/02/12 06:45:43 Done.
31 } 42 }
32 }, 43 },
33 44
34 /** @const @private */ 45 /** @const @private */
35 X_OFFSET_: 30, 46 X_OFFSET_: 30,
36 47
37 listeners: { 48 listeners: {
38 'tap': 'closeMenu', 49 'tap': 'closeMenu',
39 'toggle-menu': 'toggleMenu_' 50 'toggle-menu': 'toggleMenu_'
40 }, 51 },
41 52
42 /** 53 /**
43 * Closes the overflow menu. 54 * Closes the overflow menu.
44 */ 55 */
45 closeMenu: function() { 56 closeMenu: function() {
46 this.menuOpen = false; 57 this.menuOpen = false;
47 }, 58 },
48 59
49 /** 60 /**
61 * Clear the page completely so the page can display new results (search).
62 */
63 resetHistoryResults: function() {
64 // TODO(hsampson): make it so the old results aren't replaced immediately,
65 // only replaced when new results come in.
66 this.loading = true;
67 this.splice('historyDataByDay_', 0, this.historyDataByDay_.length);
68 },
69
70 /**
50 * Opens the overflow menu unless the menu is already open and the same button 71 * Opens the overflow menu unless the menu is already open and the same button
51 * is pressed. 72 * is pressed.
52 * @param {Event} e The event with details of the menu item that was clicked. 73 * @param {Event} e The event with details of the menu item that was clicked.
53 * @private 74 * @private
54 */ 75 */
55 toggleMenu_: function(e) { 76 toggleMenu_: function(e) {
56 var menu = this.$['overflow-menu']; 77 var menu = this.$['overflow-menu'];
57 78
58 // Menu closes if the same button is clicked. 79 // Menu closes if the same button is clicked.
59 if (this.menuOpen && this.menuIdentifier == e.detail.accessTime) { 80 if (this.menuOpen && this.menuIdentifier == e.detail.accessTime) {
60 this.closeMenu(); 81 this.closeMenu();
61 } else { 82 } else {
62 this.menuOpen = true; 83 this.menuOpen = true;
63 this.menuIdentifier = e.detail.accessTime; 84 this.menuIdentifier = e.detail.accessTime;
64 85
65 cr.ui.positionPopupAtPoint(e.detail.x + this.X_OFFSET_, e.detail.y, menu, 86 cr.ui.positionPopupAtPoint(e.detail.x + this.X_OFFSET_, e.detail.y, menu,
66 cr.ui.AnchorType.BEFORE); 87 cr.ui.AnchorType.BEFORE);
67 88
68 menu.focus(); 89 menu.focus();
69 } 90 }
70 }, 91 },
71 92
72 /** 93 /**
73 * Split the newly updated history results into history items sorted via day 94 * Split the newly updated history results into history items sorted via day
74 * accessed. 95 * accessed.
75 * @param {!Array<!HistoryEntry>} results The new history results. 96 * @param {!Array<!HistoryEntry>} results The new history results.
97 * @param {string} search The search term used for chrome.send.
76 */ 98 */
77 addNewResults: function(results) { 99 addNewResults: function(results, search) {
78 if (results.length == 0) 100 this.searchTerm = search;
101
102 if (results.length == 0) {
103 this.loading = false;
79 return; 104 return;
105 }
80 106
81 var dateSortedData = [];
82 var historyItems = []; 107 var historyItems = [];
83 var currentDate = results[0].dateRelativeDay; 108 var currentDate = results[0].dateRelativeDay;
84 109
85 for (var i = 0; i < results.length; i++) { 110 for (var i = 0; i < results.length; i++) {
86 if (!currentDate) 111 if (currentDate == undefined)
tsergeant 2016/02/12 00:03:53 I'm not sure what the intention is here? Nothing i
hsampson 2016/02/12 06:45:43 I think this may just be leftover from a different
87 continue; 112 continue;
88 113
114 results[i].visibleTimestamp =
115 search == '' ? results[i].dateTimeOfDay : results[i].dateShort;
89 results[i].selected = false; 116 results[i].selected = false;
117
90 if (results[i].dateRelativeDay != currentDate) { 118 if (results[i].dateRelativeDay != currentDate) {
91 this.appendHistoryData_(currentDate, historyItems); 119 this.appendHistoryData_(currentDate, historyItems);
92 currentDate = results[i].dateRelativeDay; 120 currentDate = results[i].dateRelativeDay;
93 historyItems = []; 121 historyItems = [];
94 } 122 }
95 historyItems.push(results[i]); 123 historyItems.push(results[i]);
96 } 124 }
97 125
98 if (currentDate) 126 if (currentDate != undefined)
99 this.appendHistoryData_(currentDate, historyItems); 127 this.appendHistoryData_(currentDate, historyItems);
100 128
101 this.lastVisitedTime = historyItems[historyItems.length - 1].time; 129 // this.lastVisitedTime = historyItems[historyItems.length - 1].time;
tsergeant 2016/02/12 00:03:52 Is this meant to be commented?
hsampson 2016/02/12 06:45:43 Done.
130 this.loading = false;
102 }, 131 },
103 132
104 /** 133 /**
105 * Cycle through each entry in historyDataByDay_ and set all items to be 134 * Cycle through each entry in historyDataByDay_ and set all items to be
106 * unselected. 135 * unselected.
107 * @param {number} overallItemCount The number of items selected. 136 * @param {number} overallItemCount The number of selected items.
108 */ 137 */
109 unselectAllItems: function(overallItemCount) { 138 unselectAllItems: function(overallItemCount) {
110 var historyCardData = this.historyDataByDay_; 139 var historyCardData = this.historyDataByDay_;
111 140
112 for (var i = 0; i < historyCardData.length; i++) { 141 for (var i = 0; i < historyCardData.length; i++) {
113 var items = historyCardData[i].historyItems; 142 var items = historyCardData[i].historyItems;
114 for (var j = 0; j < items.length; j++) { 143 for (var j = 0; j < items.length; j++) {
115 if (items[j].selected) { 144 if (items[j].selected) {
116 this.set('historyDataByDay_.' + i + '.historyItems.' + j + 145 this.set('historyDataByDay_.' + i + '.historyItems.' + j +
117 '.selected', false); 146 '.selected', false);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 var historyCards = this.historyDataByDay_; 192 var historyCards = this.historyDataByDay_;
164 for (var i = historyCards.length - 1; i >= 0; i--) { 193 for (var i = historyCards.length - 1; i >= 0; i--) {
165 if (historyCards[i].historyItems.length == 0) { 194 if (historyCards[i].historyItems.length == 0) {
166 this.splice('historyDataByDay_', i, 1); 195 this.splice('historyDataByDay_', i, 1);
167 } 196 }
168 } 197 }
169 }, 198 },
170 199
171 /** 200 /**
172 * Adds the given items into historyDataByDay_. Adds items to the last 201 * Adds the given items into historyDataByDay_. Adds items to the last
173 * existing day if the date matches, creates a new element otherwise. 202 * existing day if the currentDate matches, creates a new element otherwise.
174 * @param {string} date The date of the history items. 203 * @param {string} currentDate The currentDate for this list of history items.
175 * @param {!Array<!HistoryEntry>} historyItems The list of history items for 204 * @param {!Array<!HistoryEntry>} historyItems The list of history items for
176 * the current date. 205 * the current card.
177 * @private 206 * @private
178 */ 207 */
179 appendHistoryData_: function(date, historyItems) { 208 appendHistoryData_: function(currentDate, historyItems) {
180 var lastDay = this.historyDataByDay_.length - 1; 209 var lastDay = this.historyDataByDay_.length - 1;
181 if (lastDay > 0 && date == this.historyDataByDay_[lastDay].date) { 210 if (lastDay >= 0 &&
211 currentDate == this.historyDataByDay_[lastDay].date) {
182 this.set('historyDataByDay_.' + lastDay + '.historyItems', 212 this.set('historyDataByDay_.' + lastDay + '.historyItems',
183 this.historyDataByDay_[lastDay].historyItems.concat(historyItems)); 213 this.historyDataByDay_[lastDay].historyItems.concat(historyItems));
184 } else { 214 } else {
185 this.push('historyDataByDay_', { 215 this.push('historyDataByDay_', {
186 date: date, 216 date: currentDate,
187 historyItems: historyItems 217 historyItems: historyItems
188 }); 218 });
189 } 219 }
190 }, 220 },
191 221
192 /** 222 /**
193 * Based on which items are selected, collect an array of the info required 223 * Based on which items are selected, collect an array of the info required
194 * for chrome.send('removeHistory', ...). 224 * for chrome.send('removeHistory', ...).
195 * @param {number} count The number of items that are selected. 225 * @param {number} count The number of items that are selected.
196 * @return {Array<HistoryEntry>} toBeRemoved An array of objects which contain 226 * @return {Array<HistoryEntry>} toBeRemoved An array of objects which contain
(...skipping 25 matching lines...) Expand all
222 * @private 252 * @private
223 */ 253 */
224 scrollHandler_: function() { 254 scrollHandler_: function() {
225 // Close overflow menu on scroll. 255 // Close overflow menu on scroll.
226 this.closeMenu(); 256 this.closeMenu();
227 257
228 // Requests the next list of results when the scrollbar is near the bottom 258 // Requests the next list of results when the scrollbar is near the bottom
229 // of the window. 259 // of the window.
230 var scrollOffset = 10; 260 var scrollOffset = 10;
231 var scrollElem = this.$['infinite-list']; 261 var scrollElem = this.$['infinite-list'];
262 if (!this.loading && scrollElem.scrollHeight <=
263 scrollElem.scrollTop + scrollElem.clientHeight + scrollOffset) {
264 chrome.send('queryHistory',
265 [this.searchTerm, 0, 0, this.lastVisitedTime, RESULTS_PER_PAGE]);
266 }
267 },
232 268
233 if (scrollElem.scrollHeight <= 269 /**
234 scrollElem.scrollTop + scrollElem.clientHeight + scrollOffset) { 270 * True if there are no results available and the page has finished loading.
235 chrome.send('queryHistory', 271 * @param {number} numberOfResults The length of historyDataByDay_.
236 ['', 0, 0, this.lastVisitedTime, RESULTS_PER_PAGE]); 272 * @param {boolean} loading Whether the page has finished loading results.
237 } 273 * @return {boolean} Whether there are results to show.
274 * @private
275 */
276 noResultsAvailable_: function(numberOfResults, loading) {
277 return numberOfResults == 0 && !loading;
278 },
279
280 /**
281 * Return the message to be displayed if there are no results based on whether
282 * the empty results were for a search or normal history results.
283 * @param {string} search The search term for these results.
284 * @return {string} The displayed message.
285 * @private
286 */
287 noResultsMessage_: function(search) {
288 var messageId = search != '' ? 'noSearchResults' : 'noResults';
289 return loadTimeData.getString(messageId);
238 } 290 }
239 }); 291 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698