]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
3e146ef7ad53434cfa387199a953d1a085a58956
[ceph.git] /
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';
11
12 @Component({
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']
16 })
17 export class RgwMultisiteZonegroupDeletionFormComponent implements OnInit, AfterViewInit {
18   zonegroupData$: any;
19   poolList$: any;
20   zonesPools: Array<any> = [];
21   zonegroup: any;
22   zonesList: Array<any> = [];
23   zonegroupForm: CdFormGroup;
24   displayText: boolean = false;
25   includedPools: Set<string> = new Set<string>();
26
27   constructor(
28     public activeModal: NgbActiveModal,
29     public actionLabels: ActionLabelsI18n,
30     public notificationService: NotificationService,
31     private rgwZonegroupService: RgwZonegroupService,
32     private poolService: PoolService,
33     private rgwZoneService: RgwZoneService
34   ) {
35     this.createForm();
36   }
37
38   ngOnInit(): void {
39     this.zonegroupData$ = this.rgwZonegroupService.get(this.zonegroup);
40     this.poolList$ = this.poolService.getList();
41   }
42
43   ngAfterViewInit(): void {
44     this.updateIncludedPools();
45   }
46
47   createForm() {
48     this.zonegroupForm = new CdFormGroup({
49       deletePools: new UntypedFormControl(false)
50     });
51   }
52
53   submit() {
54     this.rgwZonegroupService
55       .delete(this.zonegroup.name, this.zonegroupForm.value.deletePools, this.includedPools)
56       .subscribe(() => {
57         this.notificationService.show(
58           NotificationType.success,
59           $localize`Zone: '${this.zonegroup.name}' deleted successfully`
60         );
61         this.activeModal.close();
62       });
63   }
64
65   showDangerText() {
66     if (this.includedPools.size > 0) {
67       this.displayText = !this.displayText;
68     }
69   }
70
71   updateIncludedPools(): void {
72     if (!this.zonegroupData$ || !this.poolList$) {
73       return;
74     }
75
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) {
87                     const val = item.val;
88                     if (val.storage_classes.STANDARD.data_pool === pool.pool_name) {
89                       this.includedPools.add(val.storage_classes.STANDARD.data_pool);
90                     }
91                     if (val.data_extra_pool === pool.pool_name) {
92                       this.includedPools.add(val.data_extra_pool);
93                     }
94                     if (val.index_pool === pool.pool_name) {
95                       this.includedPools.add(val.index_pool);
96                     }
97                   }
98                 }
99               }
100             }
101           });
102         });
103       }
104     });
105   }
106 }