This is an automated email from the ASF dual-hosted git repository.
riemer pushed a commit to branch STREAMPIPES-145
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes.git
The following commit(s) were added to refs/heads/STREAMPIPES-145 by this push:
new bb6e9d0 [STREAMPIPES-145] Improve form validation
bb6e9d0 is described below
commit bb6e9d04f3e4486b1a497937ed565d0cf1037363
Author: Dominik Riemer <[email protected]>
AuthorDate: Sat Jul 11 11:40:33 2020 +0200
[STREAMPIPES-145] Improve form validation
---
.../connect/new-adapter/new-adapter.component.html | 16 ++++++--
.../select-static-properties.component.html | 6 ++-
.../base/abstract-static-property.ts | 3 ++
.../base/abstract-validated-static-property.ts | 6 +--
.../static-collection.component.html | 36 ++++-------------
.../static-collection.component.ts | 46 ++++++++++------------
.../static-color-picker.component.html | 2 +-
.../static-free-input.component.html | 6 +--
.../static-property-util.service.ts | 1 +
.../static-property.component.html | 17 ++++++--
.../static-properties/static-property.component.ts | 4 +-
.../add-visualization-dialog.component.html | 3 +-
.../dialog/customize/customize.component.html | 1 +
.../dialog/customize/customize.component.ts | 1 -
14 files changed, 76 insertions(+), 72 deletions(-)
diff --git a/ui/src/app/connect/new-adapter/new-adapter.component.html
b/ui/src/app/connect/new-adapter/new-adapter.component.html
index dea2a71..2a88ec1 100644
--- a/ui/src/app/connect/new-adapter/new-adapter.component.html
+++ b/ui/src/app/connect/new-adapter/new-adapter.component.html
@@ -54,13 +54,21 @@
</div>
<div class="sp-blue-border padding">
<form [formGroup]="parentForm" fxFlex="100">
- <app-static-property *ngFor="let config of adapter.config"
[staticProperty]="config"
- [staticProperties]="adapter.config"
[adapterId]="adapter.appId" [parentForm]="parentForm"
+ <app-static-property *ngFor="let config of adapter.config"
+ [staticProperty]="config"
+ [staticProperties]="adapter.config"
+ [adapterId]="adapter.appId"
+ [parentForm]="parentForm"
+ [fieldName]="config.internalName"
(updateEmitter)="triggerUpdate($event)"
[completedStaticProperty]="completedStaticProperty">
</app-static-property>
<div fxFlex="100" *ngIf="isGenericAdapter">
- <app-static-property *ngFor="let config of
adapter.protocolDescription.config" [staticProperty]="config"
-
[staticProperties]="adapter.protocolDescription.config"
[adapterId]="adapter.appId" [parentForm]="parentForm"
+ <app-static-property *ngFor="let config of
adapter.protocolDescription.config"
+ [staticProperty]="config"
+
[staticProperties]="adapter.protocolDescription.config"
+ [adapterId]="adapter.appId"
+ [parentForm]="parentForm"
+ [fieldName]="config.internalName"
(updateEmitter)="triggerUpdate($event)"
[completedStaticProperty]="completedStaticProperty">
</app-static-property>
</div>
diff --git
a/ui/src/app/connect/select-static-properties-component/select-static-properties.component.html
b/ui/src/app/connect/select-static-properties-component/select-static-properties.component.html
index e874390..ff9795c 100644
---
a/ui/src/app/connect/select-static-properties-component/select-static-properties.component.html
+++
b/ui/src/app/connect/select-static-properties-component/select-static-properties.component.html
@@ -17,6 +17,10 @@
-->
<div id="select-static-properties" *ngFor="let staticProperty of
staticProperties" class="blockElement fullWidth">
- <app-static-property [adapterId]="adapterId"
[staticProperties]="staticProperties" [eventSchemas]="eventSchema"
[staticProperty]="staticProperty" (validateEmitter)="validateText()"
(updateEmitter)="triggerUpdate($event)"
[completedStaticProperty]="completedStaticProperty" class="test fullWidth">
+ <app-static-property [adapterId]="adapterId"
+ [staticProperties]="staticProperties"
+ [eventSchemas]="eventSchema"
+ [fieldName]="staticProperty.internalName"
+ [staticProperty]="staticProperty"
(validateEmitter)="validateText()" (updateEmitter)="triggerUpdate($event)"
[completedStaticProperty]="completedStaticProperty" class="test fullWidth">
</app-static-property>
</div>
\ No newline at end of file
diff --git
a/ui/src/app/connect/static-properties/base/abstract-static-property.ts
b/ui/src/app/connect/static-properties/base/abstract-static-property.ts
index 0c3c2bb..6c0d25f 100644
--- a/ui/src/app/connect/static-properties/base/abstract-static-property.ts
+++ b/ui/src/app/connect/static-properties/base/abstract-static-property.ts
@@ -42,6 +42,9 @@ export abstract class AbstractStaticPropertyRenderer<T
extends StaticProperty> {
@Input()
parentForm: FormGroup;
+ @Input()
+ fieldName: string;
+
@Output() updateEmitter: EventEmitter<ConfigurationInfo> = new
EventEmitter();
diff --git
a/ui/src/app/connect/static-properties/base/abstract-validated-static-property.ts
b/ui/src/app/connect/static-properties/base/abstract-validated-static-property.ts
index 83d6207..629e708 100644
---
a/ui/src/app/connect/static-properties/base/abstract-validated-static-property.ts
+++
b/ui/src/app/connect/static-properties/base/abstract-validated-static-property.ts
@@ -30,17 +30,17 @@ export abstract class
AbstractValidatedStaticPropertyRenderer<T extends StaticPr
}
enableValidators() {
-
this.parentForm.controls[this.staticProperty.internalName].valueChanges.subscribe(value
=> {
+ this.parentForm.controls[this.fieldName].valueChanges.subscribe(value => {
this.onValueChange(value);
});
-
this.parentForm.controls[this.staticProperty.internalName].statusChanges.subscribe(status
=> {
+ this.parentForm.controls[this.fieldName].statusChanges.subscribe(status =>
{
this.fieldValid = status === "VALID";
this.onStatusChange(status);
})
}
addValidator(defaultValue: any, validators: ValidatorFn | ValidatorFn[]) {
- this.parentForm.addControl(this.staticProperty.internalName, new
FormControl(defaultValue, validators));
+ this.parentForm.addControl(this.fieldName, new FormControl(defaultValue,
validators));
this.parentForm.updateValueAndValidity();
}
diff --git
a/ui/src/app/connect/static-properties/static-collection/static-collection.component.html
b/ui/src/app/connect/static-properties/static-collection/static-collection.component.html
index 4c2f9ed..5e70fbb 100644
---
a/ui/src/app/connect/static-properties/static-collection/static-collection.component.html
+++
b/ui/src/app/connect/static-properties/static-collection/static-collection.component.html
@@ -16,20 +16,14 @@
~
-->
-<div id="formWrapper" fxFlex="100" fxLayout="column">
-
- <div>
- <p>{{staticProperty.label}}: <br>
- <mat-hint
class="description">{{staticProperty.description}}</mat-hint>
- </p>
- </div>
-
+<div fxFlex="100" fxLayout="column">
<div fxLayout="row" fxLayoutAlign="space-between center" *ngFor="let
property of staticProperty.members; let i = index">
<div fxFlex="grow">
<app-static-property [adapterId]="adapterId"
[eventSchemas]="eventSchemas"
- [staticProperty]="property"
- (validateEmitter)="valueChange($event)">
+ [parentForm]="parentForm"
+ [fieldName]="property.internalName + '-' + i"
+ [staticProperty]="property">
</app-static-property>
</div>
<div fxFlex="nogrow" style="width: 50px" fxLayout="row"
fxLayoutAlign="end center">
@@ -38,25 +32,11 @@
</button>
</div>
</div>
-
-
- <div fxLayout="row" fxLayoutAlign="space-between center">
- <div fxFlex="grow" style="pointer-events: none; opacity: 0.4;">
- <app-static-property
- [adapterId]="adapterId"
- [eventSchemas]="eventSchemas"
-
[staticProperty]="staticProperty.staticPropertyTemplate"
- (validateEmitter)="valueChange($event)">
- </app-static-property>
- </div>
- <div fxFlex="nogrow" style="width: 50px" fxLayout="row"
fxLayoutAlign="end center">
- <button mat-icon-button class="icon-button" (click)="add()">
- <mat-icon class="icon">add</mat-icon>
- </button>
- </div>
+ <div fxFlex>
+ <button mat-button mat-flat-button (click)="add()">
+ <mat-icon class="icon">add</mat-icon><span>Add more</span>
+ </button>
</div>
-
-
</div>
diff --git
a/ui/src/app/connect/static-properties/static-collection/static-collection.component.ts
b/ui/src/app/connect/static-properties/static-collection/static-collection.component.ts
index aa5c638..8c0b6b7 100644
---
a/ui/src/app/connect/static-properties/static-collection/static-collection.component.ts
+++
b/ui/src/app/connect/static-properties/static-collection/static-collection.component.ts
@@ -16,11 +16,16 @@
*
*/
-import {Component, EventEmitter, Output} from '@angular/core';
+import {Component, EventEmitter, OnInit, Output} from '@angular/core';
import {ConfigurationInfo} from '../../model/message/ConfigurationInfo';
import {StaticPropertyUtilService} from '../static-property-util.service';
-import {CollectionStaticProperty} from
"../../../core-model/gen/streampipes-model";
+import {
+ CollectionStaticProperty,
+ StaticProperty,
+ StaticPropertyUnion
+} from "../../../core-model/gen/streampipes-model";
import {AbstractStaticPropertyRenderer} from
"../base/abstract-static-property";
+import {AbstractValidatedStaticPropertyRenderer} from
"../base/abstract-validated-static-property";
@Component({
@@ -29,45 +34,36 @@ import {AbstractStaticPropertyRenderer} from
"../base/abstract-static-property";
styleUrls: ['./static-collection.component.css']
})
export class StaticCollectionComponent
- extends AbstractStaticPropertyRenderer<CollectionStaticProperty> {
-
-
- @Output() inputEmitter: EventEmitter<Boolean> = new
EventEmitter<Boolean>();
- @Output() updateEmitter: EventEmitter<ConfigurationInfo> = new
EventEmitter();
-
- private hasInput: Boolean;
+ extends AbstractValidatedStaticPropertyRenderer<CollectionStaticProperty>
implements OnInit {
constructor(private staticPropertyUtil: StaticPropertyUtilService) {
super();
}
-
- valueChange(inputValue) {
- if ((<CollectionStaticProperty> this.staticProperty).members !==
undefined) {
- let property = (<CollectionStaticProperty>
this.staticProperty).members.find(member => (member as any).isValid == false);
- property === undefined ? this.hasInput = true : this.hasInput =
false;
- } else {
- this.hasInput = false;
- }
-
- this.inputEmitter.emit(this.hasInput);
- this.emitUpdate(this.hasInput);
+ ngOnInit() {
}
+
emitUpdate(valid) {
this.updateEmitter.emit(new
ConfigurationInfo(this.staticProperty.internalName, valid));
}
add() {
- if ( (<CollectionStaticProperty> (this.staticProperty)).members ===
undefined) {
- (<CollectionStaticProperty> (this.staticProperty)).members = [];
+ if (!this.staticProperty.members) {
+ this.staticProperty.members = [];
}
- let clone = this.staticPropertyUtil.clone((<CollectionStaticProperty>
(this.staticProperty)).staticPropertyTemplate);
- (<CollectionStaticProperty> (this.staticProperty)).members.push(clone)
+ let clone =
this.staticPropertyUtil.clone(this.staticProperty.staticPropertyTemplate);
+ this.staticProperty.members.push(clone);
}
remove(i) {
- (<CollectionStaticProperty>
(this.staticProperty)).members.splice(i,1).slice(0);
+ this.staticProperty.members.splice(i,1).slice(0);
+ }
+
+ onStatusChange(status: any) {
+ }
+
+ onValueChange(value: any) {
}
}
\ No newline at end of file
diff --git
a/ui/src/app/connect/static-properties/static-color-picker/static-color-picker.component.html
b/ui/src/app/connect/static-properties/static-color-picker/static-color-picker.component.html
index 35f6795..499b126 100644
---
a/ui/src/app/connect/static-properties/static-color-picker/static-color-picker.component.html
+++
b/ui/src/app/connect/static-properties/static-color-picker/static-color-picker.component.html
@@ -22,7 +22,7 @@
[(colorPicker)]="staticProperty.selectedColor"
(colorPickerChange)="parentForm.get(staticProperty.internalName).setValue($event)"
[cpPosition]="'bottom'"
- formControlName="{{staticProperty.internalName}}"
+ formControlName="{{fieldName}}"
[style.background]="staticProperty.selectedColor" required
(blur)="emitUpdate()" [cpPresetColors] = "presetColors"/>
</mat-form-field>
diff --git
a/ui/src/app/connect/static-properties/static-free-input/static-free-input.component.html
b/ui/src/app/connect/static-properties/static-free-input/static-free-input.component.html
index 9392dd1..fbefc7f 100644
---
a/ui/src/app/connect/static-properties/static-free-input/static-free-input.component.html
+++
b/ui/src/app/connect/static-properties/static-free-input/static-free-input.component.html
@@ -19,7 +19,7 @@
<div [formGroup]="parentForm" fxFlex="100" fxLayout="column">
<div fxFlex fxLayout="row" *ngIf="!staticProperty.valueSpecification &&
!staticProperty.multiLine">
<mat-form-field fxFlex>
- <input formControlName="{{staticProperty.internalName}}" fxFlex
+ <input formControlName="{{fieldName}}" fxFlex
matInput
[placeholder]="staticProperty.label"
required (blur)="emitUpdate()">
@@ -32,7 +32,7 @@
</div>
<div *ngIf="staticProperty.valueSpecification">
<div fxLayout="column" fxFlex="100">
- <mat-slider thumbLabel
formControlName="{{staticProperty.internalName}}"
+ <mat-slider thumbLabel formControlName="{{fieldName}}"
[max]="staticProperty.valueSpecification.maxValue"
[min]="staticProperty.valueSpecification.minValue"
[step]="staticProperty.valueSpecification.step">
@@ -49,7 +49,7 @@
</div>
</div>
<div fxFlex="100" *ngIf="staticProperty.multiLine">
- <quill-editor #textEditor
formControlName="{{staticProperty.internalName}}"
[modules]="quillModules"></quill-editor>
+ <quill-editor #textEditor formControlName="{{fieldName}}"
[modules]="quillModules"></quill-editor>
</div>
</div>
</div>
\ No newline at end of file
diff --git
a/ui/src/app/connect/static-properties/static-property-util.service.ts
b/ui/src/app/connect/static-properties/static-property-util.service.ts
index 49e4b6f..43b4c5b 100644
--- a/ui/src/app/connect/static-properties/static-property-util.service.ts
+++ b/ui/src/app/connect/static-properties/static-property-util.service.ts
@@ -134,6 +134,7 @@ export class StaticPropertyUtilService{
clone.horizontalRendering = val.horizontalRendering;
}
clone = this.copyStaticPropertyProperty(val, clone);
+ clone["@class"] = val["@class"];
return clone;
}
diff --git
a/ui/src/app/connect/static-properties/static-property.component.html
b/ui/src/app/connect/static-properties/static-property.component.html
index d46cdfc..a9e9bd6 100644
--- a/ui/src/app/connect/static-properties/static-property.component.html
+++ b/ui/src/app/connect/static-properties/static-property.component.html
@@ -27,12 +27,14 @@
[staticProperty]="staticProperty"
[parentForm]="parentForm"
[eventSchemas]="eventSchemas"
+ [fieldName]="fieldName"
(updateEmitter)="emitUpdate($event)">
</app-static-code-input>
<app-static-secret-input
*ngIf="isSecretStaticProperty(staticProperty)"
[staticProperty]="staticProperty"
[parentForm]="parentForm"
+ [fieldName]="fieldName"
(updateEmitter)="emitUpdate($event)">
</app-static-secret-input>
@@ -40,6 +42,7 @@
[staticProperty]="staticProperty"
[parentForm]="parentForm"
[eventSchemas]="eventSchemas"
+ [fieldName]="fieldName"
(updateEmitter)="emitUpdate($event)">
</app-static-free-input>
@@ -51,6 +54,7 @@
<app-static-color-picker
*ngIf="isColorPickerStaticProperty(staticProperty)"
[staticProperty]="staticProperty"
[parentForm]="parentForm"
+ [fieldName]="fieldName"
(updateEmitter)="emitUpdate($event)">
</app-static-color-picker>
@@ -75,8 +79,11 @@
</app-static-one-of-input>
<app-static-mapping-unary
*ngIf="isMappingPropertyUnary(staticProperty)"
- [eventSchemas]="eventSchemas"
(inputEmitter)="valueChange($event)"
- [staticProperty]="staticProperty"
[parentForm]="parentForm">
+ [eventSchemas]="eventSchemas"
+ [staticProperty]="staticProperty"
+ [parentForm]="parentForm"
+ [fieldName]="fieldName"
+ (inputEmitter)="valueChange($event)">
</app-static-mapping-unary>
<app-static-mapping-nary
*ngIf="isMappingNaryProperty(staticProperty)" [eventSchemas]="eventSchemas"
@@ -96,9 +103,11 @@
</app-static-group>
<app-static-collection
*ngIf="isCollectionStaticProperty(staticProperty)"
- [adapterId]="adapterId"
[eventSchemas]="eventSchemas"
+ [adapterId]="adapterId"
+ [eventSchemas]="eventSchemas"
+ [parentForm]="parentForm"
[staticProperty]="staticProperty"
class="test fullWidth"
- (inputEmitter)="valueChange($event)"
(updateEmitter)="emitUpdate($event)">
+ (updateEmitter)="emitUpdate($event)">
</app-static-collection>
</div>
</div>
diff --git a/ui/src/app/connect/static-properties/static-property.component.ts
b/ui/src/app/connect/static-properties/static-property.component.ts
index 398100e..a538ae5 100644
--- a/ui/src/app/connect/static-properties/static-property.component.ts
+++ b/ui/src/app/connect/static-properties/static-property.component.ts
@@ -73,6 +73,9 @@ export class StaticPropertyComponent implements OnInit {
@Input()
parentForm: FormGroup;
+ @Input()
+ fieldName: string;
+
constructor(
private logger: Logger,
public xsService: xsService,
@@ -82,7 +85,6 @@ export class StaticPropertyComponent implements OnInit {
}
ngOnInit() {
-
}
isCodeInputStaticProperty(val) {
diff --git
a/ui/src/app/dashboard/dialogs/add-widget/add-visualization-dialog.component.html
b/ui/src/app/dashboard/dialogs/add-widget/add-visualization-dialog.component.html
index a53de25..633adec 100644
---
a/ui/src/app/dashboard/dialogs/add-widget/add-visualization-dialog.component.html
+++
b/ui/src/app/dashboard/dialogs/add-widget/add-visualization-dialog.component.html
@@ -66,7 +66,8 @@
<div fxFlex="100" fxLayout="column">
<app-static-property *ngFor="let config of
selectedWidget.config" [staticProperty]="config"
[staticProperties]="selectedWidget.config"
-
[eventSchema]="selectedPipeline.schema"
+
[eventSchemas]="[selectedPipeline.schema]"
+ [fieldName]="config.internalName"
(validateEmitter)="validConfiguration($event)"></app-static-property>
</div>
diff --git a/ui/src/app/editor-v2/dialog/customize/customize.component.html
b/ui/src/app/editor-v2/dialog/customize/customize.component.html
index d24f742..4a9b5e4 100644
--- a/ui/src/app/editor-v2/dialog/customize/customize.component.html
+++ b/ui/src/app/editor-v2/dialog/customize/customize.component.html
@@ -48,6 +48,7 @@
[staticProperties]="cachedPipelineElement.staticProperties"
[eventSchemas]="eventSchemas"
[parentForm]="parentForm"
+ [fieldName]="config.internalName"
(validateEmitter)="validConfiguration($event)">
</app-static-property>
</form>
diff --git a/ui/src/app/editor-v2/dialog/customize/customize.component.ts
b/ui/src/app/editor-v2/dialog/customize/customize.component.ts
index a587523..768d77f 100644
--- a/ui/src/app/editor-v2/dialog/customize/customize.component.ts
+++ b/ui/src/app/editor-v2/dialog/customize/customize.component.ts
@@ -84,7 +84,6 @@ export class CustomizeComponent implements OnInit,
AfterViewInit {
});
this.parentForm.valueChanges.subscribe(v => {
- console.log(v);
});
this.parentForm.statusChanges.subscribe((status)=>{