-
-
Notifications
You must be signed in to change notification settings - Fork 785
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add Gotify custom service component (#706)
This adds a new custom service component for Gotify, a system for sending and receiving messages. The component will display the number of messages outstanding as well as the overall system health. Co-authored-by: Bastien Wirtz <[email protected]>
- Loading branch information
1 parent
a2866e1
commit 779deed
Showing
2 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<template> | ||
<Generic :item="item"> | ||
<template #content> | ||
<p class="title is-4">{{ item.name }}</p> | ||
<p class="subtitle is-6"> | ||
<template v-if="messages > 0"> | ||
<template v-if="messages > 100">100+</template> | ||
<template v-else>{{ messages }}</template> | ||
<template v-if="messages === 1"> message</template> | ||
<template v-else> messages</template> | ||
</template> | ||
</p> | ||
</template> | ||
<template #indicator> | ||
<div v-if="status" class="status" :class="status"></div> | ||
</template> | ||
</Generic> | ||
</template> | ||
|
||
<script> | ||
import service from "@/mixins/service.js"; | ||
import Generic from "./Generic.vue"; | ||
export default { | ||
name: "Gotify", | ||
mixins: [service], | ||
props: { | ||
item: Object, | ||
}, | ||
components: { | ||
Generic, | ||
}, | ||
data: () => ({ | ||
health: {}, | ||
messages: 0, | ||
}), | ||
computed: { | ||
status: function () { | ||
const statuses = [this.health.health, this.health.database]; | ||
if (statuses.includes("red")) { | ||
return "red"; | ||
} else if (statuses.includes("orange")) { | ||
return "orange"; | ||
} | ||
return "green"; | ||
} | ||
}, | ||
created() { | ||
this.fetchStatus(); | ||
this.fetchMessages(); | ||
}, | ||
methods: { | ||
fetchStatus: async function () { | ||
await this.fetch(`/health`) | ||
.catch((e) => console.log(e)) | ||
.then((resp) => this.health = resp); | ||
}, | ||
fetchMessages: async function () { | ||
const headers = { | ||
"X-Gotify-Key": this.item.apikey, | ||
}; | ||
await this.fetch(`/message?limit=100`, { headers }) | ||
.catch((e) => console.log(e)) | ||
.then((resp) => this.messages = resp.messages.length); | ||
}, | ||
}, | ||
}; | ||
</script> | ||
|
||
<style scoped lang="scss"> | ||
.status { | ||
font-size: 0.8rem; | ||
color: var(--text-title); | ||
&.green:before { | ||
background-color: #94e185; | ||
border-color: #78d965; | ||
box-shadow: 0 0 5px 1px #94e185; | ||
} | ||
&.orange:before { | ||
background-color: #ee863e; | ||
border-color: #e77322; | ||
box-shadow: 0 0 5px 1px #ee863e; | ||
} | ||
&.red:before { | ||
background-color: #c9404d; | ||
border-color: #c42c3b; | ||
box-shadow: 0 0 5px 1px #c9404d; | ||
} | ||
&:before { | ||
content: " "; | ||
display: inline-block; | ||
width: 7px; | ||
height: 7px; | ||
margin-right: 10px; | ||
border: 1px solid #000; | ||
border-radius: 7px; | ||
} | ||
} | ||
</style> |