| OLD | NEW |
| 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 * incremental: boolean, |
| 10 * range: HistoryRange, | 11 * range: HistoryRange, |
| 11 * groupedOffset: number, | 12 * groupedOffset: number, |
| 12 * sessionList: ?Array<!ForeignSession>}} | 13 * sessionList: ?Array<!ForeignSession>}} |
| 13 */ | 14 */ |
| 14 var QueryState; | 15 var QueryState; |
| 15 | 16 |
| 16 Polymer({ | 17 Polymer({ |
| 17 is: 'history-app', | 18 is: 'history-app', |
| 18 | 19 |
| 19 properties: { | 20 properties: { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 33 // TODO(calamity): Split out readOnly data into a separate property which is | 34 // TODO(calamity): Split out readOnly data into a separate property which is |
| 34 // only set on result return. | 35 // only set on result return. |
| 35 queryState_: { | 36 queryState_: { |
| 36 type: Object, | 37 type: Object, |
| 37 value: function() { | 38 value: function() { |
| 38 return { | 39 return { |
| 39 // A query is initiated by page load. | 40 // A query is initiated by page load. |
| 40 querying: true, | 41 querying: true, |
| 41 searchTerm: '', | 42 searchTerm: '', |
| 42 results: null, | 43 results: null, |
| 44 // Whether the most recent query was incremental. |
| 45 incremental: false, |
| 43 info: null, | 46 info: null, |
| 44 range: HistoryRange.ALL_TIME, | 47 range: HistoryRange.ALL_TIME, |
| 45 // TODO(calamity): Make history toolbar buttons change the offset. | 48 // TODO(calamity): Make history toolbar buttons change the offset. |
| 46 groupedOffset: 0, | 49 groupedOffset: 0, |
| 47 sessionList: null, | 50 sessionList: null, |
| 48 }; | 51 }; |
| 49 } | 52 } |
| 50 }, | 53 }, |
| 51 }, | 54 }, |
| 52 | 55 |
| 53 observers: [ | 56 observers: [ |
| 54 'searchTermChanged_(queryState_.searchTerm)', | 57 'searchTermChanged_(queryState_.searchTerm)', |
| 55 'groupedRangeChanged_(queryState_.range)', | 58 'groupedRangeChanged_(queryState_.range)', |
| 56 ], | 59 ], |
| 57 | 60 |
| 58 // TODO(calamity): Replace these event listeners with data bound properties. | 61 // TODO(calamity): Replace these event listeners with data bound properties. |
| 59 listeners: { | 62 listeners: { |
| 60 'history-checkbox-select': 'checkboxSelected', | 63 'history-checkbox-select': 'checkboxSelected', |
| 61 'unselect-all': 'unselectAll', | 64 'unselect-all': 'unselectAll', |
| 62 'delete-selected': 'deleteSelected', | 65 'delete-selected': 'deleteSelected', |
| 63 'search-domain': 'searchDomain_', | 66 'search-domain': 'searchDomain_', |
| 64 'load-more-history': 'loadMoreHistory_', | 67 'load-more-history': 'loadMoreHistory_', |
| 65 }, | 68 }, |
| 66 | 69 |
| 70 /** @override */ |
| 67 ready: function() { | 71 ready: function() { |
| 68 this.grouped_ = loadTimeData.getBoolean('groupByDomain'); | 72 this.grouped_ = loadTimeData.getBoolean('groupByDomain'); |
| 69 }, | 73 }, |
| 70 | 74 |
| 71 /** | 75 /** |
| 72 * Listens for history-item being selected or deselected (through checkbox) | 76 * Listens for history-item being selected or deselected (through checkbox) |
| 73 * and changes the view of the top toolbar. | 77 * and changes the view of the top toolbar. |
| 74 * @param {{detail: {countAddition: number}}} e | 78 * @param {{detail: {countAddition: number}}} e |
| 75 */ | 79 */ |
| 76 checkboxSelected: function(e) { | 80 checkboxSelected: function(e) { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 /** | 172 /** |
| 169 * Queries the history backend for results based on queryState_. | 173 * Queries the history backend for results based on queryState_. |
| 170 * @param {boolean} incremental Whether the new query should continue where | 174 * @param {boolean} incremental Whether the new query should continue where |
| 171 * the previous query stopped. | 175 * the previous query stopped. |
| 172 */ | 176 */ |
| 173 queryHistory: function(incremental) { | 177 queryHistory: function(incremental) { |
| 174 if (this.queryingDisabled_ || this.firstLoad_) | 178 if (this.queryingDisabled_ || this.firstLoad_) |
| 175 return; | 179 return; |
| 176 | 180 |
| 177 this.set('queryState_.querying', true); | 181 this.set('queryState_.querying', true); |
| 182 this.set('queryState_.incremental', incremental); |
| 178 | 183 |
| 179 var queryState = this.queryState_; | 184 var queryState = this.queryState_; |
| 180 | 185 |
| 181 var lastVisitTime = 0; | 186 var lastVisitTime = 0; |
| 182 if (incremental) { | 187 if (incremental) { |
| 183 var lastVisit = queryState.results.slice(-1)[0]; | 188 var lastVisit = queryState.results.slice(-1)[0]; |
| 184 lastVisitTime = lastVisit ? lastVisit.time : 0; | 189 lastVisitTime = lastVisit ? lastVisit.time : 0; |
| 185 } | 190 } |
| 186 | 191 |
| 187 var maxResults = | 192 var maxResults = |
| 188 queryState.range == HistoryRange.ALL_TIME ? RESULTS_PER_PAGE : 0; | 193 queryState.range == HistoryRange.ALL_TIME ? RESULTS_PER_PAGE : 0; |
| 189 chrome.send('queryHistory', [ | 194 chrome.send('queryHistory', [ |
| 190 queryState.searchTerm, queryState.groupedOffset, Number(queryState.range), | 195 queryState.searchTerm, queryState.groupedOffset, Number(queryState.range), |
| 191 lastVisitTime, maxResults | 196 lastVisitTime, maxResults |
| 192 ]); | 197 ]); |
| 193 }, | 198 }, |
| 194 | 199 |
| 195 /** | 200 /** |
| 196 * @param {!Array<!ForeignSession>} sessionList Array of objects describing | 201 * @param {!Array<!ForeignSession>} sessionList Array of objects describing |
| 197 * the sessions from other devices. | 202 * the sessions from other devices. |
| 198 * @param {boolean} isTabSyncEnabled Is tab sync enabled for this profile? | 203 * @param {boolean} isTabSyncEnabled Is tab sync enabled for this profile? |
| 199 */ | 204 */ |
| 200 setForeignSessions: function(sessionList, isTabSyncEnabled) { | 205 setForeignSessions: function(sessionList, isTabSyncEnabled) { |
| 201 if (!isTabSyncEnabled) | 206 if (!isTabSyncEnabled) |
| 202 return; | 207 return; |
| 203 | 208 |
| 204 this.set('queryState_.sessionList', sessionList); | 209 this.set('queryState_.sessionList', sessionList); |
| 205 }, | 210 }, |
| 206 | 211 |
| 212 /** |
| 213 * @param {string} selectedPage |
| 214 * @param {HistoryRange} range |
| 215 * @return {string} |
| 216 */ |
| 207 getSelectedPage: function(selectedPage, range) { | 217 getSelectedPage: function(selectedPage, range) { |
| 208 if (selectedPage == 'history-list' && range != HistoryRange.ALL_TIME) | 218 if (selectedPage == 'history-list' && range != HistoryRange.ALL_TIME) |
| 209 return 'history-grouped-list'; | 219 return 'history-grouped-list'; |
| 210 | 220 |
| 211 return selectedPage; | 221 return selectedPage; |
| 212 }, | 222 }, |
| 213 | 223 |
| 214 syncedTabsSelected_(selectedPage) { | 224 /** |
| 225 * @param {string} selectedPage |
| 226 * @return {boolean} |
| 227 * @private |
| 228 */ |
| 229 syncedTabsSelected_: function(selectedPage) { |
| 215 return selectedPage == 'history-synced-device-manager'; | 230 return selectedPage == 'history-synced-device-manager'; |
| 231 }, |
| 232 |
| 233 /** |
| 234 * @param {boolean} querying |
| 235 * @param {boolean} incremental |
| 236 * @param {string} searchTerm |
| 237 * @return {boolean} Whether a loading spinner should be shown (implies the |
| 238 * backend is querying a new search term). |
| 239 * @private |
| 240 */ |
| 241 shouldShowSpinner_: function(querying, incremental, searchTerm) { |
| 242 return querying && !incremental && searchTerm != ''; |
| 216 } | 243 } |
| 217 }); | 244 }); |
| OLD | NEW |