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

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

Issue 1993613002: [MD History] Implement grouped history UI. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@privatize
Patch Set: rebase Created 4 years, 7 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 /** 5 /**
6 * @typedef {{querying: boolean, 6 * @typedef {{querying: boolean,
7 * searchTerm: string, 7 * searchTerm: string,
8 * results: ?Array<!HistoryEntry>, 8 * results: ?Array<!HistoryEntry>,
9 * info: ?HistoryQuery}} 9 * info: ?HistoryQuery,
10 * range: HistoryRange,
11 * groupedOffset: number}}
10 */ 12 */
11 var QueryState; 13 var QueryState;
12 14
13 Polymer({ 15 Polymer({
14 is: 'history-app', 16 is: 'history-app',
15 17
16 properties: { 18 properties: {
17 // The id of the currently selected page. 19 // The id of the currently selected page.
18 selectedPage: { 20 selectedPage_: {
19 type: String, 21 type: String,
20 value: 'history-list'
21 }, 22 },
22 23
24 // Whether domain-grouped history is enabled.
25 grouped_: Boolean,
26
27 firstLoad_: { type: Boolean, value: true },
28
23 /** @type {!QueryState} */ 29 /** @type {!QueryState} */
24 queryState_: { 30 queryState_: {
25 type: Object, 31 type: Object,
26 value: function() { 32 value: function() {
27 return { 33 return {
28 // A query is initiated by page load. 34 // A query is initiated by page load.
29 querying: true, 35 querying: true,
30 searchTerm: '', 36 searchTerm: '',
31 results: null, 37 results: null,
32 info: null, 38 info: null,
39 range: HistoryRange.ALL_TIME,
40 // TODO(calamity): Make history toolbar buttons change the offset.
41 groupedOffset: 0,
33 }; 42 };
34 } 43 }
35 }, 44 },
36 }, 45 },
37 46
38 observers: [ 47 observers: [
39 'searchTermChanged_(queryState_.searchTerm)', 48 'searchTermChanged_(queryState_.searchTerm)',
49 'groupedRangeChanged_(queryState_.range)',
40 ], 50 ],
41 51
42 // TODO(calamity): Replace these event listeners with data bound properties. 52 // TODO(calamity): Replace these event listeners with data bound properties.
43 listeners: { 53 listeners: {
44 'history-checkbox-select': 'checkboxSelected', 54 'history-checkbox-select': 'checkboxSelected',
45 'unselect-all': 'unselectAll', 55 'unselect-all': 'unselectAll',
46 'delete-selected': 'deleteSelected', 56 'delete-selected': 'deleteSelected',
47 'search-domain': 'searchDomain_', 57 'search-domain': 'searchDomain_',
48 'load-more-history': 'loadMoreHistory_', 58 'load-more-history': 'loadMoreHistory_',
49 }, 59 },
50 60
51 ready: function() { 61 ready: function() {
52 this.$.toolbar.isGroupedMode = loadTimeData.getBoolean('groupByDomain'); 62 this.grouped_ = loadTimeData.getBoolean('groupByDomain');
53 }, 63 },
54 64
55 /** 65 /**
56 * Listens for history-item being selected or deselected (through checkbox) 66 * Listens for history-item being selected or deselected (through checkbox)
57 * and changes the view of the top toolbar. 67 * and changes the view of the top toolbar.
58 * @param {{detail: {countAddition: number}}} e 68 * @param {{detail: {countAddition: number}}} e
59 */ 69 */
60 checkboxSelected: function(e) { 70 checkboxSelected: function(e) {
61 var toolbar = /** @type {HistoryToolbarElement} */(this.$.toolbar); 71 var toolbar = /** @type {HistoryToolbarElement} */(this.$.toolbar);
62 toolbar.count += e.detail.countAddition; 72 toolbar.count += e.detail.countAddition;
(...skipping 21 matching lines...) Expand all
84 94
85 // TODO(hsampson): add a popup to check whether the user definitely 95 // TODO(hsampson): add a popup to check whether the user definitely
86 // wants to delete the selected items. 96 // wants to delete the selected items.
87 /** @type {HistoryListElement} */(this.$['history-list']).deleteSelected(); 97 /** @type {HistoryListElement} */(this.$['history-list']).deleteSelected();
88 }, 98 },
89 99
90 loadMoreHistory_: function() { 100 loadMoreHistory_: function() {
91 this.queryHistory(true); 101 this.queryHistory(true);
92 }, 102 },
93 103
104 initializeResults_: function(info, results) {
105 if (results.length == 0)
106 return;
107
108 var currentDate = results[0].dateRelativeDay;
109
110 for (var i = 0; i < results.length; i++) {
111 // Sets the default values for these fields to prevent undefined types.
112 results[i].selected = false;
113 results[i].readableTimestamp =
114 info.term == '' ? results[i].dateTimeOfDay : results[i].dateShort;
115
116 if (results[i].dateRelativeDay != currentDate) {
117 currentDate = results[i].dateRelativeDay;
118 }
119 }
120 },
121
94 /** 122 /**
95 * @param {HistoryQuery} info An object containing information about the 123 * @param {HistoryQuery} info An object containing information about the
96 * query. 124 * query.
97 * @param {!Array<HistoryEntry>} results A list of results. 125 * @param {!Array<HistoryEntry>} results A list of results.
98 */ 126 */
99 historyResult: function(info, results) { 127 historyResult: function(info, results) {
128 this.firstLoad_ = false;
129 this.set('queryState_.info', info);
130 this.set('queryState_.results', results);
100 this.set('queryState_.querying', false); 131 this.set('queryState_.querying', false);
101 this.set('queryState_.results', results); 132
102 this.set('queryState_.info', info); 133 this.initializeResults_(info, results);
134
135 if (this.grouped_ && this.queryState_.range != HistoryRange.ALL_TIME) {
136 this.$$('history-grouped-list').historyData = results;
137 return;
138 }
103 139
104 var list = /** @type {HistoryListElement} */(this.$['history-list']); 140 var list = /** @type {HistoryListElement} */(this.$['history-list']);
105 list.addNewResults(results); 141 list.addNewResults(results);
106 if (info.finished) 142 if (info.finished)
107 list.disableResultLoading(); 143 list.disableResultLoading();
108 }, 144 },
109 145
110 /** 146 /**
111 * Fired when the user presses 'More from this site'. 147 * Fired when the user presses 'More from this site'.
112 * @param {{detail: {domain: string}}} e 148 * @param {{detail: {domain: string}}} e
113 */ 149 */
114 searchDomain_: function(e) { 150 searchDomain_: function(e) {
115 this.$.toolbar.setSearchTerm(e.detail.domain); 151 this.$.toolbar.setSearchTerm(e.detail.domain);
116 }, 152 },
117 153
118 searchTermChanged_: function() { 154 searchTermChanged_: function(searchTerm) {
119 this.queryHistory(false); 155 if (!this.firstLoad_)
156 this.queryHistory(false);
120 }, 157 },
121 158
159
160 groupedRangeChanged_: function(range) {
161 if (!this.firstLoad_)
162 this.queryHistory(false);
163 },
164
165 /**
166 * Queries the history backend for results based on queryState_.
167 * @param {boolean} incremental Whether the new query should continue where
168 * the previous query stopped.
169 */
122 queryHistory: function(incremental) { 170 queryHistory: function(incremental) {
171 this.set('queryState_.querying', true);
172
173 var queryState = this.queryState_;
174
123 var lastVisitTime = 0; 175 var lastVisitTime = 0;
124 if (incremental) { 176 if (incremental) {
125 var lastVisit = this.queryState_.results.slice(-1)[0]; 177 var lastVisit = queryState.results.slice(-1)[0];
126 lastVisitTime = lastVisit ? lastVisit.time : 0; 178 lastVisitTime = lastVisit ? lastVisit.time : 0;
127 } 179 }
128 180
129 this.set('queryState_.querying', true); 181 var maxResults =
130 chrome.send( 182 queryState.range == HistoryRange.ALL_TIME ? RESULTS_PER_PAGE : 0;
131 'queryHistory', 183 chrome.send('queryHistory', [
132 [this.queryState_.searchTerm, 0, 0, lastVisitTime, RESULTS_PER_PAGE]); 184 queryState.searchTerm, queryState.groupedOffset, Number(queryState.range),
185 lastVisitTime, maxResults
186 ]);
133 }, 187 },
134 188
135 /** 189 /**
136 * @param {!Array<!ForeignSession>} sessionList Array of objects describing 190 * @param {!Array<!ForeignSession>} sessionList Array of objects describing
137 * the sessions from other devices. 191 * the sessions from other devices.
138 * @param {boolean} isTabSyncEnabled Is tab sync enabled for this profile? 192 * @param {boolean} isTabSyncEnabled Is tab sync enabled for this profile?
139 */ 193 */
140 setForeignSessions: function(sessionList, isTabSyncEnabled) { 194 setForeignSessions: function(sessionList, isTabSyncEnabled) {
141 if (!isTabSyncEnabled) 195 if (!isTabSyncEnabled)
142 return; 196 return;
143 197
144 // TODO(calamity): Add a 'no synced devices' message when sessions are 198 // TODO(calamity): Add a 'no synced devices' message when sessions are
145 // empty. 199 // empty.
146 var syncedDeviceElem = this.$['history-synced-device-manager']; 200 var syncedDeviceElem = this.$['history-synced-device-manager'];
147 var syncedDeviceManager = 201 var syncedDeviceManager =
148 /** @type {HistorySyncedDeviceManagerElement} */(syncedDeviceElem); 202 /** @type {HistorySyncedDeviceManagerElement} */(syncedDeviceElem);
149 syncedDeviceManager.setSyncedHistory(sessionList); 203 syncedDeviceManager.setSyncedHistory(sessionList);
150 } 204 },
205
206 getSelectedPage: function(selectedPage, range) {
207 if (selectedPage == 'history-list' && range != HistoryRange.ALL_TIME)
208 return 'history-grouped-list';
209
210 return selectedPage;
211 },
151 }); 212 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698