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

TEIS-2445 Add edit inspection data models and service

parent 8335021f
<teis-modal [title]="'edit_data' | translate" icon="icon-edit">
<teis-modal [title]="'edit_data' | translate" icon="icon-edit" [loading]="!form">
<teis-form-layout [colsize]="20">
<form [formGroup]="form" (ngSubmit)="submit()">
<form [formGroup]="form" (ngSubmit)="submit()" *ngIf="form">
<div class="mb-4">
<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">
......@@ -12,7 +12,7 @@
</form-row>
<form-row [label]="'inspection_type' | translate" [comment]="'required' | translate" labelClass="text-left justify-start col-xs-20 col-md-5" contentClass="col-xs-20 col-md-12">
<ska-select formControlName="inspectionType"></ska-select>
<ska-select formControlName="inspectionType" [data]="inspectionTypes" [displayFunc]="classifierDisplayFunc"></ska-select>
</form-row>
<form-row [label]="'number_of_vehicles' | translate" [comment]="'required' | translate" labelClass="text-left justify-start col-xs-20 col-md-5" contentClass="col-xs-20 col-md-12">
......
import { Component, Input, OnInit } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';
import { DriversInspectionsFacade } from '@teis/features/drivers-inspections/drivers-inspections-facade.service';
import { DriversInspectionInspectedItemsDto } from '@teis/features/drivers-inspections/services/drivers-inspections.model';
import { ClassifiersApi } from '@teis/services/classifiers/classifiers.api.service';
import { ClassifierItemDefinitionId, ClassifierItemDto } from '@teis/services/classifiers/classifiers.models';
import { triggerValidation } from '@teis/utils';
import { ModalService } from '@teis/widgets/teis-modal/modal.service';
@Component({
selector: 'teis-edit-inspection-data',
......@@ -8,23 +13,42 @@ import { DriversInspectionInspectedItemsDto } from '@teis/features/drivers-inspe
styleUrls: ['./edit-inspection-data.component.scss']
})
export class EditInspectionDataComponent implements OnInit {
constructor(private fb: FormBuilder) { }
constructor(private fb: FormBuilder, private classifiersApi: ClassifiersApi, private modal: ModalService, private facade: DriversInspectionsFacade) { }
@Input() inspectionData: DriversInspectionInspectedItemsDto;
form: FormGroup;
inspectionTypes: ClassifierItemDto[] = [];
classifierDisplayFunc = (item: ClassifierItemDto) => item.name;
ngOnInit(): void {
this.initializeForm();
this.classifiersApi.fetchClassifierItems({ definitionId: ClassifierItemDefinitionId.DriversInspectionType }).subscribe((inspectionTypes: ClassifierItemDto[]) => {
this.inspectionTypes = inspectionTypes;
this.initializeForm(inspectionTypes);
});
}
initializeForm(): void {
initializeForm(inspectionTypes: ClassifierItemDto[]): void {
const inspectionTypeValue = inspectionTypes.find(inspectionType => inspectionType.id === this.inspectionData.inspectionType?.id);
this.form = this.fb.group({
controlledPeriodBeginning: [this.inspectionData.controlledPeriodBeginning],
controlledPeriodEnd: [this.inspectionData.controlledPeriodEnd],
numberOfDrivers: [this.inspectionData.numberOfDrivers],
numberOfVehicles: [this.inspectionData.numberOfVehicles],
inspectionType: [this.inspectionData.inspectionType],
inspectionType: [inspectionTypeValue],
});
}
cancel(): void {
this.modal.close();
}
submit(): void {
triggerValidation(this.form);
if (this.form.invalid) {
return;
}
this.facade.editDriversInspectionData(this.inspectionData.id, this.form.value);
}
}
......@@ -1175,5 +1175,6 @@
"inspection_type": "Kontrolli tüüp EN",
"misdemeanor_ref_number": "Väärteomenetluse viitenumber EN",
"controlled_period_start": "Kontrollitud ajavahemiku algus EN",
"controlled_period_end": "Kontrollitud ajavahemiku lõpp EN"
"controlled_period_end": "Kontrollitud ajavahemiku lõpp EN",
"edit_inspection_data_success": "Kontrolli üldandmed edukalt muudetud EN"
}
\ No newline at end of file
......@@ -1175,5 +1175,6 @@
"inspection_type": "Kontrolli tüüp",
"misdemeanor_ref_number": "Väärteomenetluse viitenumber",
"controlled_period_start": "Kontrollitud ajavahemiku algus",
"controlled_period_end": "Kontrollitud ajavahemiku lõpp"
"controlled_period_end": "Kontrollitud ajavahemiku lõpp",
"edit_inspection_data_success": "Kontrolli üldandmed edukalt muudetud"
}
\ No newline at end of file
......@@ -1175,5 +1175,6 @@
"inspection_type": "Kontrolli tüüp RU",
"misdemeanor_ref_number": "Väärteomenetluse viitenumber RU",
"controlled_period_start": "Kontrollitud ajavahemiku algus RU",
"controlled_period_end": "Kontrollitud ajavahemiku lõpp RU"
"controlled_period_end": "Kontrollitud ajavahemiku lõpp RU",
"edit_inspection_data_success": "Kontrolli üldandmed edukalt muudetud RU"
}
\ No newline at end of file
......@@ -21,6 +21,7 @@ import {
DriversViolationPublicDto,
CreateOrEditNumberOfInspectedItemsDto,
DriversInspectionInspectedItemsDto,
EditDriversInspectionInspectedItemsDto,
} from '@teis/features/drivers-inspections/services/drivers-inspections.model';
import { BehaviorSubject, Observable, Subject } from 'rxjs';
import { distinctUntilChanged, map, take, takeUntil, tap } from 'rxjs/operators';
......@@ -389,6 +390,14 @@ export class DriversInspectionsFacade implements OnDestroy {
});
}
editDriversInspectionData(id: string, inspectionData: EditDriversInspectionInspectedItemsDto) {
this.driversInspectionOfficeApi.patchDriversInspectionData(id, inspectionData).subscribe(() => {
this.getNumberOfInspectedItems();
this.modal.close();
this.message.addToastSuccess(this.translate.instant('edit_inspection_data_success'), 3000);
});
}
postDriversInspectionFiles(file: File) {
const { id } = this.driversInspection$.getValue();
const formData: FormData = new FormData();
......
......@@ -8,6 +8,7 @@ import {
NumberOfInspectedItemsDto,
CreateOrEditNumberOfInspectedItemsDto,
DriversInspectionInspectedItemsDto,
EditDriversInspectionInspectedItemsDto,
} from '@teis/features/drivers-inspections/services/drivers-inspections.model';
import { ApiOffice } from '@teis/services/api-office';
......@@ -62,4 +63,8 @@ export class DriversInspectionsOfficeApi extends ApiOffice {
deleteNumberOfInspectedItems(id: string) {
return this.http.delete(`${this.url}/number-of-inspected-items/${id}`);
}
patchDriversInspectionData(id: string, body: EditDriversInspectionInspectedItemsDto) {
return this.http.patch(`${this.url}/${id}/inspection-data`, body);
}
}
......@@ -189,6 +189,14 @@ export interface DriversInspectionInspectedItemsDto {
permissions: PermissionDto[];
}
export interface EditDriversInspectionInspectedItemsDto {
controlledPeriodBeginning: string;
controlledPeriodEnd: string;
inspectionType: ClassifierItemDto;
numberOfDrivers: number;
numberOfVehicles: number;
}
export interface NumberOfInspectedItemsDto {
createdAt: string;
driversInspectionFileId: string;
......
......@@ -105,4 +105,5 @@ export enum ClassifierItemDefinitionId {
ViolationLegislation = 'VIOLATION_LEGISLATION',
ViolationStatus = 'VIOLATION_STATUS',
Vocabulary = 'VOCABULARY',
DriversInspectionType = 'DRIVERS_INSPECTION_TYPE'
}
\ No newline at end of file
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