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-list', | 6 is: 'history-list', |
| 7 | 7 |
| 8 properties: { | 8 properties: { |
| 9 searchedTerm: { | 9 searchedTerm: { |
| 10 type: String, | 10 type: String, |
| 11 value: '', | 11 value: '', |
| 12 }, | 12 }, |
| 13 | 13 |
| 14 lastSearchedTerm_: String, | 14 lastSearchedTerm_: String, |
| 15 | 15 |
| 16 querying: Boolean, | 16 querying: Boolean, |
| 17 | 17 |
| 18 // An array of history entries in reverse chronological order. | 18 // An array of history entries in reverse chronological order. |
| 19 historyData: Array, | 19 historyData_: Array, |
| 20 | 20 |
| 21 resultLoadingDisabled_: { | 21 resultLoadingDisabled_: { |
| 22 type: Boolean, | 22 type: Boolean, |
| 23 value: false, | 23 value: false, |
| 24 }, | 24 }, |
| 25 }, | 25 }, |
| 26 | 26 |
| 27 listeners: { | 27 listeners: { |
| 28 'infinite-list.scroll': 'closeMenu_', | 28 'infinite-list.scroll': 'closeMenu_', |
| 29 'tap': 'closeMenu_', | 29 'tap': 'closeMenu_', |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 58 }, | 58 }, |
| 59 | 59 |
| 60 /** | 60 /** |
| 61 * Disables history result loading when there are no more history results. | 61 * Disables history result loading when there are no more history results. |
| 62 */ | 62 */ |
| 63 disableResultLoading: function() { | 63 disableResultLoading: function() { |
| 64 this.resultLoadingDisabled_ = true; | 64 this.resultLoadingDisabled_ = true; |
| 65 }, | 65 }, |
| 66 | 66 |
| 67 /** | 67 /** |
| 68 * Adds the newly updated history results into historyData. Adds new fields | 68 * Adds the newly updated history results into historyData_. Adds new fields |
| 69 * for each result. | 69 * for each result. |
| 70 * @param {!Array<!HistoryEntry>} historyResults The new history results. | 70 * @param {!Array<!HistoryEntry>} historyResults The new history results. |
| 71 */ | 71 */ |
| 72 addNewResults: function(historyResults) { | 72 addNewResults: function(historyResults) { |
| 73 /** @type {IronScrollThresholdElement} */(this.$['scroll-threshold']) | 73 /** @type {IronScrollThresholdElement} */(this.$['scroll-threshold']) |
| 74 .clearTriggers(); | 74 .clearTriggers(); |
| 75 | 75 |
| 76 if (this.lastSearchedTerm_ != this.searchedTerm) { | 76 if (this.lastSearchedTerm_ != this.searchedTerm) { |
| 77 this.resultLoadingDisabled_ = false; | 77 this.resultLoadingDisabled_ = false; |
| 78 if (this.historyData) | 78 if (this.historyData_) |
| 79 this.splice('historyData', 0, this.historyData.length); | 79 this.splice('historyData_', 0, this.historyData_.length); |
| 80 this.lastSearchedTerm_ = this.searchedTerm; | 80 this.lastSearchedTerm_ = this.searchedTerm; |
| 81 } | 81 } |
| 82 | 82 |
| 83 if (historyResults.length == 0) | 83 if (historyResults.length == 0) |
| 84 return; | 84 return; |
| 85 | 85 |
| 86 // Creates a copy of historyResults to prevent accidentally modifying this | 86 // Creates a copy of historyResults to prevent accidentally modifying this |
| 87 // field. | 87 // field. |
| 88 var results = historyResults.slice(); | 88 var results = historyResults.slice(); |
| 89 | 89 |
| 90 var currentDate = results[0].dateRelativeDay; | 90 var currentDate = results[0].dateRelativeDay; |
| 91 | 91 |
| 92 for (var i = 0; i < results.length; i++) { | 92 for (var i = 0; i < results.length; i++) { |
| 93 // Sets the default values for these fields to prevent undefined types. | 93 // Sets the default values for these fields to prevent undefined types. |
| 94 results[i].selected = false; | 94 results[i].selected = false; |
| 95 results[i].readableTimestamp = | 95 results[i].readableTimestamp = |
| 96 this.searchedTerm == '' ? | 96 this.searchedTerm == '' ? |
| 97 results[i].dateTimeOfDay : results[i].dateShort; | 97 results[i].dateTimeOfDay : results[i].dateShort; |
| 98 | 98 |
| 99 if (results[i].dateRelativeDay != currentDate) { | 99 if (results[i].dateRelativeDay != currentDate) { |
| 100 currentDate = results[i].dateRelativeDay; | 100 currentDate = results[i].dateRelativeDay; |
| 101 } | 101 } |
| 102 } | 102 } |
| 103 | 103 |
| 104 if (this.historyData) { | 104 if (this.historyData_) { |
| 105 // 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 |
| 106 // existing array. | 106 // existing array. |
| 107 results.unshift('historyData'); | 107 results.unshift('historyData_'); |
| 108 this.push.apply(this, results); | 108 this.push.apply(this, results); |
| 109 } else { | 109 } else { |
| 110 // 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 |
| 111 // initialized correctly. | 111 // initialized correctly. |
| 112 this.set('historyData', results); | 112 this.set('historyData_', results); |
| 113 } | 113 } |
| 114 }, | 114 }, |
| 115 | 115 |
| 116 /** | 116 /** |
| 117 * 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 |
| 118 * unselected. | 118 * unselected. |
| 119 * @param {number} overallItemCount The number of checkboxes selected. | 119 * @param {number} overallItemCount The number of checkboxes selected. |
| 120 */ | 120 */ |
| 121 unselectAllItems: function(overallItemCount) { | 121 unselectAllItems: function(overallItemCount) { |
| 122 if (this.historyData === undefined) | 122 if (this.historyData_ === undefined) |
| 123 return; | 123 return; |
| 124 | 124 |
| 125 for (var i = 0; i < this.historyData.length; i++) { | 125 for (var i = 0; i < this.historyData_.length; i++) { |
| 126 if (this.historyData[i].selected) { | 126 if (this.historyData_[i].selected) { |
| 127 this.set('historyData.' + i + '.selected', false); | 127 this.set('historyData_.' + i + '.selected', false); |
| 128 overallItemCount--; | 128 overallItemCount--; |
| 129 if (overallItemCount == 0) | 129 if (overallItemCount == 0) |
| 130 break; | 130 break; |
| 131 } | 131 } |
| 132 } | 132 } |
| 133 }, | 133 }, |
| 134 | 134 |
| 135 /** | 135 /** |
| 136 * Remove all selected items from the overall array so that they are also | 136 * Remove all selected items from the overall array so that they are also |
| 137 * removed from view. Make sure that the card length and positioning is | 137 * removed from view. Make sure that the card length and positioning is |
| 138 * updated accordingly. | 138 * updated accordingly. |
| 139 * @param {number} overallItemCount The number of items selected. | 139 * @param {number} overallItemCount The number of items selected. |
| 140 */ | 140 */ |
| 141 removeDeletedHistory: function(overallItemCount) { | 141 removeDeletedHistory: function(overallItemCount) { |
| 142 var splices = []; | 142 var splices = []; |
| 143 for (var i = this.historyData.length - 1; i >= 0; i--) { | 143 for (var i = this.historyData_.length - 1; i >= 0; i--) { |
| 144 if (!this.historyData[i].selected) | 144 if (!this.historyData_[i].selected) |
| 145 continue; | 145 continue; |
| 146 | 146 |
| 147 // Removes the selected item from historyData. Use unshift so |splices| | 147 // Removes the selected item from historyData_. Use unshift so |splices| |
| 148 // ends up in index order. | 148 // ends up in index order. |
| 149 splices.unshift({ | 149 splices.unshift({ |
| 150 index: i, | 150 index: i, |
| 151 removed: [this.historyData[i]], | 151 removed: [this.historyData_[i]], |
| 152 addedCount: 0, | 152 addedCount: 0, |
| 153 object: this.historyData, | 153 object: this.historyData_, |
| 154 type: 'splice' | 154 type: 'splice' |
| 155 }); | 155 }); |
| 156 this.historyData.splice(i, 1); | 156 this.historyData_.splice(i, 1); |
| 157 | 157 |
| 158 overallItemCount--; | 158 overallItemCount--; |
| 159 if (overallItemCount == 0) | 159 if (overallItemCount == 0) |
| 160 break; | 160 break; |
| 161 } | 161 } |
| 162 // notifySplices gives better performance than individually splicing as it | 162 // notifySplices gives better performance than individually splicing as it |
| 163 // batches all of the updates together. | 163 // batches all of the updates together. |
| 164 this.notifySplices('historyData', splices); | 164 this.notifySplices('historyData_', splices); |
| 165 }, | 165 }, |
| 166 | 166 |
| 167 /** | 167 /** |
| 168 * Based on which items are selected, collect an array of the info required | 168 * Based on which items are selected, collect an array of the info required |
| 169 * for chrome.send('removeHistory', ...). | 169 * for chrome.send('removeHistory', ...). |
| 170 * @param {number} count The number of items that are selected. | 170 * @param {number} count The number of items that are selected. |
| 171 * @return {Array<HistoryEntry>} toBeRemoved An array of objects which contain | 171 * @return {Array<HistoryEntry>} toBeRemoved An array of objects which contain |
| 172 * information on which history-items should be deleted. | 172 * information on which history-items should be deleted. |
| 173 */ | 173 */ |
| 174 getSelectedItems: function(count) { | 174 getSelectedItems: function(count) { |
| 175 var toBeRemoved = []; | 175 var toBeRemoved = []; |
| 176 for (var i = 0; i < this.historyData.length; i++) { | 176 for (var i = 0; i < this.historyData_.length; i++) { |
| 177 if (this.historyData[i].selected) { | 177 if (this.historyData_[i].selected) { |
| 178 toBeRemoved.push({ | 178 toBeRemoved.push({ |
| 179 url: this.historyData[i].url, | 179 url: this.historyData_[i].url, |
| 180 timestamps: this.historyData[i].allTimestamps | 180 timestamps: this.historyData_[i].allTimestamps |
| 181 }); | 181 }); |
| 182 | 182 |
| 183 count--; | 183 count--; |
| 184 if (count == 0) | 184 if (count == 0) |
| 185 break; | 185 break; |
| 186 } | 186 } |
| 187 } | 187 } |
| 188 return toBeRemoved; | 188 return toBeRemoved; |
| 189 }, | 189 }, |
| 190 | 190 |
| 191 /** | 191 /** |
| 192 * 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. |
| 193 * @private | 193 * @private |
| 194 */ | 194 */ |
| 195 loadMoreData_: function() { | 195 loadMoreData_: function() { |
| 196 if (this.resultLoadingDisabled_ || this.querying) | 196 if (this.resultLoadingDisabled_ || this.querying) |
| 197 return; | 197 return; |
| 198 | 198 |
| 199 this.fire('load-more-history'); | 199 this.fire('load-more-history'); |
| 200 }, | 200 }, |
| 201 | 201 |
| 202 /** | 202 /** |
| 203 * 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 |
| 204 * next one is large enough for a spacer to be required. | 204 * next one is large enough for a spacer to be required. |
| 205 * @param {HistoryEntry} item | 205 * @param {HistoryEntry} item |
| 206 * @param {number} index The index of |item| in |historyData|. | 206 * @param {number} index The index of |item| in |historyData_|. |
| 207 * @param {number} length The length of |historyData|. | 207 * @param {number} length The length of |historyData_|. |
| 208 * @return {boolean} Whether or not time gap separator is required. | 208 * @return {boolean} Whether or not time gap separator is required. |
| 209 * @private | 209 * @private |
| 210 */ | 210 */ |
| 211 needsTimeGap_: function(item, index, length) { | 211 needsTimeGap_: function(item, index, length) { |
| 212 if (index >= length - 1 || length == 0) | 212 if (index >= length - 1 || length == 0) |
| 213 return false; | 213 return false; |
| 214 | 214 |
| 215 var currentItem = this.historyData[index]; | 215 var currentItem = this.historyData_[index]; |
| 216 var nextItem = this.historyData[index + 1]; | 216 var nextItem = this.historyData_[index + 1]; |
| 217 | 217 |
| 218 if (this.searchedTerm) | 218 if (this.searchedTerm) |
| 219 return currentItem.dateShort != nextItem.dateShort; | 219 return currentItem.dateShort != nextItem.dateShort; |
| 220 | 220 |
| 221 return currentItem.time - nextItem.time > BROWSING_GAP_TIME && | 221 return currentItem.time - nextItem.time > BROWSING_GAP_TIME && |
| 222 currentItem.dateRelativeDay == nextItem.dateRelativeDay; | 222 currentItem.dateRelativeDay == nextItem.dateRelativeDay; |
| 223 }, | 223 }, |
| 224 | 224 |
| 225 hasResults: function(historyDataLength) { | 225 hasResults: function(historyData_Length) { |
|
tsergeant
2016/05/18 06:44:02
Nit: I would probably leave this one alone, it loo
calamity
2016/05/18 07:14:16
Fiiiiiine.
| |
| 226 return historyDataLength > 0; | 226 return historyData_Length > 0; |
| 227 }, | 227 }, |
| 228 | 228 |
| 229 noResultsMessage_: function(searchedTerm, isLoading) { | 229 noResultsMessage_: function(searchedTerm, isLoading) { |
| 230 if (isLoading) | 230 if (isLoading) |
| 231 return ''; | 231 return ''; |
| 232 var messageId = searchedTerm !== '' ? 'noSearchResults' : 'noResults'; | 232 var messageId = searchedTerm !== '' ? 'noSearchResults' : 'noResults'; |
| 233 return loadTimeData.getString(messageId); | 233 return loadTimeData.getString(messageId); |
| 234 }, | 234 }, |
| 235 | 235 |
| 236 /** | 236 /** |
| 237 * 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. |
| 238 * @param {HistoryEntry} item | 238 * @param {HistoryEntry} item |
| 239 * @param {number} i Index of |item| within |historyData|. | 239 * @param {number} i Index of |item| within |historyData_|. |
| 240 * @param {number} length | 240 * @param {number} length |
| 241 * @return {boolean} | 241 * @return {boolean} |
| 242 * @private | 242 * @private |
| 243 */ | 243 */ |
| 244 isCardStart_: function(item, i, length) { | 244 isCardStart_: function(item, i, length) { |
| 245 if (length == 0 || i > length - 1) | 245 if (length == 0 || i > length - 1) |
| 246 return false; | 246 return false; |
| 247 return i == 0 || | 247 return i == 0 || |
| 248 this.historyData[i].dateRelativeDay != | 248 this.historyData_[i].dateRelativeDay != |
| 249 this.historyData[i - 1].dateRelativeDay; | 249 this.historyData_[i - 1].dateRelativeDay; |
| 250 }, | 250 }, |
| 251 | 251 |
| 252 /** | 252 /** |
| 253 * True if the given item is the end of a card. | 253 * True if the given item is the end of a card. |
| 254 * @param {HistoryEntry} item | 254 * @param {HistoryEntry} item |
| 255 * @param {number} i Index of |item| within |historyData|. | 255 * @param {number} i Index of |item| within |historyData_|. |
| 256 * @param {number} length | 256 * @param {number} length |
| 257 * @return {boolean} | 257 * @return {boolean} |
| 258 * @private | 258 * @private |
| 259 */ | 259 */ |
| 260 isCardEnd_: function(item, i, length) { | 260 isCardEnd_: function(item, i, length) { |
| 261 if (length == 0 || i > length - 1) | 261 if (length == 0 || i > length - 1) |
| 262 return false; | 262 return false; |
| 263 return i == length - 1 || | 263 return i == length - 1 || |
| 264 this.historyData[i].dateRelativeDay != | 264 this.historyData_[i].dateRelativeDay != |
| 265 this.historyData[i + 1].dateRelativeDay; | 265 this.historyData_[i + 1].dateRelativeDay; |
| 266 }, | 266 }, |
| 267 }); | 267 }); |
| OLD | NEW |