Newer
Older
// eslint-disable-next-line max-classes-per-file
import { IdService } from '../id.service';
export abstract class UIElement {
[index: string]: string | number | boolean | string[] | null | ((...args: any) => any);
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
type!: 'text' | 'button' | 'text-field' | 'text-area' | 'checkbox'
| 'dropdown' | 'radio' | 'image' | 'audio' | 'video';
id: string = 'id_placeholder';
zIndex: number = 0;
width: number = 180;
height: number = 60;
dynamicPositioning: boolean = false;
xPosition: number = 0;
yPosition: number = 0;
gridColumnStart: number = 1;
gridColumnEnd: number = 2;
gridRowStart: number = 1;
gridRowEnd: number = 2;
marginLeft: number = 0;
marginRight: number = 0;
marginTop: number = 0;
marginBottom: number = 0;
protected constructor(serializedElement: UIElement, coordinates?: { x: number; y: number }) {
Object.assign(this, serializedElement);
if (!serializedElement.id) {
this.id = IdService.getInstance().getNewID(serializedElement.type);
}
if (coordinates && this.dynamicPositioning) {
this.gridColumnStart = coordinates.x;
this.gridColumnEnd = coordinates.x + 1;
this.gridRowStart = coordinates.y;
this.gridRowEnd = coordinates.y + 1;
} else if (coordinates && !this.dynamicPositioning) {
this.xPosition = coordinates.x;
this.yPosition = coordinates.y;
}
}
}
export abstract class InputElement extends UIElement {
label: string;
required: boolean;
requiredWarnMessage: string;
protected constructor(serializedElement: UIElement, coordinates?: { x: number; y: number }) {
super(serializedElement, coordinates);
this.label = serializedElement.label as string || 'Dummylabel';
this.value = serializedElement.value as string | number | boolean | null || null;