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';
6 import { ListWithDetails } from '~/app/shared/classes/list-with-details.class';
12 } from '../models/rgw-storage-class.model';
13 import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
14 import { FinishedTask } from '~/app/shared/models/finished-task';
15 import { Icons } from '~/app/shared/enum/icons.enum';
16 import { RgwZonegroupService } from '~/app/shared/api/rgw-zonegroup.service';
17 import { DeleteConfirmationModalComponent } from '~/app/shared/components/delete-confirmation-modal/delete-confirmation-modal.component';
18 import { ModalCdsService } from '~/app/shared/services/modal-cds.service';
19 import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
20 import { RgwStorageClassService } from '~/app/shared/api/rgw-storage-class.service';
21 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
22 import { URLBuilderService } from '~/app/shared/services/url-builder.service';
23 import { Permission } from '~/app/shared/models/permissions';
24 import { BucketTieringUtils } from '../utils/rgw-bucket-tiering';
25 import { Router } from '@angular/router';
27 const BASE_URL = 'rgw/tiering';
29 selector: 'cd-rgw-storage-class-list',
30 templateUrl: './rgw-storage-class-list.component.html',
31 styleUrls: ['./rgw-storage-class-list.component.scss'],
32 providers: [{ provide: URLBuilderService, useValue: new URLBuilderService(BASE_URL) }]
34 export class RgwStorageClassListComponent extends ListWithDetails implements OnInit {
35 columns: CdTableColumn[];
36 selection = new CdTableSelection();
37 permission: Permission;
38 tableActions: CdTableAction[];
39 storageClassList: StorageClass[] = [];
42 private rgwZonegroupService: RgwZonegroupService,
43 public actionLabels: ActionLabelsI18n,
44 private cdsModalService: ModalCdsService,
45 private taskWrapper: TaskWrapperService,
46 private authStorageService: AuthStorageService,
47 private rgwStorageClassService: RgwStorageClassService,
48 private router: Router,
49 private urlBuilder: URLBuilderService
52 this.permission = this.authStorageService.getPermissions().rgw;
63 name: $localize`Storage Class`,
64 prop: 'storage_class',
68 name: $localize`Type`,
73 name: $localize`Zone Group`,
74 prop: 'zonegroup_name',
78 name: $localize`Placement Target`,
79 prop: 'placement_target',
83 name: $localize`Target Region`,
88 name: $localize`Target Endpoint`,
93 const getStorageUri = () =>
94 this.selection.first() &&
95 `${encodeURI(this.selection.first().zonegroup_name)}/${encodeURI(
96 this.selection.first().placement_target
97 )}/${encodeURI(this.selection.first().storage_class)}`;
100 name: this.actionLabels.CREATE,
101 permission: 'create',
103 click: () => this.router.navigate([this.urlBuilder.getCreate()]),
104 canBePrimary: (selection: CdTableSelection) => !selection.hasSelection
107 name: this.actionLabels.EDIT,
108 permission: 'update',
110 routerLink: () => [`/rgw/tiering/edit/${getStorageUri()}`]
113 name: this.actionLabels.REMOVE,
114 permission: 'delete',
116 click: () => this.removeStorageClassModal()
121 loadStorageClass(): Promise<void> {
122 return new Promise((resolve, reject) => {
123 this.rgwZonegroupService.getAllZonegroupsInfo().subscribe(
124 (data: ZoneGroupDetails) => {
125 this.storageClassList = [];
126 const tierObj = BucketTieringUtils.filterAndMapTierTargets(data);
127 const tierConfig = tierObj.map((item) => {
130 switch (item.tier_type?.toLowerCase()) {
131 case TIER_TYPE.CLOUD_TIER:
132 tierTypeDisplay = TIER_TYPE_DISPLAY.CLOUD_TIER;
134 case TIER_TYPE.LOCAL:
135 tierTypeDisplay = TIER_TYPE_DISPLAY.LOCAL;
137 case TIER_TYPE.GLACIER:
138 tierTypeDisplay = TIER_TYPE_DISPLAY.GLACIER;
141 tierTypeDisplay = item.tier_type;
145 tier_type: tierTypeDisplay
148 this.transformTierData(tierConfig);
149 this.storageClassList.push(...tierConfig);
159 transformTierData(tierConfig: any[]) {
160 tierConfig.forEach((item, index) => {
161 const zone_group = item?.zone_group;
162 const storageClass = item?.storage_class;
163 const uniqueId = `${zone_group}-${storageClass}-${index}`;
164 item.uniqueId = uniqueId;
169 removeStorageClassModal() {
170 const storage_class = this.selection.first().storage_class;
171 const placement_target = this.selection.first().placement_target;
172 this.cdsModalService.show(DeleteConfirmationModalComponent, {
173 itemDescription: $localize`Tiering Storage Class`,
174 itemNames: [storage_class],
175 actionDescription: 'remove',
176 submitActionObservable: () =>
177 this.taskWrapper.wrapTaskAroundCall({
178 task: new FinishedTask('rgw/zonegroup/storage-class', {
179 placement_target: placement_target,
180 storage_class: storage_class
182 call: this.rgwStorageClassService.removeStorageClass(placement_target, storage_class)
187 updateSelection(selection: CdTableSelection) {
188 this.selection = selection;
191 setExpandedRow(expandedRow: any) {
192 super.setExpandedRow(expandedRow);