diff --git a/ui-ngx/src/app/modules/home/components/integration/configuration/integration-configuration.component.html b/ui-ngx/src/app/modules/home/components/integration/configuration/integration-configuration.component.html index 862272a234..1e8f3c18ca 100644 --- a/ui-ngx/src/app/modules/home/components/integration/configuration/integration-configuration.component.html +++ b/ui-ngx/src/app/modules/home/components/integration/configuration/integration-configuration.component.html @@ -54,6 +54,7 @@ @case (integrationTypes.KPN) { diff --git a/ui-ngx/src/app/modules/home/components/integration/configuration/kpn-integration-form/kpn-integration-form.component.html b/ui-ngx/src/app/modules/home/components/integration/configuration/kpn-integration-form/kpn-integration-form.component.html index 93abe68e16..fb90406628 100644 --- a/ui-ngx/src/app/modules/home/components/integration/configuration/kpn-integration-form/kpn-integration-form.component.html +++ b/ui-ngx/src/app/modules/home/components/integration/configuration/kpn-integration-form/kpn-integration-form.component.html @@ -35,30 +35,19 @@ - - - - - {{ 'integration.allow-downlink' | translate }} - - - - -
-
- integration.credentials -
- - - - -
-
-
-
-
+ @if (isSetDownlink) { +
+ integration.downlink-credentials +
+ + + + +
+
+ } diff --git a/ui-ngx/src/app/modules/home/components/integration/configuration/kpn-integration-form/kpn-integration-form.component.ts b/ui-ngx/src/app/modules/home/components/integration/configuration/kpn-integration-form/kpn-integration-form.component.ts index 96c2777002..011eaee7b7 100644 --- a/ui-ngx/src/app/modules/home/components/integration/configuration/kpn-integration-form/kpn-integration-form.component.ts +++ b/ui-ngx/src/app/modules/home/components/integration/configuration/kpn-integration-form/kpn-integration-form.component.ts @@ -50,10 +50,24 @@ export class KpnIntegrationFormComponent extends IntegrationForm implements Cont @Input() routingKey: string; + @Input() + set isSetDownlink(value: boolean) { + if (this.isSetDownlinkValue !== value) { + this.isSetDownlinkValue = value; + this.updateCredentialsValidators(); + } + } + + get isSetDownlink(): boolean { + return this.isSetDownlinkValue; + } + private integrationType = IntegrationType.KPN; + private isSetDownlinkValue = false; private propagateChangePending = false; private propagateChange = (v: any) => { }; + private validatorChange = () => { }; constructor(private fb: UntypedFormBuilder, private store: Store, @@ -75,20 +89,14 @@ export class KpnIntegrationFormComponent extends IntegrationForm implements Cont }], enableSecurity: [false], headersFilter: [{}], - allowDownlink: [false], - apiId:[], - apiKey:[] + apiId: [], + apiKey: [] }); this.kpnIntegrationConfigForm.get('baseUrl').valueChanges.pipe( takeUntil(this.destroy$) ).subscribe((value) => { const httpEndpoint = integrationEndPointUrl(this.integrationType, value, this.routingKey); this.kpnIntegrationConfigForm.get('httpEndpoint').patchValue(httpEndpoint); - }); - this.kpnIntegrationConfigForm.get('allowDownlink').valueChanges.pipe( - takeUntil(this.destroy$) - ).subscribe(() => { - this.updateEnableFields(); }); this.kpnIntegrationConfigForm.valueChanges.pipe( takeUntil(this.destroy$) @@ -96,14 +104,12 @@ export class KpnIntegrationFormComponent extends IntegrationForm implements Cont this.updateModels(this.kpnIntegrationConfigForm.getRawValue()); }); this.kpnIntegrationConfigForm.removeControl('replaceNoContentToOk', {emitEvent: false}); + this.updateCredentialsValidators(); } writeValue(value: KpnIntegration) { if (isDefinedAndNotNull(value)) { this.kpnIntegrationConfigForm.reset(value, {emitEvent: false}); - if (!this.disabled) { - this.updateEnableFields(); - } } else { this.propagateChangePending = true; } @@ -121,13 +127,16 @@ export class KpnIntegrationFormComponent extends IntegrationForm implements Cont registerOnTouched(fn: any) { } + registerOnValidatorChange(fn: () => void) { + this.validatorChange = fn; + } + setDisabledState(isDisabled: boolean) { this.disabled = isDisabled; if (isDisabled) { this.kpnIntegrationConfigForm.disable({emitEvent: false}); } else { this.kpnIntegrationConfigForm.enable({emitEvent: false}); - this.updateEnableFields(); this.kpnIntegrationConfigForm.get('httpEndpoint').disable({emitEvent: false}); } } @@ -154,22 +163,14 @@ export class KpnIntegrationFormComponent extends IntegrationForm implements Cont this.propagateChange(value); } - private updateEnableFields() { - const allowDownlink = this.kpnIntegrationConfigForm.get('allowDownlink').value; - if (allowDownlink) { - this.kpnIntegrationConfigForm.get('apiId').enable({emitEvent: false}); - this.kpnIntegrationConfigForm.get('apiKey').enable({emitEvent: false}); - this.kpnIntegrationConfigForm.get('apiId').setValidators(Validators.required); - this.kpnIntegrationConfigForm.get('apiKey').setValidators(Validators.required); - } else { - this.kpnIntegrationConfigForm.get('apiId').disable({emitEvent: false}); - this.kpnIntegrationConfigForm.get('apiKey').disable({emitEvent: false}); - this.kpnIntegrationConfigForm.get('apiId').clearValidators(); - this.kpnIntegrationConfigForm.get('apiKey').clearValidators(); - + private updateCredentialsValidators() { + if (this.kpnIntegrationConfigForm) { + const validators = this.isSetDownlink ? [Validators.required] : []; + this.kpnIntegrationConfigForm.get('apiId').setValidators(validators); + this.kpnIntegrationConfigForm.get('apiKey').setValidators(validators); + this.kpnIntegrationConfigForm.get('apiId').updateValueAndValidity({emitEvent: false}); + this.kpnIntegrationConfigForm.get('apiKey').updateValueAndValidity({emitEvent: false}); + this.validatorChange(); } - this.kpnIntegrationConfigForm.get('apiId').updateValueAndValidity({emitEvent: false}); - this.kpnIntegrationConfigForm.get('apiKey').updateValueAndValidity({emitEvent: false}); - this.kpnIntegrationConfigForm.get('destinationSharedSecret').updateValueAndValidity({emitEvent: false}); } } diff --git a/ui-ngx/src/assets/locale/locale.constant-en_US.json b/ui-ngx/src/assets/locale/locale.constant-en_US.json index a000ee8696..367b4709eb 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -5578,6 +5578,7 @@ "credentials": "Credentials", "credentials-type": "Credentials type", "credentials-type-required": "Credentials type is required.", + "downlink-credentials": "Downlink credentials", "username": "Username", "username-required": "Username is required.", "password": "Password",