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