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

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

Issue 1641543002: MD History: Refactored design for displaying history information (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@second_patch
Patch Set: concat -> push 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_card_manager.js b/chrome/browser/resources/md_history/history_list.js
similarity index 55%
rename from chrome/browser/resources/md_history/history_card_manager.js
rename to chrome/browser/resources/md_history/history_list.js
index 6844515fc8ce23f55f008b3a95b2e296ce5c8484..8b56ef7c26dd2de8e6bfab658a4c4a68c8dda30f 100644
--- a/chrome/browser/resources/md_history/history_card_manager.js
+++ b/chrome/browser/resources/md_history/history_list.js
@@ -3,17 +3,16 @@
// found in the LICENSE file.
Polymer({
- is: 'history-card-manager',
+ is: 'history-list',
properties: {
- // An array of objects sorted in reverse chronological order.
- // Each object has a date and the history items belonging to that date.
- historyDataByDay_: {
+ // An array of history entries in reverse chronological order.
+ historyData: {
type: Array,
value: function() { return []; }
},
- // The time of access of the last element of historyDataByDay_.
+ // The time in seconds of the last history item in historyData.
lastVisitedTime: {
type: Number,
value: 0
@@ -70,80 +69,61 @@ Polymer({
},
/**
- * Split the newly updated history results into history items sorted via day
- * accessed.
+ * Adds the newly updated history results into historyData. Adds new fields
+ * for each result. Preserves the scroll position of the window when new data
tsergeant 2016/02/08 00:10:54 You can get rid of the comment about scroll positi
yingran 2016/02/08 03:20:36 Done.
+ * is loaded.
* @param {!Array<!HistoryEntry>} results The new history results.
*/
addNewResults: function(results) {
if (results.length == 0)
return;
- var dateSortedData = [];
- var historyItems = [];
var currentDate = results[0].dateRelativeDay;
for (var i = 0; i < results.length; i++) {
- if (!currentDate)
- continue;
-
+ // Sets the default values for these fields to prevent undefined types.
results[i].selected = false;
+ results[i].isLastItem = false;
+ results[i].isFirstItem = false;
+
if (results[i].dateRelativeDay != currentDate) {
- this.appendHistoryData_(currentDate, historyItems);
+ results[i - 1].isLastItem = true;
+ results[i].isFirstItem = true;
currentDate = results[i].dateRelativeDay;
- historyItems = [];
}
- historyItems.push(results[i]);
+ results[i].needsTimeGap = this.needsTimeGap_(results, i);
}
- if (currentDate)
- this.appendHistoryData_(currentDate, historyItems);
+ // If it's the first time we get data, the first item will always be the
+ // first card.
+ if (this.historyData.length == 0) {
tsergeant 2016/02/08 00:10:54 Nit: No {}
yingran 2016/02/08 03:20:36 Done.
+ results[0].isFirstItem = true;
+ }
- this.lastVisitedTime = historyItems[historyItems.length - 1].time;
+ for (var i = 0; i < results.length; i++) {
tsergeant 2016/02/08 00:10:54 We got this working with apply and no for loop on
yingran 2016/02/08 03:20:36 Yes- this'll be uploaded next patch
+ this.push('historyData', results[i]);
+ }
+
+ this.lastVisitedTime = this.historyData[this.historyData.length - 1].time;
},
/**
- * Cycle through each entry in historyDataByDay_ and set all items to be
+ * Cycle through each entry in historyData and set all items to be
* unselected.
+ * @param {number} overallItemCount The number of checkboxes selected.
*/
unselectAllItems: function(overallItemCount) {
- var historyCardData = this.historyDataByDay_;
-
- for (var i = 0; i < historyCardData.length; i++) {
- var items = historyCardData[i].historyItems;
- for (var j = 0; j < items.length; j++) {
- if (items[j].selected) {
- this.set('historyDataByDay_.' + i + '.historyItems.' + j +
- '.selected', false);
- overallItemCount--;
- if (overallItemCount == 0)
- break;
- }
+ for (var i = 0; i < this.historyData.length; i++) {
+ if (this.historyData[i].selected) {
+ this.set('historyData.' + i + '.selected', false);
+ overallItemCount--;
+ if (overallItemCount == 0)
+ break;
}
}
},
/**
- * 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.
- * @param {!Array<!HistoryEntry>} historyItems The list of history items for
- * the current date.
- * @private
- */
- appendHistoryData_: function(date, historyItems) {
- var lastDay = this.historyDataByDay_.length - 1;
- if (lastDay > 0 && date == this.historyDataByDay_[lastDay].date) {
- this.set('historyDataByDay_.' + lastDay + '.historyItems',
- this.historyDataByDay_[lastDay].historyItems.concat(historyItems));
- } else {
- this.push('historyDataByDay_', {
- date: date,
- historyItems: historyItems
- });
- }
- },
-
- /**
* Called when the card manager is scrolled.
* @private
*/
@@ -161,5 +141,19 @@ Polymer({
chrome.send('queryHistory',
['', 0, 0, this.lastVisitedTime, RESULTS_PER_PAGE]);
}
+ },
+
+ /**
+ * Check whether the time difference between the given history item and the
+ * next one is large enough for a spacer to be required.
+ * @param {number} index The index number of the first item being compared.
+ * @return {boolean} Whether or not time gap separator is required.
+ * @private
+ */
+ needsTimeGap_: function(results, index) {
+ var items = results;
+ return index + 1 < items.length &&
+ items[index].time - items[index + 1].time > BROWSING_GAP_TIME &&
+ items[index].dateRelativeDay == items[index + 1].dateRelativeDay;
}
});

Powered by Google App Engine
This is Rietveld 408576698