1 import { Component, Input, OnChanges, OnInit, SimpleChanges, ViewChild } from '@angular/core';
2 import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
3 import { BehaviorSubject, Observable } from 'rxjs';
4 import { finalize, shareReplay, switchMap } from 'rxjs/operators';
5 import { CephfsSnapshotScheduleService } from '~/app/shared/api/cephfs-snapshot-schedule.service';
6 import { CdForm } from '~/app/shared/forms/cd-form';
7 import { CdTableAction } from '~/app/shared/models/cd-table-action';
8 import { CdTableColumn } from '~/app/shared/models/cd-table-column';
9 import { CdTableFetchDataContext } from '~/app/shared/models/cd-table-fetch-data-context';
10 import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
11 import { Permissions } from '~/app/shared/models/permissions';
12 import { SnapshotSchedule } from '~/app/shared/models/snapshot-schedule';
13 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
14 import { ModalService } from '~/app/shared/services/modal.service';
15 import { Icons } from '~/app/shared/enum/icons.enum';
16 import { CellTemplate } from '~/app/shared/enum/cell-template.enum';
19 selector: 'cd-cephfs-snapshotschedule-list',
20 templateUrl: './cephfs-snapshotschedule-list.component.html',
21 styleUrls: ['./cephfs-snapshotschedule-list.component.scss']
23 export class CephfsSnapshotscheduleListComponent extends CdForm implements OnInit, OnChanges {
24 @Input() fsName!: string;
26 @ViewChild('pathTpl', { static: true })
29 snapshotSchedules$!: Observable<SnapshotSchedule[]>;
30 subject$ = new BehaviorSubject<SnapshotSchedule[]>([]);
31 isLoading$ = new BehaviorSubject<boolean>(true);
32 columns: CdTableColumn[] = [];
33 tableActions: CdTableAction[] = [];
34 context!: CdTableFetchDataContext;
35 selection = new CdTableSelection();
36 permissions!: Permissions;
37 modalRef!: NgbModalRef;
38 errorMessage: string = '';
39 selectedName: string = '';
43 private snapshotScheduleService: CephfsSnapshotScheduleService,
44 private authStorageService: AuthStorageService,
45 private modalService: ModalService
48 this.permissions = this.authStorageService.getPermissions();
51 ngOnChanges(changes: SimpleChanges): void {
53 this.subject$.next([]);
58 this.snapshotSchedules$ = this.subject$.pipe(
60 this.snapshotScheduleService
61 .getSnapshotScheduleList('/', this.fsName)
62 .pipe(finalize(() => this.isLoading$.next(false)))
68 { prop: 'path', name: $localize`Path`, flexGrow: 3, cellTemplate: this.pathTpl },
69 { prop: 'subvol', name: $localize`Subvolume` },
70 { prop: 'schedule', name: $localize`Repeat interval` },
71 { prop: 'retention', name: $localize`Retention policy` },
72 { prop: 'created_count', name: $localize`Created Count` },
73 { prop: 'pruned_count', name: $localize`Deleted Count` },
74 { prop: 'start', name: $localize`Start time`, cellTransformation: CellTemplate.timeAgo },
75 { prop: 'created', name: $localize`Created`, cellTransformation: CellTemplate.timeAgo }
78 this.tableActions = [];
82 this.subject$.next([]);
85 updateSelection(selection: CdTableSelection) {
86 this.selection = selection;
89 openModal(edit = false) {
90 this.modalService.show(