1 import { AfterViewInit, Component, OnInit } from '@angular/core';
2 import { UntypedFormControl } from '@angular/forms';
3 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
4 import { PoolService } from '~/app/shared/api/pool.service';
5 import { RgwZoneService } from '~/app/shared/api/rgw-zone.service';
6 import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
7 import { NotificationType } from '~/app/shared/enum/notification-type.enum';
8 import { CdFormGroup } from '~/app/shared/forms/cd-form-group';
9 import { NotificationService } from '~/app/shared/services/notification.service';
12 selector: 'cd-rgw-multisite-zone-deletion-form',
13 templateUrl: './rgw-multisite-zone-deletion-form.component.html',
14 styleUrls: ['./rgw-multisite-zone-deletion-form.component.scss']
16 export class RgwMultisiteZoneDeletionFormComponent implements OnInit, AfterViewInit {
20 zoneForm: CdFormGroup;
21 displayText: boolean = false;
22 includedPools: Set<string> = new Set<string>();
25 public activeModal: NgbActiveModal,
26 public actionLabels: ActionLabelsI18n,
27 public notificationService: NotificationService,
28 private rgwZoneService: RgwZoneService,
29 private poolService: PoolService
35 this.zoneData$ = this.rgwZoneService.get(this.zone);
36 this.poolList$ = this.poolService.getList();
39 ngAfterViewInit(): void {
40 this.updateIncludedPools();
44 this.zoneForm = new CdFormGroup({
45 deletePools: new UntypedFormControl(false)
51 .delete(this.zone.name, this.zoneForm.value.deletePools, this.includedPools, this.zone.parent)
54 this.notificationService.show(
55 NotificationType.success,
56 $localize`Zone: '${this.zone.name}' deleted successfully`
58 this.activeModal.close();
61 this.zoneForm.setErrors({ cdSubmitButton: true });
67 this.displayText = !this.displayText;
70 updateIncludedPools(): void {
71 if (!this.zoneData$ || !this.poolList$) {
74 this.zoneData$.subscribe((data: any) => {
75 this.poolList$.subscribe((poolList: any) => {
76 for (const pool of poolList) {
77 for (const zonePool of Object.values(data)) {
78 if (typeof zonePool === 'string' && zonePool.includes(pool.pool_name)) {
79 this.includedPools.add(pool.pool_name);
80 } else if (Array.isArray(zonePool) && zonePool[0].val) {
81 for (const item of zonePool) {
83 if (val.storage_classes.STANDARD.data_pool === pool.pool_name) {
84 this.includedPools.add(val.storage_classes.STANDARD.data_pool);
86 if (val.data_extra_pool === pool.pool_name) {
87 this.includedPools.add(val.data_extra_pool);
89 if (val.index_pool === pool.pool_name) {
90 this.includedPools.add(val.index_pool);