]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/blob
7f17d7da1c4e5d4f74260be349578c80b0b1a967
[ceph-ci.git] /
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';
4
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';
13
14 export type SubsystemPayload = {
15   nqn: string;
16   gw_group: string;
17 };
18
19 @Component({
20   selector: 'cd-nvmeof-subsystems-form',
21   templateUrl: './nvmeof-subsystems-form.component.html',
22   styleUrls: ['./nvmeof-subsystems-form.component.scss'],
23   standalone: false
24 })
25 export class NvmeofSubsystemsFormComponent implements OnInit {
26   subsystemForm: CdFormGroup;
27   action: string;
28   group: string;
29   steps: Step[] = [
30     {
31       label: $localize`Subsystem details`,
32       complete: false,
33       invalid: false
34     },
35     {
36       label: $localize`Host access control`,
37       complete: false
38     },
39     {
40       label: $localize`Authentication`,
41       complete: false
42     },
43     {
44       label: $localize`Advanced options`,
45       complete: false,
46       secondaryLabel: $localize`Advanced`
47     }
48   ];
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;
52
53   @ViewChild(TearsheetComponent) tearsheet!: TearsheetComponent;
54
55   constructor(
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
63   ) {}
64
65   ngOnInit() {
66     this.route.queryParams.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((params) => {
67       this.group = params?.['group'];
68     });
69   }
70
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
77       .wrapTaskAroundCall({
78         task: new FinishedTask(taskUrl, {
79           nqn: payload.nqn
80         }),
81         call: this.nvmeofService.createSubsystem({ ...payload, enable_ha: true })
82       })
83       .subscribe({
84         error() {
85           component.isSubmitLoading = false;
86         },
87         complete: () => {
88           component.isSubmitLoading = false;
89           this.router.navigate([pageURL, { outlets: { modal: null } }]);
90         }
91       });
92   }
93 }