| 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 {{results: ?Array<!HistoryEntry>, | |
| 7 * info: ?HistoryQuery}} | |
| 8 */ | |
| 9 var QueryResult; | |
| 10 | |
| 11 Polymer({ | 5 Polymer({ |
| 12 is: 'history-list-container', | 6 is: 'history-list-container', |
| 13 | 7 |
| 14 properties: { | 8 properties: { |
| 15 // The path of the currently selected page. | 9 // The path of the currently selected page. |
| 16 selectedPage_: String, | 10 selectedPage_: String, |
| 17 | 11 |
| 18 // Whether domain-grouped history is enabled. | 12 // Whether domain-grouped history is enabled. |
| 19 grouped: Boolean, | 13 grouped: Boolean, |
| 20 | 14 |
| 21 /** @type {!QueryState} */ | 15 /** @type {!QueryState} */ |
| 22 queryState: { | 16 queryState: Object, |
| 23 type: Object, | |
| 24 }, | |
| 25 | 17 |
| 26 /** @type {!QueryResult} */ | 18 /** @type {!QueryResult} */ |
| 27 queryResult_: { | 19 queryResult: Object, |
| 28 type: Object, | |
| 29 readOnly: true, | |
| 30 value: function() { | |
| 31 return { | |
| 32 info: null, | |
| 33 results: null, | |
| 34 }; | |
| 35 } | |
| 36 }, | |
| 37 }, | 20 }, |
| 38 | 21 |
| 39 observers: [ | 22 observers: [ |
| 40 'searchTermChanged_(queryState.searchTerm)', | 23 'searchTermChanged_(queryState.searchTerm)', |
| 41 'groupedRangeChanged_(queryState.range)', | 24 'groupedRangeChanged_(queryState.range)', |
| 42 ], | 25 ], |
| 43 | 26 |
| 44 listeners: { | 27 listeners: { |
| 45 'load-more-history': 'loadMoreHistory_', | 28 'load-more-history': 'loadMoreHistory_', |
| 46 }, | 29 }, |
| 47 | 30 |
| 48 /** | 31 /** |
| 49 * @param {HistoryQuery} info An object containing information about the | 32 * @param {HistoryQuery} info An object containing information about the |
| 50 * query. | 33 * query. |
| 51 * @param {!Array<HistoryEntry>} results A list of results. | 34 * @param {!Array<HistoryEntry>} results A list of results. |
| 52 */ | 35 */ |
| 53 historyResult: function(info, results) { | 36 historyResult: function(info, results) { |
| 54 this.initializeResults_(info, results); | 37 this.initializeResults_(info, results); |
| 55 | 38 |
| 56 this.set('queryResult_.info', info); | |
| 57 this.set('queryResult_.results', results); | |
| 58 | |
| 59 if (this.selectedPage_ == 'grouped-list') { | 39 if (this.selectedPage_ == 'grouped-list') { |
| 60 this.$$('#grouped-list').historyData = results; | 40 this.$$('#grouped-list').historyData = results; |
| 61 return; | 41 return; |
| 62 } | 42 } |
| 63 | 43 |
| 64 var list = /** @type {HistoryListElement} */(this.$['infinite-list']); | 44 var list = /** @type {HistoryListElement} */(this.$['infinite-list']); |
| 65 list.addNewResults(results); | 45 list.addNewResults(results); |
| 66 if (info.finished) | 46 if (info.finished) |
| 67 list.disableResultLoading(); | 47 list.disableResultLoading(); |
| 68 }, | 48 }, |
| 69 | 49 |
| 70 /** | 50 /** |
| 71 * Queries the history backend for results based on queryState. | 51 * Queries the history backend for results based on queryState. |
| 72 * @param {boolean} incremental Whether the new query should continue where | 52 * @param {boolean} incremental Whether the new query should continue where |
| 73 * the previous query stopped. | 53 * the previous query stopped. |
| 74 */ | 54 */ |
| 75 queryHistory: function(incremental) { | 55 queryHistory: function(incremental) { |
| 76 var queryState = this.queryState; | 56 var queryState = this.queryState; |
| 77 // Disable querying until the first set of results have been returned. | 57 // Disable querying until the first set of results have been returned. |
| 78 if (this.queryResult_.results == null || queryState.queryingDisabled) | 58 if (!this.queryResult || this.queryResult.results == null || |
| 59 queryState.queryingDisabled) { |
| 79 return; | 60 return; |
| 61 } |
| 80 | 62 |
| 81 this.set('queryState.querying', true); | 63 this.set('queryState.querying', true); |
| 82 this.set('queryState.incremental', incremental); | 64 this.set('queryState.incremental', incremental); |
| 83 | 65 |
| 84 | 66 |
| 85 var lastVisitTime = 0; | 67 var lastVisitTime = 0; |
| 86 if (incremental) { | 68 if (incremental) { |
| 87 var lastVisit = this.queryResult_.results.slice(-1)[0]; | 69 var lastVisit = this.queryResult.results.slice(-1)[0]; |
| 88 lastVisitTime = lastVisit ? lastVisit.time : 0; | 70 lastVisitTime = lastVisit ? lastVisit.time : 0; |
| 89 } | 71 } |
| 90 | 72 |
| 91 var maxResults = | 73 var maxResults = |
| 92 queryState.range == HistoryRange.ALL_TIME ? RESULTS_PER_PAGE : 0; | 74 queryState.range == HistoryRange.ALL_TIME ? RESULTS_PER_PAGE : 0; |
| 93 chrome.send('queryHistory', [ | 75 chrome.send('queryHistory', [ |
| 94 queryState.searchTerm, queryState.groupedOffset, queryState.range, | 76 queryState.searchTerm, queryState.groupedOffset, queryState.range, |
| 95 lastVisitTime, maxResults | 77 lastVisitTime, maxResults |
| 96 ]); | 78 ]); |
| 97 }, | 79 }, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 results[i].selected = false; | 125 results[i].selected = false; |
| 144 results[i].readableTimestamp = | 126 results[i].readableTimestamp = |
| 145 info.term == '' ? results[i].dateTimeOfDay : results[i].dateShort; | 127 info.term == '' ? results[i].dateTimeOfDay : results[i].dateShort; |
| 146 | 128 |
| 147 if (results[i].dateRelativeDay != currentDate) { | 129 if (results[i].dateRelativeDay != currentDate) { |
| 148 currentDate = results[i].dateRelativeDay; | 130 currentDate = results[i].dateRelativeDay; |
| 149 } | 131 } |
| 150 } | 132 } |
| 151 }, | 133 }, |
| 152 }); | 134 }); |
| OLD | NEW |