]> git.immae.eu Git - github/bastienwirtz/homer.git/blame - src/components/services/AdGuardHome.vue
Factorize fetch options
[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
BW
65 this.status = await this.fetch("/control/status").catch((e) =>
66 console.log(e)
67 );
3832025b
AW
68 },
69 fetchStats: async function () {
0a3be103
BW
70 this.stats = await this.fetch("/control/stats").catch((e) =>
71 console.log(e)
72 );
33750a4c 73 },
74 },
75};
76</script>
77
78<style scoped lang="scss">
79.media-left img {
80 max-height: 100%;
81}
82.status {
83 font-size: 0.8rem;
84 color: var(--text-title);
85
86 &.enabled:before {
87 background-color: #94e185;
88 border-color: #78d965;
89 box-shadow: 0px 0px 4px 1px #94e185;
90 }
91
92 &.disabled:before {
93 background-color: #c9404d;
94 border-color: #c42c3b;
95 box-shadow: 0px 0px 4px 1px #c9404d;
96 }
97
bebb6953
AW
98 &.unknown:before {
99 background-color: #c9c740;
100 border-color: #ccc935;
101 box-shadow: 0px 0px 4px 1px #c9c740;
102 }
103
33750a4c 104 &:before {
105 content: " ";
106 display: inline-block;
107 width: 7px;
108 height: 7px;
109 margin-right: 10px;
110 border: 1px solid #000;
111 border-radius: 7px;
112 }
113}
114</style>