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 21 matching lines...) Expand all Loading... |
53 */ | 80 */ |
54 deleteSelected: function() { | 81 deleteSelected: function() { |
55 if (!loadTimeData.getBoolean('allowDeletingHistory')) | 82 if (!loadTimeData.getBoolean('allowDeletingHistory')) |
56 return; | 83 return; |
57 | 84 |
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 /** @type {HistoryListElement} */(this.$['history-list']).deleteSelected(); | 87 /** @type {HistoryListElement} */(this.$['history-list']).deleteSelected(); |
61 }, | 88 }, |
62 | 89 |
63 /** | 90 loadMoreHistory_: function() { |
64 * When the search is changed refresh the results from the backend. | 91 this.queryHistory(true); |
65 * Ensures that the search bar is updated with the new search term. | |
66 * @param {{detail: {search: string}}} e | |
67 */ | |
68 searchChanged: function(e) { | |
69 this.$.toolbar.setSearchTerm(e.detail.search); | |
70 /** @type {HistoryListElement} */(this.$['history-list']).setLoading(); | |
71 /** @type {HistoryToolbarElement} */(this.$.toolbar).searching = true; | |
72 chrome.send('queryHistory', [e.detail.search, 0, 0, 0, RESULTS_PER_PAGE]); | |
73 }, | 92 }, |
74 | 93 |
75 /** | 94 /** |
76 * @param {HistoryQuery} info An object containing information about the | 95 * @param {HistoryQuery} info An object containing information about the |
77 * query. | 96 * query. |
78 * @param {!Array<HistoryEntry>} results A list of results. | 97 * @param {!Array<HistoryEntry>} results A list of results. |
79 */ | 98 */ |
80 historyResult: function(info, results) { | 99 historyResult: function(info, results) { |
| 100 this.set('queryState_.querying', false); |
| 101 this.set('queryState_.results', results); |
| 102 this.set('queryState_.info', info); |
| 103 |
81 var list = /** @type {HistoryListElement} */(this.$['history-list']); | 104 var list = /** @type {HistoryListElement} */(this.$['history-list']); |
82 list.addNewResults(results, info.term); | 105 list.addNewResults(results); |
83 /** @type {HistoryToolbarElement} */(this.$.toolbar).searching = false; | |
84 if (info.finished) | 106 if (info.finished) |
85 list.disableResultLoading(); | 107 list.disableResultLoading(); |
86 | |
87 var toolbar = /** @type {HistoryToolbarElement} */(this.$.toolbar); | |
88 toolbar.queryStartTime = info.queryStartTime; | |
89 toolbar.queryEndTime = info.queryEndTime; | |
90 }, | 108 }, |
91 | 109 |
92 /** | 110 /** |
| 111 * Fired when the user presses 'More from this site'. |
| 112 * @param {{detail: {domain: string}}} e |
| 113 */ |
| 114 searchDomain_: function(e) { |
| 115 this.$.toolbar.setSearchTerm(e.detail.domain); |
| 116 }, |
| 117 |
| 118 searchTermChanged_: function() { |
| 119 this.queryHistory(false); |
| 120 }, |
| 121 |
| 122 queryHistory: function(incremental) { |
| 123 var lastVisitTime = 0; |
| 124 if (incremental) { |
| 125 var lastVisit = this.queryState_.results.slice(-1)[0]; |
| 126 lastVisitTime = lastVisit ? lastVisit.time : 0; |
| 127 } |
| 128 |
| 129 this.set('queryState_.querying', true); |
| 130 chrome.send( |
| 131 'queryHistory', |
| 132 [this.queryState_.searchTerm, 0, 0, lastVisitTime, RESULTS_PER_PAGE]); |
| 133 }, |
| 134 |
| 135 /** |
93 * @param {!Array<!ForeignSession>} sessionList Array of objects describing | 136 * @param {!Array<!ForeignSession>} sessionList Array of objects describing |
94 * the sessions from other devices. | 137 * the sessions from other devices. |
95 * @param {boolean} isTabSyncEnabled Is tab sync enabled for this profile? | 138 * @param {boolean} isTabSyncEnabled Is tab sync enabled for this profile? |
96 */ | 139 */ |
97 setForeignSessions: function(sessionList, isTabSyncEnabled) { | 140 setForeignSessions: function(sessionList, isTabSyncEnabled) { |
98 if (!isTabSyncEnabled) | 141 if (!isTabSyncEnabled) |
99 return; | 142 return; |
100 | 143 |
101 // TODO(calamity): Add a 'no synced devices' message when sessions are | 144 // TODO(calamity): Add a 'no synced devices' message when sessions are |
102 // empty. | 145 // empty. |
103 var syncedDeviceElem = this.$['history-synced-device-manager']; | 146 var syncedDeviceElem = this.$['history-synced-device-manager']; |
104 var syncedDeviceManager = | 147 var syncedDeviceManager = |
105 /** @type {HistorySyncedDeviceManagerElement} */(syncedDeviceElem); | 148 /** @type {HistorySyncedDeviceManagerElement} */(syncedDeviceElem); |
106 syncedDeviceManager.setSyncedHistory(sessionList); | 149 syncedDeviceManager.setSyncedHistory(sessionList); |
107 } | 150 } |
108 }); | 151 }); |
OLD | NEW |