diff --git a/src/components/controlComponents/paneStatus.vue b/src/components/controlComponents/paneStatus.vue index 552f01c9..951b8a35 100644 --- a/src/components/controlComponents/paneStatus.vue +++ b/src/components/controlComponents/paneStatus.vue @@ -1,6 +1,6 @@ @@ -63,7 +87,8 @@ export default { data: function() { return { status: null, - settings: null + settings: null, + systemActionLinks: {} }; }, @@ -73,6 +98,9 @@ export default { }, statusUri: function() { return `${this.$store.getters.baseUri}/api/v2/status`; + }, + actionsUri: function() { + return `${this.$store.getters.baseUri}/api/v2/actions`; } }, @@ -85,6 +113,7 @@ export default { () => { this.updateStatus(); this.updateSettings(); + this.updateSystemActions(); } ); }, @@ -109,6 +138,63 @@ export default { .catch(error => { this.modalError(error); // Let mixin handle error }); + }, + updateSystemActions: function() { + axios + .get(this.actionsUri) + .then(response => { + if ("reboot" in response.data) { + this.systemActionLinks.reboot = `${this.$store.getters.baseUri}${ + response.data.reboot.links.self + }`; + } else { + delete this.systemActionLinks.reboot; + } + if ("shutdown" in response.data) { + this.systemActionLinks.shutdown = `${this.$store.getters.baseUri}${ + response.data.shutdown.links.self + }`; + } else { + delete this.systemActionLinks.shutdown; + } + }) + .catch(error => { + this.modalError(error); // Let mixin handle error + }); + }, + shutdownRequest: function() { + this.modalConfirm("Shut down microscope?").then( + () => { + if ("shutdown" in this.systemActionLinks) { + axios + .post(this.systemActionLinks.shutdown) + .then(() => { + this.$store.commit("resetState"); + }) + .catch(error => { + this.modalError(error); // Let mixin handle error + }); + } + }, + () => {} + ); + }, + rebootRequest: function() { + this.modalConfirm("Restart microscope?").then( + () => { + if ("reboot" in this.systemActionLinks) { + axios + .post(this.systemActionLinks.reboot) + .then(() => { + this.$store.commit("resetState"); + }) + .catch(error => { + this.modalError(error); // Let mixin handle error + }); + } + }, + () => {} + ); } } };