This is an automated email from the ASF dual-hosted git repository.
zehnder pushed a commit to branch STREAMPIPES-380
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes.git
The following commit(s) were added to refs/heads/STREAMPIPES-380 by this push:
new 152237e [STREAMPIPES-396] Data Set Adapter does not work with JSON
Array
152237e is described below
commit 152237e2ef0548ec662175717ba7823eb99980e0
Author: Philipp Zehnder <[email protected]>
AuthorDate: Wed Jul 7 13:31:53 2021 +0200
[STREAMPIPES-396] Data Set Adapter does not work with JSON Array
---
.../static-file-input.component.html | 12 +--
.../static-file-input.component.ts | 99 +++++++++++++---------
.../static-property.component.html | 6 +-
3 files changed, 68 insertions(+), 49 deletions(-)
diff --git
a/ui/src/app/core-ui/static-properties/static-file-input/static-file-input.component.html
b/ui/src/app/core-ui/static-properties/static-file-input/static-file-input.component.html
index 7134363..8d6290f 100644
---
a/ui/src/app/core-ui/static-properties/static-file-input/static-file-input.component.html
+++
b/ui/src/app/core-ui/static-properties/static-file-input/static-file-input.component.html
@@ -16,19 +16,19 @@
~
-->
-<div fxFlex="100" fxLayout="column">
+<div fxFlex="100" fxLayout="column" [formGroup]="parentForm">
<div fxFlex="100" fxLayout="column">
<div fxFlex="row">
- <mat-radio-group [(ngModel)]="chooseExistingFile" color="primary">
+ <mat-radio-group [formControl]="chooseExistingFileControl"
color="primary">
<mat-radio-button style="margin-right:10px;"
[value]="true">Choose existing file</mat-radio-button>
<mat-radio-button [value]="false">Upload new
file</mat-radio-button>
</mat-radio-group>
</div>
- <div *ngIf="chooseExistingFile && filesLoaded">
+ <div *ngIf="chooseExistingFileControl.value && filesLoaded" >
<mat-form-field>
<input type="text"
placeholder="Select file"
- [(ngModel)]="selectedFile"
+ formControlName="{{fieldName}}"
matInput
[matAutocomplete]="auto">
<button mat-button *ngIf="selectedFile" matSuffix
mat-icon-button aria-label="Clear" (click)="selectedFile={}">
@@ -41,8 +41,8 @@
</mat-autocomplete>
</mat-form-field>
</div>
- <div *ngIf="!chooseExistingFile">
- <mat-form-field style="width: 95%" (click)="fileInput.click();"
*ngIf="!chooseExistingFile">
+ <div *ngIf="!chooseExistingFileControl.value">
+ <mat-form-field style="width: 95%" (click)="fileInput.click();"
*ngIf="!chooseExistingFileControl.value">
<input matInput placeholder="{{staticProperty.label}}"
disabled (value)="fileName">
<input #fileInput type="file" style="display:none;"
(change)="handleFileInput($event.target.files)">
diff --git
a/ui/src/app/core-ui/static-properties/static-file-input/static-file-input.component.ts
b/ui/src/app/core-ui/static-properties/static-file-input/static-file-input.component.ts
index 279d253..2519941 100644
---
a/ui/src/app/core-ui/static-properties/static-file-input/static-file-input.component.ts
+++
b/ui/src/app/core-ui/static-properties/static-file-input/static-file-input.component.ts
@@ -16,71 +16,88 @@
*
*/
-import {Component, EventEmitter, OnInit, Output} from '@angular/core';
-import {StaticPropertyUtilService} from '../static-property-util.service';
-import {StaticFileRestService} from './static-file-rest.service';
-import {HttpEventType, HttpResponse} from '@angular/common/http';
-import {AbstractStaticPropertyRenderer} from
"../base/abstract-static-property";
-import {FileStaticProperty} from "../../../core-model/gen/streampipes-model";
-import {FilesService} from "../../../platform-services/apis/files.service";
-import {FileMetadata} from "../../../core-model/gen/streampipes-model-client";
+import { Component, EventEmitter, OnInit, Output } from '@angular/core';
+import { StaticFileRestService } from './static-file-rest.service';
+import { HttpEventType, HttpResponse } from '@angular/common/http';
+import { FileStaticProperty } from '../../../core-model/gen/streampipes-model';
+import { FilesService } from '../../../platform-services/apis/files.service';
+import { FileMetadata } from
'../../../core-model/gen/streampipes-model-client';
+import { ConfigurationInfo } from '../../../connect/model/ConfigurationInfo';
+import { AbstractValidatedStaticPropertyRenderer } from
'../base/abstract-validated-static-property';
+import { FormControl, ValidatorFn, Validators } from '@angular/forms';
@Component({
- selector: 'app-static-file-input',
+ selector: 'sp-static-file-input',
templateUrl: './static-file-input.component.html',
styleUrls: ['./static-file-input.component.css']
})
-export class StaticFileInputComponent extends
AbstractStaticPropertyRenderer<FileStaticProperty> implements OnInit {
+export class StaticFileInputComponent extends
AbstractValidatedStaticPropertyRenderer<FileStaticProperty> implements OnInit {
- @Output() inputEmitter: EventEmitter<Boolean> = new
EventEmitter<Boolean>();
+ @Output() inputEmitter: EventEmitter<boolean> = new
EventEmitter<boolean>();
- chooseExistingFile: boolean = true;
+ public chooseExistingFileControl = new FormControl();
- inputValue: String;
- fileName: String;
+ // inputValue: string;
+ fileName: string;
selectedUploadFile: File;
- hasInput: Boolean;
- errorMessage = "Please enter a value";
+ hasInput: boolean;
+ errorMessage = 'Please enter a value';
uploadStatus = 0;
fileMetadata: FileMetadata[];
selectedFile: FileMetadata;
- filesLoaded: boolean = false;
+ filesLoaded = false;
- constructor(public staticPropertyUtil: StaticPropertyUtilService,
- private staticFileRestService: StaticFileRestService,
- private filesService: FilesService){
+ constructor(private staticFileRestService: StaticFileRestService,
+ private filesService: FilesService) {
super();
+
}
ngOnInit() {
this.fetchFileMetadata();
+ this.addValidator(this.staticProperty.locationPath,
this.collectValidators());
+ this.enableValidators();
+
+ this.chooseExistingFileControl.setValue(true);
+ }
+
+ collectValidators() {
+ const validators: ValidatorFn[] = [];
+ validators.push(Validators.required);
+
+ return validators;
}
fetchFileMetadata(internalFilenameToSelect?: any) {
this.filesService.getFileMetadata(this.staticProperty.requiredFiletypes).subscribe(fm
=> {
this.fileMetadata = fm;
if (internalFilenameToSelect) {
- this.chooseExistingFile = true;
this.selectedFile =
- this.fileMetadata.find(fm => fm.internalFilename ===
internalFilenameToSelect);
+ this.fileMetadata.find(fmi => fmi.internalFilename ===
internalFilenameToSelect);
this.selectOption(this.selectedFile);
this.emitUpdate(true);
+
this.parentForm.controls[this.fieldName].setValue(this.selectedFile);
+
+ this.chooseExistingFileControl.setValue(true);
} else if (this.staticProperty.locationPath) {
this.selectedFile =
- this.fileMetadata.find(fm => fm.internalFilename ===
this.staticProperty.locationPath);
+ this.fileMetadata.find(fmi => fmi.internalFilename ===
this.staticProperty.locationPath);
} else {
if (this.fileMetadata.length > 0) {
this.selectedFile = this.fileMetadata[0];
- this.staticProperty.locationPath =
this.selectedFile.internalFilename;
+ // this.staticProperty.locationPath =
this.selectedFile.internalFilename;
+ this.selectOption(this.selectedFile);
this.emitUpdate(true);
+
this.parentForm.controls[this.fieldName].setValue(this.selectedFile);
} else {
- this.chooseExistingFile = false;
+
+ this.chooseExistingFileControl.setValue(false);
}
}
this.filesLoaded = true;
@@ -98,10 +115,12 @@ export class StaticFileInputComponent extends
AbstractStaticPropertyRenderer<Fil
if (this.selectedUploadFile !== undefined) {
this.filesService.uploadFile(this.selectedUploadFile).subscribe(
event => {
- if (event.type == HttpEventType.UploadProgress) {
+ if (event.type === HttpEventType.UploadProgress) {
this.uploadStatus = Math.round(100 * event.loaded /
event.total);
} else if (event instanceof HttpResponse) {
- let internalFilename = event.body.internalFilename;
+ const internalFilename = event.body.internalFilename;
+
this.parentForm.controls[this.fieldName].setValue(internalFilename);
+ // this.fieldName = internalFilename;
this.fetchFileMetadata(internalFilename);
}
},
@@ -111,24 +130,22 @@ export class StaticFileInputComponent extends
AbstractStaticPropertyRenderer<Fil
}
}
- valueChange(inputValue) {
- this.inputValue = inputValue;
- if(inputValue == "" || !inputValue) {
- this.hasInput = false;
- }
- else{
- this.hasInput = true;
- }
-
- this.inputEmitter.emit(this.hasInput);
- }
-
selectOption(fileMetadata: FileMetadata) {
this.staticProperty.locationPath = fileMetadata.internalFilename;
+ const valid: boolean = (fileMetadata.internalFilename !== '' ||
fileMetadata.internalFilename !== undefined);
+ this.updateEmitter.emit(new
ConfigurationInfo(this.staticProperty.internalName, valid));
}
displayFn(fileMetadata: FileMetadata) {
- return fileMetadata ? fileMetadata.originalFilename : "";
+ return fileMetadata ? fileMetadata.originalFilename : '';
+ }
+
+ onStatusChange(status: any) {
+ }
+
+ onValueChange(value: any) {
+ this.staticProperty.locationPath = value.internalFilename;
+ this.parentForm.updateValueAndValidity();
}
-}
\ No newline at end of file
+}
diff --git
a/ui/src/app/core-ui/static-properties/static-property.component.html
b/ui/src/app/core-ui/static-properties/static-property.component.html
index 964413e..e5f40ba 100644
--- a/ui/src/app/core-ui/static-properties/static-property.component.html
+++ b/ui/src/app/core-ui/static-properties/static-property.component.html
@@ -47,12 +47,14 @@
(updateEmitter)="emitUpdate($event)">
</app-static-free-input>
- <app-static-file-input *ngIf="isFileStaticProperty(staticProperty)"
+ <sp-static-file-input *ngIf="isFileStaticProperty(staticProperty)"
(inputEmitter)="valueChange($event)"
[staticProperty]="staticProperty"
+ [parentForm]="parentForm"
+ [fieldName]="fieldName"
(updateEmitter)="emitUpdate($event)"
[adapterId]="adapterId">
- </app-static-file-input>
+ </sp-static-file-input>
<app-static-color-picker
*ngIf="isColorPickerStaticProperty(staticProperty)"
[staticProperty]="staticProperty"