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 // An array of history entries in reverse chronological order. | 9 // An array of history entries in reverse chronological order. |
| 10 historyData: { | 10 historyData: { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 | 98 |
| 99 if (historyResults.length == 0) | 99 if (historyResults.length == 0) |
| 100 return; | 100 return; |
| 101 | 101 |
| 102 // Creates a copy of historyResults to prevent accidentally modifying this | 102 // Creates a copy of historyResults to prevent accidentally modifying this |
| 103 // field. | 103 // field. |
| 104 var results = historyResults.slice(); | 104 var results = historyResults.slice(); |
| 105 | 105 |
| 106 var currentDate = results[0].dateRelativeDay; | 106 var currentDate = results[0].dateRelativeDay; |
| 107 | 107 |
| 108 // Resets the last history item for the currentDate if new history results | |
| 109 // for currentDate is loaded. | |
| 110 if (this.historyData && this.historyData.length > 0) { | |
| 111 var lastHistoryItem = this.historyData[this.historyData.length - 1]; | |
| 112 if (lastHistoryItem && lastHistoryItem.dateRelativeDay == currentDate) { | |
| 113 this.set('historyData.' + (this.historyData.length - 1) + | |
| 114 '.isLastItem', false); | |
| 115 } | |
| 116 } | |
| 117 | |
| 118 for (var i = 0; i < results.length; i++) { | 108 for (var i = 0; i < results.length; i++) { |
| 119 // Sets the default values for these fields to prevent undefined types. | 109 // Sets the default values for these fields to prevent undefined types. |
| 120 results[i].selected = false; | 110 results[i].selected = false; |
| 121 results[i].isLastItem = false; | |
| 122 results[i].isFirstItem = false; | |
| 123 results[i].needsTimeGap = this.needsTimeGap_(results, i); | |
| 124 results[i].readableTimestamp = | 111 results[i].readableTimestamp = |
| 125 searchTerm == '' ? results[i].dateTimeOfDay : results[i].dateShort; | 112 searchTerm == '' ? results[i].dateTimeOfDay : results[i].dateShort; |
| 126 | 113 |
| 127 if (results[i].dateRelativeDay != currentDate) { | 114 if (results[i].dateRelativeDay != currentDate) { |
| 128 results[i - 1].isLastItem = true; | |
| 129 results[i].isFirstItem = true; | |
| 130 currentDate = results[i].dateRelativeDay; | 115 currentDate = results[i].dateRelativeDay; |
| 131 } | 116 } |
| 132 } | 117 } |
| 133 results[i - 1].isLastItem = true; | |
| 134 | |
| 135 if (!this.historyData || this.historyData.length == 0) | |
| 136 results[0].isFirstItem = true; | |
| 137 | 118 |
| 138 if (this.historyData) { | 119 if (this.historyData) { |
| 139 // If we have previously received data, push the new items onto the | 120 // If we have previously received data, push the new items onto the |
| 140 // existing array. | 121 // existing array. |
| 141 results.unshift('historyData'); | 122 results.unshift('historyData'); |
| 142 this.push.apply(this, results); | 123 this.push.apply(this, results); |
| 143 } else { | 124 } else { |
| 144 // The first time we receive data, use set() to ensure the iron-list is | 125 // The first time we receive data, use set() to ensure the iron-list is |
| 145 // initialized correctly. | 126 // initialized correctly. |
| 146 this.set('historyData', results); | 127 this.set('historyData', results); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 172 * Remove all selected items from the overall array so that they are also | 153 * Remove all selected items from the overall array so that they are also |
| 173 * removed from view. Make sure that the card length and positioning is | 154 * removed from view. Make sure that the card length and positioning is |
| 174 * updated accordingly. | 155 * updated accordingly. |
| 175 * @param {number} overallItemCount The number of items selected. | 156 * @param {number} overallItemCount The number of items selected. |
| 176 */ | 157 */ |
| 177 removeDeletedHistory: function(overallItemCount) { | 158 removeDeletedHistory: function(overallItemCount) { |
| 178 for (var i = this.historyData.length - 1; i >= 0; i--) { | 159 for (var i = this.historyData.length - 1; i >= 0; i--) { |
| 179 if (!this.historyData[i].selected) | 160 if (!this.historyData[i].selected) |
| 180 continue; | 161 continue; |
| 181 | 162 |
| 182 // TODO: Change to using computed properties to recompute the first and | |
| 183 // last cards. | |
| 184 | |
| 185 // Resets the first history item. | |
| 186 if (this.historyData[i].isFirstItem && | |
| 187 (i + 1) < this.historyData.length && | |
| 188 this.historyData[i].dateRelativeDay == | |
| 189 this.historyData[i + 1].dateRelativeDay) { | |
| 190 this.set('historyData.' + (i + 1) + '.isFirstItem', true); | |
| 191 } | |
| 192 | |
| 193 // Resets the last history item. | |
| 194 if (this.historyData[i].isLastItem && i > 0 && | |
| 195 this.historyData[i].dateRelativeDay == | |
| 196 this.historyData[i - 1].dateRelativeDay) { | |
| 197 this.set('historyData.' + (i - 1) + '.isLastItem', true); | |
| 198 | |
| 199 if (this.historyData[i - 1].needsTimeGap) | |
| 200 this.set('historyData.' + (i - 1) + '.needsTimeGap', false); | |
| 201 } | |
| 202 | |
| 203 // Makes sure that the time gap separators are preserved. | |
| 204 if (this.historyData[i].needsTimeGap && i > 0) | |
| 205 this.set('historyData.' + (i - 1) + '.needsTimeGap', true); | |
| 206 | |
| 207 // Removes the selected item from historyData. | |
|
Dan Beam
2016/04/12 19:08:29
mayyyyyyyyyybe keep this comment?
tsergeant
2016/04/12 23:44:00
Done.
| |
| 208 this.splice('historyData', i, 1); | 163 this.splice('historyData', i, 1); |
| 209 | 164 |
| 210 overallItemCount--; | 165 overallItemCount--; |
| 211 if (overallItemCount == 0) | 166 if (overallItemCount == 0) |
| 212 break; | 167 break; |
| 213 } | 168 } |
| 214 }, | 169 }, |
| 215 | 170 |
| 216 /** | 171 /** |
| 217 * Based on which items are selected, collect an array of the info required | 172 * Based on which items are selected, collect an array of the info required |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 scrollElem.scrollTop + scrollElem.clientHeight + scrollOffset) { | 209 scrollElem.scrollTop + scrollElem.clientHeight + scrollOffset) { |
| 255 this.loading_ = true; | 210 this.loading_ = true; |
| 256 chrome.send('queryHistory', | 211 chrome.send('queryHistory', |
| 257 [this.searchTerm, 0, 0, this.lastVisitedTime, RESULTS_PER_PAGE]); | 212 [this.searchTerm, 0, 0, this.lastVisitedTime, RESULTS_PER_PAGE]); |
| 258 } | 213 } |
| 259 }, | 214 }, |
| 260 | 215 |
| 261 /** | 216 /** |
| 262 * Check whether the time difference between the given history item and the | 217 * Check whether the time difference between the given history item and the |
| 263 * next one is large enough for a spacer to be required. | 218 * next one is large enough for a spacer to be required. |
| 264 * @param {Array<HistoryEntry>} results A list of history results. | 219 * @param {HistoryEntry} item |
| 265 * @param {number} index The index number of the first item being compared. | 220 * @param {number} index The index of |item| in |historyData|. |
| 221 * @param {number} length The length of |historyData|. | |
| 266 * @return {boolean} Whether or not time gap separator is required. | 222 * @return {boolean} Whether or not time gap separator is required. |
| 267 * @private | 223 * @private |
| 268 */ | 224 */ |
| 269 needsTimeGap_: function(results, index) { | 225 needsTimeGap_: function(item, index, length) { |
| 270 // TODO(tsergeant): Allow the final item from one batch of results to have a | 226 if (index >= length - 1 || length == 0) |
| 271 // timegap once more results are added. | |
| 272 if (index == results.length - 1) | |
| 273 return false; | 227 return false; |
| 274 | 228 |
| 275 var currentItem = results[index]; | 229 var currentItem = this.historyData[index]; |
| 276 var nextItem = results[index + 1]; | 230 var nextItem = this.historyData[index + 1]; |
| 277 | 231 |
| 278 if (this.searchTerm) | 232 if (this.searchTerm) |
| 279 return currentItem.dateShort != nextItem.dateShort; | 233 return currentItem.dateShort != nextItem.dateShort; |
| 280 | 234 |
| 281 return currentItem.time - nextItem.time > BROWSING_GAP_TIME && | 235 return currentItem.time - nextItem.time > BROWSING_GAP_TIME && |
| 282 currentItem.dateRelativeDay == nextItem.dateRelativeDay; | 236 currentItem.dateRelativeDay == nextItem.dateRelativeDay; |
| 283 }, | 237 }, |
| 284 | 238 |
| 285 hasResults: function(historyDataLength) { | 239 hasResults: function(historyDataLength) { |
| 286 return historyDataLength > 0; | 240 return historyDataLength > 0; |
| 287 }, | 241 }, |
| 288 | 242 |
| 289 noResultsMessage_: function(searchTerm, isLoading) { | 243 noResultsMessage_: function(searchTerm, isLoading) { |
| 290 if (isLoading) | 244 if (isLoading) |
| 291 return ''; | 245 return ''; |
| 292 var messageId = searchTerm !== '' ? 'noSearchResults' : 'noResults'; | 246 var messageId = searchTerm !== '' ? 'noSearchResults' : 'noResults'; |
| 293 return loadTimeData.getString(messageId); | 247 return loadTimeData.getString(messageId); |
| 294 } | 248 }, |
| 249 | |
| 250 /** | |
| 251 * True if the given item is the beginning of a new card. | |
| 252 * @param {HistoryEntry} item | |
| 253 * @param {number} i | |
|
Dan Beam
2016/04/12 19:08:29
d
ocument more for 1 character variables, I'd
tsergeant
2016/04/12 23:44:00
Done.
| |
| 254 * @param {number} length | |
| 255 * @return {boolean} | |
| 256 * @private | |
| 257 */ | |
| 258 isCardStart_: function(item, i, length) { | |
| 259 if (length == 0 || i > length - 1) | |
| 260 return false; | |
| 261 return i == 0 || | |
| 262 this.historyData[i].dateRelativeDay != | |
| 263 this.historyData[i - 1].dateRelativeDay; | |
| 264 }, | |
| 265 | |
| 266 /** | |
| 267 * True if the given item is the end of a card. | |
| 268 * @param {HistoryEntry} item | |
| 269 * @param {number} i | |
|
Dan Beam
2016/04/12 19:08:29
s
ame
tsergeant
2016/04/12 23:44:00
Done.
| |
| 270 * @param {number} length | |
| 271 * @return {boolean} | |
| 272 * @private | |
| 273 */ | |
| 274 isCardEnd_: function(item, i, length) { | |
| 275 if (length == 0 || i > length - 1) | |
| 276 return false; | |
| 277 return i == length - 1 || | |
| 278 this.historyData[i].dateRelativeDay != | |
| 279 this.historyData[i + 1].dateRelativeDay; | |
| 280 }, | |
| 295 }); | 281 }); |
| OLD | NEW |