Commit 8b4dc3f5 authored by Alexander Philipp Nowosad's avatar Alexander Philipp Nowosad
Browse files

Add description to canvas definition

parent dc0a973c
Pipeline #139161 failed with stages
in 8 minutes and 8 seconds
......@@ -9,12 +9,14 @@ import { DatabaseRootEntry } from '../database/database-entry';
export interface CanvasDefinitionEntry extends DatabaseRootEntry {
name: string;
description: string;
rows: CanvasDefinitionCellEntry[][];
relationshipTypes: string[];
}
interface CanvasDefinitionJsonSchema {
name: string;
description: string;
rows: CanvasDefinitionCellEntry[][];
relationshipTypes: string[];
}
......@@ -23,6 +25,7 @@ export class CanvasDefinition extends DatabaseModel {
static readonly typeName = 'CanvasDefinition';
name: string;
description: string;
rows: CanvasDefinitionCell[][] = [];
......@@ -78,6 +81,7 @@ export class CanvasDefinition extends DatabaseModel {
return {
...super.toDb(),
name: this.name,
description: this.description,
rows: this.rows.map((row) => row.map((cell) => cell.toDb())),
relationshipTypes: this.relationshipTypes,
};
......@@ -86,6 +90,7 @@ export class CanvasDefinition extends DatabaseModel {
toJSON(): CanvasDefinitionJsonSchema {
return {
name: this.name,
description: this.description,
rows: this.rows.map((row) => row.map((cell) => cell.toDb())),
relationshipTypes: this.relationshipTypes,
};
......
......@@ -11,6 +11,17 @@
/>
</div>
</div>
<div class="form-group form-row">
<label for="description" class="col-sm-4 col-form-label">Description</label>
<div class="col-sm-8">
<textarea
formControlName="description"
class="form-control"
id="description"
rows="3"
></textarea>
</div>
</div>
<div class="form-group row">
<div class="col-sm-12">
<button
......
......@@ -8,7 +8,12 @@ import {
Output,
SimpleChanges,
} from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import {
FormBuilder,
FormControl,
FormGroup,
Validators,
} from '@angular/forms';
import { Subscription } from 'rxjs';
import { debounceTime, tap } from 'rxjs/operators';
import { CanvasDefinition } from '../../../canvas-meta-model/canvas-definition';
......@@ -27,6 +32,7 @@ export class CanvasDefinitionFormComponent
form: FormGroup = this.fb.group({
name: ['', Validators.required],
description: [''],
});
changed = false;
......@@ -34,7 +40,7 @@ export class CanvasDefinitionFormComponent
constructor(private fb: FormBuilder) {}
ngOnInit() {
ngOnInit(): void {
this.changeSubscription = this.form.valueChanges
.pipe(
debounceTime(300),
......@@ -49,7 +55,7 @@ export class CanvasDefinitionFormComponent
.subscribe();
}
ngOnChanges(changes: SimpleChanges) {
ngOnChanges(changes: SimpleChanges): void {
if (changes.canvasDefinition) {
const newCanvasDefinition = changes.canvasDefinition.currentValue;
const oldCanvasDefinition = changes.canvasDefinition.previousValue;
......@@ -61,38 +67,44 @@ export class CanvasDefinitionFormComponent
}
}
ngOnDestroy() {
ngOnDestroy(): void {
if (this.changeSubscription) {
this.changeSubscription.unsubscribe();
}
}
emitSubmitForm() {
emitSubmitForm(): void {
this.submitForm.emit(this.form);
}
private loadForm(canvasDefinition: CanvasDefinition) {
private loadForm(canvasDefinition: CanvasDefinition): void {
if (canvasDefinition != null) {
this.form.setValue({ name: canvasDefinition.name });
this.form.patchValue({
name: canvasDefinition.name,
description: canvasDefinition.description,
});
} else {
this.form.setValue({ name: '' });
this.form.patchValue({ name: '', description: '' });
}
}
private equalCanvasDefinitions(
canvasDefinitionA: CanvasDefinition,
canvasDefinitionB: CanvasDefinition
) {
): boolean {
if (canvasDefinitionA == null && canvasDefinitionB == null) {
return true;
}
if (canvasDefinitionA == null || canvasDefinitionB == null) {
return false;
}
return canvasDefinitionA.name === canvasDefinitionB.name;
return (
canvasDefinitionA.name === canvasDefinitionB.name &&
canvasDefinitionA.description === canvasDefinitionB.description
);
}
get nameControl() {
return this.form.get('name');
get nameControl(): FormControl {
return this.form.get('name') as FormControl;
}
}
......@@ -53,6 +53,10 @@
"description": "The name of the canvas definition",
"type": "string"
},
"description": {
"description": "The description of the canvas definition",
"type": "string"
},
"rows": {
"description": "The rows of the canvas",
"type": "array",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment