1 import { Component, OnDestroy, OnInit } from '@angular/core';
3 import { Observable, ReplaySubject, Subscription } from 'rxjs';
4 import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
6 import { Icons } from '~/app/shared/enum/icons.enum';
7 import { CriticalConfirmationModalComponent } from '~/app/shared/components/critical-confirmation-modal/critical-confirmation-modal.component';
8 import { ModalCdsService } from '~/app/shared/services/modal-cds.service';
9 import { Permission } from '~/app/shared/models/permissions';
10 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
11 import { UpgradeService } from '~/app/shared/api/upgrade.service';
12 import { NotificationService } from '~/app/shared/services/notification.service';
13 import { NotificationType } from '~/app/shared/enum/notification-type.enum';
14 import { SummaryService } from '~/app/shared/services/summary.service';
15 import { ExecutingTask } from '~/app/shared/models/executing-task';
16 import { shareReplay, switchMap, tap } from 'rxjs/operators';
17 import { Router } from '@angular/router';
18 import { RefreshIntervalService } from '~/app/shared/services/refresh-interval.service';
19 import { UpgradeStatusInterface } from '~/app/shared/models/upgrade.interface';
22 selector: 'cd-upgrade-progress',
23 templateUrl: './upgrade-progress.component.html',
24 styleUrls: ['./upgrade-progress.component.scss']
26 export class UpgradeProgressComponent implements OnInit, OnDestroy {
27 permission: Permission;
29 modalRef: NgbModalRef;
30 interval = new Subscription();
31 executingTask: ExecutingTask;
33 upgradeStatus$: Observable<UpgradeStatusInterface>;
34 subject = new ReplaySubject<UpgradeStatusInterface>();
37 private authStorageService: AuthStorageService,
38 private upgradeService: UpgradeService,
39 private notificationService: NotificationService,
40 private modalService: ModalCdsService,
41 private summaryService: SummaryService,
42 private router: Router,
43 private refreshIntervalService: RefreshIntervalService
45 this.permission = this.authStorageService.getPermissions().configOpt;
49 this.upgradeStatus$ = this.subject.pipe(
50 switchMap(() => this.upgradeService.status()),
51 tap((status: UpgradeStatusInterface) => {
52 if (!status.in_progress) {
53 this.router.navigate(['/upgrade']);
59 this.interval = this.refreshIntervalService.intervalData$.subscribe(() => {
63 this.summaryService.subscribe((summary) => {
64 this.executingTask = summary.executing_tasks.filter((tasks) =>
65 tasks.name.includes('progress/Upgrade')
71 this.upgradeService.pause().subscribe({
73 this.notificationService.show(
74 NotificationType.error,
75 $localize`Failed to pause the upgrade`,
80 this.notificationService.show(NotificationType.success, $localize`The upgrade is paused`);
90 resumeUpgrade(modal = false) {
91 this.upgradeService.resume().subscribe({
93 this.notificationService.show(
94 NotificationType.error,
95 $localize`Failed to resume the upgrade`,
101 this.notificationService.show(NotificationType.success, $localize`Upgrade is resumed`);
103 this.modalRef.close();
110 // pause the upgrade meanwhile we get stop confirmation from user
112 this.modalRef = this.modalService.show(CriticalConfirmationModalComponent, {
113 itemDescription: 'Upgrade',
114 actionDescription: 'stop',
115 submitAction: () => this.stopUpgrade(),
116 callBackAtionObservable: () => this.resumeUpgrade(true)
121 this.modalRef.close();
122 this.upgradeService.stop().subscribe({
124 this.notificationService.show(
125 NotificationType.error,
126 $localize`Failed to stop the upgrade`,
131 this.notificationService.show(NotificationType.success, $localize`The upgrade is stopped`);
132 this.router.navigate(['/upgrade']);
138 this.interval?.unsubscribe();