Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/app/data-structures/business.data.structures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ export interface TrainrunSectionDto {
trainrunId: number; // reference to the trainrun (main object)
resourceId: number; // reference to the algined (resource - not yet implemented)

specificTrainrunSectionFrequencyId: number; // Default 0 - deprecate???
specificTrainrunSectionFrequencyId: number | null; // Default 0 - deprecate???
path: PathDto; // cached - precomputed path for rendering
warnings: WarningDto[]; // business logic failures - warnings storage
warnings: WarningDto[] | null; // business logic failures - warnings storage
}

/**
Expand Down Expand Up @@ -178,12 +178,12 @@ export interface NodeDto {
transitions: TransitionDto[]; // all tranisitons aligned to the node
connections: ConnectionDto[]; // all connections aligned to the node

resourceId: number; // reference to the algined (resource - not yet implemented)
resourceId: number | null; // reference to the algined (resource - not yet implemented)
perronkanten: number; // number of tracks where train can stop
connectionTime: number; // aka Umsteigezeit - time used to change train in minutes
trainrunCategoryHaltezeiten: TrainrunCategoryHaltezeit; // user can over-write the halte times
symmetryAxis: number; // deprecate ???
warnings: WarningDto[]; // business logic failures - warnings storage
symmetryAxis: number | null; // deprecate ???
warnings: WarningDto[] | null; // business logic failures - warnings storage

labelIds: number[]; // list of assigned filterable labels (identifiers: See Label, LabelDto.)
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/data-structures/technical.data.structures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ export interface TimeLockDto {
time: number; // minutes [0..60]
consecutiveTime: number; // automatically updated after any data changes in the application
lock: boolean; // used to stop the time propagation (forward/backward)
warning: WarningDto; // warning - if business logic detects an issue -> set human-readable warning
timeFormatter: TimeFormatter; // undefined or object - optional
warning: WarningDto | null; // warning - if business logic detects an issue -> set human-readable warning
timeFormatter: TimeFormatter | null; // undefined or object - optional
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/app/models/connection.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class Connection {
private port2Id: number;

private path: Vec2D[];
private warning: WarningDto = null;
private warning: WarningDto | null = null;

private isSelected = false;

Expand Down
8 changes: 4 additions & 4 deletions src/app/models/filterSettings.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ export class FilterSetting {
filterTrainrunName: true,
filterConnections: true,
filterShowNonStopTime: true,
filterTrainrunCategory: null,
filterTrainrunFrequency: null,
filterTrainrunTimeCategory: null,
filterDirection: null,
filterTrainrunCategory: [],
filterTrainrunFrequency: [],
filterTrainrunTimeCategory: [],
filterDirection: [],
filterAllEmptyNodes: false,
filterAllNonStopNodes: false,
filterNotes: false,
Expand Down
52 changes: 37 additions & 15 deletions src/app/models/node.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ export class Node {
private ports: Port[];
private transitions: Transition[];
private connections: Connection[];
private resourceId: number;
private resourceId: number | null;
private perronkanten: number;
private connectionTime: number;
private trainrunCategoryHaltezeiten: TrainrunCategoryHaltezeit;
private symmetryAxis: number;
private warnings: WarningDto[];
private symmetryAxis: number | null;
private warnings: WarningDto[] | null;
private isSelected: boolean;
private labelIds: number[];

Expand Down Expand Up @@ -215,7 +215,7 @@ export class Node {
return this.id;
}

getResourceId(): number {
getResourceId(): number | null {
return this.resourceId;
}

Expand Down Expand Up @@ -303,7 +303,11 @@ export class Node {
}

getPort(portId: number): Port {
return this.ports.find((p) => p.getId() === portId);
const port = this.ports.find((p) => p.getId() === portId);
if (port === undefined) {
throw new Error(`Port with id ${portId} not found on node ${this.id}`);
}
return port;
}

getNextFreePinPositionIndex(alignment: PortAlignment): number {
Expand Down Expand Up @@ -348,7 +352,7 @@ export class Node {
return undefined;
}

getTransition(trainrunSectionId: number): Transition {
getTransition(trainrunSectionId: number): Transition | undefined {
return this.getTransitions().find((trans: Transition) => {
const port = this.getPortOfTrainrunSection(trainrunSectionId);
if (port === undefined) {
Expand All @@ -358,7 +362,7 @@ export class Node {
});
}

getNextTrainrunSection(trainrunSection: TrainrunSection): TrainrunSection {
getNextTrainrunSection(trainrunSection: TrainrunSection): TrainrunSection | undefined {
let transition = this.getTransitions().find((trans: Transition) => {
const t = this.getPortOfTrainrunSection(trainrunSection.getId());
if (t === undefined) {
Expand All @@ -384,7 +388,7 @@ export class Node {
return undefined;
}

getPreviousTrainrunSection(trainrunSection: TrainrunSection): TrainrunSection {
getPreviousTrainrunSection(trainrunSection: TrainrunSection): TrainrunSection | undefined {
let transition = this.getTransitions().find((trans: Transition) => {
const t = this.getPortOfTrainrunSection(trainrunSection.getId());
if (t === undefined) {
Expand Down Expand Up @@ -423,7 +427,7 @@ export class Node {
);
}

getExtremityTrainrunSection(trainrunId: number, returnForwardStartNode = true): TrainrunSection {
getExtremityTrainrunSection(trainrunId: number, returnForwardStartNode = true): TrainrunSection | undefined {
const portsForTrainrun = this.ports.filter(
(port) => port.getTrainrunSection().getTrainrunId() === trainrunId,
);
Expand Down Expand Up @@ -524,11 +528,19 @@ export class Node {
}

getTransitionFromId(transitionId: number): Transition {
return this.transitions.find((t: Transition) => t.getId() === transitionId);
const trans = this.transitions.find((t: Transition) => t.getId() === transitionId);
if (trans === undefined) {
throw new Error(`Transition with id ${transitionId} not found on node ${this.id}`);
}
return trans;
}

getConnectionFromId(connectionId: number): Connection {
return this.connections.find((c: Connection) => c.getId() === connectionId);
const connection = this.connections.find((c: Connection) => c.getId() === connectionId);
if (connection === undefined) {
throw new Error(`Connection with id ${connectionId} not found on node ${this.id}`);
}
return connection;
}

getConnections(): Connection[] {
Expand All @@ -549,7 +561,11 @@ export class Node {
}

getPortOfTrainrunSection(trainrunSectionId: number): Port {
return this.ports.find((port) => port.getTrainrunSectionId() === trainrunSectionId);
const port = this.ports.find((port) => port.getTrainrunSectionId() === trainrunSectionId);
if (port === undefined) {
throw new Error(`Port with trainrunSectionId ${trainrunSectionId} not found on node ${this.id}`);
}
return port;
}

addTransitionAndComputeRouting(
Expand Down Expand Up @@ -782,9 +798,15 @@ export class Node {
}

getTrainrunSection(trainrun: Trainrun): TrainrunSection {
return this.ports
.find((port) => port.getTrainrunSection().getTrainrunId() === trainrun.getId())
.getTrainrunSection();
const port = this.ports.find(
(port) => port.getTrainrunSection().getTrainrunId() === trainrun.getId(),
);
if (port === undefined) {
throw new Error(
`TrainrunSection for Trainrun with id ${trainrun.getId()} not found on node ${this.id}`,
);
}
return port.getTrainrunSection();
}

getPorts(): Port[] {
Expand Down
5 changes: 4 additions & 1 deletion src/app/models/port.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class Port {
private positionIndex: number;
private positionAlignment: number;

private trainrunSection: TrainrunSection = null;
private trainrunSection: TrainrunSection | null = null;

constructor(
{id, trainrunSectionId, positionIndex, positionAlignment}: PortDto = {
Expand Down Expand Up @@ -64,6 +64,9 @@ export class Port {
}

getTrainrunSection(): TrainrunSection {
if (this.trainrunSection === null) {
throw new Error(`Error while trying to access uninitialized TrainrunSection on Port with id ${this.id}`);
}
return this.trainrunSection;
}

Expand Down
56 changes: 28 additions & 28 deletions src/app/models/trainrunsection.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ export class TrainrunSection {

private trainrunId: number;
private resourceId: number;
private specificTrainrunSectionFrequencyId: number;
private specificTrainrunSectionFrequencyId: number | null;
private path: PathDto;
private pathVec2D: Vec2D[];
private warnings: WarningDto[];
private warnings: WarningDto[] | null;

private sourceNode: Node;
private targetNode: Node;
Expand Down Expand Up @@ -149,35 +149,35 @@ export class TrainrunSection {
return ++TrainrunSection.currentId;
}

private static getDisplayTextWidth(time: TimeLockDto): number {
private static getDisplayTextWidth(time: TimeLockDto): number | undefined {
if (!time.timeFormatter?.textWidth) {
return undefined;
}
return time.timeFormatter.textWidth;
}

private static getDisplayHtmlStyle(time: TimeLockDto): string {
private static getDisplayHtmlStyle(time: TimeLockDto): string | undefined {
if (!time.timeFormatter?.htmlStyle) {
return undefined;
}
return time.timeFormatter.htmlStyle;
}

private static getDisplayColorRef(time: TimeLockDto): ColorRefType {
private static getDisplayColorRef(time: TimeLockDto): ColorRefType | undefined {
if (!time.timeFormatter?.colorRef) {
return undefined;
}
return time.timeFormatter.colorRef;
}

private static formatDisplayText(time: TimeLockDto, offset: number): string {
private static formatDisplayText(time: TimeLockDto, offset: number): string | undefined {
if (!time?.timeFormatter?.stylePattern) {
return undefined;
}

const consecutiveTimeDate = new Date(null);
const consecutiveTimeDate = new Date(0);
consecutiveTimeDate.setSeconds((time.consecutiveTime + offset) * 60);
const timeDate = new Date(null);
const timeDate = new Date(0);
timeDate.setSeconds(((time.time + offset + 24 * 60) % 60) * 60);

const patterns = {
Expand Down Expand Up @@ -301,83 +301,83 @@ export class TrainrunSection {
return this.targetArrival.time;
}

getTravelTimeFormattedDisplayText(offset = 0): string {
getTravelTimeFormattedDisplayText(offset = 0): string | undefined {
return TrainrunSection.formatDisplayText(this.travelTime, offset);
}

getSourceDepartureFormattedDisplayText(offset = 0): string {
getSourceDepartureFormattedDisplayText(offset = 0): string | undefined {
return TrainrunSection.formatDisplayText(this.sourceDeparture, offset);
}

getSourceArrivalFormattedDisplayText(offset = 0): string {
getSourceArrivalFormattedDisplayText(offset = 0): string | undefined {
return TrainrunSection.formatDisplayText(this.sourceArrival, offset);
}

getTargetDepartureFormattedDisplayText(offset = 0): string {
getTargetDepartureFormattedDisplayText(offset = 0): string | undefined {
return TrainrunSection.formatDisplayText(this.targetDeparture, offset);
}

getTargetArrivalFormattedDisplayText(offset = 0): string {
getTargetArrivalFormattedDisplayText(offset = 0): string | undefined {
return TrainrunSection.formatDisplayText(this.targetArrival, offset);
}

getTravelTimeFormattedDisplayTextWidth(): number {
getTravelTimeFormattedDisplayTextWidth(): number | undefined {
return TrainrunSection.getDisplayTextWidth(this.travelTime);
}

getSourceDepartureFormattedDisplayTextWidth(): number {
getSourceDepartureFormattedDisplayTextWidth(): number | undefined {
return TrainrunSection.getDisplayTextWidth(this.sourceDeparture);
}

getSourceArrivalFormattedDisplayTextWidth(): number {
getSourceArrivalFormattedDisplayTextWidth(): number | undefined {
return TrainrunSection.getDisplayTextWidth(this.sourceArrival);
}

getTargetDepartureFormattedDisplayTextWidth(): number {
getTargetDepartureFormattedDisplayTextWidth(): number | undefined {
return TrainrunSection.getDisplayTextWidth(this.targetDeparture);
}

getTargetArrivalFormattedDisplayTextWidth(): number {
getTargetArrivalFormattedDisplayTextWidth(): number | undefined {
return TrainrunSection.getDisplayTextWidth(this.targetArrival);
}

getTravelTimeFormattedDisplayHtmlStyle(): string {
getTravelTimeFormattedDisplayHtmlStyle(): string | undefined {
return TrainrunSection.getDisplayHtmlStyle(this.travelTime);
}

getSourceDepartureFormattedDisplayHtmlStyle(): string {
getSourceDepartureFormattedDisplayHtmlStyle(): string | undefined {
return TrainrunSection.getDisplayHtmlStyle(this.sourceDeparture);
}

getSourceArrivalFormattedDisplayHtmlStyle(): string {
getSourceArrivalFormattedDisplayHtmlStyle(): string | undefined {
return TrainrunSection.getDisplayHtmlStyle(this.sourceArrival);
}

getTargetDepartureFormattedDisplayHtmlStyle(): string {
getTargetDepartureFormattedDisplayHtmlStyle(): string | undefined {
return TrainrunSection.getDisplayHtmlStyle(this.targetDeparture);
}

getTargetArrivalFormattedDisplayHtmlStyle(): string {
getTargetArrivalFormattedDisplayHtmlStyle(): string | undefined {
return TrainrunSection.getDisplayHtmlStyle(this.targetArrival);
}

getTravelTimeFormatterColorRef(): ColorRefType {
getTravelTimeFormatterColorRef(): ColorRefType | undefined {
return TrainrunSection.getDisplayColorRef(this.travelTime);
}

getSourceDepartureFormatterColorRef(): ColorRefType {
getSourceDepartureFormatterColorRef(): ColorRefType | undefined {
return TrainrunSection.getDisplayColorRef(this.sourceDeparture);
}

getSourceArrivalFormatterColorRef(): ColorRefType {
getSourceArrivalFormatterColorRef(): ColorRefType | undefined {
return TrainrunSection.getDisplayColorRef(this.sourceArrival);
}

getTargetDepartureFormatterColorRef(): ColorRefType {
getTargetDepartureFormatterColorRef(): ColorRefType | undefined {
return TrainrunSection.getDisplayColorRef(this.targetDeparture);
}

getTargetArrivalFormatterColorRef(): ColorRefType {
getTargetArrivalFormatterColorRef(): ColorRefType | undefined {
return TrainrunSection.getDisplayColorRef(this.targetArrival);
}

Expand Down
8 changes: 4 additions & 4 deletions src/app/services/ui/filter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -844,16 +844,16 @@ export class FilterService implements OnDestroy {

private initializeFilterSetting(filterSetting: FilterSetting) {
if (filterSetting !== undefined) {
if (filterSetting.filterTrainrunCategory === null) {
if (filterSetting.filterTrainrunCategory.length === 0) {
filterSetting.filterTrainrunCategory = this.dataService.getTrainrunCategories();
}
if (filterSetting.filterTrainrunFrequency === null) {
if (filterSetting.filterTrainrunFrequency.length === 0) {
filterSetting.filterTrainrunFrequency = this.dataService.getTrainrunFrequencies();
}
if (filterSetting.filterTrainrunTimeCategory === null) {
if (filterSetting.filterTrainrunTimeCategory.length === 0) {
filterSetting.filterTrainrunTimeCategory = this.dataService.getTrainrunTimeCategories();
}
if (filterSetting.filterDirection === null) {
if (filterSetting.filterDirection.length === 0) {
filterSetting.filterDirection = this.dataService.getDirections();
}
}
Expand Down
Loading
Loading