| 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-list', | 6 is: 'history-list', |
| 7 | 7 |
| 8 properties: { | 8 properties: { |
| 9 // An array of history entries in reverse chronological order. | 9 searchedTerm: { |
| 10 historyData: { | 10 type: String, |
| 11 type: Array | 11 value: '', |
| 12 }, | 12 }, |
| 13 | 13 |
| 14 // The time of access of the last history item in historyData. | 14 lastSearchedTerm_: String, |
| 15 lastVisitedTime: { | |
| 16 type: Number, | |
| 17 value: 0 | |
| 18 }, | |
| 19 | 15 |
| 20 searchTerm: { | 16 querying: Boolean, |
| 21 type: String, | |
| 22 value: '' | |
| 23 }, | |
| 24 | 17 |
| 25 // True if there is a pending request to the backend. | 18 // An array of history entries in reverse chronological order. |
| 26 loading_: { | 19 historyData: Array, |
| 27 type: Boolean, | |
| 28 value: true | |
| 29 }, | |
| 30 | 20 |
| 31 resultLoadingDisabled_: { | 21 resultLoadingDisabled_: { |
| 32 type: Boolean, | 22 type: Boolean, |
| 33 value: false | 23 value: false, |
| 34 }, | 24 }, |
| 35 }, | 25 }, |
| 36 | 26 |
| 37 listeners: { | 27 listeners: { |
| 38 'infinite-list.scroll': 'closeMenu_', | 28 'infinite-list.scroll': 'closeMenu_', |
| 39 'tap': 'closeMenu_', | 29 'tap': 'closeMenu_', |
| 40 'toggle-menu': 'toggleMenu_', | 30 'toggle-menu': 'toggleMenu_', |
| 41 }, | 31 }, |
| 42 | 32 |
| 43 /** | 33 /** |
| 44 * Closes the overflow menu. | 34 * Closes the overflow menu. |
| 45 * @private | 35 * @private |
| 46 */ | 36 */ |
| 47 closeMenu_: function() { | 37 closeMenu_: function() { |
| 48 /** @type {CrSharedMenuElement} */(this.$.sharedMenu).closeMenu(); | 38 /** @type {CrSharedMenuElement} */(this.$.sharedMenu).closeMenu(); |
| 49 }, | 39 }, |
| 50 | 40 |
| 51 /** | 41 /** |
| 52 * Mark the page as currently loading new data from the back-end. | |
| 53 */ | |
| 54 setLoading: function() { | |
| 55 this.loading_ = true; | |
| 56 }, | |
| 57 | |
| 58 /** | |
| 59 * Opens the overflow menu unless the menu is already open and the same button | 42 * Opens the overflow menu unless the menu is already open and the same button |
| 60 * is pressed. | 43 * is pressed. |
| 61 * @param {{detail: {itemIdentifier: !Object}}} e | 44 * @param {{detail: {itemIdentifier: !Object}}} e |
| 62 * @private | 45 * @private |
| 63 */ | 46 */ |
| 64 toggleMenu_: function(e) { | 47 toggleMenu_: function(e) { |
| 65 var target = e.detail.target; | 48 var target = e.detail.target; |
| 66 /** @type {CrSharedMenuElement} */(this.$.sharedMenu).toggleMenu( | 49 /** @type {CrSharedMenuElement} */(this.$.sharedMenu).toggleMenu( |
| 67 target, e.detail.itemIdentifier); | 50 target, e.detail.itemIdentifier); |
| 68 }, | 51 }, |
| 69 | 52 |
| 70 /** @private */ | 53 /** @private */ |
| 71 onMoreFromSiteTap_: function() { | 54 onMoreFromSiteTap_: function() { |
| 72 var menu = /** @type {CrSharedMenuElement} */(this.$.sharedMenu); | 55 var menu = /** @type {CrSharedMenuElement} */(this.$.sharedMenu); |
| 73 this.fire('search-changed', {search: menu.itemData.domain}); | 56 this.fire('search-domain', {domain: menu.itemData.domain}); |
| 74 menu.closeMenu(); | 57 menu.closeMenu(); |
| 75 }, | 58 }, |
| 76 | 59 |
| 77 /** | 60 /** |
| 78 * Disables history result loading when there are no more history results. | 61 * Disables history result loading when there are no more history results. |
| 79 */ | 62 */ |
| 80 disableResultLoading: function() { | 63 disableResultLoading: function() { |
| 81 this.resultLoadingDisabled_ = true; | 64 this.resultLoadingDisabled_ = true; |
| 82 }, | 65 }, |
| 83 | 66 |
| 84 /** | 67 /** |
| 85 * Adds the newly updated history results into historyData. Adds new fields | 68 * Adds the newly updated history results into historyData. Adds new fields |
| 86 * for each result. | 69 * for each result. |
| 87 * @param {!Array<!HistoryEntry>} historyResults The new history results. | 70 * @param {!Array<!HistoryEntry>} historyResults The new history results. |
| 88 * @param {string} searchTerm Search query used to find these results. | |
| 89 */ | 71 */ |
| 90 addNewResults: function(historyResults, searchTerm) { | 72 addNewResults: function(historyResults) { |
| 91 this.loading_ = false; | |
| 92 /** @type {IronScrollThresholdElement} */(this.$['scroll-threshold']) | 73 /** @type {IronScrollThresholdElement} */(this.$['scroll-threshold']) |
| 93 .clearTriggers(); | 74 .clearTriggers(); |
| 94 | 75 |
| 95 if (this.searchTerm != searchTerm) { | 76 if (this.lastSearchedTerm_ != this.searchedTerm) { |
| 96 this.resultLoadingDisabled_ = false; | 77 this.resultLoadingDisabled_ = false; |
| 97 if (this.historyData) | 78 if (this.historyData) |
| 98 this.splice('historyData', 0, this.historyData.length); | 79 this.splice('historyData', 0, this.historyData.length); |
| 99 this.searchTerm = searchTerm; | 80 this.lastSearchedTerm_ = this.searchedTerm; |
| 100 } | 81 } |
| 101 | 82 |
| 102 if (historyResults.length == 0) | 83 if (historyResults.length == 0) |
| 103 return; | 84 return; |
| 104 | 85 |
| 105 // Creates a copy of historyResults to prevent accidentally modifying this | 86 // Creates a copy of historyResults to prevent accidentally modifying this |
| 106 // field. | 87 // field. |
| 107 var results = historyResults.slice(); | 88 var results = historyResults.slice(); |
| 108 | 89 |
| 109 var currentDate = results[0].dateRelativeDay; | 90 var currentDate = results[0].dateRelativeDay; |
| 110 | 91 |
| 111 for (var i = 0; i < results.length; i++) { | 92 for (var i = 0; i < results.length; i++) { |
| 112 // Sets the default values for these fields to prevent undefined types. | 93 // Sets the default values for these fields to prevent undefined types. |
| 113 results[i].selected = false; | 94 results[i].selected = false; |
| 114 results[i].readableTimestamp = | 95 results[i].readableTimestamp = |
| 115 searchTerm == '' ? results[i].dateTimeOfDay : results[i].dateShort; | 96 this.searchedTerm == '' ? |
| 97 results[i].dateTimeOfDay : results[i].dateShort; |
| 116 | 98 |
| 117 if (results[i].dateRelativeDay != currentDate) { | 99 if (results[i].dateRelativeDay != currentDate) { |
| 118 currentDate = results[i].dateRelativeDay; | 100 currentDate = results[i].dateRelativeDay; |
| 119 } | 101 } |
| 120 } | 102 } |
| 121 | 103 |
| 122 if (this.historyData) { | 104 if (this.historyData) { |
| 123 // If we have previously received data, push the new items onto the | 105 // If we have previously received data, push the new items onto the |
| 124 // existing array. | 106 // existing array. |
| 125 results.unshift('historyData'); | 107 results.unshift('historyData'); |
| 126 this.push.apply(this, results); | 108 this.push.apply(this, results); |
| 127 } else { | 109 } else { |
| 128 // The first time we receive data, use set() to ensure the iron-list is | 110 // The first time we receive data, use set() to ensure the iron-list is |
| 129 // initialized correctly. | 111 // initialized correctly. |
| 130 this.set('historyData', results); | 112 this.set('historyData', results); |
| 131 } | 113 } |
| 132 | |
| 133 this.lastVisitedTime = this.historyData[this.historyData.length - 1].time; | |
| 134 }, | 114 }, |
| 135 | 115 |
| 136 /** | 116 /** |
| 137 * Cycle through each entry in historyData and set all items to be | 117 * Cycle through each entry in historyData and set all items to be |
| 138 * unselected. | 118 * unselected. |
| 139 * @param {number} overallItemCount The number of checkboxes selected. | 119 * @param {number} overallItemCount The number of checkboxes selected. |
| 140 */ | 120 */ |
| 141 unselectAllItems: function(overallItemCount) { | 121 unselectAllItems: function(overallItemCount) { |
| 142 if (this.historyData === undefined) | 122 if (this.historyData === undefined) |
| 143 return; | 123 return; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 } | 186 } |
| 207 } | 187 } |
| 208 return toBeRemoved; | 188 return toBeRemoved; |
| 209 }, | 189 }, |
| 210 | 190 |
| 211 /** | 191 /** |
| 212 * Called when the page is scrolled to near the bottom of the list. | 192 * Called when the page is scrolled to near the bottom of the list. |
| 213 * @private | 193 * @private |
| 214 */ | 194 */ |
| 215 loadMoreData_: function() { | 195 loadMoreData_: function() { |
| 216 if (this.resultLoadingDisabled_ || this.loading_) | 196 if (this.resultLoadingDisabled_ || this.querying) |
| 217 return; | 197 return; |
| 218 | 198 |
| 219 this.loading_ = true; | 199 this.fire('load-more-history'); |
| 220 chrome.send('queryHistory', | |
| 221 [this.searchTerm, 0, 0, this.lastVisitedTime, RESULTS_PER_PAGE]); | |
| 222 }, | 200 }, |
| 223 | 201 |
| 224 /** | 202 /** |
| 225 * Check whether the time difference between the given history item and the | 203 * Check whether the time difference between the given history item and the |
| 226 * next one is large enough for a spacer to be required. | 204 * next one is large enough for a spacer to be required. |
| 227 * @param {HistoryEntry} item | 205 * @param {HistoryEntry} item |
| 228 * @param {number} index The index of |item| in |historyData|. | 206 * @param {number} index The index of |item| in |historyData|. |
| 229 * @param {number} length The length of |historyData|. | 207 * @param {number} length The length of |historyData|. |
| 230 * @return {boolean} Whether or not time gap separator is required. | 208 * @return {boolean} Whether or not time gap separator is required. |
| 231 * @private | 209 * @private |
| 232 */ | 210 */ |
| 233 needsTimeGap_: function(item, index, length) { | 211 needsTimeGap_: function(item, index, length) { |
| 234 if (index >= length - 1 || length == 0) | 212 if (index >= length - 1 || length == 0) |
| 235 return false; | 213 return false; |
| 236 | 214 |
| 237 var currentItem = this.historyData[index]; | 215 var currentItem = this.historyData[index]; |
| 238 var nextItem = this.historyData[index + 1]; | 216 var nextItem = this.historyData[index + 1]; |
| 239 | 217 |
| 240 if (this.searchTerm) | 218 if (this.searchedTerm) |
| 241 return currentItem.dateShort != nextItem.dateShort; | 219 return currentItem.dateShort != nextItem.dateShort; |
| 242 | 220 |
| 243 return currentItem.time - nextItem.time > BROWSING_GAP_TIME && | 221 return currentItem.time - nextItem.time > BROWSING_GAP_TIME && |
| 244 currentItem.dateRelativeDay == nextItem.dateRelativeDay; | 222 currentItem.dateRelativeDay == nextItem.dateRelativeDay; |
| 245 }, | 223 }, |
| 246 | 224 |
| 247 hasResults: function(historyDataLength) { | 225 hasResults: function(historyDataLength) { |
| 248 return historyDataLength > 0; | 226 return historyDataLength > 0; |
| 249 }, | 227 }, |
| 250 | 228 |
| 251 noResultsMessage_: function(searchTerm, isLoading) { | 229 noResultsMessage_: function(searchedTerm, isLoading) { |
| 252 if (isLoading) | 230 if (isLoading) |
| 253 return ''; | 231 return ''; |
| 254 var messageId = searchTerm !== '' ? 'noSearchResults' : 'noResults'; | 232 var messageId = searchedTerm !== '' ? 'noSearchResults' : 'noResults'; |
| 255 return loadTimeData.getString(messageId); | 233 return loadTimeData.getString(messageId); |
| 256 }, | 234 }, |
| 257 | 235 |
| 258 /** | 236 /** |
| 259 * True if the given item is the beginning of a new card. | 237 * True if the given item is the beginning of a new card. |
| 260 * @param {HistoryEntry} item | 238 * @param {HistoryEntry} item |
| 261 * @param {number} i Index of |item| within |historyData|. | 239 * @param {number} i Index of |item| within |historyData|. |
| 262 * @param {number} length | 240 * @param {number} length |
| 263 * @return {boolean} | 241 * @return {boolean} |
| 264 * @private | 242 * @private |
| (...skipping 15 matching lines...) Expand all Loading... |
| 280 * @private | 258 * @private |
| 281 */ | 259 */ |
| 282 isCardEnd_: function(item, i, length) { | 260 isCardEnd_: function(item, i, length) { |
| 283 if (length == 0 || i > length - 1) | 261 if (length == 0 || i > length - 1) |
| 284 return false; | 262 return false; |
| 285 return i == length - 1 || | 263 return i == length - 1 || |
| 286 this.historyData[i].dateRelativeDay != | 264 this.historyData[i].dateRelativeDay != |
| 287 this.historyData[i + 1].dateRelativeDay; | 265 this.historyData[i + 1].dateRelativeDay; |
| 288 }, | 266 }, |
| 289 }); | 267 }); |
| OLD | NEW |