1 import { Component, Input, OnChanges, OnInit } 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 { 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 { CdTableSelection } from '~/app/shared/models/cd-table-selection';
10 import { FinishedTask } from '~/app/shared/models/finished-task';
11 import { NvmeofListener } from '~/app/shared/models/nvmeof';
12 import { Permission } from '~/app/shared/models/permissions';
13 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
14 import { ModalCdsService } from '~/app/shared/services/modal-cds.service';
15 import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
17 const BASE_URL = 'block/nvmeof/subsystems';
20 selector: 'cd-nvmeof-listeners-list',
21 templateUrl: './nvmeof-listeners-list.component.html',
22 styleUrls: ['./nvmeof-listeners-list.component.scss']
24 export class NvmeofListenersListComponent implements OnInit, OnChanges {
31 tableActions: CdTableAction[];
32 selection = new CdTableSelection();
33 permission: Permission;
34 listeners: NvmeofListener[];
37 public actionLabels: ActionLabelsI18n,
38 private modalService: ModalCdsService,
39 private authStorageService: AuthStorageService,
40 private taskWrapper: TaskWrapperService,
41 private nvmeofService: NvmeofService,
42 private router: Router
44 this.permission = this.authStorageService.getPermissions().nvmeof;
48 this.listenerColumns = [
50 name: $localize`Host`,
54 name: $localize`Transport`,
58 name: $localize`Address`,
60 cellTransformation: CellTemplate.copy
65 name: this.actionLabels.CREATE,
70 [BASE_URL, { outlets: { modal: [URLVerbs.CREATE, this.subsystemNQN, 'listener'] } }],
71 { queryParams: { group: this.group } }
73 canBePrimary: (selection: CdTableSelection) => !selection.hasSelection
76 name: this.actionLabels.DELETE,
79 click: () => this.deleteSubsystemModal()
88 updateSelection(selection: CdTableSelection) {
89 this.selection = selection;
94 .listListeners(this.subsystemNQN)
95 .subscribe((listResponse: NvmeofListener[]) => {
96 this.listeners = listResponse.map((listener, index) => {
97 listener['id'] = index;
98 listener['full_addr'] = `${listener.traddr}:${listener.trsvcid}`;
104 deleteSubsystemModal() {
105 const listener = this.selection.first();
106 this.modalService.show(CriticalConfirmationModalComponent, {
107 itemDescription: 'Listener',
108 actionDescription: 'delete',
109 itemNames: [`listener ${listener.host_name} (${listener.traddr}:${listener.trsvcid})`],
110 submitActionObservable: () =>
111 this.taskWrapper.wrapTaskAroundCall({
112 task: new FinishedTask('nvmeof/listener/delete', {
113 nqn: this.subsystemNQN,
114 host_name: listener.host_name
116 call: this.nvmeofService.deleteListener(