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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 } | 98 } |
| 99 this.appendHistoryData_(currentDate, historyItems); | 99 this.appendHistoryData_(currentDate, historyItems); |
| 100 | 100 |
| 101 this.lastVisitedTime = historyItems[historyItems.length - 1].time; | 101 this.lastVisitedTime = historyItems[historyItems.length - 1].time; |
| 102 this.$['infinite-list'].scrollTop = scrollPosition; | 102 this.$['infinite-list'].scrollTop = scrollPosition; |
| 103 }, | 103 }, |
| 104 | 104 |
| 105 /** | 105 /** |
| 106 * Cycle through each entry in historyDataByDay_ and set all items to be | 106 * Cycle through each entry in historyDataByDay_ and set all items to be |
| 107 * unselected. | 107 * unselected. |
| 108 * @param {number} overallItemCount the number of items selected. | |
| 108 */ | 109 */ |
| 109 unselectAllItems: function(overallItemCount) { | 110 unselectAllItems: function(overallItemCount) { |
| 110 var historyCardData = this.historyDataByDay_; | 111 var historyCardData = this.historyDataByDay_; |
| 111 | 112 |
| 112 for (var i = 0; i < historyCardData.length; i++) { | 113 for (var i = 0; i < historyCardData.length; i++) { |
| 113 var items = historyCardData[i].historyItems; | 114 var items = historyCardData[i].historyItems; |
| 114 for (var j = 0; j < items.length; j++) { | 115 for (var j = 0; j < items.length; j++) { |
| 115 if (items[j].selected) { | 116 if (items[j].selected) { |
| 116 this.set('historyDataByDay_.' + i + '.historyItems.' + j + | 117 this.set('historyDataByDay_.' + i + '.historyItems.' + j + |
| 117 '.selected', false); | 118 '.selected', false); |
| 118 overallItemCount--; | 119 overallItemCount--; |
| 119 if (overallItemCount == 0) { | 120 if (overallItemCount == 0) { |
| 120 break; | 121 break; |
| 121 } | 122 } |
| 122 } | 123 } |
| 123 } | 124 } |
| 124 } | 125 } |
| 125 }, | 126 }, |
| 126 | 127 |
| 127 /** | 128 /** |
| 129 * Remove all selected items from the overall array so that they are also | |
| 130 * removed from view. Make sure that the card length and positioning is | |
| 131 * updated accordingly. | |
| 132 * @param {number} overallItemCount the number of items selected. | |
| 133 */ | |
| 134 removeDeletedHistory: function(overallItemCount) { | |
| 135 var itemDeletedFromCard = false; | |
| 136 | |
| 137 for (var i = 0; i < this.historyDataByDay_.length; i++) { | |
| 138 var items = this.historyDataByDay_[i].historyItems; | |
| 139 | |
| 140 for (var j = items.length - 1; j > -1; j--) { | |
| 141 if (items[j].selected) { | |
| 142 this.splice('historyDataByDay_.' + i + '.historyItems', j, 1); | |
| 143 itemDeletedFromCard = true; | |
|
tsergeant
2016/01/18 02:33:52
There's a subtle issue here:
itemDeletedFromCard
hsampson
2016/01/19 23:41:39
Done.
| |
| 144 overallItemCount--; | |
| 145 if (overallItemCount == 0) | |
| 146 break; | |
| 147 } | |
| 148 } | |
| 149 if (itemDeletedFromCard) { | |
|
tsergeant
2016/01/18 02:33:52
Nit: Remove {}
hsampson
2016/01/19 23:41:39
Done.
| |
| 150 this.$['infinite-list'].updateSizeForItem(i); | |
| 151 } | |
| 152 if (overallItemCount == 0) | |
|
tsergeant
2016/01/18 02:33:52
Why is overallItemCount checked twice? Is it suffi
hsampson
2016/01/19 23:41:39
Done.
| |
| 153 break; | |
| 154 } | |
| 155 this.removeExtraCards_(); | |
| 156 }, | |
| 157 | |
| 158 /** | |
| 159 * If a given day has had all the history it contains removed, remove this | |
| 160 * day from the array. | |
| 161 * @private | |
| 162 */ | |
| 163 removeExtraCards_: function() { | |
|
tsergeant
2016/01/18 02:33:52
Nit: Rename to removeEmptyCards?
hsampson
2016/01/19 23:41:39
Done.
| |
| 164 var historyCards = this.historyDataByDay_; | |
| 165 for (var i = historyCards.length - 1; i > -1; i--) { | |
| 166 if (historyCards[i].historyItems.length == 0) { | |
| 167 this.splice('historyDataByDay_', i, 1); | |
| 168 } | |
| 169 } | |
| 170 }, | |
| 171 | |
| 172 /** | |
| 128 * Adds the given items into historyDataByDay_. Adds items to the last | 173 * Adds the given items into historyDataByDay_. Adds items to the last |
| 129 * existing day if the date matches, creates a new element otherwise. | 174 * existing day if the date matches, creates a new element otherwise. |
| 130 * @param {string} date The date of the history items. | 175 * @param {string} date The date of the history items. |
| 131 * @param {array} historyItems The list of history items for the current date. | 176 * @param {array} historyItems The list of history items for the current date. |
| 132 * @private | 177 * @private |
| 133 */ | 178 */ |
| 134 appendHistoryData_: function(date, historyItems) { | 179 appendHistoryData_: function(date, historyItems) { |
| 135 var lastIndex = this.historyDataByDay_.length - 1; | 180 var lastIndex = this.historyDataByDay_.length - 1; |
| 136 if (lastIndex > 0 && date == this.historyDataByDay_[lastIndex].date) { | 181 if (lastIndex > 0 && date == this.historyDataByDay_[lastIndex].date) { |
| 137 // A new object is required for the card to update due to iron-list's | 182 // A new object is required for the card to update due to iron-list's |
| 138 // pass by reference implementation. | 183 // pass by reference implementation. |
| 139 var items = this.historyDataByDay_[lastIndex] | 184 var items = this.historyDataByDay_[lastIndex] |
| 140 .historyItems.concat(historyItems); | 185 .historyItems.concat(historyItems); |
| 141 this.splice('historyDataByDay_', lastIndex, 1, { | 186 this.splice('historyDataByDay_', lastIndex, 1, { |
| 142 date: date, | 187 date: date, |
| 143 historyItems: items, | 188 historyItems: items, |
| 144 }); | 189 }); |
| 145 } else { | 190 } else { |
| 146 this.push('historyDataByDay_', { | 191 this.push('historyDataByDay_', { |
| 147 date: date, | 192 date: date, |
| 148 historyItems: historyItems | 193 historyItems: historyItems |
| 149 }); | 194 }); |
| 150 } | 195 } |
| 151 }, | 196 }, |
| 152 | 197 |
| 153 /** | 198 /** |
| 199 * Based on which items are selected, collect an array of the info required | |
| 200 * for chrome.send('removeHistory', ...). | |
| 201 * @param {number} count The number of items that are selected. | |
| 202 * @return {array} toBeRemoved An array of objects which contain information | |
| 203 * on which history-items should be deleted. | |
| 204 */ | |
| 205 listOfItemsToDelete: function(count) { | |
|
tsergeant
2016/01/18 02:33:52
Nit: rename to getItemsToDelete
hsampson
2016/01/19 23:41:39
Done.
| |
| 206 var toBeRemoved = []; | |
| 207 for (var i = 0; i < this.historyDataByDay_.length; i++) { | |
| 208 var items = this.historyDataByDay_[i].historyItems; | |
| 209 for (j = 0; j < items.length; j++) { | |
| 210 if (items[j].selected) { | |
| 211 | |
| 212 toBeRemoved.push({ | |
| 213 url: items[j].url, | |
| 214 timestamps: items[j].allTimestamps | |
| 215 }); | |
| 216 | |
| 217 count--; | |
| 218 if (count == 0) { | |
|
tsergeant
2016/01/18 02:33:52
Nit: Remove {}
hsampson
2016/01/19 23:41:39
Done.
| |
| 219 break; | |
| 220 } | |
| 221 } | |
| 222 } | |
| 223 } | |
| 224 return toBeRemoved; | |
| 225 }, | |
| 226 | |
| 227 /** | |
| 154 * Called when the card manager is scrolled. | 228 * Called when the card manager is scrolled. |
| 155 */ | 229 */ |
| 156 scrollHandler: function(e) { | 230 scrollHandler: function(e) { |
| 157 // Closes overflow menu on scroll. | 231 // Closes overflow menu on scroll. |
| 158 this.closeMenu(); | 232 this.closeMenu(); |
| 159 | 233 |
| 160 this.doInfiniteScroll_(e); | 234 this.doInfiniteScroll_(e); |
| 161 }, | 235 }, |
| 162 | 236 |
| 163 /** | 237 /** |
| 164 * Requests the next list of results when the scrollbar is near the bottom | 238 * Requests the next list of results when the scrollbar is near the bottom |
| 165 * of the window. | 239 * of the window. |
| 166 */ | 240 */ |
| 167 doInfiniteScroll_: function(e) { | 241 doInfiniteScroll_: function(e) { |
| 168 var scrollOffset = 10; | 242 var scrollOffset = 10; |
| 169 var scrollElem = e.srcElement; | 243 var scrollElem = e.srcElement; |
| 170 | 244 |
| 171 if (scrollElem.scrollHeight <= | 245 if (scrollElem.scrollHeight <= |
| 172 scrollElem.scrollTop + scrollElem.clientHeight + scrollOffset) { | 246 scrollElem.scrollTop + scrollElem.clientHeight + scrollOffset) { |
| 173 chrome.send('queryHistory', | 247 chrome.send('queryHistory', |
| 174 ['', 0, 0, this.lastVisitedTime, RESULTS_PER_PAGE]); | 248 ['', 0, 0, this.lastVisitedTime, RESULTS_PER_PAGE]); |
| 175 } | 249 } |
| 176 } | 250 } |
| 177 }); | 251 }); |
| OLD | NEW |