-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy patheditor-edit-tools-view.component.ts
195 lines (177 loc) · 7.55 KB
/
editor-edit-tools-view.component.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import {Component, ElementRef, OnDestroy, ViewChild} from "@angular/core";
import {DataService} from "../../services/data/data.service";
import {UiInteractionService} from "../../services/ui/ui.interaction.service";
import {ConfirmationDialogParameter} from "../dialogs/confirmation-dialog/confirmation-dialog.component";
import {NodeService} from "../../services/data/node.service";
import {TrainrunSectionService} from "../../services/data/trainrunsection.service";
import {EditorMode} from "../editor-menu/editor-mode";
import {LogService} from "../../logger/log.service";
import {FilterService} from "../../services/ui/filter.service";
import {takeUntil} from "rxjs/operators";
import {Subject} from "rxjs";
import {TrainrunService} from "../../services/data/trainrun.service";
import {NoteService} from "../../services/data/note.service";
import {LabelRef} from "../../data-structures/business.data.structures";
import {LabelService} from "../../services/data/label.serivce";
import {LabelGroupService} from "../../services/data/labelgroup.service";
import {LabelGroup} from "../../models/labelGroup.model";
import {environment} from "../../../environments/environment";
@Component({
selector: "sbb-editor-edit-tools-view-component",
templateUrl: "./editor-edit-tools-view.component.html",
styleUrls: ["./editor-edit-tools-view.component.scss"],
})
export class EditorEditToolsViewComponent implements OnDestroy {
@ViewChild("netzgrafikMergeFileInput", {static: false})
netzgrafikMergeFileInput: ElementRef;
@ViewChild("netzgrafikMergeAsACopyFileInput", {static: false})
netzgrafikMergeAsACopyFileInput: ElementRef;
public editorMode: EditorMode = EditorMode.NetzgrafikEditing;
public nodeLabelGroups: LabelGroup[];
public trainrunLabelGroups: LabelGroup[];
private destroyed = new Subject<void>();
readonly disableBackend = environment.disableBackend;
constructor(
private dataService: DataService,
private nodeService: NodeService,
private trainrunService: TrainrunService,
private trainrunSectionService: TrainrunSectionService,
private noteService: NoteService,
public labelService: LabelService,
public labelGroupService: LabelGroupService,
private logger: LogService,
public filterService: FilterService,
private uiInteractionService: UiInteractionService,
) {
this.nodeLabelGroups = this.labelGroupService.getLabelGroupsFromLabelRef(
LabelRef.Node,
);
this.trainrunLabelGroups =
this.labelGroupService.getLabelGroupsFromLabelRef(LabelRef.Trainrun);
this.labelGroupService.labelGroups
.pipe(takeUntil(this.destroyed))
.subscribe(() => {
this.nodeLabelGroups =
this.labelGroupService.getLabelGroupsFromLabelRef(LabelRef.Node);
this.trainrunLabelGroups =
this.labelGroupService.getLabelGroupsFromLabelRef(LabelRef.Trainrun);
});
this.labelService.labels.pipe(takeUntil(this.destroyed)).subscribe(() => {
this.nodeLabelGroups = this.labelGroupService.getLabelGroupsFromLabelRef(
LabelRef.Node,
);
this.trainrunLabelGroups =
this.labelGroupService.getLabelGroupsFromLabelRef(LabelRef.Trainrun);
});
}
ngOnDestroy(): void {
this.destroyed.next();
this.destroyed.complete();
}
onClearAllFiltered() {
const confirmationDialogParamter = new ConfirmationDialogParameter(
$localize`:@@app.view.editor-edit-tools-view-component.delete:Delete`,
$localize`:@@app.view.editor-edit-tools-view-component.on-clear-delete-all-non-visible-elements:Should all non-visible elements be permanently deleted from the netzgrafik?`,
);
this.uiInteractionService
.showConfirmationDiagramDialog(confirmationDialogParamter)
.subscribe((confirmed: boolean) => {
if (confirmed) {
this.trainrunSectionService.deleteAllNonVisibleTrainrunSections();
this.nodeService.deleteAllNonVisibleNodes();
this.noteService.deleteAllNonVisibleNotes();
}
});
}
onClear() {
const confirmationDialogParamter = new ConfirmationDialogParameter(
$localize`:@@app.view.editor-edit-tools-view-component.delete:Delete`,
$localize`:@@app.view.editor-edit-tools-view-component.on-clear-delete-all-visible-elements:Should all visible elements be permanently deleted from the netzgrafik?`,
);
this.uiInteractionService
.showConfirmationDiagramDialog(confirmationDialogParamter)
.subscribe((confirmed: boolean) => {
if (confirmed) {
this.trainrunSectionService.deleteAllVisibleTrainrunSections();
this.nodeService.deleteAllVisibleNodes();
this.noteService.deleteAllVisibleNotes();
}
});
}
onClearAllTrainruns() {
const confirmationDialogParamter = new ConfirmationDialogParameter(
$localize`:@@app.view.editor-edit-tools-view-component.delete:Delete`,
$localize`:@@app.view.editor-edit-tools-view-component.on-clear-delete-all-visible-trainruns:Should all visible trainruns be permanently deleted from the netzgrafik?`,
);
this.uiInteractionService
.showConfirmationDiagramDialog(confirmationDialogParamter)
.subscribe((confirmed: boolean) => {
if (confirmed) {
this.trainrunSectionService.deleteAllVisibleTrainrunSections();
}
});
}
onClearAllNotes() {
const confirmationDialogParamter = new ConfirmationDialogParameter(
$localize`:@@app.view.editor-edit-tools-view-component.delete:Delete`,
$localize`:@@app.view.editor-edit-tools-view-component.on-clear-delete-all-visible-notes:Should all visible notes be permanently deleted from the netzgrafik?`,
);
this.uiInteractionService
.showConfirmationDiagramDialog(confirmationDialogParamter)
.subscribe((confirmed: boolean) => {
if (confirmed) {
this.noteService.deleteAllVisibleNotes();
}
});
}
onLoadNetzgrafikToInsertCopieButton() {
this.netzgrafikMergeAsACopyFileInput.nativeElement.click();
}
onLoadNetzgrafikToMergeButton() {
this.netzgrafikMergeFileInput.nativeElement.click();
}
onLoadNetzgrafikToMergeAsACopy(param) {
this.uiInteractionService.closeNodeStammdaten();
this.uiInteractionService.closePerlenkette();
this.loadNetzgrafik(param, (netzgrafikDto) =>
this.dataService.insertCopyNetzgrafikDto(netzgrafikDto),
);
}
onLoadNetzgrafikToMerge(param) {
this.uiInteractionService.closeNodeStammdaten();
this.uiInteractionService.closePerlenkette();
this.loadNetzgrafik(param, (netzgrafikDto) =>
this.dataService.mergeNetzgrafikDto(netzgrafikDto),
);
}
private loadNetzgrafik(param, callback) {
const file = param.target.files[0];
const reader = new FileReader();
reader.onload = () => {
const netzgrafikDto = JSON.parse(reader.result.toString());
if (
"nodes" in netzgrafikDto &&
"trainrunSections" in netzgrafikDto &&
"trainruns" in netzgrafikDto &&
"resources" in netzgrafikDto &&
"metadata" in netzgrafikDto
) {
this.logger.log(
"onLoadNetzgrafikToMerge; load netzgrafik: ",
netzgrafikDto,
);
this.setEditModeToNetzgrafikEditing();
callback(netzgrafikDto);
}
};
reader.readAsText(file);
// set the event target value to null in order to be able to load the same file multiple times after one another
param.target.value = null;
}
private setEditModeToNetzgrafikEditing() {
if (this.editorMode !== EditorMode.NetzgrafikEditing) {
this.editorMode = EditorMode.NetzgrafikEditing;
this.uiInteractionService.showNetzgrafik();
}
}
}