2021-12-01 03:07:46 +01:00
|
|
|
import { Injectable } from '@angular/core';
|
2022-05-13 10:00:45 +02:00
|
|
|
import { ConfirmationDialogService } from '../../global-confirmation-dialog/confirmation-dialog.service';
|
|
|
|
import {
|
|
|
|
ConfirmationState,
|
|
|
|
ConfirmationTargets,
|
|
|
|
} from '../../../shared/entities/shared.const';
|
|
|
|
import { ConfirmationMessage } from '../../global-confirmation-dialog/confirmation-message';
|
|
|
|
import { Configuration, StringValueItem } from './config';
|
2021-12-01 03:07:46 +01:00
|
|
|
import { ConfigureService } from 'ng-swagger-gen/services/configure.service';
|
2022-05-13 10:00:45 +02:00
|
|
|
import { clone } from '../../../shared/units/utils';
|
|
|
|
import { MessageHandlerService } from '../../../shared/services/message-handler.service';
|
|
|
|
import { finalize } from 'rxjs/operators';
|
2022-06-07 09:18:36 +02:00
|
|
|
import { Observable, Subscription } from 'rxjs';
|
2021-12-01 03:07:46 +01:00
|
|
|
|
|
|
|
const fakePass = 'aWpLOSYkIzJTTU4wMDkx';
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class ConfigService {
|
|
|
|
private _loadingConfig: boolean = false;
|
|
|
|
private _confirmSub: Subscription;
|
|
|
|
private _currentConfig: Configuration = new Configuration();
|
|
|
|
private _originalConfig: Configuration;
|
|
|
|
|
2022-05-13 10:00:45 +02:00
|
|
|
constructor(
|
|
|
|
private confirmService: ConfirmationDialogService,
|
|
|
|
private configureService: ConfigureService,
|
|
|
|
private msgHandler: MessageHandlerService
|
|
|
|
) {
|
|
|
|
this._confirmSub = this.confirmService.confirmationConfirm$.subscribe(
|
|
|
|
confirmation => {
|
|
|
|
if (
|
|
|
|
confirmation &&
|
|
|
|
confirmation.state === ConfirmationState.CONFIRMED
|
|
|
|
) {
|
|
|
|
this.resetConfig();
|
|
|
|
}
|
2021-12-01 03:07:46 +01:00
|
|
|
}
|
2022-05-13 10:00:45 +02:00
|
|
|
);
|
2021-12-01 03:07:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
getConfig(): Configuration {
|
|
|
|
return this._currentConfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
setConfig(c: Configuration) {
|
|
|
|
this._currentConfig = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
getOriginalConfig(): Configuration {
|
|
|
|
return this._originalConfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
setOriginalConfig(c: Configuration) {
|
|
|
|
this._originalConfig = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
getLoadingConfigStatus(): boolean {
|
|
|
|
return this._loadingConfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
updateConfig() {
|
|
|
|
this._loadingConfig = true;
|
2022-05-13 10:00:45 +02:00
|
|
|
this.configureService
|
|
|
|
.getConfigurations()
|
|
|
|
.pipe(finalize(() => (this._loadingConfig = false)))
|
|
|
|
.subscribe(
|
|
|
|
res => {
|
|
|
|
this._currentConfig = res as Configuration;
|
|
|
|
// Add password fields
|
|
|
|
this._currentConfig.email_password = new StringValueItem(
|
|
|
|
fakePass,
|
|
|
|
true
|
|
|
|
);
|
|
|
|
this._currentConfig.ldap_search_password =
|
|
|
|
new StringValueItem(fakePass, true);
|
|
|
|
this._currentConfig.uaa_client_secret = new StringValueItem(
|
|
|
|
fakePass,
|
|
|
|
true
|
|
|
|
);
|
|
|
|
this._currentConfig.oidc_client_secret =
|
|
|
|
new StringValueItem(fakePass, true);
|
|
|
|
// Keep the original copy of the data
|
|
|
|
this._originalConfig = clone(this._currentConfig);
|
|
|
|
},
|
|
|
|
error => {
|
|
|
|
this.msgHandler.handleError(error);
|
2021-12-01 03:07:46 +01:00
|
|
|
}
|
2022-05-13 10:00:45 +02:00
|
|
|
);
|
2021-12-01 03:07:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
resetConfig() {
|
|
|
|
if (this._originalConfig) {
|
|
|
|
this._currentConfig = clone(this._originalConfig);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
confirmUnsavedChanges(changes: any) {
|
|
|
|
let msg = new ConfirmationMessage(
|
|
|
|
'CONFIG.CONFIRM_TITLE',
|
|
|
|
'CONFIG.CONFIRM_SUMMARY',
|
|
|
|
'',
|
|
|
|
changes,
|
|
|
|
ConfirmationTargets.CONFIG
|
|
|
|
);
|
|
|
|
this.confirmService.openComfirmDialog(msg);
|
|
|
|
}
|
2022-06-07 09:18:36 +02:00
|
|
|
|
|
|
|
saveConfiguration(changes: any): Observable<any> {
|
|
|
|
return this.configureService.updateConfigurations({
|
|
|
|
configurations: changes,
|
|
|
|
});
|
|
|
|
}
|
2021-12-01 03:07:46 +01:00
|
|
|
}
|