Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1888)

Unified Diff: chrome/browser/resources/md_history/history_card_manager.js

Issue 1586373002: MD History: Delete button in the toolbar allows deletion of multiple history-items. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@patch_to_be_uploaded
Patch Set: Address reviewer comments. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 6f9cae24671a0f2ac9b27d3a60f208f0c4db943e..20f4d7f970aaf3cb8d22cf2c4fb56ff70bab7dbd 100644
--- a/chrome/browser/resources/md_history/history_card_manager.js
+++ b/chrome/browser/resources/md_history/history_card_manager.js
@@ -100,6 +100,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_;
@@ -112,13 +113,58 @@ 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--) {
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
+ if (items[j].selected) {
+ 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) {
tsergeant 2016/01/25 01:43:14 Remove {}
hsampson 2016/01/25 04:15:42 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
+ * day from the array.
+ * @private
+ */
+ removeEmptyCards_: function() {
+ var historyCards = this.historyDataByDay_;
+ for (var i = historyCards.length - 1; i > -1; 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.
@@ -140,6 +186,33 @@ 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} toBeRemoved An array of objects which contain information
+ * on which history-items should be deleted.
+ */
+ getItemsToDelete: function(count) {
+ var toBeRemoved = [];
+ for (var i = 0; i < this.historyDataByDay_.length; i++) {
+ var items = this.historyDataByDay_[i].historyItems;
+ for (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;
+ }
+ }
+ }
+ },
+
+ /**
* Called when the card manager is scrolled.
* @private
*/

Powered by Google App Engine
This is Rietveld 408576698