Chromium Code Reviews| Index: chrome/browser/resources/md_history/history_card_manager.js |
| diff --git a/chrome/browser/resources/md_history/history_card_manager.js b/chrome/browser/resources/md_history/history_card_manager.js |
| index 6844515fc8ce23f55f008b3a95b2e296ce5c8484..dac054984329373beccaa422c97b4f0c6c3ae956 100644 |
| --- a/chrome/browser/resources/md_history/history_card_manager.js |
| +++ b/chrome/browser/resources/md_history/history_card_manager.js |
| @@ -104,6 +104,7 @@ Polymer({ |
| /** |
| * Cycle through each entry in historyDataByDay_ and set all items to be |
| * unselected. |
| + * @param {number} overallItemCount The number of items selected. |
| */ |
| unselectAllItems: function(overallItemCount) { |
| var historyCardData = this.historyDataByDay_; |
| @@ -116,13 +117,57 @@ Polymer({ |
| '.selected', false); |
| overallItemCount--; |
| if (overallItemCount == 0) |
| - break; |
| + return; |
| } |
| } |
| } |
| }, |
| /** |
| + * Remove all selected items from the overall array so that they are also |
| + * removed from view. Make sure that the card length and positioning is |
| + * updated accordingly. |
| + * @param {number} overallItemCount The number of items selected. |
| + */ |
| + removeDeletedHistory: function(overallItemCount) { |
| + for (var i = 0; i < this.historyDataByDay_.length; i++) { |
| + var items = this.historyDataByDay_[i].historyItems; |
| + var itemDeletedFromCard = false; |
| + |
| + for (var j = items.length - 1; j >= 0; j--) { |
| + if (items[j].selected) { |
|
calamity
2016/02/02 05:34:58
nit: Invert and use continue.
hsampson
2016/02/02 22:59:53
Done.
|
| + this.splice('historyDataByDay_.' + i + '.historyItems', j, 1); |
| + itemDeletedFromCard = true; |
| + overallItemCount--; |
| + if (overallItemCount == 0) { |
| + this.removeEmptyCards_(); |
| + // If the last card has been removed don't try to update its size. |
| + if (this.historyDataByDay_.length > i) |
|
calamity
2016/02/02 05:34:58
nit: Flip this around. Seeing a greater than compa
hsampson
2016/02/02 22:59:53
Done.
|
| + this.$['infinite-list'].updateSizeForItem(i); |
| + return; |
| + } |
| + } |
| + } |
| + if (itemDeletedFromCard) |
| + this.$['infinite-list'].updateSizeForItem(i); |
| + } |
| + }, |
| + |
| + /** |
| + * If a given day has had all the history it contains removed, remove this |
|
tsergeant
2016/02/02 03:36:51
Nit: Reword this comment.
The word 'given' implie
hsampson
2016/02/02 22:59:53
Done.
|
| + * day from the array. |
| + * @private |
| + */ |
| + removeEmptyCards_: function() { |
| + var historyCards = this.historyDataByDay_; |
| + for (var i = historyCards.length - 1; i >= 0; i--) { |
| + if (historyCards[i].historyItems.length == 0) { |
| + this.splice('historyDataByDay_', i, 1); |
| + } |
| + } |
| + }, |
| + |
| + /** |
| * Adds the given items into historyDataByDay_. Adds items to the last |
| * existing day if the date matches, creates a new element otherwise. |
| * @param {string} date The date of the history items. |
| @@ -144,6 +189,34 @@ Polymer({ |
| }, |
| /** |
| + * Based on which items are selected, collect an array of the info required |
| + * for chrome.send('removeHistory', ...). |
| + * @param {number} count The number of items that are selected. |
| + * @return {Array<HistoryEntry>} toBeRemoved An array of objects which contain |
| + * information on which history-items should be deleted. |
| + */ |
| + getItemsToDelete: function(count) { |
|
calamity
2016/02/02 05:34:58
nit: getSelectedItems?
hsampson
2016/02/02 22:59:53
Done.
|
| + var toBeRemoved = []; |
| + for (var i = 0; i < this.historyDataByDay_.length; i++) { |
| + var items = this.historyDataByDay_[i].historyItems; |
| + for (var j = 0; j < items.length; j++) { |
| + if (items[j].selected) { |
| + |
| + toBeRemoved.push({ |
| + url: items[j].url, |
| + timestamps: items[j].allTimestamps |
| + }); |
| + |
| + count--; |
| + if (count == 0) |
| + return toBeRemoved; |
| + } |
| + } |
| + } |
| + return toBeRemoved; |
| + }, |
| + |
| + /** |
| * Called when the card manager is scrolled. |
| * @private |
| */ |