Fineract backend settings with environment variables

This commit is contained in:
Jose Alberto Hernandez
2022-07-13 16:40:23 +02:00
committed by Arnold Gálovics
parent 1b72136411
commit 14ceb4f3fd
44 changed files with 815 additions and 291 deletions
@@ -3,8 +3,11 @@ import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { ActivatedRoute } from '@angular/router';
import { Alert } from 'app/core/alert/alert.model';
import { AlertService } from 'app/core/alert/alert.service';
import { Dates } from 'app/core/utils/dates';
import { SettingsService } from 'app/settings/settings.service';
import { Subscription } from 'rxjs';
/** Custom Services */
import { SystemService } from '../../system.service';
@@ -15,10 +18,8 @@ import { SystemService } from '../../system.service';
styleUrls: ['./business-date-tab.component.scss']
})
export class BusinessDateTabComponent implements OnInit {
configurationName = 'enable_business_date';
businessDateType = 'BUSINESS_DATE';
cobDateType = 'COB_DATE';
/** Subscription to alerts. */
alert$: Subscription;
/** Minimum date allowed. */
minDate = new Date(2000, 0, 1);
@@ -30,8 +31,6 @@ export class BusinessDateTabComponent implements OnInit {
cobDate = new Date();
/** business Date form. */
businessDateForm: FormGroup;
/** Configuration data. */
configurations: any;
/** Business data. */
businessDateData: any;
@@ -42,17 +41,29 @@ export class BusinessDateTabComponent implements OnInit {
/**
* Retrieves the configurations data from `resolve`.
* @param {ActivatedRoute} route Activated Route.
* @param {SystemService} systemService System Service.
* @param {Router} router Router for navigation.
* @param {SettingsService} settingsService Settings Service.
* @param {FormBuilder} formBuilder Form Builder.
* @param {Dates} dateUtils Date Utils.
*/
constructor(private route: ActivatedRoute,
constructor(
private systemService: SystemService,
private settingsService: SettingsService,
private formBuilder: FormBuilder,
private dateUtils: Dates) {}
private dateUtils: Dates,
private alertService: AlertService) {}
ngOnInit(): void {
this.alert$ = this.alertService.alertEvent.subscribe((alertEvent: Alert) => {
const alertType = alertEvent.type;
if (alertType === SettingsService.businessDateType + ' Set Config') {
this.isBusinessDateEnabled = (alertEvent.message === 'enabled') ? true : false;
if (this.isBusinessDateEnabled) {
this.setBusinessDates();
this.createBusinessDateForm();
}
}
});
this.userDateFormat = this.settingsService.dateFormat;
this.getConfigurations();
this.createBusinessDateForm();
@@ -61,31 +72,26 @@ export class BusinessDateTabComponent implements OnInit {
/**
* Get the Configuration and the Business Date data
*/
getConfigurations(): void {
this.systemService.getConfigurations()
getConfigurations(): void {
this.systemService.getConfigurationByName(SettingsService.businessDateConfigName)
.subscribe((configurationData: any) => {
this.configurations = configurationData.globalConfiguration;
this.validateBusinessDateStatus();
this.isBusinessDateEnabled = configurationData.enabled;
if (this.isBusinessDateEnabled) {
this.systemService.getBusinessDates()
.subscribe((businessDateData: any) => {
this.businessDateData = businessDateData;
this.setBusinessDates();
});
this.setBusinessDates();
}
});
}
/**
* Set the Business Date and COB Date.
*/
setBusinessDates() {
this.businessDateData.forEach((data: any) => {
if (data.type === this.businessDateType) {
this.businessDate = new Date(data.date);
} else {
this.cobDate = new Date(data.date);
}
setBusinessDates(): void {
this.systemService.getBusinessDates()
.subscribe((businessDateData: any) => {
businessDateData.forEach((data: any) => {
if (data.type === SettingsService.businessDateType) {
this.businessDate = new Date(data.date);
} else {
this.cobDate = new Date(data.date);
}
});
});
}
@@ -99,18 +105,6 @@ export class BusinessDateTabComponent implements OnInit {
});
}
/**
* Validate If the enable_business_date configuration is enabled or disabled.
*/
validateBusinessDateStatus(): void {
this.isBusinessDateEnabled = false;
this.configurations.forEach((config: any) => {
if (config.name === this.configurationName) {
this.isBusinessDateEnabled = config.enabled;
}
});
}
/**
* Flag to display or not the datepicker control to set the Business Date value
*/
@@ -123,9 +117,9 @@ export class BusinessDateTabComponent implements OnInit {
const locale = this.settingsService.language.code;
const dateFormat = this.settingsService.dateFormat;
const prevBusinessDate: Date = this.businessDateForm.value.businessDate;
let dateType = this.businessDateType;
let dateType = SettingsService.businessDateType;
if (this.dateIndex === 1) {
dateType = this.cobDateType;
dateType = SettingsService.cobDateType;
}
const data = {
date: this.dateUtils.formatDate(prevBusinessDate, dateFormat),
@@ -4,7 +4,7 @@
<mat-tab label="Global Configurations">
<mifosx-global-configurations-tab></mifosx-global-configurations-tab>
</mat-tab>
<mat-tab label="Business Date">
<mat-tab label="Business Date" *ngIf="isBusinessDateEnabled">
<mifosx-business-date-tab></mifosx-business-date-tab>
</mat-tab>
</mat-tab-group>
@@ -1,4 +1,9 @@
import { Component, OnInit } from '@angular/core';
import { Alert } from 'app/core/alert/alert.model';
import { AlertService } from 'app/core/alert/alert.service';
import { SettingsService } from 'app/settings/settings.service';
import { Subscription } from 'rxjs';
import { SystemService } from '../system.service';
@Component({
selector: 'mifosx-configurations',
@@ -6,10 +11,31 @@ import { Component, OnInit } from '@angular/core';
styleUrls: ['./configurations.component.scss']
})
export class ConfigurationsComponent implements OnInit {
/** Subscription to alerts. */
alert$: Subscription;
constructor() { }
isBusinessDateEnabled = false;
constructor(private alertService: AlertService,
private systemService: SystemService) { }
ngOnInit(): void {
this.alert$ = this.alertService.alertEvent.subscribe((alertEvent: Alert) => {
const alertType = alertEvent.type;
if (alertType === SettingsService.businessDateType + ' Set Config') {
this.isBusinessDateEnabled = (alertEvent.message === 'enabled') ? true : false;
}
});
this.getConfigurations();
}
/**
* Get the Configuration and the Business Date data
*/
getConfigurations(): void {
this.systemService.getConfigurationByName(SettingsService.businessDateConfigName)
.subscribe((configurationData: any) => {
this.isBusinessDateEnabled = configurationData.enabled;
});
}
}
@@ -3,7 +3,8 @@ import { Component, OnInit, ViewChild } from '@angular/core';
import { MatPaginator } from '@angular/material/paginator';
import { MatSort } from '@angular/material/sort';
import { MatTableDataSource } from '@angular/material/table';
import { ActivatedRoute, Router } from '@angular/router';
import { AlertService } from 'app/core/alert/alert.service';
import { SettingsService } from 'app/settings/settings.service';
/** Custom Services */
import { SystemService } from '../../system.service';
@@ -33,7 +34,7 @@ export class GlobalConfigurationsTabComponent implements OnInit {
* @param {SystemService} systemService System Service.
* @param {Router} router Router for navigation.
*/
constructor(private route: ActivatedRoute,
constructor(private alertService: AlertService,
private systemService: SystemService) {
this.configurationData = this.systemService.getConfigurations();
}
@@ -73,6 +74,10 @@ export class GlobalConfigurationsTabComponent implements OnInit {
this.systemService.updateConfiguration(configuration.id, { enabled: !configuration.enabled })
.subscribe((response: any) => {
configuration.enabled = response.changes.enabled;
if (configuration.name === SettingsService.businessDateConfigName) {
const msg = configuration.enabled ? 'enabled' : 'disabled';
this.alertService.alert({type: SettingsService.businessDateType + ' Set Config', message: msg});
}
});
}
}
+16 -1
View File
@@ -331,10 +331,17 @@ export class SystemService {
/**
* @returns {Observable<any>} Business Date data.
*/
getBusinessDates(): Observable<any> {
getBusinessDates(): Observable<any> {
return this.http.get('/businessdate');
}
/**
* @returns {Observable<any>} Business Date data using a type BUSINESS_DATE / COB_DATE.
*/
getBusinessDate(dateType: string): Observable<any> {
return this.http.get(`/businessdate/${dateType}`);
}
/**
* @param {any} dateData Business Date data to be updated.
* @returns {Observable<any>}
@@ -358,6 +365,14 @@ export class SystemService {
return this.http.get(`/configurations/${configurationId}`);
}
/**
* @param {string} configurationId Configuration ID of configuration.
* @returns {Observable<any>} Configuration.
*/
getConfigurationByName(configurationName: string): Observable<any> {
return this.http.get(`/configurations/name/${configurationName}`);
}
/**
* @param {string} configurationId Configuration ID of configuration to be updated.
* @param {any} configuration Configuration to be updated.