Skip to content
Snippets Groups Projects
Commit 511b16df authored by rhenck's avatar rhenck
Browse files

Initialize undefined values with null

This makes checking the existence of properties for the property panel
possible, since it is possible to check for null but not for undefined.
parent 4c498653
No related branches found
No related tags found
No related merge requests found
...@@ -3,9 +3,9 @@ import { initSurfaceElement, initFontElement, UIElement } from './uIElement'; ...@@ -3,9 +3,9 @@ import { initSurfaceElement, initFontElement, UIElement } from './uIElement';
export class ButtonElement extends UIElement implements FontElement, SurfaceUIElement { export class ButtonElement extends UIElement implements FontElement, SurfaceUIElement {
label: string = 'Knopf'; label: string = 'Knopf';
imageSrc: string | undefined; imageSrc: string | null = null;
borderRadius: number = 0; borderRadius: number = 0;
action: undefined | 'previous' | 'next' | 'end'; action: null | 'previous' | 'next' | 'end' = null;
fontColor: string = 'black'; fontColor: string = 'black';
font: string = 'Roboto'; font: string = 'Roboto';
......
...@@ -3,9 +3,9 @@ import { FontElement, SurfaceUIElement } from '../interfaces/UIElementInterfaces ...@@ -3,9 +3,9 @@ import { FontElement, SurfaceUIElement } from '../interfaces/UIElementInterfaces
export class TextFieldElement extends InputElement implements FontElement, SurfaceUIElement { export class TextFieldElement extends InputElement implements FontElement, SurfaceUIElement {
appearance: 'standard' | 'legacy' | 'fill' | 'outline' = 'outline'; appearance: 'standard' | 'legacy' | 'fill' | 'outline' = 'outline';
minLength: number | undefined; minLength: number = 0;
minLengthWarnMessage: string = 'Eingabe zu kurz'; minLengthWarnMessage: string = 'Eingabe zu kurz';
maxLength: number | undefined; maxLength: number = 0;
maxLengthWarnMessage: string = 'Eingabe zu lang'; maxLengthWarnMessage: string = 'Eingabe zu lang';
pattern: string = ''; pattern: string = '';
patternWarnMessage: string = 'Eingabe entspricht nicht der Vorgabe'; patternWarnMessage: string = 'Eingabe entspricht nicht der Vorgabe';
......
...@@ -3,7 +3,7 @@ import { FontElement, SurfaceUIElement } from '../interfaces/UIElementInterfaces ...@@ -3,7 +3,7 @@ import { FontElement, SurfaceUIElement } from '../interfaces/UIElementInterfaces
import { IdService } from '../id.service'; import { IdService } from '../id.service';
export abstract class UIElement { export abstract class UIElement {
[index: string]: string | number | boolean | string[] | undefined | ((...args: any) => any); [index: string]: string | number | boolean | string[] | null | ((...args: any) => any);
type!: 'text' | 'button' | 'text-field' | 'text-area' | 'checkbox' type!: 'text' | 'button' | 'text-field' | 'text-area' | 'checkbox'
| 'dropdown' | 'radio' | 'image' | 'audio' | 'video'; | 'dropdown' | 'radio' | 'image' | 'audio' | 'video';
...@@ -42,14 +42,14 @@ export abstract class UIElement { ...@@ -42,14 +42,14 @@ export abstract class UIElement {
export abstract class InputElement extends UIElement { export abstract class InputElement extends UIElement {
label: string; label: string;
value: string | number | boolean | undefined; value: string | number | boolean | null;
required: boolean; required: boolean;
requiredWarnMessage: string; requiredWarnMessage: string;
protected constructor(serializedElement: UIElement, coordinates?: { x: number; y: number }) { protected constructor(serializedElement: UIElement, coordinates?: { x: number; y: number }) {
super(serializedElement, coordinates); super(serializedElement, coordinates);
this.label = serializedElement.label as string || 'Dummylabel'; this.label = serializedElement.label as string || 'Dummylabel';
this.value = serializedElement.value as string | number | boolean | undefined || undefined; this.value = serializedElement.value as string | number | boolean | null || null;
this.required = serializedElement.required as boolean || false; this.required = serializedElement.required as boolean || false;
this.requiredWarnMessage = serializedElement.requiredWarnMessage as string || 'Eingabe erforderlich'; this.requiredWarnMessage = serializedElement.requiredWarnMessage as string || 'Eingabe erforderlich';
} }
......
...@@ -65,7 +65,7 @@ export abstract class FormElementComponent extends ElementComponent implements O ...@@ -65,7 +65,7 @@ export abstract class FormElementComponent extends ElementComponent implements O
new FormControl({}); new FormControl({});
} }
updateFormValue(newValue: string | number | boolean | undefined): void { updateFormValue(newValue: string | number | boolean | null): void {
this.elementFormControl?.setValue(newValue, { emitEvent: false }); this.elementFormControl?.setValue(newValue, { emitEvent: false });
} }
......
...@@ -46,7 +46,7 @@ export abstract class CanvasElementOverlay implements OnInit, OnDestroy { ...@@ -46,7 +46,7 @@ export abstract class CanvasElementOverlay implements OnInit, OnDestroy {
.pipe(takeUntil(this.ngUnsubscribe)) .pipe(takeUntil(this.ngUnsubscribe))
.subscribe(() => { .subscribe(() => {
(this.childComponent.instance as FormElementComponent).updateFormValue( (this.childComponent.instance as FormElementComponent).updateFormValue(
(this.element as InputElement).value as string | number | boolean | undefined (this.element as InputElement).value as string | number | boolean | null
); );
}); });
} }
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
<input matInput type="text" disabled *ngIf="selectedElements.length > 1" [value]="'Muss eindeutig sein'"> <input matInput type="text" disabled *ngIf="selectedElements.length > 1" [value]="'Muss eindeutig sein'">
</mat-form-field> </mat-form-field>
<mat-form-field *ngIf="combinedProperties.label !== null" appearance="fill"> <mat-form-field *ngIf="combinedProperties.label !== undefined" appearance="fill">
<mat-label>Label</mat-label> <mat-label>Label</mat-label>
<input matInput type="text" [value]="combinedProperties.label" <input matInput type="text" [value]="combinedProperties.label"
(input)="updateModel('label', $any($event.target).value)"> (input)="updateModel('label', $any($event.target).value)">
...@@ -25,25 +25,25 @@ ...@@ -25,25 +25,25 @@
</div> </div>
</ng-container> </ng-container>
<mat-form-field *ngIf="combinedProperties.borderRadius != null" appearance="fill"> <mat-form-field *ngIf="combinedProperties.borderRadius !== undefined" appearance="fill">
<mat-label>Kantenradius</mat-label> <mat-label>Kantenradius</mat-label>
<input matInput type="number" [value]="combinedProperties.borderRadius" <input matInput type="number" [value]="combinedProperties.borderRadius"
(input)="updateModel('borderRadius', $any($event.target).value)"> (input)="updateModel('borderRadius', $any($event.target).value)">
</mat-form-field> </mat-form-field>
<mat-checkbox *ngIf="combinedProperties.highlightable != null" <mat-checkbox *ngIf="combinedProperties.highlightable !== undefined"
[checked]="$any(combinedProperties.highlightable)" [checked]="$any(combinedProperties.highlightable)"
(change)="updateModel('highlightable', $event.checked)"> (change)="updateModel('highlightable', $event.checked)">
Farbmarkierungen erlauben Farbmarkierungen erlauben
</mat-checkbox> </mat-checkbox>
<mat-checkbox *ngIf="combinedProperties.allowUnset != null" <mat-checkbox *ngIf="combinedProperties.allowUnset !== undefined"
[checked]="$any(combinedProperties.allowUnset)" [checked]="$any(combinedProperties.allowUnset)"
(change)="updateModel('allowUnset', $event.checked)"> (change)="updateModel('allowUnset', $event.checked)">
Deselektion erlauben Deselektion erlauben
</mat-checkbox> </mat-checkbox>
<mat-checkbox *ngIf="combinedProperties.required != null" <mat-checkbox *ngIf="combinedProperties.required !== undefined"
[checked]="$any(combinedProperties.required)" [checked]="$any(combinedProperties.required)"
(change)="updateModel('required', $event.checked)"> (change)="updateModel('required', $event.checked)">
Pflichtfeld Pflichtfeld
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
(input)="updateModel('requiredWarnMessage', $any($event.target).value)"> (input)="updateModel('requiredWarnMessage', $any($event.target).value)">
</mat-form-field> </mat-form-field>
<mat-form-field disabled="true" *ngIf="combinedProperties.options != null"> <mat-form-field disabled="true" *ngIf="combinedProperties.options !== undefined">
<ng-container> <ng-container>
<mat-label>Optionen</mat-label> <mat-label>Optionen</mat-label>
<div class="drop-list" cdkDropList [cdkDropListData]="combinedProperties.options" <div class="drop-list" cdkDropList [cdkDropListData]="combinedProperties.options"
...@@ -92,29 +92,28 @@ ...@@ -92,29 +92,28 @@
</mat-select> </mat-select>
</mat-form-field> </mat-form-field>
<mat-checkbox *ngIf="combinedProperties.resizeEnabled != null" <mat-checkbox *ngIf="combinedProperties.resizeEnabled !== undefined"
[checked]="$any(combinedProperties.resizeEnabled)" [checked]="$any(combinedProperties.resizeEnabled)"
(change)="updateModel('resizeEnabled', $event.checked)"> (change)="updateModel('resizeEnabled', $event.checked)">
größenverstellbar größenverstellbar
</mat-checkbox> </mat-checkbox>
</div> </div>
<!-- Some type specific fields which may be undefined but need to show up regardless --> <mat-form-field *ngIf="combinedProperties.action !== undefined" appearance="fill">
<ng-container *ngIf="combinedProperties.type == 'button'"> <mat-label>Aktion</mat-label>
<mat-form-field appearance="fill"> <mat-select [value]="combinedProperties.action"
<mat-label>Aktion</mat-label> (selectionChange)="updateModel('action', $event.value)">
<mat-select [value]="combinedProperties.action" <mat-option *ngFor="let option of [{displayValue: 'keine', value: undefined},
(selectionChange)="updateModel('action', $event.value)"> {displayValue: 'Vorherige Seite', value: 'previous'},
<mat-option *ngFor="let option of [{displayValue: 'keine', value: undefined}, {displayValue: 'Nächste Seite', value: 'next'},
{displayValue: 'Vorherige Seite', value: 'previous'}, {displayValue: 'Letzte Seite', value: 'end'}]"
{displayValue: 'Nächste Seite', value: 'next'}, [value]="option.value">
{displayValue: 'Letzte Seite', value: 'end'}]" {{option.displayValue}}
[value]="option.value"> </mat-option>
{{option.displayValue}} </mat-select>
</mat-option> </mat-form-field>
</mat-select>
</mat-form-field>
<ng-container *ngIf="combinedProperties.imageSrc !== undefined">
<input #imageUpload type="file" hidden (click)="loadImage()"> <input #imageUpload type="file" hidden (click)="loadImage()">
<button mat-raised-button (click)="imageUpload.click()">Bild laden</button> <button mat-raised-button (click)="imageUpload.click()">Bild laden</button>
<button mat-raised-button (click)="removeImage()">Bild entfernen</button> <button mat-raised-button (click)="removeImage()">Bild entfernen</button>
...@@ -123,7 +122,19 @@ ...@@ -123,7 +122,19 @@
[width]="200"> [width]="200">
</ng-container> </ng-container>
<ng-container *ngIf="combinedProperties.type === 'checkbox'"> <mat-form-field *ngIf="combinedProperties.options !== undefined"
appearance="fill">
<mat-label>Vorbelegung</mat-label>
<mat-select [value]="combinedProperties.value"
(selectionChange)="updateModel('value', $event.value)">
<mat-option>undefiniert</mat-option>
<mat-option *ngFor="let option of $any(combinedProperties).options" [value]="option">
{{option}}
</mat-option>
</mat-select>
</mat-form-field>
<ng-container *ngIf="combinedProperties.value === true || combinedProperties.value === false">
Vorbelegung Vorbelegung
<mat-button-toggle-group [value]="combinedProperties.value" <mat-button-toggle-group [value]="combinedProperties.value"
(change)="updateModel('value', $event.value)"> (change)="updateModel('value', $event.value)">
...@@ -132,79 +143,72 @@ ...@@ -132,79 +143,72 @@
</mat-button-toggle-group> </mat-button-toggle-group>
</ng-container> </ng-container>
<mat-form-field *ngIf="combinedProperties.type === 'dropdown' || combinedProperties.type === 'radio'" <!-- <ng-container *ngIf="combinedProperties.type === 'text-field' || combinedProperties.type === 'text-area'">-->
<!-- <ng-container *ngIf="combinedProperties.value !== undefined &&-->
<!--combinedProperties.value !== true || combinedProperties.value !== false">-->
<mat-form-field *ngIf="combinedProperties.value !== undefined &&
combinedProperties.value !== true && combinedProperties.value !== false"
appearance="fill"> appearance="fill">
<mat-label>Vorbelegung</mat-label> <mat-label>Vorbelegung</mat-label>
<mat-select [value]="combinedProperties.value" <input matInput type="text"
(selectionChange)="updateModel('value', $event.value)"> [value]="combinedProperties.value"
<mat-option>undefiniert</mat-option> (input)="updateModel('value', $any($event.target).value)">
<mat-option *ngFor="let option of $any(combinedProperties).options" [value]="option"> </mat-form-field>
{{option}}
<mat-form-field *ngIf="combinedProperties.appearance !== undefined" appearance="fill">
<mat-label>Aussehen</mat-label>
<mat-select [value]="combinedProperties.appearance"
(selectionChange)="updateModel('appearance', $event.value)">
<mat-option *ngFor="let option of [{displayValue: 'standard', value: 'standard'},
{displayValue: 'legacy', value: 'legacy'},
{displayValue: 'fill', value: 'fill'},
{displayValue: 'outline', value: 'outline'}]"
[value]="option.value">
{{option.displayValue}}
</mat-option> </mat-option>
</mat-select> </mat-select>
</mat-form-field> </mat-form-field>
<ng-container *ngIf="combinedProperties.type === 'text-field' || combinedProperties.type === 'text-area'"> <mat-form-field *ngIf="combinedProperties.minLength !== undefined" appearance="fill">
<mat-form-field appearance="fill"> <mat-label>Minimallänge</mat-label>
<mat-label>Vorbelegung</mat-label> <input matInput type="number" #minLength="ngModel" min="0"
<input matInput type="text" [ngModel]="combinedProperties.minLength"
[value]="combinedProperties.value" (ngModelChange)="updateModel('minLength', $event, minLength.valid)">
(input)="updateModel('value', $any($event.target).value)"> </mat-form-field>
</mat-form-field> <mat-form-field *ngIf="combinedProperties.minLength &&
<mat-form-field appearance="fill"> $any(combinedProperties.minLength) > 0"
<mat-label>Aussehen</mat-label> appearance="fill">
<mat-select [value]="combinedProperties.appearance" <mat-label>Minimalwert Warnmeldung</mat-label>
(selectionChange)="updateModel('appearance', $event.value)"> <input matInput type="text" [value]="combinedProperties.minLengthWarnMessage"
<mat-option *ngFor="let option of [{displayValue: 'standard', value: 'standard'}, (input)="updateModel('minLengthWarnMessage', $any($event.target).value)">
{displayValue: 'legacy', value: 'legacy'}, </mat-form-field>
{displayValue: 'fill', value: 'fill'},
{displayValue: 'outline', value: 'outline'}]"
[value]="option.value">
{{option.displayValue}}
</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field appearance="fill">
<mat-label>Minimallänge</mat-label>
<input matInput type="number" #minLength="ngModel" min="0"
[ngModel]="combinedProperties.minLength"
(ngModelChange)="updateModel('minLength', $event, minLength.valid)">
</mat-form-field>
<mat-form-field *ngIf="combinedProperties.minLength &&
$any(combinedProperties.minLength) > 0"
appearance="fill">
<mat-label>Minimalwert Warnmeldung</mat-label>
<input matInput type="text" [value]="combinedProperties.minLengthWarnMessage"
(input)="updateModel('minLengthWarnMessage', $any($event.target).value)">
</mat-form-field>
<mat-form-field appearance="fill">
<mat-label>Maximalwert</mat-label>
<input matInput type="number" #maxLength="ngModel" min="0"
[ngModel]="combinedProperties.maxLength"
(ngModelChange)="updateModel('maxLength', $event, maxLength.valid)">
</mat-form-field>
<mat-form-field *ngIf="combinedProperties.maxLength &&
$any(combinedProperties.maxLength) > 0"
appearance="fill">
<mat-label>Maximalwert Warnmeldung</mat-label>
<input matInput type="text" [value]="combinedProperties.maxLengthWarnMessage"
(input)="updateModel('maxLengthWarnMessage', $any($event.target).value)">
</mat-form-field>
<mat-form-field appearance="fill"> <mat-form-field *ngIf="combinedProperties.maxLength !== undefined" appearance="fill">
<mat-label>Muster</mat-label> <mat-label>Maximalwert</mat-label>
<input matInput [value]="combinedProperties.pattern" <input matInput type="number" #maxLength="ngModel" min="0"
(input)="updateModel('pattern', $any($event.target).value)"> [ngModel]="combinedProperties.maxLength"
</mat-form-field> (ngModelChange)="updateModel('maxLength', $event, maxLength.valid)">
<mat-form-field *ngIf="combinedProperties.pattern && </mat-form-field>
$any(combinedProperties.pattern) != ''" <mat-form-field *ngIf="combinedProperties.maxLength &&
appearance="fill" $any(combinedProperties.maxLength) > 0"
matTooltip="Angabe als regulärer Ausdruck."> appearance="fill">
<mat-label>Muster Warnmeldung</mat-label> <mat-label>Maximalwert Warnmeldung</mat-label>
<input matInput type="text" [value]="combinedProperties.patternWarnMessage" <input matInput type="text" [value]="combinedProperties.maxLengthWarnMessage"
(input)="updateModel('patternWarnMessage', $any($event.target).value)"> (input)="updateModel('maxLengthWarnMessage', $any($event.target).value)">
</mat-form-field> </mat-form-field>
</ng-container>
<mat-form-field *ngIf="combinedProperties.pattern !== undefined" appearance="fill">
<mat-label>Muster</mat-label>
<input matInput [value]="combinedProperties.pattern"
(input)="updateModel('pattern', $any($event.target).value)">
</mat-form-field>
<mat-form-field *ngIf="combinedProperties.pattern && $any(combinedProperties.pattern) !== ''"
appearance="fill"
matTooltip="Angabe als regulärer Ausdruck.">
<mat-label>Muster Warnmeldung</mat-label>
<input matInput type="text" [value]="combinedProperties.patternWarnMessage"
(input)="updateModel('patternWarnMessage', $any($event.target).value)">
</mat-form-field>
<mat-divider></mat-divider> <mat-divider></mat-divider>
......
...@@ -61,7 +61,7 @@ export class ElementPropertiesComponent implements OnInit, OnDestroy { ...@@ -61,7 +61,7 @@ export class ElementPropertiesComponent implements OnInit, OnDestroy {
} }
} }
if (this.selectedElements[i][property] !== this.combinedProperties[property]) { if (this.selectedElements[i][property] !== this.combinedProperties[property]) {
this.combinedProperties[property] = undefined; this.combinedProperties[property] = null;
} }
} else { } else {
delete this.combinedProperties[property]; delete this.combinedProperties[property];
...@@ -73,7 +73,7 @@ export class ElementPropertiesComponent implements OnInit, OnDestroy { ...@@ -73,7 +73,7 @@ export class ElementPropertiesComponent implements OnInit, OnDestroy {
} }
updateModel(property: string, updateModel(property: string,
value: string | number | boolean | string[] | undefined, value: string | number | boolean | string[] | null,
isInputValid: boolean | null = true): void { isInputValid: boolean | null = true): void {
if (isInputValid && value !== null) { if (isInputValid && value !== null) {
this.unitService.updateElementProperty(this.selectedElements, property, value); this.unitService.updateElementProperty(this.selectedElements, property, value);
...@@ -124,6 +124,6 @@ export class ElementPropertiesComponent implements OnInit, OnDestroy { ...@@ -124,6 +124,6 @@ export class ElementPropertiesComponent implements OnInit, OnDestroy {
} }
removeImage(): void { removeImage(): void {
this.updateModel('imageSrc', undefined); this.updateModel('imageSrc', null);
} }
} }
...@@ -157,7 +157,7 @@ export class UnitService { ...@@ -157,7 +157,7 @@ export class UnitService {
} }
updateElementProperty(elements: UIElement[], property: string, updateElementProperty(elements: UIElement[], property: string,
value: string | number | boolean | string[] | undefined): void { value: string | number | boolean | string[] | null): void {
elements.forEach((element: UIElement) => { elements.forEach((element: UIElement) => {
if (property === 'id') { if (property === 'id') {
if (!IdService.getInstance().isIdAvailable((value as string))) { // prohibit existing IDs if (!IdService.getInstance().isIdAvailable((value as string))) { // prohibit existing IDs
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment