]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
d5f24e897284928b93c8cfd6b4de4aec04bf6411
[ceph.git] /
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';
17
18 @Component({
19   selector: 'cd-cephfs-snapshotschedule-list',
20   templateUrl: './cephfs-snapshotschedule-list.component.html',
21   styleUrls: ['./cephfs-snapshotschedule-list.component.scss']
22 })
23 export class CephfsSnapshotscheduleListComponent extends CdForm implements OnInit, OnChanges {
24   @Input() fsName!: string;
25
26   @ViewChild('pathTpl', { static: true })
27   pathTpl: any;
28
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 = '';
40   icons = Icons;
41
42   constructor(
43     private snapshotScheduleService: CephfsSnapshotScheduleService,
44     private authStorageService: AuthStorageService,
45     private modalService: ModalService
46   ) {
47     super();
48     this.permissions = this.authStorageService.getPermissions();
49   }
50
51   ngOnChanges(changes: SimpleChanges): void {
52     if (changes.fsName) {
53       this.subject$.next([]);
54     }
55   }
56
57   ngOnInit(): void {
58     this.snapshotSchedules$ = this.subject$.pipe(
59       switchMap(() =>
60         this.snapshotScheduleService
61           .getSnapshotScheduleList('/', this.fsName)
62           .pipe(finalize(() => this.isLoading$.next(false)))
63       ),
64       shareReplay(1)
65     );
66
67     this.columns = [
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 }
76     ];
77
78     this.tableActions = [];
79   }
80
81   fetchData() {
82     this.subject$.next([]);
83   }
84
85   updateSelection(selection: CdTableSelection) {
86     this.selection = selection;
87   }
88
89   openModal(edit = false) {
90     this.modalService.show(
91       {},
92       {
93         fsName: 'fs1',
94         isEdit: edit
95       },
96       { size: 'lg' }
97     );
98   }
99 }