Skip to content

Commit a393242

Browse files
committed
Add expander for all sites (if more 30)
1 parent 8c84194 commit a393242

File tree

3 files changed

+71
-5
lines changed

3 files changed

+71
-5
lines changed

scripts/ui.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,24 @@ class UI {
184184
this.getTableOfSite().appendChild(div);
185185
}
186186

187+
addExpander() {
188+
if (document.getElementById('expander') === null) {
189+
var div = document.createElement('div');
190+
div.id = 'expander';
191+
div.innerText = 'Show all';
192+
div.classList.add('expander');
193+
div.addEventListener('click', function () {
194+
ui.expand();
195+
});
196+
this.getTableOfSite().appendChild(div);
197+
}
198+
}
199+
200+
expand(){
201+
getTabsForExpander();
202+
this.getTableOfSite().removeChild(document.getElementById('expander'));
203+
}
204+
187205
addBlockForCalendar(range) {
188206
var div = document.getElementById('byDays');
189207

scripts/webact.js

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ function getDataFromStorageByDays() {
5656
storage.loadTabs(STORAGE_TABS, getTabsByDays);
5757
}
5858

59-
function getLimitsListFromStorageCallback(items){
59+
function getLimitsListFromStorageCallback(items) {
6060
if (items !== undefined)
6161
restrictionList = items;
6262
else restrictionList = [];
6363
}
6464

65-
function fillEmptyBlock(){
65+
function fillEmptyBlock() {
6666
ui.fillEmptyBlock('chart');
6767
}
6868

@@ -121,14 +121,18 @@ function getTabsFromStorage(tabs) {
121121
var counter;
122122
if (currentTypeOfList === TypeListEnum.ToDay) {
123123
summaryTime = targetTabs[i].days.find(x => x.date == today).summary;
124-
counter = targetTabs[i].days.find(x => x.date == today).counter;
124+
if (targetTabs[i].days.find(x => x.date == today))
125+
counter = targetTabs[i].days.find(x => x.date == today).counter;
125126
}
126127
if (currentTypeOfList === TypeListEnum.All) {
127128
summaryTime = targetTabs[i].summaryTime;
128129
counter = targetTabs[i].counter;
129130
}
130131

131-
ui.addLineToTableOfSite(targetTabs[i], currentTab, summaryTime, currentTypeOfList, counter);
132+
if (currentTypeOfList === TypeListEnum.ToDay || (currentTypeOfList === TypeListEnum.All && i <= 30))
133+
ui.addLineToTableOfSite(targetTabs[i], currentTab, summaryTime, currentTypeOfList, counter);
134+
else
135+
ui.addExpander();
132136

133137
if (i <= 8)
134138
addTabForChart(tabsForChart, targetTabs[i].url, summaryTime, counter);
@@ -141,6 +145,41 @@ function getTabsFromStorage(tabs) {
141145
ui.setActiveTooltipe(currentTab);
142146
}
143147

148+
function getTabsForExpander() {
149+
storage.loadTabs(STORAGE_TABS, getTabsFromStorageForExpander);
150+
}
151+
152+
function getTabsFromStorageForExpander(tabs) {
153+
tabsFromStorage = tabs;
154+
targetTabs = [];
155+
156+
targetTabs = tabs.sort(function (a, b) {
157+
return b.summaryTime - a.summaryTime;
158+
});
159+
160+
var currentTab = getCurrentTab();
161+
162+
for (var i = 31; i < targetTabs.length; i++) {
163+
var summaryTime;
164+
var counter;
165+
if (currentTypeOfList === TypeListEnum.ToDay) {
166+
summaryTime = targetTabs[i].days.find(x => x.date == today).summary;
167+
if (targetTabs[i].days.find(x => x.date == today))
168+
counter = targetTabs[i].days.find(x => x.date == today).counter;
169+
}
170+
if (currentTypeOfList === TypeListEnum.All) {
171+
summaryTime = targetTabs[i].summaryTime;
172+
counter = targetTabs[i].counter;
173+
}
174+
175+
ui.addLineToTableOfSite(targetTabs[i], currentTab, summaryTime, currentTypeOfList, counter);
176+
}
177+
178+
var table = ui.getTableOfSite();
179+
table.removeChild(table.getElementsByTagName('hr')[0]);
180+
ui.addHrAfterTableOfSite();
181+
}
182+
144183
function getTotalTime(tabs) {
145184
var total;
146185
if (currentTypeOfList === TypeListEnum.ToDay) {
@@ -221,7 +260,7 @@ function getFirstDay() {
221260

222261
function getTabsByDays(tabs) {
223262
var range = ui.getDateRange();
224-
if (tabs === undefined){
263+
if (tabs === undefined) {
225264
ui.fillEmptyBlockForDays();
226265
return;
227266
}

style/webact.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,4 +298,13 @@ p.table-header{
298298
width: 17px;
299299
height: 17px;
300300
margin: 2px 7px 5px 3px;
301+
}
302+
303+
.expander{
304+
background-color: rgb(231, 227, 227);
305+
height: 20px;
306+
text-align: center;
307+
font-weight: 600;
308+
border-radius: 5px;
309+
cursor: pointer;
301310
}

0 commit comments

Comments
 (0)