]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-form-client/nfs-form-client.component.ts
bump version to 16.2.6-pve2
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / nfs / nfs-form-client / nfs-form-client.component.ts
1 import { Component, Input, OnInit } from '@angular/core';
2 import { FormArray, FormControl, NgForm, Validators } from '@angular/forms';
3
4 import _ from 'lodash';
5
6 import { NfsService } from '~/app/shared/api/nfs.service';
7 import { Icons } from '~/app/shared/enum/icons.enum';
8 import { CdFormGroup } from '~/app/shared/forms/cd-form-group';
9
10 @Component({
11 selector: 'cd-nfs-form-client',
12 templateUrl: './nfs-form-client.component.html',
13 styleUrls: ['./nfs-form-client.component.scss']
14 })
15 export class NfsFormClientComponent implements OnInit {
16 @Input()
17 form: CdFormGroup;
18
19 @Input()
20 clients: any[];
21
22 nfsSquash: any[] = this.nfsService.nfsSquash;
23 nfsAccessType: any[] = this.nfsService.nfsAccessType;
24 icons = Icons;
25
26 constructor(private nfsService: NfsService) {}
27
28 ngOnInit() {
29 _.forEach(this.clients, (client) => {
30 const fg = this.addClient();
31 fg.patchValue(client);
32 });
33 }
34
35 getNoAccessTypeDescr() {
36 if (this.form.getValue('access_type')) {
37 return `${this.form.getValue('access_type')} ${$localize`(inherited from global config)`}`;
38 }
39 return $localize`-- Select the access type --`;
40 }
41
42 getAccessTypeHelp(index: number) {
43 const accessTypeItem = this.nfsAccessType.find((currentAccessTypeItem) => {
44 return this.getValue(index, 'access_type') === currentAccessTypeItem.value;
45 });
46 return _.isObjectLike(accessTypeItem) ? accessTypeItem.help : '';
47 }
48
49 getNoSquashDescr() {
50 if (this.form.getValue('squash')) {
51 return `${this.form.getValue('squash')} (${$localize`inherited from global config`})`;
52 }
53 return $localize`-- Select what kind of user id squashing is performed --`;
54 }
55
56 addClient() {
57 const clients = this.form.get('clients') as FormArray;
58
59 const REGEX_IP = `(([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})\.([0-9]{1,3})([/](\\d|[1-2]\\d|3[0-2]))?)`;
60 const REGEX_LIST_IP = `${REGEX_IP}([ ,]{1,2}${REGEX_IP})*`;
61
62 const fg = new CdFormGroup({
63 addresses: new FormControl('', {
64 validators: [Validators.required, Validators.pattern(REGEX_LIST_IP)]
65 }),
66 access_type: new FormControl(''),
67 squash: new FormControl('')
68 });
69
70 clients.push(fg);
71 return fg;
72 }
73
74 removeClient(index: number) {
75 const clients = this.form.get('clients') as FormArray;
76 clients.removeAt(index);
77 }
78
79 showError(index: number, control: string, formDir: NgForm, x: string) {
80 return (<any>this.form.controls.clients).controls[index].showError(control, formDir, x);
81 }
82
83 getValue(index: number, control: string) {
84 const clients = this.form.get('clients') as FormArray;
85 const client = clients.at(index) as CdFormGroup;
86 return client.getValue(control);
87 }
88
89 trackByFn(index: number) {
90 return index;
91 }
92 }