feat(report): Added reporting for frånvaro and avvikelser. (TV-731)
Squashed commit of the following:
commit 3df2d57cc2afdd3a64bea03b7d6e1e6520b18a0c
Author: Daniel Appelgren <daniel.appelgren@arbetsformedlingen.se>
Date: Fri Oct 8 14:41:39 2021 +0200
wip
commit ce4acffd4d4919a0dd38d83226ba6917ee9ecf32
Author: Daniel Appelgren <daniel.appelgren@arbetsformedlingen.se>
Date: Fri Oct 8 14:33:58 2021 +0200
recievedTimestamp
commit a8aa0494c39d9e0218bdd3edefa6f6c063d60189
Merge: 0bbe98e2 6c6e37ed
Author: Daniel Appelgren <daniel.appelgren@arbetsformedlingen.se>
Date: Fri Oct 8 14:31:34 2021 +0200
Merge pull request #188 in TEA/mina-sidor-fa-web from feature/TV-731-new-avvikelserapport to feature/TV-731-refaktorisera-avvikelserapport-split-rapporter
* commit '6c6e37edeed74b6a8ea6dec24f68765027c3b50b':
Avvikelserapport (avvikelse)
Delete avvikelse-orsak-kod.enum.ts
Update deltagare-avvikelserapport.component.html
cleanup and rearrange
unsubscribe, add types and error handling
Delete avvikelse-form-validator.ts
remove uneccessary component
fix validation
form and dialog done
wip
wip
make fragor dynamic with formarray
form arrays working
first
commit 6c6e37edeed74b6a8ea6dec24f68765027c3b50b
Merge: a621fc7f 0bbe98e2
Author: Daniel Appelgren <daniel.appelgren@arbetsformedlingen.se>
Date: Fri Oct 8 14:00:47 2021 +0200
Merge branch 'feature/TV-731-refaktorisera-avvikelserapport-split-rapporter' into feature/TV-731-new-avvikelserapport
# Conflicts:
# apps/mina-sidor-fa/src/app/pages/deltagare/pages/deltagare-details/deltagare-details.module.ts
# apps/mina-sidor-fa/src/app/pages/deltagare/pages/deltagare-details/pages/deltagare-card/components/deltagare-tab-reports/deltagare-tab-reports.component.html
# apps/mina-sidor-fa/src/app/pages/deltagare/pages/deltagare-details/pages/deltagare-reports/components/report-layout/report-layout.component.html
# apps/mina-sidor-fa/src/app/shared/constants/navigation.ts
# apps/mina-sidor-fa/src/app/shared/enums/report-type.enum.ts
commit a621fc7f2425699b6f8720d9cc53776174b65d42
Merge: 3a34d434 a1b81ba3
Author: Daniel Appelgren <daniel.appelgren@arbetsformedlingen.se>
Date: Fri Oct 8 13:55:45 2021 +0200
Merge branch 'feature/TV-731-refaktorisera-avvikelserapport-split-rapporter' into feature/TV-731-new-avvikelserapport
commit 0bbe98e2165ec412d61f1314a1021191c3b77042
Merge: a1b81ba3 d2041c10
Author: Daniel Appelgren <daniel.appelgren@arbetsformedlingen.se>
Date: Fri Oct 8 13:55:16 2021 +0200
Merge pull request #189 in TEA/mina-sidor-fa-web from feature/TV-731-franvaro-erik to feature/TV-731-refaktorisera-avvikelserapport-split-rapporter
* commit 'd2041c10fe02a6c197571149093f734f3bf026f9':
Updated constant
Minor change after PR
Minor changes after PR
Minor changes after demo
Removed console.log
Implemented confirm dialog
Fixed breadcrumbs
Removed steps and fixed error message
Added more validation and styling
Added validation
Started validation
possible to post
WIP
implemented some form elements
Added frånvaro-report component
commit d2041c10fe02a6c197571149093f734f3bf026f9
Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se>
Date: Fri Oct 8 13:53:09 2021 +0200
Updated constant
commit 59820cef664c467d8a85fcfde79de7f1930cd9ed
Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se>
Date: Fri Oct 8 13:52:00 2021 +0200
Minor change after PR
commit b45d975135d1de351661f42d6cb90fd9cd5e9aa3
Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se>
Date: Fri Oct 8 13:43:13 2021 +0200
Minor changes after PR
commit a1b81ba3a7318c5ad7183194e1959058fbc151df
Merge: dad332c3 132aba21
Author: Daniel Appelgren <daniel.appelgren@arbetsformedlingen.se>
Date: Fri Oct 8 13:39:03 2021 +0200
Merge branch 'develop' into feature/TV-731-refaktorisera-avvikelserapport-split-rapporter
commit 3a34d434c0504cb9e4317e9fa5bfa786750d7ae4
Author: Daniel Appelgren <daniel.appelgren@arbetsformedlingen.se>
Date: Fri Oct 8 13:38:49 2021 +0200
Avvikelserapport (avvikelse)
commit b122196d3edf32b8535f01a2bf8159a032409b8f
Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se>
Date: Fri Oct 8 13:16:05 2021 +0200
Minor changes after demo
commit 582e5f4b73fab2bcb86096cdda74c58b9320b3b2
Author: Daniel Appelgren <daniel.appelgren@arbetsformedlingen.se>
Date: Fri Oct 8 13:04:49 2021 +0200
Delete avvikelse-orsak-kod.enum.ts
commit 70a20b7232289669915ae452a4c06db2a20f4f5a
Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se>
Date: Fri Oct 8 12:17:11 2021 +0200
Removed console.log
commit d63e20f087efdf664f05f90b27ff52ad1d912561
Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se>
Date: Fri Oct 8 12:15:51 2021 +0200
Implemented confirm dialog
commit ccbb7709451e6af43bb5463bc5847bda9d5fe097
Author: Daniel Appelgren <daniel.appelgren@arbetsformedlingen.se>
Date: Fri Oct 8 12:04:47 2021 +0200
Update deltagare-avvikelserapport.component.html
commit 9bb05d9e8d66a412e1435ff8fb6b9f14ae442f2c
Author: Daniel Appelgren <daniel.appelgren@arbetsformedlingen.se>
Date: Fri Oct 8 12:04:23 2021 +0200
cleanup and rearrange
commit c8b7496bdc3258efa7169bafd17284899baba862
Author: Daniel Appelgren <daniel.appelgren@arbetsformedlingen.se>
Date: Fri Oct 8 12:00:55 2021 +0200
unsubscribe, add types and error handling
commit bfedf8c5c1d282cd049aef1ae0775aaa2a1bf74f
Author: Daniel Appelgren <daniel.appelgren@arbetsformedlingen.se>
Date: Fri Oct 8 11:52:36 2021 +0200
Delete avvikelse-form-validator.ts
commit 9f060e2f1271822a3f18be58d6f6ad4faa6c5ecc
Author: Daniel Appelgren <daniel.appelgren@arbetsformedlingen.se>
Date: Fri Oct 8 11:51:11 2021 +0200
remove uneccessary component
... and 29 more commits
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
<a class="back-link" [routerLink]="route">
|
||||
<msfa-icon [icon]="iconType.ARROW_LEFT"></msfa-icon>
|
||||
<a [ngClass]="backLinkClass" [routerLink]="route">
|
||||
<msfa-icon *ngIf="showIcon" [icon]="iconType.ARROW_LEFT"></msfa-icon>
|
||||
<ng-content></ng-content>
|
||||
</a>
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
@import 'mixins/buttons';
|
||||
@import 'mixins/link';
|
||||
|
||||
.back-link {
|
||||
@include msfa__link(true);
|
||||
&--link {
|
||||
@include msfa__link(true);
|
||||
}
|
||||
|
||||
&--button {
|
||||
@include msfa__button('secondary');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,17 @@ import { IconType } from '@msfa-enums/icon-type.enum';
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class BackLinkComponent {
|
||||
private readonly _defaultClass = 'back-link';
|
||||
@Input() route: string[];
|
||||
@Input() showIcon = true;
|
||||
@Input() asButton = false;
|
||||
iconType = IconType;
|
||||
|
||||
get backLinkClass(): string {
|
||||
if (this.asButton) {
|
||||
return `${this._defaultClass} ${this._defaultClass}--button`;
|
||||
}
|
||||
|
||||
return `${this._defaultClass} ${this._defaultClass}--link`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
<digi-ng-dialog
|
||||
*ngIf="openConfirmDialog"
|
||||
[afActive]="openConfirmDialog"
|
||||
(afOnPrimaryClick)="sendRequest()"
|
||||
(afOnSecondaryClick)="closeConfirmDialog()"
|
||||
(afOnInactive)="closeConfirmDialog()"
|
||||
afHeading="Bekräfta"
|
||||
*ngIf="dialogOpen"
|
||||
[afActive]="dialogOpen"
|
||||
(afOnPrimaryClick)="closeDialog(true)"
|
||||
(afOnSecondaryClick)="closeDialog(false)"
|
||||
(afOnInactive)="closeDialog(false)"
|
||||
[afHeading]="dialogTitle"
|
||||
afHeadingLevel="h2"
|
||||
[afAriaLabel]="'Bekräfta att skicka in en ' + reportToConfirm"
|
||||
afPrimaryButtonText="Skicka"
|
||||
afSecondaryButtonText="Avbryt"
|
||||
[afAriaLabel]="ariaLabel"
|
||||
[afPrimaryButtonText]="primaryButtonText"
|
||||
[afSecondaryButtonText]="secondaryButtonText"
|
||||
>
|
||||
<p>Är du säker på att du vill skicka in en {{reportToConfirm}}?</p>
|
||||
<ng-content></ng-content>
|
||||
</digi-ng-dialog>
|
||||
|
||||
@@ -8,17 +8,15 @@ import { ConfirmDialog } from '@msfa-enums/confirm-dialog.enum';
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class ConfirmDialogComponent {
|
||||
@Input() openConfirmDialog: boolean;
|
||||
@Input() reportToConfirm: string;
|
||||
@Input() dialogOpen: boolean;
|
||||
@Input() dialogTitle = 'Bekräfta';
|
||||
@Input() ariaLabel = 'Bekräfta för att gå vidare';
|
||||
@Input() primaryButtonText = 'Skicka';
|
||||
@Input() secondaryButtonText = 'Avbryt';
|
||||
@Output() confirmDialogChanged = new EventEmitter<ConfirmDialog>();
|
||||
|
||||
sendRequest(): void {
|
||||
this.openConfirmDialog = false;
|
||||
this.confirmDialogChanged.emit(ConfirmDialog.ACCEPTED);
|
||||
}
|
||||
|
||||
closeConfirmDialog(): void {
|
||||
this.openConfirmDialog = false;
|
||||
this.confirmDialogChanged.emit(ConfirmDialog.DISMISSED);
|
||||
closeDialog(confirmed: boolean): void {
|
||||
this.dialogOpen = false;
|
||||
this.confirmDialogChanged.emit(confirmed ? ConfirmDialog.ACCEPTED : ConfirmDialog.DISMISSED);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
export const ANNAN_KAND_ORSAK_ID = '18';
|
||||
export const ANNAN_ORSAK_ID = '5';
|
||||
@@ -1,7 +1,8 @@
|
||||
export const DELTAGARE_REPORTING_ROUTES = {
|
||||
'gemensam-planering': 'Gemensam planering',
|
||||
'periodisk-redovisning': 'Periodisk redovisning',
|
||||
avvikelserapport: 'Avvikelserapport',
|
||||
franvarorapport: 'Avvikelserapport (frånvaro)',
|
||||
avvikelserapport: 'Avvikelserapport (avvikelse)',
|
||||
};
|
||||
|
||||
export const NAVIGATION = {
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
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]))$/;
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
export enum AvvikelseOrsaksKodEnum {
|
||||
TackatNejTillInsatsEllerAktivitet = 19,
|
||||
TackatNejTillErbjudetArbete = 20,
|
||||
KanInteTillGodoGoraSigProgrammet = 21,
|
||||
MisskottSigEllerStortVerksamheten = 22,
|
||||
SerTillAttErbjudetArbeteInteKommerTillStand = 28
|
||||
}
|
||||
@@ -2,6 +2,6 @@ export enum ReportType {
|
||||
FRANVARO = 'franvaro',
|
||||
AVVIKELSE = 'avvikelse',
|
||||
GemensamPlanering = 'Gemensam planering',
|
||||
Franvaro = 'Frånvaro',
|
||||
Avvikelse = 'Avvikelse',
|
||||
Avvikelse = 'Avvikelserapport (avvikelse)',
|
||||
Franvaro = 'Avvikelserapport (frånvaro)',
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ export interface AvropResponse {
|
||||
sparNamn: string;
|
||||
handledareCiamUserId: string;
|
||||
handledare: string;
|
||||
recievedTimestamp: string;
|
||||
recievedTimestamp: Date;
|
||||
}
|
||||
|
||||
export interface AvropApiResponse {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
export interface OrsaksKoderFranvaroResponse {
|
||||
id: number;
|
||||
name: string;
|
||||
state: number;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ export interface Avrop extends AvropCompact {
|
||||
utforandeVerksamhet: string; // utforandeverksamhet
|
||||
handledareCiamUserId: string;
|
||||
handledare: string;
|
||||
recievedTimestamp: Date;
|
||||
}
|
||||
|
||||
export interface AvropCompactData {
|
||||
@@ -49,6 +50,7 @@ export function mapAvropResponseToAvrop(data: AvropResponse): Avrop {
|
||||
utforandeverksamhet,
|
||||
handledareCiamUserId,
|
||||
handledare,
|
||||
recievedTimestamp,
|
||||
} = data;
|
||||
|
||||
return {
|
||||
@@ -69,5 +71,6 @@ export function mapAvropResponseToAvrop(data: AvropResponse): Avrop {
|
||||
utforandeVerksamhet: utforandeverksamhet,
|
||||
handledareCiamUserId: handledareCiamUserId,
|
||||
handledare,
|
||||
recievedTimestamp,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
import { Fraga } from './fraga.model';
|
||||
|
||||
export interface AvvikelseAlternativ {
|
||||
avvikelseorsakskod: string,
|
||||
frageformular: Array<Fraga>,
|
||||
rapporteringsdatum: string
|
||||
}
|
||||
@@ -1,5 +1,11 @@
|
||||
import { AvvikelseAlternativ } from './avvikelse-alternativ.model';
|
||||
import { FranvaroAlternativ } from './franvaro-alternativ.model';
|
||||
import { Fraga } from '@msfa-models/fraga.model';
|
||||
|
||||
export interface AvvikelseAlternativ {
|
||||
avvikelseorsakskod: string;
|
||||
frageformular: Fraga[];
|
||||
rapporteringsdatum: string;
|
||||
}
|
||||
|
||||
export interface Avvikelse {
|
||||
genomforandeReferens: number;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
export interface DateFormatOptions {
|
||||
year?: 'short' | 'long' | 'numeric';
|
||||
year?: 'numeric' | '2-digit';
|
||||
month?: 'short' | 'long' | 'numeric';
|
||||
day?: 'short' | 'long' | 'numeric';
|
||||
weekday?: 'short' | 'long' | 'numeric';
|
||||
day?: 'numeric' | '2-digit';
|
||||
weekday?: 'short' | 'long' | 'narrow';
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ export interface FranvaroAlternativ {
|
||||
avvikelseOrsaksKod: string;
|
||||
datum: string;
|
||||
heldag: boolean;
|
||||
startTid: string;
|
||||
slutTid: string;
|
||||
startTid: string | null;
|
||||
slutTid: string | null;
|
||||
forvantadNarvaro: {
|
||||
startTid: string;
|
||||
slutTid: string;
|
||||
|
||||
11
apps/mina-sidor-fa/src/app/shared/models/franvaro.model.ts
Normal file
11
apps/mina-sidor-fa/src/app/shared/models/franvaro.model.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
export interface Franvaro {
|
||||
reason: string;
|
||||
date: Date;
|
||||
wholeDay: boolean;
|
||||
startTime: string;
|
||||
endTime: string;
|
||||
expectedPresenceStartTime: string;
|
||||
expectedPresenceEndTime: string;
|
||||
otherKnownReason: string;
|
||||
knownReasonComment: string;
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
import { AvvikelseOrsaksKodEnum } from '@msfa-enums/avvikelse-orsak-kod.enum';
|
||||
import { OrsaksKoderAvvikelseResponse } from './api/orsaks-koder-avvikelse.response.model';
|
||||
|
||||
// TODO rename to AvvikelseOrsaker
|
||||
export interface OrsaksKoderAvvikelse {
|
||||
name: string;
|
||||
value: AvvikelseOrsaksKodEnum;
|
||||
id: string; //AvvikelseOrsaksKodEnum
|
||||
state: number;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ export function mapResponseToOrsaksKoderAvvikelse(data: OrsaksKoderAvvikelseResp
|
||||
|
||||
return {
|
||||
name,
|
||||
value: id,
|
||||
state
|
||||
}
|
||||
id: id.toString(),
|
||||
state,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import { OrsaksKoderFranvaroResponse } from './api/orsaks-koder-franvaro.respons
|
||||
export interface OrsaksKoderFranvaro {
|
||||
name: string;
|
||||
value: FranvaroOrsaksKodEnum;
|
||||
state: number;
|
||||
index?: number;
|
||||
}
|
||||
|
||||
@@ -15,13 +14,12 @@ export interface KandaAvvikelseKoder {
|
||||
}
|
||||
|
||||
export function mapResponseToOrsaksKoderFranvaro(data: OrsaksKoderFranvaroResponse): OrsaksKoderFranvaro {
|
||||
const { name, id, state } = data;
|
||||
const { name, id } = data;
|
||||
|
||||
return {
|
||||
name,
|
||||
value: id,
|
||||
state
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function mapResponseToAndraKandaOrsaker(data: KandaAvvikelseKoderResponse): KandaAvvikelseKoder {
|
||||
@@ -29,6 +27,6 @@ export function mapResponseToAndraKandaOrsaker(data: KandaAvvikelseKoderResponse
|
||||
|
||||
return {
|
||||
name,
|
||||
value: id
|
||||
}
|
||||
value: id,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -14,7 +14,9 @@ import {
|
||||
OrsaksKoderFranvaro,
|
||||
} from '@msfa-models/orsaks-koder-franvaro.model';
|
||||
import { Observable } from 'rxjs';
|
||||
import { filter, map } from 'rxjs/operators';
|
||||
import { catchError, filter, map } from 'rxjs/operators';
|
||||
import { CustomError } from '@msfa-models/error/custom-error';
|
||||
import { ErrorType } from '@msfa-enums/error-type.enum';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
@@ -56,8 +58,16 @@ export class AvvikelseApiService {
|
||||
);
|
||||
}
|
||||
|
||||
public createAvvikelse$(avvikelse: Avvikelse): Promise<void> {
|
||||
return this.httpClient.post<void>(`${this._apiBaseUrl}/avvikelse`, avvikelse).toPromise();
|
||||
public createAvvikelse$(avvikelse: Avvikelse): Observable<unknown> {
|
||||
return this.httpClient.post<void>(`${this._apiBaseUrl}/avvikelse`, avvikelse).pipe(
|
||||
catchError((error: Error) => {
|
||||
throw new CustomError({
|
||||
error,
|
||||
message: 'Det gick inte att skicka avvikelse \n\n' + error.message,
|
||||
type: ErrorType.API,
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
public createFranvaro$(avvikelse: Avvikelse): Promise<void> {
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { environment } from '@msfa-environment';
|
||||
import { OrsaksKoderFranvaroResponse } from '@msfa-models/api/orsaks-koder-franvaro.response.model';
|
||||
import { Avrop } from '@msfa-models/avrop.model';
|
||||
import { FranvaroRequestData } from '@msfa-models/avvikelse.model';
|
||||
import { CustomError, errorToCustomError } from '@msfa-models/error/custom-error';
|
||||
import { mapResponseToOrsaksKoderFranvaro, OrsaksKoderFranvaro } from '@msfa-models/orsaks-koder-franvaro.model';
|
||||
import { DeltagareApiService } from '@msfa-services/api/deltagare.api.service';
|
||||
import { Observable } from 'rxjs';
|
||||
import { catchError, filter, map, shareReplay } from 'rxjs/operators';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class FranvaroReportApiService {
|
||||
private _apiBaseUrl = `${environment.api.url}/rapporter`;
|
||||
|
||||
constructor(private httpClient: HttpClient, private deltagareApiService: DeltagareApiService) {}
|
||||
|
||||
public fetchReasons$(): Observable<OrsaksKoderFranvaro[]> {
|
||||
return this.httpClient.get<{ data: OrsaksKoderFranvaroResponse[] }>(`${this._apiBaseUrl}/orsakskoderfranvaro`).pipe(
|
||||
filter(response => !!response?.data),
|
||||
map(({ data }) => data.map(reason => mapResponseToOrsaksKoderFranvaro(reason))),
|
||||
catchError((error: Error & { status: number }) => {
|
||||
throw new CustomError(
|
||||
errorToCustomError({ ...error, message: `Kunde inte hämta orsaker till frånvaro.\n\n${error.message}` })
|
||||
);
|
||||
}),
|
||||
shareReplay(1)
|
||||
);
|
||||
}
|
||||
public fetchOtherKnownReasons$(): Observable<OrsaksKoderFranvaro[]> {
|
||||
return this.httpClient.get<{ data: OrsaksKoderFranvaroResponse[] }>(`${this._apiBaseUrl}/kandaavvikelsekoder`).pipe(
|
||||
filter(response => !!response?.data),
|
||||
map(({ data }) => data.map(reason => mapResponseToOrsaksKoderFranvaro(reason))),
|
||||
catchError((error: Error & { status: number }) => {
|
||||
throw new CustomError(
|
||||
errorToCustomError({ ...error, message: `Kunde inte hämta kända orsaker till frånvaro.\n\n${error.message}` })
|
||||
);
|
||||
}),
|
||||
shareReplay(1)
|
||||
);
|
||||
}
|
||||
|
||||
public fetchAvropInformation$(genomforandeReferens: number): Observable<Avrop> {
|
||||
return this.deltagareApiService.fetchAvropInformation$(genomforandeReferens);
|
||||
}
|
||||
|
||||
public async postFranvaroReport$(requestData: FranvaroRequestData): Promise<void> {
|
||||
return this.httpClient.post<void>(`${this._apiBaseUrl}/franvaro`, requestData).toPromise();
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
import { DateFormatOptions } from '@msfa-models/date-format-options.model';
|
||||
|
||||
// Takes either 6 or 8 characters string (YYYYMMDD) and formats it to ISO standard (YYYY-MM-DD).
|
||||
export function formatToIsoString(date: string): string {
|
||||
if (date.length === 6) {
|
||||
@@ -16,3 +18,13 @@ export function formatToDate(date: string): Date {
|
||||
|
||||
return new Date(`${year}-${month}-${day}`);
|
||||
}
|
||||
|
||||
export function dateToIsoString(date: Date, locale: string = 'sv-SE'): string {
|
||||
const formatOptions: DateFormatOptions = {
|
||||
year: 'numeric',
|
||||
month: 'numeric',
|
||||
day: 'numeric',
|
||||
};
|
||||
|
||||
return new Date(date).toLocaleDateString(locale, formatOptions);
|
||||
}
|
||||
|
||||
@@ -1,172 +0,0 @@
|
||||
import { AbstractControl, ValidatorFn } from '@angular/forms';
|
||||
import { ReportType } from '@msfa-enums/report-type.enum';
|
||||
import { DayOrPartOfDay } from '@msfa-enums/day-or-part-of-day.enum';
|
||||
import { FranvaroOrsaksKodEnum } from '@msfa-enums/franvaro-orsak-kod.enum';
|
||||
import { KandaOrsakerEnum } from '@msfa-enums/kanda-orsaker-kod.enum';
|
||||
import { ValidationError } from '@msfa-models/validation-error.model';
|
||||
|
||||
export interface Controls {
|
||||
[key: string]: AbstractControl;
|
||||
}
|
||||
|
||||
export function requiredDescriptionValidator(): ValidatorFn {
|
||||
return (control: AbstractControl): ValidationError => {
|
||||
const ctrls = control?.parent?.controls as Controls;
|
||||
|
||||
if (ctrls) {
|
||||
const valueOfNestedFormControl = ctrls['orsakerFormGroup'].get('andraKandaOrsaker').value as string;
|
||||
const valueOfFormControl = control.value as string;
|
||||
const isRequired = !valueOfFormControl && +valueOfNestedFormControl === KandaOrsakerEnum.AnnanOrsak;
|
||||
|
||||
if (isRequired) {
|
||||
return { type: 'required', message: 'Beskrivning är obligatoriskt' };
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function requiredOrsakerValidator(): ValidatorFn {
|
||||
return (control: AbstractControl): ValidationError => {
|
||||
const ctrls = control?.parent?.controls as Controls;
|
||||
|
||||
if (ctrls) {
|
||||
const valueOfNestedFormControl = ctrls['orsaker'].value as string;
|
||||
const isRequired = !valueOfNestedFormControl && !ctrls['andraKandaOrsaker'].value;
|
||||
|
||||
if (isRequired) {
|
||||
return { type: 'required', message: `Orsak är obligatoriskt` };
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function requiredAnnanKandOrsakValidator(): ValidatorFn {
|
||||
return (control: AbstractControl): ValidationError => {
|
||||
const ctrls = control?.parent?.controls as Controls;
|
||||
|
||||
if (ctrls) {
|
||||
const isAnnanKandOrsak = +ctrls['orsaker'].value === FranvaroOrsaksKodEnum.AnnanKandOrsak;
|
||||
const valueOfNestedFormControl = ctrls['andraKandaOrsaker'].value as string;
|
||||
const isRequired = isAnnanKandOrsak && !valueOfNestedFormControl;
|
||||
|
||||
if (isRequired) {
|
||||
return { type: 'required', message: `Annan orsak är obligatoriskt` };
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export class RequiredDateValidator {
|
||||
static CheckIfRequired(): ValidatorFn {
|
||||
return (fg: AbstractControl): { [key: string]: string } => {
|
||||
const valueOfFormControl = fg?.get('date')?.value as string;
|
||||
const isRequired = !valueOfFormControl;
|
||||
|
||||
return isRequired ? { dateIsRequired: 'Datum är obligatoriskt' } : null;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export function requiredDayOrPartOfDayValidator(): ValidatorFn {
|
||||
return (control: AbstractControl): ValidationError => {
|
||||
const ctrls = control?.parent?.controls as Controls;
|
||||
|
||||
if (ctrls) {
|
||||
const isFranvaro = ctrls['alternative'].value === ReportType.FRANVARO;
|
||||
const valueOfFormControl = control.value as string;
|
||||
const isRequired = isFranvaro && !valueOfFormControl;
|
||||
|
||||
if (isRequired) {
|
||||
return { type: 'required', message: `Hel- eller del av dag är obligatoriskt` };
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function requiredStartTimeValidator(): ValidatorFn {
|
||||
return (control: AbstractControl): ValidationError => {
|
||||
const ctrls = control?.parent?.parent?.controls as Controls;
|
||||
|
||||
if (ctrls) {
|
||||
const isFranvaro = (ctrls['alternative']?.value as string) === ReportType.FRANVARO;
|
||||
const isPartOfDay = ctrls['dayOrPartOfDay']?.value === DayOrPartOfDay.DEL_AV_DAG;
|
||||
const valueOfFormControl = control?.value as string;
|
||||
const isRequired = isFranvaro && isPartOfDay && (valueOfFormControl === '' || valueOfFormControl === null);
|
||||
|
||||
if (isRequired) {
|
||||
return { type: 'required', message: `Starttid är obligatoriskt` };
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function requiredEndTimeValidator(): ValidatorFn {
|
||||
return (control: AbstractControl): ValidationError => {
|
||||
const ctrls = control?.parent?.parent?.controls as Controls;
|
||||
|
||||
if (ctrls) {
|
||||
const isFranvaro = (ctrls['alternative']?.value as string) === ReportType.FRANVARO;
|
||||
const isPartOfDay = ctrls['dayOrPartOfDay']?.value === DayOrPartOfDay.DEL_AV_DAG;
|
||||
const valueOfFormControl = control?.value as string;
|
||||
const isRequired = isFranvaro && isPartOfDay && (valueOfFormControl === '' || valueOfFormControl === null);
|
||||
|
||||
if (isRequired) {
|
||||
return { type: 'required', message: `Sluttid är obligatoriskt` };
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function requiredFraga1Validator(): ValidatorFn {
|
||||
return (control: AbstractControl): ValidationError => {
|
||||
const ctrls = control?.parent?.parent?.controls as Controls;
|
||||
|
||||
if (ctrls) {
|
||||
const isAvvikelse = ctrls['alternative']?.value === 'avvikelse';
|
||||
const valueOfFormControl = control.value as string;
|
||||
const isRequired = isAvvikelse && !valueOfFormControl;
|
||||
|
||||
if (isRequired) {
|
||||
return { type: 'required', message: `Beskrivning är obligatoriskt` };
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function requiredfraga2Validator(): ValidatorFn {
|
||||
return (control: AbstractControl): ValidationError => {
|
||||
const ctrls = control?.parent?.parent?.controls as Controls;
|
||||
|
||||
if (ctrls) {
|
||||
const isAvvikelse = ctrls['alternative']?.value === 'avvikelse';
|
||||
const valueOfFormControl = control.value as string;
|
||||
const orsaksKodToValidate = ctrls['orsakerFormGroup']?.get('orsaker')?.value as string;
|
||||
const isRequired =
|
||||
isAvvikelse &&
|
||||
!valueOfFormControl &&
|
||||
orsaksKodToValidate !== '19' &&
|
||||
orsaksKodToValidate !== '20' &&
|
||||
orsaksKodToValidate !== '28';
|
||||
|
||||
if (isRequired) {
|
||||
return { type: 'required', message: `Beskrivning är obligatoriskt` };
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { AbstractControl, ValidatorFn } from '@angular/forms';
|
||||
import { ISO_DATE_NO_TIME } from '@msfa-constants/regex';
|
||||
import { ValidationError } from '@msfa-models/validation-error.model';
|
||||
|
||||
export function isoDateIsValid(date: string): boolean {
|
||||
return ISO_DATE_NO_TIME.test(date);
|
||||
}
|
||||
|
||||
export function isoDateWithoutTimeValidator(): ValidatorFn {
|
||||
return (control: AbstractControl): ValidationError => {
|
||||
if (control && control.value) {
|
||||
const value: string = control.value as string;
|
||||
|
||||
if (!isoDateIsValid(value)) {
|
||||
return { type: 'invalid', message: `Ogiltigt datum, vänligen ange YYYY-MM-DD` };
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user