1 import { Component, DestroyRef, OnInit, ViewChild } from '@angular/core';
2 import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
3 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
5 import { ActionLabelsI18n, URLVerbs } from '~/app/shared/constants/app.constants';
6 import { CdFormGroup } from '~/app/shared/forms/cd-form-group';
7 import { ActivatedRoute, Router } from '@angular/router';
8 import { Step } from 'carbon-components-angular';
9 import { FinishedTask } from '~/app/shared/models/finished-task';
10 import { NvmeofService } from '~/app/shared/api/nvmeof.service';
11 import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
12 import { TearsheetComponent } from '~/app/shared/components/tearsheet/tearsheet.component';
14 export type SubsystemPayload = {
17 subsystemDchapKey: string;
21 selector: 'cd-nvmeof-subsystems-form',
22 templateUrl: './nvmeof-subsystems-form.component.html',
23 styleUrls: ['./nvmeof-subsystems-form.component.scss'],
26 export class NvmeofSubsystemsFormComponent implements OnInit {
27 subsystemForm: CdFormGroup;
32 label: $localize`Subsystem details`,
37 label: $localize`Host access control`,
41 label: $localize`Authentication`,
45 label: $localize`Advanced options`,
47 secondaryLabel: $localize`Advanced`
50 title: string = $localize`Create Subsystem`;
51 description: string = $localize`Subsytems define how hosts connect to NVMe namespaces and ensure secure access to storage.`;
52 isSubmitLoading: boolean = false;
54 @ViewChild(TearsheetComponent) tearsheet!: TearsheetComponent;
57 public actionLabels: ActionLabelsI18n,
58 public activeModal: NgbActiveModal,
59 private route: ActivatedRoute,
60 private destroyRef: DestroyRef,
61 private nvmeofService: NvmeofService,
62 private taskWrapperService: TaskWrapperService,
63 private router: Router
67 this.route.queryParams.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((params) => {
68 this.group = params?.['group'];
72 onSubmit(payload: SubsystemPayload) {
73 const component = this;
74 const pageURL = 'block/nvmeof/subsystems';
75 let taskUrl = `nvmeof/subsystem/${URLVerbs.CREATE}`;
76 this.isSubmitLoading = true;
77 this.taskWrapperService
79 task: new FinishedTask(taskUrl, {
82 call: this.nvmeofService.createSubsystem({
85 dhchap_key: payload.subsystemDchapKey,
91 component.isSubmitLoading = false;
94 component.isSubmitLoading = false;
95 this.router.navigate([pageURL, { outlets: { modal: null } }]);