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

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

Issue 1643693003: MD History: Implement search functionality. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@patch_to_be_uploaded
Patch Set: Fix time-gap-separator insertion. 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_card_manager.js
diff --git a/chrome/browser/resources/md_history/history_card_manager.js b/chrome/browser/resources/md_history/history_card_manager.js
index 99225473f348c2a32338717022a36c4ca5ec6f37..26efda51b8fc7a1267360b1d63c58ce612f66a62 100644
--- a/chrome/browser/resources/md_history/history_card_manager.js
+++ b/chrome/browser/resources/md_history/history_card_manager.js
@@ -28,6 +28,17 @@ Polymer({
menuIdentifier: {
type: Number,
value: 0
+ },
+
+ searchTerm: {
+ type: String,
+ value: ''
+ },
+
+ // Page waits until results have finished loading before displaying message.
+ loading: {
+ type: Boolean,
+ value: false
tsergeant 2016/02/12 00:03:52 Can you change to `value: true` instead of your ch
hsampson 2016/02/12 06:45:43 Done.
}
},
@@ -47,6 +58,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('historyDataByDay_', 0, this.historyDataByDay_.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,20 +94,27 @@ Polymer({
* Split the newly updated history results into history items sorted via day
* accessed.
* @param {!Array<!HistoryEntry>} results The new history results.
+ * @param {string} search The search term used for chrome.send.
*/
- addNewResults: function(results) {
- if (results.length == 0)
+ addNewResults: function(results, search) {
+ this.searchTerm = search;
+
+ if (results.length == 0) {
+ this.loading = false;
return;
+ }
- var dateSortedData = [];
var historyItems = [];
var currentDate = results[0].dateRelativeDay;
for (var i = 0; i < results.length; i++) {
- if (!currentDate)
+ if (currentDate == undefined)
tsergeant 2016/02/12 00:03:53 I'm not sure what the intention is here? Nothing i
hsampson 2016/02/12 06:45:43 I think this may just be leftover from a different
continue;
+ results[i].visibleTimestamp =
+ search == '' ? results[i].dateTimeOfDay : results[i].dateShort;
results[i].selected = false;
+
if (results[i].dateRelativeDay != currentDate) {
this.appendHistoryData_(currentDate, historyItems);
currentDate = results[i].dateRelativeDay;
@@ -95,16 +123,17 @@ Polymer({
historyItems.push(results[i]);
}
- if (currentDate)
+ if (currentDate != undefined)
this.appendHistoryData_(currentDate, historyItems);
- this.lastVisitedTime = historyItems[historyItems.length - 1].time;
+ // this.lastVisitedTime = historyItems[historyItems.length - 1].time;
tsergeant 2016/02/12 00:03:52 Is this meant to be commented?
hsampson 2016/02/12 06:45:43 Done.
+ this.loading = false;
},
/**
* Cycle through each entry in historyDataByDay_ and set all items to be
* unselected.
- * @param {number} overallItemCount The number of items selected.
+ * @param {number} overallItemCount The number of selected items.
*/
unselectAllItems: function(overallItemCount) {
var historyCardData = this.historyDataByDay_;
@@ -170,20 +199,21 @@ Polymer({
/**
* Adds the given items into historyDataByDay_. Adds items to the last
- * existing day if the date matches, creates a new element otherwise.
- * @param {string} date The date of the history items.
+ * existing day if the currentDate matches, creates a new element otherwise.
+ * @param {string} currentDate The currentDate for this list of history items.
* @param {!Array<!HistoryEntry>} historyItems The list of history items for
- * the current date.
+ * the current card.
* @private
*/
- appendHistoryData_: function(date, historyItems) {
+ appendHistoryData_: function(currentDate, historyItems) {
var lastDay = this.historyDataByDay_.length - 1;
- if (lastDay > 0 && date == this.historyDataByDay_[lastDay].date) {
+ if (lastDay >= 0 &&
+ currentDate == this.historyDataByDay_[lastDay].date) {
this.set('historyDataByDay_.' + lastDay + '.historyItems',
this.historyDataByDay_[lastDay].historyItems.concat(historyItems));
} else {
this.push('historyDataByDay_', {
- date: date,
+ date: currentDate,
historyItems: historyItems
});
}
@@ -229,11 +259,33 @@ Polymer({
// of the window.
var scrollOffset = 10;
var scrollElem = this.$['infinite-list'];
-
- if (scrollElem.scrollHeight <=
- scrollElem.scrollTop + scrollElem.clientHeight + scrollOffset) {
+ 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]);
}
+ },
+
+ /**
+ * 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 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);
}
});

Powered by Google App Engine
This is Rietveld 408576698