From e10e00f2223396e581995067c081ac79f759fe34 Mon Sep 17 00:00:00 2001 From: marcsello Date: Sun, 13 Jun 2021 16:56:31 +0200 Subject: [PATCH] Added success toasts --- src/components/GlobalDeviceBuzgerator.vue | 36 ++++++++++++++-------- src/components/SingleDeviceBuzgerator.vue | 37 +++++++++++++++-------- 2 files changed, 47 insertions(+), 26 deletions(-) diff --git a/src/components/GlobalDeviceBuzgerator.vue b/src/components/GlobalDeviceBuzgerator.vue index dc39ac4..a873658 100644 --- a/src/components/GlobalDeviceBuzgerator.vue +++ b/src/components/GlobalDeviceBuzgerator.vue @@ -24,24 +24,34 @@ export default { }, 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}`) - } + return new Promise((resolve, reject) => { + this.actionPending = true + this.$api.post(url).then(() => { + this.actionPending = false + resolve() + }).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 - }); + this.actionPending = false + reject() + }) + }) }, allOnline() { - this.performPostAndEverything("/devices/online") + this.performPostAndEverything("/devices/online").then(() => { + this.$showToast("Global online command issued", "success") + }) }, allOffline() { - this.performPostAndEverything("/devices/offline") + this.performPostAndEverything("/devices/offline").then(() => { + this.$showToast("Global offline command issued", "success") + }) } } } diff --git a/src/components/SingleDeviceBuzgerator.vue b/src/components/SingleDeviceBuzgerator.vue index b1a128a..43e74dd 100644 --- a/src/components/SingleDeviceBuzgerator.vue +++ b/src/components/SingleDeviceBuzgerator.vue @@ -35,24 +35,35 @@ export default { }, 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}`) - } + return new Promise((resolve, reject) => { + this.actionPending = true + this.$api.post(url).then(() => { + this.actionPending = false + resolve() + }).catch((error) => { - this.actionPending = false - }); + 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 + reject() + }) + }) }, bringOffline() { - this.performPostAndEverything(`/devices/${this.device_id}/offline`) + this.performPostAndEverything(`/devices/${this.device_id}/offline`).then(()=> { + this.$showToast("Offline command issued!", "success") + }) }, bringOnline() { - this.performPostAndEverything(`/devices/${this.device_id}/online`) + this.performPostAndEverything(`/devices/${this.device_id}/online`).then(() => { + this.$showToast("Online command issued!", "success") + }) }, doManualAlert() { this.performPostAndEverything(`/devices/${this.device_id}/alert`)