Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 Polymer({ | 5 Polymer({ |
| 6 is: 'history-query-manager', | 6 is: 'history-query-manager', |
| 7 | 7 |
| 8 properties: { | 8 properties: { |
| 9 /** @type {QueryState} */ | 9 /** @type {QueryState} */ |
| 10 queryState: { | 10 queryState: { |
| 11 type: Object, | 11 type: Object, |
| 12 notify: true, | 12 notify: true, |
| 13 value: function() { | 13 value: function() { |
| 14 return { | 14 return { |
| 15 // Whether the most recent query was incremental. | 15 // Whether the most recent query was incremental. |
| 16 incremental: false, | 16 incremental: false, |
| 17 // A query is initiated by page load. | 17 // A query is initiated by page load. |
| 18 querying: true, | 18 querying: true, |
| 19 queryingDisabled: false, | 19 queryingDisabled: false, |
| 20 _range: HistoryRange.ALL_TIME, | |
| 21 searchTerm: '', | 20 searchTerm: '', |
| 22 groupedOffset: 0, | |
| 23 | |
| 24 set range(val) { | |
| 25 this._range = Number(val); | |
| 26 }, | |
| 27 get range() { | |
| 28 return this._range; | |
| 29 }, | |
| 30 }; | 21 }; |
| 31 }, | 22 }, |
| 32 }, | 23 }, |
| 33 | 24 |
| 34 /** @type {QueryResult} */ | 25 /** @type {QueryResult} */ |
| 35 queryResult: Object, | 26 queryResult: Object, |
| 36 | 27 |
| 37 /** @type {?HistoryRouterElement} */ | 28 /** @type {?HistoryRouterElement} */ |
| 38 router: Object, | 29 router: Object, |
| 39 }, | 30 }, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 | 63 |
| 73 this.set('queryState.querying', true); | 64 this.set('queryState.querying', true); |
| 74 this.set('queryState.incremental', incremental); | 65 this.set('queryState.incremental', incremental); |
| 75 | 66 |
| 76 var lastVisitTime = 0; | 67 var lastVisitTime = 0; |
| 77 if (incremental) { | 68 if (incremental) { |
| 78 var lastVisit = this.queryResult.results.slice(-1)[0]; | 69 var lastVisit = this.queryResult.results.slice(-1)[0]; |
| 79 lastVisitTime = lastVisit ? Math.floor(lastVisit.time) : 0; | 70 lastVisitTime = lastVisit ? Math.floor(lastVisit.time) : 0; |
| 80 } | 71 } |
| 81 | 72 |
| 82 var maxResults = | |
| 83 this.queryState.range == HistoryRange.ALL_TIME ? RESULTS_PER_PAGE : 0; | |
| 84 | |
| 85 chrome.send('queryHistory', [ | 73 chrome.send('queryHistory', [ |
| 86 queryState.searchTerm, | 74 queryState.searchTerm, |
| 87 queryState.groupedOffset, | 75 0, |
| 88 queryState.range, | 76 HistoryRange.ALL_TIME, |
| 89 lastVisitTime, | 77 lastVisitTime, |
| 90 maxResults, | 78 RESULTS_PER_PAGE, |
| 91 ]); | 79 ]); |
| 92 }, | 80 }, |
| 93 | 81 |
| 94 /** | 82 /** |
| 95 * @param {!Event} e | 83 * @param {!Event} e |
| 96 * @private | 84 * @private |
| 97 */ | 85 */ |
| 98 onChangeQuery_: function(e) { | 86 onChangeQuery_: function(e) { |
| 99 var changes = | 87 var changes = |
| 100 /** @type {{range: ?HistoryRange, offset: ?number, search: ?string}} */ | 88 /** @type {{range: ?HistoryRange, offset: ?number, search: ?string}} */ |
|
calamity
2017/02/09 02:45:08
Shouldn't need HistoryRange anymore. Also get rid
tsergeant
2017/02/09 03:13:41
Done.
| |
| 101 (e.detail); | 89 (e.detail); |
| 102 var needsUpdate = false; | 90 var needsUpdate = false; |
| 103 | 91 |
| 104 if (changes.range != null && changes.range != this.queryState.range) { | |
| 105 this.set('queryState.range', changes.range); | |
| 106 needsUpdate = true; | |
| 107 | |
| 108 // Reset back to page 0 of the results, unless changing to a specific | |
| 109 // page. | |
| 110 if (!changes.offset) | |
| 111 this.set('queryState.groupedOffset', 0); | |
| 112 | |
| 113 this.fire('history-view-changed'); | |
| 114 } | |
| 115 | |
| 116 if (changes.offset != null && | |
| 117 changes.offset != this.queryState.groupedOffset) { | |
| 118 this.set('queryState.groupedOffset', changes.offset); | |
| 119 needsUpdate = true; | |
| 120 } | |
| 121 | |
| 122 if (changes.search != null && | 92 if (changes.search != null && |
| 123 changes.search != this.queryState.searchTerm) { | 93 changes.search != this.queryState.searchTerm) { |
| 124 this.set('queryState.searchTerm', changes.search); | 94 this.set('queryState.searchTerm', changes.search); |
| 125 needsUpdate = true; | 95 needsUpdate = true; |
| 126 } | 96 } |
| 127 | 97 |
| 128 if (needsUpdate) { | 98 if (needsUpdate) { |
| 129 this.queryHistory_(false); | 99 this.queryHistory_(false); |
| 130 if (this.router) | 100 if (this.router) |
| 131 this.router.serializeUrl(); | 101 this.router.serializeUrl(); |
| 132 } | 102 } |
| 133 }, | 103 }, |
| 134 | 104 |
| 135 /** | 105 /** |
| 136 * @param {!Event} e | 106 * @param {!Event} e |
| 137 * @private | 107 * @private |
| 138 */ | 108 */ |
| 139 onQueryHistory_: function(e) { | 109 onQueryHistory_: function(e) { |
| 140 this.queryHistory_(/** @type {boolean} */ e.detail); | 110 this.queryHistory_(/** @type {boolean} */ e.detail); |
| 141 return false; | 111 return false; |
| 142 }, | 112 }, |
| 143 | 113 |
| 144 /** @private */ | 114 /** @private */ |
| 145 searchTermChanged_: function() { | 115 searchTermChanged_: function() { |
| 146 // TODO(tsergeant): Ignore incremental searches in this metric. | 116 // TODO(tsergeant): Ignore incremental searches in this metric. |
| 147 if (this.queryState.searchTerm) | 117 if (this.queryState.searchTerm) |
| 148 md_history.BrowserService.getInstance().recordAction('Search'); | 118 md_history.BrowserService.getInstance().recordAction('Search'); |
| 149 }, | 119 }, |
| 150 }); | 120 }); |
| OLD | NEW |