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';
38 selector: 'cd-cephfs-subvolume-list',
39 templateUrl: './cephfs-subvolume-list.component.html',
40 styleUrls: ['./cephfs-subvolume-list.component.scss']
42 export class CephfsSubvolumeListComponent extends CdForm implements OnInit, OnChanges {
43 @ViewChild('quotaUsageTpl', { static: true })
46 @ViewChild('typeTpl', { static: true })
49 @ViewChild('modeToHumanReadableTpl', { static: true })
50 modeToHumanReadableTpl: any;
52 @ViewChild('nameTpl', { static: true })
55 @ViewChild('quotaSizeTpl', { static: true })
58 @ViewChild('removeTmpl', { static: true })
59 removeTmpl: TemplateRef<any>;
61 @Input() fsName: string;
62 @Input() pools: any[];
64 columns: CdTableColumn[] = [];
65 tableActions: CdTableAction[];
66 context: CdTableFetchDataContext;
67 selection = new CdTableSelection();
68 removeForm: CdFormGroup;
70 permissions: Permissions;
71 modalRef: NgbModalRef;
72 errorMessage: string = '';
73 selectedName: string = '';
75 subVolumes$: Observable<CephfsSubvolume[]>;
76 subVolumeGroups$: Observable<CephfsSubvolumeGroup[]>;
77 subject = new BehaviorSubject<CephfsSubvolume[]>([]);
78 groupsSubject = new BehaviorSubject<CephfsSubvolume[]>([]);
80 subvolumeGroupList: string[] = [];
81 subVolumesList: CephfsSubvolume[] = [];
83 activeGroupName: string = '';
86 private cephfsSubVolumeService: CephfsSubvolumeService,
87 private actionLabels: ActionLabelsI18n,
88 private modalService: ModalService,
89 private authStorageService: AuthStorageService,
90 private taskWrapper: TaskWrapperService,
91 private cephfsSubvolumeGroupService: CephfsSubvolumeGroupService,
92 private healthService: HealthService
95 this.permissions = this.authStorageService.getPermissions();
101 name: $localize`Name`,
104 cellTemplate: this.nameTpl
107 name: $localize`Data Pool`,
108 prop: 'info.data_pool',
110 cellTransformation: CellTemplate.badge,
111 customTemplateConfig: {
112 class: 'badge-background-primary'
116 name: $localize`Usage`,
117 prop: 'info.bytes_pcent',
119 cellTemplate: this.quotaUsageTpl,
120 cellClass: 'text-right'
123 name: $localize`Path`,
126 cellTransformation: CellTemplate.path
129 name: $localize`Mode`,
132 cellTemplate: this.modeToHumanReadableTpl
135 name: $localize`Created`,
136 prop: 'info.created_at',
138 cellTransformation: CellTemplate.timeAgo
142 this.tableActions = [
144 name: this.actionLabels.CREATE,
145 permission: 'create',
147 click: () => this.openModal()
150 name: this.actionLabels.EDIT,
151 permission: 'update',
153 click: () => this.openModal(true)
156 name: this.actionLabels.ATTACH,
159 disable: () => !this.selection?.hasSelection,
160 click: () => this.showAttachInfo()
163 name: this.actionLabels.REMOVE,
164 permission: 'delete',
166 click: () => this.removeSubVolumeModal()
170 this.subVolumeGroups$ = this.groupsSubject.pipe(
172 this.cephfsSubvolumeGroupService.get(this.fsName, false).pipe(
174 this.subvolumeGroupList = groups.map((group) => group.name);
175 this.subvolumeGroupList.unshift('');
178 this.context.error();
187 this.subject.next([]);
190 ngOnChanges(changes: SimpleChanges) {
191 if (changes.fsName) {
192 this.subject.next([]);
193 this.groupsSubject.next([]);
197 updateSelection(selection: CdTableSelection) {
198 this.selection = selection;
202 const selectedSubVolume = this.selection?.selected?.[0];
204 this.healthService.getClusterFsid().subscribe({
205 next: (clusterId: string) => {
206 this.modalRef = this.modalService.show(CephfsMountDetailsComponent, {
207 onSubmit: () => this.modalRef.close(),
211 rootPath: selectedSubVolume.info.path
218 openModal(edit = false) {
219 this.modalService.show(
220 CephfsSubvolumeFormComponent,
223 subVolumeName: this.selection?.first()?.name,
224 subVolumeGroupName: this.activeGroupName,
232 removeSubVolumeModal() {
233 this.removeForm = new CdFormGroup({
234 retainSnapshots: new FormControl(false)
236 this.errorMessage = '';
237 this.selectedName = this.selection.first().name;
238 this.modalRef = this.modalService.show(CriticalConfirmationModalComponent, {
239 actionDescription: 'Remove',
240 itemNames: [this.selectedName],
241 itemDescription: 'Subvolume',
242 childFormGroup: this.removeForm,
243 childFormGroupTemplate: this.removeTmpl,
246 .wrapTaskAroundCall({
247 task: new FinishedTask('cephfs/subvolume/remove', { subVolumeName: this.selectedName }),
248 call: this.cephfsSubVolumeService.remove(
251 this.activeGroupName,
252 this.removeForm.getValue('retainSnapshots')
256 complete: () => this.modalRef.close(),
258 this.modalRef.componentInstance.stopLoadingSpinner();
259 this.errorMessage = error.error.detail;
265 selectSubVolumeGroup(subVolumeGroupName: string) {
266 this.activeGroupName = subVolumeGroupName;
267 this.getSubVolumes();
271 this.subVolumes$ = this.subject.pipe(
273 this.cephfsSubVolumeService.get(this.fsName, this.activeGroupName).pipe(
275 this.context?.error();