| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 /** |
| 6 * @typedef {{results: ?Array<!HistoryEntry>, |
| 7 * info: ?HistoryQuery}} |
| 8 */ |
| 9 var QueryResult; |
| 10 |
| 11 Polymer({ |
| 12 is: 'history-list-container', |
| 13 |
| 14 properties: { |
| 15 // The path of the currently selected page. |
| 16 selectedPage_: String, |
| 17 |
| 18 // Whether domain-grouped history is enabled. |
| 19 grouped: Boolean, |
| 20 |
| 21 /** @type {!QueryState} */ |
| 22 queryState: { |
| 23 type: Object, |
| 24 }, |
| 25 |
| 26 /** @type {!QueryResult} */ |
| 27 queryResult_: { |
| 28 type: Object, |
| 29 readOnly: true, |
| 30 value: function() { |
| 31 return { |
| 32 info: null, |
| 33 results: null, |
| 34 }; |
| 35 } |
| 36 }, |
| 37 }, |
| 38 |
| 39 observers: [ |
| 40 'searchTermChanged_(queryState.searchTerm)', |
| 41 'groupedRangeChanged_(queryState.range)', |
| 42 ], |
| 43 |
| 44 listeners: { |
| 45 'load-more-history': 'loadMoreHistory_', |
| 46 }, |
| 47 |
| 48 /** |
| 49 * @param {HistoryQuery} info An object containing information about the |
| 50 * query. |
| 51 * @param {!Array<HistoryEntry>} results A list of results. |
| 52 */ |
| 53 historyResult: function(info, results) { |
| 54 this.initializeResults_(info, results); |
| 55 |
| 56 this.set('queryResult_.info', info); |
| 57 this.set('queryResult_.results', results); |
| 58 |
| 59 if (this.selectedPage_ == 'grouped-list') { |
| 60 this.$$('#grouped-list').historyData = results; |
| 61 return; |
| 62 } |
| 63 |
| 64 var list = /** @type {HistoryListElement} */(this.$['infinite-list']); |
| 65 list.addNewResults(results); |
| 66 if (info.finished) |
| 67 list.disableResultLoading(); |
| 68 }, |
| 69 |
| 70 /** |
| 71 * Queries the history backend for results based on queryState. |
| 72 * @param {boolean} incremental Whether the new query should continue where |
| 73 * the previous query stopped. |
| 74 */ |
| 75 queryHistory: function(incremental) { |
| 76 var queryState = this.queryState; |
| 77 // Disable querying until the first set of results have been returned. |
| 78 if (this.queryResult_.results == null || queryState.queryingDisabled) |
| 79 return; |
| 80 |
| 81 this.set('queryState.querying', true); |
| 82 this.set('queryState.incremental', incremental); |
| 83 |
| 84 |
| 85 var lastVisitTime = 0; |
| 86 if (incremental) { |
| 87 var lastVisit = this.queryResult_.results.slice(-1)[0]; |
| 88 lastVisitTime = lastVisit ? lastVisit.time : 0; |
| 89 } |
| 90 |
| 91 var maxResults = |
| 92 queryState.range == HistoryRange.ALL_TIME ? RESULTS_PER_PAGE : 0; |
| 93 chrome.send('queryHistory', [ |
| 94 queryState.searchTerm, queryState.groupedOffset, queryState.range, |
| 95 lastVisitTime, maxResults |
| 96 ]); |
| 97 }, |
| 98 |
| 99 unselectAllItems: function(count) { |
| 100 /** @type {HistoryListElement} */ (this.$['infinite-list']) |
| 101 .unselectAllItems(count); |
| 102 }, |
| 103 |
| 104 deleteSelected: function() { |
| 105 /** @type {HistoryListElement} */ (this.$['infinite-list']) |
| 106 .deleteSelected(); |
| 107 }, |
| 108 |
| 109 /** |
| 110 * @param {string} searchTerm |
| 111 * @private |
| 112 */ |
| 113 searchTermChanged_: function(searchTerm) { this.queryHistory(false); }, |
| 114 |
| 115 /** |
| 116 * @param {HistoryRange} range |
| 117 * @private |
| 118 */ |
| 119 groupedRangeChanged_: function(range) { |
| 120 this.selectedPage_ = this.queryState.range == HistoryRange.ALL_TIME ? |
| 121 'infinite-list' : 'grouped-list'; |
| 122 |
| 123 this.queryHistory(false); |
| 124 }, |
| 125 |
| 126 /** @private */ |
| 127 loadMoreHistory_: function() { this.queryHistory(true); }, |
| 128 |
| 129 |
| 130 /** |
| 131 * @param {HistoryQuery} info |
| 132 * @param {!Array<HistoryEntry>} results |
| 133 * @private |
| 134 */ |
| 135 initializeResults_: function(info, results) { |
| 136 if (results.length == 0) |
| 137 return; |
| 138 |
| 139 var currentDate = results[0].dateRelativeDay; |
| 140 |
| 141 for (var i = 0; i < results.length; i++) { |
| 142 // Sets the default values for these fields to prevent undefined types. |
| 143 results[i].selected = false; |
| 144 results[i].readableTimestamp = |
| 145 info.term == '' ? results[i].dateTimeOfDay : results[i].dateShort; |
| 146 |
| 147 if (results[i].dateRelativeDay != currentDate) { |
| 148 currentDate = results[i].dateRelativeDay; |
| 149 } |
| 150 } |
| 151 }, |
| 152 }); |
| OLD | NEW |