forked from Stigmatoz/web-activity-time-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebsiteStats.vue
More file actions
144 lines (132 loc) · 4.19 KB
/
WebsiteStats.vue
File metadata and controls
144 lines (132 loc) · 4.19 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
<template>
<div class="settings-item">
<label class="title link" @click="openPage(SettingsTab.Dashboard)">
{{ t('dashboard.message') }}
</label>
<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">
<div>
<Favicon :favicon="tab?.favicon" :type="getTypeOfUrl(tab?.url!)" />
<span class="title"> {{ tab?.url }}</span>
</div>
<VueDatePicker
range
:enable-time-picker="false"
class="date-picker mt-10"
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 class="mt-20 ml-10 mr-10 by-days-chart">
<by-days-chart :data="tabInfoByDays!" />
</div>
<div>
<website-stats-details :details="tabInfoByDays!" />
</div>
</div>
</div>
</div>
</template>
<script lang="ts">
export default {
name: 'WebsiteStats',
};
</script>
<script lang="ts" setup>
import { useI18n } from 'vue-i18n';
import Favicon from './Favicon.vue';
import NoDataByDays from './NoDataByDays.vue';
import ByDaysChart from '../components/ByDaysChart.vue';
import WebsiteStatsDetails from '../components/WebsiteStatsDetails.vue';
import { openPage } from '../utils/open-page';
import { computed, onMounted, ref } from 'vue';
import { SettingsTab } from '../utils/enums';
import { ThisWeekRange, ranges } from '../utils/date';
import { useTabStatsByDays } from '../functions/useTabStatsByDays';
import { TabListByDays } from '../dto/tabListSummary';
import { Tab } from '../entity/tab';
import { getTypeOfUrl } from '../utils/get-type-of-url';
import { injectTabsRepository } from '../repository/inject-tabs-repository';
const props = defineProps<{
domain: string;
}>();
const { t } = useI18n();
const presetRanges = ranges();
const tabInfoByDays = ref<TabListByDays>();
const isLoading = ref<boolean>();
const noData = ref<boolean>(false);
const selectedDate = ref<Date[]>();
const tab = ref<Tab>();
const countOfDays = computed(() =>
tabInfoByDays.value != undefined ? tabInfoByDays.value.days.length : 0,
);
onMounted(async () => {
isLoading.value = true;
selectedDate.value = ThisWeekRange;
const dateFrom = selectedDate.value?.[0] as Date;
const dateTo = selectedDate.value?.[1] as Date;
const repo = await injectTabsRepository();
tab.value = repo.getTab(props.domain);
if (tab == undefined) {
noData.value = true;
return;
}
await loadList(dateFrom, dateTo);
});
async function loadList(dateFrom: Date, dateTo: Date) {
const tabList = await useTabStatsByDays(dateFrom, dateTo, tab.value?.url!);
if (tabList != null) {
tabInfoByDays.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);
}
</script>
<style scoped>
.link {
cursor: pointer;
color: grey;
text-decoration: underline;
}
.date-block {
display: flex;
justify-content: space-between;
}
.by-days-chart {
height: 400px;
}
</style>