]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
e36b8acae19609b12f4168127f88efa9ce125908
[ceph.git] /
1 import { Component, OnInit } from '@angular/core';
2 import { CdTableAction } from '~/app/shared/models/cd-table-action';
3 import { CdTableColumn } from '~/app/shared/models/cd-table-column';
4 import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
5
6 import { ListWithDetails } from '~/app/shared/classes/list-with-details.class';
7 import { StorageClass, ZoneGroupDetails } from '../models/rgw-storage-class.model';
8 import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
9 import { FinishedTask } from '~/app/shared/models/finished-task';
10 import { Icons } from '~/app/shared/enum/icons.enum';
11 import { RgwZonegroupService } from '~/app/shared/api/rgw-zonegroup.service';
12 import { DeleteConfirmationModalComponent } from '~/app/shared/components/delete-confirmation-modal/delete-confirmation-modal.component';
13 import { ModalCdsService } from '~/app/shared/services/modal-cds.service';
14 import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
15 import { RgwStorageClassService } from '~/app/shared/api/rgw-storage-class.service';
16 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
17 import { URLBuilderService } from '~/app/shared/services/url-builder.service';
18 import { Permission } from '~/app/shared/models/permissions';
19 import { BucketTieringUtils } from '../utils/rgw-bucket-tiering';
20
21 import { Router } from '@angular/router';
22
23 const BASE_URL = 'rgw/tiering';
24 @Component({
25   selector: 'cd-rgw-storage-class-list',
26   templateUrl: './rgw-storage-class-list.component.html',
27   styleUrls: ['./rgw-storage-class-list.component.scss'],
28   providers: [{ provide: URLBuilderService, useValue: new URLBuilderService(BASE_URL) }]
29 })
30 export class RgwStorageClassListComponent extends ListWithDetails implements OnInit {
31   columns: CdTableColumn[];
32   selection = new CdTableSelection();
33   permission: Permission;
34   tableActions: CdTableAction[];
35   storageClassList: StorageClass[] = [];
36
37   constructor(
38     private rgwZonegroupService: RgwZonegroupService,
39     public actionLabels: ActionLabelsI18n,
40     private cdsModalService: ModalCdsService,
41     private taskWrapper: TaskWrapperService,
42     private authStorageService: AuthStorageService,
43     private rgwStorageClassService: RgwStorageClassService,
44     private router: Router,
45     private urlBuilder: URLBuilderService
46   ) {
47     super();
48     this.permission = this.authStorageService.getPermissions().rgw;
49   }
50
51   ngOnInit() {
52     this.columns = [
53       {
54         name: $localize`Storage Class`,
55         prop: 'storage_class',
56         flexGrow: 2
57       },
58       {
59         name: $localize`Zone Group`,
60         prop: 'zonegroup_name',
61         flexGrow: 2
62       },
63       {
64         name: $localize`Placement Target`,
65         prop: 'placement_target',
66         flexGrow: 2
67       },
68       {
69         name: $localize`Target Region`,
70         prop: 'region',
71         flexGrow: 2
72       },
73       {
74         name: $localize`Target Endpoint`,
75         prop: 'endpoint',
76         flexGrow: 2
77       }
78     ];
79     const getStorageUri = () =>
80       this.selection.first() &&
81       `${encodeURI(this.selection.first().zonegroup_name)}/${encodeURI(
82         this.selection.first().placement_target
83       )}/${encodeURI(this.selection.first().storage_class)}`;
84     this.tableActions = [
85       {
86         name: this.actionLabels.CREATE,
87         permission: 'create',
88         icon: Icons.add,
89         click: () => this.router.navigate([this.urlBuilder.getCreate()]),
90         canBePrimary: (selection: CdTableSelection) => !selection.hasSelection
91       },
92       {
93         name: this.actionLabels.EDIT,
94         permission: 'update',
95         icon: Icons.edit,
96         routerLink: () => [`/rgw/tiering/edit/${getStorageUri()}`]
97       },
98       {
99         name: this.actionLabels.REMOVE,
100         permission: 'delete',
101         icon: Icons.destroy,
102         click: () => this.removeStorageClassModal()
103       }
104     ];
105   }
106
107   loadStorageClass(): Promise<void> {
108     return new Promise((resolve, reject) => {
109       this.rgwZonegroupService.getAllZonegroupsInfo().subscribe(
110         (data: ZoneGroupDetails) => {
111           this.storageClassList = [];
112           const tierObj = BucketTieringUtils.filterAndMapTierTargets(data);
113           this.storageClassList.push(...tierObj);
114           resolve();
115         },
116         (error) => {
117           reject(error);
118         }
119       );
120     });
121   }
122
123   removeStorageClassModal() {
124     const storage_class = this.selection.first().storage_class;
125     const placement_target = this.selection.first().placement_target;
126     this.cdsModalService.show(DeleteConfirmationModalComponent, {
127       itemDescription: $localize`Tiering Storage Class`,
128       itemNames: [storage_class],
129       actionDescription: 'remove',
130       submitActionObservable: () =>
131         this.taskWrapper.wrapTaskAroundCall({
132           task: new FinishedTask('rgw/zonegroup/storage-class', {
133             placement_target: placement_target,
134             storage_class: storage_class
135           }),
136           call: this.rgwStorageClassService.removeStorageClass(placement_target, storage_class)
137         })
138     });
139   }
140
141   updateSelection(selection: CdTableSelection) {
142     this.selection = selection;
143   }
144
145   setExpandedRow(expandedRow: any) {
146     super.setExpandedRow(expandedRow);
147   }
148 }