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

Side by Side Diff: chrome/browser/resources/md_history/grouped_list.js

Issue 2684493002: MD History: Delete Grouped History (Closed)
Patch Set: Rebase Created 3 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 /**
6 * @typedef {{domain: string,
7 * visits: !Array<HistoryEntry>,
8 * rendered: boolean,
9 * expanded: boolean}}
10 */
11 var HistoryDomain;
12
13 /**
14 * @typedef {{title: string,
15 * domains: !Array<HistoryDomain>}}
16 */
17 var HistoryGroup;
18
19 Polymer({
20 is: 'history-grouped-list',
21
22 behaviors: [HistoryListBehavior],
23
24 properties: {
25 searchedTerm: {
26 type: String,
27 value: '',
28 },
29
30 /**
31 * @type {Array<HistoryGroup>}
32 */
33 groupedHistoryData_: Array,
34
35 // An array of history entries in reverse chronological order.
36 historyData: Array,
37
38 queryInterval: String,
39
40 range: Number,
41 },
42
43 observers: ['updateGroupedHistoryData_(historyData)'],
44
45 /**
46 * @param {!Array<!HistoryEntry>} results
47 * @param {boolean} incremental
48 * @param {boolean} finished
49 */
50 addNewResults: function(results, incremental, finished) {
51 this.historyData = results;
52 },
53
54 /**
55 * Make a list of domains from visits.
56 * @param {!Array<!HistoryEntry>} visits
57 * @return {!Array<!HistoryDomain>}
58 */
59 createHistoryDomains_: function(visits) {
60 var domainIndexes = {};
61 var domains = [];
62
63 // Group the visits into a dictionary and generate a list of domains.
64 for (var i = 0, visit; visit = visits[i]; i++) {
65 var domain = visit.domain;
66 if (domainIndexes[domain] == undefined) {
67 domainIndexes[domain] = domains.length;
68 domains.push({
69 domain: domain,
70 visits: [],
71 expanded: false,
72 rendered: false,
73 });
74 }
75 domains[domainIndexes[domain]].visits.push(visit);
76 }
77 var sortByVisits = function(a, b) {
78 return b.visits.length - a.visits.length;
79 };
80 domains.sort(sortByVisits);
81
82 return domains;
83 },
84
85 /** @private */
86 updateGroupedHistoryData_: function() {
87 if (this.historyData.length == 0) {
88 this.groupedHistoryData_ = [];
89 return;
90 }
91
92 if (this.range == HistoryRange.WEEK) {
93 // Group each day into a list of results.
94 var days = [];
95 var currentDayVisits = [this.historyData[0]];
96
97 var pushCurrentDay = function() {
98 days.push({
99 title: this.searchedTerm ? currentDayVisits[0].dateShort :
100 currentDayVisits[0].dateRelativeDay,
101 domains: this.createHistoryDomains_(currentDayVisits),
102 });
103 }.bind(this);
104
105 var visitsSameDay = function(a, b) {
106 if (this.searchedTerm)
107 return a.dateShort == b.dateShort;
108
109 return a.dateRelativeDay == b.dateRelativeDay;
110 }.bind(this);
111
112 for (var i = 1; i < this.historyData.length; i++) {
113 var visit = this.historyData[i];
114 if (!visitsSameDay(visit, currentDayVisits[0])) {
115 pushCurrentDay();
116 currentDayVisits = [];
117 }
118 currentDayVisits.push(visit);
119 }
120 pushCurrentDay();
121
122 this.groupedHistoryData_ = days;
123 } else if (this.range == HistoryRange.MONTH) {
124 // Group each all visits into a single list.
125 this.groupedHistoryData_ = [{
126 title: this.queryInterval,
127 domains: this.createHistoryDomains_(this.historyData)
128 }];
129 }
130 },
131
132 /**
133 * @param {{model:Object, currentTarget:IronCollapseElement}} e
134 */
135 toggleDomainExpanded_: function(e) {
136 var collapse = e.currentTarget.parentNode.querySelector('iron-collapse');
137 e.model.set('domain.rendered', true);
138
139 // Give the history-items time to render.
140 setTimeout(function() {
141 collapse.toggle()
142 }, 0);
143 },
144
145 /**
146 * Check whether the time difference between the given history item and the
147 * next one is large enough for a spacer to be required.
148 * @param {number} groupIndex
149 * @param {number} domainIndex
150 * @param {number} itemIndex
151 * @return {boolean} Whether or not time gap separator is required.
152 * @private
153 */
154 needsTimeGap_: function(groupIndex, domainIndex, itemIndex) {
155 var visits =
156 this.groupedHistoryData_[groupIndex].domains[domainIndex].visits;
157
158 return md_history.HistoryItem.needsTimeGap(
159 visits, itemIndex, this.searchedTerm);
160 },
161
162 /**
163 * @param {number} groupIndex
164 * @param {number} domainIndex
165 * @param {number} itemIndex
166 * @return {string}
167 * @private
168 */
169 pathForItem_: function(groupIndex, domainIndex, itemIndex) {
170 return [
171 'groupedHistoryData_', groupIndex, 'domains', domainIndex, 'visits',
172 itemIndex
173 ].join('.');
174 },
175
176 /**
177 * @param {HistoryDomain} domain
178 * @return {string}
179 * @private
180 */
181 getWebsiteIconStyle_: function(domain) {
182 return 'background-image: ' + cr.icon.getFavicon(domain.visits[0].url);
183 },
184
185 /**
186 * @param {boolean} expanded
187 * @return {string}
188 * @private
189 */
190 getDropdownIcon_: function(expanded) {
191 return expanded ? 'cr:expand-less' : 'cr:expand-more';
192 },
193 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/md_history/grouped_list.html ('k') | chrome/browser/resources/md_history/history.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698