-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathtrainrun.model.ts
161 lines (133 loc) · 3.74 KB
/
trainrun.model.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import {
LinePatternRefs,
TrainrunCategory,
TrainrunDto,
TrainrunFrequency,
TrainrunTimeCategory,
} from "../data-structures/business.data.structures";
import {DataMigration} from "../utils/data-migration";
export class Trainrun {
public static DEFAULT_TRAINRUN_NAME = "X";
public static DEFAULT_TRAINRUN_CATEGORY = 1; // default is IC
public static DEFAULT_TRAINRUN_FREQUENCY = 3; // default is stuendlich
public static DEFAULT_TRAINRUN_TIME_CATEGORY = 0; // default is täglich, immer
private static currentId = 0;
private id: number;
private name: string;
private categoryId: number;
private frequencyId: number;
private trainrunTimeCategoryId: number;
private trainrunCategory: TrainrunCategory;
private trainrunFrequency: TrainrunFrequency;
private trainrunTimeCategory: TrainrunTimeCategory;
private isSelected: boolean;
private labelIds: number[];
constructor(
{
id,
name,
categoryId,
frequencyId,
trainrunTimeCategoryId,
labelIds,
}: TrainrunDto = {
id: Trainrun.incrementId(),
name: Trainrun.DEFAULT_TRAINRUN_NAME,
categoryId: Trainrun.DEFAULT_TRAINRUN_CATEGORY,
frequencyId: Trainrun.DEFAULT_TRAINRUN_FREQUENCY,
trainrunTimeCategoryId: Trainrun.DEFAULT_TRAINRUN_TIME_CATEGORY,
labelIds: [],
},
) {
this.id = id;
this.name = name;
this.categoryId = categoryId;
this.frequencyId = frequencyId;
this.isSelected = false;
this.trainrunTimeCategoryId = trainrunTimeCategoryId;
this.labelIds = labelIds;
if (Trainrun.currentId < this.id) {
Trainrun.currentId = this.id;
}
DataMigration.migrateTrainrunLabelIds(this);
}
private static incrementId(): number {
return ++Trainrun.currentId;
}
getTitle(): string {
return this.name;
}
setTitle(title: string) {
this.name = title;
}
getId(): number {
return this.id;
}
getFrequency(): number {
return this.trainrunFrequency.frequency;
}
getFrequencyOffset(): number {
return this.trainrunFrequency.offset;
}
getFrequencyLinePatternRef(): LinePatternRefs {
return this.trainrunFrequency.linePatternRef;
}
getCategoryShortName(): string {
return this.trainrunCategory.shortName.toUpperCase();
}
getCategoryColorRef(): string {
return this.trainrunCategory.colorRef;
}
getTimeCategoryLinePatternRef(): LinePatternRefs {
return this.trainrunTimeCategory.linePatternRef;
}
setTrainrunFrequency(trainrunFrequency: TrainrunFrequency) {
this.trainrunFrequency = trainrunFrequency;
}
getTrainrunFrequency(): TrainrunFrequency {
return this.trainrunFrequency;
}
setTrainrunCategory(trainrunCategory: TrainrunCategory) {
this.trainrunCategory = trainrunCategory;
}
getTrainrunCategory(): TrainrunCategory {
return this.trainrunCategory;
}
getTimeCategoryShortName(): string {
return this.trainrunTimeCategory.shortName;
}
setTrainrunTimeCategory(trainrunTimeCategory: TrainrunTimeCategory) {
this.trainrunTimeCategory = trainrunTimeCategory;
}
getTrainrunTimeCategory(): TrainrunTimeCategory {
return this.trainrunTimeCategory;
}
getCategoryOrder(): number {
return this.trainrunCategory.order;
}
select() {
this.isSelected = true;
}
unselect() {
this.isSelected = false;
}
selected(): boolean {
return this.isSelected;
}
getLabelIds(): number[] {
return this.labelIds;
}
setLabelIds(labelIds: number[]) {
this.labelIds = labelIds;
}
getDto(): TrainrunDto {
return {
id: this.id,
name: this.name,
categoryId: this.trainrunCategory.id,
frequencyId: this.trainrunFrequency.id,
trainrunTimeCategoryId: this.trainrunTimeCategory.id,
labelIds: this.labelIds,
};
}
}