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; | |
|
tsergeant
2016/06/24 06:19:17
Should this one move to constants.js as well?
calamity
2016/06/27 03:35:46
This will likely stay confined to this element.
| |
| 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 initializeResults_: function(info, results) { | |
|
tsergeant
2016/06/24 06:19:17
Nit: /** @private */
calamity
2016/06/27 03:35:46
Done.
| |
| 49 if (results.length == 0) | |
| 50 return; | |
| 51 | |
| 52 var currentDate = results[0].dateRelativeDay; | |
| 53 | |
| 54 for (var i = 0; i < results.length; i++) { | |
| 55 // Sets the default values for these fields to prevent undefined types. | |
| 56 results[i].selected = false; | |
| 57 results[i].readableTimestamp = | |
| 58 info.term == '' ? results[i].dateTimeOfDay : results[i].dateShort; | |
| 59 | |
| 60 if (results[i].dateRelativeDay != currentDate) { | |
| 61 currentDate = results[i].dateRelativeDay; | |
| 62 } | |
| 63 } | |
| 64 }, | |
| 65 | |
| 66 searchTermChanged_: function(searchTerm) { this.queryHistory(false); }, | |
| 67 | |
| 68 groupedRangeChanged_: function(range) { | |
| 69 this.selectedPage_ = this.queryState.range == HistoryRange.ALL_TIME ? | |
| 70 'infinite-list' : 'grouped-list'; | |
| 71 | |
| 72 this.queryHistory(false); | |
| 73 }, | |
| 74 | |
| 75 loadMoreHistory_: function() { this.queryHistory(true); }, | |
| 76 | |
| 77 /** | |
| 78 * @param {HistoryQuery} info An object containing information about the | |
| 79 * query. | |
| 80 * @param {!Array<HistoryEntry>} results A list of results. | |
| 81 */ | |
| 82 historyResult: function(info, results) { | |
|
tsergeant
2016/06/24 06:19:17
Style guide is for public functions to appear befo
calamity
2016/06/27 03:35:46
Done.
| |
| 83 this.initializeResults_(info, results); | |
| 84 | |
| 85 this.set('queryResult_.info', info); | |
| 86 this.set('queryResult_.results', results); | |
| 87 | |
| 88 if (this.selectedPage_ == 'grouped-list') { | |
| 89 this.$$('#grouped-list').historyData = results; | |
| 90 return; | |
| 91 } | |
| 92 | |
| 93 var list = /** @type {HistoryListElement} */(this.$['infinite-list']); | |
| 94 list.addNewResults(results); | |
| 95 if (info.finished) | |
| 96 list.disableResultLoading(); | |
| 97 }, | |
| 98 | |
| 99 /** | |
| 100 * Queries the history backend for results based on queryState. | |
| 101 * @param {boolean} incremental Whether the new query should continue where | |
| 102 * the previous query stopped. | |
| 103 */ | |
| 104 queryHistory: function(incremental) { | |
| 105 var queryState = this.queryState; | |
| 106 // Disable querying until the first set of results have been returned. | |
| 107 if (this.queryResult_.results == null || queryState.queryingDisabled) | |
| 108 return; | |
| 109 | |
| 110 this.set('queryState.querying', true); | |
| 111 this.set('queryState.incremental', incremental); | |
| 112 | |
| 113 | |
| 114 var lastVisitTime = 0; | |
| 115 if (incremental) { | |
| 116 var lastVisit = this.queryResult_.results.slice(-1)[0]; | |
| 117 lastVisitTime = lastVisit ? lastVisit.time : 0; | |
| 118 } | |
| 119 | |
| 120 var maxResults = | |
| 121 queryState.range == HistoryRange.ALL_TIME ? RESULTS_PER_PAGE : 0; | |
| 122 chrome.send('queryHistory', [ | |
| 123 queryState.searchTerm, queryState.groupedOffset, queryState.range, | |
| 124 lastVisitTime, maxResults | |
| 125 ]); | |
| 126 }, | |
| 127 | |
| 128 unselectAllItems: function(count) { | |
| 129 /** @type {HistoryListElement} */ (this.$['infinite-list']) | |
| 130 .unselectAllItems(count); | |
| 131 }, | |
| 132 | |
| 133 deleteSelected: function() { | |
| 134 /** @type {HistoryListElement} */ (this.$['infinite-list']) | |
| 135 .deleteSelected(); | |
| 136 } | |
| 137 }); | |
| OLD | NEW |