]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
1de2883b1dd05201cbdfb7c684cb2bab33b9164a
[ceph.git] /
1 import { Component, OnInit } from '@angular/core';
2 import { Router } from '@angular/router';
3
4 import { ActionLabelsI18n, URLVerbs } from '~/app/shared/constants/app.constants';
5 import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
6 import { NvmeofSubsystem } from '~/app/shared/models/nvmeof';
7 import { Permission } from '~/app/shared/models/permissions';
8 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
9 import { ListWithDetails } from '~/app/shared/classes/list-with-details.class';
10 import { CdTableAction } from '~/app/shared/models/cd-table-action';
11 import { Icons } from '~/app/shared/enum/icons.enum';
12 import { CriticalConfirmationModalComponent } from '~/app/shared/components/critical-confirmation-modal/critical-confirmation-modal.component';
13 import { FinishedTask } from '~/app/shared/models/finished-task';
14 import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
15 import { NvmeofService } from '~/app/shared/api/nvmeof.service';
16 import { ModalCdsService } from '~/app/shared/services/modal-cds.service';
17
18 const BASE_URL = 'block/nvmeof/subsystems';
19
20 @Component({
21   selector: 'cd-nvmeof-subsystems',
22   templateUrl: './nvmeof-subsystems.component.html',
23   styleUrls: ['./nvmeof-subsystems.component.scss']
24 })
25 export class NvmeofSubsystemsComponent extends ListWithDetails implements OnInit {
26   subsystems: NvmeofSubsystem[] = [];
27   subsystemsColumns: any;
28   permission: Permission;
29   selection = new CdTableSelection();
30   tableActions: CdTableAction[];
31   subsystemDetails: any[];
32
33   constructor(
34     private nvmeofService: NvmeofService,
35     private authStorageService: AuthStorageService,
36     public actionLabels: ActionLabelsI18n,
37     private router: Router,
38     private modalService: ModalCdsService,
39     private taskWrapper: TaskWrapperService
40   ) {
41     super();
42     this.permission = this.authStorageService.getPermissions().nvmeof;
43   }
44
45   ngOnInit() {
46     this.subsystemsColumns = [
47       {
48         name: $localize`NQN`,
49         prop: 'nqn'
50       },
51       {
52         name: $localize`# Namespaces`,
53         prop: 'namespace_count'
54       },
55       {
56         name: $localize`# Maximum Allowed Namespaces`,
57         prop: 'max_namespaces'
58       }
59     ];
60     this.tableActions = [
61       {
62         name: this.actionLabels.CREATE,
63         permission: 'create',
64         icon: Icons.add,
65         click: () => this.router.navigate([BASE_URL, { outlets: { modal: [URLVerbs.CREATE] } }]),
66         canBePrimary: (selection: CdTableSelection) => !selection.hasSelection
67       },
68       {
69         name: this.actionLabels.EDIT,
70         permission: 'update',
71         icon: Icons.edit,
72         click: () =>
73           this.router.navigate([
74             BASE_URL,
75             {
76               outlets: {
77                 modal: [
78                   URLVerbs.EDIT,
79                   this.selection.first().nqn,
80                   this.selection.first().max_namespaces
81                 ]
82               }
83             }
84           ])
85       },
86       {
87         name: this.actionLabels.DELETE,
88         permission: 'delete',
89         icon: Icons.destroy,
90         click: () => this.deleteSubsystemModal()
91       }
92     ];
93   }
94
95   updateSelection(selection: CdTableSelection) {
96     this.selection = selection;
97   }
98
99   getSubsystems() {
100     this.nvmeofService
101       .listSubsystems()
102       .subscribe((subsystems: NvmeofSubsystem[] | NvmeofSubsystem) => {
103         if (Array.isArray(subsystems)) this.subsystems = subsystems;
104         else this.subsystems = [subsystems];
105       });
106   }
107
108   deleteSubsystemModal() {
109     const subsystem = this.selection.first();
110     this.modalService.show(CriticalConfirmationModalComponent, {
111       itemDescription: 'Subsystem',
112       itemNames: [subsystem.nqn],
113       actionDescription: 'delete',
114       submitActionObservable: () =>
115         this.taskWrapper.wrapTaskAroundCall({
116           task: new FinishedTask('nvmeof/subsystem/delete', { nqn: subsystem.nqn }),
117           call: this.nvmeofService.deleteSubsystem(subsystem.nqn)
118         })
119     });
120   }
121 }