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

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: 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: []
Dan Beam 2016/01/16 02:54:35 should also probably be funtion() { return []; }
yingran 2016/01/18 05:40:28 Done.
14 },
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 */
32 X_OFFSET: 30,
Dan Beam 2016/01/16 02:54:35 can this be @private?
yingran 2016/01/18 05:40:29 Done.
33
34 listeners: {
35 'tap': 'closeMenu',
36 'toggle-menu': 'toggleMenu_'
37 },
38
39 /**
40 * Closes the overflow menu.
41 */
42 closeMenu: function() {
43 if (this.menuOpen) {
44 this.menuOpen = false;
Dan Beam 2016/01/16 02:54:35 why not just always do this.menuOpen = false; and
yingran 2016/01/18 05:40:28 Done.
45 }
Dan Beam 2016/01/16 02:54:36 no curlies
yingran 2016/01/18 05:40:29 Done.
46 },
47
48 /**
49 * Opens the overflow menu unless the menu is already open and the same button
50 * is pressed.
51 * @param {Event} e The event with details of the menu item that was clicked.
52 * @private
53 */
54 toggleMenu_: function(e) {
55 var menu = this.$['overflow-menu'];
56
57 // Menu closes if the same button is clicked.
58 if (this.menuOpen && this.menuIdentifier == e.detail.accessTime) {
59 this.menuOpen = false;
60 } else {
61 this.menuOpen = true;
62 this.menuIdentifier = e.detail.accessTime;
63
64 cr.ui.positionPopupAtPoint(e.detail.x + this.X_OFFSET, e.detail.y, menu,
65 cr.ui.AnchorType.BEFORE);
66
67 menu.focus();
68 }
69 },
70
71 /**
72 * Split the newly updated history results into history items sorted via day
73 * accessed. Makes sure the page stays in the same position when new content
74 * is loaded by saving the previous scroll bar position.
75 * @param {Array} results The new history results.
76 */
77 addNewResults: function(results) {
78 // Saves the current position of the scroll bar before the new list items
79 // are rendered.
Dan Beam 2016/01/16 02:54:35 why is this necessary?
yingran 2016/01/18 05:40:28 now that i test it - it doesn't seem to be necessa
80 var scrollPosition = this.$['infinite-list'].scrollTop;
81
82 if (results.length == 0) {
83 return;
84 }
Dan Beam 2016/01/16 02:54:35 no curlies
yingran 2016/01/18 05:40:28 Done.
85
86 var dateSortedData = [];
87 var historyItems = [];
88 var currentDate = results[0].dateRelativeDay;
89
90 for (var i = 0; i < results.length; i++) {
91 results[i].selected = false;
92 if (results[i].dateRelativeDay != currentDate) {
93 this.appendHistoryData_(currentDate, historyItems);
94 currentDate = results[i].dateRelativeDay;
95 historyItems = [];
96 }
97 historyItems.push(results[i]);
98 }
99 this.appendHistoryData_(currentDate, historyItems);
100
101 this.lastVisitedTime = historyItems[historyItems.length - 1].time;
102 this.$['infinite-list'].scrollTop = scrollPosition;
103 },
104
105 /**
106 * Cycle through each entry in historyDataByDay_ and set all items to be
107 * unselected.
108 */
109 unselectAllItems: function(overallItemCount) {
110 var historyCardData = this.historyDataByDay_;
111
112 for (var i = 0; i < historyCardData.length; i++) {
113 var items = historyCardData[i].historyItems;
114 for (var j = 0; j < items.length; j++) {
115 if (items[j].selected) {
116 this.set('historyDataByDay_.' + i + '.historyItems.' + j +
117 '.selected', false);
118 overallItemCount--;
119 if (overallItemCount == 0) {
120 break;
121 }
Dan Beam 2016/01/16 02:54:35 no curlies
yingran 2016/01/18 05:40:29 Done.
122 }
123 }
124 }
125 },
126
127 /**
128 * Adds the given items into historyDataByDay_. Adds items to the last
129 * existing day if the date matches, creates a new element otherwise.
130 * @param {string} date The date of the history items.
131 * @param {array} historyItems The list of history items for the current date.
132 * @private
133 */
134 appendHistoryData_: function(date, historyItems) {
135 var lastIndex = this.historyDataByDay_.length - 1;
Dan Beam 2016/01/16 02:54:35 could this be oldestDay or lastDay?
yingran 2016/01/18 05:40:29 Done.
136 if (lastIndex > 0 && date == this.historyDataByDay_[lastIndex].date) {
137 // A new object is required for the card to update due to iron-list's
138 // pass by reference implementation.
Dan Beam 2016/01/16 02:54:35 can you give an example of when this happens or wh
yingran 2016/01/18 05:40:28 Notify path only works if the oldValue!=newValue s
Dan Beam 2016/01/26 23:07:39 did you try: this.notifyPath('historyDataByDay_
yingran 2016/01/27 05:05:03 Notify path for 'historyDataByDay_.' + lastDay + '
139 var items = this.historyDataByDay_[lastIndex]
140 .historyItems.concat(historyItems);
141 this.splice('historyDataByDay_', lastIndex, 1, {
Dan Beam 2016/01/16 02:54:35 how is splice('thing_', this.thing_.length - 1, 1,
yingran 2016/01/18 05:40:29 Done. this.push won't work because |historyItems|
142 date: date,
143 historyItems: items,
144 });
145 } else {
146 this.push('historyDataByDay_', {
147 date: date,
148 historyItems: historyItems
149 });
150 }
151 },
152
153 /**
154 * Called when the card manager is scrolled.
155 */
156 scrollHandler: function(e) {
Dan Beam 2016/01/16 02:54:35 make @private (being called from the template is n
yingran 2016/01/18 05:40:28 Done.
157 // Closes overflow menu on scroll.
158 this.closeMenu();
159
160 this.doInfiniteScroll_(e);
161 },
162
163 /**
164 * Requests the next list of results when the scrollbar is near the bottom
165 * of the window.
Dan Beam 2016/01/16 02:54:35 @param
yingran 2016/01/18 05:40:29 Removed param e since no longer needed as per comm
166 */
167 doInfiniteScroll_: function(e) {
Dan Beam 2016/01/16 02:54:35 nit: loadMoreIfAtEnd_? "doInfiniteScroll_" makes
yingran 2016/01/18 05:40:29 Done.
168 var scrollOffset = 10;
169 var scrollElem = e.srcElement;
Dan Beam 2016/01/16 02:54:35 srcElement -> target, but why are we using |e| at
yingran 2016/01/18 05:40:29 Done.
170
171 if (scrollElem.scrollHeight <=
172 scrollElem.scrollTop + scrollElem.clientHeight + scrollOffset) {
Dan Beam 2016/01/16 02:54:35 this looks a lot like the downloads implementation
yingran 2016/01/18 05:40:28 :)
173 chrome.send('queryHistory',
174 ['', 0, 0, this.lastVisitedTime, RESULTS_PER_PAGE]);
175 }
176 }
177 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698