]> git.immae.eu Git - github/bastienwirtz/homer.git/blame - src/components/services/AdGuardHome.vue
Linting update
[github/bastienwirtz/homer.git] / src / components / services / AdGuardHome.vue
CommitLineData
33750a4c 1<template>
2ca4faad
BW
2 <Generic :item="item">
3 <template #content>
4 <p class="title is-4">{{ item.name }}</p>
5 <p class="subtitle is-6">
6 <template v-if="item.subtitle">
7 {{ item.subtitle }}
8 </template>
9 <template v-else-if="stats">
10 {{ percentage }}&percnt; blocked
11 </template>
12 </p>
13 </template>
14 <template #indicator>
15 <div class="status" :class="protection">
16 {{ protection }}
17 </div>
18 </template>
19 </Generic>
33750a4c 20</template>
21
22<script>
0a3be103 23import service from "@/mixins/service.js";
2ca4faad
BW
24import Generic from "./Generic.vue";
25
33750a4c 26export default {
27 name: "AdGuardHome",
0a3be103 28 mixins: [service],
33750a4c 29 props: {
30 item: Object,
31 },
2ca4faad
BW
32 components: {
33 Generic,
34 },
33750a4c 35 data: () => {
36 return {
37 status: null,
3832025b 38 stats: null,
33750a4c 39 };
40 },
3832025b
AW
41 computed: {
42 percentage: function () {
43 if (this.stats) {
bebb6953
AW
44 return (
45 (this.stats.num_blocked_filtering * 100) /
46 this.stats.num_dns_queries
47 ).toFixed(2);
3832025b
AW
48 }
49 return "";
50 },
bebb6953
AW
51 protection: function () {
52 if (this.status) {
53 return this.status.protection_enabled ? "enabled" : "disabled";
54 } else return "unknown";
55 },
3832025b 56 },
33750a4c 57 created: function () {
58 this.fetchStatus();
3832025b
AW
59 if (!this.item.subtitle) {
60 this.fetchStats();
61 }
33750a4c 62 },
63 methods: {
64 fetchStatus: async function () {
0a3be103 65 this.status = await this.fetch("/control/status").catch((e) =>
de4b7e61 66 console.log(e),
0a3be103 67 );
3832025b
AW
68 },
69 fetchStats: async function () {
0a3be103 70 this.stats = await this.fetch("/control/stats").catch((e) =>
de4b7e61 71 console.log(e),
0a3be103 72 );
33750a4c 73 },
74 },
75};
76</script>
77
78<style scoped lang="scss">
33750a4c 79.status {
80 font-size: 0.8rem;
81 color: var(--text-title);
82
83 &.enabled:before {
84 background-color: #94e185;
85 border-color: #78d965;
86 box-shadow: 0px 0px 4px 1px #94e185;
87 }
88
89 &.disabled:before {
90 background-color: #c9404d;
91 border-color: #c42c3b;
92 box-shadow: 0px 0px 4px 1px #c9404d;
93 }
94
bebb6953
AW
95 &.unknown:before {
96 background-color: #c9c740;
97 border-color: #ccc935;
98 box-shadow: 0px 0px 4px 1px #c9c740;
99 }
100
33750a4c 101 &:before {
102 content: " ";
103 display: inline-block;
104 width: 7px;
105 height: 7px;
106 margin-right: 10px;
107 border: 1px solid #000;
108 border-radius: 7px;
109 }
110}
111</style>