1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
<template>
<Generic :item="item">
<template #content>
<p class="title is-4">{{ item.name }}</p>
<p class="subtitle is-6">
<template v-if="speedtest">
<i class="fas fa-arrow-down"></i> {{ download }} Mbit/s |
<i class="fas fa-arrow-up"></i> {{ upload }} Mbit/s |
<i class="fas fa-stopwatch"></i> {{ ping }} ms
</template>
</p>
</template>
</Generic>
</template>
<script>
import service from "@/mixins/service.js";
import Generic from "./Generic.vue";
export default {
name: "SpeedtestTracker",
mixins: [service],
props: {
item: Object,
},
components: {
Generic,
},
data: () => ({
speedtest: null,
}),
computed: {
download: function () {
return this.format(this.speedtest?.download);
},
upload: function () {
return this.format(this.speedtest?.upload);
},
ping: function () {
return this.format(this.speedtest?.ping);
},
},
created() {
this.fetchStatus();
},
methods: {
fetchStatus: async function () {
this.fetch("/api/speedtest/latest")
.then((response) => {
this.speedtest = response.data;
})
.catch((e) => console.log(e));
},
format: function (value) {
return value ? parseFloat(value).toFixed(2) : "n/a";
},
},
};
</script>
|