1 import { Component, OnInit } from '@angular/core';
2 import { FormControl, Validators } from '@angular/forms';
3 import { Observable } from 'rxjs';
5 import { Icons } from '~/app/shared/enum/icons.enum';
6 import { Permission } from '~/app/shared/models/permissions';
7 import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
8 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
9 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
10 import { UpgradeService } from '~/app/shared/api/upgrade.service';
11 import { UpgradeInfoInterface } from '~/app/shared/models/upgrade.interface';
12 import { NotificationType } from '~/app/shared/enum/notification-type.enum';
13 import { CdFormGroup } from '~/app/shared/forms/cd-form-group';
14 import { NotificationService } from '~/app/shared/services/notification.service';
17 selector: 'cd-upgrade-start-modal.component',
18 templateUrl: './upgrade-start-modal.component.html',
19 styleUrls: ['./upgrade-start-modal.component.scss']
21 export class UpgradeStartModalComponent implements OnInit {
22 permission: Permission;
23 upgradeInfoError$: Observable<any>;
24 upgradeInfo$: Observable<UpgradeInfoInterface>;
25 upgradeForm: CdFormGroup;
30 public actionLabels: ActionLabelsI18n,
31 private authStorageService: AuthStorageService,
32 public activeModal: NgbActiveModal,
33 private upgradeService: UpgradeService,
34 private notificationService: NotificationService
36 this.permission = this.authStorageService.getPermissions().configOpt;
40 this.upgradeForm = new CdFormGroup({
41 availableVersions: new FormControl(null, [Validators.required])
46 this.upgradeService.start(this.upgradeForm.getValue('availableVersions')).subscribe({
48 this.notificationService.show(
49 NotificationType.success,
50 $localize`Started upgrading the cluster`
54 this.upgradeForm.setErrors({ cdSubmitButton: true });
55 this.notificationService.show(
56 NotificationType.error,
57 $localize`Failed to start the upgrade`,
62 this.activeModal.close();