Skip to content

Commit 198acd5

Browse files
committed
feat: add total time for daily tab
1 parent 15f6ad3 commit 198acd5

File tree

1 file changed

+45
-9
lines changed

1 file changed

+45
-9
lines changed

src/components/ByDays.vue

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
<div class="no-data" v-if="isLoading">
33
<img height="55" src="../assets/icons/preloader.gif" />
44
</div>
5+
56
<div v-else>
67
<no-data-by-days v-if="countOfDays == undefined || (countOfDays == 0 && !noData)" />
8+
79
<div v-else-if="noData">
810
<div class="no-data">
911
{{ t('noDataForPeriod.message') }}
@@ -17,10 +19,11 @@
1719
>
1820
<template #yearly="{ label, range, presetDateRange }">
1921
<span @click="presetDateRange(range)">{{ label }}</span>
20-
</template></VueDatePicker
21-
>
22+
</template>
23+
</VueDatePicker>
2224
</div>
2325
</div>
26+
2427
<div v-else>
2528
<div class="date-block">
2629
<VueDatePicker
@@ -33,29 +36,40 @@
3336
>
3437
<template #yearly="{ label, range, presetDateRange }">
3538
<span @click="presetDateRange(range)">{{ label }}</span>
36-
</template></VueDatePicker
37-
>
39+
</template>
40+
</VueDatePicker>
3841
<input type="button" :value="t('exportToCsv.message')" @click="exportToCsv()" />
3942
</div>
43+
4044
<div class="stats-block block">
4145
<div class="header">{{ t('averageTimeByDays.message') }}</div>
4246
<p>{{ convertSummaryTimeToString(tabsByDays!.averageTime) }}</p>
4347
</div>
48+
4449
<div class="ml-20 mr-20 by-days-chart">
4550
<ByDaysChart :data="tabsByDays!" />
4651
</div>
52+
4753
<div>
54+
<Expander day="Total" :time="tabsByDays?.summaryTime || 0">
55+
<TabItem
56+
v-for="(tab, i) of mergeAllDays(tabsByDays?.days)"
57+
:item="tab"
58+
:summaryTimeForWholeDay="tabsByDays?.summaryTime || 0"
59+
/>
60+
</Expander>
61+
4862
<Expander
4963
v-for="(tabDay, i) of tabsByDays?.days"
5064
:key="i"
5165
:day="tabDay.day"
5266
:time="tabDay.time"
5367
>
54-
<TabItem
55-
v-for="(tab, i) of tabDay.tabs"
56-
:key="i"
57-
:item="tab"
58-
:summaryTimeForWholeDay="tabDay.time"
68+
<TabItem
69+
v-for="(tab, i) of tabDay.tabs"
70+
:key="i"
71+
:item="tab"
72+
:summaryTimeForWholeDay="tabDay.time"
5973
/>
6074
</Expander>
6175
</div>
@@ -77,6 +91,7 @@ import NoDataByDays from './NoDataByDays.vue';
7791
import ByDaysChart from '../components/ByDaysChart.vue';
7892
import Expander from '../components/Expander.vue';
7993
import { TabListByDays } from '../dto/tabListSummary';
94+
import { CurrentTabItem } from '../dto/currentTabItem';
8095
import { useTabListByDays } from '../functions/useTabListByDays';
8196
import { convertSummaryTimeToString } from '../utils/converter';
8297
import { ranges, ThisWeekRange } from '../utils/date';
@@ -131,6 +146,27 @@ async function exportToCsv() {
131146
`websites_${dateFrom.toLocaleDateString()}-${dateTo.toLocaleDateString()}.csv`,
132147
);
133148
}
149+
150+
function mergeAllDays(days: TabListByDays['days'] | undefined): CurrentTabItem[] {
151+
if (!days) return [];
152+
153+
const urlMap = new Map<string, CurrentTabItem>();
154+
155+
for (const day of days) {
156+
for (const tab of day.tabs) {
157+
if (!urlMap.has(tab.url)) {
158+
urlMap.set(tab.url, { ...tab });
159+
continue;
160+
}
161+
162+
const existingTab = urlMap.get(tab.url)!;
163+
existingTab.summaryTime += tab.summaryTime;
164+
existingTab.sessions += tab.sessions;
165+
}
166+
}
167+
168+
return Array.from(urlMap.values()).sort((a, b) => b.summaryTime - a.summaryTime);
169+
}
134170
</script>
135171

136172
<style scoped>

0 commit comments

Comments
 (0)