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';
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';
21 import { Router } from '@angular/router';
23 const BASE_URL = 'rgw/tiering';
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) }]
30 export class RgwStorageClassListComponent extends ListWithDetails implements OnInit {
31 columns: CdTableColumn[];
32 selection = new CdTableSelection();
33 permission: Permission;
34 tableActions: CdTableAction[];
35 storageClassList: StorageClass[] = [];
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
48 this.permission = this.authStorageService.getPermissions().rgw;
54 name: $localize`Storage Class`,
55 prop: 'storage_class',
59 name: $localize`Zone Group`,
60 prop: 'zonegroup_name',
64 name: $localize`Placement Target`,
65 prop: 'placement_target',
69 name: $localize`Target Region`,
74 name: $localize`Target Endpoint`,
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)}`;
86 name: this.actionLabels.CREATE,
89 click: () => this.router.navigate([this.urlBuilder.getCreate()]),
90 canBePrimary: (selection: CdTableSelection) => !selection.hasSelection
93 name: this.actionLabels.EDIT,
96 routerLink: () => [`/rgw/tiering/edit/${getStorageUri()}`]
99 name: this.actionLabels.REMOVE,
100 permission: 'delete',
102 click: () => this.removeStorageClassModal()
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);
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
136 call: this.rgwStorageClassService.removeStorageClass(placement_target, storage_class)
141 updateSelection(selection: CdTableSelection) {
142 this.selection = selection;
145 setExpandedRow(expandedRow: any) {
146 super.setExpandedRow(expandedRow);