WEB-693: Implement Date and Datetime Global Variables (#3123)
Signed-off-by: DeathGun44 <krishnamewara841@gmail.com>
This commit is contained in:
@@ -0,0 +1,102 @@
|
|||||||
|
import { TestBed } from '@angular/core/testing';
|
||||||
|
import { DatePipe } from '@angular/common';
|
||||||
|
import { Dates } from './dates';
|
||||||
|
|
||||||
|
describe('Dates', () => {
|
||||||
|
let service: Dates;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
providers: [
|
||||||
|
Dates,
|
||||||
|
DatePipe
|
||||||
|
]
|
||||||
|
});
|
||||||
|
service = TestBed.inject(Dates);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be created', () => {
|
||||||
|
expect(service).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('angularToMomentFormat', () => {
|
||||||
|
it('should convert dd/MM/yyyy to DD/MM/YYYY', () => {
|
||||||
|
expect(service.angularToMomentFormat('dd/MM/yyyy')).toBe('DD/MM/YYYY');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should convert d MMMM yy to D MMMM YY', () => {
|
||||||
|
expect(service.angularToMomentFormat('d MMMM yy')).toBe('D MMMM YY');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should convert yyyy-MM-dd HH:mm:ss to YYYY-MM-DD HH:mm:ss', () => {
|
||||||
|
expect(service.angularToMomentFormat('yyyy-MM-dd HH:mm:ss')).toBe('YYYY-MM-DD HH:mm:ss');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle single characters d/M/y to D/M/Y', () => {
|
||||||
|
expect(service.angularToMomentFormat('d/M/y')).toBe('D/M/Y');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should preserve other characters like HH:mm a to HH:mm A', () => {
|
||||||
|
expect(service.angularToMomentFormat('HH:mm a')).toBe('HH:mm A');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should convert dd MMMM yyyy to DD MMMM YYYY', () => {
|
||||||
|
expect(service.angularToMomentFormat('dd MMMM yyyy')).toBe('DD MMMM YYYY');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should convert all y variants: y, yy, yyy, yyyy', () => {
|
||||||
|
expect(service.angularToMomentFormat('y')).toBe('Y');
|
||||||
|
expect(service.angularToMomentFormat('yy')).toBe('YY');
|
||||||
|
expect(service.angularToMomentFormat('yyy')).toBe('YYY');
|
||||||
|
expect(service.angularToMomentFormat('yyyy')).toBe('YYYY');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should convert all d variants: d, dd', () => {
|
||||||
|
expect(service.angularToMomentFormat('d')).toBe('D');
|
||||||
|
expect(service.angularToMomentFormat('dd')).toBe('DD');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle complex format with all patterns', () => {
|
||||||
|
expect(service.angularToMomentFormat('dd-MM-yyyy HH:mm:ss a')).toBe('DD-MM-YYYY HH:mm:ss A');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should preserve MM (month) unchanged', () => {
|
||||||
|
expect(service.angularToMomentFormat('MM')).toBe('MM');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should preserve time components HH, mm, ss unchanged', () => {
|
||||||
|
expect(service.angularToMomentFormat('HH:mm:ss')).toBe('HH:mm:ss');
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('App-Supported Formats', () => {
|
||||||
|
const formats = [
|
||||||
|
// HH:mm:ss variants
|
||||||
|
{ angular: 'dd MMMM yyyy HH:mm:ss', moment: 'DD MMMM YYYY HH:mm:ss' },
|
||||||
|
{ angular: 'dd/MMMM/yyyy HH:mm:ss', moment: 'DD/MMMM/YYYY HH:mm:ss' },
|
||||||
|
{ angular: 'dd-MMMM-yyyy HH:mm:ss', moment: 'DD-MMMM-YYYY HH:mm:ss' },
|
||||||
|
{ angular: 'dd-MM-yy HH:mm:ss', moment: 'DD-MM-YY HH:mm:ss' },
|
||||||
|
{ angular: 'MMMM-dd-yyyy HH:mm:ss', moment: 'MMMM-DD-YYYY HH:mm:ss' },
|
||||||
|
{ angular: 'MMMM dd yyyy HH:mm:ss', moment: 'MMMM DD YYYY HH:mm:ss' },
|
||||||
|
{ angular: 'MMMM/dd/yyyy HH:mm:ss', moment: 'MMMM/DD/YYYY HH:mm:ss' },
|
||||||
|
{ angular: 'MM-dd-yy HH:mm:ss', moment: 'MM-DD-YY HH:mm:ss' },
|
||||||
|
{ angular: 'yyyy-MM-dd HH:mm:ss', moment: 'YYYY-MM-DD HH:mm:ss' },
|
||||||
|
// HH:mm variants
|
||||||
|
{ angular: 'dd MMMM yyyy HH:mm', moment: 'DD MMMM YYYY HH:mm' },
|
||||||
|
{ angular: 'dd/MMMM/yyyy HH:mm', moment: 'DD/MMMM/YYYY HH:mm' },
|
||||||
|
{ angular: 'dd-MMMM-yyyy HH:mm', moment: 'DD-MMMM-YYYY HH:mm' },
|
||||||
|
{ angular: 'dd-MM-yy HH:mm', moment: 'DD-MM-YY HH:mm' },
|
||||||
|
{ angular: 'MMMM-dd-yyyy HH:mm', moment: 'MMMM-DD-YYYY HH:mm' },
|
||||||
|
{ angular: 'MMMM dd yyyy HH:mm', moment: 'MMMM DD YYYY HH:mm' },
|
||||||
|
{ angular: 'MMMM/dd/yyyy HH:mm', moment: 'MMMM/DD/YYYY HH:mm' },
|
||||||
|
{ angular: 'MM-dd-yy HH:mm', moment: 'MM-DD-YY HH:mm' },
|
||||||
|
{ angular: 'yyyy-MM-dd HH:mm', moment: 'YYYY-MM-DD HH:mm' }
|
||||||
|
];
|
||||||
|
|
||||||
|
formats.forEach((f) => {
|
||||||
|
it(`should convert "${f.angular}" to "${f.moment}"`, () => {
|
||||||
|
expect(service.angularToMomentFormat(f.angular)).toBe(f.moment);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -29,10 +29,21 @@ export class Dates {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public formatDateAsString(value: Date, dateFormat: string): string {
|
public formatDateAsString(value: Date, dateFormat: string): string {
|
||||||
const momentFormat = dateFormat.replace(/y/g, 'Y').replace(/d/g, 'D').replace(/a/g, 'A');
|
const momentFormat = this.angularToMomentFormat(dateFormat);
|
||||||
return moment(value).format(momentFormat);
|
return moment(value).format(momentFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public angularToMomentFormat(angularFormat: string): string {
|
||||||
|
return angularFormat.replace(/y/g, 'Y').replace(/d/g, 'D').replace(/a/g, 'A');
|
||||||
|
}
|
||||||
|
|
||||||
|
public getMomentLocale(language?: { code: string }): string {
|
||||||
|
const langCode = language?.code;
|
||||||
|
if (!langCode) return 'en';
|
||||||
|
if (langCode.includes('-')) return langCode.split('-')[0];
|
||||||
|
return langCode;
|
||||||
|
}
|
||||||
|
|
||||||
public parseDate(value: any): Date {
|
public parseDate(value: any): Date {
|
||||||
if (value instanceof Array) {
|
if (value instanceof Array) {
|
||||||
return moment(value.join('-'), 'YYYY-MM-DD').toDate();
|
return moment(value.join('-'), 'YYYY-MM-DD').toDate();
|
||||||
@@ -46,7 +57,7 @@ export class Dates {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public convertToDate(value: any, format: string): Date {
|
public convertToDate(value: any, format: string): Date {
|
||||||
const momentFormat = format.replace(/y/g, 'Y').replace(/d/g, 'D').replace(/a/g, 'A');
|
const momentFormat = this.angularToMomentFormat(format);
|
||||||
return moment(value, momentFormat).toDate();
|
return moment(value, momentFormat).toDate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
import { Pipe, PipeTransform, inject, OnDestroy } from '@angular/core';
|
import { Pipe, PipeTransform, inject, OnDestroy } from '@angular/core';
|
||||||
import { SettingsService } from 'app/settings/settings.service';
|
import { SettingsService } from 'app/settings/settings.service';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
|
import { Dates } from 'app/core/utils/dates';
|
||||||
import { Subscription } from 'rxjs';
|
import { Subscription } from 'rxjs';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
|
||||||
@@ -29,6 +30,7 @@ import 'moment/locale/cs'; // Czech
|
|||||||
export class DateFormatPipe implements PipeTransform, OnDestroy {
|
export class DateFormatPipe implements PipeTransform, OnDestroy {
|
||||||
private settingsService = inject(SettingsService);
|
private settingsService = inject(SettingsService);
|
||||||
private translateService = inject(TranslateService);
|
private translateService = inject(TranslateService);
|
||||||
|
private dateUtils = inject(Dates);
|
||||||
private onLangChange: Subscription;
|
private onLangChange: Subscription;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
@@ -45,24 +47,12 @@ export class DateFormatPipe implements PipeTransform, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
transform(value: any, dateFormat?: string): any {
|
transform(value: any, dateFormat?: string): any {
|
||||||
const defaultDateFormat = this.settingsService.dateFormat.replace('dd', 'DD');
|
const defaultDateFormat = this.dateUtils.angularToMomentFormat(this.settingsService.dateFormat);
|
||||||
if (typeof value === 'undefined' || value === null) {
|
if (typeof value === 'undefined' || value === null) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Map SettingsService language code to a moment.js locale identifier
|
const momentLocale = this.dateUtils.getMomentLocale(this.settingsService.language);
|
||||||
const langCode = this.settingsService.language.code;
|
|
||||||
let momentLocale: string;
|
|
||||||
|
|
||||||
if (!langCode) {
|
|
||||||
momentLocale = 'en';
|
|
||||||
} else if (langCode.includes('-')) {
|
|
||||||
// Convert codes like 'ne-NE' or 'es-MX' to base language 'ne', 'es'
|
|
||||||
momentLocale = langCode.split('-')[0];
|
|
||||||
} else {
|
|
||||||
momentLocale = langCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
moment.locale(momentLocale);
|
moment.locale(momentLocale);
|
||||||
|
|
||||||
let dateVal;
|
let dateVal;
|
||||||
|
|||||||
@@ -6,13 +6,38 @@
|
|||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Pipe, PipeTransform } from '@angular/core';
|
import { Pipe, PipeTransform, inject, OnDestroy } from '@angular/core';
|
||||||
|
import { SettingsService } from 'app/settings/settings.service';
|
||||||
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
|
import { Dates } from 'app/core/utils/dates';
|
||||||
|
import { Subscription } from 'rxjs';
|
||||||
import moment, { Moment } from 'moment';
|
import moment, { Moment } from 'moment';
|
||||||
|
|
||||||
@Pipe({ name: 'datetimeFormat', standalone: true })
|
@Pipe({ name: 'datetimeFormat', pure: false })
|
||||||
export class DatetimeFormatPipe implements PipeTransform {
|
export class DatetimeFormatPipe implements PipeTransform, OnDestroy {
|
||||||
|
private settingsService = inject(SettingsService);
|
||||||
|
private translateService = inject(TranslateService);
|
||||||
|
private dateUtils = inject(Dates);
|
||||||
|
private onLangChange: Subscription;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.onLangChange = this.translateService.onLangChange.subscribe(() => {});
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnDestroy(): void {
|
||||||
|
if (this.onLangChange) {
|
||||||
|
this.onLangChange.unsubscribe();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
transform(value: unknown, datetimeFormat?: string): string {
|
transform(value: unknown, datetimeFormat?: string): string {
|
||||||
|
const defaultDatetimeFormat = this.dateUtils.angularToMomentFormat(this.settingsService.datetimeFormat);
|
||||||
|
|
||||||
if (value == null || value === '') return '';
|
if (value == null || value === '') return '';
|
||||||
|
|
||||||
|
const momentLocale = this.dateUtils.getMomentLocale(this.settingsService.language);
|
||||||
|
moment.locale(momentLocale);
|
||||||
|
|
||||||
let dateVal: Moment;
|
let dateVal: Moment;
|
||||||
if (Array.isArray(value)) {
|
if (Array.isArray(value)) {
|
||||||
const [
|
const [
|
||||||
@@ -24,17 +49,31 @@ export class DatetimeFormatPipe implements PipeTransform {
|
|||||||
ss
|
ss
|
||||||
] = value as number[];
|
] = value as number[];
|
||||||
if (hh != null) {
|
if (hh != null) {
|
||||||
dateVal = moment({ year: y, month: (m ?? 1) - 1, date: d, hour: hh, minute: mm ?? 0, second: ss ?? 0 });
|
dateVal = moment({
|
||||||
|
year: y,
|
||||||
|
month: (m ?? 1) - 1,
|
||||||
|
date: d,
|
||||||
|
hour: hh,
|
||||||
|
minute: mm ?? 0,
|
||||||
|
second: ss ?? 0
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
dateVal = moment({ year: y, month: (m ?? 1) - 1, date: d });
|
dateVal = moment({ year: y, month: (m ?? 1) - 1, date: d });
|
||||||
}
|
}
|
||||||
} else if (typeof value === 'number' && value < 1e12) {
|
} else if (typeof value === 'number' && value < 1e12) {
|
||||||
// epoch seconds
|
|
||||||
dateVal = moment.unix(value);
|
dateVal = moment.unix(value);
|
||||||
} else {
|
} else {
|
||||||
dateVal = moment(value as any);
|
dateVal = moment(value as any);
|
||||||
}
|
}
|
||||||
const fmt = datetimeFormat ?? 'YYYY-MM-DDTHH:mm:ssZ';
|
|
||||||
return dateVal.format(fmt);
|
if (!dateVal.isValid()) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!datetimeFormat) {
|
||||||
|
return dateVal.format(defaultDatetimeFormat);
|
||||||
|
}
|
||||||
|
|
||||||
|
return dateVal.format(datetimeFormat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,17 @@
|
|||||||
</mat-select>
|
</mat-select>
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
|
|
||||||
|
<mat-form-field>
|
||||||
|
<mat-label>{{ 'labels.inputs.Default Datetime Format' | translate }}</mat-label>
|
||||||
|
<mat-select [formControl]="datetimeFormat">
|
||||||
|
@for (datetimeFormat of datetimeFormats; track datetimeFormat) {
|
||||||
|
<mat-option [value]="datetimeFormat">
|
||||||
|
{{ datetimeFormat }}
|
||||||
|
</mat-option>
|
||||||
|
}
|
||||||
|
</mat-select>
|
||||||
|
</mat-form-field>
|
||||||
|
|
||||||
<mat-form-field>
|
<mat-form-field>
|
||||||
<mat-label>{{ 'labels.inputs.Decimals to Display' | translate }}</mat-label>
|
<mat-label>{{ 'labels.inputs.Decimals to Display' | translate }}</mat-label>
|
||||||
<mat-select [formControl]="decimalsToDisplay">
|
<mat-select [formControl]="decimalsToDisplay">
|
||||||
|
|||||||
@@ -7,11 +7,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/** Angular Imports */
|
/** Angular Imports */
|
||||||
import { Component, OnInit, inject } from '@angular/core';
|
import { Component, OnInit, OnDestroy, inject } from '@angular/core';
|
||||||
|
|
||||||
/** Custom Service */
|
/** Custom Service */
|
||||||
import { SettingsService } from './settings.service';
|
import { SettingsService } from './settings.service';
|
||||||
import { UntypedFormControl, ReactiveFormsModule } from '@angular/forms';
|
import { FormControl, ReactiveFormsModule } from '@angular/forms';
|
||||||
|
import { Subject } from 'rxjs';
|
||||||
|
import { takeUntil } from 'rxjs/operators';
|
||||||
import {
|
import {
|
||||||
MatAccordion,
|
MatAccordion,
|
||||||
MatExpansionPanel,
|
MatExpansionPanel,
|
||||||
@@ -39,8 +41,9 @@ import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module';
|
|||||||
ThemePickerComponent
|
ThemePickerComponent
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class SettingsComponent implements OnInit {
|
export class SettingsComponent implements OnInit, OnDestroy {
|
||||||
private settingsService = inject(SettingsService);
|
private settingsService = inject(SettingsService);
|
||||||
|
private destroy$ = new Subject<void>();
|
||||||
|
|
||||||
/** Placeholder for languages. update once translations are set up */
|
/** Placeholder for languages. update once translations are set up */
|
||||||
languages: any[] = [
|
languages: any[] = [
|
||||||
@@ -61,6 +64,28 @@ export class SettingsComponent implements OnInit {
|
|||||||
'MM-dd-yy',
|
'MM-dd-yy',
|
||||||
'yyyy-MM-dd'
|
'yyyy-MM-dd'
|
||||||
];
|
];
|
||||||
|
datetimeFormats: string[] = [
|
||||||
|
// All date formats with HH:mm:ss (seconds)
|
||||||
|
'dd MMMM yyyy HH:mm:ss',
|
||||||
|
'dd/MMMM/yyyy HH:mm:ss',
|
||||||
|
'dd-MMMM-yyyy HH:mm:ss',
|
||||||
|
'dd-MM-yy HH:mm:ss',
|
||||||
|
'MMMM-dd-yyyy HH:mm:ss',
|
||||||
|
'MMMM dd yyyy HH:mm:ss',
|
||||||
|
'MMMM/dd/yyyy HH:mm:ss',
|
||||||
|
'MM-dd-yy HH:mm:ss',
|
||||||
|
'yyyy-MM-dd HH:mm:ss',
|
||||||
|
// All date formats with HH:mm (no seconds)
|
||||||
|
'dd MMMM yyyy HH:mm',
|
||||||
|
'dd/MMMM/yyyy HH:mm',
|
||||||
|
'dd-MMMM-yyyy HH:mm',
|
||||||
|
'dd-MM-yy HH:mm',
|
||||||
|
'MMMM-dd-yyyy HH:mm',
|
||||||
|
'MMMM dd yyyy HH:mm',
|
||||||
|
'MMMM/dd/yyyy HH:mm',
|
||||||
|
'MM-dd-yy HH:mm',
|
||||||
|
'yyyy-MM-dd HH:mm'
|
||||||
|
];
|
||||||
/** Decimals. */
|
/** Decimals. */
|
||||||
decimals: string[] = [
|
decimals: string[] = [
|
||||||
'0',
|
'0',
|
||||||
@@ -77,15 +102,18 @@ export class SettingsComponent implements OnInit {
|
|||||||
fonts: any;
|
fonts: any;
|
||||||
|
|
||||||
/** Language Setting */
|
/** Language Setting */
|
||||||
language = new UntypedFormControl('');
|
language = new FormControl('');
|
||||||
/** Date Format Setting */
|
/** Date Format Setting */
|
||||||
dateFormat = new UntypedFormControl('');
|
dateFormat = new FormControl('');
|
||||||
|
/** Datetime Format Setting */
|
||||||
|
datetimeFormat = new FormControl('');
|
||||||
/** Decimals to Display Setting */
|
/** Decimals to Display Setting */
|
||||||
decimalsToDisplay = new UntypedFormControl('');
|
decimalsToDisplay = new FormControl('');
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.language.patchValue(this.settingsService.language);
|
this.language.patchValue(this.settingsService.language);
|
||||||
this.dateFormat.patchValue(this.settingsService.dateFormat);
|
this.dateFormat.patchValue(this.settingsService.dateFormat);
|
||||||
|
this.datetimeFormat.patchValue(this.settingsService.datetimeFormat);
|
||||||
this.decimalsToDisplay.patchValue(this.settingsService.decimals);
|
this.decimalsToDisplay.patchValue(this.settingsService.decimals);
|
||||||
this.buildDependencies();
|
this.buildDependencies();
|
||||||
}
|
}
|
||||||
@@ -94,17 +122,25 @@ export class SettingsComponent implements OnInit {
|
|||||||
* Subscribe to value changes.
|
* Subscribe to value changes.
|
||||||
*/
|
*/
|
||||||
buildDependencies() {
|
buildDependencies() {
|
||||||
this.language.valueChanges.subscribe((language: any) => {
|
this.language.valueChanges.pipe(takeUntil(this.destroy$)).subscribe((language: any) => {
|
||||||
this.settingsService.setLanguage(language);
|
this.settingsService.setLanguage(language);
|
||||||
});
|
});
|
||||||
this.dateFormat.valueChanges.subscribe((dateFormat: string) => {
|
this.dateFormat.valueChanges.pipe(takeUntil(this.destroy$)).subscribe((dateFormat: string) => {
|
||||||
this.settingsService.setDateFormat(dateFormat);
|
this.settingsService.setDateFormat(dateFormat);
|
||||||
});
|
});
|
||||||
this.decimalsToDisplay.valueChanges.subscribe((decimals: string) => {
|
this.datetimeFormat.valueChanges.pipe(takeUntil(this.destroy$)).subscribe((datetimeFormat: string) => {
|
||||||
|
this.settingsService.setDatetimeFormat(datetimeFormat);
|
||||||
|
});
|
||||||
|
this.decimalsToDisplay.valueChanges.pipe(takeUntil(this.destroy$)).subscribe((decimals: string) => {
|
||||||
this.settingsService.setDecimalToDisplay(decimals);
|
this.settingsService.setDecimalToDisplay(decimals);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngOnDestroy() {
|
||||||
|
this.destroy$.next();
|
||||||
|
this.destroy$.complete();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compare function for mat-select.
|
* Compare function for mat-select.
|
||||||
* Useful in patching values if value is an object.
|
* Useful in patching values if value is an object.
|
||||||
|
|||||||
@@ -39,6 +39,10 @@ export class SettingsService {
|
|||||||
localStorage.setItem('mifosXDateFormat', JSON.stringify(dateFormat));
|
localStorage.setItem('mifosXDateFormat', JSON.stringify(dateFormat));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setDatetimeFormat(datetimeFormat: string) {
|
||||||
|
localStorage.setItem('mifosXDatetimeFormat', JSON.stringify(datetimeFormat));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets language setting throughout the app.
|
* Sets language setting throughout the app.
|
||||||
* @param {any} language Language.
|
* @param {any} language Language.
|
||||||
@@ -112,10 +116,37 @@ export class SettingsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns date format setting.
|
* Returns date format setting with fallback precedence:
|
||||||
|
* 1. User setting (localStorage)
|
||||||
|
* 2. Global env var
|
||||||
|
* 3. Hardcoded default
|
||||||
*/
|
*/
|
||||||
get dateFormat() {
|
get dateFormat() {
|
||||||
return JSON.parse(localStorage.getItem('mifosXDateFormat'));
|
const userSetting = localStorage.getItem('mifosXDateFormat');
|
||||||
|
if (userSetting) {
|
||||||
|
return JSON.parse(userSetting);
|
||||||
|
}
|
||||||
|
if (environment.defaultFormatDate) {
|
||||||
|
return environment.defaultFormatDate;
|
||||||
|
}
|
||||||
|
return 'dd MMMM yyyy';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns datetime format setting with fallback precedence:
|
||||||
|
* 1. User setting (localStorage)
|
||||||
|
* 2. Global env var
|
||||||
|
* 3. Hardcoded default
|
||||||
|
*/
|
||||||
|
get datetimeFormat() {
|
||||||
|
const userSetting = localStorage.getItem('mifosXDatetimeFormat');
|
||||||
|
if (userSetting) {
|
||||||
|
return JSON.parse(userSetting);
|
||||||
|
}
|
||||||
|
if (environment.defaultFormatDatetime) {
|
||||||
|
return environment.defaultFormatDatetime;
|
||||||
|
}
|
||||||
|
return 'dd MMMM yyyy HH:mm:ss';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -223,9 +223,6 @@ export class WebAppComponent implements OnInit, OnDestroy {
|
|||||||
if (!localStorage.getItem('mifosXLanguage')) {
|
if (!localStorage.getItem('mifosXLanguage')) {
|
||||||
this.settingsService.setDefaultLanguage();
|
this.settingsService.setDefaultLanguage();
|
||||||
}
|
}
|
||||||
if (!localStorage.getItem('mifosXDateFormat')) {
|
|
||||||
this.settingsService.setDateFormat('dd MMMM yyyy');
|
|
||||||
}
|
|
||||||
// Set default max date picker as Today
|
// Set default max date picker as Today
|
||||||
this.settingsService.setBusinessDate(this.dateUtils.formatDate(new Date(), SettingsService.businessDateFormat));
|
this.settingsService.setBusinessDate(this.dateUtils.formatDate(new Date(), SettingsService.businessDateFormat));
|
||||||
// Set the server list from the env var FINERACT_API_URLS, but avoid overwriting "Add new server" user choice
|
// Set the server list from the env var FINERACT_API_URLS, but avoid overwriting "Add new server" user choice
|
||||||
|
|||||||
+16
-13
@@ -6,19 +6,19 @@
|
|||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function(window) {
|
(function (window) {
|
||||||
window["env"] = window["env"] || {};
|
window["env"] = window["env"] || {};
|
||||||
|
|
||||||
// BackEnd Environment variables
|
// BackEnd Environment variables
|
||||||
window["env"]["fineractApiUrls"] = '';
|
window["env"]["fineractApiUrls"] = '';
|
||||||
window["env"]["fineractApiUrl"] = '';
|
window["env"]["fineractApiUrl"] = '';
|
||||||
|
|
||||||
window["env"]["apiProvider"] = '';
|
window["env"]["apiProvider"] = '';
|
||||||
window["env"]["apiVersion"] = '';
|
window["env"]["apiVersion"] = '';
|
||||||
window["env"]["apiActuator"] = '';
|
window["env"]["apiActuator"] = '';
|
||||||
|
|
||||||
window["env"]["fineractPlatformTenantId"] = '';
|
window["env"]["fineractPlatformTenantId"] = '';
|
||||||
window["env"]["fineractPlatformTenantIds"] = '';
|
window["env"]["fineractPlatformTenantIds"] = '';
|
||||||
|
|
||||||
window['env']['tenantLogoUrl'] = '';
|
window['env']['tenantLogoUrl'] = '';
|
||||||
window['env']['tenantLogoUrlDark'] = '';
|
window['env']['tenantLogoUrlDark'] = '';
|
||||||
@@ -27,6 +27,9 @@
|
|||||||
window["env"]["defaultLanguage"] = '';
|
window["env"]["defaultLanguage"] = '';
|
||||||
window["env"]["supportedLanguages"] = '';
|
window["env"]["supportedLanguages"] = '';
|
||||||
|
|
||||||
|
window["env"]["defaultFormatDate"] = '';
|
||||||
|
window["env"]["defaultFormatDatetime"] = '';
|
||||||
|
|
||||||
window['env']['preloadClients'] = '';
|
window['env']['preloadClients'] = '';
|
||||||
|
|
||||||
// Char delimiter to Export CSV options: ',' ';' '|' ' '
|
// Char delimiter to Export CSV options: ',' ';' '|' ' '
|
||||||
@@ -34,7 +37,7 @@
|
|||||||
|
|
||||||
// Display or not the Server Selector
|
// Display or not the Server Selector
|
||||||
window['env']['allowServerSwitch'] = '';
|
window['env']['allowServerSwitch'] = '';
|
||||||
|
|
||||||
// Display or not the BackEnd Info
|
// Display or not the BackEnd Info
|
||||||
window['env']['displayBackEndInfo'] = '';
|
window['env']['displayBackEndInfo'] = '';
|
||||||
|
|
||||||
@@ -81,12 +84,12 @@
|
|||||||
// Hide client data (mask names)
|
// Hide client data (mask names)
|
||||||
window['env']['complianceHideClientData'] = '';
|
window['env']['complianceHideClientData'] = '';
|
||||||
|
|
||||||
// Interbank Transfers Environment variables
|
// Interbank Transfers Environment variables
|
||||||
window['env']['mifosInterbankTransfersApiUrl'] = '';
|
window['env']['mifosInterbankTransfersApiUrl'] = '';
|
||||||
window['env']['mifosInterbankTransfersApiProvider'] = '';
|
window['env']['mifosInterbankTransfersApiProvider'] = '';
|
||||||
window['env']['mifosInterbankTransfersApiVersion'] = '';
|
window['env']['mifosInterbankTransfersApiVersion'] = '';
|
||||||
window['env']['mifosInterbankTransfersEnabled'] = 'true';
|
window['env']['mifosInterbankTransfersEnabled'] = 'true';
|
||||||
|
|
||||||
// Enable Role-Based Access Control (RBAC) for menu/button permissions
|
// Enable Role-Based Access Control (RBAC) for menu/button permissions
|
||||||
// Set to true to enable RBAC, false (default) for backward compatibility
|
// Set to true to enable RBAC, false (default) for backward compatibility
|
||||||
window['env']['productionModeEnableRBAC'] = false;
|
window['env']['productionModeEnableRBAC'] = false;
|
||||||
@@ -103,9 +106,9 @@
|
|||||||
|
|
||||||
// OIDC Plugin Environment variables
|
// OIDC Plugin Environment variables
|
||||||
window['env']['oidcServerEnabled'] = false;
|
window['env']['oidcServerEnabled'] = false;
|
||||||
window['env']['oidcBaseUrl'] = '';
|
window['env']['oidcBaseUrl'] = '';
|
||||||
window['env']['oidcClientId'] = '';
|
window['env']['oidcClientId'] = '';
|
||||||
window['env']['oidcApiUrl'] = '';
|
window['env']['oidcApiUrl'] = '';
|
||||||
window['env']['oidcFrontUrl'] = '';
|
window['env']['oidcFrontUrl'] = '';
|
||||||
|
|
||||||
})(this);
|
})(this);
|
||||||
|
|||||||
@@ -32,6 +32,9 @@
|
|||||||
|
|
||||||
window['env']['supportedLanguages'] = '$MIFOS_SUPPORTED_LANGUAGES';
|
window['env']['supportedLanguages'] = '$MIFOS_SUPPORTED_LANGUAGES';
|
||||||
|
|
||||||
|
window['env']['defaultFormatDate'] = '$MIFOS_DEFAULT_FORMAT_DATE';
|
||||||
|
window['env']['defaultFormatDatetime'] = '$MIFOS_DEFAULT_FORMAT_DATETIME';
|
||||||
|
|
||||||
window['env']['preloadClients'] = '$MIFOS_PRELOAD_CLIENTS';
|
window['env']['preloadClients'] = '$MIFOS_PRELOAD_CLIENTS';
|
||||||
|
|
||||||
// Char delimiter to Export CSV options: ',' ';' '|' ' '
|
// Char delimiter to Export CSV options: ',' ';' '|' ' '
|
||||||
|
|||||||
@@ -1644,6 +1644,7 @@
|
|||||||
"Decimals to Display": "Zobrazení desetinných míst",
|
"Decimals to Display": "Zobrazení desetinných míst",
|
||||||
"Default": "Výchozí",
|
"Default": "Výchozí",
|
||||||
"Default Date Format": "Výchozí formát data",
|
"Default Date Format": "Výchozí formát data",
|
||||||
|
"Default Datetime Format": "Výchozí formát data a času",
|
||||||
"Default Font": "Výchozí písmo",
|
"Default Font": "Výchozí písmo",
|
||||||
"Default Language": "Základní jazyk",
|
"Default Language": "Základní jazyk",
|
||||||
"Default Savings Account": "Výchozí spořicí účet",
|
"Default Savings Account": "Výchozí spořicí účet",
|
||||||
|
|||||||
@@ -1646,6 +1646,7 @@
|
|||||||
"Decimals to Display": "Anzuzeigende Dezimalstellen",
|
"Decimals to Display": "Anzuzeigende Dezimalstellen",
|
||||||
"Default": "Standard",
|
"Default": "Standard",
|
||||||
"Default Date Format": "Standarddatumsformat",
|
"Default Date Format": "Standarddatumsformat",
|
||||||
|
"Default Datetime Format": "Standard-Datums- und Zeitformat",
|
||||||
"Default Font": "Standardschriftart",
|
"Default Font": "Standardschriftart",
|
||||||
"Default Language": "Standardsprache",
|
"Default Language": "Standardsprache",
|
||||||
"Default Savings Account": "Standardsparkonto",
|
"Default Savings Account": "Standardsparkonto",
|
||||||
|
|||||||
@@ -1651,6 +1651,7 @@
|
|||||||
"Decimals to Display": "Decimals to Display",
|
"Decimals to Display": "Decimals to Display",
|
||||||
"Default": "Default",
|
"Default": "Default",
|
||||||
"Default Date Format": "Default Date Format",
|
"Default Date Format": "Default Date Format",
|
||||||
|
"Default Datetime Format": "Default Datetime Format",
|
||||||
"Default Font": "Default Font",
|
"Default Font": "Default Font",
|
||||||
"Default Language": "Default Language",
|
"Default Language": "Default Language",
|
||||||
"Default Savings Account": "Default Savings Account",
|
"Default Savings Account": "Default Savings Account",
|
||||||
|
|||||||
@@ -1646,6 +1646,7 @@
|
|||||||
"Decimals to Display": "Decimales para mostrar",
|
"Decimals to Display": "Decimales para mostrar",
|
||||||
"Default": "Predeterminado",
|
"Default": "Predeterminado",
|
||||||
"Default Date Format": "Formato de fecha predeterminado",
|
"Default Date Format": "Formato de fecha predeterminado",
|
||||||
|
"Default Datetime Format": "Formato de fecha y hora predeterminado",
|
||||||
"Default Font": "Fuente predeterminada",
|
"Default Font": "Fuente predeterminada",
|
||||||
"Default Language": "Idioma predeterminado",
|
"Default Language": "Idioma predeterminado",
|
||||||
"Default Savings Account": "Cuenta de Ahorros predeterminada",
|
"Default Savings Account": "Cuenta de Ahorros predeterminada",
|
||||||
|
|||||||
@@ -1645,6 +1645,7 @@
|
|||||||
"Decimals to Display": "Decimales para mostrar",
|
"Decimals to Display": "Decimales para mostrar",
|
||||||
"Default": "Predeterminado",
|
"Default": "Predeterminado",
|
||||||
"Default Date Format": "Formato de fecha predeterminado",
|
"Default Date Format": "Formato de fecha predeterminado",
|
||||||
|
"Default Datetime Format": "Formato de fecha y hora predeterminado",
|
||||||
"Default Font": "Fuente predeterminada",
|
"Default Font": "Fuente predeterminada",
|
||||||
"Default Language": "Idioma predeterminado",
|
"Default Language": "Idioma predeterminado",
|
||||||
"Default Savings Account": "Cuenta de Ahorros predeterminada",
|
"Default Savings Account": "Cuenta de Ahorros predeterminada",
|
||||||
|
|||||||
@@ -1649,6 +1649,7 @@
|
|||||||
"Decimals to Display": "Décimales à afficher",
|
"Decimals to Display": "Décimales à afficher",
|
||||||
"Default": "Défaut",
|
"Default": "Défaut",
|
||||||
"Default Date Format": "Format de date par défaut",
|
"Default Date Format": "Format de date par défaut",
|
||||||
|
"Default Datetime Format": "Format de date et heure par défaut",
|
||||||
"Default Font": "Police par défaut",
|
"Default Font": "Police par défaut",
|
||||||
"Default Language": "Langage par défaut",
|
"Default Language": "Langage par défaut",
|
||||||
"Default Savings Account": "Compte d'épargne par défaut",
|
"Default Savings Account": "Compte d'épargne par défaut",
|
||||||
|
|||||||
@@ -1645,6 +1645,7 @@
|
|||||||
"Decimals to Display": "Decimali da visualizzare",
|
"Decimals to Display": "Decimali da visualizzare",
|
||||||
"Default": "Predefinito",
|
"Default": "Predefinito",
|
||||||
"Default Date Format": "Formato data predefinito",
|
"Default Date Format": "Formato data predefinito",
|
||||||
|
"Default Datetime Format": "Formato data e ora predefinito",
|
||||||
"Default Font": "Carattere predefinito",
|
"Default Font": "Carattere predefinito",
|
||||||
"Default Language": "Lingua di default",
|
"Default Language": "Lingua di default",
|
||||||
"Default Savings Account": "Conto di risparmio predefinito",
|
"Default Savings Account": "Conto di risparmio predefinito",
|
||||||
|
|||||||
@@ -1647,6 +1647,7 @@
|
|||||||
"Decimals to Display": "표시할 소수점",
|
"Decimals to Display": "표시할 소수점",
|
||||||
"Default": "기본",
|
"Default": "기본",
|
||||||
"Default Date Format": "기본 날짜 형식",
|
"Default Date Format": "기본 날짜 형식",
|
||||||
|
"Default Datetime Format": "기본 날짜 및 시간 형식",
|
||||||
"Default Font": "기본 글꼴",
|
"Default Font": "기본 글꼴",
|
||||||
"Default Language": "기본 설정 언어",
|
"Default Language": "기본 설정 언어",
|
||||||
"Default Savings Account": "기본 저축 계좌",
|
"Default Savings Account": "기본 저축 계좌",
|
||||||
|
|||||||
@@ -1644,6 +1644,7 @@
|
|||||||
"Decimals to Display": "Rodomos dešimtainės trupmenos",
|
"Decimals to Display": "Rodomos dešimtainės trupmenos",
|
||||||
"Default": "Numatytas",
|
"Default": "Numatytas",
|
||||||
"Default Date Format": "Numatytasis datos formatas",
|
"Default Date Format": "Numatytasis datos formatas",
|
||||||
|
"Default Datetime Format": "Numatytasis datos ir laiko formatas",
|
||||||
"Default Font": "Numatytasis šriftas",
|
"Default Font": "Numatytasis šriftas",
|
||||||
"Default Language": "Numatytoji kalba",
|
"Default Language": "Numatytoji kalba",
|
||||||
"Default Savings Account": "Numatytoji taupomoji sąskaita",
|
"Default Savings Account": "Numatytoji taupomoji sąskaita",
|
||||||
|
|||||||
@@ -1646,6 +1646,7 @@
|
|||||||
"Decimals to Display": "Parādāmie decimālskaitļi",
|
"Decimals to Display": "Parādāmie decimālskaitļi",
|
||||||
"Default": "Noklusējums",
|
"Default": "Noklusējums",
|
||||||
"Default Date Format": "Noklusējuma datuma formāts",
|
"Default Date Format": "Noklusējuma datuma formāts",
|
||||||
|
"Default Datetime Format": "Noklusējuma datuma un laika formāts",
|
||||||
"Default Font": "Noklusējuma fonts",
|
"Default Font": "Noklusējuma fonts",
|
||||||
"Default Language": "Noklusējuma valoda",
|
"Default Language": "Noklusējuma valoda",
|
||||||
"Default Savings Account": "Noklusējuma krājkonts",
|
"Default Savings Account": "Noklusējuma krājkonts",
|
||||||
|
|||||||
@@ -1644,6 +1644,7 @@
|
|||||||
"Decimals to Display": "प्रदर्शन गर्न दशमलव",
|
"Decimals to Display": "प्रदर्शन गर्न दशमलव",
|
||||||
"Default": "पूर्वनिर्धारित",
|
"Default": "पूर्वनिर्धारित",
|
||||||
"Default Date Format": "पूर्वनिर्धारित मिति ढाँचा",
|
"Default Date Format": "पूर्वनिर्धारित मिति ढाँचा",
|
||||||
|
"Default Datetime Format": "पूर्वनिर्धारित मिति र समय ढाँचा",
|
||||||
"Default Font": "पूर्वनिर्धारित फन्ट",
|
"Default Font": "पूर्वनिर्धारित फन्ट",
|
||||||
"Default Language": "पूर्वनिर्धारित भाषा",
|
"Default Language": "पूर्वनिर्धारित भाषा",
|
||||||
"Default Savings Account": "पूर्वनिर्धारित बचत खाता",
|
"Default Savings Account": "पूर्वनिर्धारित बचत खाता",
|
||||||
|
|||||||
@@ -1645,6 +1645,7 @@
|
|||||||
"Decimals to Display": "Decimais para exibir",
|
"Decimals to Display": "Decimais para exibir",
|
||||||
"Default": "Padrão",
|
"Default": "Padrão",
|
||||||
"Default Date Format": "Formato de data padrão",
|
"Default Date Format": "Formato de data padrão",
|
||||||
|
"Default Datetime Format": "Formato de data e hora padrão",
|
||||||
"Default Font": "Fonte padrão",
|
"Default Font": "Fonte padrão",
|
||||||
"Default Language": "Idioma padrão",
|
"Default Language": "Idioma padrão",
|
||||||
"Default Savings Account": "Conta poupança padrão",
|
"Default Savings Account": "Conta poupança padrão",
|
||||||
|
|||||||
@@ -1643,6 +1643,7 @@
|
|||||||
"Decimals to Display": "Desimali za Kuonyeshwa",
|
"Decimals to Display": "Desimali za Kuonyeshwa",
|
||||||
"Default": "Chaguomsingi",
|
"Default": "Chaguomsingi",
|
||||||
"Default Date Format": "Umbizo la Tarehe Chaguomsingi",
|
"Default Date Format": "Umbizo la Tarehe Chaguomsingi",
|
||||||
|
"Default Datetime Format": "Umbizo la Tarehe na Wakati Chaguomsingi",
|
||||||
"Default Font": "Fonti Chaguomsingi",
|
"Default Font": "Fonti Chaguomsingi",
|
||||||
"Default Language": "Lugha Chaguomsingi",
|
"Default Language": "Lugha Chaguomsingi",
|
||||||
"Default Savings Account": "Akaunti ya Akiba chaguomsingi",
|
"Default Savings Account": "Akaunti ya Akiba chaguomsingi",
|
||||||
|
|||||||
@@ -56,6 +56,8 @@ export const environment = {
|
|||||||
defaultLanguage: loadedEnv['defaultLanguage'] || 'en-US',
|
defaultLanguage: loadedEnv['defaultLanguage'] || 'en-US',
|
||||||
supportedLanguages:
|
supportedLanguages:
|
||||||
loadedEnv['supportedLanguages'] || 'cs-CS,de-DE,en-US,es-MX,fr-FR,it-IT,ko-KO,lt-LT,lv-LV,ne-NE,pt-PT,sw-SW',
|
loadedEnv['supportedLanguages'] || 'cs-CS,de-DE,en-US,es-MX,fr-FR,it-IT,ko-KO,lt-LT,lv-LV,ne-NE,pt-PT,sw-SW',
|
||||||
|
defaultFormatDate: loadedEnv['defaultFormatDate'] || '',
|
||||||
|
defaultFormatDatetime: loadedEnv['defaultFormatDatetime'] || '',
|
||||||
preloadClients: loadedEnv['preloadClients'] || true,
|
preloadClients: loadedEnv['preloadClients'] || true,
|
||||||
|
|
||||||
defaultCharDelimiter: loadedEnv['defaultCharDelimiter'] || ',',
|
defaultCharDelimiter: loadedEnv['defaultCharDelimiter'] || ',',
|
||||||
|
|||||||
@@ -58,6 +58,8 @@ export const environment = {
|
|||||||
defaultLanguage: loadedEnv.defaultLanguage || 'en-US',
|
defaultLanguage: loadedEnv.defaultLanguage || 'en-US',
|
||||||
supportedLanguages:
|
supportedLanguages:
|
||||||
loadedEnv.supportedLanguages || 'cs-CS,de-DE,en-US,es-MX,fr-FR,it-IT,ko-KO,lt-LT,lv-LV,ne-NE,pt-PT,sw-SW',
|
loadedEnv.supportedLanguages || 'cs-CS,de-DE,en-US,es-MX,fr-FR,it-IT,ko-KO,lt-LT,lv-LV,ne-NE,pt-PT,sw-SW',
|
||||||
|
defaultFormatDate: loadedEnv.defaultFormatDate || '',
|
||||||
|
defaultFormatDatetime: loadedEnv.defaultFormatDatetime || '',
|
||||||
preloadClients: loadedEnv['preloadClients'] || true,
|
preloadClients: loadedEnv['preloadClients'] || true,
|
||||||
|
|
||||||
defaultCharDelimiter: loadedEnv.defaultCharDelimiter || ',',
|
defaultCharDelimiter: loadedEnv.defaultCharDelimiter || ',',
|
||||||
|
|||||||
Reference in New Issue
Block a user