| 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: { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 }, | 26 }, |
| 27 get range() { | 27 get range() { |
| 28 return this._range; | 28 return this._range; |
| 29 }, | 29 }, |
| 30 }; | 30 }; |
| 31 }, | 31 }, |
| 32 }, | 32 }, |
| 33 | 33 |
| 34 /** @type {QueryResult} */ | 34 /** @type {QueryResult} */ |
| 35 queryResult: Object, | 35 queryResult: Object, |
| 36 |
| 37 /** @type {?HistoryRouterElement} */ |
| 38 router: Object, |
| 36 }, | 39 }, |
| 37 | 40 |
| 38 observers: [ | 41 observers: [ |
| 39 'searchTermChanged_(queryState.searchTerm)', | 42 'searchTermChanged_(queryState.searchTerm)', |
| 40 ], | 43 ], |
| 41 | 44 |
| 42 /** @private {!Object<string, !function(!Event)>} */ | 45 /** @private {!Object<string, !function(!Event)>} */ |
| 43 documentListeners_: {}, | 46 documentListeners_: {}, |
| 44 | 47 |
| 45 /** @override */ | 48 /** @override */ |
| (...skipping 10 matching lines...) Expand all Loading... |
| 56 for (var e in this.documentListeners_) | 59 for (var e in this.documentListeners_) |
| 57 document.removeEventListener(e, this.documentListeners_[e]); | 60 document.removeEventListener(e, this.documentListeners_[e]); |
| 58 }, | 61 }, |
| 59 | 62 |
| 60 /** | 63 /** |
| 61 * @param {boolean} incremental | 64 * @param {boolean} incremental |
| 62 * @private | 65 * @private |
| 63 */ | 66 */ |
| 64 queryHistory_: function(incremental) { | 67 queryHistory_: function(incremental) { |
| 65 var queryState = this.queryState; | 68 var queryState = this.queryState; |
| 66 // Disable querying until the first set of results have been returned. If | 69 |
| 67 // there is a search, query immediately to support search query params from | 70 if (queryState.queryingDisabled) |
| 68 // the URL. | |
| 69 var noResults = !this.queryResult || this.queryResult.results == null; | |
| 70 if (queryState.queryingDisabled || | |
| 71 (!this.queryState.searchTerm && noResults)) { | |
| 72 return; | 71 return; |
| 73 } | |
| 74 | 72 |
| 75 this.set('queryState.querying', true); | 73 this.set('queryState.querying', true); |
| 76 this.set('queryState.incremental', incremental); | 74 this.set('queryState.incremental', incremental); |
| 77 | 75 |
| 78 var lastVisitTime = 0; | 76 var lastVisitTime = 0; |
| 79 if (incremental) { | 77 if (incremental) { |
| 80 var lastVisit = this.queryResult.results.slice(-1)[0]; | 78 var lastVisit = this.queryResult.results.slice(-1)[0]; |
| 81 lastVisitTime = lastVisit ? Math.floor(lastVisit.time) : 0; | 79 lastVisitTime = lastVisit ? Math.floor(lastVisit.time) : 0; |
| 82 } | 80 } |
| 83 | 81 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 this.set('queryState.groupedOffset', changes.offset); | 118 this.set('queryState.groupedOffset', changes.offset); |
| 121 needsUpdate = true; | 119 needsUpdate = true; |
| 122 } | 120 } |
| 123 | 121 |
| 124 if (changes.search != null && | 122 if (changes.search != null && |
| 125 changes.search != this.queryState.searchTerm) { | 123 changes.search != this.queryState.searchTerm) { |
| 126 this.set('queryState.searchTerm', changes.search); | 124 this.set('queryState.searchTerm', changes.search); |
| 127 needsUpdate = true; | 125 needsUpdate = true; |
| 128 } | 126 } |
| 129 | 127 |
| 130 if (needsUpdate) | 128 if (needsUpdate) { |
| 131 this.queryHistory_(false); | 129 this.queryHistory_(false); |
| 130 if (this.router) |
| 131 this.router.serializeUrl(); |
| 132 } |
| 132 }, | 133 }, |
| 133 | 134 |
| 134 /** | 135 /** |
| 135 * @param {!Event} e | 136 * @param {!Event} e |
| 136 * @private | 137 * @private |
| 137 */ | 138 */ |
| 138 onQueryHistory_: function(e) { | 139 onQueryHistory_: function(e) { |
| 139 this.queryHistory_(/** @type {boolean} */ e.detail); | 140 this.queryHistory_(/** @type {boolean} */ e.detail); |
| 140 return false; | 141 return false; |
| 141 }, | 142 }, |
| 142 | 143 |
| 143 /** @private */ | 144 /** @private */ |
| 144 searchTermChanged_: function() { | 145 searchTermChanged_: function() { |
| 145 // TODO(tsergeant): Ignore incremental searches in this metric. | 146 // TODO(tsergeant): Ignore incremental searches in this metric. |
| 146 if (this.queryState.searchTerm) | 147 if (this.queryState.searchTerm) |
| 147 md_history.BrowserService.getInstance().recordAction('Search'); | 148 md_history.BrowserService.getInstance().recordAction('Search'); |
| 148 }, | 149 }, |
| 149 }); | 150 }); |
| OLD | NEW |