| 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 // The search term for the current query. Set when the query returns. | 9 // The search term for the current query. Set when the query returns. |
| 10 searchedTerm: { | 10 searchedTerm: { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 disableResultLoading: function() { | 79 disableResultLoading: function() { |
| 80 this.resultLoadingDisabled_ = true; | 80 this.resultLoadingDisabled_ = true; |
| 81 }, | 81 }, |
| 82 | 82 |
| 83 /** | 83 /** |
| 84 * Adds the newly updated history results into historyData_. Adds new fields | 84 * Adds the newly updated history results into historyData_. Adds new fields |
| 85 * for each result. | 85 * for each result. |
| 86 * @param {!Array<!HistoryEntry>} historyResults The new history results. | 86 * @param {!Array<!HistoryEntry>} historyResults The new history results. |
| 87 */ | 87 */ |
| 88 addNewResults: function(historyResults) { | 88 addNewResults: function(historyResults) { |
| 89 var results = historyResults.slice(); |
| 89 /** @type {IronScrollThresholdElement} */(this.$['scroll-threshold']) | 90 /** @type {IronScrollThresholdElement} */(this.$['scroll-threshold']) |
| 90 .clearTriggers(); | 91 .clearTriggers(); |
| 91 | 92 |
| 92 if (this.lastSearchedTerm_ != this.searchedTerm) { | 93 if (this.lastSearchedTerm_ != this.searchedTerm) { |
| 93 this.resultLoadingDisabled_ = false; | 94 this.resultLoadingDisabled_ = false; |
| 94 if (this.historyData_) | 95 if (this.historyData_) |
| 95 this.splice('historyData_', 0, this.historyData_.length); | 96 this.splice('historyData_', 0, this.historyData_.length); |
| 96 this.lastSearchedTerm_ = this.searchedTerm; | 97 this.lastSearchedTerm_ = this.searchedTerm; |
| 97 } | 98 } |
| 98 | 99 |
| 99 if (historyResults.length == 0) | |
| 100 return; | |
| 101 | |
| 102 // Creates a copy of historyResults to prevent accidentally modifying this | |
| 103 // field. | |
| 104 var results = historyResults.slice(); | |
| 105 | |
| 106 var currentDate = results[0].dateRelativeDay; | |
| 107 | |
| 108 for (var i = 0; i < results.length; i++) { | |
| 109 // Sets the default values for these fields to prevent undefined types. | |
| 110 results[i].selected = false; | |
| 111 results[i].readableTimestamp = | |
| 112 this.searchedTerm == '' ? | |
| 113 results[i].dateTimeOfDay : results[i].dateShort; | |
| 114 | |
| 115 if (results[i].dateRelativeDay != currentDate) { | |
| 116 currentDate = results[i].dateRelativeDay; | |
| 117 } | |
| 118 } | |
| 119 | |
| 120 if (this.historyData_) { | 100 if (this.historyData_) { |
| 121 // If we have previously received data, push the new items onto the | 101 // If we have previously received data, push the new items onto the |
| 122 // existing array. | 102 // existing array. |
| 123 results.unshift('historyData_'); | 103 results.unshift('historyData_'); |
| 124 this.push.apply(this, results); | 104 this.push.apply(this, results); |
| 125 } else { | 105 } else { |
| 126 // The first time we receive data, use set() to ensure the iron-list is | 106 // The first time we receive data, use set() to ensure the iron-list is |
| 127 // initialized correctly. | 107 // initialized correctly. |
| 128 this.set('historyData_', results); | 108 this.set('historyData_', results); |
| 129 } | 109 } |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 /** | 190 /** |
| 211 * Check whether the time difference between the given history item and the | 191 * Check whether the time difference between the given history item and the |
| 212 * next one is large enough for a spacer to be required. | 192 * next one is large enough for a spacer to be required. |
| 213 * @param {HistoryEntry} item | 193 * @param {HistoryEntry} item |
| 214 * @param {number} index The index of |item| in |historyData_|. | 194 * @param {number} index The index of |item| in |historyData_|. |
| 215 * @param {number} length The length of |historyData_|. | 195 * @param {number} length The length of |historyData_|. |
| 216 * @return {boolean} Whether or not time gap separator is required. | 196 * @return {boolean} Whether or not time gap separator is required. |
| 217 * @private | 197 * @private |
| 218 */ | 198 */ |
| 219 needsTimeGap_: function(item, index, length) { | 199 needsTimeGap_: function(item, index, length) { |
| 220 if (index >= length - 1 || length == 0) | 200 return md_history.HistoryItem.needsTimeGap( |
| 221 return false; | 201 this.historyData_, index, this.searchedTerm); |
| 222 | |
| 223 var currentItem = this.historyData_[index]; | |
| 224 var nextItem = this.historyData_[index + 1]; | |
| 225 | |
| 226 if (this.searchedTerm) | |
| 227 return currentItem.dateShort != nextItem.dateShort; | |
| 228 | |
| 229 return currentItem.time - nextItem.time > BROWSING_GAP_TIME && | |
| 230 currentItem.dateRelativeDay == nextItem.dateRelativeDay; | |
| 231 }, | 202 }, |
| 232 | 203 |
| 233 hasResults: function(historyDataLength) { | 204 hasResults: function(historyDataLength) { |
| 234 return historyDataLength > 0; | 205 return historyDataLength > 0; |
| 235 }, | 206 }, |
| 236 | 207 |
| 237 noResultsMessage_: function(searchedTerm, isLoading) { | 208 noResultsMessage_: function(searchedTerm, isLoading) { |
| 238 if (isLoading) | 209 if (isLoading) |
| 239 return ''; | 210 return ''; |
| 240 var messageId = searchedTerm !== '' ? 'noSearchResults' : 'noResults'; | 211 var messageId = searchedTerm !== '' ? 'noSearchResults' : 'noResults'; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 266 * @private | 237 * @private |
| 267 */ | 238 */ |
| 268 isCardEnd_: function(item, i, length) { | 239 isCardEnd_: function(item, i, length) { |
| 269 if (length == 0 || i > length - 1) | 240 if (length == 0 || i > length - 1) |
| 270 return false; | 241 return false; |
| 271 return i == length - 1 || | 242 return i == length - 1 || |
| 272 this.historyData_[i].dateRelativeDay != | 243 this.historyData_[i].dateRelativeDay != |
| 273 this.historyData_[i + 1].dateRelativeDay; | 244 this.historyData_[i + 1].dateRelativeDay; |
| 274 }, | 245 }, |
| 275 }); | 246 }); |
| OLD | NEW |