9 } from '@angular/core';
10 import { BehaviorSubject, Observable, of } from 'rxjs';
11 import { catchError, switchMap, tap } from 'rxjs/operators';
12 import { CephfsSubvolumeService } from '~/app/shared/api/cephfs-subvolume.service';
13 import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
14 import { CellTemplate } from '~/app/shared/enum/cell-template.enum';
15 import { Icons } from '~/app/shared/enum/icons.enum';
16 import { CdTableAction } from '~/app/shared/models/cd-table-action';
17 import { CdTableColumn } from '~/app/shared/models/cd-table-column';
18 import { CdTableFetchDataContext } from '~/app/shared/models/cd-table-fetch-data-context';
19 import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
20 import { CephfsSubvolume } from '~/app/shared/models/cephfs-subvolume.model';
21 import { ModalService } from '~/app/shared/services/modal.service';
22 import { CephfsSubvolumeFormComponent } from '../cephfs-subvolume-form/cephfs-subvolume-form.component';
23 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
24 import { Permissions } from '~/app/shared/models/permissions';
25 import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
26 import { FinishedTask } from '~/app/shared/models/finished-task';
27 import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
28 import { FormControl } from '@angular/forms';
29 import { CdFormGroup } from '~/app/shared/forms/cd-form-group';
30 import { CdForm } from '~/app/shared/forms/cd-form';
31 import { CriticalConfirmationModalComponent } from '~/app/shared/components/critical-confirmation-modal/critical-confirmation-modal.component';
32 import { CephfsSubvolumeGroupService } from '~/app/shared/api/cephfs-subvolume-group.service';
33 import { CephfsSubvolumeGroup } from '~/app/shared/models/cephfs-subvolume-group.model';
34 import { CephfsMountDetailsComponent } from '../cephfs-mount-details/cephfs-mount-details.component';
35 import { HealthService } from '~/app/shared/api/health.service';
36 import _ from 'lodash';
37 import { DeletionImpact } from '~/app/shared/enum/critical-confirmation-modal-impact.enum';
39 const DEFAULT_SUBVOLUME_GROUP = '_nogroup';
42 selector: 'cd-cephfs-subvolume-list',
43 templateUrl: './cephfs-subvolume-list.component.html',
44 styleUrls: ['./cephfs-subvolume-list.component.scss']
46 export class CephfsSubvolumeListComponent extends CdForm implements OnInit, OnChanges {
47 @ViewChild('quotaUsageTpl', { static: true })
50 @ViewChild('typeTpl', { static: true })
53 @ViewChild('modeToHumanReadableTpl', { static: true })
54 modeToHumanReadableTpl: any;
56 @ViewChild('nameTpl', { static: true })
59 @ViewChild('quotaSizeTpl', { static: true })
62 @ViewChild('removeTmpl', { static: true })
63 removeTmpl: TemplateRef<any>;
65 @Input() fsName: string;
66 @Input() pools: any[];
68 columns: CdTableColumn[] = [];
69 tableActions: CdTableAction[];
70 context: CdTableFetchDataContext;
71 selection = new CdTableSelection();
72 removeForm: CdFormGroup;
74 permissions: Permissions;
75 modalRef: NgbModalRef;
76 errorMessage: string = '';
77 selectedName: string = '';
79 subVolumes$: Observable<CephfsSubvolume[]>;
80 subVolumeGroups$: Observable<CephfsSubvolumeGroup[]>;
81 subject = new BehaviorSubject<CephfsSubvolume[]>([]);
82 groupsSubject = new BehaviorSubject<CephfsSubvolume[]>([]);
84 subvolumeGroupList: string[] = [];
85 subVolumesList: CephfsSubvolume[] = [];
87 activeGroupName: string = '';
90 private cephfsSubVolumeService: CephfsSubvolumeService,
91 private actionLabels: ActionLabelsI18n,
92 private modalService: ModalService,
93 private authStorageService: AuthStorageService,
94 private taskWrapper: TaskWrapperService,
95 private cephfsSubvolumeGroupService: CephfsSubvolumeGroupService,
96 private healthService: HealthService
99 this.permissions = this.authStorageService.getPermissions();
105 name: $localize`Name`,
108 cellTemplate: this.nameTpl
111 name: $localize`Data Pool`,
112 prop: 'info.data_pool',
114 cellTransformation: CellTemplate.badge,
115 customTemplateConfig: {
116 class: 'badge-background-primary'
120 name: $localize`Usage`,
121 prop: 'info.bytes_pcent',
123 cellTemplate: this.quotaUsageTpl,
124 cellClass: 'text-right'
127 name: $localize`Path`,
130 cellTransformation: CellTemplate.path
133 name: $localize`Mode`,
136 cellTemplate: this.modeToHumanReadableTpl
139 name: $localize`Created`,
140 prop: 'info.created_at',
142 cellTransformation: CellTemplate.timeAgo
146 this.tableActions = [
148 name: this.actionLabels.CREATE,
149 permission: 'create',
151 click: () => this.openModal()
154 name: this.actionLabels.EDIT,
155 permission: 'update',
157 click: () => this.openModal(true)
160 name: this.actionLabels.ATTACH,
163 disable: () => !this.selection?.hasSelection,
164 click: () => this.showAttachInfo()
167 name: this.actionLabels.NFS_EXPORT,
168 permission: 'create',
169 icon: Icons.nfsExport,
171 '/cephfs/nfs/create',
173 _.isEmpty(this.activeGroupName) ? DEFAULT_SUBVOLUME_GROUP : this.activeGroupName,
174 { subvolume: this.selection?.first()?.name }
176 disable: () => !this.selection?.hasSingleSelection
179 name: this.actionLabels.REMOVE,
180 permission: 'delete',
182 click: () => this.removeSubVolumeModal()
186 this.subVolumeGroups$ = this.groupsSubject.pipe(
188 this.cephfsSubvolumeGroupService.get(this.fsName, false).pipe(
190 this.subvolumeGroupList = groups.map((group) => group.name);
191 this.subvolumeGroupList.unshift('');
194 this.context.error();
203 this.subject.next([]);
206 ngOnChanges(changes: SimpleChanges) {
207 if (changes.fsName) {
208 this.subject.next([]);
209 this.groupsSubject.next([]);
213 updateSelection(selection: CdTableSelection) {
214 this.selection = selection;
218 const selectedSubVolume = this.selection?.selected?.[0];
220 this.healthService.getClusterFsid().subscribe({
221 next: (clusterId: string) => {
222 this.modalRef = this.modalService.show(CephfsMountDetailsComponent, {
223 onSubmit: () => this.modalRef.close(),
227 rootPath: selectedSubVolume.info.path
234 openModal(edit = false) {
235 this.modalService.show(
236 CephfsSubvolumeFormComponent,
239 subVolumeName: this.selection?.first()?.name,
240 subVolumeGroupName: this.activeGroupName,
248 removeSubVolumeModal() {
249 this.removeForm = new CdFormGroup({
250 retainSnapshots: new FormControl(false)
252 this.errorMessage = '';
253 this.selectedName = this.selection.first().name;
254 this.modalRef = this.modalService.show(CriticalConfirmationModalComponent, {
255 impact: DeletionImpact.high,
256 actionDescription: 'Remove',
257 itemNames: [this.selectedName],
258 itemDescription: 'Subvolume',
259 childFormGroup: this.removeForm,
260 childFormGroupTemplate: this.removeTmpl,
263 .wrapTaskAroundCall({
264 task: new FinishedTask('cephfs/subvolume/remove', { subVolumeName: this.selectedName }),
265 call: this.cephfsSubVolumeService.remove(
268 this.activeGroupName,
269 this.removeForm.getValue('retainSnapshots')
273 complete: () => this.modalRef.close(),
275 this.modalRef.componentInstance.stopLoadingSpinner();
276 this.errorMessage = error.error.detail;
282 selectSubVolumeGroup(subVolumeGroupName: string) {
283 this.activeGroupName = subVolumeGroupName;
284 this.getSubVolumes();
288 this.subVolumes$ = this.subject.pipe(
290 this.cephfsSubVolumeService.get(this.fsName, this.activeGroupName).pipe(
292 this.context?.error();