forked from Stigmatoz/web-activity-time-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeneralSettings.vue
More file actions
183 lines (171 loc) · 5.55 KB
/
GeneralSettings.vue
File metadata and controls
183 lines (171 loc) · 5.55 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<template>
<div class="settings-item">
<label class="setting-header">
<input
type="checkbox"
class="filled-in"
id="viewTimeInBadge"
v-model="viewTimeInBadge"
@change="onChange(StorageParams.VIEW_TIME_IN_BADGE, $event.target)"
/>
<span>Display time tracker in icon</span>
<p class="description">
You can see current spent time in short format in the icon of extension
</p>
</label>
</div>
<div class="settings-item">
<label class="setting-header">
<input
type="checkbox"
class="filled-in"
id="blockDeferral"
v-model="allowDeferringBlock"
@change="onChange(StorageParams.BLOCK_DEFERRAL, $event.target)"
/>
<span>Allow deferring block for 5 minutes</span>
<p class="description">
After the site is blocked, you can postpone the blocking for 5 minutes ones
</p>
</label>
</div>
<!-- <div class="settings-item">
<label class="setting-header">
<input
type="checkbox"
class="filled-in"
id="darkMode"
v-model="darkMode"
@change="onChange(StorageParams.DARK_MODE, $event.target)"
/>
<span>Dark mode</span>
<p class="description">Dark theme</p>
</label>
</div> -->
<div class="settings-item">
<label class="setting-header d-inline-block"
>Stop tracking if there is no activity during:
</label>
<div class="d-inline-block ml-10">
<select
class="option"
v-model="intervalInactivity"
@change="onChange(StorageParams.INTERVAL_INACTIVITY, $event.target)"
>
<option :value="InactivityInterval.Seconds_30">30 seconds</option>
<option :value="InactivityInterval.Seconds_45">45 seconds</option>
<option :value="InactivityInterval.Min_1">1 min</option>
<option :value="InactivityInterval.Min_2">2 min</option>
<option :value="InactivityInterval.Min_5">5 mins</option>
<option :value="InactivityInterval.Min_10">10 mins</option>
<option :value="InactivityInterval.Min_20">20 mins</option>
<option :value="InactivityInterval.Min_30">30 mins</option>
</select>
</div>
<p class="description">These are any actions with the mouse or keyboard</p>
</div>
<div class="settings-item">
<label class="setting-header d-inline-block">Exporting your web activity data to CSV </label>
<p class="description">You can export your web activity for any date range</p>
<div class="export-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="Export to CSV" @click="exportToCsv()" />
</div>
</div>
</template>
<script lang="ts">
export default {
name: 'GeneralSettings',
};
</script>
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { injecStorage } from '../storage/inject-storage';
import { useNotification } from '@kyvg/vue3-notification';
import {
BLOCK_DEFERRAL_DEFAULT,
DARK_MODE_DEFAULT,
INTERVAL_INACTIVITY_DEFAULT,
StorageParams,
VIEW_TIME_IN_BADGE_DEFAULT,
InactivityInterval,
} from '../storage/storage-params';
import { ranges, ThisWeekRange } from '../utils/date';
import { useImportToCsv } from '../compositions/toCsv';
import { FileType, useFile } from '../compositions/loadFile';
const settingsStorage = injecStorage();
const notification = useNotification();
const viewTimeInBadge = ref<boolean>();
const intervalInactivity = ref<InactivityInterval>();
const allowDeferringBlock = ref<boolean>();
const darkMode = ref<boolean>();
const selectedDate = ref<Date[]>();
const presetRanges = ranges();
onMounted(async () => {
viewTimeInBadge.value = await settingsStorage.getValue(
StorageParams.VIEW_TIME_IN_BADGE,
VIEW_TIME_IN_BADGE_DEFAULT,
);
intervalInactivity.value = await settingsStorage.getValue(
StorageParams.INTERVAL_INACTIVITY,
INTERVAL_INACTIVITY_DEFAULT,
);
darkMode.value = await settingsStorage.getValue(StorageParams.DARK_MODE, DARK_MODE_DEFAULT);
allowDeferringBlock.value = await settingsStorage.getValue(
StorageParams.BLOCK_DEFERRAL,
BLOCK_DEFERRAL_DEFAULT,
);
selectedDate.value = ThisWeekRange;
});
async function onChange(storageParam: StorageParams, target: any) {
if (target != null)
await save(
storageParam,
storageParam == StorageParams.INTERVAL_INACTIVITY ? Number(target.value) : target.checked,
);
}
async function save(storageParam: StorageParams, value: any) {
if (value != undefined) await settingsStorage.saveValue(storageParam, value);
}
async function handleDate(modelData: Date[]) {
selectedDate.value = modelData;
}
async function exportToCsv() {
const dateFrom = selectedDate.value?.[0] as Date;
const dateTo = selectedDate.value?.[1] as Date;
if (dateFrom == undefined || dateTo == undefined) {
notification.notify({
title: 'No time period selected',
type: 'warn',
});
} else {
const csv = await useImportToCsv(dateFrom, dateTo);
useFile(
csv,
FileType.CSV,
`websites_${dateFrom.toLocaleDateString()}-${dateTo.toLocaleDateString()}.csv`,
);
}
}
</script>
<style scoped>
.export-block {
display: flex;
justify-content: start;
}
.export-block .date-picker {
width: 250px;
margin-right: 15px;
}
</style>