forked from Stigmatoz/web-activity-time-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTabItem.vue
More file actions
179 lines (163 loc) · 4.44 KB
/
TabItem.vue
File metadata and controls
179 lines (163 loc) · 4.44 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
<template>
<div class="tab-item">
<Favicon :favicon="item.favicon" :type="typeOfUrl" />
<div
class="ml-10 flex-grow-2"
@mouseover="isShowCmdButtons = true"
@mouseleave="isShowCmdButtons = false"
>
<div class="first-block">
<div>
<p class="url">{{ url }}</p>
<BadgeIcons :url="url" :type="typeOfUrl" :listType="listType" />
<p class="links" v-if="isShowCmdButtons" title="Statistics">
<img
class="link"
src="../assets/icons/details-link.svg"
height="21"
@click="openStats(item.url)"
/>
</p>
<p class="links" v-if="isShowCmdButtons" title="Open website">
<img
class="link"
src="../assets/icons/open-link.svg"
height="21"
@click="openUrl(item.url)"
/>
</p>
</div>
<p class="text-right time">{{ summaryTimeForTab }}</p>
</div>
<p v-if="showWarningMessage" class="warning-message">
{{ t('cannotOpenFile.message') }}
</p>
<div class="second-block">
<div class="progress-bar">
<div :style="styleForProgressBar"></div>
</div>
<p class="text-right percent">{{ percent }} %</p>
</div>
<p class="sessions">{{ sessions }}</p>
</div>
</div>
</template>
<script lang="ts">
export default {
name: 'TabItem',
};
</script>
<script lang="ts" setup>
import { computed, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import Favicon from './Favicon.vue';
import BadgeIcons from './BadgeIcons.vue';
import { convertSummaryTimeToString } from '../utils/converter';
import { getPercentage } from '../utils/common';
import { CurrentTabItem } from '../dto/currentTabItem';
import { SettingsTab, TypeOfList, TypeOfUrl } from '../utils/enums';
import { openPage } from '../utils/open-page';
import { getTypeOfUrl } from '../utils/get-type-of-url';
const { t } = useI18n();
const props = defineProps<{
item: CurrentTabItem;
summaryTimeForWholeDay: number;
listType: TypeOfList;
}>();
const isShowCmdButtons = ref<boolean>();
const typeOfUrl = computed(() => getTypeOfUrl(props.item.url));
const url = computed(() =>
typeOfUrl.value == TypeOfUrl.Document
? decodeURI(props.item.url.split('///')[1])
: props.item.url,
);
const sessions = computed(() => {
if (props.item.sessions == 0) return `0 ${t('someSession.message')}`;
if (props.item.sessions > 1) return `${props.item.sessions} ${t('someSession.message')}`;
if (props.item.sessions == 1) return `${props.item.sessions} ${t('session.message')}`;
});
const summaryTimeForTab = computed(() => convertSummaryTimeToString(props.item.summaryTime));
const percent = computed(() => getPercentage(props.item.summaryTime, props.summaryTimeForWholeDay));
const styleForProgressBar = computed(() => `width: ${percent.value}%`);
function openUrl(url: string) {
if (typeOfUrl.value != TypeOfUrl.Document && !url.startsWith('http')) {
url = `https://${url}`;
window.open(url, '_blank');
} else showWarningMessage.value = true;
}
async function openStats(url: string) {
await openPage(SettingsTab.WebsiteStats, url);
}
const showWarningMessage = ref<boolean>();
</script>
<style scoped>
.tab-item {
padding: 7px;
border: 1px transparent solid;
border-radius: 10px;
margin: 5px 15px;
display: flex;
justify-content: flex-start;
align-items: center;
}
.tab-item:hover {
border: 1px rgb(202, 202, 202) solid;
}
.tab-item .links {
display: inline-block;
margin: 0;
cursor: pointer;
margin: 0 5px;
}
.tab-item .links .link {
vertical-align: middle;
}
.tab-item .url {
font-size: 15px;
cursor: pointer;
overflow-wrap: anywhere;
display: inline-block;
}
.tab-item .url:hover {
color: rgb(99, 99, 243);
}
.tab-item p {
margin: 5px;
}
.tab-item .time {
font-size: 14px;
font-weight: 600;
}
.tab-item .progress-bar {
width: 100%;
margin: 5px 0 0 5px;
border-radius: 10px;
border: 1.5px rgb(225 224 224) solid;
}
.tab-item .progress-bar div {
height: 6px;
background-color: var(--progress-bar);
}
.flex-grow-2 {
flex-grow: 2;
}
.tab-item .first-block {
display: flex;
justify-content: space-between;
}
.tab-item .second-block {
display: flex;
flex-direction: row;
align-items: baseline;
}
.tab-item .percent {
white-space: nowrap;
margin: 0 5px 0 20px;
}
.tab-item .sessions {
margin: 0 0 0 5px;
}
.tab-item .warning-message {
color: grey;
}
</style>