Skip to content

Commit

Permalink
add shutdown UI from senyoret PR
Browse files Browse the repository at this point in the history
  • Loading branch information
mrpalide committed Nov 2, 2023
1 parent a99b2a6 commit c7748aa
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class NodeActionsHelper {
returnButtonText: string;

private updateSubscription: Subscription;
private shutdownSubscription: Subscription;

// Services this class need.
private dialog: MatDialog;
Expand Down Expand Up @@ -70,6 +71,12 @@ export class NodeActionsHelper {
});
}

this.options.push({
name: 'actions.menu.turn-off',
actionName: 'shutdown',
icon: 'power_settings_new'
});

this.options.push({
name: 'actions.menu.logs',
actionName: 'logs',
Expand Down Expand Up @@ -122,6 +129,8 @@ export class NodeActionsHelper {
this.terminal();
} else if (actionName === 'update') {
this.update();
} else if (actionName === 'shutdown') {
this.shutdown();
} else if (actionName === 'logs') {
this.runtimeLogs();
} else if (actionName === null) {
Expand All @@ -137,6 +146,28 @@ export class NodeActionsHelper {
if (this.updateSubscription) {
this.updateSubscription.unsubscribe();
}
if (this.shutdownSubscription) {
this.shutdownSubscription.unsubscribe();
}
}

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() {
Expand Down
7 changes: 7 additions & 0 deletions static/skywire-manager-src/src/app/services/node.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,13 @@ export class NodeService {
return this.apiService.delete(`visors/${nodeKey}/reward`);
}

/**
* Turns off a node.
*/
shutdown(nodeKey: string): Observable<any> {
return this.apiService.post(`visors/${nodeKey}/shutdown`);
}

/**
* Checks if a node is currently being updated.
*/
Expand Down
5 changes: 5 additions & 0 deletions static/skywire-manager-src/src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,16 @@
"terminal": "Terminal",
"config": "Configuration",
"update": "Update",
"turn-off": "Turn off",
"logs": "View logs"
},
"update": {
"confirmation": "A terminal will be opened in a new tab and the update procedure will be started automatically. Do you want to continue?"
},
"turn-off": {
"confirmation": "Are you sure you want to turn off the visor?",
"done": "The visor is shutting down."
},
"terminal-options": {
"full": "Full terminal",
"simple": "Simple terminal"
Expand Down
5 changes: 5 additions & 0 deletions static/skywire-manager-src/src/assets/i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,16 @@
"terminal": "Terminal",
"config": "Configuración",
"update": "Actualizar",
"turn-off": "Apagar",
"logs": "Ver logs"
},
"update": {
"confirmation": "Una terminal será abierta en una nueva pestaña y el proceso de actualización iniciará automáticamente. ¿Desea continuar?"
},
"turn-off": {
"confirmation": "¿Seguro que desea apagar el visor?",
"done": "El visor se está apagando."
},
"terminal-options": {
"full": "Terminal completa",
"simple": "Terminal simple"
Expand Down
5 changes: 5 additions & 0 deletions static/skywire-manager-src/src/assets/i18n/es_base.json
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,16 @@
"terminal": "Terminal",
"config": "Configuration",
"update": "Update",
"turn-off": "Turn off",
"logs": "View logs"
},
"update": {
"confirmation": "A terminal will be opened in a new tab and the update procedure will be started automatically. Do you want to continue?"
},
"turn-off": {
"confirmation": "Are you sure you want to turn off the visor?",
"done": "The visor is shutting down."
},
"terminal-options": {
"full": "Full terminal",
"simple": "Simple terminal"
Expand Down

0 comments on commit c7748aa

Please sign in to comment.