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

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