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

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: Hide cards that haven't been rerendered from previous chrome.send(). 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.
11 historyDataByDay_: { 11 historyDataByDay_: {
12 type: Array, 12 type: Array,
13 value: function() { return []; } 13 value: function() { return []; }
14 }, 14 },
15
15 // The time of access of the last element of historyDataByDay_. 16 // The time of access of the last element of historyDataByDay_.
16 lastVisitedTime: { 17 lastVisitedTime: {
17 type: Number, 18 type: Number,
18 value: 0 19 value: 0
19 }, 20 },
21
20 menuOpen: { 22 menuOpen: {
21 type: Boolean, 23 type: Boolean,
22 value: false, 24 value: false,
23 reflectToAttribute: true 25 reflectToAttribute: true
24 }, 26 },
27
25 menuIdentifier: { 28 menuIdentifier: {
26 type: Number, 29 type: Number,
27 value: 0 30 value: 0
31 },
32
33 searchTerm: {
34 type: String,
35 value: ''
36 },
37
38 // Message shown when no results available. Depends on searchTerm.
39 noResultsMessage: {
tsergeant 2016/02/02 02:57:36 Can this be private?
hsampson 2016/02/03 02:37:58 Done.
40 type: String,
41 value: ''
42 },
43
44 // Page waits until results have finished loading before displaying message.
45 loading: {
tsergeant 2016/02/02 02:57:36 And this?
hsampson 2016/02/03 02:37:58 Done.
46 type: Boolean,
47 value: false
28 } 48 }
29 }, 49 },
30 50
31 /** @const @private */ 51 /** @const @private */
32 X_OFFSET_: 30, 52 X_OFFSET_: 30,
33 53
34 listeners: { 54 listeners: {
35 'tap': 'closeMenu', 55 'tap': 'closeMenu',
36 'toggle-menu': 'toggleMenu_' 56 'toggle-menu': 'toggleMenu_'
37 }, 57 },
38 58
39 /** 59 /**
40 * Closes the overflow menu. 60 * Closes the overflow menu.
41 */ 61 */
42 closeMenu: function() { 62 closeMenu: function() {
43 this.menuOpen = false; 63 this.menuOpen = false;
44 }, 64 },
45 65
46 /** 66 /**
67 * Clear the page completely so the page can display new results (search).
68 */
69 resetHistoryResults: function() {
70 this.loading = true;
71 this.splice('historyDataByDay_', 0, this.historyDataByDay_.length);
72 },
73
74 /**
47 * Opens the overflow menu unless the menu is already open and the same button 75 * Opens the overflow menu unless the menu is already open and the same button
48 * is pressed. 76 * is pressed.
49 * @param {Event} e The event with details of the menu item that was clicked. 77 * @param {Event} e The event with details of the menu item that was clicked.
50 * @private 78 * @private
51 */ 79 */
52 toggleMenu_: function(e) { 80 toggleMenu_: function(e) {
53 var menu = this.$['overflow-menu']; 81 var menu = this.$['overflow-menu'];
54 82
55 // Menu closes if the same button is clicked. 83 // Menu closes if the same button is clicked.
56 if (this.menuOpen && this.menuIdentifier == e.detail.accessTime) { 84 if (this.menuOpen && this.menuIdentifier == e.detail.accessTime) {
57 this.menuOpen = false; 85 this.menuOpen = false;
58 } else { 86 } else {
59 this.menuOpen = true; 87 this.menuOpen = true;
60 this.menuIdentifier = e.detail.accessTime; 88 this.menuIdentifier = e.detail.accessTime;
61 89
62 cr.ui.positionPopupAtPoint(e.detail.x + this.X_OFFSET_, e.detail.y, menu, 90 cr.ui.positionPopupAtPoint(e.detail.x + this.X_OFFSET_, e.detail.y, menu,
63 cr.ui.AnchorType.BEFORE); 91 cr.ui.AnchorType.BEFORE);
64 92
65 menu.focus(); 93 menu.focus();
66 } 94 }
67 }, 95 },
68 96
69 /** 97 /**
98 * Reformat the search results so they all have the same dateRelativeDay (will
99 * all display on the same card). Also so the date displays instead of time.
100 * @param {array<HistoryEntry>} results The new search results.
101 * @param {string} searchTerm The search term used to find these results.
102 */
103 reformatSearchResults_: function(results, searchTerm) {
104 for (i = 0; i < results.length; i++) {
105 results[i].dateRelativeDay = searchTerm;
106 results[i].dateTimeOfDay = results[i].dateShort;
107 results[i].historySearchTerm = searchTerm;
tsergeant 2016/02/02 02:57:36 What's this? I don't see it anywhere else
hsampson 2016/02/03 02:37:58 This is used in addNewResults() if the results ret
108 }
109 },
110
111 /**
70 * Split the newly updated history results into history items sorted via day 112 * Split the newly updated history results into history items sorted via day
71 * accessed. 113 * accessed.
72 * @param {Array<HistoryEntry>} results The new history results. 114 * @param {Array<HistoryEntry>} results The new history results.
115 * @param {string} searchTerm The search term used for chrome.send.
73 */ 116 */
74 addNewResults: function(results) { 117 addNewResults: function(results, searchTerm) {
75 if (results.length == 0) 118 this.searchTerm = searchTerm;
119 this.noResultsMessage_();
120
121 if (results.length == 0) {
122 this.loading = false;
76 return; 123 return;
124 }
125
126 if (searchTerm != '')
127 this.reformatSearchResults_(results, searchTerm);
77 128
78 var dateSortedData = []; 129 var dateSortedData = [];
79 var historyItems = []; 130 var historyItems = [];
80 var currentDate = results[0].dateRelativeDay; 131 var currentDate = results[0].dateRelativeDay;
81 132
82 for (var i = 0; i < results.length; i++) { 133 for (var i = 0; i < results.length; i++) {
83 if (currentDate == undefined) 134 if (currentDate == undefined)
84 continue; 135 continue;
85 136
86 results[i].selected = false; 137 results[i].selected = false;
87 if (results[i].dateRelativeDay != currentDate) { 138 if (results[i].dateRelativeDay != currentDate) {
88 this.appendHistoryData_(currentDate, historyItems); 139 this.appendHistoryData_(currentDate, historyItems);
89 currentDate = results[i].dateRelativeDay; 140 currentDate = results[i].dateRelativeDay;
90 historyItems = []; 141 historyItems = [];
91 } 142 }
92 historyItems.push(results[i]); 143 historyItems.push(results[i]);
93 } 144 }
94 if (currentDate != undefined) 145 if (currentDate != undefined)
95 this.appendHistoryData_(currentDate, historyItems); 146 this.appendHistoryData_(currentDate, historyItems);
96 147
97 this.lastVisitedTime = historyItems[historyItems.length - 1].time; 148 this.lastVisitedTime = historyItems[historyItems.length - 1].time;
149 this.loading = false;
150 Polymer.dom.flush();
98 }, 151 },
99 152
100 /** 153 /**
101 * Cycle through each entry in historyDataByDay_ and set all items to be 154 * Cycle through each entry in historyDataByDay_ and set all items to be
102 * unselected. 155 * unselected.
103 */ 156 */
104 unselectAllItems: function(overallItemCount) { 157 unselectAllItems: function(overallItemCount) {
105 var historyCardData = this.historyDataByDay_; 158 var historyCardData = this.historyDataByDay_;
106 159
107 for (var i = 0; i < historyCardData.length; i++) { 160 for (var i = 0; i < historyCardData.length; i++) {
(...skipping 13 matching lines...) Expand all
121 /** 174 /**
122 * Adds the given items into historyDataByDay_. Adds items to the last 175 * Adds the given items into historyDataByDay_. Adds items to the last
123 * existing day if the date matches, creates a new element otherwise. 176 * existing day if the date matches, creates a new element otherwise.
124 * @param {string} date The date of the history items. 177 * @param {string} date The date of the history items.
125 * @param {Array<HistoryEntry>} historyItems The list of history items for the 178 * @param {Array<HistoryEntry>} historyItems The list of history items for the
126 * current date. 179 * current date.
127 * @private 180 * @private
128 */ 181 */
129 appendHistoryData_: function(date, historyItems) { 182 appendHistoryData_: function(date, historyItems) {
130 var lastDay = this.historyDataByDay_.length - 1; 183 var lastDay = this.historyDataByDay_.length - 1;
131 if (lastDay > 0 && date == this.historyDataByDay_[lastDay].date) { 184 if (lastDay >= 0 && date == this.historyDataByDay_[lastDay].date) {
132 this.set('historyDataByDay_.' + lastDay + '.historyItems', 185 this.set('historyDataByDay_.' + lastDay + '.historyItems',
133 this.historyDataByDay_[lastDay].historyItems.concat(historyItems)); 186 this.historyDataByDay_[lastDay].historyItems.concat(historyItems));
134 } else { 187 } else {
135 this.push('historyDataByDay_', { 188 this.push('historyDataByDay_', {
136 date: date, 189 date: date,
137 historyItems: historyItems 190 historyItems: historyItems
138 }); 191 });
139 } 192 }
140 }, 193 },
141 194
142 /** 195 /**
143 * Called when the card manager is scrolled. 196 * Called when the card manager is scrolled.
144 * @private 197 * @private
145 */ 198 */
146 scrollHandler_: function() { 199 scrollHandler_: function() {
147 // Closes overflow menu on scroll. 200 // Closes overflow menu on scroll.
148 this.closeMenu(); 201 this.closeMenu();
149
150 this.loadMoreIfAtEnd_(); 202 this.loadMoreIfAtEnd_();
151 }, 203 },
152 204
153 /** 205 /**
154 * Requests the next list of results when the scrollbar is near the bottom 206 * Requests the next list of results when the scrollbar is near the bottom
155 * of the window. 207 * of the window.
156 */ 208 */
157 loadMoreIfAtEnd_: function() { 209 loadMoreIfAtEnd_: function() {
158 var scrollOffset = 10; 210 var scrollOffset = 10;
159 var scrollElem = this.$['infinite-list']; 211 var scrollElem = this.$$('#infinite-list');
tsergeant 2016/02/02 02:57:36 If you use hidden$=, then you won't need to worry
hsampson 2016/02/03 02:37:58 Done.
212 if ((scrollElem != undefined) && (scrollElem.scrollHeight <=
213 scrollElem.scrollTop + scrollElem.clientHeight + scrollOffset) &&
214 (scrollElem.scrollTop != 0)) {
215 chrome.send('queryHistory',
216 [this.searchTerm, 0, 0, this.lastVisitedTime, RESULTS_PER_PAGE]);
217 }
218 },
160 219
161 if (scrollElem.scrollHeight <= 220 /**
162 scrollElem.scrollTop + scrollElem.clientHeight + scrollOffset) { 221 * True if there are no results available and the page has finished loading.
163 chrome.send('queryHistory', 222 * @param {number} numberOfResults The length of historyDataByDay_.
164 ['', 0, 0, this.lastVisitedTime, RESULTS_PER_PAGE]); 223 * @return {boolean} Whether there are results to show.
165 } 224 * @private
225 */
226 noResults_: function(numberOfResults) {
227 return numberOfResults == 0 && !this.loading;
228 },
229
230 /**
231 * Sets the message displayed when there are no results. Displayed if there is
232 * no history at all or if the search returned no results.
233 * @private
234 */
235 noResultsMessage_: function() {
236 var messageId = this.searchTerm == '' ? 'noResults' : 'noSearchResults';
237 this.noResultsMessage = loadTimeData.getString(messageId);
166 } 238 }
167 }); 239 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698