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 { DeleteConfirmationModalComponent } from '~/app/shared/components/delete-confirmation-modal/delete-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'],
24 export class NvmeofInitiatorsListComponent implements OnInit {
30 @ViewChild('hostTpl', { static: true })
31 hostTpl: TemplateRef<any>;
33 initiatorColumns: any;
34 tableActions: CdTableAction[];
35 selection = new CdTableSelection();
36 permission: Permission;
37 initiators: NvmeofSubsystemInitiator[] = [];
40 public actionLabels: ActionLabelsI18n,
41 private authStorageService: AuthStorageService,
42 private nvmeofService: NvmeofService,
43 private modalService: ModalCdsService,
44 private router: Router,
45 private taskWrapper: TaskWrapperService
47 this.permission = this.authStorageService.getPermissions().nvmeof;
51 this.initiatorColumns = [
53 name: $localize`Initiator`,
55 cellTemplate: this.hostTpl
60 name: this.actionLabels.ADD,
65 [BASE_URL, { outlets: { modal: [URLVerbs.ADD, this.subsystemNQN, 'initiator'] } }],
66 { queryParams: { group: this.group } }
68 canBePrimary: (selection: CdTableSelection) => !selection.hasSelection
71 name: this.actionLabels.REMOVE,
74 click: () => this.removeInitiatorModal(),
75 disable: () => !this.selection.hasSelection,
76 canBePrimary: (selection: CdTableSelection) => selection.hasSelection
81 getAllowAllHostIndex() {
82 return this.selection.selected.findIndex((selected) => selected.nqn === '*');
85 updateSelection(selection: CdTableSelection) {
86 this.selection = selection;
91 .getInitiators(this.subsystemNQN, this.group)
92 .subscribe((initiators: NvmeofSubsystemInitiator[]) => {
93 this.initiators = initiators;
98 return this.selection.selected.map((selected) => selected.nqn);
101 removeInitiatorModal() {
102 const hostNQNs = this.getSelectedNQNs();
103 const allowAllHostIndex = this.getAllowAllHostIndex();
104 const host_nqn = hostNQNs.join(',');
105 let itemNames = hostNQNs;
106 if (allowAllHostIndex !== -1) {
107 hostNQNs.splice(allowAllHostIndex, 1);
108 itemNames = [...hostNQNs, $localize`Allow any host(*)`];
110 this.modalService.show(DeleteConfirmationModalComponent, {
111 itemDescription: 'Initiator',
113 actionDescription: 'remove',
114 submitActionObservable: () =>
115 this.taskWrapper.wrapTaskAroundCall({
116 task: new FinishedTask('nvmeof/initiator/remove', {
117 nqn: this.subsystemNQN,
118 plural: itemNames.length > 1
120 call: this.nvmeofService.removeInitiators(this.subsystemNQN, {