Skip to content

Commit eaf4a43

Browse files
committed
fix: There is no business required to enter smaller values than 0.6s ~1s thus we enforce not having those values. The validator output warning should only become active when a 3rd party JSON gets imported
1 parent 998dd73 commit eaf4a43

File tree

5 files changed

+15
-12
lines changed

5 files changed

+15
-12
lines changed

src/app/models/trainrunsection.model.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import {TrainrunSectionValidator} from "../services/util/trainrunsection.validat
1414
import {formatDate} from "@angular/common";
1515

1616
export class TrainrunSection {
17+
static MIN_TRAVEL_TIME = 0.01; // 1 / 100 minute = 0.6 second - defined min. travel time
18+
1719
private static currentId = 0;
1820

1921
private id: number;
@@ -386,8 +388,8 @@ export class TrainrunSection {
386388
}
387389

388390
setTravelTime(time: number) {
389-
this.travelTime.time = time;
390-
TrainrunSectionValidator.validateTravelTime(this, 1); // TODO: I don't think this should be done here
391+
this.travelTime.time = Math.max(time, TrainrunSection.MIN_TRAVEL_TIME);
392+
TrainrunSectionValidator.validateTravelTime(this);
391393
}
392394

393395
setSourceDeparture(time: number) {

src/app/services/data/trainrun-section-times.service.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,11 @@ export class TrainrunSectionTimesService {
321321
this.roundAllTimes();
322322
this.removeOffsetAndBackTransformTimeStructure();
323323

324+
this.timeStructure.travelTime = Math.max(
325+
this.timeStructure.travelTime,
326+
TrainrunSection.MIN_TRAVEL_TIME,
327+
);
328+
324329
if (!this.lockStructure.rightLock) {
325330
this.timeStructure.rightArrivalTime = MathUtils.mod60(
326331
this.timeStructure.leftDepartureTime + this.timeStructure.travelTime,

src/app/services/data/trainrunsection.service.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,7 @@ export class TrainrunSectionService implements OnDestroy {
231231

232232
this.trainrunSectionsStore.trainrunSections.forEach((trainrunSection) => {
233233
TrainrunSectionValidator.validateOneSection(trainrunSection);
234-
TrainrunSectionValidator.validateTravelTime(
235-
trainrunSection,
236-
this.filterService.getTimeDisplayPrecision(),
237-
);
234+
TrainrunSectionValidator.validateTravelTime(trainrunSection);
238235
});
239236
}
240237

src/app/services/util/trainrunsection.validator.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,11 @@ export class TrainrunSectionValidator {
8282
}
8383
}
8484

85-
static validateTravelTime(trainrunSection: TrainrunSection, timeDisplayPrecision: number = 1) {
86-
const minimumTravelTime = 1 / Math.pow(10, timeDisplayPrecision);
87-
if (trainrunSection.getTravelTime() < minimumTravelTime) {
85+
static validateTravelTime(trainrunSection: TrainrunSection) {
86+
if (trainrunSection.getTravelTime() < TrainrunSection.MIN_TRAVEL_TIME) {
8887
trainrunSection.setTravelTimeWarning(
89-
$localize`:@@app.services.util.trainrunsection-validator.travel-time-less-than-1.title:Travel Time less than ${minimumTravelTime}:minimumTravelTime:`,
90-
$localize`:@@app.services.util.trainrunsection-validator.travel-time-less-than-1.description:Travel time must be greater than or equal to ${minimumTravelTime}:minimumTravelTime:`,
88+
$localize`:@@app.services.util.trainrunsection-validator.travel-time-less-than-1.title:Travel Time less than ${TrainrunSection.MIN_TRAVEL_TIME}:minimumTravelTime:`,
89+
$localize`:@@app.services.util.trainrunsection-validator.travel-time-less-than-1.description:Travel time must be greater than or equal to ${TrainrunSection.MIN_TRAVEL_TIME}:minimumTravelTime:`,
9190
);
9291
} else {
9392
trainrunSection.resetTravelTimeWarning();

src/app/view/editor-tools-view-component/editor-tools-view.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ export class EditorToolsViewComponent {
787787
// step(6) Validate all trainrun sections
788788
this.trainrunSectionService.getTrainrunSections().forEach((ts) => {
789789
TrainrunSectionValidator.validateOneSection(ts);
790-
TrainrunSectionValidator.validateTravelTime(ts, this.filterService.getTimeDisplayPrecision());
790+
TrainrunSectionValidator.validateTravelTime(ts);
791791
});
792792
}
793793

0 commit comments

Comments
 (0)