forked from Stigmatoz/web-activity-time-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathByDays.vue
More file actions
167 lines (154 loc) · 4.65 KB
/
ByDays.vue
File metadata and controls
167 lines (154 loc) · 4.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<template>
<div class="no-data" v-if="isLoading">
<img height="55" src="../assets/icons/preloader.gif" />
</div>
<div v-else>
<no-data-by-days v-if="countOfDays == undefined || (countOfDays == 0 && !noData)" />
<div v-else-if="noData">
<div class="no-data">
{{ t('noDataForPeriod.message') }}
<VueDatePicker
range
:enable-time-picker="false"
class="date-picker"
v-model="selectedDate"
:preset-ranges="presetRanges"
@update:model-value="handleDate"
>
<template #yearly="{ label, range, presetDateRange }">
<span @click="presetDateRange(range)">{{ label }}</span>
</template></VueDatePicker
>
</div>
</div>
<div v-else>
<div class="date-block">
<VueDatePicker
range
:enable-time-picker="false"
class="date-picker"
v-model="selectedDate"
:preset-ranges="presetRanges"
@update:model-value="handleDate"
>
<template #yearly="{ label, range, presetDateRange }">
<span @click="presetDateRange(range)">{{ label }}</span>
</template></VueDatePicker
>
<input type="button" :value="t('exportToCsv.message')" @click="exportToCsv()" />
</div>
<div class="stats-block block">
<div class="header">{{ t('averageTimeByDays.message') }}</div>
<p>{{ convertSummaryTimeToString(tabsByDays!.averageTime) }}</p>
</div>
<div class="ml-20 mr-20 by-days-chart">
<ByDaysChart :data="tabsByDays!" />
</div>
<div>
<Expander
v-for="(tabDay, i) of tabsByDays?.days"
:key="i"
:day="tabDay.day"
:time="tabDay.time"
>
<TabItem
v-for="(tab, i) of tabDay.tabs"
:key="i"
:item="tab"
:summaryTimeForWholeDay="tabDay.time"
/>
</Expander>
</div>
</div>
</div>
</template>
<script lang="ts">
export default {
name: 'TabList',
};
</script>
<script lang="ts" setup>
import { computed, onMounted, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import TabItem from '../components/TabItem.vue';
import NoDataByDays from './NoDataByDays.vue';
import ByDaysChart from '../components/ByDaysChart.vue';
import Expander from '../components/Expander.vue';
import { TabListByDays } from '../dto/tabListSummary';
import { useTabListByDays } from '../functions/useTabListByDays';
import { convertSummaryTimeToString } from '../utils/converter';
import { ranges, ThisWeekRange } from '../utils/date';
import { useImportToCsvWithData } from '../functions/useImportToCsv';
import { useFile, FileType } from '../functions/useFile';
const { t } = useI18n();
const tabsByDays = ref<TabListByDays>();
const isLoading = ref<boolean>();
const noData = ref<boolean>();
const selectedDate = ref<Date[]>();
const presetRanges = ranges();
const countOfDays = computed(() =>
tabsByDays.value != undefined ? tabsByDays.value.days.length : 0,
);
async function loadList(dateFrom: Date, dateTo: Date) {
const tabList = await useTabListByDays(dateFrom, dateTo);
if (tabList != null) {
tabsByDays.value = tabList;
if (tabList.days.length == 0 && tabList.summaryTime == 0) noData.value = true;
else noData.value = false;
}
isLoading.value = false;
}
async function handleDate(modelData: Date[]) {
selectedDate.value = modelData;
const dateFrom = selectedDate.value?.[0] as Date;
const dateTo = selectedDate.value?.[1] as Date;
await loadList(dateFrom, dateTo);
}
onMounted(async () => {
isLoading.value = true;
selectedDate.value = ThisWeekRange;
const dateFrom = selectedDate.value?.[0] as Date;
const dateTo = selectedDate.value?.[1] as Date;
await loadList(dateFrom, dateTo);
});
async function exportToCsv() {
const dateFrom = selectedDate.value?.[0] as Date;
const dateTo = selectedDate.value?.[1] as Date;
const csv = await useImportToCsvWithData(tabsByDays.value?.days);
useFile(
csv,
FileType.CSV,
`websites_${dateFrom.toLocaleDateString()}-${dateTo.toLocaleDateString()}.csv`,
);
}
</script>
<style scoped>
.stats-block.block {
display: flex;
flex-direction: column;
justify-content: space-around;
margin: 10px 25px;
text-align: center;
}
.stats-block.block .header {
background-color: var(--popup-header);
color: rgb(66, 66, 66);
padding: 5px 5px;
border-radius: 5px;
}
.stats-block.block p {
margin: 2px;
text-align: center;
font-weight: 700;
font-size: 13px;
color: rgb(59, 59, 59);
}
.date-block {
display: flex;
justify-content: space-between;
margin: 0 25px;
}
.by-days-chart {
height: 240px;
}
</style>