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