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

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

Issue 2084843002: [MD History] Add history-list-container between app and history lists. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@tim_toolbar
Patch Set: address comments Created 4 years, 6 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 /**
6 * @typedef {{querying: boolean,
7 * searchTerm: string,
8 * results: ?Array<!HistoryEntry>,
9 * info: ?HistoryQuery,
10 * incremental: boolean,
11 * range: HistoryRange,
12 * groupedOffset: number,
13 * sessionList: ?Array<!ForeignSession>}}
14 */
15 var QueryState;
16
17 Polymer({ 5 Polymer({
18 is: 'history-app', 6 is: 'history-app',
19 7
20 properties: { 8 properties: {
21 // The id of the currently selected page. 9 // The id of the currently selected page.
22 selectedPage_: { 10 selectedPage_: {type: String, value: 'history', observer: 'unselectAll'},
23 type: String,
24 value: 'history-list',
25 observer: 'unselectAll'
26 },
27 11
28 // Whether domain-grouped history is enabled. 12 // Whether domain-grouped history is enabled.
29 grouped_: { 13 grouped_: {
30 type: Boolean, 14 type: Boolean,
31 reflectToAttribute: true 15 reflectToAttribute: true
32 }, 16 },
33 17
34 // Whether the first set of results have returned.
35 firstLoad_: { type: Boolean, value: true },
36
37 // True if the history queries are disabled.
38 queryingDisabled_: Boolean,
39
40 /** @type {!QueryState} */ 18 /** @type {!QueryState} */
41 // TODO(calamity): Split out readOnly data into a separate property which is 19 // TODO(calamity): Split out readOnly data into a separate property which is
tsergeant 2016/06/24 06:19:17 Can remove this todo
calamity 2016/06/27 03:35:46 Done.
42 // only set on result return. 20 // only set on result return.
43 queryState_: { 21 queryState_: {
44 type: Object, 22 type: Object,
45 value: function() { 23 value: function() {
46 return { 24 return {
25 // Whether the most recent query was incremental.
26 incremental: false,
47 // A query is initiated by page load. 27 // A query is initiated by page load.
48 querying: true, 28 querying: true,
29 queryingDisabled: Boolean,
30 _range: HistoryRange.ALL_TIME,
49 searchTerm: '', 31 searchTerm: '',
50 results: null, 32 // TODO(calamity): Make history toolbar buttons change the offset
51 // Whether the most recent query was incremental.
52 incremental: false,
53 info: null,
54 range: HistoryRange.ALL_TIME,
55 // TODO(calamity): Make history toolbar buttons change the offset.
56 groupedOffset: 0, 33 groupedOffset: 0,
57 sessionList: null, 34
35 set range(val) { this._range = Number(val); },
36 get range() { return this._range; },
58 }; 37 };
59 } 38 }
60 }, 39 },
40
41 sessionList: Array,
61 }, 42 },
62 43
63 observers: [
64 'searchTermChanged_(queryState_.searchTerm)',
65 'groupedRangeChanged_(queryState_.range)',
66 ],
67
68 // TODO(calamity): Replace these event listeners with data bound properties.
69 listeners: { 44 listeners: {
70 'cr-toolbar-menu-click': 'onMenuClick_', 45 'cr-toolbar-menu-click': 'onMenuClick_',
71 'history-checkbox-select': 'checkboxSelected', 46 'history-checkbox-select': 'checkboxSelected',
72 'unselect-all': 'unselectAll', 47 'unselect-all': 'unselectAll',
73 'delete-selected': 'deleteSelected', 48 'delete-selected': 'deleteSelected',
74 'search-domain': 'searchDomain_', 49 'search-domain': 'searchDomain_',
75 'load-more-history': 'loadMoreHistory_',
76 }, 50 },
77 51
78 /** @override */ 52 /** @override */
79 ready: function() { 53 ready: function() {
80 this.grouped_ = loadTimeData.getBoolean('groupByDomain'); 54 this.grouped_ = loadTimeData.getBoolean('groupByDomain');
81 }, 55 },
82 56
83 onMenuClick_: function() { 57 onMenuClick_: function() { this.$['side-bar'].toggle(); },
84 this.$['side-bar'].toggle();
85 },
86 58
87 /** 59 /**
88 * Listens for history-item being selected or deselected (through checkbox) 60 * Listens for history-item being selected or deselected (through checkbox)
89 * and changes the view of the top toolbar. 61 * and changes the view of the top toolbar.
90 * @param {{detail: {countAddition: number}}} e 62 * @param {{detail: {countAddition: number}}} e
91 */ 63 */
92 checkboxSelected: function(e) { 64 checkboxSelected: function(e) {
93 var toolbar = /** @type {HistoryToolbarElement} */(this.$.toolbar); 65 var toolbar = /** @type {HistoryToolbarElement} */ (this.$.toolbar);
94 toolbar.count += e.detail.countAddition; 66 toolbar.count += e.detail.countAddition;
95 }, 67 },
96 68
97 /** 69 /**
98 * Listens for call to cancel selection and loops through all items to set 70 * Listens for call to cancel selection and loops through all items to set
99 * checkbox to be unselected. 71 * checkbox to be unselected.
100 */ 72 */
101 unselectAll: function() { 73 unselectAll: function() {
102 var historyList = 74 var listContainer =
103 /** @type {HistoryListElement} */(this.$['history-list']); 75 /** @type {HistoryListContainerElement} */ (this.$['history']);
104 var toolbar = /** @type {HistoryToolbarElement} */(this.$.toolbar); 76 var toolbar = /** @type {HistoryToolbarElement} */ (this.$.toolbar);
105 historyList.unselectAllItems(toolbar.count); 77 listContainer.unselectAllItems(toolbar.count);
106 toolbar.count = 0; 78 toolbar.count = 0;
107 }, 79 },
108 80
109 /** 81 /**
110 * Listens for call to delete all selected items and loops through all items 82 * Listens for call to delete all selected items and loops through all items
111 * to determine which ones are selected and deletes these. 83 * to determine which ones are selected and deletes these.
112 */ 84 */
113 deleteSelected: function() { 85 deleteSelected: function() {
114 if (!loadTimeData.getBoolean('allowDeletingHistory')) 86 if (!loadTimeData.getBoolean('allowDeletingHistory'))
115 return; 87 return;
116 88
117 // TODO(hsampson): add a popup to check whether the user definitely 89 // TODO(hsampson): add a popup to check whether the user definitely
118 // wants to delete the selected items. 90 // wants to delete the selected items.
119 /** @type {HistoryListElement} */(this.$['history-list']).deleteSelected(); 91 /** @type {HistoryListContainerElement} */ (this.$['history'])
120 }, 92 .deleteSelected();
121
122 initializeResults_: function(info, results) {
123 if (results.length == 0)
124 return;
125
126 var currentDate = results[0].dateRelativeDay;
127
128 for (var i = 0; i < results.length; i++) {
129 // Sets the default values for these fields to prevent undefined types.
130 results[i].selected = false;
131 results[i].readableTimestamp =
132 info.term == '' ? results[i].dateTimeOfDay : results[i].dateShort;
133
134 if (results[i].dateRelativeDay != currentDate) {
135 currentDate = results[i].dateRelativeDay;
136 }
137 }
138 }, 93 },
139 94
140 /** 95 /**
141 * @param {HistoryQuery} info An object containing information about the 96 * @param {HistoryQuery} info An object containing information about the
142 * query. 97 * query.
143 * @param {!Array<HistoryEntry>} results A list of results. 98 * @param {!Array<HistoryEntry>} results A list of results.
144 */ 99 */
145 historyResult: function(info, results) { 100 historyResult: function(info, results) {
146 this.firstLoad_ = false;
147 this.set('queryState_.info', info);
148 this.set('queryState_.results', results);
149 this.set('queryState_.querying', false); 101 this.set('queryState_.querying', false);
150 102 var listContainer =
151 this.initializeResults_(info, results); 103 /** @type {HistoryListContainerElement} */ (this.$['history']);
152 104 listContainer.historyResult(info, results);
153 if (this.grouped_ && this.queryState_.range != HistoryRange.ALL_TIME) {
154 this.$$('history-grouped-list').historyData = results;
155 return;
156 }
157
158 var list = /** @type {HistoryListElement} */(this.$['history-list']);
159 list.addNewResults(results);
160 if (info.finished)
161 list.disableResultLoading();
162 }, 105 },
163 106
164 /** 107 /**
165 * Fired when the user presses 'More from this site'. 108 * Fired when the user presses 'More from this site'.
166 * @param {{detail: {domain: string}}} e 109 * @param {{detail: {domain: string}}} e
167 */ 110 */
168 searchDomain_: function(e) { 111 searchDomain_: function(e) { this.$.toolbar.setSearchTerm(e.detail.domain); },
169 this.$.toolbar.setSearchTerm(e.detail.domain);
170 },
171
172 searchTermChanged_: function(searchTerm) {
173 this.queryHistory(false);
174 },
175
176 groupedRangeChanged_: function(range) {
177 this.queryHistory(false);
178 },
179
180 loadMoreHistory_: function() {
181 this.queryHistory(true);
182 },
183
184 /**
185 * Queries the history backend for results based on queryState_.
186 * @param {boolean} incremental Whether the new query should continue where
187 * the previous query stopped.
188 */
189 queryHistory: function(incremental) {
190 if (this.queryingDisabled_ || this.firstLoad_)
191 return;
192
193 this.set('queryState_.querying', true);
194 this.set('queryState_.incremental', incremental);
195
196 var queryState = this.queryState_;
197
198 var lastVisitTime = 0;
199 if (incremental) {
200 var lastVisit = queryState.results.slice(-1)[0];
201 lastVisitTime = lastVisit ? lastVisit.time : 0;
202 }
203
204 var maxResults =
205 queryState.range == HistoryRange.ALL_TIME ? RESULTS_PER_PAGE : 0;
206 chrome.send('queryHistory', [
207 queryState.searchTerm, queryState.groupedOffset, Number(queryState.range),
208 lastVisitTime, maxResults
209 ]);
210 },
211 112
212 /** 113 /**
213 * @param {!Array<!ForeignSession>} sessionList Array of objects describing 114 * @param {!Array<!ForeignSession>} sessionList Array of objects describing
214 * the sessions from other devices. 115 * the sessions from other devices.
215 * @param {boolean} isTabSyncEnabled Is tab sync enabled for this profile? 116 * @param {boolean} isTabSyncEnabled Is tab sync enabled for this profile?
216 */ 117 */
217 setForeignSessions: function(sessionList, isTabSyncEnabled) { 118 setForeignSessions: function(sessionList, isTabSyncEnabled) {
218 if (!isTabSyncEnabled) 119 if (!isTabSyncEnabled)
219 return; 120 return;
220 121
221 this.set('queryState_.sessionList', sessionList); 122 this.sessionList = sessionList;
222 }, 123 },
223 124
224 /** 125 /**
225 * @param {string} selectedPage
226 * @param {HistoryRange} range
227 * @return {string}
228 */
229 getSelectedPage: function(selectedPage, range) {
230 if (selectedPage == 'history-list' && range != HistoryRange.ALL_TIME)
231 return 'history-grouped-list';
232
233 return selectedPage;
234 },
235
236 /**
237 * @param {string} selectedPage 126 * @param {string} selectedPage
238 * @return {boolean} 127 * @return {boolean}
239 * @private 128 * @private
240 */ 129 */
241 syncedTabsSelected_: function(selectedPage) { 130 syncedTabsSelected_: function(selectedPage) {
242 return selectedPage == 'history-synced-device-manager'; 131 return selectedPage == 'synced-devices';
243 }, 132 },
244 133
245 /** 134 /**
246 * @param {boolean} querying 135 * @param {boolean} querying
247 * @param {boolean} incremental 136 * @param {boolean} incremental
248 * @param {string} searchTerm 137 * @param {string} searchTerm
249 * @return {boolean} Whether a loading spinner should be shown (implies the 138 * @return {boolean} Whether a loading spinner should be shown (implies the
250 * backend is querying a new search term). 139 * backend is querying a new search term).
251 * @private 140 * @private
252 */ 141 */
253 shouldShowSpinner_: function(querying, incremental, searchTerm) { 142 shouldShowSpinner_: function(querying, incremental, searchTerm) {
254 return querying && !incremental && searchTerm != ''; 143 return querying && !incremental && searchTerm != '';
255 } 144 },
256 }); 145 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698