Merge branch 'next' into develop

This commit is contained in:
Erik Tiekstra
2021-10-11 15:14:02 +02:00
7 changed files with 63 additions and 23 deletions

View File

@@ -32,15 +32,11 @@
afPlaceholder="Välj orsak till avvikelse"
[afSelectItems]="reason"
[afRequired]="true"
[afInvalidMessage]="reasonFormControl.errors?.required"
[afAnnounceIfOptional]="true"
[afDisableValidStyle]="true"
[afInvalid]="formControlIsInvalid(reasonFormControl)"
></digi-ng-form-select>
<div aria-atomic="true" role="alert">
<digi-form-validation-message *ngIf="formControlIsInvalid(reasonFormControl)" af-variation="error"
>{{reasonFormControl.errors?.required}}
</digi-form-validation-message>
</div>
</div>
<div
@@ -57,15 +53,11 @@
[afLabel]="questions[i]?.name"
[afDisableValidStyle]="true"
[afRequired]="questionIsRequired(questions[i])"
[afInvalidMessage]="question.errors?.required || question.errors?.invalid"
[afAnnounceIfOptional]="true"
[afMaxLength]="2000"
[afInvalid]="formControlIsInvalid(question)"
></digi-ng-form-textarea>
<div aria-atomic="true" role="alert">
<digi-form-validation-message *ngIf="formControlIsInvalid(question)" af-variation="error"
>{{question.errors?.required}}
</digi-form-validation-message>
</div>
</div>
</div>

View File

@@ -8,6 +8,8 @@ import { CustomError } from '@msfa-models/error/custom-error';
import { FragorForAvvikelser } from '@msfa-models/fragor-for-avvikelser.model';
import { OrsaksKoderAvvikelse } from '@msfa-models/orsaks-koder-avvikelse.model';
import { DeltagareApiService } from '@msfa-services/api/deltagare.api.service';
import { markControlsAsDirty } from '@msfa-utils/mark-controls-as-dirty.util';
import { RegexValidator } from '@msfa-utils/validators/regex.validator';
import { RequiredValidator } from '@msfa-validators/required.validator';
import { BehaviorSubject, combineLatest, Observable, Subscription } from 'rxjs';
import { map, shareReplay, switchMap, take } from 'rxjs/operators';
@@ -48,7 +50,7 @@ export class DeltagareAvvikelserapportComponent implements OnInit, OnDestroy {
shareReplay(1)
);
reasons$ = this.deltagareAvvikelseService.getAvvikelseOrsaker$;
reasons$: Observable<OrsaksKoderAvvikelse[]> = this.deltagareAvvikelseService.getAvvikelseOrsaker$;
reasonsAsNgDigiFormSelectItems$: Observable<FormSelectItem[]> = this.reasons$.pipe(
map(reasons => reasons.map(reason => ({ name: reason.name, value: reason.id })))
);
@@ -63,8 +65,8 @@ export class DeltagareAvvikelserapportComponent implements OnInit, OnDestroy {
private subscriptions: Subscription[] = [];
private todayDateISO = new Date().toISOString().slice(0, 10);
avvikelseFormGroup = new FormGroup({
[this.reasonFormName]: new FormControl(null, RequiredValidator('Orsak är obligatorisk')),
[this.reportingDateFormName]: new FormControl(this.todayDateISO, RequiredValidator('Datum är obligatoriskt')),
[this.reasonFormName]: new FormControl(null, [RequiredValidator('Orsak är obligatorisk')]),
[this.reportingDateFormName]: new FormControl(this.todayDateISO, [RequiredValidator('Datum är obligatoriskt')]),
[this.questionsFormName]: new FormArray([]),
});
private formData$: Observable<AvvikelseFormData> = this.avvikelseFormGroup
@@ -141,6 +143,8 @@ export class DeltagareAvvikelserapportComponent implements OnInit, OnDestroy {
openConfirmDialog(): void {
this.shouldValidate$.next(true);
markControlsAsDirty(Object.values(this.avvikelseFormGroup.controls));
this.avvikelseFormGroup.markAllAsTouched();
if (this.avvikelseFormGroup.valid) {
this.confirmDialogIsOpen$.next(true);
@@ -184,7 +188,7 @@ export class DeltagareAvvikelserapportComponent implements OnInit, OnDestroy {
svar: question,
})),
rapporteringsdatum: formData.reportingDate,
};
} as AvvikelseAlternativ;
return { genomforandeReferens, avvikelseAlternativ };
}
@@ -199,7 +203,12 @@ export class DeltagareAvvikelserapportComponent implements OnInit, OnDestroy {
this.currentQuestions.push(question);
this.questionsFormArray.push(
new FormControl('', this.questionIsRequired(question) ? RequiredValidator('Frågan är obligatorisk') : null)
new FormControl(
'',
this.questionIsRequired(question)
? [RequiredValidator('Frågan är obligatorisk'), RegexValidator()]
: [RegexValidator()]
)
);
}
}

View File

@@ -3,7 +3,6 @@
*ngIf="avrop$ | async as avrop; else skeletonRef"
reportTitle="Gemensam planering"
[avrop]="avrop"
[isPeriodDate]="true"
>
<div class="gemensam-planering" *ngIf="currentGenomforandeReferens$ | async as genomforandeReferens">
<div class="gemensam-planering__warning" *ngIf="today < avrop.startDate; else reportRef">
@@ -120,9 +119,12 @@
</dd>
<dt>Tjänst</dt>
<dd>{{avrop.tjanst}}</dd>
<dt>Avser period</dt>
<dt>Startdatum</dt>
<dd>
<digi-typography-time [afDateTime]="avrop.startDate"></digi-typography-time>
</dd>
<dt>Slutdatum</dt>
<dd>
<digi-typography-time [afDateTime]="avrop.startDate"></digi-typography-time> -
<digi-typography-time [afDateTime]="avrop.endDate"></digi-typography-time>
</dd>
<dt>Deltar arbetssökande på distans?</dt>

View File

@@ -1,5 +1,6 @@
import { AbstractControl, ValidatorFn } from '@angular/forms';
import { ANNAN_KAND_ORSAK_ID, ANNAN_ORSAK_ID } from '@msfa-constants/franvaro-reasons';
import { CHARACTER_REGEX } from '@msfa-constants/regex';
import { Franvaro } from '@msfa-models/franvaro.model';
const TIME_REGEX = /^([0-1]?[0-9]|2[0-4]):([0-5][0-9])(:[0-5][0-9])?$/;
@@ -36,11 +37,18 @@ export class FranvaroReportValidator {
...errors,
otherKnownReason: 'Känd orsak måste väljas',
};
} else if (otherKnownReason === ANNAN_ORSAK_ID && !knownReasonComment) {
errors = {
...errors,
knownReasonComment: 'Beskrivning av frånvaro är obligatorisk',
};
} else if (otherKnownReason === ANNAN_ORSAK_ID) {
if (!knownReasonComment) {
errors = {
...errors,
knownReasonComment: 'Beskrivning av frånvaro är obligatorisk',
};
} else if (!CHARACTER_REGEX.test(knownReasonComment)) {
errors = {
...errors,
knownReasonComment: 'Beskrivning av frånvaro har en ogiltig värde',
};
}
}
}
if (!date) {

View File

@@ -1,2 +1,3 @@
export const EMAIL_REGEX = /^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$/;
export const ISO_DATE_NO_TIME = /^\d{4}[-/\s]?((((0[13578])|(1[02]))[-/\s]?(([0-2][0-9])|(3[01])))|(((0[469])|(11))[-/\s]?(([0-2][0-9])|(30)))|(02[-/\s]?[0-2][0-9]))$/;
export const CHARACTER_REGEX = /\w/;

View File

@@ -0,0 +1,13 @@
import { AbstractControl, FormArray, FormControl, FormGroup } from '@angular/forms';
export function markControlsAsDirty(controls: AbstractControl[]): void {
controls.forEach(control => {
if (control instanceof FormControl) {
control.markAsDirty({ onlySelf: true });
} else if (control instanceof FormGroup) {
markControlsAsDirty(Object.values(control.controls));
} else if (control instanceof FormArray) {
markControlsAsDirty(control.controls);
}
});
}

View File

@@ -0,0 +1,15 @@
import { AbstractControl, ValidatorFn } from '@angular/forms';
import { CHARACTER_REGEX } from '@msfa-constants/regex';
import { ValidationError } from '@msfa-models/validation-error.model';
export function RegexValidator(regex = CHARACTER_REGEX, message = 'Ogiltig värde'): ValidatorFn {
return (control: AbstractControl): ValidationError => {
if (control && control.value) {
if (!regex.test(control.value)) {
return { invalid: message };
}
}
return null;
};
}