Skip to content

Commit

Permalink
fix(CB2-15894): initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tomcrawleyy committed Jan 14, 2025
1 parent 99df9fa commit 22399c1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="section-wrapper" [formGroup]="form" *ngIf="techRecord() as tr">

<ng-container *ngIf="tr.techRecord_vehicleType === VehicleTypes.PSV">
<govuk-form-group-input
<govuk-form-group-input
class="govuk-!-margin-bottom-7"
type="number"
label="Speed Restriction"
Expand Down Expand Up @@ -47,9 +47,9 @@
<ng-container *ngFor="let axle of techRecordAxles.controls; let i = index">
<tr class="govuk-table__row" formGroupName="{{ i }}">
<th class="govuk-table__header" scope="row">T{{ axle.value.axleNumber }}</th>

<!-- Tyre Code -->
<td class="govuk-table__cell">
<td class="govuk-table__cell">
<govuk-form-group-input
id="tyres_tyreCode-{{ i + 1 }}"
type="number"
Expand All @@ -58,7 +58,7 @@
(blur)="getTyresRefData(i + 1)"
></govuk-form-group-input>
</td>

<!-- Tyre Size -->
<td class="govuk-table__cell">
<govuk-form-group-input
Expand All @@ -68,7 +68,7 @@
(blur)="getTyresRefData(i + 1)"
></govuk-form-group-input>
</td>

<!-- Ply Rating -->
<td class="govuk-table__cell">
<govuk-form-group-input
Expand All @@ -78,7 +78,7 @@
(blur)="getTyresRefData(i + 1)"
></govuk-form-group-input>
</td>

<!-- Data Tr Axles -->
<td class="govuk-table__cell">
<govuk-form-group-input
Expand All @@ -89,7 +89,7 @@
(blur)="getTyresRefData(i + 1)"
></govuk-form-group-input>
</td>

<!-- Speed Category Symbol (PSV Only)-->
<td class="govuk-table__cell" *ngIf="tr.techRecord_vehicleType === VehicleTypes.PSV">
<govuk-form-group-select
Expand All @@ -100,7 +100,7 @@
(blur)="getTyresRefData(i + 1)"
></govuk-form-group-select>
</td>

<!-- Fitment Code -->
<td class="govuk-table__cell">
<govuk-form-group-select
Expand All @@ -111,13 +111,13 @@
(blur)="getTyresRefData(i + 1)"
></govuk-form-group-select>
</td>

<td class="govuk-table__cell">
<a class="axleButton" id="tyres_search-{{ i + 1 }}" href="javascript:void(0)" (click)="getTyreSearchPage(axle.value.axleNumber)">
Search
</a>
</td>

<td class="govuk-table__cell">
<a class="axleButton" id="tyres_remove-{{ i + 1 }}" href="javascript:void(0)" (click)="removeAxle(i)">Remove</a>
</td>
Expand All @@ -141,7 +141,7 @@
</tr>
</tfoot>
</table>


<!-- Tyre Use Code (HGV) -->
<govuk-form-group-select
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { ViewportScroller } from '@angular/common';
import { Component, OnChanges, OnDestroy, OnInit, SimpleChanges, inject, input } from '@angular/core';
import { ControlContainer, FormArray, FormBuilder, FormGroup } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
import { PSVAxles } from '@dvsa/cvs-type-definitions/types/v3/tech-record/get/psv/skeleton';
import { TechRecordType } from '@dvsa/cvs-type-definitions/types/v3/tech-record/tech-record-vehicle-type';
import { CommonValidatorsService } from '@forms/validators/common-validators.service';
import { Axle, FitmentCode, ReasonForEditing, Tyre, VehicleTypes } from '@models/vehicle-tech-record.model';
Expand Down Expand Up @@ -245,14 +246,17 @@ export class TyresSectionEditComponent implements OnInit, OnDestroy, OnChanges {

getTyresRefData(axleNumber: number) {
const axles = this.techRecordAxles.value;
console.log(axles);

// Don't search if the axle is unfocused by removing the axle
if (axles === null || axles === undefined) return;

// Get the last added axle, as this is the one that needs autopopulating
const lastAxle = axles[axleNumber - 1];
console.log(lastAxle);

if (lastAxle?.tyres_tyreCode) {
console.log('test 2');
const refData = this.tyresReferenceData.find((tyre) => tyre.code === String(lastAxle.tyres_tyreCode));

if (!refData) {
Expand All @@ -264,14 +268,26 @@ export class TyresSectionEditComponent implements OnInit, OnDestroy, OnChanges {
lastAxle.tyres_fitmentCode === FitmentCode.SINGLE
? Number.parseInt(String(refData.loadIndexSingleLoad), 10)
: Number.parseInt(String(refData.loadIndexTwinLoad), 10);

const tyre = new Tyre({
tyreCode: lastAxle.tyres_tyreCode,
tyreSize: refData.tyreSize,
plyRating: refData.plyRating,
dataTrAxles: indexLoad,
fitmentCode: lastAxle.tyres_fitmentCode,
});
let tyre;
if (this.techRecord().techRecord_vehicleType !== VehicleTypes.PSV) {
tyre = new Tyre({
tyreCode: lastAxle.tyres_tyreCode,
tyreSize: refData.tyreSize,
plyRating: refData.plyRating,
dataTrAxles: indexLoad,
fitmentCode: lastAxle.tyres_fitmentCode,
});
} else {
console.log('test 3');
tyre = new Tyre({
tyreCode: lastAxle.tyres_tyreCode,
tyreSize: refData.tyreSize,
plyRating: refData.plyRating,
dataTrAxles: indexLoad,
fitmentCode: lastAxle.tyres_fitmentCode,
speedCategorySymbol: lastAxle.speedCategorySymbol,
});
}

this.addTyre(tyre, axleNumber);
}
Expand Down Expand Up @@ -309,6 +325,7 @@ export class TyresSectionEditComponent implements OnInit, OnDestroy, OnChanges {
}

addTyre(tyre: Tyre, axleNumber: number) {
console.log(tyre);
const techRecord = this.techRecord();

// Only add tyres if we can push to the axles array
Expand All @@ -326,6 +343,9 @@ export class TyresSectionEditComponent implements OnInit, OnDestroy, OnChanges {
axle.tyres_plyRating = tyre.plyRating;
axle.tyres_dataTrAxles = tyre.dataTrAxles;
axle.tyres_fitmentCode = tyre.fitmentCode;
if (techRecord.techRecord_vehicleType === VehicleTypes.PSV) {
(axle as PSVAxles).tyres_speedCategorySymbol = tyre.speedCategorySymbol;
}

this.techRecordAxles.patchValue(axlesClone);
this.technicalRecordService.updateEditingTechRecord({ techRecord_axles: axlesClone } as any);
Expand Down

0 comments on commit 22399c1

Please sign in to comment.