Chromium Code Reviews| Index: chrome/browser/resources/md_history/list_container.js |
| diff --git a/chrome/browser/resources/md_history/list_container.js b/chrome/browser/resources/md_history/list_container.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2e0018b52dcb51f68a19241d636973ddcb9421dd |
| --- /dev/null |
| +++ b/chrome/browser/resources/md_history/list_container.js |
| @@ -0,0 +1,137 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +/** |
| + * @typedef {{results: ?Array<!HistoryEntry>, |
| + * info: ?HistoryQuery}} |
| + */ |
| +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.
|
| + |
| +Polymer({ |
| + is: 'history-list-container', |
| + |
| + properties: { |
| + // The path of the currently selected page. |
| + selectedPage_: String, |
| + |
| + // Whether domain-grouped history is enabled. |
| + grouped: Boolean, |
| + |
| + /** @type {!QueryState} */ |
| + queryState: { |
| + type: Object, |
| + }, |
| + |
| + /** @type {!QueryResult} */ |
| + queryResult_: { |
| + type: Object, |
| + readOnly: true, |
| + value: function() { |
| + return { |
| + info: null, |
| + results: null, |
| + }; |
| + } |
| + }, |
| + }, |
| + |
| + observers: [ |
| + 'searchTermChanged_(queryState.searchTerm)', |
| + 'groupedRangeChanged_(queryState.range)', |
| + ], |
| + |
| + listeners: { |
| + 'load-more-history': 'loadMoreHistory_', |
| + }, |
| + |
| + initializeResults_: function(info, results) { |
|
tsergeant
2016/06/24 06:19:17
Nit: /** @private */
calamity
2016/06/27 03:35:46
Done.
|
| + if (results.length == 0) |
| + return; |
| + |
| + var currentDate = results[0].dateRelativeDay; |
| + |
| + for (var i = 0; i < results.length; i++) { |
| + // Sets the default values for these fields to prevent undefined types. |
| + results[i].selected = false; |
| + results[i].readableTimestamp = |
| + info.term == '' ? results[i].dateTimeOfDay : results[i].dateShort; |
| + |
| + if (results[i].dateRelativeDay != currentDate) { |
| + currentDate = results[i].dateRelativeDay; |
| + } |
| + } |
| + }, |
| + |
| + searchTermChanged_: function(searchTerm) { this.queryHistory(false); }, |
| + |
| + groupedRangeChanged_: function(range) { |
| + this.selectedPage_ = this.queryState.range == HistoryRange.ALL_TIME ? |
| + 'infinite-list' : 'grouped-list'; |
| + |
| + this.queryHistory(false); |
| + }, |
| + |
| + loadMoreHistory_: function() { this.queryHistory(true); }, |
| + |
| + /** |
| + * @param {HistoryQuery} info An object containing information about the |
| + * query. |
| + * @param {!Array<HistoryEntry>} results A list of results. |
| + */ |
| + 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.
|
| + this.initializeResults_(info, results); |
| + |
| + this.set('queryResult_.info', info); |
| + this.set('queryResult_.results', results); |
| + |
| + if (this.selectedPage_ == 'grouped-list') { |
| + this.$$('#grouped-list').historyData = results; |
| + return; |
| + } |
| + |
| + var list = /** @type {HistoryListElement} */(this.$['infinite-list']); |
| + list.addNewResults(results); |
| + if (info.finished) |
| + list.disableResultLoading(); |
| + }, |
| + |
| + /** |
| + * Queries the history backend for results based on queryState. |
| + * @param {boolean} incremental Whether the new query should continue where |
| + * the previous query stopped. |
| + */ |
| + queryHistory: function(incremental) { |
| + var queryState = this.queryState; |
| + // Disable querying until the first set of results have been returned. |
| + if (this.queryResult_.results == null || queryState.queryingDisabled) |
| + return; |
| + |
| + this.set('queryState.querying', true); |
| + this.set('queryState.incremental', incremental); |
| + |
| + |
| + var lastVisitTime = 0; |
| + if (incremental) { |
| + var lastVisit = this.queryResult_.results.slice(-1)[0]; |
| + lastVisitTime = lastVisit ? lastVisit.time : 0; |
| + } |
| + |
| + var maxResults = |
| + queryState.range == HistoryRange.ALL_TIME ? RESULTS_PER_PAGE : 0; |
| + chrome.send('queryHistory', [ |
| + queryState.searchTerm, queryState.groupedOffset, queryState.range, |
| + lastVisitTime, maxResults |
| + ]); |
| + }, |
| + |
| + unselectAllItems: function(count) { |
| + /** @type {HistoryListElement} */ (this.$['infinite-list']) |
| + .unselectAllItems(count); |
| + }, |
| + |
| + deleteSelected: function() { |
| + /** @type {HistoryListElement} */ (this.$['infinite-list']) |
| + .deleteSelected(); |
| + } |
| +}); |