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

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: add tests for deletion and logic for supervised users. 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..cec3ee2e279c6a6d550757c8657a4aea6d7281c6 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.
calamity 2016/01/21 00:11:08 nit: Capitalize 'The' since it's the start of the
hsampson 2016/01/21 05:34:47 Done.
*/
unselectAllItems: function(overallItemCount) {
var historyCardData = this.historyDataByDay_;
@@ -112,13 +113,60 @@ 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) {
+ 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--) {
calamity 2016/01/21 00:11:08 j >= 0 tends to be the usual way to do this.
hsampson 2016/01/21 05:34:46 Done.
+ 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) {
+ this.$['infinite-list'].updateSizeForItem(i);
+ }
+ return;
+ }
+ }
+ }
+ if (itemDeletedFromCard)
+ this.$['infinite-list'].updateSizeForItem(i);
+ itemDeletedFromCard = false;
calamity 2016/01/21 00:11:08 Instead of doing this, just move the declaration o
hsampson 2016/01/21 05:34:46 Done.
+ }
+ },
+
+ /**
+ * 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 +188,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} toBeRemoved An array of objects which contain information
+ * on which history-items should be deleted.
+ */
+ getItemsToDelete: function(count) {
calamity 2016/01/21 00:11:08 After a small chat with Tim, I think there's a pos
hsampson 2016/01/21 05:34:46 Once all of the big cls are uploaded I will create
tsergeant 2016/01/25 01:43:14 Chris and I have ~even more~ ideas about how to do
+ 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)
+ break;
calamity 2016/01/21 00:11:08 Change this to return toBeRemoved;
hsampson 2016/01/21 05:34:46 Done.
+ }
+ }
+ }
+ return toBeRemoved;
+ },
+
+ /**
* Called when the card manager is scrolled.
* @private
*/

Powered by Google App Engine
This is Rietveld 408576698