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 { 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 { 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 } 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';
24 const BASE_URL = 'block/nvmeof/subsystems';
27 selector: 'cd-nvmeof-subsystems',
28 templateUrl: './nvmeof-subsystems.component.html',
29 styleUrls: ['./nvmeof-subsystems.component.scss']
31 export class NvmeofSubsystemsComponent extends ListWithDetails implements OnInit {
32 subsystems: NvmeofSubsystem[] = [];
33 subsystemsColumns: any;
34 permission: Permission;
35 selection = new CdTableSelection();
36 tableActions: CdTableAction[];
37 subsystemDetails: any[];
38 gwGroups: ComboBoxItem[] = [];
42 private nvmeofService: NvmeofService,
43 private authStorageService: AuthStorageService,
44 public actionLabels: ActionLabelsI18n,
45 private router: Router,
46 private modalService: ModalCdsService,
47 private taskWrapper: TaskWrapperService,
48 private route: ActivatedRoute
51 this.permission = this.authStorageService.getPermissions().nvmeof;
55 this.route.queryParams.subscribe((params) => {
56 if (params?.['group']) this.onGroupSelection({ content: params?.['group'] });
58 this.getGatewayGroups();
59 this.subsystemsColumns = [
65 name: $localize`# Namespaces`,
66 prop: 'namespace_count'
69 name: $localize`# Maximum Allowed Namespaces`,
70 prop: 'max_namespaces'
75 name: this.actionLabels.CREATE,
79 this.router.navigate([BASE_URL, { outlets: { modal: [URLVerbs.CREATE] } }], {
80 queryParams: { group: this.group }
82 canBePrimary: (selection: CdTableSelection) => !selection.hasSelection,
83 disable: () => !this.group
86 name: this.actionLabels.DELETE,
89 click: () => this.deleteSubsystemModal()
95 updateSelection(selection: CdTableSelection) {
96 this.selection = selection;
102 .listSubsystems(this.group)
103 .subscribe((subsystems: NvmeofSubsystem[] | NvmeofSubsystem) => {
104 if (Array.isArray(subsystems)) this.subsystems = subsystems;
105 else this.subsystems = [subsystems];
108 this.subsystems = [];
112 deleteSubsystemModal() {
113 const subsystem = this.selection.first();
114 this.modalService.show(DeleteConfirmationModalComponent, {
115 itemDescription: 'Subsystem',
116 itemNames: [subsystem.nqn],
117 actionDescription: 'delete',
118 submitActionObservable: () =>
119 this.taskWrapper.wrapTaskAroundCall({
120 task: new FinishedTask('nvmeof/subsystem/delete', { nqn: subsystem.nqn }),
121 call: this.nvmeofService.deleteSubsystem(subsystem.nqn, this.group)
127 onGroupSelection(selected: ComboBoxItem) {
128 selected.selected = true;
129 this.group = selected.content;
130 this.getSubsystems();
135 this.getSubsystems();
139 this.nvmeofService.listGatewayGroups().subscribe((response: CephServiceSpec[][]) => {
140 if (response?.[0].length) {
141 this.gwGroups = response[0].map((group: CephServiceSpec) => {
143 content: group?.spec?.group
147 // Select first group if no group is selected
148 if (!this.group && this.gwGroups.length) this.onGroupSelection(this.gwGroups[0]);