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

TEIS-2497 Number of inspected items model changes

parent a1e575df
......@@ -9,7 +9,7 @@
<tr *ngFor="let item of itemsData">
<td *ngFor="let field of tableFields">{{ item[field] === null ? '-' : item[field] }}</td>
<td class="table-actions fit-width">
<ng-container *permission="{ id: item.id, type: permissionType, permission: managePermission }">
<ng-container *ngIf="itemHasManagePermission(item)">
<teis-icon-button role="button" variant="no-style" icon="icon-edit" (click)="openEditInspectedItemsModal(item)"> </teis-icon-button>
<teis-icon-button role="button" variant="no-style" icon="icon-delete" (click)="delete(item)"></teis-icon-button>
</ng-container>
......
......@@ -16,24 +16,30 @@ import { calculateSums, numberOfInspectedItemsTableFields } from './utils';
export class NumberOfInspectedItemsTableComponent implements OnInit {
@Input() itemsData: NumberOfInspectedItemsDto[] = [];
@Input() inspectionType: DriversInspectionType;
constructor(private modal: ModalService, private facade: DriversInspectionsFacade) { }
readonly managePermission = GenericPermission.MANAGE;
readonly permissionType = PermissionDataObjectType.DRIVERS_NUMBER_OF_INSPECTED_ITEMS;
readonly tableFields = numberOfInspectedItemsTableFields(DriversInspectionType.GOODS); // TODO: remove hardcode when BE done;
tableFields: (keyof NumberOfInspectedItemsDto)[];
fieldSums: Partial<Record<keyof NumberOfInspectedItemsDto, number>> = {};
ngOnInit(): void {
this.tableFields = numberOfInspectedItemsTableFields(this.inspectionType);
if (this.itemsData.length > 1) {
this.fieldSums = calculateSums(this.itemsData, DriversInspectionType.GOODS); // TODO: remove hardcode when BE done;
this.fieldSums = calculateSums(this.itemsData, this.inspectionType);
}
}
openEditInspectedItemsModal(numberOfInspectedItems: NumberOfInspectedItemsDto) {
openEditInspectedItemsModal(numberOfInspectedItems: NumberOfInspectedItemsDto): void {
this.modal.openWithComponent(AddOrEditNumberOfInspectedItemsComponent, { numberOfInspectedItems });
}
delete(numberOfInspectedItems: NumberOfInspectedItemsDto) {
itemHasManagePermission(numberOfInspectedItems: NumberOfInspectedItemsDto): boolean {
return numberOfInspectedItems.permissions.some(permission => permission.dataObjectPermissions?.includes(this.managePermission));
}
delete(numberOfInspectedItems: NumberOfInspectedItemsDto): void {
const options: ConfirmationOptions = {
title: `number_of_inspected_items_delete_${numberOfInspectedItems.item}`,
question: `number_of_inspected_items_delete_confirmation_${numberOfInspectedItems.item}`,
......
......@@ -7,6 +7,7 @@
<p class="font-weight-bold">{{ 'inspected_drivers' | translate }}</p>
<teis-number-of-inspected-items-table
*ngIf="(numberOfDriversItems$ | async)?.length; else inspectedDriversNotFound"
[inspectionType]="inspectionType$ | async"
[itemsData]="numberOfDriversItems$ | async"
></teis-number-of-inspected-items-table>
<ng-template #inspectedDriversNotFound>
......@@ -24,6 +25,7 @@
<p class="font-weight-bold mt-4">{{ 'inspected_work_days' | translate }}</p>
<teis-number-of-inspected-items-table
*ngIf="(numberOfWorkDaysItems$ | async)?.length; else inspectedWorkDaysNotFound"
[inspectionType]="inspectionType$ | async"
[itemsData]="numberOfWorkDaysItems$ | async"
></teis-number-of-inspected-items-table>
<ng-template #inspectedWorkDaysNotFound>
......
......@@ -20,6 +20,7 @@ export class NumberOfInspectedItemsComponent implements OnInit {
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 }));
inspectionId$ = this.facade.driversInspectionId;
readonly addItemPermission = DriversInspectionPermission.ADD_DRIVERS_NUMBER_OF_INSPECTED_ITEM;
......
......@@ -20,6 +20,7 @@ import {
DriversViolationTypePublicDto,
DriversViolationPublicDto,
CreateOrEditNumberOfInspectedItemsDto,
DriversInspectionInspectedItemsDto,
} from '@teis/features/drivers-inspections/services/drivers-inspections.model';
import { BehaviorSubject, Observable, Subject } from 'rxjs';
import { distinctUntilChanged, map, take, takeUntil, tap } from 'rxjs/operators';
......@@ -89,6 +90,7 @@ export class DriversInspectionsFacade implements OnDestroy {
private openedViolation$ = new BehaviorSubject<string>(null);
private driversInspectionFiles$ = new BehaviorSubject<DriversInspectionFileDto[]>([]);
private numberOfInspectedItems$ = new BehaviorSubject<NumberOfInspectedItemsDto[]>([]);
private driversInspectionInspectedItems$ = new BehaviorSubject<DriversInspectionInspectedItemsDto>(null);
driversViolationsFilter = new FormControl(this.allDriversFilterOption);
private driversViolationsFilterValue$ = new BehaviorSubject<DriverDto>(null);
private driversViolationTypes$ = new BehaviorSubject<DriversViolationTypeDto[]>([]);
......@@ -148,6 +150,10 @@ export class DriversInspectionsFacade implements OnDestroy {
return this.numberOfInspectedItems$.asObservable().pipe(map((items: NumberOfInspectedItemsDto[]) => items.filter((item: NumberOfInspectedItemsDto) => item.item === InspectedItem.WORKINGDAYS)));
}
get driversInspectionInspectedItems(): Observable<DriversInspectionInspectedItemsDto> {
return this.driversInspectionInspectedItems$.asObservable();
}
getViolationDetailById(id: string): Observable<DriversViolationDto> {
return this.violationDetails$.asObservable().pipe(map((details: DriversViolationDto[]) => details.find((detail: DriversViolationDto) => detail.id === id)));
}
......@@ -350,11 +356,13 @@ export class DriversInspectionsFacade implements OnDestroy {
const { id } = this.driversInspection$.getValue();
this.handleLoading('numberOfInspectedItems', true);
this.driversInspectionOfficeApi.getNumberOfInspectedItems(id).subscribe(
(items) => {
this.numberOfInspectedItems$.next(items);
(items: DriversInspectionInspectedItemsDto) => {
this.driversInspectionInspectedItems$.next(items);
this.numberOfInspectedItems$.next(items.numberOfInspectedItems);
this.handleLoading('numberOfInspectedItems', false);
},
() => {
this.driversInspectionInspectedItems$.next(null);
this.numberOfInspectedItems$.next([]);
this.handleLoading('numberOfInspectedItems', false);
}
......@@ -453,6 +461,7 @@ export class DriversInspectionsFacade implements OnDestroy {
this.driversViolationsFilterValue$.next(null);
this.loading$.next(initialLoading);
this.driversInspectionFiles$.next([]);
this.driversInspectionInspectedItems$.next(null);
this.numberOfInspectedItems$.next([]);
this.driversViolationTypes$.next([]);
}
......
......@@ -7,6 +7,7 @@ import {
CreateOrEditDriversInfringmentDto,
NumberOfInspectedItemsDto,
CreateOrEditNumberOfInspectedItemsDto,
DriversInspectionInspectedItemsDto,
} from '@teis/features/drivers-inspections/services/drivers-inspections.model';
import { ApiOffice } from '@teis/services/api-office';
......@@ -47,7 +48,7 @@ export class DriversInspectionsOfficeApi extends ApiOffice {
}
getNumberOfInspectedItems(id: string) {
return this.http.get<NumberOfInspectedItemsDto[]>(`${this.url}/${id}/number-of-inspected-items`);
return this.http.get<DriversInspectionInspectedItemsDto>(`${this.url}/${id}/number-of-inspected-items`);
}
postNumberOfInspectedItems(id: string, body: CreateOrEditNumberOfInspectedItemsDto) {
......
......@@ -173,6 +173,22 @@ export interface DriversInspectionFileDto {
status: ClassifierItemLightDto;
uploadTime: string;
}
export interface DriversInspectionInspectedItemsDto {
controlledPeriodBeginning: string;
controlledPeriodEnd: string;
convictedPersonCode: string;
convictedPersonName: string;
id: string;
inspectionType: ClassifierItemLightDto;
misdemeanorRefNumber: string;
numberOfDrivers: number;
numberOfInspectedItems: NumberOfInspectedItemsDto[];
numberOfVehicles: number;
objectStatus: ObjectStatus;
permissions: PermissionDto[];
}
export interface NumberOfInspectedItemsDto {
createdAt: string;
driversInspectionFileId: string;
......
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