1- import { Component } from '@angular/core' ;
1+ import { Component , OnInit } from '@angular/core' ;
2+ import { UtmConfigParamsService } from '../../../shared/services/config/utm-config-params.service' ;
3+ import { SectionConfigParamType } from '../../../shared/types/configuration/section-config-param.type' ;
24import {
35 FEDERATION_EMAIL_CONFIG_PARAMS ,
46 FEDERATION_EMAIL_CONFIG_SECTION
@@ -9,7 +11,46 @@ import {
911 templateUrl : './federation-email-config.page.component.html' ,
1012 styleUrls : [ './federation-email-config.page.component.scss' ]
1113} )
12- export class FederationEmailConfigPageComponent {
14+ export class FederationEmailConfigPageComponent implements OnInit {
1315 readonly section = FEDERATION_EMAIL_CONFIG_SECTION ;
14- readonly params = FEDERATION_EMAIL_CONFIG_PARAMS ;
16+ readonly params : SectionConfigParamType [ ] = FEDERATION_EMAIL_CONFIG_PARAMS . map ( p => ( { ...p } ) ) ;
17+
18+ constructor ( private paramsService : UtmConfigParamsService ) { }
19+
20+ ngOnInit ( ) : void {
21+ this . paramsService . query ( {
22+ page : 0 ,
23+ size : 10000 ,
24+ 'sectionId.equals' : this . section . id ,
25+ sort : 'id,asc'
26+ } ) . subscribe ( response => {
27+ const byShort = new Map < string , SectionConfigParamType > ( ) ;
28+ ( response . body || [ ] ) . forEach ( p => byShort . set ( p . confParamShort , p ) ) ;
29+ this . params . forEach ( p => {
30+ const server = byShort . get ( p . confParamShort ) ;
31+ if ( server ) {
32+ p . id = server . id ;
33+ p . confParamValue = server . confParamValue ;
34+ }
35+ } ) ;
36+ this . maskPasswordIfPreviouslySet ( ) ;
37+ } ) ;
38+ }
39+
40+ private maskPasswordIfPreviouslySet ( ) : void {
41+ const password = this . params . find ( p => p . confParamShort === 'utmstack.mail.password' ) ;
42+ if ( ! password || ! this . isEmpty ( password . confParamValue ) ) {
43+ return ;
44+ }
45+ const others = this . params . filter ( p => p !== password ) ;
46+ const allOthersFilled = others . length > 0 && others . every ( p => ! this . isEmpty ( p . confParamValue ) ) ;
47+ if ( allOthersFilled ) {
48+ password . confParamPlaceholder = '••••••••' ;
49+ password . confParamRequired = false ;
50+ }
51+ }
52+
53+ private isEmpty ( value : unknown ) : boolean {
54+ return value === null || value === undefined || value === '' ;
55+ }
1556}
0 commit comments