1 import { Component, Input, OnChanges, OnInit, ViewChild } from '@angular/core';
2 import { Observable, ReplaySubject, of } from 'rxjs';
3 import { catchError, shareReplay, switchMap } from 'rxjs/operators';
5 import { CephfsSubvolumeGroupService } from '~/app/shared/api/cephfs-subvolume-group.service';
6 import { CellTemplate } from '~/app/shared/enum/cell-template.enum';
7 import { Icons } from '~/app/shared/enum/icons.enum';
8 import { CdTableAction } from '~/app/shared/models/cd-table-action';
9 import { CdTableColumn } from '~/app/shared/models/cd-table-column';
10 import { CdTableFetchDataContext } from '~/app/shared/models/cd-table-fetch-data-context';
11 import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
12 import { CephfsSubvolumeGroup } from '~/app/shared/models/cephfs-subvolumegroup.model';
13 import { CephfsSubvolumegroupFormComponent } from '../cephfs-subvolumegroup-form/cephfs-subvolumegroup-form.component';
14 import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
15 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
16 import { ModalService } from '~/app/shared/services/modal.service';
17 import { Permissions } from '~/app/shared/models/permissions';
18 import { CriticalConfirmationModalComponent } from '~/app/shared/components/critical-confirmation-modal/critical-confirmation-modal.component';
19 import { FinishedTask } from '~/app/shared/models/finished-task';
20 import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
23 selector: 'cd-cephfs-subvolume-group',
24 templateUrl: './cephfs-subvolume-group.component.html',
25 styleUrls: ['./cephfs-subvolume-group.component.scss']
27 export class CephfsSubvolumeGroupComponent implements OnInit, OnChanges {
28 @ViewChild('quotaUsageTpl', { static: true })
31 @ViewChild('typeTpl', { static: true })
34 @ViewChild('modeToHumanReadableTpl', { static: true })
35 modeToHumanReadableTpl: any;
37 @ViewChild('nameTpl', { static: true })
40 @ViewChild('quotaSizeTpl', { static: true })
45 @Input() pools: any[];
47 columns: CdTableColumn[];
48 tableActions: CdTableAction[];
49 context: CdTableFetchDataContext;
50 selection = new CdTableSelection();
52 permissions: Permissions;
54 subvolumeGroup$: Observable<CephfsSubvolumeGroup[]>;
55 subject = new ReplaySubject<CephfsSubvolumeGroup[]>();
58 private cephfsSubvolumeGroup: CephfsSubvolumeGroupService,
59 private actionLabels: ActionLabelsI18n,
60 private modalService: ModalService,
61 private authStorageService: AuthStorageService,
62 private taskWrapper: TaskWrapperService
64 this.permissions = this.authStorageService.getPermissions();
70 name: $localize`Name`,
73 cellTransformation: CellTemplate.bold
76 name: $localize`Data Pool`,
77 prop: 'info.data_pool',
79 cellTransformation: CellTemplate.badge,
80 customTemplateConfig: {
81 class: 'badge-background-primary'
85 name: $localize`Usage`,
86 prop: 'info.bytes_pcent',
88 cellTemplate: this.quotaUsageTpl,
89 cellClass: 'text-right'
92 name: $localize`Mode`,
95 cellTemplate: this.modeToHumanReadableTpl
98 name: $localize`Created`,
99 prop: 'info.created_at',
101 cellTransformation: CellTemplate.timeAgo
105 this.tableActions = [
107 name: this.actionLabels.CREATE,
108 permission: 'create',
110 click: () => this.openModal(),
111 canBePrimary: (selection: CdTableSelection) => !selection.hasSelection
114 name: this.actionLabels.EDIT,
115 permission: 'update',
117 click: () => this.openModal(true)
120 name: this.actionLabels.REMOVE,
121 permission: 'delete',
123 click: () => this.removeSubVolumeModal()
127 this.subvolumeGroup$ = this.subject.pipe(
129 this.cephfsSubvolumeGroup.get(this.fsName).pipe(
131 this.context.error();
148 updateSelection(selection: CdTableSelection) {
149 this.selection = selection;
152 openModal(edit = false) {
153 this.modalService.show(
154 CephfsSubvolumegroupFormComponent,
157 subvolumegroupName: this.selection?.first()?.name,
165 removeSubVolumeModal() {
166 const name = this.selection.first().name;
167 this.modalService.show(CriticalConfirmationModalComponent, {
168 itemDescription: 'subvolume group',
170 actionDescription: 'remove',
171 submitActionObservable: () =>
172 this.taskWrapper.wrapTaskAroundCall({
173 task: new FinishedTask('cephfs/subvolume/group/remove', { subvolumegroupName: name }),
174 call: this.cephfsSubvolumeGroup.remove(this.fsName, name)