| 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..11f2674d3afce73c5cfd5d8acb666a8b07b59987
|
| --- /dev/null
|
| +++ b/chrome/browser/resources/md_history/list_container.js
|
| @@ -0,0 +1,152 @@
|
| +// 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;
|
| +
|
| +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_',
|
| + },
|
| +
|
| + /**
|
| + * @param {HistoryQuery} info An object containing information about the
|
| + * query.
|
| + * @param {!Array<HistoryEntry>} results A list of results.
|
| + */
|
| + historyResult: function(info, results) {
|
| + 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();
|
| + },
|
| +
|
| + /**
|
| + * @param {string} searchTerm
|
| + * @private
|
| + */
|
| + searchTermChanged_: function(searchTerm) { this.queryHistory(false); },
|
| +
|
| + /**
|
| + * @param {HistoryRange} range
|
| + * @private
|
| + */
|
| + groupedRangeChanged_: function(range) {
|
| + this.selectedPage_ = this.queryState.range == HistoryRange.ALL_TIME ?
|
| + 'infinite-list' : 'grouped-list';
|
| +
|
| + this.queryHistory(false);
|
| + },
|
| +
|
| + /** @private */
|
| + loadMoreHistory_: function() { this.queryHistory(true); },
|
| +
|
| +
|
| + /**
|
| + * @param {HistoryQuery} info
|
| + * @param {!Array<HistoryEntry>} results
|
| + * @private
|
| + */
|
| + initializeResults_: function(info, results) {
|
| + 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;
|
| + }
|
| + }
|
| + },
|
| +});
|
|
|