From f860cacba9ae1f3a90e2a8cc4dcc62e6918005ab Mon Sep 17 00:00:00 2001 From: Senyoret1 <34079003+Senyoret1@users.noreply.github.com> Date: Mon, 3 Jul 2023 21:03:40 -0400 Subject: [PATCH] UI for turning off the visor --- .../pages/node/actions/node-actions-helper.ts | 31 +++++++++++++++++++ .../src/app/services/node.service.ts | 7 +++++ .../src/assets/i18n/en.json | 5 +++ .../src/assets/i18n/es.json | 5 +++ .../src/assets/i18n/es_base.json | 5 +++ 5 files changed, 53 insertions(+) diff --git a/static/skywire-manager-src/src/app/components/pages/node/actions/node-actions-helper.ts b/static/skywire-manager-src/src/app/components/pages/node/actions/node-actions-helper.ts index b57e44e88e..c813c98080 100644 --- a/static/skywire-manager-src/src/app/components/pages/node/actions/node-actions-helper.ts +++ b/static/skywire-manager-src/src/app/components/pages/node/actions/node-actions-helper.ts @@ -35,6 +35,7 @@ export class NodeActionsHelper { returnButtonText: string; private rebootSubscription: Subscription; + private shutdownSubscription: Subscription; private updateSubscription: Subscription; // Services this class need. @@ -84,6 +85,12 @@ export class NodeActionsHelper { actionName: 'reboot', icon: 'rotate_right' }); + + this.options.push({ + name: 'actions.menu.turn-off', + actionName: 'shutdown', + icon: 'power_settings_new' + }); } // TODO: remove if the option will not be added again. Delete the translatable strings too. @@ -138,6 +145,8 @@ export class NodeActionsHelper { this.runtimeLogs(); } else if (actionName === 'reboot') { this.reboot(); + } else if (actionName === 'shutdown') { + this.shutdown(); } else if (actionName === null) { // Null is returned if the back button was pressed. this.back(); @@ -151,6 +160,9 @@ export class NodeActionsHelper { if (this.rebootSubscription) { this.rebootSubscription.unsubscribe(); } + if (this.shutdownSubscription) { + this.shutdownSubscription.unsubscribe(); + } if (this.updateSubscription) { this.updateSubscription.unsubscribe(); } @@ -173,6 +185,25 @@ export class NodeActionsHelper { }); } + shutdown() { + const confirmationDialog = GeneralUtils.createConfirmationDialog(this.dialog, 'actions.turn-off.confirmation'); + + confirmationDialog.componentInstance.operationAccepted.subscribe(() => { + confirmationDialog.componentInstance.showProcessing(); + + this.shutdownSubscription = this.nodeService.shutdown(this.currentNodeKey).subscribe(() => { + this.snackbarService.showDone('actions.turn-off.done'); + confirmationDialog.close(); + + this.router.navigate(['nodes']); + }, (err: OperationError) => { + err = processServiceError(err); + + confirmationDialog.componentInstance.showDone('confirmation.error-header-text', err.translatableErrorMsg); + }); + }); + } + update() { const confirmationDialog = GeneralUtils.createConfirmationDialog(this.dialog, 'actions.update.confirmation'); diff --git a/static/skywire-manager-src/src/app/services/node.service.ts b/static/skywire-manager-src/src/app/services/node.service.ts index 2daca7966b..ec050fd545 100644 --- a/static/skywire-manager-src/src/app/services/node.service.ts +++ b/static/skywire-manager-src/src/app/services/node.service.ts @@ -353,6 +353,13 @@ export class NodeService { return this.apiService.post(`visors/${nodeKey}/restart`); } + /** + * Turns off a node. + */ + shutdown(nodeKey: string): Observable { + return this.apiService.post(`visors/${nodeKey}/shutdown`); + } + /** * Checks if a node is currently being updated. */ diff --git a/static/skywire-manager-src/src/assets/i18n/en.json b/static/skywire-manager-src/src/assets/i18n/en.json index 79aa6c8329..b4e240e1aa 100644 --- a/static/skywire-manager-src/src/assets/i18n/en.json +++ b/static/skywire-manager-src/src/assets/i18n/en.json @@ -337,12 +337,17 @@ "config": "Configuration", "update": "Update", "reboot": "Reboot", + "turn-off": "Turn off", "logs": "View logs" }, "reboot": { "confirmation": "Are you sure you want to reboot the visor?", "done": "The visor is restarting." }, + "turn-off": { + "confirmation": "Are you sure you want to turn off the visor?", + "done": "The visor is shutting down." + }, "update": { "confirmation": "A terminal will be opened in a new tab and the update procedure will be started automatically. Do you want to continue?" }, diff --git a/static/skywire-manager-src/src/assets/i18n/es.json b/static/skywire-manager-src/src/assets/i18n/es.json index 27dd44541f..5c07559235 100644 --- a/static/skywire-manager-src/src/assets/i18n/es.json +++ b/static/skywire-manager-src/src/assets/i18n/es.json @@ -341,12 +341,17 @@ "config": "Configuración", "update": "Actualizar", "reboot": "Reiniciar", + "turn-off": "Apagar", "logs": "Ver logs" }, "reboot": { "confirmation": "¿Seguro que desea reiniciar el visor?", "done": "El visor se está reiniciando." }, + "turn-off": { + "confirmation": "¿Seguro que desea apagar el visor?", + "done": "El visor se está apagando." + }, "update": { "confirmation": "Una terminal será abierta en una nueva pestaña y el proceso de actualización iniciará automáticamente. ¿Desea continuar?" }, diff --git a/static/skywire-manager-src/src/assets/i18n/es_base.json b/static/skywire-manager-src/src/assets/i18n/es_base.json index 8c853eda94..9b7b55b0ec 100644 --- a/static/skywire-manager-src/src/assets/i18n/es_base.json +++ b/static/skywire-manager-src/src/assets/i18n/es_base.json @@ -341,12 +341,17 @@ "config": "Configuration", "update": "Update", "reboot": "Reboot", + "turn-off": "Turn off", "logs": "View logs" }, "reboot": { "confirmation": "Are you sure you want to reboot the visor?", "done": "The visor is restarting." }, + "turn-off": { + "confirmation": "Are you sure you want to turn off the visor?", + "done": "The visor is shutting down." + }, "update": { "confirmation": "A terminal will be opened in a new tab and the update procedure will be started automatically. Do you want to continue?" },