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