1 import { Component, OnInit } from '@angular/core';
2 import { ActivatedRoute, Router } from '@angular/router';
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 { Permissions } 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 { DeleteConfirmationModalComponent } from '~/app/shared/components/delete-confirmation-modal/delete-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, GroupsComboboxItem } from '~/app/shared/api/nvmeof.service';
16 import { ModalCdsService } from '~/app/shared/services/modal-cds.service';
17 import { CephServiceSpec } from '~/app/shared/models/service.interface';
19 const BASE_URL = 'block/nvmeof/subsystems';
20 const DEFAULT_PLACEHOLDER = $localize`Enter group name`;
23 selector: 'cd-nvmeof-subsystems',
24 templateUrl: './nvmeof-subsystems.component.html',
25 styleUrls: ['./nvmeof-subsystems.component.scss'],
28 export class NvmeofSubsystemsComponent extends ListWithDetails implements OnInit {
29 subsystems: NvmeofSubsystem[] = [];
30 subsystemsColumns: any;
31 permissions: Permissions;
32 selection = new CdTableSelection();
33 tableActions: CdTableAction[];
34 subsystemDetails: any[];
35 gwGroups: GroupsComboboxItem[] = [];
37 gwGroupsEmpty: boolean = false;
38 gwGroupPlaceholder: string = DEFAULT_PLACEHOLDER;
41 private nvmeofService: NvmeofService,
42 private authStorageService: AuthStorageService,
43 public actionLabels: ActionLabelsI18n,
44 private router: Router,
45 private modalService: ModalCdsService,
46 private taskWrapper: TaskWrapperService,
47 private route: ActivatedRoute
50 this.permissions = this.authStorageService.getPermissions();
54 this.route.queryParams.subscribe((params) => {
55 if (params?.['group']) this.onGroupSelection({ content: params?.['group'] });
57 this.setGatewayGroups();
58 this.subsystemsColumns = [
64 name: $localize`# Namespaces`,
65 prop: 'namespace_count'
68 name: $localize`# Maximum Allowed Namespaces`,
69 prop: 'max_namespaces'
74 name: this.actionLabels.CREATE,
78 this.router.navigate([BASE_URL, { outlets: { modal: [URLVerbs.CREATE] } }], {
79 queryParams: { group: this.group }
81 canBePrimary: (selection: CdTableSelection) => !selection.hasSelection,
82 disable: () => !this.group
85 name: this.actionLabels.DELETE,
88 click: () => this.deleteSubsystemModal()
94 updateSelection(selection: CdTableSelection) {
95 this.selection = selection;
101 .listSubsystems(this.group)
102 .subscribe((subsystems: NvmeofSubsystem[] | NvmeofSubsystem) => {
103 if (Array.isArray(subsystems)) this.subsystems = subsystems;
104 else this.subsystems = [subsystems];
107 this.subsystems = [];
111 deleteSubsystemModal() {
112 const subsystem = this.selection.first();
113 this.modalService.show(DeleteConfirmationModalComponent, {
114 itemDescription: 'Subsystem',
115 itemNames: [subsystem.nqn],
116 actionDescription: 'delete',
117 submitActionObservable: () =>
118 this.taskWrapper.wrapTaskAroundCall({
119 task: new FinishedTask('nvmeof/subsystem/delete', { nqn: subsystem.nqn }),
120 call: this.nvmeofService.deleteSubsystem(subsystem.nqn, this.group)
126 onGroupSelection(selected: GroupsComboboxItem) {
127 selected.selected = true;
128 this.group = selected.content;
129 this.getSubsystems();
134 this.getSubsystems();
138 this.nvmeofService.listGatewayGroups().subscribe((response: CephServiceSpec[][]) => {
139 if (response?.[0]?.length) {
140 this.gwGroups = this.nvmeofService.formatGwGroupsList(response);
141 } else this.gwGroups = [];
142 // Select first group if no group is selected
143 if (!this.group && this.gwGroups.length) {
144 this.onGroupSelection(this.gwGroups[0]);
145 this.gwGroupsEmpty = false;
146 this.gwGroupPlaceholder = DEFAULT_PLACEHOLDER;
148 this.gwGroupsEmpty = true;
149 this.gwGroupPlaceholder = $localize`No groups available`;