1 import { Component, Input } from '@angular/core';
2 import { FormArray, FormControl, Validators } from '@angular/forms';
4 import { I18n } from '@ngx-translate/i18n-polyfill';
5 import * as _ from 'lodash';
7 import { NfsService } from '../../../shared/api/nfs.service';
8 import { CdFormGroup } from '../../../shared/forms/cd-form-group';
11 selector: 'cd-nfs-form-client',
12 templateUrl: './nfs-form-client.component.html',
13 styleUrls: ['./nfs-form-client.component.scss']
15 export class NfsFormClientComponent {
19 nfsSquash: any[] = this.nfsService.nfsSquash;
20 nfsAccessType: any[] = this.nfsService.nfsAccessType;
22 constructor(private nfsService: NfsService, private i18n: I18n) {}
24 getNoAccessTypeDescr() {
25 if (this.form.getValue('access_type')) {
26 return `${this.form.getValue('access_type')} ${this.i18n('(inherited from global config)')}`;
28 return this.i18n('-- Select the access type --');
31 getAccessTypeHelp(index) {
32 const accessTypeItem = this.nfsAccessType.find((currentAccessTypeItem) => {
33 return this.getValue(index, 'access_type') === currentAccessTypeItem.value;
35 return _.isObjectLike(accessTypeItem) ? accessTypeItem.help : '';
39 if (this.form.getValue('squash')) {
40 return `${this.form.getValue('squash')} (${this.i18n('inherited from global config')})`;
42 return this.i18n('-- Select what kind of user id squashing is performed --');
46 const clients = this.form.get('clients') as FormArray;
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})*`;
51 const fg = new CdFormGroup({
52 addresses: new FormControl('', {
53 validators: [Validators.required, Validators.pattern(REGEX_LIST_IP)]
55 access_type: new FormControl(''),
56 squash: new FormControl('')
64 const clients = this.form.get('clients') as FormArray;
65 clients.removeAt(index);
68 showError(index, control, formDir, x) {
69 return (<any>this.form.controls.clients).controls[index].showError(control, formDir, x);
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);
78 resolveModel(clients: any[]) {
79 _.forEach(clients, (client) => {
80 const fg = this.addClient();
81 fg.patchValue(client);