Skip to content
Snippets Groups Projects
Commit 9880a4cc authored by jojohoch's avatar jojohoch
Browse files

Convert VisibilityRule to interface

parent 0e8b4c77
No related branches found
No related tags found
No related merge requests found
......@@ -39,10 +39,7 @@ export class Section {
if (sanitizedBlueprint.visibilityDelay) this.visibilityDelay = sanitizedBlueprint.visibilityDelay;
if (sanitizedBlueprint.animatedVisibility) this.animatedVisibility = sanitizedBlueprint.animatedVisibility;
if (sanitizedBlueprint.enableReHide) this.enableReHide = sanitizedBlueprint.enableReHide;
if (sanitizedBlueprint.visibilityRules) {
this.visibilityRules = sanitizedBlueprint.visibilityRules
.map(rule => new VisibilityRule(rule.id, rule.operator, rule.value));
}
if (sanitizedBlueprint.visibilityRules) this.visibilityRules = sanitizedBlueprint.visibilityRules;
this.elements =
sanitizedBlueprint.elements?.map(element => ElementFactory.createElement({
...element,
......
export class VisibilityRule {
export interface VisibilityRule {
id: string;
operator: Operator;
value: string;
static operators = ['=', '!=', '<', '<=', '>', '>='];
constructor(id: string, operator: Operator, value: string) {
this.id = id;
this.operator = operator;
this.value = value;
}
}
export type Operator = typeof VisibilityRule.operators[number];
export const VisibilityRuleOperators = ['=', '!=', '<', '<=', '>', '>='];
type Operator = typeof VisibilityRuleOperators[number];
......@@ -14,7 +14,7 @@
<mat-label>{{'section.operator' | translate}}</mat-label>
<mat-select [(ngModel)]="visibilityRule.operator"
(ngModelChange)="visibilityRuleChange.emit(visibilityRule)">
<mat-option *ngFor="let operator of VisibilityRule.operators"
<mat-option *ngFor="let operator of VisibilityRuleOperators"
[value]="operator">
{{operator}}
</mat-option>
......
import {
Component, EventEmitter, Input, Output
} from '@angular/core';
import { VisibilityRule } from 'common/models/visibility-rule';
import { VisibilityRule, VisibilityRuleOperators } from 'common/models/visibility-rule';
@Component({
selector: 'aspect-visibility-rule-editor',
......@@ -12,5 +12,5 @@ export class VisibilityRuleEditorComponent {
@Input() visibilityRule!: VisibilityRule;
@Output() visibilityRuleChange = new EventEmitter<VisibilityRule>();
protected readonly VisibilityRule = VisibilityRule;
protected readonly VisibilityRuleOperators = VisibilityRuleOperators;
}
......@@ -30,7 +30,7 @@ export class VisibilityRulesDialogComponent {
}
addVisibilityRule(): void {
this.visibilityRules.push(new VisibilityRule('', '=', ''));
this.visibilityRules.push({ id: '', operator: '=', value: '' });
}
deleteVisibilityRule(index: number): void {
......
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