1 import { Component, Input, OnInit, TemplateRef, ViewChild } from '@angular/core';
2 import { Router } from '@angular/router';
3 import { NvmeofService } from '~/app/shared/api/nvmeof.service';
4 import { CriticalConfirmationModalComponent } from '~/app/shared/components/critical-confirmation-modal/critical-confirmation-modal.component';
5 import { ActionLabelsI18n, URLVerbs } from '~/app/shared/constants/app.constants';
6 import { Icons } from '~/app/shared/enum/icons.enum';
7 import { CdTableAction } from '~/app/shared/models/cd-table-action';
8 import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
9 import { FinishedTask } from '~/app/shared/models/finished-task';
10 import { NvmeofSubsystemInitiator } from '~/app/shared/models/nvmeof';
11 import { Permission } from '~/app/shared/models/permissions';
12 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
13 import { ModalCdsService } from '~/app/shared/services/modal-cds.service';
14 import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
16 const BASE_URL = 'block/nvmeof/subsystems';
19 selector: 'cd-nvmeof-initiators-list',
20 templateUrl: './nvmeof-initiators-list.component.html',
21 styleUrls: ['./nvmeof-initiators-list.component.scss']
23 export class NvmeofInitiatorsListComponent implements OnInit {
29 @ViewChild('hostTpl', { static: true })
30 hostTpl: TemplateRef<any>;
32 initiatorColumns: any;
33 tableActions: CdTableAction[];
34 selection = new CdTableSelection();
35 permission: Permission;
36 initiators: NvmeofSubsystemInitiator[] = [];
39 public actionLabels: ActionLabelsI18n,
40 private authStorageService: AuthStorageService,
41 private nvmeofService: NvmeofService,
42 private modalService: ModalCdsService,
43 private router: Router,
44 private taskWrapper: TaskWrapperService
46 this.permission = this.authStorageService.getPermissions().nvmeof;
50 this.initiatorColumns = [
52 name: $localize`Initiator`,
54 cellTemplate: this.hostTpl
59 name: this.actionLabels.ADD,
64 [BASE_URL, { outlets: { modal: [URLVerbs.ADD, this.subsystemNQN, 'initiator'] } }],
65 { queryParams: { group: this.group } }
67 canBePrimary: (selection: CdTableSelection) => !selection.hasSelection
70 name: this.actionLabels.REMOVE,
73 click: () => this.removeInitiatorModal(),
74 disable: () => !this.selection.hasSelection,
75 canBePrimary: (selection: CdTableSelection) => selection.hasSelection
80 getAllowAllHostIndex() {
81 return this.selection.selected.findIndex((selected) => selected.nqn === '*');
84 updateSelection(selection: CdTableSelection) {
85 this.selection = selection;
90 .getInitiators(this.subsystemNQN, this.group)
91 .subscribe((initiators: NvmeofSubsystemInitiator[]) => {
92 this.initiators = initiators;
97 return this.selection.selected.map((selected) => selected.nqn);
100 removeInitiatorModal() {
101 const hostNQNs = this.getSelectedNQNs();
102 const allowAllHostIndex = this.getAllowAllHostIndex();
103 const host_nqn = hostNQNs.join(',');
104 let itemNames = hostNQNs;
105 if (allowAllHostIndex !== -1) {
106 hostNQNs.splice(allowAllHostIndex, 1);
107 itemNames = [...hostNQNs, $localize`Allow any host(*)`];
109 this.modalService.show(CriticalConfirmationModalComponent, {
110 itemDescription: 'Initiator',
112 actionDescription: 'remove',
113 submitActionObservable: () =>
114 this.taskWrapper.wrapTaskAroundCall({
115 task: new FinishedTask('nvmeof/initiator/remove', {
116 nqn: this.subsystemNQN,
117 plural: itemNames.length > 1
119 call: this.nvmeofService.removeInitiators(this.subsystemNQN, {