forked from Stigmatoz/web-activity-time-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLimits.vue
More file actions
141 lines (125 loc) · 3.58 KB
/
Limits.vue
File metadata and controls
141 lines (125 loc) · 3.58 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
<template>
<div>
<p class="setting-header mt-0">Daily restrictions on access to websites:</p>
<p class="description">
Set the maximum time allowed to visit the site per day. After this time, the site will be
blocked.
</p>
<p class="description">
If you set the blocking time to 0 hours 0 minutes, the website will be blocked immediately
</p>
<ul readonly class="url-list">
<li v-for="(limit, i) of limitList" :key="i">
<div>
<img
src="../assets/icons/delete.png"
height="16"
@click="deleteFromLimitList(limit.domain)"
/>
{{ limit.domain }}
<p class="time-value">{{ getTimeForLimit(limit.time) }}</p>
</div>
</li>
</ul>
<div class="limits-time-block mt-20">
<input
type="text"
class="d-inline-block"
placeholder="Enter website name..."
v-model="newWebsiteForLimitList"
/>
<VueDatePicker v-model="time" time-picker class="date-picker height" />
<input
type="button"
class="d-inline-block small-btn"
value="Add Website"
:disabled="newWebsiteForLimitList == null || newWebsiteForLimitList == '' || time == null"
@click="addToLimitList()"
/>
</div>
</div>
</template>
<script lang="ts">
export default {
name: 'Limits',
};
</script>
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { useNotification } from '@kyvg/vue3-notification';
import { injecStorage } from '../storage/inject-storage';
import { StorageParams } from '../storage/storage-params';
import { isDomainEquals } from '../utils/common';
import { extractHostname } from '../compositions/extract-hostname';
import { Restriction } from '../entity/restriction';
import { convertSecondsToHHMM } from '../utils/converter';
const notification = useNotification();
const settingsStorage = injecStorage();
const limitList = ref<Restriction[]>();
const time = ref({
hours: 0,
minutes: 30,
});
const newWebsiteForLimitList = ref<string>();
onMounted(async () => {
limitList.value = Object.values(
await settingsStorage.getValue(StorageParams.RESTRICTION_LIST, []),
);
});
function addToLimitList() {
const existingItem = limitList.value?.find(x =>
isDomainEquals(extractHostname(x.domain), extractHostname(newWebsiteForLimitList.value!)),
);
if (existingItem !== undefined) {
notification.notify({
title: 'You have already added this site',
type: 'error',
});
} else {
const newLimit = new Restriction(
extractHostname(newWebsiteForLimitList.value!),
time.value.hours,
time.value.minutes,
);
limitList.value?.push(newLimit);
save(limitList.value);
newWebsiteForLimitList.value = '';
}
}
function getTimeForLimit(time: number) {
const timeObj = convertSecondsToHHMM(time);
return `${timeObj.hours}:${timeObj.minutes < 10 ? '0' + timeObj.minutes : timeObj.minutes}`;
}
function deleteFromLimitList(url: string) {
limitList.value = limitList.value!.filter(x => x.domain != url);
save(limitList.value);
}
async function save(value: any) {
if (value != undefined) await settingsStorage.saveValue(StorageParams.RESTRICTION_LIST, value);
}
</script>
<style scoped>
.about .about-label {
font-size: 14px;
margin-bottom: 30px;
display: block;
}
.limits-time-block {
display: flex;
justify-content: start;
}
.limits-time-block .date-picker {
width: 120px;
margin: 0 15px;
}
.height {
height: 36px;
}
.url-list {
width: 655px !important;
}
.url-list .time-value {
margin-top: 5px;
margin-left: 30px;
}
</style>