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

Side by Side 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 unified diff | Download patch
OLDNEW
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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 } 93 }
94 if (currentDate != undefined) 94 if (currentDate != undefined)
95 this.appendHistoryData_(currentDate, historyItems); 95 this.appendHistoryData_(currentDate, historyItems);
96 96
97 this.lastVisitedTime = historyItems[historyItems.length - 1].time; 97 this.lastVisitedTime = historyItems[historyItems.length - 1].time;
98 }, 98 },
99 99
100 /** 100 /**
101 * Cycle through each entry in historyDataByDay_ and set all items to be 101 * Cycle through each entry in historyDataByDay_ and set all items to be
102 * unselected. 102 * unselected.
103 * @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.
103 */ 104 */
104 unselectAllItems: function(overallItemCount) { 105 unselectAllItems: function(overallItemCount) {
105 var historyCardData = this.historyDataByDay_; 106 var historyCardData = this.historyDataByDay_;
106 107
107 for (var i = 0; i < historyCardData.length; i++) { 108 for (var i = 0; i < historyCardData.length; i++) {
108 var items = historyCardData[i].historyItems; 109 var items = historyCardData[i].historyItems;
109 for (var j = 0; j < items.length; j++) { 110 for (var j = 0; j < items.length; j++) {
110 if (items[j].selected) { 111 if (items[j].selected) {
111 this.set('historyDataByDay_.' + i + '.historyItems.' + j + 112 this.set('historyDataByDay_.' + i + '.historyItems.' + j +
112 '.selected', false); 113 '.selected', false);
113 overallItemCount--; 114 overallItemCount--;
114 if (overallItemCount == 0) 115 if (overallItemCount == 0)
115 break; 116 return;
116 } 117 }
117 } 118 }
118 } 119 }
119 }, 120 },
120 121
121 /** 122 /**
123 * Remove all selected items from the overall array so that they are also
124 * removed from view. Make sure that the card length and positioning is
125 * updated accordingly.
126 * @param {number} overallItemCount the number of items selected.
127 */
128 removeDeletedHistory: function(overallItemCount) {
129 var itemDeletedFromCard = false;
130
131 for (var i = 0; i < this.historyDataByDay_.length; i++) {
132 var items = this.historyDataByDay_[i].historyItems;
133
134 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.
135 if (items[j].selected) {
136 this.splice('historyDataByDay_.' + i + '.historyItems', j, 1);
137 itemDeletedFromCard = true;
138 overallItemCount--;
139 if (overallItemCount == 0) {
140 this.removeEmptyCards_();
141 // If the last card has been removed don't try to update its size.
142 if (this.historyDataByDay_.length > i) {
143 this.$['infinite-list'].updateSizeForItem(i);
144 }
145 return;
146 }
147 }
148 }
149 if (itemDeletedFromCard)
150 this.$['infinite-list'].updateSizeForItem(i);
151 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.
152 }
153 },
154
155 /**
156 * If a given day has had all the history it contains removed, remove this
157 * day from the array.
158 * @private
159 */
160 removeEmptyCards_: function() {
161 var historyCards = this.historyDataByDay_;
162 for (var i = historyCards.length - 1; i > -1; i--) {
163 if (historyCards[i].historyItems.length == 0) {
164 this.splice('historyDataByDay_', i, 1);
165 }
166 }
167 },
168
169 /**
122 * Adds the given items into historyDataByDay_. Adds items to the last 170 * Adds the given items into historyDataByDay_. Adds items to the last
123 * existing day if the date matches, creates a new element otherwise. 171 * existing day if the date matches, creates a new element otherwise.
124 * @param {string} date The date of the history items. 172 * @param {string} date The date of the history items.
125 * @param {Array<HistoryEntry>} historyItems The list of history items for the 173 * @param {Array<HistoryEntry>} historyItems The list of history items for the
126 * current date. 174 * current date.
127 * @private 175 * @private
128 */ 176 */
129 appendHistoryData_: function(date, historyItems) { 177 appendHistoryData_: function(date, historyItems) {
130 var lastDay = this.historyDataByDay_.length - 1; 178 var lastDay = this.historyDataByDay_.length - 1;
131 if (lastDay > 0 && date == this.historyDataByDay_[lastDay].date) { 179 if (lastDay > 0 && date == this.historyDataByDay_[lastDay].date) {
132 this.set('historyDataByDay_.' + lastDay + '.historyItems', 180 this.set('historyDataByDay_.' + lastDay + '.historyItems',
133 this.historyDataByDay_[lastDay].historyItems.concat(historyItems)); 181 this.historyDataByDay_[lastDay].historyItems.concat(historyItems));
134 } else { 182 } else {
135 this.push('historyDataByDay_', { 183 this.push('historyDataByDay_', {
136 date: date, 184 date: date,
137 historyItems: historyItems 185 historyItems: historyItems
138 }); 186 });
139 } 187 }
140 }, 188 },
141 189
142 /** 190 /**
191 * Based on which items are selected, collect an array of the info required
192 * for chrome.send('removeHistory', ...).
193 * @param {number} count The number of items that are selected.
194 * @return {array} toBeRemoved An array of objects which contain information
195 * on which history-items should be deleted.
196 */
197 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
198 var toBeRemoved = [];
199 for (var i = 0; i < this.historyDataByDay_.length; i++) {
200 var items = this.historyDataByDay_[i].historyItems;
201 for (j = 0; j < items.length; j++) {
202 if (items[j].selected) {
203
204 toBeRemoved.push({
205 url: items[j].url,
206 timestamps: items[j].allTimestamps
207 });
208
209 count--;
210 if (count == 0)
211 break;
calamity 2016/01/21 00:11:08 Change this to return toBeRemoved;
hsampson 2016/01/21 05:34:46 Done.
212 }
213 }
214 }
215 return toBeRemoved;
216 },
217
218 /**
143 * Called when the card manager is scrolled. 219 * Called when the card manager is scrolled.
144 * @private 220 * @private
145 */ 221 */
146 scrollHandler_: function() { 222 scrollHandler_: function() {
147 // Closes overflow menu on scroll. 223 // Closes overflow menu on scroll.
148 this.closeMenu(); 224 this.closeMenu();
149 225
150 this.loadMoreIfAtEnd_(); 226 this.loadMoreIfAtEnd_();
151 }, 227 },
152 228
153 /** 229 /**
154 * Requests the next list of results when the scrollbar is near the bottom 230 * Requests the next list of results when the scrollbar is near the bottom
155 * of the window. 231 * of the window.
156 */ 232 */
157 loadMoreIfAtEnd_: function() { 233 loadMoreIfAtEnd_: function() {
158 var scrollOffset = 10; 234 var scrollOffset = 10;
159 var scrollElem = this.$['infinite-list']; 235 var scrollElem = this.$['infinite-list'];
160 236
161 if (scrollElem.scrollHeight <= 237 if (scrollElem.scrollHeight <=
162 scrollElem.scrollTop + scrollElem.clientHeight + scrollOffset) { 238 scrollElem.scrollTop + scrollElem.clientHeight + scrollOffset) {
163 chrome.send('queryHistory', 239 chrome.send('queryHistory',
164 ['', 0, 0, this.lastVisitedTime, RESULTS_PER_PAGE]); 240 ['', 0, 0, this.lastVisitedTime, RESULTS_PER_PAGE]);
165 } 241 }
166 } 242 }
167 }); 243 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698