fix models
This commit is contained in:
@@ -102,9 +102,9 @@
|
||||
<ui-loader *ngIf="submitLoading$ | async" uiType="absolute"></ui-loader>
|
||||
<msfa-report-description-list [avrop]="avrop">
|
||||
<dt>Typ av sysselsättning</dt>
|
||||
<dd>{{typeFormControl.value}}</dd>
|
||||
<dd>{{convertTypeValueToLabel(typeFormControl.value)}}</dd>
|
||||
<dt>Omfattning</dt>
|
||||
<dd>{{omfattningFormControl.value}}</dd>
|
||||
<dd>{{convertOmfattningValueToLabel(omfattningFormControl.value)}}</dd>
|
||||
<ng-container *ngIf="showPercentFormControl">
|
||||
<dt>Antal procent vid deltid</dt>
|
||||
<dd>{{percentFormControl.value}}%</dd>
|
||||
|
||||
@@ -12,7 +12,7 @@ import { BehaviorSubject, Observable } from 'rxjs';
|
||||
import { map, shareReplay, switchMap, take } from 'rxjs/operators';
|
||||
import { SignalFormService } from './signal-form.service';
|
||||
import { SignalFormValidator } from './signal-form.validator';
|
||||
import { SignalFormData, SignalFormKeys, SignalOmfattning } from './signal-form.model';
|
||||
import { SignalFormData, SignalFormKeys, SignalOmfattning, SignalType } from './signal-form.model';
|
||||
|
||||
@Component({
|
||||
selector: 'msfa-signal-form',
|
||||
@@ -31,7 +31,7 @@ export class SignalFormComponent {
|
||||
signalFormGroup = new FormGroup(
|
||||
{
|
||||
type: new FormControl(null),
|
||||
omfattning: new FormControl('heltid'),
|
||||
omfattning: new FormControl(SignalOmfattning.Heltid),
|
||||
percent: new FormControl(50),
|
||||
startDate: new FormControl(new Date()),
|
||||
},
|
||||
@@ -50,8 +50,8 @@ export class SignalFormComponent {
|
||||
);
|
||||
|
||||
typeSelectItems: FormSelectItem[] = [
|
||||
{ name: 'Arbete', value: 'arbete' },
|
||||
{ name: 'Utbildning', value: 'utbildning' },
|
||||
{ name: 'Arbete', value: SignalType.Arbete },
|
||||
{ name: 'Utbildning', value: SignalType.Utbildning },
|
||||
];
|
||||
|
||||
omfattningRadioButtons: Radiobutton[] = [
|
||||
@@ -61,6 +61,13 @@ export class SignalFormComponent {
|
||||
|
||||
constructor(private signalFormService: SignalFormService, private activatedRoute: ActivatedRoute) {}
|
||||
|
||||
convertTypeValueToLabel(type: SignalType): string {
|
||||
return this.typeSelectItems?.find(selectItem => selectItem.value === type)?.name;
|
||||
}
|
||||
convertOmfattningValueToLabel(type: SignalType): string {
|
||||
return this.omfattningRadioButtons?.find(radiobuttons => radiobuttons.value === type)?.label;
|
||||
}
|
||||
|
||||
get formErrors(): { [key: string]: string } {
|
||||
return this.signalFormGroup.errors || {};
|
||||
}
|
||||
@@ -79,7 +86,7 @@ export class SignalFormComponent {
|
||||
}
|
||||
|
||||
get showPercentFormControl(): boolean {
|
||||
return this.omfattningFormControl.value === 'deltid';
|
||||
return this.omfattningFormControl.value === SignalOmfattning.Deltid;
|
||||
}
|
||||
|
||||
get startDateFormValueAsDate(): Date {
|
||||
@@ -110,9 +117,9 @@ export class SignalFormComponent {
|
||||
|
||||
private typeToRequest(type: string): SignalRequestType {
|
||||
switch (type) {
|
||||
case 'arbete':
|
||||
case SignalType.Arbete:
|
||||
return SignalRequestType.Work;
|
||||
case 'utbildning':
|
||||
case SignalType.Utbildning:
|
||||
return SignalRequestType.Education;
|
||||
default:
|
||||
return;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { AbstractControl, ValidatorFn } from '@angular/forms';
|
||||
import { SignalFormData } from './signal-form.model';
|
||||
import { SignalFormData, SignalOmfattning } from './signal-form.model';
|
||||
|
||||
export class SignalFormValidator {
|
||||
static isSignalValid(): ValidatorFn {
|
||||
@@ -13,7 +13,7 @@ export class SignalFormValidator {
|
||||
type: 'Typ av sysselsättning måste väljas',
|
||||
};
|
||||
}
|
||||
if (type && omfattning === 'deltid') {
|
||||
if (type && omfattning === SignalOmfattning.Deltid) {
|
||||
if (percent < 1) {
|
||||
errors = {
|
||||
...errors,
|
||||
|
||||
@@ -1,6 +1,17 @@
|
||||
export interface SignalResponse {
|
||||
typ: 'arbete' | 'utbildning';
|
||||
omfattning: 'heltid' | 'deltid';
|
||||
omfattning_procent: number;
|
||||
startdatum: string;
|
||||
export enum SignalResponseType {
|
||||
Work = 'work',
|
||||
Education = 'education',
|
||||
}
|
||||
|
||||
export enum SignalResponseOmfattning {
|
||||
Heltid = 'heltid',
|
||||
Deltid = 'deltid',
|
||||
}
|
||||
|
||||
export interface SignalResponse {
|
||||
genomforandereferens: number;
|
||||
type: SignalResponseType;
|
||||
omfattning: SignalResponseOmfattning;
|
||||
omfattningPercent: number;
|
||||
startDate: string;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
import { SignalResponse } from './api/signal.response.model';
|
||||
import { Signal } from '../../pages/deltagare/pages/deltagare-details/pages/report-forms/signal-form/signal-form.model';
|
||||
|
||||
export type Signal = SignalResponse;
|
||||
|
||||
export function mapResponseToSignal(data: SignalResponse): Signal {
|
||||
const { typ, startdatum, omfattning, omfattning_procent } = data;
|
||||
|
||||
return {
|
||||
type: typ,
|
||||
omfattning,
|
||||
percent: omfattning_procent,
|
||||
startDate: new Date(startdatum),
|
||||
};
|
||||
return data;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user