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 = {
20 selector: 'cd-nvmeof-subsystems-form',
21 templateUrl: './nvmeof-subsystems-form.component.html',
22 styleUrls: ['./nvmeof-subsystems-form.component.scss'],
25 export class NvmeofSubsystemsFormComponent implements OnInit {
26 subsystemForm: CdFormGroup;
31 label: $localize`Subsystem details`,
36 label: $localize`Host access control`,
40 label: $localize`Authentication`,
44 label: $localize`Advanced options`,
46 secondaryLabel: $localize`Advanced`
49 title: string = $localize`Create Subsystem`;
50 description: string = $localize`Subsytems define how hosts connect to NVMe namespaces and ensure secure access to storage.`;
51 isSubmitLoading: boolean = false;
53 @ViewChild(TearsheetComponent) tearsheet!: TearsheetComponent;
56 public actionLabels: ActionLabelsI18n,
57 public activeModal: NgbActiveModal,
58 private route: ActivatedRoute,
59 private destroyRef: DestroyRef,
60 private nvmeofService: NvmeofService,
61 private taskWrapperService: TaskWrapperService,
62 private router: Router
66 this.route.queryParams.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((params) => {
67 this.group = params?.['group'];
71 onSubmit(payload: SubsystemPayload) {
72 const component = this;
73 const pageURL = 'block/nvmeof/subsystems';
74 let taskUrl = `nvmeof/subsystem/${URLVerbs.CREATE}`;
75 this.isSubmitLoading = true;
76 this.taskWrapperService
78 task: new FinishedTask(taskUrl, {
81 call: this.nvmeofService.createSubsystem({ ...payload, enable_ha: true })
85 component.isSubmitLoading = false;
88 component.isSubmitLoading = false;
89 this.router.navigate([pageURL, { outlets: { modal: null } }]);