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';
36 selector: 'cd-cephfs-subvolume-list',
37 templateUrl: './cephfs-subvolume-list.component.html',
38 styleUrls: ['./cephfs-subvolume-list.component.scss']
40 export class CephfsSubvolumeListComponent extends CdForm implements OnInit, OnChanges {
41 @ViewChild('quotaUsageTpl', { static: true })
44 @ViewChild('typeTpl', { static: true })
47 @ViewChild('modeToHumanReadableTpl', { static: true })
48 modeToHumanReadableTpl: any;
50 @ViewChild('nameTpl', { static: true })
53 @ViewChild('quotaSizeTpl', { static: true })
56 @ViewChild('removeTmpl', { static: true })
57 removeTmpl: TemplateRef<any>;
59 @Input() fsName: string;
60 @Input() pools: any[];
62 columns: CdTableColumn[] = [];
63 tableActions: CdTableAction[];
64 context: CdTableFetchDataContext;
65 selection = new CdTableSelection();
66 removeForm: CdFormGroup;
68 permissions: Permissions;
69 modalRef: NgbModalRef;
70 errorMessage: string = '';
71 selectedName: string = '';
73 subVolumes$: Observable<CephfsSubvolume[]>;
74 subVolumeGroups$: Observable<CephfsSubvolumeGroup[]>;
75 subject = new BehaviorSubject<CephfsSubvolume[]>([]);
76 groupsSubject = new BehaviorSubject<CephfsSubvolume[]>([]);
78 subvolumeGroupList: string[] = [];
79 subVolumesList: CephfsSubvolume[] = [];
81 activeGroupName: string = '';
84 private cephfsSubVolumeService: CephfsSubvolumeService,
85 private actionLabels: ActionLabelsI18n,
86 private modalService: ModalService,
87 private authStorageService: AuthStorageService,
88 private taskWrapper: TaskWrapperService,
89 private cephfsSubvolumeGroupService: CephfsSubvolumeGroupService
92 this.permissions = this.authStorageService.getPermissions();
98 name: $localize`Name`,
101 cellTemplate: this.nameTpl
104 name: $localize`Data Pool`,
105 prop: 'info.data_pool',
107 cellTransformation: CellTemplate.badge,
108 customTemplateConfig: {
109 class: 'badge-background-primary'
113 name: $localize`Usage`,
114 prop: 'info.bytes_pcent',
116 cellTemplate: this.quotaUsageTpl,
117 cellClass: 'text-right'
120 name: $localize`Path`,
123 cellTransformation: CellTemplate.path
126 name: $localize`Mode`,
129 cellTemplate: this.modeToHumanReadableTpl
132 name: $localize`Created`,
133 prop: 'info.created_at',
135 cellTransformation: CellTemplate.timeAgo
139 this.tableActions = [
141 name: this.actionLabels.CREATE,
142 permission: 'create',
144 click: () => this.openModal()
147 name: this.actionLabels.EDIT,
148 permission: 'update',
150 click: () => this.openModal(true)
153 name: this.actionLabels.REMOVE,
154 permission: 'delete',
156 click: () => this.removeSubVolumeModal()
160 this.subVolumeGroups$ = this.groupsSubject.pipe(
162 this.cephfsSubvolumeGroupService.get(this.fsName, false).pipe(
164 this.subvolumeGroupList = groups.map((group) => group.name);
165 this.subvolumeGroupList.unshift('');
168 this.context.error();
177 this.subject.next([]);
180 ngOnChanges(changes: SimpleChanges) {
181 if (changes.fsName) {
182 this.subject.next([]);
183 this.groupsSubject.next([]);
187 updateSelection(selection: CdTableSelection) {
188 this.selection = selection;
191 openModal(edit = false) {
192 this.modalService.show(
193 CephfsSubvolumeFormComponent,
196 subVolumeName: this.selection?.first()?.name,
197 subVolumeGroupName: this.activeGroupName,
205 removeSubVolumeModal() {
206 this.removeForm = new CdFormGroup({
207 retainSnapshots: new FormControl(false)
209 this.errorMessage = '';
210 this.selectedName = this.selection.first().name;
211 this.modalRef = this.modalService.show(CriticalConfirmationModalComponent, {
212 actionDescription: 'Remove',
213 itemNames: [this.selectedName],
214 itemDescription: 'Subvolume',
215 childFormGroup: this.removeForm,
216 childFormGroupTemplate: this.removeTmpl,
219 .wrapTaskAroundCall({
220 task: new FinishedTask('cephfs/subvolume/remove', { subVolumeName: this.selectedName }),
221 call: this.cephfsSubVolumeService.remove(
224 this.activeGroupName,
225 this.removeForm.getValue('retainSnapshots')
229 complete: () => this.modalRef.close(),
231 this.modalRef.componentInstance.stopLoadingSpinner();
232 this.errorMessage = error.error.detail;
238 selectSubVolumeGroup(subVolumeGroupName: string) {
239 this.activeGroupName = subVolumeGroupName;
240 this.getSubVolumes();
244 this.subVolumes$ = this.subject.pipe(
246 this.cephfsSubVolumeService.get(this.fsName, this.activeGroupName).pipe(
248 this.context.error();