Commit 35301e38 authored by Pearu Sarv's avatar Pearu Sarv
Browse files

TEIS-2445: Add edit inspection data modal

parent ce0ad333
<teis-modal [title]="'edit_data' | translate" icon="icon-edit">
<teis-form-layout [colsize]="20">
<form [formGroup]="form" (ngSubmit)="submit()">
<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">
<ska-datepicker class="flex-grow-1 mr-2" formControlName="controlledPeriodBeginning"> </ska-datepicker>
</form-row>
<form-row [label]="'controlled_period_end' | 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="controlledPeriodEnd"> </ska-datepicker>
</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>
</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">
<ska-number min="0" max="999999999" formControlName="numberOfVehicles" [name]="'number_of_vehicles' | translate" required pattern="\d+"></ska-number>
</form-row>
<form-row [label]="'number_of_drivers' | translate" [comment]="'required' | translate" labelClass="text-left justify-start col-xs-20 col-md-5" contentClass="col-xs-20 col-md-12">
<ska-number min="0" max="999999999" formControlName="numberOfDrivers" [name]="'number_of_drivers' | translate" required pattern="\d+"></ska-number>
</form-row>
</div>
<teis-flex>
<form-button-with-confirmation [form]="form" [buttonBackLabel]="'abandon' | translate" (confirm)="cancel()"> </form-button-with-confirmation>
<button teis-button teis-submitting type="submit">
{{ 'save' | translate }}
</button>
</teis-flex>
</form>
</teis-form-layout>
</teis-modal>
\ No newline at end of file
import { Component, Input, OnInit } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';
import { DriversInspectionInspectedItemsDto } from '@teis/features/drivers-inspections/services/drivers-inspections.model';
@Component({
selector: 'teis-edit-inspection-data',
templateUrl: './edit-inspection-data.component.html',
styleUrls: ['./edit-inspection-data.component.scss']
})
export class EditInspectionDataComponent implements OnInit {
constructor(private fb: FormBuilder) { }
@Input() inspectionData: DriversInspectionInspectedItemsDto;
form: FormGroup;
ngOnInit(): void {
this.initializeForm();
}
initializeForm(): void {
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],
});
}
}
......@@ -24,7 +24,7 @@ export const calculateSums = (items: NumberOfInspectedItemsDto[], inspectionType
}, {});
};
export const calculateTotalSum = (items: NumberOfInspectedItemsDto[]): number | null => {
export const calculateTotalSum = (items: NumberOfInspectedItemsDto[]): number => {
return !items?.length
? null
: items.reduce((totalSum, item) => {
......
<teis-loader *ngIf="(facade.loading | async).numberOfInspectedItems; else content"></teis-loader>
<ng-template #content>
<div class="mt-4">
<teis-header variant="block" [title]="'inspected_numbers' | translate"> </teis-header>
<teis-header variant="block" [title]="'inspected_numbers' | translate">
<button *permission="{ id: inspectionId$ | async, type: permissionType, permission: editInspectionPermission }" teis-button variant="plain" (click)="openEditInspectionDataModal()">
<teis-icon icon="icon-edit"></teis-icon>
{{ 'edit' | translate }}
</button>
</teis-header>
</div>
<number-of-inspected-items-detail [itemsDetails]="inspectionInspectedItems$ | async"></number-of-inspected-items-detail>
......
import { Component, OnInit } from '@angular/core';
import { DriversInspectionsFacade } from '@teis/features/drivers-inspections/drivers-inspections-facade.service';
import { DriversInspectionPermission, DriversInspectionType, InspectedItem } from '@teis/features/drivers-inspections/services/drivers-inspections.model';
import { DriversInspectionInspectedItemsDto, DriversInspectionPermission, InspectedItem, NumberOfInspectedItemsDto } from '@teis/features/drivers-inspections/services/drivers-inspections.model';
import { PermissionDataObjectType } from '@teis/services/permissions/permissions.model';
import { ModalService } from '@teis/widgets/teis-modal/modal.service';
import { Observable } from 'rxjs';
import { map, shareReplay, take } from 'rxjs/operators';
import { AddOrEditNumberOfInspectedItemsComponent } from '../add-or-edit-number-of-inspected-items/add-or-edit-number-of-inspected-items.component';
import { EditInspectionDataComponent } from '../edit-inspection-data/edit-inspection-data.component';
import { calculateTotalSum } from '../number-of-inspected-items-table/utils';
@Component({
......@@ -16,21 +18,28 @@ export class NumberOfInspectedItemsComponent implements OnInit {
constructor(public facade: DriversInspectionsFacade, private modal: ModalService) { }
numberOfDriversItems$ = this.facade.numberOfDriversItems.pipe(shareReplay({ refCount: true }));
totalSumOfDriversItems$ = this.facade.numberOfDriversItems.pipe(map(calculateTotalSum), shareReplay({ refCount: true }));
numberOfWorkDaysItems$ = this.facade.numberOfWorkingDaysItems.pipe(shareReplay({ refCount: true }));
totalSumOfWorkDaysItems$ = this.facade.numberOfWorkingDaysItems.pipe(map(calculateTotalSum), shareReplay({ refCount: true }));
inspectionType$ = this.facade.driversInspectionInspectedItems.pipe(map(items => items.inspectionType?.code), shareReplay({ refCount: true }));
inspectionInspectedItems$ = this.facade.driversInspectionInspectedItems;
inspectionId$ = this.facade.driversInspectionId;
numberOfDriversItems$: Observable<NumberOfInspectedItemsDto[]> = this.facade.numberOfDriversItems.pipe(shareReplay({ refCount: true }));
totalSumOfDriversItems$: Observable<number> = this.facade.numberOfDriversItems.pipe(map(calculateTotalSum), shareReplay({ refCount: true }));
numberOfWorkDaysItems$: Observable<NumberOfInspectedItemsDto[]> = this.facade.numberOfWorkingDaysItems.pipe(shareReplay({ refCount: true }));
totalSumOfWorkDaysItems$: Observable<number> = this.facade.numberOfWorkingDaysItems.pipe(map(calculateTotalSum), shareReplay({ refCount: true }));
inspectionType$: Observable<string> = this.facade.driversInspectionInspectedItems.pipe(map(items => items.inspectionType?.code), shareReplay({ refCount: true }));
inspectionInspectedItems$: Observable<DriversInspectionInspectedItemsDto> = this.facade.driversInspectionInspectedItems;
inspectionId$: Observable<string> = this.facade.driversInspectionId.pipe(shareReplay({ refCount: true }));
readonly addItemPermission = DriversInspectionPermission.ADD_DRIVERS_NUMBER_OF_INSPECTED_ITEM;
readonly editInspectionPermission = DriversInspectionPermission.ENTER_INSPECTION_DATA;
readonly permissionType = PermissionDataObjectType.DRIVERS_INSPECTION;
ngOnInit(): void {
this.facade.getNumberOfInspectedItems();
}
openEditInspectionDataModal() {
this.inspectionInspectedItems$.pipe(take(1)).subscribe((inspectionData) => {
this.modal.openWithComponent(EditInspectionDataComponent, { inspectionData });
});
}
openAddInspectedItemsModal(item: InspectedItem) {
this.inspectionType$.pipe(take(1)).subscribe((inspectionType) => {
this.modal.openWithComponent(AddOrEditNumberOfInspectedItemsComponent, { item, inspectionType });
......
......@@ -8,6 +8,7 @@ import { NumberOfInspectedItemsTableComponent } from './containers/number-of-ins
import { AddFileComponent } from './containers/add-file/add-file.component';
import { AddOrEditNumberOfInspectedItemsComponent } from './containers/add-or-edit-number-of-inspected-items/add-or-edit-number-of-inspected-items.component';
import { NumberOfInspectedItemsDetailComponent } from './containers/number-of-inspected-items-detail/number-of-inspected-items-detail.component';
import { EditInspectionDataComponent } from './containers/edit-inspection-data/edit-inspection-data.component';
@NgModule({
declarations: [
......@@ -18,6 +19,7 @@ import { NumberOfInspectedItemsDetailComponent } from './containers/number-of-in
AddFileComponent,
AddOrEditNumberOfInspectedItemsComponent,
NumberOfInspectedItemsDetailComponent,
EditInspectionDataComponent,
],
exports: [],
imports: [DriversInspectionsRoutingModule, DriversInspectionsSharedModule],
......
......@@ -1173,5 +1173,7 @@
"number_of_drivers": "Juhtide arv kontrollitud ettevõttes EN",
"number_of_vehicles": "Sõidukite arv kontrollitud ettevõttes EN",
"inspection_type": "Kontrolli tüüp EN",
"misdemeanor_ref_number": "Väärteomenetluse viitenumber EN"
"misdemeanor_ref_number": "Väärteomenetluse viitenumber EN",
"controlled_period_start": "Kontrollitud ajavahemiku algus EN",
"controlled_period_end": "Kontrollitud ajavahemiku lõpp EN"
}
\ No newline at end of file
......@@ -1173,5 +1173,7 @@
"number_of_drivers": "Juhtide arv kontrollitud ettevõttes",
"number_of_vehicles": "Sõidukite arv kontrollitud ettevõttes",
"inspection_type": "Kontrolli tüüp",
"misdemeanor_ref_number": "Väärteomenetluse viitenumber"
"misdemeanor_ref_number": "Väärteomenetluse viitenumber",
"controlled_period_start": "Kontrollitud ajavahemiku algus",
"controlled_period_end": "Kontrollitud ajavahemiku lõpp"
}
\ No newline at end of file
......@@ -1173,5 +1173,7 @@
"number_of_drivers": "Juhtide arv kontrollitud ettevõttes RU",
"number_of_vehicles": "Sõidukite arv kontrollitud ettevõttes RU",
"inspection_type": "Kontrolli tüüp RU",
"misdemeanor_ref_number": "Väärteomenetluse viitenumber RU"
"misdemeanor_ref_number": "Väärteomenetluse viitenumber RU",
"controlled_period_start": "Kontrollitud ajavahemiku algus RU",
"controlled_period_end": "Kontrollitud ajavahemiku lõpp RU"
}
\ No newline at end of file
......@@ -292,4 +292,5 @@ export enum DriversInspectionPermission {
ENTER_JUSTIFICATION = 'ENTER_JUSTIFICATION',
ADD_DRIVERS_VIOLATION_FILE = 'ADD_DRIVERS_VIOLATION_FILE',
DELETE_DRIVERS_VIOLATION_FILE = 'DELETE_DRIVERS_VIOLATION_FILE',
ENTER_INSPECTION_DATA = 'ENTER_INSPECTION_DATA'
}
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