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 /** |
| 6 * @typedef {{querying: boolean, |
| 7 * searchTerm: string, |
| 8 * results: ?Array<!HistoryEntry>, |
| 9 * info: ?HistoryQuery}} |
| 10 */ |
| 11 var QueryState; |
| 12 |
5 Polymer({ | 13 Polymer({ |
6 is: 'history-app', | 14 is: 'history-app', |
7 | 15 |
8 properties: { | 16 properties: { |
9 // The id of the currently selected page. | 17 // The id of the currently selected page. |
10 selectedPage: { | 18 selectedPage: { |
11 type: String, | 19 type: String, |
12 value: 'history-list' | 20 value: 'history-list' |
13 } | 21 }, |
| 22 |
| 23 /** @type {!QueryState} */ |
| 24 queryState_: { |
| 25 type: Object, |
| 26 value: function() { |
| 27 return { |
| 28 // A query is initiated by page load. |
| 29 querying: true, |
| 30 searchTerm: '', |
| 31 results: null, |
| 32 info: null, |
| 33 }; |
| 34 } |
| 35 }, |
14 }, | 36 }, |
15 | 37 |
| 38 observers: [ |
| 39 'searchTermChanged_(queryState_.searchTerm)', |
| 40 ], |
| 41 |
16 // TODO(calamity): Replace these event listeners with data bound properties. | 42 // TODO(calamity): Replace these event listeners with data bound properties. |
17 listeners: { | 43 listeners: { |
18 'history-checkbox-select': 'checkboxSelected', | 44 'history-checkbox-select': 'checkboxSelected', |
19 'unselect-all': 'unselectAll', | 45 'unselect-all': 'unselectAll', |
20 'delete-selected': 'deleteSelected', | 46 'delete-selected': 'deleteSelected', |
21 'search-changed': 'searchChanged', | 47 'search-domain': 'searchDomain_', |
| 48 'load-more-history': 'loadMoreHistory_', |
22 }, | 49 }, |
23 | 50 |
24 ready: function() { | 51 ready: function() { |
25 this.$.toolbar.isGroupedMode = loadTimeData.getBoolean('groupByDomain'); | 52 this.$.toolbar.isGroupedMode = loadTimeData.getBoolean('groupByDomain'); |
26 }, | 53 }, |
27 | 54 |
28 /** | 55 /** |
29 * Listens for history-item being selected or deselected (through checkbox) | 56 * Listens for history-item being selected or deselected (through checkbox) |
30 * and changes the view of the top toolbar. | 57 * and changes the view of the top toolbar. |
31 * @param {{detail: {countAddition: number}}} e | 58 * @param {{detail: {countAddition: number}}} e |
(...skipping 26 matching lines...) Expand all Loading... |
58 // TODO(hsampson): add a popup to check whether the user definitely | 85 // TODO(hsampson): add a popup to check whether the user definitely |
59 // wants to delete the selected items. | 86 // wants to delete the selected items. |
60 | 87 |
61 var historyList = | 88 var historyList = |
62 /** @type {HistoryListElement} */(this.$['history-list']); | 89 /** @type {HistoryListElement} */(this.$['history-list']); |
63 var toolbar = /** @type {HistoryToolbarElement} */(this.$.toolbar); | 90 var toolbar = /** @type {HistoryToolbarElement} */(this.$.toolbar); |
64 var toBeRemoved = historyList.getSelectedItems(toolbar.count); | 91 var toBeRemoved = historyList.getSelectedItems(toolbar.count); |
65 chrome.send('removeVisits', toBeRemoved); | 92 chrome.send('removeVisits', toBeRemoved); |
66 }, | 93 }, |
67 | 94 |
68 /** | 95 loadMoreHistory_: function() { |
69 * When the search is changed refresh the results from the backend. | 96 this.queryHistory(true); |
70 * Ensures that the search bar is updated with the new search term. | |
71 * @param {{detail: {search: string}}} e | |
72 */ | |
73 searchChanged: function(e) { | |
74 this.$.toolbar.setSearchTerm(e.detail.search); | |
75 /** @type {HistoryListElement} */(this.$['history-list']).setLoading(); | |
76 /** @type {HistoryToolbarElement} */(this.$.toolbar).searching = true; | |
77 chrome.send('queryHistory', [e.detail.search, 0, 0, 0, RESULTS_PER_PAGE]); | |
78 }, | 97 }, |
79 | 98 |
80 /** | 99 /** |
81 * @param {HistoryQuery} info An object containing information about the | 100 * @param {HistoryQuery} info An object containing information about the |
82 * query. | 101 * query. |
83 * @param {!Array<HistoryEntry>} results A list of results. | 102 * @param {!Array<HistoryEntry>} results A list of results. |
84 */ | 103 */ |
85 historyResult: function(info, results) { | 104 historyResult: function(info, results) { |
| 105 this.set('queryState_.querying', false); |
| 106 this.set('queryState_.results', results); |
| 107 this.set('queryState_.info', info); |
| 108 |
86 var list = /** @type {HistoryListElement} */(this.$['history-list']); | 109 var list = /** @type {HistoryListElement} */(this.$['history-list']); |
87 list.addNewResults(results, info.term); | 110 list.addNewResults(results); |
88 /** @type {HistoryToolbarElement} */(this.$.toolbar).searching = false; | |
89 if (info.finished) | 111 if (info.finished) |
90 list.disableResultLoading(); | 112 list.disableResultLoading(); |
91 | |
92 var toolbar = /** @type {HistoryToolbarElement} */(this.$.toolbar); | |
93 toolbar.queryStartTime = info.queryStartTime; | |
94 toolbar.queryEndTime = info.queryEndTime; | |
95 }, | 113 }, |
96 | 114 |
97 /** | 115 /** |
| 116 * Fired when the user presses 'More from this site'. |
| 117 * @param {{detail: {domain: string}}} e |
| 118 */ |
| 119 searchDomain_: function(e) { |
| 120 this.$.toolbar.setSearchTerm(e.detail.domain); |
| 121 }, |
| 122 |
| 123 searchTermChanged_: function() { |
| 124 this.queryHistory(false); |
| 125 }, |
| 126 |
| 127 queryHistory: function(incremental) { |
| 128 var lastVisitTime = 0; |
| 129 if (incremental) { |
| 130 var lastVisit = this.queryState_.results.slice(-1)[0]; |
| 131 lastVisitTime = lastVisit ? lastVisit.time : 0; |
| 132 } |
| 133 |
| 134 this.set('queryState_.querying', true); |
| 135 chrome.send( |
| 136 'queryHistory', |
| 137 [this.queryState_.searchTerm, 0, 0, lastVisitTime, RESULTS_PER_PAGE]); |
| 138 }, |
| 139 |
| 140 /** |
98 * @param {!Array<!ForeignSession>} sessionList Array of objects describing | 141 * @param {!Array<!ForeignSession>} sessionList Array of objects describing |
99 * the sessions from other devices. | 142 * the sessions from other devices. |
100 * @param {boolean} isTabSyncEnabled Is tab sync enabled for this profile? | 143 * @param {boolean} isTabSyncEnabled Is tab sync enabled for this profile? |
101 */ | 144 */ |
102 setForeignSessions: function(sessionList, isTabSyncEnabled) { | 145 setForeignSessions: function(sessionList, isTabSyncEnabled) { |
103 if (!isTabSyncEnabled) | 146 if (!isTabSyncEnabled) |
104 return; | 147 return; |
105 | 148 |
106 // TODO(calamity): Add a 'no synced devices' message when sessions are | 149 // TODO(calamity): Add a 'no synced devices' message when sessions are |
107 // empty. | 150 // empty. |
108 var syncedDeviceElem = this.$['history-synced-device-manager']; | 151 var syncedDeviceElem = this.$['history-synced-device-manager']; |
109 var syncedDeviceManager = | 152 var syncedDeviceManager = |
110 /** @type {HistorySyncedDeviceManagerElement} */(syncedDeviceElem); | 153 /** @type {HistorySyncedDeviceManagerElement} */(syncedDeviceElem); |
111 syncedDeviceManager.setSyncedHistory(sessionList); | 154 syncedDeviceManager.setSyncedHistory(sessionList); |
112 }, | 155 }, |
113 | 156 |
114 deleteComplete: function() { | 157 deleteComplete: function() { |
115 var historyList = /** @type {HistoryListElement} */(this.$['history-list']); | 158 var historyList = /** @type {HistoryListElement} */(this.$['history-list']); |
116 var toolbar = /** @type {HistoryToolbarElement} */(this.$.toolbar); | 159 var toolbar = /** @type {HistoryToolbarElement} */(this.$.toolbar); |
117 historyList.removeDeletedHistory(toolbar.count); | 160 historyList.removeDeletedHistory(toolbar.count); |
118 toolbar.count = 0; | 161 toolbar.count = 0; |
119 } | 162 } |
120 }); | 163 }); |
OLD | NEW |