]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/models/rgw-multisite-zone-deletion-form/rgw-multisite-zone-deletion-form.component.ts
update ceph source to reef 18.2.1
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / rgw / models / rgw-multisite-zone-deletion-form / rgw-multisite-zone-deletion-form.component.ts
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';
10
11 @Component({
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']
15 })
16 export class RgwMultisiteZoneDeletionFormComponent implements OnInit, AfterViewInit {
17 zoneData$: any;
18 poolList$: any;
19 zone: any;
20 zoneForm: CdFormGroup;
21 displayText: boolean = false;
22 includedPools: Set<string> = new Set<string>();
23
24 constructor(
25 public activeModal: NgbActiveModal,
26 public actionLabels: ActionLabelsI18n,
27 public notificationService: NotificationService,
28 private rgwZoneService: RgwZoneService,
29 private poolService: PoolService
30 ) {
31 this.createForm();
32 }
33
34 ngOnInit(): void {
35 this.zoneData$ = this.rgwZoneService.get(this.zone);
36 this.poolList$ = this.poolService.getList();
37 }
38
39 ngAfterViewInit(): void {
40 this.updateIncludedPools();
41 }
42
43 createForm() {
44 this.zoneForm = new CdFormGroup({
45 deletePools: new UntypedFormControl(false)
46 });
47 }
48
49 submit() {
50 this.rgwZoneService
51 .delete(this.zone.name, this.zoneForm.value.deletePools, this.includedPools, this.zone.parent)
52 .subscribe(
53 () => {
54 this.notificationService.show(
55 NotificationType.success,
56 $localize`Zone: '${this.zone.name}' deleted successfully`
57 );
58 this.activeModal.close();
59 },
60 () => {
61 this.zoneForm.setErrors({ cdSubmitButton: true });
62 }
63 );
64 }
65
66 showDangerText() {
67 this.displayText = !this.displayText;
68 }
69
70 updateIncludedPools(): void {
71 if (!this.zoneData$ || !this.poolList$) {
72 return;
73 }
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) {
82 const val = item.val;
83 if (val.storage_classes.STANDARD.data_pool === pool.pool_name) {
84 this.includedPools.add(val.storage_classes.STANDARD.data_pool);
85 }
86 if (val.data_extra_pool === pool.pool_name) {
87 this.includedPools.add(val.data_extra_pool);
88 }
89 if (val.index_pool === pool.pool_name) {
90 this.includedPools.add(val.index_pool);
91 }
92 }
93 }
94 }
95 }
96 });
97 });
98 }
99 }