forked from Stigmatoz/web-activity-time-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTabList.vue
More file actions
167 lines (144 loc) · 4.63 KB
/
TabList.vue
File metadata and controls
167 lines (144 loc) · 4.63 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>
<div class="no-data" v-if="countOfSites == undefined || countOfSites == 0">
{{ t('noData.message') }}
</div>
<div v-else>
<OverallStatistics v-if="isShowOverallStats" :data="dataForOvarallStats" />
<DonutChart
:time="timeForChart"
:labels="sitesForChart"
v-if="type != TypeOfList.Dashboard"
/>
<TabItemHeader
:listType="type"
:summaryTime="summaryTime"
:countOfSites="countOfSites"
:firstDay="firstDay"
:countOfActiveDays="countOfActiveDays"
@sortingBy="sorting"
/>
<TabItem
v-for="(tab, i) of tabs"
:key="i"
:item="getItem(tab)"
:listType="type"
:summaryTimeForWholeDay="summaryTime"
/>
<div class="show-all" v-if="showOnlyFirst100Items">
<button @click="showAllWebSites()">{{ t('showAll.message') }}</button>
</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 TabItemHeader from '../components/TabItemHeader.vue';
import DonutChart from '../components/DonutChart.vue';
import OverallStatistics from '../components/OverallStatistics.vue';
import { Tab } from '../entity/tab';
import { SortingBy, TypeOfList } from '../utils/enums';
import { useTodayTabListSummary } from '../functions/useTodayTabListSummary';
import { useAllTabListSummary } from '../functions/useAllTabListSummary';
import { CurrentTabItem } from '../dto/currentTabItem';
import { todayLocalDate } from '../utils/date';
import { OverallStats } from '../dto/tabListSummary';
const { t } = useI18n();
const props = defineProps<{
type: TypeOfList;
showAllStats: boolean;
}>();
const isShowOverallStats = computed(() => props.showAllStats && props.type == TypeOfList.All);
let loadedTabs: Tab[] = [];
const tabs = ref<Tab[]>();
const dataForOvarallStats = ref<OverallStats>();
const timeForChart = ref<number[]>();
const sitesForChart = ref<string[]>();
const summaryTime = ref<number>();
const firstDay = ref<Date>();
const countOfActiveDays = ref<number>();
const countOfSites = computed(() => (tabs.value != undefined ? tabs.value.length : 0));
const isLoading = ref<boolean>();
const showOnlyFirst100Items = ref<boolean>();
function showAllWebSites() {
showOnlyFirst100Items.value = false;
tabs.value = loadedTabs;
}
async function loadList(sortingBy: SortingBy) {
let tabSummary = null;
if (props.type == TypeOfList.Today || props.type == TypeOfList.Dashboard)
tabSummary = await useTodayTabListSummary(sortingBy);
if (props.type == TypeOfList.All) {
tabSummary = await useAllTabListSummary(sortingBy);
if (tabSummary != null) {
firstDay.value = tabSummary.firstDay;
countOfActiveDays.value = tabSummary.activeDaysTotal;
dataForOvarallStats.value = tabSummary;
}
}
if (tabSummary != null) {
loadedTabs = tabSummary.tabs;
tabs.value = tabSummary.tabs;
summaryTime.value = tabSummary.summaryTime;
timeForChart.value = tabSummary.chart.timeForChart;
sitesForChart.value = tabSummary.chart.sitesForChart;
if (props.type == TypeOfList.All && loadedTabs.length > 100) {
showOnlyFirst100Items.value = true;
tabs.value = tabSummary.tabs.slice(0, 100);
} else showOnlyFirst100Items.value = false;
}
isLoading.value = false;
}
async function sorting(sortingBy: SortingBy) {
switch (sortingBy) {
case SortingBy.UsageTime:
await loadList(SortingBy.UsageTime);
break;
case SortingBy.Sessions:
await loadList(SortingBy.Sessions);
break;
}
}
function getItem(tab: Tab): CurrentTabItem {
return {
summaryTime:
props.type == TypeOfList.Today || props.type == TypeOfList.Dashboard
? tab.days.find(day => day.date === todayLocalDate())!.summary
: tab.summaryTime,
favicon: tab.favicon,
url: tab.url,
sessions:
props.type == TypeOfList.Today || props.type == TypeOfList.Dashboard
? tab.days.find(day => day.date === todayLocalDate())!.counter
: tab.counter,
};
}
onMounted(async () => {
isLoading.value = true;
await loadList(SortingBy.UsageTime);
});
</script>
<style scoped>
.show-all {
text-align: center;
padding-bottom: 10px;
}
.show-all button {
background-color: aliceblue;
border-radius: 5px;
border: 1px rgb(202, 202, 202) solid;
font-size: 13px;
cursor: pointer;
padding: 5px 25px;
}
</style>