Skip to content

Commit

Permalink
NAS-131326: Add reboot reason
Browse files Browse the repository at this point in the history
  • Loading branch information
Boris Vasilenko committed Oct 9, 2024
1 parent 14193eb commit dbca167
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/app/interfaces/api/api-job-directory.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ export interface ApiJobDirectory {
'support.new_ticket': { params: [CreateNewTicket]; response: NewTicketResponse };

// System
'system.reboot': { params: { delay?: number }; response: void };
'system.shutdown': { params: { delay?: number }; response: void };
'system.reboot': { params: { delay?: number; reason: string }; response: void };
'system.shutdown': { params: { delay?: number; reason: string }; response: void };
'system.security.update': { params: [SystemSecurityConfig]; response: void };

// SystemDataset
Expand Down
7 changes: 5 additions & 2 deletions src/app/pages/system-tasks/reboot/reboot.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Location } from '@angular/common';
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { Router } from '@angular/router';
import { ActivatedRoute, Router } from '@angular/router';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { DialogService } from 'app/modules/dialog/dialog.service';
import { AppLoaderService } from 'app/modules/loader/app-loader.service';
Expand All @@ -21,6 +21,7 @@ export class RebootComponent implements OnInit {
protected ws: WebSocketService,
private wsManager: WebSocketConnectionService,
protected router: Router,
private route: ActivatedRoute,
private errorHandler: ErrorHandlerService,
protected loader: AppLoaderService,
protected dialogService: DialogService,
Expand All @@ -30,11 +31,13 @@ export class RebootComponent implements OnInit {
}

ngOnInit(): void {
const reason = this.route.snapshot.queryParamMap.get('reason') || 'Unknown Reason';

// Replace URL so that we don't reboot again if page is refreshed.
this.location.replaceState('/signin');

this.matDialog.closeAll();
this.ws.job('system.reboot').pipe(untilDestroyed(this)).subscribe({
this.ws.job('system.reboot', { reason }).pipe(untilDestroyed(this)).subscribe({
error: (error: unknown) => { // error on reboot
this.dialogService.error(this.errorHandler.parseError(error))
.pipe(untilDestroyed(this))
Expand Down
7 changes: 5 additions & 2 deletions src/app/pages/system-tasks/shutdown/shutdown.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Location } from '@angular/common';
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { ActivatedRoute, Router } from '@angular/router';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { DialogService } from 'app/modules/dialog/dialog.service';
import { ErrorHandlerService } from 'app/services/error-handler.service';
Expand All @@ -20,15 +20,18 @@ export class ShutdownComponent implements OnInit {
private wsManager: WebSocketConnectionService,
private errorHandler: ErrorHandlerService,
protected router: Router,
private route: ActivatedRoute,
protected dialogService: DialogService,
private location: Location,
) {}

ngOnInit(): void {
const reason = this.route.snapshot.queryParamMap.get('reason') || 'Unknown Reason';

// Replace URL so that we don't shutdown again if page is refreshed.
this.location.replaceState('/signin');

this.ws.job('system.shutdown', {}).pipe(untilDestroyed(this)).subscribe({
this.ws.job('system.shutdown', { reason }).pipe(untilDestroyed(this)).subscribe({
error: (error: unknown) => { // error on shutdown
this.dialogService.error(this.errorHandler.parseError(error))
.pipe(untilDestroyed(this))
Expand Down

0 comments on commit dbca167

Please sign in to comment.