van fej
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Pünkösd Marcell 2021-06-12 23:36:23 +02:00
parent 0fa57f4905
commit f8cf26eee3
6 changed files with 115 additions and 10 deletions

1
.env Normal file
View File

@ -0,0 +1 @@
VUE_APP_API_LOCATION=https://birb.k8s.kmlabz.com/

11
package-lock.json generated
View File

@ -2661,6 +2661,14 @@
"integrity": "sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==", "integrity": "sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==",
"dev": true "dev": true
}, },
"axios": {
"version": "0.21.1",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz",
"integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==",
"requires": {
"follow-redirects": "^1.10.0"
}
},
"babel-code-frame": { "babel-code-frame": {
"version": "6.26.0", "version": "6.26.0",
"resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.26.0.tgz", "resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.26.0.tgz",
@ -5781,8 +5789,7 @@
"follow-redirects": { "follow-redirects": {
"version": "1.14.1", "version": "1.14.1",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.1.tgz", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.1.tgz",
"integrity": "sha512-HWqDgT7ZEkqRzBvc2s64vSZ/hfOceEol3ac/7tKwzuvEyWx3/4UegXh5oBOIotkGsObyk3xznnSRVADBgWSQVg==", "integrity": "sha512-HWqDgT7ZEkqRzBvc2s64vSZ/hfOceEol3ac/7tKwzuvEyWx3/4UegXh5oBOIotkGsObyk3xznnSRVADBgWSQVg=="
"dev": true
}, },
"for-in": { "for-in": {
"version": "1.0.2", "version": "1.0.2",

View File

@ -8,6 +8,7 @@
"lint": "vue-cli-service lint" "lint": "vue-cli-service lint"
}, },
"dependencies": { "dependencies": {
"axios": "^0.21.1",
"bootstrap": "^4.5.2", "bootstrap": "^4.5.2",
"bootstrap-vue": "^2.16.0", "bootstrap-vue": "^2.16.0",
"core-js": "^3.6.5", "core-js": "^3.6.5",

View File

@ -1,23 +1,49 @@
<template> <template>
<b-overlay :show="false" rounded="sm"> <b-overlay :show="actionPending" rounded="sm">
<b-card <b-card
title="All devices" title="All devices"
tag="all-devices"
class="m-2" class="m-2"
> >
<b-card-text> <b-card-text>
Control all devices Control all devices
</b-card-text> </b-card-text>
<b-button variant="success" class="mr-1">Bring online</b-button> <b-button @click="allOnline" variant="success" class="mr-1 mt-1">Bring online</b-button>
<b-button variant="danger" class="mr-1">Bring offline</b-button> <b-button @click="allOffline" variant="danger" class="mr-1 mt-1">Bring offline</b-button>
</b-card> </b-card>
</b-overlay> </b-overlay>
</template> </template>
<script> <script>
export default { export default {
name: "GlobalDeviceBuzgerator" name: "GlobalDeviceBuzgerator",
data() {
return {
actionPending: false
}
},
methods: {
performPostAndEverything(url) {
this.actionPending = true
this.$api.post(url).then(() => this.actionPending = false).catch((error) => {
if (!error.response) {
// network error happened
this.$showToast("Some network error happened.\nCheck logs!")
} else {
// server returned bruh moment
this.$showToast(`The server returned error: ${error.response.status} ${error.response.statusText}\n${error.response.data}`)
}
this.actionPending = false
});
},
allOnline() {
this.performPostAndEverything("/devices/online")
},
allOffline() {
this.performPostAndEverything("/devices/offline")
}
}
} }
</script> </script>

View File

@ -8,9 +8,9 @@
Could not read device data! Could not read device data!
</b-card-text> </b-card-text>
<b-button variant="success" class="mr-1">Bring online</b-button> <b-button @click="bringOnline" variant="success" class="mr-1 mt-1">Bring online</b-button>
<b-button variant="danger" class="mr-1">Bring offline</b-button> <b-button @click="bringOffline" variant="danger" class="mr-1 mt-1">Bring offline</b-button>
<b-button variant="warning" class="mr-1">Manual alert</b-button> <b-button @click="doManualAlert" variant="warning" class="mr-1 mt-1">Manual alert</b-button>
</b-card> </b-card>
</b-overlay> </b-overlay>
</template> </template>
@ -23,10 +23,40 @@ export default {
type: String type: String
} }
}, },
data() {
return {
actionPending: false
}
},
computed: { computed: {
cardTitle() { cardTitle() {
return `Device: ${this.device_id}` return `Device: ${this.device_id}`
} }
},
methods: {
performPostAndEverything(url) {
this.actionPending = true
this.$api.post(url).then(() => this.actionPending = false).catch((error) => {
if (!error.response) {
// network error happened
this.$showToast("Some network error happened.\nCheck logs!")
} else {
// server returned bruh moment
this.$showToast(`The server returned error: ${error.response.status} ${error.response.statusText}\n${error.response.data}`)
}
this.actionPending = false
});
},
bringOffline() {
this.performPostAndEverything(`/devices/${this.device_id}/offline`)
},
bringOnline() {
this.performPostAndEverything(`/devices/${this.device_id}/online`)
},
doManualAlert() {
this.performPostAndEverything(`/devices/${this.device_id}/alert`)
}
} }
} }
</script> </script>

View File

@ -3,6 +3,8 @@ import App from './App.vue'
import router from './router' import router from './router'
import store from './store' import store from './store'
import axios from 'axios'
import { BootstrapVue, IconsPlugin } from 'bootstrap-vue' import { BootstrapVue, IconsPlugin } from 'bootstrap-vue'
import 'bootstrap/dist/css/bootstrap.css' import 'bootstrap/dist/css/bootstrap.css'
@ -13,6 +15,44 @@ Vue.use(IconsPlugin)
Vue.config.productionTip = false Vue.config.productionTip = false
Vue.prototype.$api = axios.create({
baseURL: process.env.VUE_APP_API_LOCATION
});
Vue.prototype.$showToast = function (text, type = 'error', local=true) {
let options = {}
switch (type) {
case "error":
options = {
title: "Error!",
variant: "danger"
}
break;
case "user_error":
options = {
title: "Oopsie woopsie",
variant: "warning"
}
break;
case "success":
options = {
title: "Success!",
variant: "success"
}
break;
}
const bvToast = local ? this.$bvToast : this.$root.$bvToast
bvToast.toast(text, {
...options,
toaster: 'b-toaster-top-right',
solid: true,
appendToast: false
})
}
new Vue({ new Vue({
router, router,
store, store,