Commit 3167c05c authored by Madis Põld's avatar Madis Põld
Browse files

Merge branch 'feature/TEIS-2349' into 'develop'

TEIS-2349 Justification status change

Closes TEIS-2349

See merge request teis/public-web-client!733
parents 9185a707 b7b7700f
......@@ -1173,5 +1173,6 @@
"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",
"edit_infringement_status_error": "Kõvalekalde staatuse muutmine ebaõnnestus EN"
}
\ No newline at end of file
......@@ -1173,5 +1173,6 @@
"number_of_drivers": "Juhtide arv ettevõttes",
"number_of_vehicles": "Sõidukite arv ettevõttes",
"inspection_type": "Kontrolli tüüp",
"misdemeanor_ref_number": "Väärteomenetluse viitenumber"
"misdemeanor_ref_number": "Väärteomenetluse viitenumber",
"edit_infringement_status_error": "Kõrvalekalde staatuse muutmine ebaõnnestus"
}
\ No newline at end of file
......@@ -1173,5 +1173,6 @@
"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",
"edit_infringement_status_error": "Kõvalekalde staatuse muutmine ebaõnnestus RU"
}
\ No newline at end of file
<div *ngIf="hasChangePermission$ | async; else plainStatus" class="actions-container">
<button
class="infringement-status-action infringement-status-action--info"
[class.active]="infringement.status?.code === driversInfringementStatus.UNIMPORTANT"
[class.active]="currentStatus === driversInfringementStatus.UNIMPORTANT"
(click)="handleStatusChange(driversInfringementStatus.UNIMPORTANT)"
>
<i class="icon icon-minus" aria-hidden="true"></i>
</button>
<button
class="infringement-status-action infringement-status-action--success"
[class.active]="infringement.status?.code === driversInfringementStatus.ACCEPTED"
[class.active]="currentStatus === driversInfringementStatus.ACCEPTED"
(click)="handleStatusChange(driversInfringementStatus.ACCEPTED)"
>
<i class="icon icon-check" aria-hidden="true"></i>
</button>
<button
class="infringement-status-action infringement-status-action--danger"
[class.active]="infringement.status?.code === driversInfringementStatus.DECLINED"
[class.active]="currentStatus === driversInfringementStatus.DECLINED"
(click)="handleStatusChange(driversInfringementStatus.DECLINED)"
>
<i class="icon icon-cross" aria-hidden="true"></i>
......
import { Component, Input, OnInit } from '@angular/core';
import { MessageContext } from '@ska-angular/core';
import { GenericPermission, PermissionDataObjectType } from '@teis/services/permissions/permissions.model';
import { PermissionsService } from '@teis/services/permissions/permissions.service';
import { StatusColors } from '@teis/services/status-colors/status-colors';
import { Observable } from 'rxjs';
import { DriversInspectionsFacade } from '../../drivers-inspections-facade.service';
import { DriversInfringementDto, DriversInfringementStatus } from '../../services/drivers-inspections.model';
@Component({
......@@ -13,18 +15,25 @@ import { DriversInfringementDto, DriversInfringementStatus } from '../../service
export class InfringementStatusComponent implements OnInit {
@Input() infringement: DriversInfringementDto;
currentStatus: DriversInfringementStatus;
readonly statusColors = StatusColors.infringements;
readonly driversInfringementStatus = DriversInfringementStatus;
hasChangePermission$: Observable<Boolean>;
constructor(private permissions: PermissionsService) { }
constructor(private permissions: PermissionsService, private facade: DriversInspectionsFacade, private message: MessageContext) { }
ngOnInit(): void {
this.hasChangePermission$ = this.permissions.hasPermissionForObject(PermissionDataObjectType.DRIVERS_INFRINGEMENT, this.infringement.id, GenericPermission.CHANGE_STATUS);
this.currentStatus = this.infringement.status.code as DriversInfringementStatus;
}
handleStatusChange(status: DriversInfringementStatus) {
// To be implemented
const previousStatus = this.currentStatus;
this.currentStatus = status;
this.facade.updateDriversInfringementStatus(this.infringement.id, status).subscribe(() => {}, () => {
this.currentStatus = previousStatus;
this.message.addToastError('edit_infringement_status_error', 2000);
});
}
}
......@@ -19,8 +19,10 @@ import {
UpdateDriversInspectionStatusDto,
DriversViolationTypePublicDto,
DriversViolationPublicDto,
DriversInfringementStatus,
CreateOrEditNumberOfInspectedItemsDto,
DriversInspectionInspectedItemsDto,
DriversInfringementExtendedDto,
} from '@teis/features/drivers-inspections/services/drivers-inspections.model';
import { BehaviorSubject, Observable, Subject } from 'rxjs';
import { distinctUntilChanged, map, take, takeUntil, tap } from 'rxjs/operators';
......@@ -31,6 +33,7 @@ import { ConfirmationOptions } from '@teis/widgets/teis-modal/confirmation/confi
import { FileApi } from '@teis/services/file/file.api';
import { FileReferenceWithPermissionsDto } from '@teis/services/file/file.model';
import { FileService } from '@teis/services/file/file.service';
import { getUpdatedViolations } from './utils';
interface Loading {
driversInspection: boolean;
......@@ -431,6 +434,18 @@ export class DriversInspectionsFacade implements OnDestroy {
});
}
updateDriversInfringementStatus(id: string, status: DriversInfringementStatus) {
return this.driversInspectionOfficeApi.patchInfringementStatus(id, status).pipe(tap((infringement: DriversInfringementExtendedDto) => {
this.updateViolationsJustificationStatuses(infringement.category);
}));
}
private updateViolationsJustificationStatuses(updatedViolation: DriversInspectionViolationPublicDto): void {
const violations = this.driversInspectionViolations$.getValue();
const updatedViolations = getUpdatedViolations(violations, updatedViolation);
this.driversInspectionViolations$.next(updatedViolations);
}
setActiveTab(tab: DriversInspectionTab) {
this.currentTab$.next(tab);
}
......
......@@ -6,8 +6,10 @@ import {
DriversViolationTypeDto,
CreateOrEditDriversInfringmentDto,
NumberOfInspectedItemsDto,
DriversInfringementStatus,
CreateOrEditNumberOfInspectedItemsDto,
DriversInspectionInspectedItemsDto,
DriversInfringementExtendedDto,
} from '@teis/features/drivers-inspections/services/drivers-inspections.model';
import { ApiOffice } from '@teis/services/api-office';
......@@ -47,6 +49,10 @@ export class DriversInspectionsOfficeApi extends ApiOffice {
return this.http.delete(`${this.url}/drivers-infringements/${id}`);
}
patchInfringementStatus(id: string, status: DriversInfringementStatus) {
return this.http.patch<DriversInfringementExtendedDto>(`${this.url}/drivers-infringements/${id}/status`, { status: { code: status } });
}
getNumberOfInspectedItems(id: string) {
return this.http.get<DriversInspectionInspectedItemsDto>(`${this.url}/${id}/number-of-inspected-items`);
}
......
......@@ -113,6 +113,11 @@ export interface DriversInfringementDto {
status: ClassifierItemLightDto;
}
export interface DriversInfringementExtendedDto extends DriversInfringementDto {
category: DriversInspectionViolationPublicDto;
driversViolation: DriversViolationOfficeDto;
}
export interface DriversInfringementOfficeDto {
dateAndTimeFrom: string;
dateAndTimeUntil: string;
......
import { DriversInspectionViolationPublicDto, DriversViolationPublicDto, DriversViolationTypePublicDto } from './services/drivers-inspections.model';
export const getUpdatedViolations = (violations: DriversInspectionViolationPublicDto[], updatedViolation: DriversInspectionViolationPublicDto): DriversInspectionViolationPublicDto[] => {
const updatedDriversViolationType: DriversViolationTypePublicDto = updatedViolation.driversViolationTypes[0];
return violations.map((violation: DriversInspectionViolationPublicDto) => {
if (updatedViolation.id === violation.id) {
const updatedDriversViolationTypes = getUpdatedDriversViolationTypes(violation.driversViolationTypes, updatedDriversViolationType);
return { ...violation, justificationStatus: updatedViolation.justificationStatus, driversViolationTypes: updatedDriversViolationTypes };
}
return violation;
});
};
const getUpdatedDriversViolationTypes = (driversViolationTypes: DriversViolationTypePublicDto[], updatedDriversViolationType: DriversViolationTypePublicDto): DriversViolationTypePublicDto[] => {
const updatedDriversViolation: DriversViolationPublicDto = updatedDriversViolationType.driversViolations[0];
return driversViolationTypes.map((driversViolationType: DriversViolationTypePublicDto) => {
if (updatedDriversViolationType.id === driversViolationType.id) {
const updatedDriversViolations = getUpdatedDriversViolations(driversViolationType.driversViolations, updatedDriversViolation);
return { ...driversViolationType, justificationStatus: updatedDriversViolationType.justificationStatus, driversViolations: updatedDriversViolations };
}
return driversViolationType;
});
};
const getUpdatedDriversViolations = (driversViolations: DriversViolationPublicDto[], updatedDriversViolation: DriversViolationPublicDto): DriversViolationPublicDto[] => {
return driversViolations.map((driversViolation: DriversViolationPublicDto) => {
if (updatedDriversViolation.id === driversViolation.id) {
return { ...driversViolation, justificationStatus: updatedDriversViolation.justificationStatus };
}
return driversViolation;
});
};
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