Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 // Message shown when no results available. Depends on searchTerm. | |
| 39 noResultsMessage_: { | |
| 40 type: String, | |
| 41 value: '' | |
| 42 }, | |
| 43 | |
| 44 // Page waits until results have finished loading before displaying message. | |
| 45 loading_: { | |
| 46 type: Boolean, | |
| 47 value: false | |
| 31 } | 48 } |
| 32 }, | 49 }, |
| 33 | 50 |
| 34 /** @const @private */ | 51 /** @const @private */ |
| 35 X_OFFSET_: 30, | 52 X_OFFSET_: 30, |
| 36 | 53 |
| 37 listeners: { | 54 listeners: { |
| 38 'tap': 'closeMenu', | 55 'tap': 'closeMenu', |
| 39 'toggle-menu': 'toggleMenu_' | 56 'toggle-menu': 'toggleMenu_' |
| 40 }, | 57 }, |
| 41 | 58 |
| 42 /** | 59 /** |
| 43 * Closes the overflow menu. | 60 * Closes the overflow menu. |
| 44 */ | 61 */ |
| 45 closeMenu: function() { | 62 closeMenu: function() { |
| 46 this.menuOpen = false; | 63 this.menuOpen = false; |
| 47 }, | 64 }, |
| 48 | 65 |
| 49 /** | 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); | |
|
tsergeant
2016/02/04 02:28:49
Have you thought about not replacing the old resul
hsampson
2016/02/08 04:40:23
Acknowledged.
| |
| 72 }, | |
| 73 | |
| 74 /** | |
| 50 * 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 |
| 51 * is pressed. | 76 * is pressed. |
| 52 * @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. |
| 53 * @private | 78 * @private |
| 54 */ | 79 */ |
| 55 toggleMenu_: function(e) { | 80 toggleMenu_: function(e) { |
| 56 var menu = this.$['overflow-menu']; | 81 var menu = this.$['overflow-menu']; |
| 57 | 82 |
| 58 // Menu closes if the same button is clicked. | 83 // Menu closes if the same button is clicked. |
| 59 if (this.menuOpen && this.menuIdentifier == e.detail.accessTime) { | 84 if (this.menuOpen && this.menuIdentifier == e.detail.accessTime) { |
| 60 this.closeMenu(); | 85 this.closeMenu(); |
| 61 } else { | 86 } else { |
| 62 this.menuOpen = true; | 87 this.menuOpen = true; |
| 63 this.menuIdentifier = e.detail.accessTime; | 88 this.menuIdentifier = e.detail.accessTime; |
| 64 | 89 |
| 65 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, |
| 66 cr.ui.AnchorType.BEFORE); | 91 cr.ui.AnchorType.BEFORE); |
| 67 | 92 |
| 68 menu.focus(); | 93 menu.focus(); |
| 69 } | 94 } |
| 70 }, | 95 }, |
| 71 | 96 |
| 72 /** | 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} search The search term used to find these results. | |
| 102 */ | |
| 103 reformatSearchResults_: function(results, search) { | |
| 104 for (var i = 0; i < results.length; i++) { | |
| 105 results[i].dateRelativeDay = search; | |
|
tsergeant
2016/02/04 02:28:49
On further thought, I don't like this pattern. It'
hsampson
2016/02/08 04:40:23
Done.
| |
| 106 results[i].dateTimeOfDay = results[i].dateShort; | |
| 107 results[i].historySearchTerm = search; | |
|
tsergeant
2016/02/08 22:59:01
What happened to historySearchTerm? Was it unused?
hsampson
2016/02/09 02:17:51
Yes it wasn't being used anywhere.
| |
| 108 } | |
| 109 }, | |
| 110 | |
| 111 /** | |
| 73 * 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 |
| 74 * accessed. | 113 * accessed. |
| 75 * @param {!Array<!HistoryEntry>} results The new history results. | 114 * @param {!Array<!HistoryEntry>} results The new history results. |
| 115 * @param {string} search The search term used for chrome.send. | |
| 76 */ | 116 */ |
| 77 addNewResults: function(results) { | 117 addNewResults: function(results, search) { |
| 78 if (results.length == 0) | 118 this.searchTerm = search; |
| 119 this.noResults_(); | |
| 120 | |
| 121 if (results.length == 0) { | |
| 122 this.loading_ = false; | |
| 79 return; | 123 return; |
| 124 } | |
| 125 | |
| 126 if (search != '') | |
| 127 this.reformatSearchResults_(results, search); | |
| 80 | 128 |
| 81 var dateSortedData = []; | 129 var dateSortedData = []; |
| 82 var historyItems = []; | 130 var historyItems = []; |
| 83 var currentDate = results[0].dateRelativeDay; | 131 var currentDate = results[0].dateRelativeDay; |
| 84 | 132 |
| 85 for (var i = 0; i < results.length; i++) { | 133 for (var i = 0; i < results.length; i++) { |
| 86 if (!currentDate) | 134 if (!currentDate) |
| 87 continue; | 135 continue; |
| 88 | 136 |
| 89 results[i].selected = false; | 137 results[i].selected = false; |
| 90 if (results[i].dateRelativeDay != currentDate) { | 138 if (results[i].dateRelativeDay != currentDate) { |
| 91 this.appendHistoryData_(currentDate, historyItems); | 139 this.appendHistoryData_(currentDate, historyItems); |
| 92 currentDate = results[i].dateRelativeDay; | 140 currentDate = results[i].dateRelativeDay; |
| 93 historyItems = []; | 141 historyItems = []; |
| 94 } | 142 } |
| 95 historyItems.push(results[i]); | 143 historyItems.push(results[i]); |
| 96 } | 144 } |
| 97 | 145 |
| 98 if (currentDate) | 146 if (currentDate) |
| 99 this.appendHistoryData_(currentDate, historyItems); | 147 this.appendHistoryData_(currentDate, historyItems); |
| 100 | 148 |
| 101 this.lastVisitedTime = historyItems[historyItems.length - 1].time; | 149 this.lastVisitedTime = historyItems[historyItems.length - 1].time; |
| 150 this.loading_ = false; | |
| 151 Polymer.dom.flush(); | |
| 102 }, | 152 }, |
| 103 | 153 |
| 104 /** | 154 /** |
| 105 * Cycle through each entry in historyDataByDay_ and set all items to be | 155 * Cycle through each entry in historyDataByDay_ and set all items to be |
| 106 * unselected. | 156 * unselected. |
| 107 */ | 157 */ |
| 108 unselectAllItems: function(overallItemCount) { | 158 unselectAllItems: function(overallItemCount) { |
| 109 var historyCardData = this.historyDataByDay_; | 159 var historyCardData = this.historyDataByDay_; |
| 110 | 160 |
| 111 for (var i = 0; i < historyCardData.length; i++) { | 161 for (var i = 0; i < historyCardData.length; i++) { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 125 /** | 175 /** |
| 126 * Adds the given items into historyDataByDay_. Adds items to the last | 176 * Adds the given items into historyDataByDay_. Adds items to the last |
| 127 * existing day if the date matches, creates a new element otherwise. | 177 * existing day if the date matches, creates a new element otherwise. |
| 128 * @param {string} date The date of the history items. | 178 * @param {string} date The date of the history items. |
| 129 * @param {!Array<!HistoryEntry>} historyItems The list of history items for | 179 * @param {!Array<!HistoryEntry>} historyItems The list of history items for |
| 130 * the current date. | 180 * the current date. |
| 131 * @private | 181 * @private |
| 132 */ | 182 */ |
| 133 appendHistoryData_: function(date, historyItems) { | 183 appendHistoryData_: function(date, historyItems) { |
| 134 var lastDay = this.historyDataByDay_.length - 1; | 184 var lastDay = this.historyDataByDay_.length - 1; |
| 135 if (lastDay > 0 && date == this.historyDataByDay_[lastDay].date) { | 185 if (lastDay >= 0 && date == this.historyDataByDay_[lastDay].date) { |
| 136 this.set('historyDataByDay_.' + lastDay + '.historyItems', | 186 this.set('historyDataByDay_.' + lastDay + '.historyItems', |
| 137 this.historyDataByDay_[lastDay].historyItems.concat(historyItems)); | 187 this.historyDataByDay_[lastDay].historyItems.concat(historyItems)); |
| 138 } else { | 188 } else { |
| 139 this.push('historyDataByDay_', { | 189 this.push('historyDataByDay_', { |
| 140 date: date, | 190 date: date, |
| 141 historyItems: historyItems | 191 historyItems: historyItems |
| 142 }); | 192 }); |
| 143 } | 193 } |
| 144 }, | 194 }, |
| 145 | 195 |
| 146 /** | 196 /** |
| 147 * Called when the card manager is scrolled. | 197 * Called when the card manager is scrolled. |
| 148 * @private | 198 * @private |
| 149 */ | 199 */ |
| 150 scrollHandler_: function() { | 200 scrollHandler_: function() { |
| 151 // Close overflow menu on scroll. | 201 // Close overflow menu on scroll. |
| 152 this.closeMenu(); | 202 this.closeMenu(); |
| 153 | 203 |
| 154 // Requests the next list of results when the scrollbar is near the bottom | 204 // Requests the next list of results when the scrollbar is near the bottom |
| 155 // of the window. | 205 // of the window. |
| 156 var scrollOffset = 10; | 206 var scrollOffset = 10; |
| 157 var scrollElem = this.$['infinite-list']; | 207 var scrollElem = this.$$('#infinite-list'); |
|
tsergeant
2016/02/04 02:28:49
infinite-list will always be present, so you can u
hsampson
2016/02/08 04:40:23
Done.
| |
| 208 if ((!this.loading_) && (scrollElem.scrollHeight <= | |
| 209 scrollElem.scrollTop + scrollElem.clientHeight + scrollOffset)) { | |
|
calamity
2016/02/05 02:30:10
nit: less parens.
hsampson
2016/02/08 04:40:23
Done.
| |
| 210 chrome.send('queryHistory', | |
| 211 [this.searchTerm, 0, 0, this.lastVisitedTime, RESULTS_PER_PAGE]); | |
| 212 } | |
| 213 }, | |
| 158 | 214 |
| 159 if (scrollElem.scrollHeight <= | 215 /** |
| 160 scrollElem.scrollTop + scrollElem.clientHeight + scrollOffset) { | 216 * True if there are results available or the page hasn't finished loading. |
| 161 chrome.send('queryHistory', | 217 * @param {number} numberOfResults The length of historyDataByDay_. |
| 162 ['', 0, 0, this.lastVisitedTime, RESULTS_PER_PAGE]); | 218 * @return {boolean} Whether there are results to show. |
| 163 } | 219 * @private |
| 220 */ | |
| 221 resultsAvailable_: function(numberOfResults) { | |
|
calamity
2016/02/05 02:30:10
Does this run? It needs an underscore?
hsampson
2016/02/08 04:40:23
Yes it runs.
| |
| 222 return numberOfResults != 0 || this.loading_; | |
| 223 }, | |
| 224 | |
| 225 /** | |
| 226 * Sets the message displayed when there are no results. Displayed if there is | |
| 227 * no history at all or if the search returned no results. | |
| 228 * @private | |
| 229 */ | |
| 230 noResults_: function() { | |
| 231 var messageId = this.searchTerm == '' ? 'noResults' : 'noSearchResults'; | |
| 232 this.noResultsMessage_ = loadTimeData.getString(messageId); | |
| 164 } | 233 } |
| 165 }); | 234 }); |
| OLD | NEW |