mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-06-30 18:15:11 +00:00
Fix host component (#3463)
This commit is contained in:
parent
fc26eb42f3
commit
3281891dcd
@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Component, EventEmitter, Output, ViewEncapsulation, OnInit } from '@angular/core';
|
import { Component, EventEmitter, Output, ViewEncapsulation, OnInit } from '@angular/core';
|
||||||
import { Validators, FormGroup, FormBuilder, AbstractControl } from '@angular/forms';
|
import { Validators, FormGroup, FormBuilder, AbstractControl, FormControl } from '@angular/forms';
|
||||||
import { UserPreferencesService } from '../services/user-preferences.service';
|
import { UserPreferencesService } from '../services/user-preferences.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@ -59,8 +59,9 @@ export class HostSettingsComponent implements OnInit {
|
|||||||
@Output()
|
@Output()
|
||||||
bpmHostChange = new EventEmitter<string>();
|
bpmHostChange = new EventEmitter<string>();
|
||||||
|
|
||||||
constructor(private fb: FormBuilder,
|
constructor(
|
||||||
private userPreference: UserPreferencesService) {
|
private fb: FormBuilder,
|
||||||
|
private userPreference: UserPreferencesService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
@ -68,14 +69,54 @@ export class HostSettingsComponent implements OnInit {
|
|||||||
let providerSelected = this.userPreference.providers;
|
let providerSelected = this.userPreference.providers;
|
||||||
|
|
||||||
this.form = this.fb.group({
|
this.form = this.fb.group({
|
||||||
providers: [providerSelected, Validators.required],
|
providers: [providerSelected, Validators.required]
|
||||||
ecmHost: [this.userPreference.ecmHost, [Validators.required, Validators.pattern(this.HOST_REGEX)]],
|
|
||||||
bpmHost: [this.userPreference.bpmHost, [Validators.required, Validators.pattern(this.HOST_REGEX)]]
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.addFormGroups();
|
||||||
|
|
||||||
|
this.providers.valueChanges.subscribe( () => {
|
||||||
|
this.removeFormGroups();
|
||||||
|
this.addFormGroups();
|
||||||
|
}) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
private removeFormGroups() {
|
||||||
|
this.form.removeControl('oauthConfig');
|
||||||
|
this.form.removeControl('bpmHost');
|
||||||
|
this.form.removeControl('ecmHost');
|
||||||
|
}
|
||||||
|
|
||||||
|
private addFormGroups() {
|
||||||
|
this.addBPMFormControl();
|
||||||
|
this.addECMFormControl();
|
||||||
|
this.addOAuthFormGroup();
|
||||||
|
}
|
||||||
|
|
||||||
|
private addOAuthFormGroup() {
|
||||||
|
if (this.isOAUTH() && !this.oauthConfig) {
|
||||||
|
const oauthFormGroup = this.createOAuthFormGroup();
|
||||||
|
this.form.addControl('oauthConfig', oauthFormGroup);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private addBPMFormControl() {
|
||||||
|
if ((this.isBPM() || this.isALL() || this.isOAUTH()) && !this.bpmHost) {
|
||||||
|
const bpmFormControl = this.createBPMFormControl();
|
||||||
|
this.form.addControl('bpmHost', bpmFormControl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private addECMFormControl() {
|
||||||
|
if ((this.isECM() || this.isALL()) && !this.ecmHost) {
|
||||||
|
const ecmFormControl = this.createECMFormControl();
|
||||||
|
this.form.addControl('ecmHost', ecmFormControl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private createOAuthFormGroup(): AbstractControl {
|
||||||
const oAuthConfig = this.userPreference.oauthConfig;
|
const oAuthConfig = this.userPreference.oauthConfig;
|
||||||
if (oAuthConfig) {
|
if (oAuthConfig) {
|
||||||
const oauthGroup = this.fb.group( {
|
return this.fb.group({
|
||||||
host: [oAuthConfig.host, [Validators.required, Validators.pattern(this.HOST_REGEX)]],
|
host: [oAuthConfig.host, [Validators.required, Validators.pattern(this.HOST_REGEX)]],
|
||||||
clientId: [oAuthConfig.clientId, Validators.required],
|
clientId: [oAuthConfig.clientId, Validators.required],
|
||||||
redirectUri: [oAuthConfig.redirectUri, Validators.required],
|
redirectUri: [oAuthConfig.redirectUri, Validators.required],
|
||||||
@ -84,9 +125,15 @@ export class HostSettingsComponent implements OnInit {
|
|||||||
silentLogin: oAuthConfig.silentLogin,
|
silentLogin: oAuthConfig.silentLogin,
|
||||||
implicitFlow: oAuthConfig.implicitFlow
|
implicitFlow: oAuthConfig.implicitFlow
|
||||||
});
|
});
|
||||||
this.form.addControl('oauthConfig', oauthGroup);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private createBPMFormControl(): AbstractControl {
|
||||||
|
return new FormControl (this.userPreference.bpmHost, [Validators.required, Validators.pattern(this.HOST_REGEX)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private createECMFormControl(): AbstractControl {
|
||||||
|
return new FormControl (this.userPreference.ecmHost, [Validators.required, Validators.pattern(this.HOST_REGEX)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
onCancel() {
|
onCancel() {
|
||||||
@ -108,16 +155,16 @@ export class HostSettingsComponent implements OnInit {
|
|||||||
this.success.emit(true);
|
this.success.emit(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
saveOAuthValues(values: any) {
|
private saveOAuthValues(values: any) {
|
||||||
this.userPreference.oauthConfig = values.oauthConfig;
|
this.userPreference.oauthConfig = values.oauthConfig;
|
||||||
this.userPreference.bpmHost = values.bpmHost;
|
this.userPreference.bpmHost = values.bpmHost;
|
||||||
}
|
}
|
||||||
|
|
||||||
saveBPMValues(values: any) {
|
private saveBPMValues(values: any) {
|
||||||
this.userPreference.bpmHost = values.bpmHost;
|
this.userPreference.bpmHost = values.bpmHost;
|
||||||
}
|
}
|
||||||
|
|
||||||
saveECMValues(values: any) {
|
private saveECMValues(values: any) {
|
||||||
this.userPreference.ecmHost = values.ecmHost;
|
this.userPreference.ecmHost = values.ecmHost;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user