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

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

Issue 2590093002: MD History: Move queryState to be managed by history-router (Closed)
Patch Set: Rebase Created 3 years, 11 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 Polymer({ 5 Polymer({
6 is: 'history-list-container', 6 is: 'history-list-container',
7 7
8 properties: { 8 properties: {
9 /** @type {HistoryRange} */ 9 /** @type {HistoryRange} */
10 groupedRange: { 10 groupedRange: {
11 type: Number, 11 type: Number,
12 observer: 'groupedRangeChanged_', 12 observer: 'groupedRangeChanged_',
13 }, 13 },
14 14
15 // The path of the currently selected page. 15 // The path of the currently selected page.
16 selectedPage_: String, 16 selectedPage_: {
17 type: String,
18 computed: 'computeSelectedPage_(groupedRange)',
19 },
17 20
18 // Whether domain-grouped history is enabled. 21 // Whether domain-grouped history is enabled.
19 grouped: Boolean, 22 grouped: Boolean,
20 23
21 /** @type {!QueryState} */ 24 /** @type {!QueryState} */
22 queryState: Object, 25 queryState: Object,
23 26
24 /** @type {!QueryResult} */ 27 /** @type {!QueryResult} */
25 queryResult: Object, 28 queryResult: Object,
26 29
27 /** 30 /**
28 * @private {?{ 31 * @private {?{
29 * index: number, 32 * index: number,
30 * item: !HistoryEntry, 33 * item: !HistoryEntry,
31 * path: string, 34 * path: string,
32 * target: !HTMLElement 35 * target: !HTMLElement
33 * }} 36 * }}
34 */ 37 */
35 actionMenuModel_: Object, 38 actionMenuModel_: Object,
36 }, 39 },
37 40
38 observers: [ 41 observers: [
39 'searchTermChanged_(queryState.searchTerm)', 42 'groupedRangeChanged_(queryState.range)',
40 'groupedOffsetChanged_(queryState.groupedOffset)',
41 ], 43 ],
42 44
43 listeners: { 45 listeners: {
44 'load-more-history': 'loadMoreHistory_',
45 'open-menu': 'openMenu_', 46 'open-menu': 'openMenu_',
46 }, 47 },
47 48
48 /** 49 /**
49 * @param {HistoryQuery} info An object containing information about the 50 * @param {HistoryQuery} info An object containing information about the
50 * query. 51 * query.
51 * @param {!Array<!HistoryEntry>} results A list of results. 52 * @param {!Array<!HistoryEntry>} results A list of results.
52 */ 53 */
53 historyResult: function(info, results) { 54 historyResult: function(info, results) {
54 this.initializeResults_(info, results); 55 this.initializeResults_(info, results);
55 this.closeMenu_(); 56 this.closeMenu_();
56 57
57 if (info.term && !this.queryState.incremental) { 58 if (info.term && !this.queryState.incremental) {
58 Polymer.IronA11yAnnouncer.requestAvailability(); 59 Polymer.IronA11yAnnouncer.requestAvailability();
59 this.fire('iron-announce', { 60 this.fire('iron-announce', {
60 text: 61 text:
61 md_history.HistoryItem.searchResultsTitle(results.length, info.term) 62 md_history.HistoryItem.searchResultsTitle(results.length, info.term)
62 }); 63 });
63 } 64 }
64 65
65 var list = /** @type {HistoryListBehavior} */ this.getSelectedList_(); 66 var list = /** @type {HistoryListBehavior} */ this.getSelectedList_();
66 list.addNewResults(results, this.queryState.incremental, info.finished); 67 list.addNewResults(results, this.queryState.incremental, info.finished);
67 }, 68 },
68 69
69 /**
70 * Queries the history backend for results based on queryState.
71 * @param {boolean} incremental Whether the new query should continue where
72 * the previous query stopped.
73 */
74 queryHistory: function(incremental) {
75 var queryState = this.queryState;
76 // Disable querying until the first set of results have been returned. If
77 // there is a search, query immediately to support search query params from
78 // the URL.
79 var noResults = !this.queryResult || this.queryResult.results == null;
80 if (queryState.queryingDisabled ||
81 (!this.queryState.searchTerm && noResults)) {
82 return;
83 }
84
85 // Close any open dialog if a new query is initiated.
86 var dialog = this.$.dialog.getIfExists();
87 if (!incremental && dialog && dialog.open)
88 dialog.close();
89
90 this.set('queryState.querying', true);
91 this.set('queryState.incremental', incremental);
92
93 var lastVisitTime = 0;
94 if (incremental) {
95 var lastVisit = this.queryResult.results.slice(-1)[0];
96 lastVisitTime = lastVisit ? Math.floor(lastVisit.time) : 0;
97 }
98
99 var maxResults =
100 this.groupedRange == HistoryRange.ALL_TIME ? RESULTS_PER_PAGE : 0;
101 chrome.send('queryHistory', [
102 queryState.searchTerm, queryState.groupedOffset, queryState.range,
103 lastVisitTime, maxResults
104 ]);
105 },
106
107 historyDeleted: function() { 70 historyDeleted: function() {
108 // Do not reload the list when there are items checked. 71 // Do not reload the list when there are items checked.
109 if (this.getSelectedItemCount() > 0) 72 if (this.getSelectedItemCount() > 0)
110 return; 73 return;
111 74
112 // Reload the list with current search state. 75 // Reload the list with current search state.
113 this.queryHistory(false); 76 this.fire('query-history', false);
114 }, 77 },
115 78
116 /** @return {Element} */ 79 /** @return {Element} */
117 getContentScrollTarget: function() { 80 getContentScrollTarget: function() {
118 return this.getSelectedList_(); 81 return this.getSelectedList_();
119 }, 82 },
120 83
121 /** @return {number} */ 84 /** @return {number} */
122 getSelectedItemCount: function() { 85 getSelectedItemCount: function() {
123 return this.getSelectedList_().selectedPaths.size; 86 return this.getSelectedList_().selectedPaths.size;
(...skipping 18 matching lines...) Expand all
142 if (this.queryState.searchTerm != '') 105 if (this.queryState.searchTerm != '')
143 browserService.recordAction('SearchResultRemove'); 106 browserService.recordAction('SearchResultRemove');
144 this.$.dialog.get().showModal(); 107 this.$.dialog.get().showModal();
145 108
146 // TODO(dbeam): remove focus flicker caused by showModal() + focus(). 109 // TODO(dbeam): remove focus flicker caused by showModal() + focus().
147 this.$$('.action-button').focus(); 110 this.$$('.action-button').focus();
148 }, 111 },
149 112
150 /** 113 /**
151 * @param {HistoryRange} range 114 * @param {HistoryRange} range
115 * @return {string}
116 * @private
117 */
118 computeSelectedPage_: function(range) {
119 return range == HistoryRange.ALL_TIME ? 'infinite-list' : 'grouped-list';
120 },
121
122 /**
123 * @param {HistoryRange} range
152 * @private 124 * @private
153 */ 125 */
154 groupedRangeChanged_: function(range, oldRange) { 126 groupedRangeChanged_: function(range) {
155 this.selectedPage_ =
156 range == HistoryRange.ALL_TIME ? 'infinite-list' : 'grouped-list';
157
158 if (oldRange == undefined)
159 return;
160
161 this.set('queryState.groupedOffset', 0);
162
163 // Reset the results on range change to prevent stale results from being 127 // Reset the results on range change to prevent stale results from being
164 // processed into the incoming range's UI. 128 // processed into the incoming range's UI.
165 if (this.queryResult.info) { 129 if (range != HistoryRange.ALL_TIME && this.queryResult.info) {
166 this.set('queryResult.results', []); 130 this.set('queryResult.results', []);
167 this.historyResult(this.queryResult.info, []); 131 this.historyResult(this.queryResult.info, []);
168 } 132 }
169
170 this.queryHistory(false);
171 this.fire('history-view-changed');
172 },
173
174 /** @private */
175 searchTermChanged_: function() {
176 this.queryHistory(false);
177 // TODO(tsergeant): Ignore incremental searches in this metric.
178 if (this.queryState.searchTerm)
179 md_history.BrowserService.getInstance().recordAction('Search');
180 },
181
182 /** @private */
183 groupedOffsetChanged_: function() {
184 this.queryHistory(false);
185 },
186
187 /** @private */
188 loadMoreHistory_: function() {
189 this.queryHistory(true);
190 }, 133 },
191 134
192 /** 135 /**
193 * @param {HistoryQuery} info 136 * @param {HistoryQuery} info
194 * @param {!Array<HistoryEntry>} results 137 * @param {!Array<HistoryEntry>} results
195 * @private 138 * @private
196 */ 139 */
197 initializeResults_: function(info, results) { 140 initializeResults_: function(info, results) {
198 if (results.length == 0) 141 if (results.length == 0)
199 return; 142 return;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 */ 250 */
308 getSelectedList_: function() { 251 getSelectedList_: function() {
309 return this.$$('#' + this.selectedPage_); 252 return this.$$('#' + this.selectedPage_);
310 }, 253 },
311 254
312 /** @private */ 255 /** @private */
313 canDeleteHistory_: function() { 256 canDeleteHistory_: function() {
314 return loadTimeData.getBoolean('allowDeletingHistory'); 257 return loadTimeData.getBoolean('allowDeletingHistory');
315 } 258 }
316 }); 259 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/md_history/history_list.js ('k') | chrome/browser/resources/md_history/query_manager.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698