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

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

Issue 1574063003: MD History: Add basic material design history cards and history items (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed reviewer's comments 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
(Empty)
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
3 // found in the LICENSE file.
4
5 Polymer({
6 is: 'history-card-manager',
7
8 properties: {
9 // An array of objects sorted in reverse chronological order.
10 // Each object has a date and the history items belonging to that date.
11 historyDataByDay_: {
12 type: Array,
13 value: function() { return []; }
14 },
15
16 // The time of access of the last element of historyDataByDay_.
17 lastVisitedTime: {
18 type: Number,
19 value: 0
20 },
21
22 menuOpen: {
23 type: Boolean,
24 value: false,
25 reflectToAttribute: true
26 },
27
28 menuIdentifier: {
29 type: Number,
30 value: 0
31 }
32 },
33
34 /** @const @private */
35 X_OFFSET_: 30,
36
37 listeners: {
38 'tap': 'closeMenu',
39 'toggle-menu': 'toggleMenu_'
40 },
41
42 /**
43 * Closes the overflow menu.
44 */
45 closeMenu: function() {
46 this.menuOpen = false;
47 },
48
49 /**
50 * Opens the overflow menu unless the menu is already open and the same button
51 * is pressed.
52 * @param {Event} e The event with details of the menu item that was clicked.
53 * @private
54 */
55 toggleMenu_: function(e) {
56 var menu = this.$['overflow-menu'];
57
58 // Menu closes if the same button is clicked.
59 if (this.menuOpen && this.menuIdentifier == e.detail.accessTime) {
60 this.closeMenu();
61 } else {
62 this.menuOpen = true;
63 this.menuIdentifier = e.detail.accessTime;
64
65 cr.ui.positionPopupAtPoint(e.detail.x + this.X_OFFSET_, e.detail.y, menu,
66 cr.ui.AnchorType.BEFORE);
67
68 menu.focus();
69 }
70 },
71
72 /**
73 * Split the newly updated history results into history items sorted via day
74 * accessed.
75 * @param {!Array<!HistoryEntry>} results The new history results.
76 */
77 addNewResults: function(results) {
78 if (results.length == 0)
79 return;
80
81 var dateSortedData = [];
82 var historyItems = [];
83 var currentDate = results[0].dateRelativeDay;
84
85 for (var i = 0; i < results.length; i++) {
86 if (!currentDate)
87 continue;
88
89 results[i].selected = false;
90 if (results[i].dateRelativeDay != currentDate) {
91 this.appendHistoryData_(currentDate, historyItems);
92 currentDate = results[i].dateRelativeDay;
93 historyItems = [];
94 }
95 historyItems.push(results[i]);
96 }
Dan Beam 2016/01/27 18:20:07 nit: \n
yingran 2016/01/28 00:51:01 Done.
97 if (currentDate)
98 this.appendHistoryData_(currentDate, historyItems);
99
100 this.lastVisitedTime = historyItems[historyItems.length - 1].time;
101 },
102
103 /**
104 * Cycle through each entry in historyDataByDay_ and set all items to be
105 * unselected.
106 */
107 unselectAllItems: function(overallItemCount) {
108 var historyCardData = this.historyDataByDay_;
109
110 for (var i = 0; i < historyCardData.length; i++) {
111 var items = historyCardData[i].historyItems;
112 for (var j = 0; j < items.length; j++) {
113 if (items[j].selected) {
114 this.set('historyDataByDay_.' + i + '.historyItems.' + j +
115 '.selected', false);
116 overallItemCount--;
117 if (overallItemCount == 0)
118 break;
119 }
120 }
121 }
122 },
123
124 /**
125 * Adds the given items into historyDataByDay_. Adds items to the last
126 * existing day if the date matches, creates a new element otherwise.
127 * @param {string} date The date of the history items.
128 * @param {!Array<!HistoryEntry>} historyItems The list of history items for
129 * the current date.
130 * @private
131 */
132 appendHistoryData_: function(date, historyItems) {
133 var lastDay = this.historyDataByDay_.length - 1;
134 if (lastDay > 0 && date == this.historyDataByDay_[lastDay].date) {
135 this.set('historyDataByDay_.' + lastDay + '.historyItems',
136 this.historyDataByDay_[lastDay].historyItems.concat(historyItems));
137 } else {
138 this.push('historyDataByDay_', {
139 date: date,
140 historyItems: historyItems
141 });
142 }
143 },
144
145 /**
146 * Called when the card manager is scrolled.
147 * @private
148 */
149 scrollHandler_: function() {
150 // Close overflow menu on scroll.
151 this.closeMenu();
152
153 this.loadMoreIfAtEnd_();
Dan Beam 2016/01/27 18:20:07 is loadMoreIfAtEnd_ only called from here? if so,
yingran 2016/01/28 00:51:01 Done.
154 },
155
156 /**
157 * Requests the next list of results when the scrollbar is near the bottom
158 * of the window.
159 * @private
160 */
161 loadMoreIfAtEnd_: function() {
162 var scrollOffset = 10;
163 var scrollElem = this.$['infinite-list'];
164
165 if (scrollElem.scrollHeight <=
166 scrollElem.scrollTop + scrollElem.clientHeight + scrollOffset) {
167 chrome.send('queryHistory',
168 ['', 0, 0, this.lastVisitedTime, RESULTS_PER_PAGE]);
169 }
170 }
171 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698