Skip to content

Commit 8253970

Browse files
fix: add date range validation translations for all languages (#2851)
1 parent e6dddd5 commit 8253970

File tree

15 files changed

+94
-14
lines changed

15 files changed

+94
-14
lines changed

src/app/reports/run-report/run-report.component.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
{{ param.label }} {{ 'labels.commons.is' | translate }}
3030
<strong>{{ 'labels.commons.required' | translate }}</strong>
3131
</mat-error>
32+
<mat-error *ngIf="reportForm.controls[param.name].hasError('endBeforeStart')">
33+
{{ param.label }} {{ 'labels.commons.must be after or equal to start date' | translate }}
34+
</mat-error>
3235
</mat-form-field>
3336

3437
<mat-form-field class="form-field" *ngSwitchCase="'select'">

src/app/reports/run-report/run-report.component.ts

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
/** Angular Imports */
22
import { Component, OnInit } from '@angular/core';
33
import { ActivatedRoute, RouterLink } from '@angular/router';
4-
import { UntypedFormControl, UntypedFormGroup, Validators, ReactiveFormsModule } from '@angular/forms';
4+
import {
5+
AbstractControl,
6+
UntypedFormControl,
7+
UntypedFormGroup,
8+
ValidatorFn,
9+
Validators,
10+
ReactiveFormsModule
11+
} from '@angular/forms';
512

613
/** Custom Services */
714
import { ReportsService } from '../reports.service';
@@ -176,6 +183,7 @@ export class RunReportComponent implements OnInit {
176183
}
177184
this.decimalChoice.patchValue('0');
178185
this.setChildControls();
186+
this.addDateRangeValidator();
179187
}
180188

181189
/**
@@ -206,6 +214,62 @@ export class RunReportComponent implements OnInit {
206214
});
207215
}
208216

217+
addDateRangeValidator(): void {
218+
const dateParams = this.paramData.filter((param: ReportParameter) => param.displayType === 'date');
219+
const startParam = dateParams.find((param: ReportParameter) => this.isStartDateParam(param));
220+
const endParam = dateParams.find((param: ReportParameter) => this.isEndDateParam(param));
221+
222+
if (!startParam || !endParam) {
223+
return;
224+
}
225+
226+
const startControl = this.reportForm.get(startParam.name);
227+
const endControl = this.reportForm.get(endParam.name);
228+
229+
if (!startControl || !endControl) {
230+
return;
231+
}
232+
233+
endControl.addValidators(this.endDateAfterStartValidator(startParam.name));
234+
endControl.updateValueAndValidity({ emitEvent: false });
235+
startControl.valueChanges.subscribe(() => endControl.updateValueAndValidity({ emitEvent: false }));
236+
}
237+
238+
endDateAfterStartValidator(startControlName: string): ValidatorFn {
239+
return (control: AbstractControl) => {
240+
const startControl = control.parent?.get(startControlName);
241+
const startValue = startControl?.value;
242+
const endValue = control.value;
243+
244+
if (!startValue || !endValue) {
245+
return null;
246+
}
247+
248+
const startDate = new Date(startValue);
249+
const endDate = new Date(endValue);
250+
251+
if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) {
252+
return null;
253+
}
254+
255+
if (endDate < startDate) {
256+
return { endBeforeStart: true };
257+
}
258+
259+
return null;
260+
};
261+
}
262+
263+
isStartDateParam(param: ReportParameter): boolean {
264+
const identifier = `${param.name}${param.variable}${param.label}`.toLowerCase();
265+
return identifier.includes('start') || identifier.includes('from');
266+
}
267+
268+
isEndDateParam(param: ReportParameter): boolean {
269+
const identifier = `${param.name}${param.variable}${param.label}`.toLowerCase();
270+
return identifier.includes('end') || identifier.includes('to');
271+
}
272+
209273
/**
210274
* Subscribes to changes in parent parameters value, builds child parameter vis-a-vis parent's value.
211275
*/

src/assets/translations/cs-CS.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,8 @@
807807
"on": "na",
808808
"Password validation": "Heslo by mělo obsahovat minimálně {{minchar}} znaků, které by měly obsahovat 1 velké písmeno, malé písmeno a speciální znak a nemělo by se skládat z opakujících se znaků nebo mezer.",
809809
"Must be at least": "Musí být alespoň",
810-
"Must be less or equal to": "Musí být menší nebo rovno"
810+
"Must be less or equal to": "Musí být menší nebo rovno",
811+
"must be after or equal to start date": "musí být po nebo rovno datu zahájení"
811812
},
812813
"heading": {
813814
"Account Linked Financial": "Seznam účtů spojených s různými finančními aktivitami. Chcete-li vědět více, klikněte:",

src/assets/translations/de-DE.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,8 @@
807807
"on": "An",
808808
"Password validation": "Das Passwort sollte mindestens {{michar}} Zeichen enthalten, aus 1 Großbuchstaben, Kleinbuchstaben und Sonderzeichen bestehen und darf nicht aus wiederholten Zeichen oder Leerzeichen bestehen",
809809
"Must be at least": "Muss mindestens",
810-
"Must be less or equal to": "Muss kleiner oder gleich sein"
810+
"Must be less or equal to": "Muss kleiner oder gleich sein",
811+
"must be after or equal to start date": "muss nach oder gleich dem Startdatum sein"
811812
},
812813
"heading": {
813814
"Account Linked Financial": "Liste der Konten, die mit verschiedenen Finanzaktivitäten verknüpft sind. Um mehr zu erfahren, klicken Sie:",

src/assets/translations/en-US.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,8 @@
811811
"on": "on",
812812
"Password validation": "The password should contain a minimum of {{minchar}} characters, including 1 uppercase, 1 lowercase and a special character and should not include repeated characters or spaces.",
813813
"Must be at least": "Must be at least",
814-
"Must be less or equal to": "Must be less or equal to"
814+
"Must be less or equal to": "Must be less or equal to",
815+
"must be after or equal to start date": "must be after or equal to start date"
815816
},
816817
"heading": {
817818
"Account Linked Financial": "List of accounts linked to different financial activities. To know more click:",

src/assets/translations/es-CL.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,8 @@
806806
"on": "en",
807807
"Password validation": "La contraseña debe contener un mínimo de {{minchar}} caracteres, que deben incluir 1 carácter mayúscula, minúscula y especial y no debe constar de caracteres repetidos ni espacios en blanco.",
808808
"Must be at least": "Debe ser al menos",
809-
"Must be less or equal to": "Debe ser menor o igual a"
809+
"Must be less or equal to": "Debe ser menor o igual a",
810+
"must be after or equal to start date": "debe ser posterior o igual a la fecha de inicio"
810811
},
811812
"heading": {
812813
"Account Linked Financial": "Listado de cuentas vinculadas a diferentes actividades financieras. Para saber más haga clic en:",

src/assets/translations/es-MX.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,8 @@
806806
"on": "en",
807807
"Password validation": "La contraseña debe contener un mínimo de {{minchar}} caracteres, que deben incluir 1 carácter mayúscula, minúscula y especial y no debe constar de caracteres repetidos ni espacios en blanco.",
808808
"Must be at least": "Debe ser al menos",
809-
"Must be less or equal to": "Debe ser menor o igual a"
809+
"Must be less or equal to": "Debe ser menor o igual a",
810+
"must be after or equal to start date": "debe ser posterior o igual a la fecha de inicio"
810811
},
811812
"heading": {
812813
"Account Linked Financial": "Listado de cuentas vinculadas a diferentes actividades financieras. Para saber más haga clic en:",

src/assets/translations/fr-FR.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,8 @@
807807
"on": "sur",
808808
"Password validation": "Le mot de passe doit contenir au minimum {{minchar}} caractères, dont 1 majuscule, 1 minuscule et un caractère spécial et ne doit pas être composé de caractères répétés ou d'espaces blancs.",
809809
"Must be at least": "Doit être au moins",
810-
"Must be less or equal to": "Doit être inférieur ou égal à"
810+
"Must be less or equal to": "Doit être inférieur ou égal à",
811+
"must be after or equal to start date": "doit être postérieure ou égale à la date de début"
811812
},
812813
"heading": {
813814
"Account Linked Financial": "Liste des comptes liés aux différentes activités financières. Pour en savoir plus cliquez :",

src/assets/translations/it-IT.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,8 @@
807807
"on": "SU",
808808
"Password validation": "La password deve contenere almeno {{minchar}} caratteri, di cui 1 carattere maiuscolo, minuscolo e speciale e non deve essere composta da caratteri ripetuti o spazi bianchi",
809809
"Must be at least": "Deve essere almeno",
810-
"Must be less or equal to": "Deve essere minore o uguale a"
810+
"Must be less or equal to": "Deve essere minore o uguale a",
811+
"must be after or equal to start date": "deve essere successiva o uguale alla data di inizio"
811812
},
812813
"heading": {
813814
"Account Linked Financial": "Elenco dei conti collegati a diverse attività finanziarie. Per saperne di più clicca:",

src/assets/translations/ko-KO.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,8 @@
807807
"on": "~에",
808808
"Password validation": "비밀번호는 최소 자여야 하며 대문자, 소문자 및 특수 문자 1개가 포함되어야 하며 반복되는 문자나 공백으로 구성되어서는 안 됩니다.",
809809
"Must be at least": "최소한이어야 합니다",
810-
"Must be less or equal to": "이보다 작거나 같아야 합니다."
810+
"Must be less or equal to": "이보다 작거나 같아야 합니다.",
811+
"must be after or equal to start date": "시작 날짜 이후이거나 같아야 합니다"
811812
},
812813
"heading": {
813814
"Account Linked Financial": "다양한 금융 활동과 연결된 계정 목록입니다. 자세한 내용을 보려면 다음을 클릭하세요.",

0 commit comments

Comments
 (0)