1 import { Component, Input, OnInit, ViewChild } from '@angular/core';
2 import { Observable, ReplaySubject, of } from 'rxjs';
3 import { catchError, shareReplay, switchMap } from 'rxjs/operators';
5 import { CephfsSubvolumeGroupService } from '~/app/shared/api/cephfs-subvolume-group.service';
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 { CephfsSubvolumeGroup } from '~/app/shared/models/cephfs-subvolume-group.model';
13 import { CephfsSubvolumegroupFormComponent } from '../cephfs-subvolumegroup-form/cephfs-subvolumegroup-form.component';
14 import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
15 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
16 import { ModalService } from '~/app/shared/services/modal.service';
17 import { Permissions } from '~/app/shared/models/permissions';
20 selector: 'cd-cephfs-subvolume-group',
21 templateUrl: './cephfs-subvolume-group.component.html',
22 styleUrls: ['./cephfs-subvolume-group.component.scss']
24 export class CephfsSubvolumeGroupComponent implements OnInit {
25 @ViewChild('quotaUsageTpl', { static: true })
28 @ViewChild('typeTpl', { static: true })
31 @ViewChild('modeToHumanReadableTpl', { static: true })
32 modeToHumanReadableTpl: any;
34 @ViewChild('nameTpl', { static: true })
37 @ViewChild('quotaSizeTpl', { static: true })
42 @Input() pools: any[];
44 columns: CdTableColumn[];
45 tableActions: CdTableAction[];
46 context: CdTableFetchDataContext;
47 selection = new CdTableSelection();
49 permissions: Permissions;
51 subvolumeGroup$: Observable<CephfsSubvolumeGroup[]>;
52 subject = new ReplaySubject<CephfsSubvolumeGroup[]>();
55 private cephfsSubvolumeGroup: CephfsSubvolumeGroupService,
56 private actionLabels: ActionLabelsI18n,
57 private modalService: ModalService,
58 private authStorageService: AuthStorageService
60 this.permissions = this.authStorageService.getPermissions();
66 name: $localize`Name`,
69 cellTransformation: CellTemplate.bold
72 name: $localize`Data Pool`,
73 prop: 'info.data_pool',
75 cellTransformation: CellTemplate.badge,
76 customTemplateConfig: {
77 class: 'badge-background-primary'
81 name: $localize`Usage`,
82 prop: 'info.bytes_pcent',
84 cellTemplate: this.quotaUsageTpl,
85 cellClass: 'text-right'
88 name: $localize`Mode`,
91 cellTemplate: this.modeToHumanReadableTpl
94 name: $localize`Created`,
95 prop: 'info.created_at',
97 cellTransformation: CellTemplate.timeAgo
101 this.tableActions = [
103 name: this.actionLabels.CREATE,
104 permission: 'create',
107 this.modalService.show(
108 CephfsSubvolumegroupFormComponent,
118 this.subvolumeGroup$ = this.subject.pipe(
120 this.cephfsSubvolumeGroup.get(this.fsName).pipe(
122 this.context.error();
139 updateSelection(selection: CdTableSelection) {
140 this.selection = selection;