1 import { ChangeDetectorRef, Component, Inject, OnInit, Optional } from '@angular/core';
2 import { FormArray, FormControl, FormGroup, UntypedFormControl, Validators } from '@angular/forms';
3 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
4 import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
5 import { CdFormGroup } from '~/app/shared/forms/cd-form-group';
6 import { CdValidators } from '~/app/shared/forms/cd-validators';
8 import { NotificationService } from '~/app/shared/services/notification.service';
9 import { RgwRealmService } from '~/app/shared/api/rgw-realm.service';
10 import { SmbService } from '~/app/shared/api/smb.service';
11 import { CdForm } from '~/app/shared/forms/cd-form';
12 import { DomainSettings } from '../smb.model';
15 selector: 'cd-smb-domain-setting-modal',
16 templateUrl: './smb-domain-setting-modal.component.html',
17 styleUrls: ['./smb-domain-setting-modal.component.scss']
19 export class SmbDomainSettingModalComponent extends CdForm implements OnInit {
20 domainSettingsForm: CdFormGroup;
24 public activeModal: NgbActiveModal,
25 public actionLabels: ActionLabelsI18n,
26 public rgwRealmService: RgwRealmService,
27 public notificationService: NotificationService,
28 public smbService: SmbService,
29 private cd: ChangeDetectorRef,
30 @Optional() @Inject('action') public action: string,
31 @Optional() @Inject('resource') public resource: string,
33 @Inject('domainSettingsObject')
34 public domainSettingsObject?: DomainSettings
37 this.action = this.actionLabels.UPDATE;
38 this.resource = $localize`Domain Setting`;
41 private createForm() {
42 this.domainSettingsForm = new CdFormGroup({
43 realm: new UntypedFormControl('', {
46 CdValidators.custom('uniqueName', (realm: string) => {
47 return this.realmNames && this.realmNames.indexOf(realm) !== -1;
51 join_sources: new FormArray([])
58 this.domainSettingsForm.get('realm').setValue(this.domainSettingsObject?.realm);
59 const join_sources = this.domainSettingsForm.get('join_sources') as FormArray;
61 if (this.domainSettingsObject?.join_sources) {
62 this.domainSettingsObject.join_sources.forEach((source: { ref: string }) => {
65 ref: new FormControl(source.ref || '', Validators.required)
71 if (!this.domainSettingsObject) {
72 this.join_sources.push(
74 ref: new FormControl('', Validators.required)
78 this.action = this.actionLabels.EDIT;
83 this.smbService.passData(this.domainSettingsForm.value);
88 return this.domainSettingsForm.get('join_sources') as FormArray;
92 this.join_sources.push(
94 ref: new FormControl('', Validators.required)
97 this.cd.detectChanges();
100 removeJoinSource(index: number) {
101 const join_sources = this.domainSettingsForm.get('join_sources') as FormArray;
103 if (index >= 0 && index < join_sources.length) {
104 join_sources.removeAt(index);
107 this.cd.detectChanges();