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

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
42 // only set on result return.
43 queryState_: { 19 queryState_: {
44 type: Object, 20 type: Object,
45 value: function() { 21 value: function() {
46 return { 22 return {
23 // Whether the most recent query was incremental.
24 incremental: false,
47 // A query is initiated by page load. 25 // A query is initiated by page load.
48 querying: true, 26 querying: true,
27 queryingDisabled: Boolean,
28 _range: HistoryRange.ALL_TIME,
49 searchTerm: '', 29 searchTerm: '',
50 results: null, 30 // 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, 31 groupedOffset: 0,
57 sessionList: null, 32
33 set range(val) { this._range = Number(val); },
34 get range() { return this._range; },
58 }; 35 };
59 } 36 }
60 }, 37 },
38
39 sessionList: Array,
61 }, 40 },
62 41
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: { 42 listeners: {
70 'cr-toolbar-menu-click': 'onMenuClick_', 43 'cr-toolbar-menu-click': 'onMenuClick_',
71 'history-checkbox-select': 'checkboxSelected', 44 'history-checkbox-select': 'checkboxSelected',
72 'unselect-all': 'unselectAll', 45 'unselect-all': 'unselectAll',
73 'delete-selected': 'deleteSelected', 46 'delete-selected': 'deleteSelected',
74 'search-domain': 'searchDomain_', 47 'search-domain': 'searchDomain_',
75 'load-more-history': 'loadMoreHistory_',
76 }, 48 },
77 49
78 /** @override */ 50 /** @override */
79 ready: function() { 51 ready: function() {
80 this.grouped_ = loadTimeData.getBoolean('groupByDomain'); 52 this.grouped_ = loadTimeData.getBoolean('groupByDomain');
81 }, 53 },
82 54
83 onMenuClick_: function() { 55 onMenuClick_: function() { this.$['side-bar'].toggle(); },
84 this.$['side-bar'].toggle();
85 },
86 56
87 /** 57 /**
88 * Listens for history-item being selected or deselected (through checkbox) 58 * Listens for history-item being selected or deselected (through checkbox)
89 * and changes the view of the top toolbar. 59 * and changes the view of the top toolbar.
90 * @param {{detail: {countAddition: number}}} e 60 * @param {{detail: {countAddition: number}}} e
91 */ 61 */
92 checkboxSelected: function(e) { 62 checkboxSelected: function(e) {
93 var toolbar = /** @type {HistoryToolbarElement} */(this.$.toolbar); 63 var toolbar = /** @type {HistoryToolbarElement} */ (this.$.toolbar);
94 toolbar.count += e.detail.countAddition; 64 toolbar.count += e.detail.countAddition;
95 }, 65 },
96 66
97 /** 67 /**
98 * Listens for call to cancel selection and loops through all items to set 68 * Listens for call to cancel selection and loops through all items to set
99 * checkbox to be unselected. 69 * checkbox to be unselected.
100 */ 70 */
101 unselectAll: function() { 71 unselectAll: function() {
102 var historyList = 72 var listContainer =
103 /** @type {HistoryListElement} */(this.$['history-list']); 73 /** @type {HistoryListContainerElement} */ (this.$['history']);
104 var toolbar = /** @type {HistoryToolbarElement} */(this.$.toolbar); 74 var toolbar = /** @type {HistoryToolbarElement} */ (this.$.toolbar);
105 historyList.unselectAllItems(toolbar.count); 75 listContainer.unselectAllItems(toolbar.count);
106 toolbar.count = 0; 76 toolbar.count = 0;
107 }, 77 },
108 78
109 /** 79 /**
110 * Listens for call to delete all selected items and loops through all items 80 * Listens for call to delete all selected items and loops through all items
111 * to determine which ones are selected and deletes these. 81 * to determine which ones are selected and deletes these.
112 */ 82 */
113 deleteSelected: function() { 83 deleteSelected: function() {
114 if (!loadTimeData.getBoolean('allowDeletingHistory')) 84 if (!loadTimeData.getBoolean('allowDeletingHistory'))
115 return; 85 return;
116 86
117 // TODO(hsampson): add a popup to check whether the user definitely 87 // TODO(hsampson): add a popup to check whether the user definitely
118 // wants to delete the selected items. 88 // wants to delete the selected items.
119 /** @type {HistoryListElement} */(this.$['history-list']).deleteSelected(); 89 /** @type {HistoryListContainerElement} */ (this.$['history'])
120 }, 90 .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 }, 91 },
139 92
140 /** 93 /**
141 * @param {HistoryQuery} info An object containing information about the 94 * @param {HistoryQuery} info An object containing information about the
142 * query. 95 * query.
143 * @param {!Array<HistoryEntry>} results A list of results. 96 * @param {!Array<HistoryEntry>} results A list of results.
144 */ 97 */
145 historyResult: function(info, results) { 98 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); 99 this.set('queryState_.querying', false);
150 100 var listContainer =
151 this.initializeResults_(info, results); 101 /** @type {HistoryListContainerElement} */ (this.$['history']);
152 102 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 }, 103 },
163 104
164 /** 105 /**
165 * Fired when the user presses 'More from this site'. 106 * Fired when the user presses 'More from this site'.
166 * @param {{detail: {domain: string}}} e 107 * @param {{detail: {domain: string}}} e
167 */ 108 */
168 searchDomain_: function(e) { 109 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 110
212 /** 111 /**
213 * @param {!Array<!ForeignSession>} sessionList Array of objects describing 112 * @param {!Array<!ForeignSession>} sessionList Array of objects describing
214 * the sessions from other devices. 113 * the sessions from other devices.
215 * @param {boolean} isTabSyncEnabled Is tab sync enabled for this profile? 114 * @param {boolean} isTabSyncEnabled Is tab sync enabled for this profile?
216 */ 115 */
217 setForeignSessions: function(sessionList, isTabSyncEnabled) { 116 setForeignSessions: function(sessionList, isTabSyncEnabled) {
218 if (!isTabSyncEnabled) 117 if (!isTabSyncEnabled)
219 return; 118 return;
220 119
221 this.set('queryState_.sessionList', sessionList); 120 this.sessionList = sessionList;
222 }, 121 },
223 122
224 /** 123 /**
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 124 * @param {string} selectedPage
238 * @return {boolean} 125 * @return {boolean}
239 * @private 126 * @private
240 */ 127 */
241 syncedTabsSelected_: function(selectedPage) { 128 syncedTabsSelected_: function(selectedPage) {
242 return selectedPage == 'history-synced-device-manager'; 129 return selectedPage == 'synced-devices';
243 }, 130 },
244 131
245 /** 132 /**
246 * @param {boolean} querying 133 * @param {boolean} querying
247 * @param {boolean} incremental 134 * @param {boolean} incremental
248 * @param {string} searchTerm 135 * @param {string} searchTerm
249 * @return {boolean} Whether a loading spinner should be shown (implies the 136 * @return {boolean} Whether a loading spinner should be shown (implies the
250 * backend is querying a new search term). 137 * backend is querying a new search term).
251 * @private 138 * @private
252 */ 139 */
253 shouldShowSpinner_: function(querying, incremental, searchTerm) { 140 shouldShowSpinner_: function(querying, incremental, searchTerm) {
254 return querying && !incremental && searchTerm != ''; 141 return querying && !incremental && searchTerm != '';
255 } 142 },
256 }); 143 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698