]> git.immae.eu Git - github/bastienwirtz/homer.git/blobdiff - src/components/services/PiHole.vue
Merge pull request #213 from simonporte/main
[github/bastienwirtz/homer.git] / src / components / services / PiHole.vue
index 10d5ece9e25327341e8a0df5cc70fbd750b1dd68..7042a7b2a5055662e7434bead008af4036a6e934 100644 (file)
                 <template v-if="item.subtitle">
                   {{ item.subtitle }}
                 </template>
-                <template v-else-if="status">
-                  {{ percentage }}% blocked
+                <template v-else-if="api">
+                  {{ percentage }}&percnt; blocked
                 </template>
               </p>
             </div>
-            <div v-if="status" class="status" :class="status.status">
-              {{ status.status }}
+            <div v-if="api" class="status" :class="api.status">
+              {{ api.status }}
             </div>
           </div>
           <div class="tag" :class="item.tagstyle" v-if="item.tag">
@@ -44,27 +44,29 @@ export default {
   props: {
     item: Object,
   },
-  data: () => {
-    return {
-      status: null,
-    };
-  },
+  data: () => ({
+    api: {
+      status: "",
+      ads_percentage_today: 0,
+    },
+  }),
   computed: {
-    blocked: function () {
-      if (this.status) {
-        return this.status.dns_queries_today.toFixed(0);
+    percentage: function () {
+      if (this.api) {
+        return this.api.ads_percentage_today.toFixed(1);
       }
       return "";
     },
   },
-  created: function () {
+  created() {
     this.fetchStatus();
   },
   methods: {
     fetchStatus: async function () {
-      this.status = await fetch(`${this.item.url}/api.php`).then((response) =>
-        response.json()
-      );
+      const url = `${this.item.url}/api.php`;
+      this.api = await fetch(url)
+        .then((response) => response.json())
+        .catch((e) => console.log(e));
     },
   },
 };
@@ -81,13 +83,13 @@ export default {
   &.enabled:before {
     background-color: #94e185;
     border-color: #78d965;
-    box-shadow: 0 0 4px 1px #94e185;
+    box-shadow: 0 0 5px 1px #94e185;
   }
 
   &.disabled:before {
     background-color: #c9404d;
     border-color: #c42c3b;
-    box-shadow: 0 0 4px 1px #c9404d;
+    box-shadow: 0 0 5px 1px #c9404d;
   }
 
   &:before {