1 import { Component, Input, OnChanges, OnInit, ViewChild } from '@angular/core';
2 import { Observable, ReplaySubject, of } from 'rxjs';
3 import { catchError, shareReplay, switchMap } from 'rxjs/operators';
4 import { CephfsSubvolumeService } from '~/app/shared/api/cephfs-subvolume.service';
5 import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
6 import { CellTemplate } from '~/app/shared/enum/cell-template.enum';
7 import { Icons } from '~/app/shared/enum/icons.enum';
8 import { CdTableAction } from '~/app/shared/models/cd-table-action';
9 import { CdTableColumn } from '~/app/shared/models/cd-table-column';
10 import { CdTableFetchDataContext } from '~/app/shared/models/cd-table-fetch-data-context';
11 import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
12 import { CephfsSubvolume } from '~/app/shared/models/cephfs-subvolume.model';
13 import { ModalService } from '~/app/shared/services/modal.service';
14 import { CephfsSubvolumeFormComponent } from '../cephfs-subvolume-form/cephfs-subvolume-form.component';
15 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
16 import { Permissions } from '~/app/shared/models/permissions';
19 selector: 'cd-cephfs-subvolume-list',
20 templateUrl: './cephfs-subvolume-list.component.html',
21 styleUrls: ['./cephfs-subvolume-list.component.scss']
23 export class CephfsSubvolumeListComponent implements OnInit, OnChanges {
24 @ViewChild('quotaUsageTpl', { static: true })
27 @ViewChild('typeTpl', { static: true })
30 @ViewChild('modeToHumanReadableTpl', { static: true })
31 modeToHumanReadableTpl: any;
33 @ViewChild('nameTpl', { static: true })
36 @ViewChild('quotaSizeTpl', { static: true })
39 @Input() fsName: string;
40 @Input() pools: any[];
42 columns: CdTableColumn[] = [];
43 tableActions: CdTableAction[];
44 context: CdTableFetchDataContext;
45 selection = new CdTableSelection();
47 permissions: Permissions;
49 subVolumes$: Observable<CephfsSubvolume[]>;
50 subject = new ReplaySubject<CephfsSubvolume[]>();
53 private cephfsSubVolume: CephfsSubvolumeService,
54 private actionLabels: ActionLabelsI18n,
55 private modalService: ModalService,
56 private authStorageService: AuthStorageService
58 this.permissions = this.authStorageService.getPermissions();
64 name: $localize`Name`,
67 cellTemplate: this.nameTpl
70 name: $localize`Data Pool`,
71 prop: 'info.data_pool',
73 cellTransformation: CellTemplate.badge,
74 customTemplateConfig: {
75 class: 'badge-background-primary'
79 name: $localize`Usage`,
80 prop: 'info.bytes_pcent',
82 cellTemplate: this.quotaUsageTpl,
83 cellClass: 'text-right'
86 name: $localize`Path`,
89 cellTransformation: CellTemplate.path
92 name: $localize`Mode`,
95 cellTemplate: this.modeToHumanReadableTpl
98 name: $localize`Created`,
99 prop: 'info.created_at',
101 cellTransformation: CellTemplate.timeAgo
105 this.tableActions = [
107 name: this.actionLabels.CREATE,
108 permission: 'create',
111 this.modalService.show(
112 CephfsSubvolumeFormComponent,
122 this.subVolumes$ = this.subject.pipe(
124 this.cephfsSubVolume.get(this.fsName).pipe(
126 this.context.error();
143 updateSelection(selection: CdTableSelection) {
144 this.selection = selection;