1 import { Component, OnInit } from '@angular/core';
2 import { UntypedFormControl, Validators } from '@angular/forms';
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 { CdValidators } from '~/app/shared/forms/cd-validators';
8 import { Permission } from '~/app/shared/models/permissions';
9 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
10 import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
11 import { FinishedTask } from '~/app/shared/models/finished-task';
12 import { Router } from '@angular/router';
13 import { NvmeofService } from '~/app/shared/api/nvmeof.service';
16 selector: 'cd-nvmeof-subsystems-form',
17 templateUrl: './nvmeof-subsystems-form.component.html',
18 styleUrls: ['./nvmeof-subsystems-form.component.scss']
20 export class NvmeofSubsystemsFormComponent implements OnInit {
21 permission: Permission;
22 subsystemForm: CdFormGroup;
28 NQN_REGEX = /^nqn\.(19|20)\d\d-(0[1-9]|1[0-2])\.\D{2,3}(\.[A-Za-z0-9-]+)+(:[A-Za-z0-9-\.]+)$/;
31 private authStorageService: AuthStorageService,
32 public actionLabels: ActionLabelsI18n,
33 public activeModal: NgbActiveModal,
34 private nvmeofService: NvmeofService,
35 private taskWrapperService: TaskWrapperService,
36 private router: Router
38 this.permission = this.authStorageService.getPermissions().nvmeof;
39 this.resource = $localize`Subsystem`;
40 this.pageURL = 'block/nvmeof/subsystems';
45 this.action = this.actionLabels.CREATE;
49 this.subsystemForm = new CdFormGroup({
50 nqn: new UntypedFormControl('nqn.2001-07.com.ceph:' + Date.now(), {
53 Validators.pattern(this.NQN_REGEX),
56 (nqnInput: string) => new TextEncoder().encode(nqnInput).length > 223
60 CdValidators.unique(this.nvmeofService.isSubsystemPresent, this.nvmeofService)
63 max_namespaces: new UntypedFormControl(256, {
64 validators: [CdValidators.number(false), Validators.max(256), Validators.min(1)]
70 const component = this;
71 const nqn: string = this.subsystemForm.getValue('nqn');
72 let max_namespaces: number = Number(this.subsystemForm.getValue('max_namespaces'));
80 if (!max_namespaces) {
81 delete request.max_namespaces;
84 let taskUrl = `nvmeof/subsystem/${URLVerbs.CREATE}`;
86 this.taskWrapperService
88 task: new FinishedTask(taskUrl, {
91 call: this.nvmeofService.createSubsystem(request)
95 component.subsystemForm.setErrors({ cdSubmitButton: true });
98 this.router.navigate([this.pageURL, { outlets: { modal: null } }]);