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

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: Add TODO and remove console.logs. 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 d7156f6303f0627d786cd6572e4b606ab6340d8a..fbba6ad40e09d4ad746d16182f39ace33e3c384d 100644
--- a/chrome/browser/resources/md_history/history-card-manager.js
+++ b/chrome/browser/resources/md_history/history-card-manager.js
@@ -105,6 +105,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_;
@@ -125,6 +126,50 @@ Polymer({
},
/**
+ * 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) {
+ var itemDeletedFromCard = false;
+
+ for (var i = 0; i < this.historyDataByDay_.length; i++) {
+ var items = this.historyDataByDay_[i].historyItems;
+
+ for (var j = items.length - 1; j > -1; j--) {
+ if (items[j].selected) {
+ this.splice('historyDataByDay_.' + i + '.historyItems', j, 1);
+ itemDeletedFromCard = true;
tsergeant 2016/01/18 02:33:52 There's a subtle issue here: itemDeletedFromCard
hsampson 2016/01/19 23:41:39 Done.
+ overallItemCount--;
+ if (overallItemCount == 0)
+ break;
+ }
+ }
+ if (itemDeletedFromCard) {
tsergeant 2016/01/18 02:33:52 Nit: Remove {}
hsampson 2016/01/19 23:41:39 Done.
+ this.$['infinite-list'].updateSizeForItem(i);
+ }
+ 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.
+ break;
+ }
+ this.removeExtraCards_();
+ },
+
+ /**
+ * If a given day has had all the history it contains removed, remove this
+ * day from the array.
+ * @private
+ */
+ removeExtraCards_: function() {
tsergeant 2016/01/18 02:33:52 Nit: Rename to removeEmptyCards?
hsampson 2016/01/19 23:41:39 Done.
+ 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.
@@ -151,6 +196,35 @@ 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.
+ */
+ listOfItemsToDelete: function(count) {
tsergeant 2016/01/18 02:33:52 Nit: rename to getItemsToDelete
hsampson 2016/01/19 23:41:39 Done.
+ 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) {
tsergeant 2016/01/18 02:33:52 Nit: Remove {}
hsampson 2016/01/19 23:41:39 Done.
+ break;
+ }
+ }
+ }
+ }
+ return toBeRemoved;
+ },
+
+ /**
* Called when the card manager is scrolled.
*/
scrollHandler: function(e) {

Powered by Google App Engine
This is Rietveld 408576698