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';
14 } from '../models/rgw-storage-class.model';
15 import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
16 import { FinishedTask } from '~/app/shared/models/finished-task';
17 import { Icons } from '~/app/shared/enum/icons.enum';
18 import { CriticalConfirmationModalComponent } from '~/app/shared/components/critical-confirmation-modal/critical-confirmation-modal.component';
19 import { RgwZonegroupService } from '~/app/shared/api/rgw-zonegroup.service';
20 import { ModalCdsService } from '~/app/shared/services/modal-cds.service';
21 import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
22 import { RgwStorageClassService } from '~/app/shared/api/rgw-storage-class.service';
23 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
24 import { URLBuilderService } from '~/app/shared/services/url-builder.service';
25 import { Permission } from '~/app/shared/models/permissions';
27 import { Router } from '@angular/router';
29 const BASE_URL = 'rgw/tiering';
32 selector: 'cd-rgw-storage-class-list',
33 templateUrl: './rgw-storage-class-list.component.html',
34 styleUrls: ['./rgw-storage-class-list.component.scss'],
35 providers: [{ provide: URLBuilderService, useValue: new URLBuilderService(BASE_URL) }]
37 export class RgwStorageClassListComponent extends ListWithDetails implements OnInit {
38 columns: CdTableColumn[];
39 selection = new CdTableSelection();
40 permission: Permission;
41 tableActions: CdTableAction[];
42 storageClassList: StorageClass[] = [];
45 private rgwZonegroupService: RgwZonegroupService,
46 public actionLabels: ActionLabelsI18n,
47 private cdsModalService: ModalCdsService,
48 private taskWrapper: TaskWrapperService,
49 private authStorageService: AuthStorageService,
50 private rgwStorageClassService: RgwStorageClassService,
51 private router: Router,
52 private urlBuilder: URLBuilderService
55 this.permission = this.authStorageService.getPermissions().rgw;
61 name: $localize`Zone Group`,
62 prop: 'zonegroup_name',
66 name: $localize`Placement Target`,
67 prop: 'placement_target',
71 name: $localize`Storage Class`,
72 prop: 'storage_class',
76 name: $localize`Target Region`,
81 name: $localize`Target Endpoint`,
88 name: this.actionLabels.CREATE,
91 click: () => this.router.navigate([this.urlBuilder.getCreate()]),
92 canBePrimary: (selection: CdTableSelection) => !selection.hasSelection
95 name: this.actionLabels.REMOVE,
98 click: () => this.removeStorageClassModal()
103 loadStorageClass(): Promise<void> {
104 return new Promise((resolve, reject) => {
105 this.rgwZonegroupService.getAllZonegroupsInfo().subscribe(
106 (data: ZoneGroupDetails) => {
107 this.storageClassList = [];
109 const tierObj = data.zonegroups.flatMap((zoneGroup: ZoneGroup) =>
110 zoneGroup.placement_targets
111 .filter((target: Target) => target.tier_targets)
112 .flatMap((target: Target) =>
114 .filter((tierTarget: TierTarget) => tierTarget.val.tier_type === CLOUD_TIER)
115 .map((tierTarget: TierTarget) => {
116 return this.getTierTargets(tierTarget, zoneGroup.name, target.name);
120 this.storageClassList.push(...tierObj);
130 getTierTargets(tierTarget: TierTarget, zoneGroup: string, targetName: string) {
131 if (tierTarget.val.tier_type !== CLOUD_TIER) return null;
133 zonegroup_name: zoneGroup,
134 placement_target: targetName,
135 storage_class: tierTarget.val.storage_class,
140 removeStorageClassModal() {
141 const storage_class = this.selection.first().storage_class;
142 const placement_target = this.selection.first().placement_target;
143 this.cdsModalService.show(CriticalConfirmationModalComponent, {
144 itemDescription: $localize`Tiering Storage Class`,
145 itemNames: [storage_class],
146 actionDescription: 'remove',
147 submitActionObservable: () =>
148 this.taskWrapper.wrapTaskAroundCall({
149 task: new FinishedTask('rgw/zonegroup/storage-class', {
150 placement_target: placement_target,
151 storage_class: storage_class
153 call: this.rgwStorageClassService.removeStorageClass(placement_target, storage_class)
158 updateSelection(selection: CdTableSelection) {
159 this.selection = selection;
162 setExpandedRow(expandedRow: any) {
163 super.setExpandedRow(expandedRow);