-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathnote-dialog.component.ts
179 lines (157 loc) · 5.28 KB
/
note-dialog.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
import {Component, OnDestroy, TemplateRef, ViewChild} from "@angular/core";
import {
SbbDialog,
SbbDialogConfig,
SbbDialogPosition,
} from "@sbb-esta/angular/dialog";
import {Vec2D} from "../../../utils/vec2D";
import {UiInteractionService} from "../../../services/ui/ui.interaction.service";
import {GeneralViewFunctions} from "../../util/generalViewFunctions";
import {Subject} from "rxjs";
import {NoteFormComponentModel} from "./note-form/note-form.component";
import {takeUntil} from "rxjs/operators";
import {environment} from "../../../../environments/environment";
export enum NoteDialogType {
NOTE_DIALOG,
NOTE_FILTERABLE_LABELS_DIALOG,
}
export class NoteDialogParameter {
public type: NoteDialogType;
public position: Vec2D;
public offset: number;
public noteFormComponentModel: NoteFormComponentModel;
constructor(type: NoteDialogType, position: Vec2D) {
this.type = type;
this.position = position;
this.offset = 0;
}
setOffset(offset: number) {
this.offset = offset;
}
}
@Component({
selector: "sbb-note-dialog",
templateUrl: "./note-dialog.component.html",
styleUrls: ["./note-dialog.component.scss"],
})
export class NoteDialogComponent implements OnDestroy {
@ViewChild("noteEditorTabsViewTemplate", {static: true})
noteEditorTabsViewTemplate: TemplateRef<any>;
public data = null;
public noteId: number;
public noteTitle: string;
public noteText: string;
readonly disableBackend = environment.disableBackend;
private destroyed = new Subject<void>();
private deleteNoteCallback = null;
private saveNoteCallback = null;
private updateNoteCallback = null;
private dialogRef = null;
private dialogConfig = null;
private dialogPos = null;
private dialogMovementLastPosition: Vec2D = undefined;
constructor(
public dialog: SbbDialog,
private uiInteractionService: UiInteractionService,
) {
this.uiInteractionService.noteDialog
.pipe(takeUntil(this.destroyed))
.subscribe((parameter) => {
this.data = parameter;
this.noteText = this.data.noteText;
this.noteId = this.data.id;
this.noteTitle = this.data.noteTitle;
this.deleteNoteCallback = this.data.deleteNoteCallback;
this.saveNoteCallback = this.data.saveNoteCallback;
this.updateNoteCallback = this.data.updateNoteCallback;
this.openDialog(parameter);
});
}
static getDialogConfig(parameter: NoteDialogParameter): SbbDialogConfig {
const width = 630;
const height = 477;
const dialogConfig = new SbbDialogConfig();
const xPosition = parameter.position.getX();
const yPosition = parameter.position.getY();
const topLeft = GeneralViewFunctions.calcDialogTopLeftScreenCoordinate(
new Vec2D(xPosition, yPosition),
new Vec2D(width, height),
);
dialogConfig.position = {
top: topLeft.getY() + "px",
left: topLeft.getX() + "px",
};
dialogConfig.width = width + "px";
dialogConfig.minWidth = dialogConfig.width;
dialogConfig.maxWidth = dialogConfig.width;
dialogConfig.height = height + "px";
dialogConfig.minHeight = dialogConfig.height;
dialogConfig.maxHeight = dialogConfig.height;
dialogConfig.panelClass = "";
dialogConfig.id = "NoteEditorTabsViewId";
return dialogConfig;
}
ngOnDestroy() {
this.destroyed.next();
this.destroyed.complete();
}
openDialog(parameter: NoteDialogParameter) {
this.dialogConfig = NoteDialogComponent.getDialogConfig(parameter);
this.dialogRef = this.dialog.open(
this.noteEditorTabsViewTemplate,
this.dialogConfig,
);
this.dialogPos = {
bottom:
parseInt(this.dialogConfig.position.top, 10) +
parseInt(this.dialogConfig.height, 10),
left: parseInt(this.dialogConfig.position.left, 10),
right:
parseInt(this.dialogConfig.position.left, 10) +
parseInt(this.dialogConfig.width, 10),
top: parseInt(this.dialogConfig.position.top, 10),
};
}
onMouseUp(event: MouseEvent) {
this.dialogMovementLastPosition = undefined;
}
onMouseDown(event: MouseEvent) {
if (event.buttons === 1) {
const eventTarget = event.target as HTMLElement;
if (eventTarget.className === "sbb-tab-labels") {
this.dialogMovementLastPosition = new Vec2D(
event.screenX,
event.screenY,
);
}
}
}
onMouseMove(event: MouseEvent) {
if (event.buttons === 1) {
if (this.dialogMovementLastPosition !== undefined) {
const newLayer = new Vec2D(event.screenX, event.screenY);
const movement = Vec2D.sub(newLayer, this.dialogMovementLastPosition);
this.dialogMovementLastPosition = newLayer;
this.dialogPos.top += movement.getY();
this.dialogPos.bottom += movement.getY();
this.dialogPos.left += movement.getX();
this.dialogPos.right += movement.getX();
this.dialogRef.updatePosition(this.convertDialogPos(this.dialogPos));
event.preventDefault();
}
}
}
closeDialog() {
if (this.dialogRef !== null) {
this.dialogRef.close();
}
}
private convertDialogPos(dialogPos: SbbDialogPosition): SbbDialogPosition {
return {
bottom: dialogPos.bottom + "px",
left: dialogPos.left + "px",
right: dialogPos.right + "px",
top: dialogPos.top + "px",
};
}
}