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

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

Issue 1643693003: MD History: Implement search functionality. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@patch_to_be_uploaded
Patch Set: Rebase and address reviewer comments. Created 4 years, 10 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/history_list.js
diff --git a/chrome/browser/resources/md_history/history_list.js b/chrome/browser/resources/md_history/history_list.js
index fe3926f570966f8d3f2f5125da96bfeac3d83016..9803295b4dada421ad00687ef4743f9fb99b4617 100644
--- a/chrome/browser/resources/md_history/history_list.js
+++ b/chrome/browser/resources/md_history/history_list.js
@@ -24,9 +24,20 @@ Polymer({
reflectToAttribute: true
},
+ searchTerm: {
+ type: String,
+ value: ''
+ },
+
menuIdentifier: {
type: Number,
value: 0
+ },
+
+ // Page waits until results have finished loading before displaying message.
+ loading_: {
+ type: Boolean,
+ value: true
}
},
@@ -46,6 +57,16 @@ Polymer({
},
/**
+ * Clear the page completely so the page can display new results (search).
+ */
+ resetHistoryResults: function() {
+ // TODO(hsampson): make it so the old results aren't replaced immediately,
+ // only replaced when new results come in.
+ this.loading_ = true;
+ this.splice('historyData', 0, this.historyData.length);
+ },
+
+ /**
* Opens the overflow menu unless the menu is already open and the same button
* is pressed.
* @param {Event} e The event with details of the menu item that was clicked.
@@ -73,9 +94,13 @@ Polymer({
* for each result.
* @param {!Array<!HistoryEntry>} historyResults The new history results.
*/
- addNewResults: function(historyResults) {
- if (historyResults.length == 0)
+ addNewResults: function(historyResults, search) {
+ this.searchTerm = search;
+
+ if (historyResults.length == 0) {
+ this.loading_ = false;
return;
+ }
// Creates a copy of historyResults to prevent accidentally modifying this
// field.
@@ -97,15 +122,20 @@ Polymer({
results[i].selected = false;
results[i].isLastItem = false;
results[i].isFirstItem = false;
+ results[i].visibleTimestamp =
+ search == '' ? results[i].dateTimeOfDay : results[i].dateShort;
if (results[i].dateRelativeDay != currentDate) {
results[i - 1].isLastItem = true;
results[i].isFirstItem = true;
currentDate = results[i].dateRelativeDay;
}
- results[i].needsTimeGap = this.needsTimeGap_(results, i);
+ if (i != 0) {
+ results[i - 1].needsTimeGap = this.needsTimeGap_(results, i - 1);
+ }
}
results[i - 1].isLastItem = true;
+ results[i - 1].needsTimeGap = false;
// If it's the first time we get data, the first item will always be the
// first card.
@@ -117,6 +147,7 @@ Polymer({
this.push.apply(this, results);
this.lastVisitedTime = this.historyData[this.historyData.length - 1].time;
+ this.loading_ = false;
},
/**
@@ -198,6 +229,7 @@ Polymer({
return toBeRemoved;
}
}
+ return toBeRemoved;
},
/**
@@ -213,10 +245,10 @@ Polymer({
var scrollOffset = 10;
var scrollElem = this.$['infinite-list'];
- if (scrollElem.scrollHeight <=
+ if (!this.loading_ && scrollElem.scrollHeight <=
scrollElem.scrollTop + scrollElem.clientHeight + scrollOffset) {
chrome.send('queryHistory',
- ['', 0, 0, this.lastVisitedTime, RESULTS_PER_PAGE]);
+ [this.searchTerm, 0, 0, this.lastVisitedTime, RESULTS_PER_PAGE]);
}
},
@@ -232,10 +264,33 @@ Polymer({
var currentItem = results[index];
var nextItem = results[index + 1];
- if (index + 1 >= results.length)
- return false;
+ if (this.searchTerm)
+ return currentItem.visibleTimestamp != nextItem.visibleTimestamp;
+ else
+ return currentItem.time - nextItem.time > BROWSING_GAP_TIME &&
+ currentItem.dateRelativeDay == nextItem.dateRelativeDay;
+ },
+
+ /**
+ * True if there are no results available and the page has finished loading.
+ * @param {number} numberOfResults The length of historyDataByDay_.
+ * @param {boolean} loading Whether the page has finished loading results.
+ * @return {boolean} Whether there are results to show.
+ * @private
+ */
+ noResultsAvailable_: function(numberOfResults, loading) {
+ return numberOfResults == 0 && !loading;
+ },
- return currentItem.time - nextItem.time > BROWSING_GAP_TIME &&
- currentItem.dateRelativeDay == nextItem.dateRelativeDay;
+ /**
+ * Return the message to be displayed if there are no results based on whether
+ * the empty results were for a search or normal history results.
+ * @param {string} search The search term for these results.
+ * @return {string} The displayed message.
+ * @private
+ */
+ noResultsMessage_: function(search) {
+ var messageId = search != '' ? 'noSearchResults' : 'noResults';
+ return loadTimeData.getString(messageId);
}
});
« no previous file with comments | « chrome/browser/resources/md_history/history_list.html ('k') | chrome/browser/resources/md_history/history_toolbar.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698