]> git.immae.eu Git - github/bastienwirtz/homer.git/blob - src/components/services/PiHole.vue
Services refactoring
[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 result = await this.fetch("/api.php").catch((e) => console.log(e));
53
54 this.status = result.status;
55 this.ads_percentage_today = result.ads_percentage_today;
56 },
57 },
58 };
59 </script>
60
61 <style scoped lang="scss">
62 .status {
63 font-size: 0.8rem;
64 color: var(--text-title);
65
66 &.enabled:before {
67 background-color: #94e185;
68 border-color: #78d965;
69 box-shadow: 0 0 5px 1px #94e185;
70 }
71
72 &.disabled:before {
73 background-color: #c9404d;
74 border-color: #c42c3b;
75 box-shadow: 0 0 5px 1px #c9404d;
76 }
77
78 &:before {
79 content: " ";
80 display: inline-block;
81 width: 7px;
82 height: 7px;
83 margin-right: 10px;
84 border: 1px solid #000;
85 border-radius: 7px;
86 }
87 }
88 </style>