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

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

Powered by Google App Engine
This is Rietveld 408576698