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

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

Powered by Google App Engine
This is Rietveld 408576698