Commit c3dea9b5 authored by Pearu Sarv's avatar Pearu Sarv
Browse files

TEIS-2446 Edit misdemeanor data form

parent a7876c12
......@@ -2,34 +2,43 @@
<teis-form-layout [colsize]="20">
<form [formGroup]="form" (ngSubmit)="submit()" *ngIf="form">
<div class="mb-4">
<form-row [label]="'controlled_period_start' | translate" labelClass="text-left justify-start col-xs-20 col-md-5" contentClass="col-xs-20 col-md-12">
<form-row [label]="'convicted_person' | translate" labelClass="text-left justify-start col-xs-20 col-md-5" contentClass="col-xs-20 col-md-12">
<div class="d-flex flex-column justify-content-around">
<div class="custom-control custom-radio">
<input
class="custom-control-input"
type="radio"
id="radio-{{convictedPersonType.NaturalPerson}}"
[value]="convictedPersonType.NaturalPerson"
id="radio-{{convictedPersonType.EmployerUnderProceedings}}"
[value]="convictedPersonType.EmployerUnderProceedings"
formControlName="convictedPersonType"
/>
<label class="custom-control-label" for="radio-{{convictedPersonType.NaturalPerson}}">{{ convictedPersonType.NaturalPerson | translate }}</label>
<label class="custom-control-label" for="radio-{{convictedPersonType.EmployerUnderProceedings}}">{{ convictedPersonType.EmployerUnderProceedings | translate }}</label>
</div>
<div class="custom-control custom-radio">
<input
class="custom-control-input"
type="radio"
id="radio-{{convictedPersonType.EmployerUnderProceedings}}"
[value]="convictedPersonType.EmployerUnderProceedings"
id="radio-{{convictedPersonType.NaturalPerson}}"
[value]="convictedPersonType.NaturalPerson"
formControlName="convictedPersonType"
/>
<label class="custom-control-label" for="radio-{{convictedPersonType.EmployerUnderProceedings}}">{{ convictedPersonType.EmployerUnderProceedings | translate }}</label>
<label class="custom-control-label" for="radio-{{convictedPersonType.NaturalPerson}}">{{ convictedPersonType.NaturalPerson | translate }}</label>
</div>
</div>
</form-row>
<form-row [label]="'controlled_period_start' | translate" [comment]="'required' | translate" labelClass="text-left justify-start col-xs-20 col-md-5" contentClass="col-xs-20 col-md-12">
<!-- <ska-datepicker class="flex-grow-1 mr-2" formControlName="controlledPeriodBeginning"> </ska-datepicker> -->
<form-row [label]="'misdemeanor_ref_number' | translate" [comment]="'required' | translate" labelClass="text-left justify-start col-xs-20 col-md-5" contentClass="col-xs-20 col-md-12">
<ska-input type="text" formControlName="misdemeanorRefNumber" minlength="12" maxlength="12"></ska-input>
</form-row>
<ng-container *ngIf="form.value.convictedPersonType === convictedPersonType.NaturalPerson">
<form-row [label]="'name' | translate" [comment]="'required' | translate" labelClass="text-left justify-start col-xs-20 col-md-5" contentClass="col-xs-20 col-md-12">
<ska-input type="text" [required]="true" formControlName="convictedPersonName"></ska-input>
</form-row>
<form-row [label]="'id_code' | translate" [comment]="'required' | translate" labelClass="text-left justify-start col-xs-20 col-md-5" contentClass="col-xs-20 col-md-12">
<ska-input type="text" [required]="true" formControlName="convictedPersonCode" minlength="11" maxlength="11"></ska-input>
</form-row>
</ng-container>
</div>
<teis-flex>
......
import { Component, Input, OnInit } from '@angular/core';
import { Component, Input, OnDestroy, OnInit } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';
import { DriversInspectionsFacade } from '@teis/features/drivers-inspections/drivers-inspections-facade.service';
import { EditMisdemeanorDataDto } from '@teis/features/drivers-inspections/services/drivers-inspections.model';
import { triggerValidation } from '@teis/utils';
import { ModalService } from '@teis/widgets/teis-modal/modal.service';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
enum ConvictedPersonType {
NaturalPerson = 'NATURAL_PERSON',
EmployerUnderProceedings = 'EMPLOYER_UNDER_PROCEEDINGS'
NaturalPerson = 'natural_person',
EmployerUnderProceedings = 'employer_under_proceedings'
}
@Component({
......@@ -12,26 +17,68 @@ enum ConvictedPersonType {
templateUrl: './edit-misdemeanor-data.component.html',
styleUrls: ['./edit-misdemeanor-data.component.scss']
})
export class EditMisdemeanorDataComponent implements OnInit {
export class EditMisdemeanorDataComponent implements OnInit, OnDestroy {
constructor(private fb: FormBuilder) { }
constructor(private fb: FormBuilder, private modal: ModalService, private facade: DriversInspectionsFacade) { }
@Input() misdemeanorData: EditMisdemeanorDataDto;
readonly convictedPersonType = ConvictedPersonType;
private destroy$ = new Subject<boolean>();
form: FormGroup;
ngOnInit(): void {
this.initializeForm();
this.onConvictedPersonTypeChange();
}
initializeForm() {
initializeForm(): void {
const convictedPersonType = this.misdemeanorData.convictedPersonCode ? ConvictedPersonType.NaturalPerson : ConvictedPersonType.EmployerUnderProceedings;
this.form = this.fb.group({
convictedPersonType: [],
convictedPersonCode: [],
convictedPersonName: [],
misdemeanorRefNumber: [],
convictedPersonType: [convictedPersonType],
convictedPersonCode: [this.misdemeanorData.convictedPersonCode],
convictedPersonName: [this.misdemeanorData.convictedPersonName],
misdemeanorRefNumber: [this.misdemeanorData.misdemeanorRefNumber],
});
}
onConvictedPersonTypeChange(): void {
this.form.get('convictedPersonType').valueChanges.pipe(takeUntil(this.destroy$)).subscribe((convictedPersonType: ConvictedPersonType) => {
const codeControl = this.form.get('convictedPersonCode');
const nameControl = this.form.get('convictedPersonName');
if (convictedPersonType === ConvictedPersonType.EmployerUnderProceedings) {
codeControl.clearValidators();
codeControl.reset();
codeControl.markAsPristine();
nameControl.clearValidators();
nameControl.reset();
nameControl.markAsPristine();
}
});
}
cancel(): void {
this.modal.close();
}
submit(): void {
this.form.updateValueAndValidity();
triggerValidation(this.form);
if (this.form.valid) {
const formValue = this.form.value;
const misdemeanorData: EditMisdemeanorDataDto = {
convictedPersonCode: formValue.convictedPersonCode,
convictedPersonName: formValue.convictedPersonName,
misdemeanorRefNumber: formValue.misdemeanorRefNumber,
};
this.facade.editDriversInspectionMisdemeanorData(misdemeanorData);
}
}
ngOnDestroy(): void {
this.destroy$.next(true);
this.destroy$.complete();
}
}
......@@ -1176,5 +1176,9 @@
"misdemeanor_ref_number": "Väärteomenetluse viitenumber EN",
"controlled_period_start": "Kontrollitud ajavahemiku algus EN",
"controlled_period_end": "Kontrollitud ajavahemiku lõpp EN",
"edit_inspection_data_success": "Kontrolli üldandmed edukalt muudetud EN"
"edit_inspection_data_success": "Kontrolli üldandmed edukalt muudetud EN",
"natural_person": "Füüsiline isik EN",
"employer_under_proceedings": "Menetlusalune tööandja EN",
"convicted_person": "Karistatud isik EN",
"edit_inspection_misdemeanor_data_success": "Väärteomenetluse andmed edukalt muudetud EN"
}
\ No newline at end of file
......@@ -1176,5 +1176,9 @@
"misdemeanor_ref_number": "Väärteomenetluse viitenumber",
"controlled_period_start": "Kontrollitud ajavahemiku algus",
"controlled_period_end": "Kontrollitud ajavahemiku lõpp",
"edit_inspection_data_success": "Kontrolli üldandmed edukalt muudetud"
"edit_inspection_data_success": "Kontrolli üldandmed edukalt muudetud",
"natural_person": "Füüsiline isik",
"employer_under_proceedings": "Menetlusalune tööandja",
"convicted_person": "Karistatud isik",
"edit_inspection_misdemeanor_data_success": "Väärteomenetluse andmed edukalt muudetud"
}
\ No newline at end of file
......@@ -1176,5 +1176,9 @@
"misdemeanor_ref_number": "Väärteomenetluse viitenumber RU",
"controlled_period_start": "Kontrollitud ajavahemiku algus RU",
"controlled_period_end": "Kontrollitud ajavahemiku lõpp RU",
"edit_inspection_data_success": "Kontrolli üldandmed edukalt muudetud RU"
"edit_inspection_data_success": "Kontrolli üldandmed edukalt muudetud RU",
"natural_person": "Füüsiline isik RU",
"employer_under_proceedings": "Menetlusalune tööandja RU",
"convicted_person": "Karistatud isik RU",
"edit_inspection_misdemeanor_data_success": "Väärteomenetluse andmed edukalt muudetud RU"
}
\ No newline at end of file
......@@ -22,6 +22,7 @@ import {
CreateOrEditNumberOfInspectedItemsDto,
DriversInspectionInspectedItemsDto,
EditDriversInspectionInspectedItemsDto,
EditMisdemeanorDataDto,
} from '@teis/features/drivers-inspections/services/drivers-inspections.model';
import { BehaviorSubject, Observable, Subject } from 'rxjs';
import { distinctUntilChanged, map, take, takeUntil, tap } from 'rxjs/operators';
......@@ -398,6 +399,15 @@ export class DriversInspectionsFacade implements OnDestroy {
});
}
editDriversInspectionMisdemeanorData(misdemeanorData: EditMisdemeanorDataDto) {
const { id } = this.driversInspection$.getValue();
this.driversInspectionOfficeApi.patchDriversInspectionMisdemeanorData(id, misdemeanorData).subscribe(() => {
this.getNumberOfInspectedItems();
this.modal.close();
this.message.addToastSuccess(this.translate.instant('edit_inspection_misdemeanor_data_success'), 3000);
});
}
postDriversInspectionFiles(file: File) {
const { id } = this.driversInspection$.getValue();
const formData: FormData = new FormData();
......
......@@ -9,6 +9,7 @@ import {
CreateOrEditNumberOfInspectedItemsDto,
DriversInspectionInspectedItemsDto,
EditDriversInspectionInspectedItemsDto,
EditMisdemeanorDataDto,
} from '@teis/features/drivers-inspections/services/drivers-inspections.model';
import { ApiOffice } from '@teis/services/api-office';
......@@ -67,4 +68,8 @@ export class DriversInspectionsOfficeApi extends ApiOffice {
patchDriversInspectionData(id: string, body: EditDriversInspectionInspectedItemsDto) {
return this.http.patch(`${this.url}/${id}/inspection-data`, body);
}
patchDriversInspectionMisdemeanorData(id: string, body: EditMisdemeanorDataDto) {
return this.http.patch(`${this.url}/${id}/misdemeanor-data`, body);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment