Merge pull request #169 from bramceulemans/extended-pihole-component

Added extended PiHole statistics
This commit is contained in:
Bastien Wirtz 2020-12-09 15:16:19 -08:00 committed by GitHub
commit 16a86df3e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 15 deletions

View File

@ -109,7 +109,7 @@ services:
items:
- name: "Pi-hole"
logo: "assets/tools/sample.png"
subtitle: "Network-wide Ad Blocking"
# subtitle: "Network-wide Ad Blocking" # optional, if no subtitle is defined, PiHole statistics will be shown
tag: "other"
url: "http://192.168.0.151/admin"
type: "PiHole" # optional, loads a specific component that provides extra features. MUST MATCH a file name (without file extension) available in `src/components/services`

View File

@ -11,15 +11,22 @@
</div>
<div v-if="item.icon" class="media-left">
<figure class="image is-48x48">
<i style="font-size: 35px;" :class="['fa-fw', item.icon]"></i>
<i style="font-size: 35px" :class="['fa-fw', item.icon]"></i>
</figure>
</div>
<div class="media-content">
<p class="title is-4">{{ item.name }}</p>
<p class="subtitle is-6">{{ item.subtitle }}</p>
<p class="subtitle is-6">
<template v-if="item.subtitle">
{{ item.subtitle }}
</template>
<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">
@ -37,19 +44,29 @@ export default {
props: {
item: Object,
},
data: () => {
return {
status: null,
};
data: () => ({
api: {
status: "",
ads_percentage_today: 0,
},
}),
computed: {
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));
},
},
};
@ -66,13 +83,13 @@ export default {
&.enabled:before {
background-color: #94e185;
border-color: #78d965;
box-shadow: 0px 0px 4px 1px #94e185;
box-shadow: 0 0 4px 1px #94e185;
}
&.disabled:before {
background-color: #c9404d;
border-color: #c42c3b;
box-shadow: 0px 0px 4px 1px #c9404d;
box-shadow: 0 0 4px 1px #c9404d;
}
&:before {