aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/components/services/SpeedtestTracker.vue86
1 files changed, 86 insertions, 0 deletions
diff --git a/src/components/services/SpeedtestTracker.vue b/src/components/services/SpeedtestTracker.vue
new file mode 100644
index 0000000..f836001
--- /dev/null
+++ b/src/components/services/SpeedtestTracker.vue
@@ -0,0 +1,86 @@
1<template>
2 <div>
3 <div class="card" :class="item.class">
4 <a :href="item.url" :target="item.target" rel="noreferrer">
5 <div class="card-content">
6 <div class="media">
7 <div v-if="item.logo" class="media-left">
8 <figure class="image is-48x48">
9 <img :src="item.logo" :alt="`${item.name} logo`" />
10 </figure>
11 </div>
12 <div v-if="item.icon" class="media-left">
13 <figure class="image is-48x48">
14 <i style="font-size: 35px" :class="['fa-fw', item.icon]"></i>
15 </figure>
16 </div>
17 <div class="media-content">
18 <p class="title is-4">{{ item.name }}</p>
19 <p class="subtitle is-6">
20 <template v-if="item.subtitle">
21 {{ item.subtitle }}
22 </template>
23 <template v-else-if="api">
24 <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
25 </template>
26 </p>
27 </div>
28 </div>
29 <div class="tag" :class="item.tagstyle" v-if="item.tag">
30 <strong class="tag-text">#{{ item.tag }}</strong>
31 </div>
32 </div>
33 </a>
34 </div>
35 </div>
36</template>
37
38<script>
39export default {
40 name: "SpeedtestTracker",
41 props: {
42 item: Object,
43 },
44 data: () => ({
45 api: null,
46 }),
47 computed: {
48 download: function() {
49 var download = this.api.data.download;
50 return parseFloat(download).toFixed(2);
51 },
52 upload: function() {
53 var upload = this.api.data.upload;
54 return parseFloat(upload).toFixed(2);
55 },
56 ping: function() {
57 var ping = this.api.data.ping;
58 return parseFloat(ping).toFixed(2);
59 },
60 },
61 created() {
62 this.fetchStatus();
63 },
64 methods: {
65 fetchStatus: async function () {
66 if (this.item.subtitle != null) return; // omitting unnecessary ajax call as the subtitle is showing
67 const url = `${this.item.url}/api/speedtest/latest`;
68 this.api = await fetch(url)
69 .then(function(response) {
70 if (!response.ok) {
71 throw new Error("Not 2xx response");
72 } else {
73 return response.json();
74 }
75 })
76 .catch((e) => console.log(e));
77 },
78 },
79};
80</script>
81
82<style scoped lang="scss">
83.media-left img {
84 max-height: 100%;
85}
86</style>