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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 } | 93 } |
| 94 if (currentDate != undefined) | 94 if (currentDate != undefined) |
| 95 this.appendHistoryData_(currentDate, historyItems); | 95 this.appendHistoryData_(currentDate, historyItems); |
| 96 | 96 |
| 97 this.lastVisitedTime = historyItems[historyItems.length - 1].time; | 97 this.lastVisitedTime = historyItems[historyItems.length - 1].time; |
| 98 }, | 98 }, |
| 99 | 99 |
| 100 /** | 100 /** |
| 101 * Cycle through each entry in historyDataByDay_ and set all items to be | 101 * Cycle through each entry in historyDataByDay_ and set all items to be |
| 102 * unselected. | 102 * unselected. |
| 103 * @param {number} overallItemCount The number of items selected. | |
| 103 */ | 104 */ |
| 104 unselectAllItems: function(overallItemCount) { | 105 unselectAllItems: function(overallItemCount) { |
| 105 var historyCardData = this.historyDataByDay_; | 106 var historyCardData = this.historyDataByDay_; |
| 106 | 107 |
| 107 for (var i = 0; i < historyCardData.length; i++) { | 108 for (var i = 0; i < historyCardData.length; i++) { |
| 108 var items = historyCardData[i].historyItems; | 109 var items = historyCardData[i].historyItems; |
| 109 for (var j = 0; j < items.length; j++) { | 110 for (var j = 0; j < items.length; j++) { |
| 110 if (items[j].selected) { | 111 if (items[j].selected) { |
| 111 this.set('historyDataByDay_.' + i + '.historyItems.' + j + | 112 this.set('historyDataByDay_.' + i + '.historyItems.' + j + |
| 112 '.selected', false); | 113 '.selected', false); |
| 113 overallItemCount--; | 114 overallItemCount--; |
| 114 if (overallItemCount == 0) | 115 if (overallItemCount == 0) |
| 115 break; | 116 return; |
| 116 } | 117 } |
| 117 } | 118 } |
| 118 } | 119 } |
| 119 }, | 120 }, |
| 120 | 121 |
| 121 /** | 122 /** |
| 123 * Remove all selected items from the overall array so that they are also | |
| 124 * removed from view. Make sure that the card length and positioning is | |
| 125 * updated accordingly. | |
| 126 * @param {number} overallItemCount The number of items selected. | |
| 127 */ | |
| 128 removeDeletedHistory: function(overallItemCount) { | |
| 129 for (var i = 0; i < this.historyDataByDay_.length; i++) { | |
| 130 var items = this.historyDataByDay_[i].historyItems; | |
| 131 var itemDeletedFromCard = false; | |
| 132 | |
| 133 for (var j = items.length - 1; j >= 0; j--) { | |
|
tsergeant
2016/01/25 01:43:14
There's a problem here that is kinda tough to expl
hsampson
2016/01/25 04:15:42
As discussed the loop going through backwards is t
| |
| 134 if (items[j].selected) { | |
| 135 this.splice('historyDataByDay_.' + i + '.historyItems', j, 1); | |
| 136 itemDeletedFromCard = true; | |
| 137 overallItemCount--; | |
| 138 if (overallItemCount == 0) { | |
| 139 this.removeEmptyCards_(); | |
| 140 // If the last card has been removed don't try to update its size. | |
| 141 if (this.historyDataByDay_.length > i) { | |
|
tsergeant
2016/01/25 01:43:14
Remove {}
hsampson
2016/01/25 04:15:42
Done.
| |
| 142 this.$['infinite-list'].updateSizeForItem(i); | |
| 143 } | |
| 144 return; | |
| 145 } | |
| 146 } | |
| 147 } | |
| 148 if (itemDeletedFromCard) | |
| 149 this.$['infinite-list'].updateSizeForItem(i); | |
| 150 } | |
| 151 }, | |
| 152 | |
| 153 /** | |
| 154 * If a given day has had all the history it contains removed, remove this | |
| 155 * day from the array. | |
| 156 * @private | |
| 157 */ | |
| 158 removeEmptyCards_: function() { | |
| 159 var historyCards = this.historyDataByDay_; | |
| 160 for (var i = historyCards.length - 1; i > -1; i--) { | |
| 161 if (historyCards[i].historyItems.length == 0) { | |
| 162 this.splice('historyDataByDay_', i, 1); | |
| 163 } | |
| 164 } | |
| 165 }, | |
| 166 | |
| 167 /** | |
| 122 * Adds the given items into historyDataByDay_. Adds items to the last | 168 * Adds the given items into historyDataByDay_. Adds items to the last |
| 123 * existing day if the date matches, creates a new element otherwise. | 169 * existing day if the date matches, creates a new element otherwise. |
| 124 * @param {string} date The date of the history items. | 170 * @param {string} date The date of the history items. |
| 125 * @param {Array<HistoryEntry>} historyItems The list of history items for the | 171 * @param {Array<HistoryEntry>} historyItems The list of history items for the |
| 126 * current date. | 172 * current date. |
| 127 * @private | 173 * @private |
| 128 */ | 174 */ |
| 129 appendHistoryData_: function(date, historyItems) { | 175 appendHistoryData_: function(date, historyItems) { |
| 130 var lastDay = this.historyDataByDay_.length - 1; | 176 var lastDay = this.historyDataByDay_.length - 1; |
| 131 if (lastDay > 0 && date == this.historyDataByDay_[lastDay].date) { | 177 if (lastDay > 0 && date == this.historyDataByDay_[lastDay].date) { |
| 132 this.set('historyDataByDay_.' + lastDay + '.historyItems', | 178 this.set('historyDataByDay_.' + lastDay + '.historyItems', |
| 133 this.historyDataByDay_[lastDay].historyItems.concat(historyItems)); | 179 this.historyDataByDay_[lastDay].historyItems.concat(historyItems)); |
| 134 } else { | 180 } else { |
| 135 this.push('historyDataByDay_', { | 181 this.push('historyDataByDay_', { |
| 136 date: date, | 182 date: date, |
| 137 historyItems: historyItems | 183 historyItems: historyItems |
| 138 }); | 184 }); |
| 139 } | 185 } |
| 140 }, | 186 }, |
| 141 | 187 |
| 142 /** | 188 /** |
| 189 * Based on which items are selected, collect an array of the info required | |
| 190 * for chrome.send('removeHistory', ...). | |
| 191 * @param {number} count The number of items that are selected. | |
| 192 * @return {array} toBeRemoved An array of objects which contain information | |
| 193 * on which history-items should be deleted. | |
| 194 */ | |
| 195 getItemsToDelete: function(count) { | |
| 196 var toBeRemoved = []; | |
| 197 for (var i = 0; i < this.historyDataByDay_.length; i++) { | |
| 198 var items = this.historyDataByDay_[i].historyItems; | |
| 199 for (j = 0; j < items.length; j++) { | |
| 200 if (items[j].selected) { | |
| 201 | |
| 202 toBeRemoved.push({ | |
| 203 url: items[j].url, | |
| 204 timestamps: items[j].allTimestamps | |
| 205 }); | |
| 206 | |
| 207 count--; | |
| 208 if (count == 0) | |
| 209 return toBeRemoved; | |
| 210 } | |
| 211 } | |
| 212 } | |
| 213 }, | |
| 214 | |
| 215 /** | |
| 143 * Called when the card manager is scrolled. | 216 * Called when the card manager is scrolled. |
| 144 * @private | 217 * @private |
| 145 */ | 218 */ |
| 146 scrollHandler_: function() { | 219 scrollHandler_: function() { |
| 147 // Closes overflow menu on scroll. | 220 // Closes overflow menu on scroll. |
| 148 this.closeMenu(); | 221 this.closeMenu(); |
| 149 | 222 |
| 150 this.loadMoreIfAtEnd_(); | 223 this.loadMoreIfAtEnd_(); |
| 151 }, | 224 }, |
| 152 | 225 |
| 153 /** | 226 /** |
| 154 * Requests the next list of results when the scrollbar is near the bottom | 227 * Requests the next list of results when the scrollbar is near the bottom |
| 155 * of the window. | 228 * of the window. |
| 156 */ | 229 */ |
| 157 loadMoreIfAtEnd_: function() { | 230 loadMoreIfAtEnd_: function() { |
| 158 var scrollOffset = 10; | 231 var scrollOffset = 10; |
| 159 var scrollElem = this.$['infinite-list']; | 232 var scrollElem = this.$['infinite-list']; |
| 160 | 233 |
| 161 if (scrollElem.scrollHeight <= | 234 if (scrollElem.scrollHeight <= |
| 162 scrollElem.scrollTop + scrollElem.clientHeight + scrollOffset) { | 235 scrollElem.scrollTop + scrollElem.clientHeight + scrollOffset) { |
| 163 chrome.send('queryHistory', | 236 chrome.send('queryHistory', |
| 164 ['', 0, 0, this.lastVisitedTime, RESULTS_PER_PAGE]); | 237 ['', 0, 0, this.lastVisitedTime, RESULTS_PER_PAGE]); |
| 165 } | 238 } |
| 166 } | 239 } |
| 167 }); | 240 }); |
| OLD | NEW |