]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-form-client/nfs-form-client.component.ts
import ceph nautilus 14.2.2
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / nfs / nfs-form-client / nfs-form-client.component.ts
CommitLineData
11fdf7f2
TL
1import { Component, Input } from '@angular/core';
2import { FormArray, FormControl, Validators } from '@angular/forms';
3
4import { I18n } from '@ngx-translate/i18n-polyfill';
5import * as _ from 'lodash';
6
7import { NfsService } from '../../../shared/api/nfs.service';
8import { CdFormGroup } from '../../../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})
15export class NfsFormClientComponent {
16 @Input()
17 form: CdFormGroup;
18
19 nfsSquash: any[] = this.nfsService.nfsSquash;
20 nfsAccessType: any[] = this.nfsService.nfsAccessType;
21
22 constructor(private nfsService: NfsService, private i18n: I18n) {}
23
24 getNoAccessTypeDescr() {
25 if (this.form.getValue('access_type')) {
26 return `${this.form.getValue('access_type')} ${this.i18n('(inherited from global config)')}`;
27 }
28 return this.i18n('-- Select the access type --');
29 }
30
31 getAccessTypeHelp(index) {
32 const accessTypeItem = this.nfsAccessType.find((currentAccessTypeItem) => {
33 return this.getValue(index, 'access_type') === currentAccessTypeItem.value;
34 });
35 return _.isObjectLike(accessTypeItem) ? accessTypeItem.help : '';
36 }
37
38 getNoSquashDescr() {
39 if (this.form.getValue('squash')) {
40 return `${this.form.getValue('squash')} (${this.i18n('inherited from global config')})`;
41 }
42 return this.i18n('-- Select what kind of user id squashing is performed --');
43 }
44
45 addClient() {
46 const clients = this.form.get('clients') as FormArray;
47
48 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]))?)`;
49 const REGEX_LIST_IP = `${REGEX_IP}([ ,]{1,2}${REGEX_IP})*`;
50
51 const fg = new CdFormGroup({
52 addresses: new FormControl('', {
53 validators: [Validators.required, Validators.pattern(REGEX_LIST_IP)]
54 }),
81eedcae
TL
55 access_type: new FormControl(''),
56 squash: new FormControl('')
11fdf7f2
TL
57 });
58
59 clients.push(fg);
60 return fg;
61 }
62
63 removeClient(index) {
64 const clients = this.form.get('clients') as FormArray;
65 clients.removeAt(index);
66 }
67
68 showError(index, control, formDir, x) {
69 return (<any>this.form.controls.clients).controls[index].showError(control, formDir, x);
70 }
71
72 getValue(index, control) {
73 const clients = this.form.get('clients') as FormArray;
74 const client = clients.at(index) as CdFormGroup;
75 return client.getValue(control);
76 }
77
78 resolveModel(clients: any[]) {
79 _.forEach(clients, (client) => {
80 const fg = this.addClient();
81 fg.patchValue(client);
82 });
83 }
84
85 trackByFn(index) {
86 return index;
87 }
88}