feat(smartcard): Simplify ping card

pull/784/merge
Bastien Wirtz 2024-11-08 18:08:14 +01:00
parent f7cc9761e9
commit a666d7aa93
3 changed files with 16 additions and 13 deletions

View File

@ -145,17 +145,15 @@ API key can be generated in Settings > Administration > Auth Tokens
## Ping ## Ping
For Ping you need to set the type to Ping and provide a url. By default the HEAD method is used but it can be configured to use GET using the optional `method` property. You can also choose to show the round trip time (RTT) by setting `showRtt` to true, default is false. The RTT will be displayed in the subtitle section. This card checks if the target link is available. All you need is to set the `type` to `Ping` and provide a url. By default the HEAD method is used but it can be configured to use GET using the optional `method` property. By default, the subtitle line shows the round trip time (RTT) of the request, unless you provide the `subtitle` property.
```yaml ```yaml
- name: "Awesome app" - name: "Awesome app"
type: Ping type: Ping
logo: "assets/tools/sample.png" logo: "assets/tools/sample.png"
tag: "app"
url: "https://www.wikipedia.org/" url: "https://www.wikipedia.org/"
method: "head" # method: "head"
subtitle: "Bookmark example" # subtitle: "Bookmark example" # By default, request round trip time is displayed when subtitle is not set.
# showRtt: true
``` ```
## Prometheus ## Prometheus

View File

@ -8,15 +8,12 @@
<template #content> <template #content>
<p class="title is-4">{{ item.name }}</p> <p class="title is-4">{{ item.name }}</p>
<p class="subtitle is-6"> <p class="subtitle is-6">
<template v-if="status === 'online' && item.showRtt"> <template v-if="item.subtitle">
{{ rtt }} ms
</template>
<template v-else-if="status === 'offline' && item.showRtt">
N/A
</template>
<template v-else-if="!item.showRtt && item.subtitle">
{{ item.subtitle }} {{ item.subtitle }}
</template> </template>
<template v-else>
{{ rttLabel }}
</template>
</p> </p>
</template> </template>
</Generic> </Generic>
@ -39,6 +36,14 @@ export default {
status: null, status: null,
rtt: null, rtt: null,
}), }),
computed: {
rttLabel: function () {
if (this.status === 'online') {
return `${this.rtt}ms`;
}
return "unavailable";
}
},
created() { created() {
this.fetchStatus(); this.fetchStatus();
}, },

View File

@ -48,7 +48,7 @@ export default {
return fetch(url, options).then((response) => { return fetch(url, options).then((response) => {
if (!response.ok) { if (!response.ok) {
throw new Error("Not 2xx response"); throw new Error(`Ping: target not available (${response.status} error)`);
} }
return json ? response.json() : response; return json ? response.json() : response;