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

Side by Side Diff: chrome/browser/resources/md_history/history_list.js

Issue 1641543002: MD History: Refactored design for displaying history information (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@second_patch
Patch Set: concat -> push 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-list',
7 7
8 properties: { 8 properties: {
9 // An array of objects sorted in reverse chronological order. 9 // An array of history entries in reverse chronological order.
10 // Each object has a date and the history items belonging to that date. 10 historyData: {
11 historyDataByDay_: {
12 type: Array, 11 type: Array,
13 value: function() { return []; } 12 value: function() { return []; }
14 }, 13 },
15 14
16 // The time of access of the last element of historyDataByDay_. 15 // The time in seconds of the last history item in historyData.
17 lastVisitedTime: { 16 lastVisitedTime: {
18 type: Number, 17 type: Number,
19 value: 0 18 value: 0
20 }, 19 },
21 20
22 menuOpen: { 21 menuOpen: {
23 type: Boolean, 22 type: Boolean,
24 value: false, 23 value: false,
25 reflectToAttribute: true 24 reflectToAttribute: true
26 }, 25 },
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 this.menuIdentifier = e.detail.accessTime; 62 this.menuIdentifier = e.detail.accessTime;
64 63
65 cr.ui.positionPopupAtPoint(e.detail.x + this.X_OFFSET_, e.detail.y, menu, 64 cr.ui.positionPopupAtPoint(e.detail.x + this.X_OFFSET_, e.detail.y, menu,
66 cr.ui.AnchorType.BEFORE); 65 cr.ui.AnchorType.BEFORE);
67 66
68 menu.focus(); 67 menu.focus();
69 } 68 }
70 }, 69 },
71 70
72 /** 71 /**
73 * Split the newly updated history results into history items sorted via day 72 * Adds the newly updated history results into historyData. Adds new fields
74 * accessed. 73 * for each result. Preserves the scroll position of the window when new data
tsergeant 2016/02/08 00:10:54 You can get rid of the comment about scroll positi
yingran 2016/02/08 03:20:36 Done.
74 * is loaded.
75 * @param {!Array<!HistoryEntry>} results The new history results. 75 * @param {!Array<!HistoryEntry>} results The new history results.
76 */ 76 */
77 addNewResults: function(results) { 77 addNewResults: function(results) {
78 if (results.length == 0) 78 if (results.length == 0)
79 return; 79 return;
80 80
81 var dateSortedData = [];
82 var historyItems = [];
83 var currentDate = results[0].dateRelativeDay; 81 var currentDate = results[0].dateRelativeDay;
84 82
85 for (var i = 0; i < results.length; i++) { 83 for (var i = 0; i < results.length; i++) {
86 if (!currentDate) 84 // Sets the default values for these fields to prevent undefined types.
87 continue; 85 results[i].selected = false;
86 results[i].isLastItem = false;
87 results[i].isFirstItem = false;
88 88
89 results[i].selected = false;
90 if (results[i].dateRelativeDay != currentDate) { 89 if (results[i].dateRelativeDay != currentDate) {
91 this.appendHistoryData_(currentDate, historyItems); 90 results[i - 1].isLastItem = true;
91 results[i].isFirstItem = true;
92 currentDate = results[i].dateRelativeDay; 92 currentDate = results[i].dateRelativeDay;
93 historyItems = [];
94 } 93 }
95 historyItems.push(results[i]); 94 results[i].needsTimeGap = this.needsTimeGap_(results, i);
96 } 95 }
97 96
98 if (currentDate) 97 // If it's the first time we get data, the first item will always be the
99 this.appendHistoryData_(currentDate, historyItems); 98 // first card.
99 if (this.historyData.length == 0) {
tsergeant 2016/02/08 00:10:54 Nit: No {}
yingran 2016/02/08 03:20:36 Done.
100 results[0].isFirstItem = true;
101 }
100 102
101 this.lastVisitedTime = historyItems[historyItems.length - 1].time; 103 for (var i = 0; i < results.length; i++) {
tsergeant 2016/02/08 00:10:54 We got this working with apply and no for loop on
yingran 2016/02/08 03:20:36 Yes- this'll be uploaded next patch
104 this.push('historyData', results[i]);
105 }
106
107 this.lastVisitedTime = this.historyData[this.historyData.length - 1].time;
102 }, 108 },
103 109
104 /** 110 /**
105 * Cycle through each entry in historyDataByDay_ and set all items to be 111 * Cycle through each entry in historyData and set all items to be
106 * unselected. 112 * unselected.
113 * @param {number} overallItemCount The number of checkboxes selected.
107 */ 114 */
108 unselectAllItems: function(overallItemCount) { 115 unselectAllItems: function(overallItemCount) {
109 var historyCardData = this.historyDataByDay_; 116 for (var i = 0; i < this.historyData.length; i++) {
110 117 if (this.historyData[i].selected) {
111 for (var i = 0; i < historyCardData.length; i++) { 118 this.set('historyData.' + i + '.selected', false);
112 var items = historyCardData[i].historyItems; 119 overallItemCount--;
113 for (var j = 0; j < items.length; j++) { 120 if (overallItemCount == 0)
114 if (items[j].selected) { 121 break;
115 this.set('historyDataByDay_.' + i + '.historyItems.' + j +
116 '.selected', false);
117 overallItemCount--;
118 if (overallItemCount == 0)
119 break;
120 }
121 } 122 }
122 } 123 }
123 }, 124 },
124 125
125 /** 126 /**
126 * Adds the given items into historyDataByDay_. Adds items to the last
127 * existing day if the date matches, creates a new element otherwise.
128 * @param {string} date The date of the history items.
129 * @param {!Array<!HistoryEntry>} historyItems The list of history items for
130 * the current date.
131 * @private
132 */
133 appendHistoryData_: function(date, historyItems) {
134 var lastDay = this.historyDataByDay_.length - 1;
135 if (lastDay > 0 && date == this.historyDataByDay_[lastDay].date) {
136 this.set('historyDataByDay_.' + lastDay + '.historyItems',
137 this.historyDataByDay_[lastDay].historyItems.concat(historyItems));
138 } else {
139 this.push('historyDataByDay_', {
140 date: date,
141 historyItems: historyItems
142 });
143 }
144 },
145
146 /**
147 * Called when the card manager is scrolled. 127 * Called when the card manager is scrolled.
148 * @private 128 * @private
149 */ 129 */
150 scrollHandler_: function() { 130 scrollHandler_: function() {
151 // Close overflow menu on scroll. 131 // Close overflow menu on scroll.
152 this.closeMenu(); 132 this.closeMenu();
153 133
154 // Requests the next list of results when the scrollbar is near the bottom 134 // Requests the next list of results when the scrollbar is near the bottom
155 // of the window. 135 // of the window.
156 var scrollOffset = 10; 136 var scrollOffset = 10;
157 var scrollElem = this.$['infinite-list']; 137 var scrollElem = this.$['infinite-list'];
158 138
159 if (scrollElem.scrollHeight <= 139 if (scrollElem.scrollHeight <=
160 scrollElem.scrollTop + scrollElem.clientHeight + scrollOffset) { 140 scrollElem.scrollTop + scrollElem.clientHeight + scrollOffset) {
161 chrome.send('queryHistory', 141 chrome.send('queryHistory',
162 ['', 0, 0, this.lastVisitedTime, RESULTS_PER_PAGE]); 142 ['', 0, 0, this.lastVisitedTime, RESULTS_PER_PAGE]);
163 } 143 }
144 },
145
146 /**
147 * Check whether the time difference between the given history item and the
148 * next one is large enough for a spacer to be required.
149 * @param {number} index The index number of the first item being compared.
150 * @return {boolean} Whether or not time gap separator is required.
151 * @private
152 */
153 needsTimeGap_: function(results, index) {
154 var items = results;
155 return index + 1 < items.length &&
156 items[index].time - items[index + 1].time > BROWSING_GAP_TIME &&
157 items[index].dateRelativeDay == items[index + 1].dateRelativeDay;
164 } 158 }
165 }); 159 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698