1 import { Component, OnInit, TemplateRef, ViewChild } from '@angular/core';
2 import { ActivatedRoute } from '@angular/router';
3 import { forkJoin, of } from 'rxjs';
4 import { catchError, map, switchMap } from 'rxjs/operators';
5 import { NvmeofService } from '~/app/shared/api/nvmeof.service';
9 NvmeofSubsystemInitiator
10 } from '~/app/shared/models/nvmeof';
11 import { CdTableColumn } from '~/app/shared/models/cd-table-column';
12 import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
14 import { ICON_TYPE } from '~/app/shared/enum/icons.enum';
15 import { NvmeofSubsystemAuthType } from '~/app/shared/enum/nvmeof.enum';
18 selector: 'cd-nvmeof-gateway-subsystem',
19 templateUrl: './nvmeof-gateway-subsystem.component.html',
20 styleUrls: ['./nvmeof-gateway-subsystem.component.scss'],
23 export class NvmeofGatewaySubsystemComponent implements OnInit {
24 @ViewChild('authTpl', { static: true })
25 authTpl!: TemplateRef<any>;
29 columns: CdTableColumn[] = [];
31 subsystems: NvmeofSubsystemData[] = [];
32 selection = new CdTableSelection();
35 authType = NvmeofSubsystemAuthType;
37 constructor(private nvmeofService: NvmeofService, private route: ActivatedRoute) {}
42 name: $localize`Subsystem NQN`,
47 name: $localize`Authentication`,
50 cellTemplate: this.authTpl
53 name: $localize`Hosts (Initiators)`,
59 this.route.parent?.params.subscribe((params) => {
60 if (params['group']) {
61 this.groupName = params['group'];
62 this.getSubsystemsData();
69 .listSubsystems(this.groupName)
71 switchMap((subsystems: NvmeofSubsystem[] | NvmeofSubsystem) => {
72 const subs = Array.isArray(subsystems) ? subsystems : [subsystems];
73 if (subs.length === 0) return of([]);
77 this.nvmeofService.getInitiators(sub.nqn, this.groupName).pipe(
78 catchError(() => of([])),
81 initiators: NvmeofSubsystemInitiator[] | { hosts?: NvmeofSubsystemInitiator[] }
84 if (Array.isArray(initiators)) count = initiators.length;
85 else if (initiators?.hosts && Array.isArray(initiators.hosts)) {
86 count = initiators.hosts.length;
89 let authStatus = NvmeofSubsystemAuthType.NO_AUTH;
91 authStatus = NvmeofSubsystemAuthType.BIDIRECTIONAL;
94 'hosts' in initiators &&
95 Array.isArray(initiators.hosts)
97 const hasDhchapKey = initiators.hosts.some(
98 (host: NvmeofSubsystemInitiator) => !!host.dhchap_key
101 authStatus = NvmeofSubsystemAuthType.UNIDIRECTIONAL;
103 } else if (Array.isArray(initiators)) {
104 // Fallback for unexpected structure, though getInitiators usually returns {hosts: []}
105 const hasDhchapKey = (initiators as NvmeofSubsystemInitiator[]).some(
106 (host: NvmeofSubsystemInitiator) => !!host.dhchap_key
109 authStatus = NvmeofSubsystemAuthType.UNIDIRECTIONAL;
126 next: (subsystems: NvmeofSubsystemData[]) => {
127 this.subsystems = subsystems;
130 this.subsystems = [];
135 updateSelection(selection: CdTableSelection): void {
136 this.selection = selection;