Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Unified Diff: chrome/browser/resources/md_history/list_container.js

Issue 2084843002: [MD History] Add history-list-container between app and history lists. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@tim_toolbar
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..7d1ab5fb635631cc7da236114b847a4691f44c77
--- /dev/null
+++ b/chrome/browser/resources/md_history/list_container.js
@@ -0,0 +1,146 @@
+// 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;
+
+/**
+ * @typedef {{groupedOffset: number,
+ * incremental: boolean,
+ * querying: boolean,
+ * range: HistoryRange,
+ * searchTerm: string}}
+ */
+var QueryState;
tsergeant 2016/06/23 06:35:25 I find it strange that the typedef for this type i
calamity 2016/06/24 05:39:47 I think.... I want to move this to constants.js or
+
+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) {
+ 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 ?
+ 'history-list' : 'history-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) {
+ this.initializeResults_(info, results);
+
+ this.set('queryResult_.info', info);
+ this.set('queryResult_.results', results);
+ this.set('queryState.querying', false);
+
+ if (this.selectedPage_ == 'history-grouped-list') {
+ this.$$('history-grouped-list').historyData = results;
+ return;
+ }
+
+ var list = /** @type {HistoryListElement} */(this.$['history-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 (queryState.queryingDisabled || this.queryResult_.results == null)
tsergeant 2016/06/23 06:35:25 Very minor nit: Maybe reorder the two || clauses?
calamity 2016/06/24 05:39:47 Done.
+ 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.$['history-list'])
+ .unselectAllItems(count);
+ },
+
+ deleteSelected: function() {
+ /** @type {HistoryListElement} */ (this.$['history-list']).deleteSelected();
+ }
+});

Powered by Google App Engine
This is Rietveld 408576698