Skip to content
Snippets Groups Projects
Commit 32927bb6 authored by rhenck's avatar rhenck
Browse files

MathTable: Rework none-operation to 'flexible'

- New property group for flexible layout with more options to change the 
behaviour. It is now possible to build all other operations in this 
preset.
parent 58a81c7a
No related branches found
No related tags found
No related merge requests found
Pipeline #53157 failed
...@@ -138,6 +138,10 @@ iqb-aspect-definition@1.0.0 ...@@ -138,6 +138,10 @@ iqb-aspect-definition@1.0.0
- new property in "OtherStyles": lastHelperRowColor - new property in "OtherStyles": lastHelperRowColor
- MathTable: - MathTable:
- new styling property: lastHelperRowColor - new styling property: lastHelperRowColor
- new property: allowArithmeticChars - new property value: operation: 'variable'
- new property: isFirstLineUnderlined - new property: variableLayoutOptions: {
- new property value: operation: 'none' allowArithmeticChars: boolean;
isFirstLineUnderlined: boolean;
showResultRow: boolean;
showTopHelperRows: boolean;
allowFirstLineCrossOut: boolean; }
...@@ -15,7 +15,15 @@ import { ValueChangeElement } from 'common/models/elements/element'; ...@@ -15,7 +15,15 @@ import { ValueChangeElement } from 'common/models/elements/element';
</div> </div>
<ng-template #elseBlock> <ng-template #elseBlock>
<div class="wrapper"> <div class="wrapper">
<table [class.multiplication]="elementModel.operation === 'multiplication'" <table [class.underline-first-row]="elementModel.operation === 'multiplication' ||
(elementModel.operation === 'variable' &&
elementModel.variableLayoutOptions.isFirstLineUnderlined &&
!elementModel.variableLayoutOptions.showTopHelperRows)"
[class.underline-third-row]="elementModel.operation === 'variable' &&
elementModel.variableLayoutOptions.isFirstLineUnderlined &&
elementModel.variableLayoutOptions.showTopHelperRows"
[class.has-result-row]="elementModel.operation !== 'variable' ||
elementModel.variableLayoutOptions.showResultRow"
[style.color]="elementModel.styling.fontColor" [style.color]="elementModel.styling.fontColor"
[style.background-color]="elementModel.styling.backgroundColor" [style.background-color]="elementModel.styling.backgroundColor"
[style.font-size.px]="elementModel.styling.fontSize" [style.font-size.px]="elementModel.styling.fontSize"
...@@ -27,9 +35,7 @@ import { ValueChangeElement } from 'common/models/elements/element'; ...@@ -27,9 +35,7 @@ import { ValueChangeElement } from 'common/models/elements/element';
elementModel.styling.fontSize * 2" elementModel.styling.fontSize * 2"
[style.font-size]="row.cells.length && row.isHelperRow && '70%'" [style.font-size]="row.cells.length && row.isHelperRow && '70%'"
[style.background-color]="index === tableModel.length - 2 ? [style.background-color]="index === tableModel.length - 2 ?
elementModel.styling.lastHelperRowColor : 'transparent'" elementModel.styling.lastHelperRowColor : 'transparent'">
[class.underline]="(index === tableModel.length - 2 && elementModel.operation !== 'none') ||
(index === 0 && elementModel.operation === 'none' && elementModel.isFirstLineUnderlined)">
<td *ngFor="let cell of row.cells" [attr.contenteditable]="cell.isEditable" <td *ngFor="let cell of row.cells" [attr.contenteditable]="cell.isEditable"
[style.width.px]="elementModel.styling.fontSize * 2" [style.width.px]="elementModel.styling.fontSize * 2"
[class.strike-through]="cell.isCrossedOut" [class.strike-through]="cell.isCrossedOut"
...@@ -67,8 +73,9 @@ import { ValueChangeElement } from 'common/models/elements/element'; ...@@ -67,8 +73,9 @@ import { ValueChangeElement } from 'common/models/elements/element';
'td {border: 1px solid grey; text-align: center; caret-color: transparent;}', 'td {border: 1px solid grey; text-align: center; caret-color: transparent;}',
'td.strike-through {text-decoration: line-through; text-decoration-thickness: 3px;}', 'td.strike-through {text-decoration: line-through; text-decoration-thickness: 3px;}',
'td:focus {background-color: #00606425; outline: unset;}', 'td:focus {background-color: #00606425; outline: unset;}',
'table .underline {border-bottom: 3px solid black;}', 'table.underline-first-row tr:first-child {border-bottom: 3px solid black;}',
'table.multiplication tr:first-child {border-bottom: 3px solid black;}', 'table.underline-third-row tr:nth-child(3) {border-bottom: 3px solid black;}',
'table.has-result-row tr:last-child {border-top: 3px solid black;}',
'.terms-missing-warning {font-size: larger; color: red;}' '.terms-missing-warning {font-size: larger; color: red;}'
] ]
}) })
...@@ -87,8 +94,8 @@ export class MathTableComponent extends ElementComponent implements OnInit { ...@@ -87,8 +94,8 @@ export class MathTableComponent extends ElementComponent implements OnInit {
private createTableModel(): void { private createTableModel(): void {
switch (this.elementModel.operation) { switch (this.elementModel.operation) {
case 'none': { case 'variable': {
this.tableModel = this.createCustomModel(); this.tableModel = this.createVariableModel();
break; break;
} }
case 'addition': { case 'addition': {
...@@ -108,18 +115,26 @@ export class MathTableComponent extends ElementComponent implements OnInit { ...@@ -108,18 +115,26 @@ export class MathTableComponent extends ElementComponent implements OnInit {
} }
} }
private createCustomModel(): MathTableRow[] { private createVariableModel(): MathTableRow[] {
const operatorOffset = 1; // offset for operatorChar const operatorOffset = 0; // offset for operatorChar
const width = Math.max( const width = Math.max(
...this.elementModel.terms.map(term => term.length + operatorOffset), ...this.elementModel.terms.map(term => term.length + operatorOffset),
this.elementModel.result.length, this.elementModel.result.length,
2 // have at least one empty column, so the table does not disappear completely when terms are empty 1 // have at least one empty column, so the table does not disappear completely when terms are empty
); );
return [ return [
...this.elementModel.variableLayoutOptions.showTopHelperRows ?
[MathTableComponent.createHelperRow(width, true)] : [],
...this.elementModel.variableLayoutOptions.showTopHelperRows ?
[MathTableComponent.createHelperRow(width, true)] : [],
...this.elementModel.terms ...this.elementModel.terms
.map(term => MathTableComponent.createNormalRow( .map((term: string, i: number) => MathTableComponent.createNormalRow(
term, width - operatorOffset term, width - operatorOffset, undefined, i === 0
)) )),
...this.elementModel.variableLayoutOptions.showResultRow ?
[MathTableComponent.createHelperRow(width)] : [],
...this.elementModel.variableLayoutOptions.showResultRow ?
[MathTableComponent.createResultRow(this.elementModel.result, width)] : []
]; ];
} }
...@@ -256,7 +271,7 @@ export class MathTableComponent extends ElementComponent implements OnInit { ...@@ -256,7 +271,7 @@ export class MathTableComponent extends ElementComponent implements OnInit {
if (this.elementModel.operation === 'multiplication' && !row.isHelperRow) { if (this.elementModel.operation === 'multiplication' && !row.isHelperRow) {
allowedKeys.push('+', '-', '*', ':', '/'); allowedKeys.push('+', '-', '*', ':', '/');
} }
if (this.elementModel.operation === 'none' && this.elementModel.allowArithmeticChars) { if (this.elementModel.operation === 'variable' && this.elementModel.variableLayoutOptions.allowArithmeticChars) {
allowedKeys.push('+', '-', '*', ':', '/', '='); allowedKeys.push('+', '-', '*', ':', '/', '=');
} }
if (!allowedKeys.includes(event.key)) return; if (!allowedKeys.includes(event.key)) return;
......
import { UIElement, UIElementProperties, UIElementType } from 'common/models/elements/element'; import { UIElement, UIElementProperties, UIElementType, UIElementValue } from 'common/models/elements/element';
import { AnswerScheme } from 'common/models/elements/answer-scheme-interfaces'; import { AnswerScheme } from 'common/models/elements/answer-scheme-interfaces';
import { Type } from '@angular/core'; import { Type } from '@angular/core';
import { ElementComponent } from 'common/directives/element-component.directive'; import { ElementComponent } from 'common/directives/element-component.directive';
...@@ -13,11 +13,22 @@ import { ...@@ -13,11 +13,22 @@ import {
export class MathTableElement extends UIElement implements MathTableProperties { export class MathTableElement extends UIElement implements MathTableProperties {
type: UIElementType = 'math-table'; type: UIElementType = 'math-table';
operation: 'none' | 'addition' | 'subtraction' | 'multiplication' = 'addition'; operation: 'variable' | 'addition' | 'subtraction' | 'multiplication' = 'addition';
terms: string[] = ['123', '456']; terms: string[] = ['123', '456'];
result: string = ''; result: string = '';
allowArithmeticChars: boolean = false; variableLayoutOptions: {
isFirstLineUnderlined: boolean = true; allowArithmeticChars: boolean;
isFirstLineUnderlined: boolean;
showResultRow: boolean;
showTopHelperRows: boolean;
allowFirstLineCrossOut: boolean; } = {
allowArithmeticChars: false,
isFirstLineUnderlined: true,
showResultRow: false,
showTopHelperRows: false,
allowFirstLineCrossOut: false
};
styling: BasicStyles & { styling: BasicStyles & {
lastHelperRowColor: string; lastHelperRowColor: string;
}; };
...@@ -28,8 +39,7 @@ export class MathTableElement extends UIElement implements MathTableProperties { ...@@ -28,8 +39,7 @@ export class MathTableElement extends UIElement implements MathTableProperties {
this.operation = element.operation; this.operation = element.operation;
this.terms = [...element.terms]; this.terms = [...element.terms];
this.result = element.result; this.result = element.result;
this.allowArithmeticChars = element.allowArithmeticChars; this.variableLayoutOptions = { ...element.variableLayoutOptions };
this.isFirstLineUnderlined = element.isFirstLineUnderlined;
this.styling = { ...element.styling }; this.styling = { ...element.styling };
} else { } else {
if (environment.strictInstantiation) { if (environment.strictInstantiation) {
...@@ -38,8 +48,7 @@ export class MathTableElement extends UIElement implements MathTableProperties { ...@@ -38,8 +48,7 @@ export class MathTableElement extends UIElement implements MathTableProperties {
if (element?.operation !== undefined) this.operation = element.operation; if (element?.operation !== undefined) this.operation = element.operation;
if (element?.terms !== undefined) this.terms = [...element.terms]; if (element?.terms !== undefined) this.terms = [...element.terms];
if (element?.result !== undefined) this.result = element.result; if (element?.result !== undefined) this.result = element.result;
if (element?.allowArithmeticChars !== undefined) this.allowArithmeticChars = element.allowArithmeticChars; if (element?.variableLayoutOptions !== undefined) this.variableLayoutOptions = { ...element.variableLayoutOptions };
if (element?.isFirstLineUnderlined !== undefined) this.isFirstLineUnderlined = element.isFirstLineUnderlined;
this.styling = { this.styling = {
...PropertyGroupGenerators.generateBasicStyleProps(element?.styling), ...PropertyGroupGenerators.generateBasicStyleProps(element?.styling),
lastHelperRowColor: 'transparent' lastHelperRowColor: 'transparent'
...@@ -47,6 +56,14 @@ export class MathTableElement extends UIElement implements MathTableProperties { ...@@ -47,6 +56,14 @@ export class MathTableElement extends UIElement implements MathTableProperties {
} }
} }
setProperty(property: string, value: unknown): void {
if (Object.keys(this.variableLayoutOptions).includes(property)) {
this.variableLayoutOptions[property as keyof typeof this.variableLayoutOptions] = value as boolean;
} else {
super.setProperty(property, value);
}
}
hasAnswerScheme(): boolean { hasAnswerScheme(): boolean {
return Boolean(this.getAnswerScheme); return Boolean(this.getAnswerScheme);
} }
...@@ -73,11 +90,16 @@ export class MathTableElement extends UIElement implements MathTableProperties { ...@@ -73,11 +90,16 @@ export class MathTableElement extends UIElement implements MathTableProperties {
} }
export interface MathTableProperties extends UIElementProperties { export interface MathTableProperties extends UIElementProperties {
operation: 'none' | 'addition' | 'subtraction' | 'multiplication'; operation: 'variable' | 'addition' | 'subtraction' | 'multiplication';
terms: string[]; terms: string[];
result: string; result: string;
allowArithmeticChars: boolean; variableLayoutOptions: {
isFirstLineUnderlined: boolean; allowArithmeticChars: boolean;
isFirstLineUnderlined: boolean;
showResultRow: boolean;
showTopHelperRows: boolean;
allowFirstLineCrossOut: boolean;
}
styling: BasicStyles & { styling: BasicStyles & {
lastHelperRowColor: string; lastHelperRowColor: string;
}; };
...@@ -88,7 +110,11 @@ function isValid(blueprint?: MathTableProperties): boolean { ...@@ -88,7 +110,11 @@ function isValid(blueprint?: MathTableProperties): boolean {
return blueprint.operation !== undefined && return blueprint.operation !== undefined &&
blueprint.terms !== undefined && blueprint.terms !== undefined &&
blueprint.result !== undefined && blueprint.result !== undefined &&
blueprint.allowArithmeticChars !== undefined && blueprint.variableLayoutOptions !== undefined &&
blueprint.isFirstLineUnderlined !== undefined && blueprint.variableLayoutOptions.allowArithmeticChars !== undefined &&
blueprint.variableLayoutOptions.isFirstLineUnderlined !== undefined &&
blueprint.variableLayoutOptions.showResultRow !== undefined &&
blueprint.variableLayoutOptions.showTopHelperRows !== undefined &&
blueprint.variableLayoutOptions.allowFirstLineCrossOut !== undefined &&
PropertyGroupValidators.isValidBasicStyles(blueprint.styling); PropertyGroupValidators.isValidBasicStyles(blueprint.styling);
} }
...@@ -18,7 +18,7 @@ import { UIElement } from 'common/models/elements/element'; ...@@ -18,7 +18,7 @@ import { UIElement } from 'common/models/elements/element';
<mat-label>Operation</mat-label> <mat-label>Operation</mat-label>
<mat-select [value]="combinedProperties.operation" <mat-select [value]="combinedProperties.operation"
(selectionChange)="updateModel.emit({ property: 'operation', value: $event.value })"> (selectionChange)="updateModel.emit({ property: 'operation', value: $event.value })">
<mat-option *ngFor="let operation of ['none', 'addition', 'subtraction', 'multiplication']" <mat-option *ngFor="let operation of ['addition', 'subtraction', 'multiplication', 'variable']"
[value]="operation"> [value]="operation">
{{operation | translate}} {{operation | translate}}
</mat-option> </mat-option>
...@@ -50,22 +50,44 @@ import { UIElement } from 'common/models/elements/element'; ...@@ -50,22 +50,44 @@ import { UIElement } from 'common/models/elements/element';
<mat-form-field (input)="updateModel.emit({ property: 'result', value: $any($event.target).value })"> <mat-form-field (input)="updateModel.emit({ property: 'result', value: $any($event.target).value })">
<mat-label>{{'resultRow' | translate}}</mat-label> <mat-label>{{'resultRow' | translate}}</mat-label>
<input matInput [disabled]="combinedProperties.operation === 'none'" [value]="combinedProperties.result"> <input matInput [disabled]="combinedProperties.operation === 'variable' &&
!$any(combinedProperties.variableLayoutOptions).showResultRow"
[value]="combinedProperties.result">
</mat-form-field> </mat-form-field>
<mat-checkbox *ngIf="combinedProperties.allowArithmeticChars !== undefined"
[disabled]="combinedProperties.operation !== 'none'"
[checked]="$any(combinedProperties.allowArithmeticChars)"
(change)="updateModel.emit({ property: 'allowArithmeticChars', value: $event.checked })">
{{'propertiesPanel.allowArithmeticChars' | translate }}
</mat-checkbox>
<mat-checkbox *ngIf="combinedProperties.isFirstLineUnderlined !== undefined" <button mat-raised-button color="primary"
[disabled]="combinedProperties.operation !== 'none'" [disabled]="combinedProperties.operation !== 'variable'"
[checked]="$any(combinedProperties.isFirstLineUnderlined)" [matMenuTriggerFor]="variableLayoutOptions">
(change)="updateModel.emit({ property: 'isFirstLineUnderlined', value: $event.checked })"> Optionen für variables Layout
{{'propertiesPanel.isFirstLineUnderlined' | translate }} </button>
</mat-checkbox> <mat-menu #variableLayoutOptions="matMenu">
<mat-checkbox [checked]="$any(combinedProperties.variableLayoutOptions).allowArithmeticChars"
(click)="$event.stopPropagation()"
(change)="updateModel.emit({ property: 'allowArithmeticChars', value: $event.checked })">
{{'propertiesPanel.allowArithmeticChars' | translate }}
</mat-checkbox>
<mat-checkbox [checked]="$any(combinedProperties.variableLayoutOptions).isFirstLineUnderlined"
(click)="$event.stopPropagation()"
(change)="updateModel.emit({ property: 'isFirstLineUnderlined', value: $event.checked })">
{{'propertiesPanel.isFirstLineUnderlined' | translate }}
</mat-checkbox>
<mat-checkbox [checked]="$any(combinedProperties.variableLayoutOptions).showResultRow"
(click)="$event.stopPropagation()"
(change)="updateModel.emit({ property: 'showResultRow', value: $event.checked })">
{{'propertiesPanel.showResultRow' | translate }}
</mat-checkbox>
<mat-checkbox [checked]="$any(combinedProperties.variableLayoutOptions).showTopHelperRows"
(click)="$event.stopPropagation()"
(change)="updateModel.emit({ property: 'showTopHelperRows', value: $event.checked })">
{{'propertiesPanel.showTopHelperRows' | translate }}
</mat-checkbox>
<mat-checkbox [checked]="$any(combinedProperties.variableLayoutOptions).allowFirstLineCrossOut"
(click)="$event.stopPropagation()"
(change)="updateModel.emit({ property: 'allowFirstLineCrossOut', value: $event.checked })">
{{'propertiesPanel.allowFirstLineCrossOut' | translate }}
</mat-checkbox>
</mat-menu>
</div> </div>
`, `,
styles: [` styles: [`
......
...@@ -254,6 +254,9 @@ ...@@ -254,6 +254,9 @@
"lastHelperRowColor": "Farbe unterer Hilfszeile", "lastHelperRowColor": "Farbe unterer Hilfszeile",
"allowArithmeticChars": "Rechen- und Gleichheitszeichen erlauben", "allowArithmeticChars": "Rechen- und Gleichheitszeichen erlauben",
"isFirstLineUnderlined": "Unterstreichung erste Zeile", "isFirstLineUnderlined": "Unterstreichung erste Zeile",
"showResultRow": "Ergebniszeile",
"showTopHelperRows": "obere Helferzeilen",
"allowFirstLineCrossOut": "Durchstreichen in erster Zeile",
"trackedVariables": "Ergebnisvariablen" "trackedVariables": "Ergebnisvariablen"
}, },
"hotspot": { "hotspot": {
...@@ -349,7 +352,7 @@ ...@@ -349,7 +352,7 @@
"addition": "Addition", "addition": "Addition",
"subtraction": "Subtraktion", "subtraction": "Subtraktion",
"multiplication": "Multiplikation", "multiplication": "Multiplikation",
"none": "keine", "variable": "variables Layout",
"termRows": "Termzeilen", "termRows": "Termzeilen",
"addTermRow": "Termzeile hinzufügen", "addTermRow": "Termzeile hinzufügen",
"resultRow": "Ergebniszeile" "resultRow": "Ergebniszeile"
......
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