1 import { Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core';
2 import { BehaviorSubject, Observable, forkJoin, of } from 'rxjs';
3 import { catchError, shareReplay, switchMap, tap } from 'rxjs/operators';
4 import { CephfsSubvolumeGroupService } from '~/app/shared/api/cephfs-subvolume-group.service';
5 import { CephfsSubvolumeService } from '~/app/shared/api/cephfs-subvolume.service';
6 import { CellTemplate } from '~/app/shared/enum/cell-template.enum';
7 import { CdTableColumn } from '~/app/shared/models/cd-table-column';
8 import { CdTableFetchDataContext } from '~/app/shared/models/cd-table-fetch-data-context';
9 import { CephfsSubvolume, SubvolumeSnapshot } from '~/app/shared/models/cephfs-subvolume.model';
12 selector: 'cd-cephfs-subvolume-snapshots-list',
13 templateUrl: './cephfs-subvolume-snapshots-list.component.html',
14 styleUrls: ['./cephfs-subvolume-snapshots-list.component.scss']
16 export class CephfsSubvolumeSnapshotsListComponent implements OnInit, OnChanges {
17 @Input() fsName: string;
19 context: CdTableFetchDataContext;
20 columns: CdTableColumn[] = [];
22 subVolumes$: Observable<CephfsSubvolume[]>;
23 snapshots$: Observable<any[]>;
24 snapshotSubject = new BehaviorSubject<SubvolumeSnapshot[]>([]);
25 subVolumeSubject = new BehaviorSubject<CephfsSubvolume[]>([]);
27 subvolumeGroupList: string[] = [];
28 subVolumesList: string[];
31 activeSubVolumeName = '';
33 isSubVolumesAvailable = false;
36 observables: any = [];
39 private cephfsSubvolumeGroupService: CephfsSubvolumeGroupService,
40 private cephfsSubvolumeService: CephfsSubvolumeService
46 name: $localize`Name`,
51 name: $localize`Created`,
52 prop: 'info.created_at',
54 cellTransformation: CellTemplate.timeAgo
57 name: $localize`Pending Clones`,
58 prop: 'info.has_pending_clones',
60 cellTransformation: CellTemplate.badge,
61 customTemplateConfig: {
63 no: { class: 'badge-success' },
64 yes: { class: 'badge-info' }
70 this.cephfsSubvolumeGroupService
73 switchMap((groups) => {
74 // manually adding the group '_nogroup' to the list.
75 groups.unshift({ name: '' });
77 const observables = groups.map((group) =>
78 this.cephfsSubvolumeService.existsInFs(this.fsName, group.name).pipe(
81 this.subvolumeGroupList.push(group.name);
83 return of(resp); // Emit the response
88 return forkJoin(observables);
92 if (this.subvolumeGroupList.length) {
93 this.isSubVolumesAvailable = true;
95 this.isLoading = false;
99 ngOnChanges(changes: SimpleChanges): void {
100 if (changes.fsName) {
101 this.subVolumeSubject.next([]);
105 selectSubVolumeGroup(subVolumeGroupName: string) {
106 this.activeGroupName = subVolumeGroupName;
107 this.getSubVolumes();
110 selectSubVolume(subVolumeName: string) {
111 this.activeSubVolumeName = subVolumeName;
112 this.getSubVolumesSnapshot();
116 this.subVolumes$ = this.subVolumeSubject.pipe(
118 this.cephfsSubvolumeService.get(this.fsName, this.activeGroupName, false).pipe(
120 this.subVolumesList = resp.map((subVolume) => subVolume.name);
121 this.activeSubVolumeName = resp[0].name;
122 this.getSubVolumesSnapshot();
129 getSubVolumesSnapshot() {
130 this.snapshots$ = this.snapshotSubject.pipe(
132 this.cephfsSubvolumeService
133 .getSnapshots(this.fsName, this.activeSubVolumeName, this.activeGroupName)
136 this.context.error();
146 this.snapshotSubject.next([]);