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

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

Powered by Google App Engine
This is Rietveld 408576698