1 import { Component, OnInit, TemplateRef, ViewChild } from '@angular/core';
2 import { BehaviorSubject, forkJoin, Observable, of } from 'rxjs';
3 import { catchError, map, switchMap } from 'rxjs/operators';
4 import { GatewayGroup, NvmeofService } from '~/app/shared/api/nvmeof.service';
5 import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
6 import { TableComponent } from '~/app/shared/datatable/table/table.component';
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 { Permission } from '~/app/shared/models/permissions';
12 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
13 import { Icons, IconSize } from '~/app/shared/enum/icons.enum';
14 import { NvmeofGatewayGroup } from '~/app/shared/models/nvmeof';
15 import { CephServiceSpec } from '~/app/shared/models/service.interface';
18 selector: 'cd-nvmeof-gateway-group',
19 templateUrl: './nvmeof-gateway-group.component.html',
20 styleUrls: ['./nvmeof-gateway-group.component.scss'],
23 export class NvmeofGatewayGroupComponent implements OnInit {
24 @ViewChild(TableComponent, { static: true })
25 table: TableComponent;
27 @ViewChild('dateTpl', { static: true })
28 dateTpl: TemplateRef<any>;
30 @ViewChild('gatewayStatusTpl', { static: true })
31 gatewayStatusTpl: TemplateRef<any>;
33 permission: Permission;
34 tableActions: CdTableAction[];
35 columns: CdTableColumn[] = [];
36 selection: CdTableSelection = new CdTableSelection();
37 gatewayGroup$: Observable<CephServiceSpec[]>;
38 subject = new BehaviorSubject<CephServiceSpec[]>([]);
39 context: CdTableFetchDataContext;
40 gatewayGroupName: string;
41 subsystemCount: number;
49 public actionLabels: ActionLabelsI18n,
50 private authStorageService: AuthStorageService,
51 private nvmeofService: NvmeofService
55 this.permission = this.authStorageService.getPermissions().nvmeof;
59 name: $localize`Name`,
63 name: $localize`Gateways`,
65 cellTemplate: this.gatewayStatusTpl
68 name: $localize`Subsystems`,
69 prop: 'subSystemCount'
72 name: $localize`Created on`,
74 cellTemplate: this.dateTpl
78 this.gatewayGroup$ = this.subject.pipe(
80 this.nvmeofService.listGatewayGroups().pipe(
81 switchMap((gatewayGroups: GatewayGroup[][]) => {
82 const groups = gatewayGroups?.[0] ?? [];
84 groups.map((group: NvmeofGatewayGroup) =>
85 this.nvmeofService.listSubsystems(group.spec.group).pipe(
86 catchError(() => of([])),
89 name: group.spec?.group,
91 running: group.status?.running ?? 0,
92 error: (group.status?.size ?? 0) - (group.status?.running ?? 0)
95 subSystemCount: Array.isArray(subs) ? subs.length : 0,
96 gateWayNode: group.placement?.hosts?.length ?? 0,
97 created: group.status?.created ? new Date(group.status.created) : null
103 catchError((error) => {
104 this.context?.error?.(error);
113 this.subject.next([]);
116 updateSelection(selection: CdTableSelection): void {
117 this.selection = selection;