1 import { Component, OnInit } from '@angular/core';
2 import { 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 { 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';
18 const BASE_URL = 'block/nvmeof/subsystems';
21 selector: 'cd-nvmeof-subsystems',
22 templateUrl: './nvmeof-subsystems.component.html',
23 styleUrls: ['./nvmeof-subsystems.component.scss']
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[];
34 private nvmeofService: NvmeofService,
35 private authStorageService: AuthStorageService,
36 public actionLabels: ActionLabelsI18n,
37 private router: Router,
38 private modalService: ModalService,
39 private taskWrapper: TaskWrapperService
42 this.permission = this.authStorageService.getPermissions().nvmeof;
46 this.subsystemsColumns = [
52 name: $localize`# Namespaces`,
53 prop: 'namespace_count'
56 name: $localize`# Maximum Allowed Namespaces`,
57 prop: 'max_namespaces'
62 name: this.actionLabels.CREATE,
65 click: () => this.router.navigate([BASE_URL, { outlets: { modal: [URLVerbs.CREATE] } }]),
66 canBePrimary: (selection: CdTableSelection) => !selection.hasSelection
69 name: this.actionLabels.DELETE,
72 click: () => this.deleteSubsystemModal()
77 updateSelection(selection: CdTableSelection) {
78 this.selection = selection;
84 .subscribe((subsystems: NvmeofSubsystem[] | NvmeofSubsystem) => {
85 if (Array.isArray(subsystems)) this.subsystems = subsystems;
86 else this.subsystems = [subsystems];
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)