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';
4 import { CephfsSubvolumeService } from '~/app/shared/api/cephfs-subvolume.service';
5 import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
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 { CephfsSubvolume } from '~/app/shared/models/cephfs-subvolume.model';
13 import { ModalService } from '~/app/shared/services/modal.service';
14 import { CephfsSubvolumeFormComponent } from '../cephfs-subvolume-form/cephfs-subvolume-form.component';
15 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
16 import { Permissions } from '~/app/shared/models/permissions';
17 import { CriticalConfirmationModalComponent } from '~/app/shared/components/critical-confirmation-modal/critical-confirmation-modal.component';
18 import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
19 import { FinishedTask } from '~/app/shared/models/finished-task';
22 selector: 'cd-cephfs-subvolume-list',
23 templateUrl: './cephfs-subvolume-list.component.html',
24 styleUrls: ['./cephfs-subvolume-list.component.scss']
26 export class CephfsSubvolumeListComponent implements OnInit, OnChanges {
27 @ViewChild('quotaUsageTpl', { static: true })
30 @ViewChild('typeTpl', { static: true })
33 @ViewChild('modeToHumanReadableTpl', { static: true })
34 modeToHumanReadableTpl: any;
36 @ViewChild('nameTpl', { static: true })
39 @ViewChild('quotaSizeTpl', { static: true })
42 @Input() fsName: string;
43 @Input() pools: any[];
45 columns: CdTableColumn[] = [];
46 tableActions: CdTableAction[];
47 context: CdTableFetchDataContext;
48 selection = new CdTableSelection();
50 permissions: Permissions;
52 subVolumes$: Observable<CephfsSubvolume[]>;
53 subject = new ReplaySubject<CephfsSubvolume[]>();
56 private cephfsSubVolume: CephfsSubvolumeService,
57 private actionLabels: ActionLabelsI18n,
58 private modalService: ModalService,
59 private authStorageService: AuthStorageService,
60 private taskWrapper: TaskWrapperService
62 this.permissions = this.authStorageService.getPermissions();
68 name: $localize`Name`,
71 cellTemplate: this.nameTpl
74 name: $localize`Data Pool`,
75 prop: 'info.data_pool',
77 cellTransformation: CellTemplate.badge,
78 customTemplateConfig: {
79 class: 'badge-background-primary'
83 name: $localize`Usage`,
84 prop: 'info.bytes_pcent',
86 cellTemplate: this.quotaUsageTpl,
87 cellClass: 'text-right'
90 name: $localize`Path`,
93 cellTransformation: CellTemplate.path
96 name: $localize`Mode`,
99 cellTemplate: this.modeToHumanReadableTpl
102 name: $localize`Created`,
103 prop: 'info.created_at',
105 cellTransformation: CellTemplate.timeAgo
109 this.tableActions = [
111 name: this.actionLabels.CREATE,
112 permission: 'create',
115 this.modalService.show(
116 CephfsSubvolumeFormComponent,
125 name: this.actionLabels.REMOVE,
126 permission: 'delete',
128 click: () => this.removeSubVolumeModal()
132 this.subVolumes$ = this.subject.pipe(
134 this.cephfsSubVolume.get(this.fsName).pipe(
136 this.context.error();
153 updateSelection(selection: CdTableSelection) {
154 this.selection = selection;
157 openModal(edit = false) {
158 this.modalService.show(
159 CephfsSubvolumeFormComponent,
162 subVolumeName: this.selection?.first()?.name,
170 removeSubVolumeModal() {
171 const name = this.selection.first().name;
172 this.modalService.show(CriticalConfirmationModalComponent, {
173 itemDescription: 'subvolume',
175 actionDescription: 'remove',
176 submitActionObservable: () =>
177 this.taskWrapper.wrapTaskAroundCall({
178 task: new FinishedTask('cephfs/subvolume/remove', { subVolumeName: name }),
179 call: this.cephfsSubVolume.remove(this.fsName, name)