]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
8c4b3cbd26e9ae81e09351c4d134317cd99d17f4
[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 { ModalService } from '~/app/shared/services/modal.service';
15 import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
16 import { NvmeofService } from '~/app/shared/api/nvmeof.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: ModalService,
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.DELETE,
70         permission: 'delete',
71         icon: Icons.destroy,
72         click: () => this.deleteSubsystemModal()
73       }
74     ];
75   }
76
77   updateSelection(selection: CdTableSelection) {
78     this.selection = selection;
79   }
80
81   getSubsystems() {
82     this.nvmeofService
83       .listSubsystems()
84       .subscribe((subsystems: NvmeofSubsystem[] | NvmeofSubsystem) => {
85         if (Array.isArray(subsystems)) this.subsystems = subsystems;
86         else this.subsystems = [subsystems];
87       });
88   }
89
90   deleteSubsystemModal() {
91     const subsystem = this.selection.first();
92     this.modalService.show(CriticalConfirmationModalComponent, {
93       itemDescription: 'Subsystem',
94       itemNames: [subsystem.nqn],
95       actionDescription: 'delete',
96       submitActionObservable: () =>
97         this.taskWrapper.wrapTaskAroundCall({
98           task: new FinishedTask('nvmeof/subsystem/delete', { nqn: subsystem.nqn }),
99           call: this.nvmeofService.deleteSubsystem(subsystem.nqn)
100         })
101     });
102   }
103 }