| Index: chrome/browser/resources/md_history/app.js
|
| diff --git a/chrome/browser/resources/md_history/app.js b/chrome/browser/resources/md_history/app.js
|
| index d58fcfdab7c06a8f7add679dc7801ff72f42bb3c..60e079a0ba338dac707f869b2464be2c7a97827b 100644
|
| --- a/chrome/browser/resources/md_history/app.js
|
| +++ b/chrome/browser/resources/md_history/app.js
|
| @@ -6,7 +6,9 @@
|
| * @typedef {{querying: boolean,
|
| * searchTerm: string,
|
| * results: ?Array<!HistoryEntry>,
|
| - * info: ?HistoryQuery}}
|
| + * info: ?HistoryQuery,
|
| + * range: HistoryRange,
|
| + * groupedOffset: number}}
|
| */
|
| var QueryState;
|
|
|
| @@ -15,11 +17,15 @@ Polymer({
|
|
|
| properties: {
|
| // The id of the currently selected page.
|
| - selectedPage: {
|
| + selectedPage_: {
|
| type: String,
|
| - value: 'history-list'
|
| },
|
|
|
| + // Whether domain-grouped history is enabled.
|
| + grouped_: Boolean,
|
| +
|
| + firstLoad_: { type: Boolean, value: true },
|
| +
|
| /** @type {!QueryState} */
|
| queryState_: {
|
| type: Object,
|
| @@ -30,6 +36,9 @@ Polymer({
|
| searchTerm: '',
|
| results: null,
|
| info: null,
|
| + range: HistoryRange.ALL_TIME,
|
| + // TODO(calamity): Make history toolbar buttons change the offset.
|
| + groupedOffset: 0,
|
| };
|
| }
|
| },
|
| @@ -37,6 +46,7 @@ Polymer({
|
|
|
| observers: [
|
| 'searchTermChanged_(queryState_.searchTerm)',
|
| + 'groupedRangeChanged_(queryState_.range)',
|
| ],
|
|
|
| // TODO(calamity): Replace these event listeners with data bound properties.
|
| @@ -49,7 +59,7 @@ Polymer({
|
| },
|
|
|
| ready: function() {
|
| - this.$.toolbar.isGroupedMode = loadTimeData.getBoolean('groupByDomain');
|
| + this.grouped_ = loadTimeData.getBoolean('groupByDomain');
|
| },
|
|
|
| /**
|
| @@ -91,15 +101,41 @@ Polymer({
|
| this.queryHistory(true);
|
| },
|
|
|
| + 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;
|
| + }
|
| + }
|
| + },
|
| +
|
| /**
|
| * @param {HistoryQuery} info An object containing information about the
|
| * query.
|
| * @param {!Array<HistoryEntry>} results A list of results.
|
| */
|
| historyResult: function(info, results) {
|
| - this.set('queryState_.querying', false);
|
| - this.set('queryState_.results', results);
|
| + this.firstLoad_ = false;
|
| this.set('queryState_.info', info);
|
| + this.set('queryState_.results', results);
|
| + this.set('queryState_.querying', false);
|
| +
|
| + this.initializeResults_(info, results);
|
| +
|
| + if (this.grouped_ && this.queryState_.range != HistoryRange.ALL_TIME) {
|
| + this.$$('history-grouped-list').historyData = results;
|
| + return;
|
| + }
|
|
|
| var list = /** @type {HistoryListElement} */(this.$['history-list']);
|
| list.addNewResults(results);
|
| @@ -115,21 +151,39 @@ Polymer({
|
| this.$.toolbar.setSearchTerm(e.detail.domain);
|
| },
|
|
|
| - searchTermChanged_: function() {
|
| - this.queryHistory(false);
|
| + searchTermChanged_: function(searchTerm) {
|
| + if (!this.firstLoad_)
|
| + this.queryHistory(false);
|
| + },
|
| +
|
| +
|
| + groupedRangeChanged_: function(range) {
|
| + if (!this.firstLoad_)
|
| + this.queryHistory(false);
|
| },
|
|
|
| + /**
|
| + * 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) {
|
| + this.set('queryState_.querying', true);
|
| +
|
| + var queryState = this.queryState_;
|
| +
|
| var lastVisitTime = 0;
|
| if (incremental) {
|
| - var lastVisit = this.queryState_.results.slice(-1)[0];
|
| + var lastVisit = queryState.results.slice(-1)[0];
|
| lastVisitTime = lastVisit ? lastVisit.time : 0;
|
| }
|
|
|
| - this.set('queryState_.querying', true);
|
| - chrome.send(
|
| - 'queryHistory',
|
| - [this.queryState_.searchTerm, 0, 0, lastVisitTime, RESULTS_PER_PAGE]);
|
| + var maxResults =
|
| + queryState.range == HistoryRange.ALL_TIME ? RESULTS_PER_PAGE : 0;
|
| + chrome.send('queryHistory', [
|
| + queryState.searchTerm, queryState.groupedOffset, Number(queryState.range),
|
| + lastVisitTime, maxResults
|
| + ]);
|
| },
|
|
|
| /**
|
| @@ -147,5 +201,12 @@ Polymer({
|
| var syncedDeviceManager =
|
| /** @type {HistorySyncedDeviceManagerElement} */(syncedDeviceElem);
|
| syncedDeviceManager.setSyncedHistory(sessionList);
|
| - }
|
| + },
|
| +
|
| + getSelectedPage: function(selectedPage, range) {
|
| + if (selectedPage == 'history-list' && range != HistoryRange.ALL_TIME)
|
| + return 'history-grouped-list';
|
| +
|
| + return selectedPage;
|
| + },
|
| });
|
|
|