Skip to content

Commit

Permalink
NAS-131403: Add restart action to installed apps
Browse files Browse the repository at this point in the history
  • Loading branch information
denysbutenko committed Sep 30, 2024
1 parent d68b879 commit 40362a6
Show file tree
Hide file tree
Showing 95 changed files with 235 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@
<ix-icon name="mdi-play"></ix-icon>
</button>
} @else {
<button
mat-icon-button
matTooltipPosition="above"
[ixTest]="[app().name, 'restart']"
[attr.aria-label]="'Restart App' | translate"
[matTooltip]="'Restart App' | translate"
[disabled]="!inProgress()"
(click)="restart()"
>
<ix-icon name="mdi-restart"></ix-icon>
</button>

<button
mat-icon-button
matTooltipPosition="above"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ describe('AppRowComponent', () => {

const stopIcon = await loader.getHarness(IxIconHarness.with({ name: 'mdi-stop' }));
const startIcon = await loader.getHarnessOrNull(IxIconHarness.with({ name: 'mdi-play' }));
const restartIcon = await loader.getHarnessOrNull(IxIconHarness.with({ name: 'mdi-restart' }));

expect(stopIcon).toExist();
expect(restartIcon).toExist();
expect(startIcon).not.toExist();
});

Expand All @@ -114,7 +116,9 @@ describe('AppRowComponent', () => {

const stopIcon = await loader.getHarnessOrNull(IxIconHarness.with({ name: 'mdi-stop' }));
const startIcon = await loader.getHarness(IxIconHarness.with({ name: 'mdi-play' }));
const restartIcon = await loader.getHarnessOrNull(IxIconHarness.with({ name: 'mdi-restart' }));

expect(restartIcon).not.toExist();
expect(stopIcon).not.toExist();
expect(startIcon).toExist();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class AppRowComponent {

readonly startApp = output();
readonly stopApp = output();
readonly restartApp = output();
readonly clickStatus = output();
readonly selectionChange = output();

Expand Down Expand Up @@ -60,6 +61,10 @@ export class AppRowComponent {
this.stopApp.emit();
}

restart(): void {
this.restartApp.emit();
}

statusPressed(): void {
this.clickStatus.emit();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ <h2>{{ 'Applications' | translate }}</h2>
[job]="appJobs.get(app.name)"
(startApp)="start(app.name)"
(stopApp)="stop(app.name)"
(restartApp)="restart(app.name)"
(clickStatus)="openStatusDialog(app.name)"
(selectionChange)="selection.toggle(app.id)"
(click)="viewDetails(app)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ describe('InstalledAppsComponent', () => {
events: of(),
}),
mockProvider(ApplicationsService, {
restartApplication: jest.fn(() => of()),
startApplication: jest.fn(() => of()),
stopApplication: jest.fn(() => of()),
getInstalledAppsStatusUpdates: jest.fn(() => of({
Expand Down Expand Up @@ -135,4 +136,9 @@ describe('InstalledAppsComponent', () => {
spectator.query(AppRowComponent).stopApp.emit();
expect(spectator.inject(ApplicationsService).stopApplication).toHaveBeenCalledWith('test-app');
});

it('restarts application', () => {
spectator.query(AppRowComponent).restartApp.emit();
expect(spectator.inject(ApplicationsService).restartApplication).toHaveBeenCalledWith('test-app');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,11 @@ export class InstalledAppsComponent implements OnInit, AfterViewInit {

start(name: string): void {
this.appService.startApplication(name)
.pipe(this.errorHandler.catchError(), untilDestroyed(this))
.pipe(
tapOnce(() => this.loader.open(this.translate.instant('Starting "{app}"', { app: name }))),
this.errorHandler.catchError(),
untilDestroyed(this),
)
.subscribe((job: Job<void, AppStartQueryParams>) => {
this.appJobs.set(name, job);
this.sortChanged(this.sortingInfo);
Expand All @@ -336,6 +340,20 @@ export class InstalledAppsComponent implements OnInit, AfterViewInit {
});
}

restart(name: string): void {
this.appService.restartApplication(name)
.pipe(
tapOnce(() => this.loader.open(this.translate.instant('Restarting "{app}"', { app: name }))),
this.errorHandler.catchError(),
untilDestroyed(this),
)
.subscribe((job: Job<void, AppStartQueryParams>) => {
this.appJobs.set(name, job);
this.sortChanged(this.sortingInfo);
this.cdr.markForCheck();
});
}

openStatusDialog(name: string): void {
if (!this.appJobs.has(name)) {
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import {
Component, ChangeDetectionStrategy, input,
signal,
computed,
} from '@angular/core';
import { Router } from '@angular/router';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { TranslateService } from '@ngx-translate/core';
import { AppState } from 'app/enums/app-state.enum';
import { tapOnce } from 'app/helpers/operators/tap-once.operator';
import { LoadingState } from 'app/helpers/operators/to-loading-state.helper';
import { App } from 'app/interfaces/app.interface';
import { mapLoadedValue } from 'app/modules/loader/directives/with-loading-state/map-loaded-value.utils';
import { SnackbarService } from 'app/modules/snackbar/services/snackbar.service';
import { ApplicationsService } from 'app/pages/apps/services/applications.service';
import { RedirectService } from 'app/services/redirect.service';
Expand All @@ -21,7 +24,9 @@ import { RedirectService } from 'app/services/redirect.service';
export class AppControlsComponent {
app = input.required<LoadingState<App>>();

protected isRestarting = signal<boolean>(false);
protected isRestarting = computed(() => {
return mapLoadedValue(this.app(), (app) => app.state === AppState.Deploying);
});

constructor(
private translate: TranslateService,
Expand All @@ -32,15 +37,13 @@ export class AppControlsComponent {
) {}

onRestartApp(app: App): void {
this.isRestarting.set(true);
this.snackbar.success(this.translate.instant('App is restarting'));
this.appService.restartApplication(app.name)
.pipe(untilDestroyed(this))
.pipe(
tapOnce(() => this.snackbar.success(this.translate.instant('App is restarting'))),
untilDestroyed(this),
)
.subscribe({
complete: () => {
this.isRestarting.set(false);
this.snackbar.success(this.translate.instant('App is restarted'));
},
complete: () => this.snackbar.success(this.translate.instant('App is restarted')),
});
}

Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/af.json
Original file line number Diff line number Diff line change
Expand Up @@ -3377,6 +3377,7 @@
"Restart is required after changing this setting.": "",
"Restart of a remote system is required for new FIPS setting to take effect. Would you like to restart standby now?": "",
"Restart the system?": "",
"Restarting \"{app}\"": "",
"Restarting Standby": "",
"Restore": "",
"Restore Cloud Sync Task": "",
Expand Down Expand Up @@ -4053,6 +4054,7 @@
"Start {service} Service": "",
"Started": "",
"Starting": "",
"Starting \"{app}\"": "",
"Starting task": "",
"State": "",
"Static IP addresses which SMB listens on for connections. Leaving all unselected defaults to listening on all active interfaces.": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -3377,6 +3377,7 @@
"Restart is required after changing this setting.": "",
"Restart of a remote system is required for new FIPS setting to take effect. Would you like to restart standby now?": "",
"Restart the system?": "",
"Restarting \"{app}\"": "",
"Restarting Standby": "",
"Restore": "",
"Restore Cloud Sync Task": "",
Expand Down Expand Up @@ -4053,6 +4054,7 @@
"Start {service} Service": "",
"Started": "",
"Starting": "",
"Starting \"{app}\"": "",
"Starting task": "",
"State": "",
"Static IP addresses which SMB listens on for connections. Leaving all unselected defaults to listening on all active interfaces.": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/ast.json
Original file line number Diff line number Diff line change
Expand Up @@ -3377,6 +3377,7 @@
"Restart is required after changing this setting.": "",
"Restart of a remote system is required for new FIPS setting to take effect. Would you like to restart standby now?": "",
"Restart the system?": "",
"Restarting \"{app}\"": "",
"Restarting Standby": "",
"Restore": "",
"Restore Cloud Sync Task": "",
Expand Down Expand Up @@ -4053,6 +4054,7 @@
"Start {service} Service": "",
"Started": "",
"Starting": "",
"Starting \"{app}\"": "",
"Starting task": "",
"State": "",
"Static IP addresses which SMB listens on for connections. Leaving all unselected defaults to listening on all active interfaces.": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/az.json
Original file line number Diff line number Diff line change
Expand Up @@ -3377,6 +3377,7 @@
"Restart is required after changing this setting.": "",
"Restart of a remote system is required for new FIPS setting to take effect. Would you like to restart standby now?": "",
"Restart the system?": "",
"Restarting \"{app}\"": "",
"Restarting Standby": "",
"Restore": "",
"Restore Cloud Sync Task": "",
Expand Down Expand Up @@ -4053,6 +4054,7 @@
"Start {service} Service": "",
"Started": "",
"Starting": "",
"Starting \"{app}\"": "",
"Starting task": "",
"State": "",
"Static IP addresses which SMB listens on for connections. Leaving all unselected defaults to listening on all active interfaces.": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/be.json
Original file line number Diff line number Diff line change
Expand Up @@ -3377,6 +3377,7 @@
"Restart is required after changing this setting.": "",
"Restart of a remote system is required for new FIPS setting to take effect. Would you like to restart standby now?": "",
"Restart the system?": "",
"Restarting \"{app}\"": "",
"Restarting Standby": "",
"Restore": "",
"Restore Cloud Sync Task": "",
Expand Down Expand Up @@ -4053,6 +4054,7 @@
"Start {service} Service": "",
"Started": "",
"Starting": "",
"Starting \"{app}\"": "",
"Starting task": "",
"State": "",
"Static IP addresses which SMB listens on for connections. Leaving all unselected defaults to listening on all active interfaces.": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/bg.json
Original file line number Diff line number Diff line change
Expand Up @@ -3377,6 +3377,7 @@
"Restart is required after changing this setting.": "",
"Restart of a remote system is required for new FIPS setting to take effect. Would you like to restart standby now?": "",
"Restart the system?": "",
"Restarting \"{app}\"": "",
"Restarting Standby": "",
"Restore": "",
"Restore Cloud Sync Task": "",
Expand Down Expand Up @@ -4053,6 +4054,7 @@
"Start {service} Service": "",
"Started": "",
"Starting": "",
"Starting \"{app}\"": "",
"Starting task": "",
"State": "",
"Static IP addresses which SMB listens on for connections. Leaving all unselected defaults to listening on all active interfaces.": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/bn.json
Original file line number Diff line number Diff line change
Expand Up @@ -3377,6 +3377,7 @@
"Restart is required after changing this setting.": "",
"Restart of a remote system is required for new FIPS setting to take effect. Would you like to restart standby now?": "",
"Restart the system?": "",
"Restarting \"{app}\"": "",
"Restarting Standby": "",
"Restore": "",
"Restore Cloud Sync Task": "",
Expand Down Expand Up @@ -4053,6 +4054,7 @@
"Start {service} Service": "",
"Started": "",
"Starting": "",
"Starting \"{app}\"": "",
"Starting task": "",
"State": "",
"Static IP addresses which SMB listens on for connections. Leaving all unselected defaults to listening on all active interfaces.": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/br.json
Original file line number Diff line number Diff line change
Expand Up @@ -3377,6 +3377,7 @@
"Restart is required after changing this setting.": "",
"Restart of a remote system is required for new FIPS setting to take effect. Would you like to restart standby now?": "",
"Restart the system?": "",
"Restarting \"{app}\"": "",
"Restarting Standby": "",
"Restore": "",
"Restore Cloud Sync Task": "",
Expand Down Expand Up @@ -4053,6 +4054,7 @@
"Start {service} Service": "",
"Started": "",
"Starting": "",
"Starting \"{app}\"": "",
"Starting task": "",
"State": "",
"Static IP addresses which SMB listens on for connections. Leaving all unselected defaults to listening on all active interfaces.": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/bs.json
Original file line number Diff line number Diff line change
Expand Up @@ -3377,6 +3377,7 @@
"Restart is required after changing this setting.": "",
"Restart of a remote system is required for new FIPS setting to take effect. Would you like to restart standby now?": "",
"Restart the system?": "",
"Restarting \"{app}\"": "",
"Restarting Standby": "",
"Restore": "",
"Restore Cloud Sync Task": "",
Expand Down Expand Up @@ -4053,6 +4054,7 @@
"Start {service} Service": "",
"Started": "",
"Starting": "",
"Starting \"{app}\"": "",
"Starting task": "",
"State": "",
"Static IP addresses which SMB listens on for connections. Leaving all unselected defaults to listening on all active interfaces.": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -3377,6 +3377,7 @@
"Restart is required after changing this setting.": "",
"Restart of a remote system is required for new FIPS setting to take effect. Would you like to restart standby now?": "",
"Restart the system?": "",
"Restarting \"{app}\"": "",
"Restarting Standby": "",
"Restore": "",
"Restore Cloud Sync Task": "",
Expand Down Expand Up @@ -4053,6 +4054,7 @@
"Start {service} Service": "",
"Started": "",
"Starting": "",
"Starting \"{app}\"": "",
"Starting task": "",
"State": "",
"Static IP addresses which SMB listens on for connections. Leaving all unselected defaults to listening on all active interfaces.": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -2775,6 +2775,7 @@
"Restart is recommended for new FIPS setting to take effect. Would you like to restart now?": "",
"Restart is required after changing this setting.": "",
"Restart of a remote system is required for new FIPS setting to take effect. Would you like to restart standby now?": "",
"Restarting \"{app}\"": "",
"Restarting Standby": "",
"Restore": "",
"Restore Cloud Sync Task": "",
Expand Down Expand Up @@ -3403,6 +3404,7 @@
"Start {service} Service": "",
"Started": "",
"Starting": "",
"Starting \"{app}\"": "",
"Starting task": "",
"Static IP addresses which SMB listens on for connections. Leaving all unselected defaults to listening on all active interfaces.": "",
"Static IPv4 address of the IPMI web interface.": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/cy.json
Original file line number Diff line number Diff line change
Expand Up @@ -3377,6 +3377,7 @@
"Restart is required after changing this setting.": "",
"Restart of a remote system is required for new FIPS setting to take effect. Would you like to restart standby now?": "",
"Restart the system?": "",
"Restarting \"{app}\"": "",
"Restarting Standby": "",
"Restore": "",
"Restore Cloud Sync Task": "",
Expand Down Expand Up @@ -4053,6 +4054,7 @@
"Start {service} Service": "",
"Started": "",
"Starting": "",
"Starting \"{app}\"": "",
"Starting task": "",
"State": "",
"Static IP addresses which SMB listens on for connections. Leaving all unselected defaults to listening on all active interfaces.": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/da.json
Original file line number Diff line number Diff line change
Expand Up @@ -3377,6 +3377,7 @@
"Restart is required after changing this setting.": "",
"Restart of a remote system is required for new FIPS setting to take effect. Would you like to restart standby now?": "",
"Restart the system?": "",
"Restarting \"{app}\"": "",
"Restarting Standby": "",
"Restore": "",
"Restore Cloud Sync Task": "",
Expand Down Expand Up @@ -4053,6 +4054,7 @@
"Start {service} Service": "",
"Started": "",
"Starting": "",
"Starting \"{app}\"": "",
"Starting task": "",
"State": "",
"Static IP addresses which SMB listens on for connections. Leaving all unselected defaults to listening on all active interfaces.": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -2397,6 +2397,7 @@
"Restart is recommended for new FIPS setting to take effect. Would you like to restart now?": "",
"Restart is required after changing this setting.": "",
"Restart of a remote system is required for new FIPS setting to take effect. Would you like to restart standby now?": "",
"Restarting \"{app}\"": "",
"Restarting Standby": "",
"Restore Config": "",
"Restore Config Defaults": "",
Expand Down Expand Up @@ -2876,6 +2877,7 @@
"Start {service} Service": "",
"Started": "",
"Starting": "",
"Starting \"{app}\"": "",
"Starting task": "",
"Static IP addresses which SMB listens on for connections. Leaving all unselected defaults to listening on all active interfaces.": "",
"Static IPv4 address of the IPMI web interface.": "",
Expand Down
Loading

0 comments on commit 40362a6

Please sign in to comment.