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

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: Update comments. 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,
tsergeant 2016/02/09 04:28:53 Should loading_ be true to start with while initia
hsampson 2016/02/11 02:46:26 Yes it should. Now when the page loads this is set
41 value: false
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 = []; 107 var dateSortedData = [];
82 var historyItems = []; 108 var historyItems = [];
83 var currentDate = results[0].dateRelativeDay; 109 var currentCardTitle = search == '' ? results[0].dateRelativeDay : search;
84 110
85 for (var i = 0; i < results.length; i++) { 111 for (var i = 0; i < results.length; i++) {
86 if (!currentDate) 112 if (!currentCardTitle)
87 continue; 113 continue;
88 114
115 results[i].cardTitle = search == '' ? results[i].dateRelativeDay : search;
116 results[i].visibleTimestamp =
117 search == '' ? results[i].dateTimeOfDay : results[i].dateShort;
89 results[i].selected = false; 118 results[i].selected = false;
90 if (results[i].dateRelativeDay != currentDate) { 119
91 this.appendHistoryData_(currentDate, historyItems); 120 if (results[i].cardTitle != currentCardTitle) {
92 currentDate = results[i].dateRelativeDay; 121 this.appendHistoryData_(currentCardTitle, historyItems);
122 currentCardTitle = results[i].cardTitle;
93 historyItems = []; 123 historyItems = [];
94 } 124 }
95 historyItems.push(results[i]); 125 historyItems.push(results[i]);
96 } 126 }
97 127
98 if (currentDate) 128 if (currentCardTitle)
99 this.appendHistoryData_(currentDate, historyItems); 129 this.appendHistoryData_(currentCardTitle, historyItems);
100 130
101 this.lastVisitedTime = historyItems[historyItems.length - 1].time; 131 this.lastVisitedTime = historyItems[historyItems.length - 1].time;
132 this.loading_ = false;
133 Polymer.dom.flush();
tsergeant 2016/02/09 04:28:53 Why is this here?
hsampson 2016/02/11 02:46:26 Unnecessary now.
102 }, 134 },
103 135
104 /** 136 /**
105 * Cycle through each entry in historyDataByDay_ and set all items to be 137 * Cycle through each entry in historyDataByDay_ and set all items to be
106 * unselected. 138 * unselected.
139 * @param {number} overallItemCount The number of selected items.
107 */ 140 */
108 unselectAllItems: function(overallItemCount) { 141 unselectAllItems: function(overallItemCount) {
109 var historyCardData = this.historyDataByDay_; 142 var historyCardData = this.historyDataByDay_;
110 143
111 for (var i = 0; i < historyCardData.length; i++) { 144 for (var i = 0; i < historyCardData.length; i++) {
112 var items = historyCardData[i].historyItems; 145 var items = historyCardData[i].historyItems;
113 for (var j = 0; j < items.length; j++) { 146 for (var j = 0; j < items.length; j++) {
114 if (items[j].selected) { 147 if (items[j].selected) {
115 this.set('historyDataByDay_.' + i + '.historyItems.' + j + 148 this.set('historyDataByDay_.' + i + '.historyItems.' + j +
116 '.selected', false); 149 '.selected', false);
117 overallItemCount--; 150 overallItemCount--;
118 if (overallItemCount == 0) 151 if (overallItemCount == 0)
119 break; 152 break;
120 } 153 }
121 } 154 }
122 } 155 }
123 }, 156 },
124 157
125 /** 158 /**
126 * Adds the given items into historyDataByDay_. Adds items to the last 159 * Adds the given items into historyDataByDay_. Adds items to the last
127 * existing day if the date matches, creates a new element otherwise. 160 * existing day if the cardTitle matches, creates a new element otherwise.
128 * @param {string} date The date of the history items. 161 * @param {string} cardTitle The cardTitle for this list of history items.
129 * @param {!Array<!HistoryEntry>} historyItems The list of history items for 162 * @param {!Array<!HistoryEntry>} historyItems The list of history items for
130 * the current date. 163 * the current card.
131 * @private 164 * @private
132 */ 165 */
133 appendHistoryData_: function(date, historyItems) { 166 appendHistoryData_: function(cardTitle, historyItems) {
134 var lastDay = this.historyDataByDay_.length - 1; 167 var lastDay = this.historyDataByDay_.length - 1;
135 if (lastDay > 0 && date == this.historyDataByDay_[lastDay].date) { 168 if (lastDay >= 0 &&
169 cardTitle == this.historyDataByDay_[lastDay].cardTitle) {
136 this.set('historyDataByDay_.' + lastDay + '.historyItems', 170 this.set('historyDataByDay_.' + lastDay + '.historyItems',
137 this.historyDataByDay_[lastDay].historyItems.concat(historyItems)); 171 this.historyDataByDay_[lastDay].historyItems.concat(historyItems));
138 } else { 172 } else {
139 this.push('historyDataByDay_', { 173 this.push('historyDataByDay_', {
140 date: date, 174 cardTitle: cardTitle,
141 historyItems: historyItems 175 historyItems: historyItems
142 }); 176 });
143 } 177 }
144 }, 178 },
145 179
146 /** 180 /**
147 * Called when the card manager is scrolled. 181 * Called when the card manager is scrolled.
148 * @private 182 * @private
149 */ 183 */
150 scrollHandler_: function() { 184 scrollHandler_: function() {
151 // Close overflow menu on scroll. 185 // Close overflow menu on scroll.
152 this.closeMenu(); 186 this.closeMenu();
153 187
154 // Requests the next list of results when the scrollbar is near the bottom 188 // Requests the next list of results when the scrollbar is near the bottom
155 // of the window. 189 // of the window.
156 var scrollOffset = 10; 190 var scrollOffset = 10;
157 var scrollElem = this.$['infinite-list']; 191 var scrollElem = this.$['infinite-list'];
192 if (!this.loading_ && scrollElem.scrollHeight <=
193 scrollElem.scrollTop + scrollElem.clientHeight + scrollOffset) {
194 chrome.send('queryHistory',
195 [this.searchTerm, 0, 0, this.lastVisitedTime, RESULTS_PER_PAGE]);
196 }
197 },
158 198
159 if (scrollElem.scrollHeight <= 199 /**
160 scrollElem.scrollTop + scrollElem.clientHeight + scrollOffset) { 200 * True if there are no results available and the page has finished loading.
161 chrome.send('queryHistory', 201 * @param {number} numberOfResults The length of historyDataByDay_.
162 ['', 0, 0, this.lastVisitedTime, RESULTS_PER_PAGE]); 202 * @param {boolean} loading Whether the page has finished loading results.
163 } 203 * @return {boolean} Whether there are results to show.
204 * @private
205 */
206 noResultsAvailable_: function(numberOfResults, loading) {
207 return numberOfResults == 0 && !loading;
208 },
209
210 /**
211 * True if there are results available or the page hasn't finished loading, or
212 * the results being returned are part of a search.
213 * @param {number} numberOfResults The length of historyDataByDay_.
214 * @param {boolean} loading Whether the page has finished loading results.
215 * @param {string} search The search term associated with these results.
216 * @return {boolean} Whether the "noResults" message should be shown.
217 * @private
218 */
219 resultsAvailable_: function(numberOfResults, loading, search) {
220 return !this.noResultsAvailable_(numberOfResults, loading) || search != '';
221 },
222
223 /**
224 * True if there are results available or the page hasn't finished loading, or
225 * the results being returned are not part of a search.
226 * @param {number} numberOfResults The length of historyDataByDay_.
227 * @param {boolean} loading Whether the page has finished loading results.
228 * @param {string} search The search term associated with these results.
229 * @return {boolean} Whether the "noSearchResults" message should be shown.
230 * @private
231 */
232 noSearch_: function(numberOfResults, loading, search) {
233 return !this.noResultsAvailable_(numberOfResults, loading) || search == '';
164 } 234 }
165 }); 235 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698