]> git.immae.eu Git - github/bastienwirtz/homer.git/blob - src/components/services/PiHole.vue
Implement PiHole API token (#580)
[github/bastienwirtz/homer.git] / src / components / services / PiHole.vue
1 <template>
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="percentage">
10 {{ percentage }}&percnt; blocked
11 </template>
12 </p>
13 </template>
14 <template #indicator>
15 <div v-if="status" class="status" :class="status">
16 {{ status }}
17 </div>
18 </template>
19 </Generic>
20 </template>
21
22 <script>
23 import service from "@/mixins/service.js";
24 import Generic from "./Generic.vue";
25
26 export default {
27 name: "PiHole",
28 mixins: [service],
29 props: {
30 item: Object,
31 },
32 components: {
33 Generic,
34 },
35 data: () => ({
36 status: "",
37 ads_percentage_today: 0,
38 }),
39 computed: {
40 percentage: function () {
41 if (this.ads_percentage_today) {
42 return this.ads_percentage_today.toFixed(1);
43 }
44 return "";
45 },
46 },
47 created() {
48 this.fetchStatus();
49 },
50 methods: {
51 fetchStatus: async function () {
52 const authQueryParams = this.item.apikey
53 ? `?summaryRaw&auth=${this.item.apikey}`
54 : "";
55 const result = await this.fetch(`/api.php${authQueryParams}`)
56 .catch((e) => console.log(e));
57
58 this.status = result.status;
59 this.ads_percentage_today = result.ads_percentage_today;
60 },
61 },
62 };
63 </script>
64
65 <style scoped lang="scss">
66 .status {
67 font-size: 0.8rem;
68 color: var(--text-title);
69
70 &.enabled:before {
71 background-color: #94e185;
72 border-color: #78d965;
73 box-shadow: 0 0 5px 1px #94e185;
74 }
75
76 &.disabled:before {
77 background-color: #c9404d;
78 border-color: #c42c3b;
79 box-shadow: 0 0 5px 1px #c9404d;
80 }
81
82 &:before {
83 content: " ";
84 display: inline-block;
85 width: 7px;
86 height: 7px;
87 margin-right: 10px;
88 border: 1px solid #000;
89 border-radius: 7px;
90 }
91 }
92 </style>