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 item.tier_type?.toLowerCase() === TIER_TYPE.CLOUD_TIER
131 ? TIER_TYPE_DISPLAY.CLOUD_TIER
132 : item.tier_type?.toLowerCase() === TIER_TYPE.LOCAL
133 ? TIER_TYPE_DISPLAY.LOCAL
136 this.transformTierData(tierConfig);
137 this.storageClassList.push(...tierConfig);
147 transformTierData(tierConfig: any[]) {
148 tierConfig.forEach((item, index) => {
149 const zone_group = item?.zone_group;
150 const storageClass = item?.storage_class;
151 const uniqueId = `${zone_group}-${storageClass}-${index}`;
152 item.uniqueId = uniqueId;
157 removeStorageClassModal() {
158 const storage_class = this.selection.first().storage_class;
159 const placement_target = this.selection.first().placement_target;
160 this.cdsModalService.show(DeleteConfirmationModalComponent, {
161 itemDescription: $localize`Tiering Storage Class`,
162 itemNames: [storage_class],
163 actionDescription: 'remove',
164 submitActionObservable: () =>
165 this.taskWrapper.wrapTaskAroundCall({
166 task: new FinishedTask('rgw/zonegroup/storage-class', {
167 placement_target: placement_target,
168 storage_class: storage_class
170 call: this.rgwStorageClassService.removeStorageClass(placement_target, storage_class)
175 updateSelection(selection: CdTableSelection) {
176 this.selection = selection;
179 setExpandedRow(expandedRow: any) {
180 super.setExpandedRow(expandedRow);