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 { RgwZonegroupService } from '~/app/shared/api/rgw-zonegroup.service';
7 import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
8 import { NotificationType } from '~/app/shared/enum/notification-type.enum';
9 import { CdFormGroup } from '~/app/shared/forms/cd-form-group';
10 import { NotificationService } from '~/app/shared/services/notification.service';
13 selector: 'cd-rgw-multisite-zonegroup-deletion-form',
14 templateUrl: './rgw-multisite-zonegroup-deletion-form.component.html',
15 styleUrls: ['./rgw-multisite-zonegroup-deletion-form.component.scss']
17 export class RgwMultisiteZonegroupDeletionFormComponent implements OnInit, AfterViewInit {
20 zonesPools: Array<any> = [];
22 zonesList: Array<any> = [];
23 zonegroupForm: CdFormGroup;
24 displayText: boolean = false;
25 includedPools: Set<string> = new Set<string>();
28 public activeModal: NgbActiveModal,
29 public actionLabels: ActionLabelsI18n,
30 public notificationService: NotificationService,
31 private rgwZonegroupService: RgwZonegroupService,
32 private poolService: PoolService,
33 private rgwZoneService: RgwZoneService
39 this.zonegroupData$ = this.rgwZonegroupService.get(this.zonegroup);
40 this.poolList$ = this.poolService.getList();
43 ngAfterViewInit(): void {
44 this.updateIncludedPools();
48 this.zonegroupForm = new CdFormGroup({
49 deletePools: new UntypedFormControl(false)
54 this.rgwZonegroupService
55 .delete(this.zonegroup.name, this.zonegroupForm.value.deletePools, this.includedPools)
57 this.notificationService.show(
58 NotificationType.success,
59 $localize`Zone: '${this.zonegroup.name}' deleted successfully`
61 this.activeModal.close();
66 if (this.includedPools.size > 0) {
67 this.displayText = !this.displayText;
71 updateIncludedPools(): void {
72 if (!this.zonegroupData$ || !this.poolList$) {
76 this.zonegroupData$.subscribe((zgData: any) => {
77 for (const zone of zgData.zones) {
78 this.zonesList.push(zone.name);
79 this.rgwZoneService.get(zone).subscribe((zonesPools: any) => {
80 this.poolList$.subscribe((poolList: any) => {
81 for (const zonePool of Object.values(zonesPools)) {
82 for (const pool of poolList) {
83 if (typeof zonePool === 'string' && zonePool.includes(pool.pool_name)) {
84 this.includedPools.add(pool.pool_name);
85 } else if (Array.isArray(zonePool) && zonePool[0].val) {
86 for (const item of zonePool) {
88 if (val.storage_classes.STANDARD.data_pool === pool.pool_name) {
89 this.includedPools.add(val.storage_classes.STANDARD.data_pool);
91 if (val.data_extra_pool === pool.pool_name) {
92 this.includedPools.add(val.data_extra_pool);
94 if (val.index_pool === pool.pool_name) {
95 this.includedPools.add(val.index_pool);