]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
b79dc51a88fccfefb9d1d88bb942367be93fdb3a
[ceph.git] /
1 import { Component, Input, OnInit } 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 { 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';
16
17 const BASE_URL = 'block/nvmeof/subsystems';
18
19 @Component({
20   selector: 'cd-nvmeof-listeners-list',
21   templateUrl: './nvmeof-listeners-list.component.html',
22   styleUrls: ['./nvmeof-listeners-list.component.scss']
23 })
24 export class NvmeofListenersListComponent implements OnInit {
25   @Input()
26   subsystemNQN: string;
27   @Input()
28   group: string;
29
30   listenerColumns: any;
31   tableActions: CdTableAction[];
32   selection = new CdTableSelection();
33   permission: Permission;
34   listeners: NvmeofListener[];
35
36   constructor(
37     public actionLabels: ActionLabelsI18n,
38     private modalService: ModalCdsService,
39     private authStorageService: AuthStorageService,
40     private taskWrapper: TaskWrapperService,
41     private nvmeofService: NvmeofService,
42     private router: Router
43   ) {
44     this.permission = this.authStorageService.getPermissions().nvmeof;
45   }
46
47   ngOnInit() {
48     this.listenerColumns = [
49       {
50         name: $localize`Host`,
51         prop: 'host_name'
52       },
53       {
54         name: $localize`Transport`,
55         prop: 'trtype'
56       },
57       {
58         name: $localize`Address`,
59         prop: 'full_addr',
60         cellTransformation: CellTemplate.copy
61       }
62     ];
63     this.tableActions = [
64       {
65         name: this.actionLabels.CREATE,
66         permission: 'create',
67         icon: Icons.add,
68         click: () =>
69           this.router.navigate(
70             [BASE_URL, { outlets: { modal: [URLVerbs.CREATE, this.subsystemNQN, 'listener'] } }],
71             { queryParams: { group: this.group } }
72           ),
73         canBePrimary: (selection: CdTableSelection) => !selection.hasSelection
74       },
75       {
76         name: this.actionLabels.DELETE,
77         permission: 'delete',
78         icon: Icons.destroy,
79         click: () => this.deleteListenerModal()
80       }
81     ];
82   }
83
84   updateSelection(selection: CdTableSelection) {
85     this.selection = selection;
86   }
87
88   listListeners() {
89     this.nvmeofService
90       .listListeners(this.subsystemNQN, this.group)
91       .subscribe((listResponse: NvmeofListener[]) => {
92         this.listeners = listResponse.map((listener, index) => {
93           listener['id'] = index;
94           listener['full_addr'] = `${listener.traddr}:${listener.trsvcid}`;
95           return listener;
96         });
97       });
98   }
99
100   deleteListenerModal() {
101     const listener = this.selection.first();
102     this.modalService.show(DeleteConfirmationModalComponent, {
103       itemDescription: $localize`Listener`,
104       actionDescription: 'delete',
105       itemNames: [
106         $localize`listener` + ' ' + `${listener.host_name} (${listener.traddr}:${listener.trsvcid})`
107       ],
108       submitActionObservable: () =>
109         this.taskWrapper.wrapTaskAroundCall({
110           task: new FinishedTask('nvmeof/listener/delete', {
111             nqn: this.subsystemNQN,
112             host_name: listener.host_name
113           }),
114           call: this.nvmeofService.deleteListener(
115             this.subsystemNQN,
116             this.group,
117             listener.host_name,
118             listener.traddr,
119             listener.trsvcid
120           )
121         })
122     });
123   }
124 }