]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
539551b5f80e965f5c35f886a3201f08dee4dafb
[ceph.git] /
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 { 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 { ModalService } from '~/app/shared/services/modal.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, OnChanges {
25   @Input()
26   subsystemNQN: string;
27
28   listenerColumns: any;
29   tableActions: CdTableAction[];
30   selection = new CdTableSelection();
31   permission: Permission;
32   listeners: NvmeofListener[];
33
34   constructor(
35     public actionLabels: ActionLabelsI18n,
36     private modalService: ModalService,
37     private authStorageService: AuthStorageService,
38     private taskWrapper: TaskWrapperService,
39     private nvmeofService: NvmeofService,
40     private router: Router
41   ) {
42     this.permission = this.authStorageService.getPermissions().nvmeof;
43   }
44
45   ngOnInit() {
46     this.listenerColumns = [
47       {
48         name: $localize`Host`,
49         prop: 'host_name'
50       },
51       {
52         name: $localize`Transport`,
53         prop: 'trtype'
54       },
55       {
56         name: $localize`Address`,
57         prop: 'full_addr',
58         cellTransformation: CellTemplate.copy
59       }
60     ];
61     this.tableActions = [
62       {
63         name: this.actionLabels.CREATE,
64         permission: 'create',
65         icon: Icons.add,
66         click: () =>
67           this.router.navigate([
68             BASE_URL,
69             { outlets: { modal: [URLVerbs.CREATE, this.subsystemNQN, 'listener'] } }
70           ]),
71         canBePrimary: (selection: CdTableSelection) => !selection.hasSelection
72       },
73       {
74         name: this.actionLabels.DELETE,
75         permission: 'delete',
76         icon: Icons.destroy,
77         click: () => this.deleteListenerModal()
78       }
79     ];
80   }
81
82   ngOnChanges() {
83     this.listListeners();
84   }
85
86   updateSelection(selection: CdTableSelection) {
87     this.selection = selection;
88   }
89
90   listListeners() {
91     this.nvmeofService
92       .listListeners(this.subsystemNQN)
93       .subscribe((listResponse: NvmeofListener[]) => {
94         this.listeners = listResponse.map((listener, index) => {
95           listener['id'] = index;
96           listener['full_addr'] = `${listener.traddr}:${listener.trsvcid}`;
97           return listener;
98         });
99       });
100   }
101
102   deleteListenerModal() {
103     const listener = this.selection.first();
104     this.modalService.show(DeleteConfirmationModalComponent, {
105       itemDescription: 'Listener',
106       actionDescription: 'delete',
107       itemNames: [`listener ${listener.host_name} (${listener.traddr}:${listener.trsvcid})`],
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             listener.host_name,
117             listener.traddr,
118             listener.trsvcid
119           )
120         })
121     });
122   }
123 }