This is an automated email from the ASF dual-hosted git repository. zehnder pushed a commit to branch STREAMPIPES-145 in repository https://gitbox.apache.org/repos/asf/incubator-streampipes.git
commit afb52bc7a0abe80fe012540e7be284b73524a9c4 Author: Philipp Zehnder <[email protected]> AuthorDate: Wed Jul 1 22:07:38 2020 +0200 [STREAMPIPES-145] Move event property dialog --- ui/src/app/connect/connect.module.ts | 4 +- .../edit-event-property-list.component.ts | 9 +- .../edit-event-property-primitive.component.html | 83 +++---------- .../edit-event-property-primitive.component.ts | 129 +++---------------- .../edit-event-property.component.html | 30 ++--- .../edit-event-property.component.ts | 19 ++- .../unit-transformation.component.css} | 50 ++++---- .../unit-transformation.component.html | 49 ++++++++ .../unit-transformation.component.ts | 137 +++++++++++++++++++++ 9 files changed, 272 insertions(+), 238 deletions(-) diff --git a/ui/src/app/connect/connect.module.ts b/ui/src/app/connect/connect.module.ts index e122740..42e0db5 100644 --- a/ui/src/app/connect/connect.module.ts +++ b/ui/src/app/connect/connect.module.ts @@ -92,6 +92,7 @@ import {MatSliderModule} from "@angular/material/slider"; import { QuillModule } from 'ngx-quill' import {MatChipsModule} from "@angular/material/chips"; import { EditEventPropertyComponent } from './dialog/edit-event-property/edit-event-property.component'; +import { UnitTransformationComponent } from './dialog/unit-transformation/unit-transformation.component'; @NgModule({ @@ -154,7 +155,8 @@ import { EditEventPropertyComponent } from './dialog/edit-event-property/edit-ev StaticAlternativesComponent, StaticCollectionComponent, StaticColorPickerComponent, - PipelineElementRuntimeInfoComponent + PipelineElementRuntimeInfoComponent, + UnitTransformationComponent ], providers: [ RestService, diff --git a/ui/src/app/connect/dialog/edit-event-property-list/edit-event-property-list.component.ts b/ui/src/app/connect/dialog/edit-event-property-list/edit-event-property-list.component.ts index 87238c2..24e07b4 100644 --- a/ui/src/app/connect/dialog/edit-event-property-list/edit-event-property-list.component.ts +++ b/ui/src/app/connect/dialog/edit-event-property-list/edit-event-property-list.component.ts @@ -16,13 +16,12 @@ * */ -import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core'; -import {DataTypesService} from '../../schema-editor/data-type.service'; -import {EventProperty} from "../../../core-model/gen/streampipes-model"; - +import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; +import { EventProperty } from '../../../core-model/gen/streampipes-model'; +import { DataTypesService } from '../../schema-editor/data-type.service'; @Component({ - selector: 'app-event-property-list', + selector: 'sp-edit-event-property-list', templateUrl: './edit-event-property-list.component.html', styleUrls: ['./edit-event-property-list.component.css'] }) diff --git a/ui/src/app/connect/dialog/edit-event-property-primitive/edit-event-property-primitive.component.html b/ui/src/app/connect/dialog/edit-event-property-primitive/edit-event-property-primitive.component.html index db7780f..9a08e38 100644 --- a/ui/src/app/connect/dialog/edit-event-property-primitive/edit-event-property-primitive.component.html +++ b/ui/src/app/connect/dialog/edit-event-property-primitive/edit-event-property-primitive.component.html @@ -18,7 +18,7 @@ <div class="divBorder"> <mat-form-field class="doubleWidth"> - <mat-select placeholder="Runtime Type" [(ngModel)]="property.runtimeType" + <mat-select placeholder="Runtime Type" [(ngModel)]="cachedProperty.runtimeType" [disabled]="isTimestampProperty"> <mat-option *ngFor="let dataType of runtimeDataTypes" [value]="dataType.url"> {{ dataType.label }} @@ -26,60 +26,18 @@ </mat-select> </mat-form-field> - <!-- TODO FIX this --> - <!--<form [formGroup]="propertyPrimitivForm " novalidate>--> - <!--<div fxLayout="row" fxLayoutAlign="start">--> - <!--<div class="form-group">--> - <!--<select class="form-controll" formControlName="dataType">--> - <!--<mat-error *ngIf="propertyForm.controls['dataType'].errors?.required && propertyForm.controls['dataType'].touched">--> - <!--DataTypey is <strong>required</strong>--> - <!--</mat-error>--> - <!--<option *ngFor="let dataType of dataTypes" [value]="dataType">{{dataType}}</option>--> - <!--</select>--> - <!--</div>--> - <!--</div>--> - <!----> - <!--</form>--> - - - <div fxLayout="row" fxLayoutAlign="start" *ngIf="!isTimestampProperty"> - <div class="form-group" fxFlexAlign="center" style="width: 155px"> - <mat-form-field *ngIf="!hadMeasarumentUnit" class="example-full-width" style="width: 155px"> - <input matInput placeholder="Unit" [matAutocomplete]="auto" [formControl]="stateCtrl" - [attr.disabled]="transformUnitEnable ? '' : null"> - <mat-autocomplete #auto="matAutocomplete" [displayWith]="displayFn"> - <mat-option *ngFor="let unit of filteredUnits | async" [value]="unit.label"> - {{unit.label}} - </mat-option> - </mat-autocomplete> - </mat-form-field> - <mat-form-field *ngIf="hadMeasarumentUnit" class="example-full-width" style="width: 155px"> - <input matInput placeholder="Unit" disabled [(ngModel)]="oldMeasurementUnitDipsplay"> - </mat-form-field> - - </div> - <button mat-button (click)="transformUnit()" color="primary" class="form-group" fxFlexAlign="center" - style="min-width: 60px; max-width: 60px"> - <mat-icon *ngIf="!transformUnitEnable">arrow_forward</mat-icon> - <mat-icon *ngIf="transformUnitEnable" style="transform: rotate(180deg)">arrow_forward</mat-icon> - </button> - <mat-form-field class="example-full-width" style="width: 155px" *ngIf="transformUnitEnable"> - <mat-select placeholder="New Unit" [(ngModel)]="selectUnit" [formControl]="newUnitStateCtrl"[compareWith]="compareFn"> - <mat-option *ngFor="let unit of possibleUnitTransformations" [value]="unit" - (click)="changeTargetUnit(unit)"> - {{unit.label}} - </mat-option> - </mat-select> - </mat-form-field> - </div> + <sp-unit-transformation + [cachedProperty]= "cachedProperty" + [showUnitTransformation]="!isTimestampProperty"> + </sp-unit-transformation> <div fxLayout="row" fxLayoutAlign="start" *ngIf="isTimestampProperty"> <div class="form-group" fxFlexAlign="center"> - <mat-form-field [class.example-full-width]="property.timestampTransformationMode !== undefined " - style="margin-right: 10px" [class.doubleWidth]="property.timestampTransformationMode === undefined" - [class.aThirdWidth]="selectedTimeMultiplier === 'custom' && property.timestampTransformationMode === 'timeUnit'"> + <mat-form-field [class.example-full-width]="cachedProperty.timestampTransformationMode !== undefined " + style="margin-right: 10px" [class.doubleWidth]="cachedProperty.timestampTransformationMode === undefined" + [class.aThirdWidth]="selectedTimeMultiplier === 'custom' && cachedProperty.timestampTransformationMode === 'timeUnit'"> <mat-select placeholder="Timestamp converter (unix timestamp)" - [(value)]="property.timestampTransformationMode"> + [(value)]="cachedProperty.timestampTransformationMode"> <mat-option>None</mat-option> <mat-option value="formatString">Date String</mat-option> <mat-option value="timeUnit">Date Number</mat-option> @@ -87,37 +45,26 @@ </mat-form-field> </div> <div class="form-group" fxFlexAlign="center"> - <mat-form-field *ngIf="property.timestampTransformationMode === 'formatString'"> + <mat-form-field *ngIf="cachedProperty.timestampTransformationMode === 'formatString'"> <input matInput placeholder="E.g. yyyy-MM-dd HH:mm:ss.SSSZ" - [(ngModel)]="property.timestampTransformationFormatString"> + [(ngModel)]="cachedProperty.timestampTransformationFormatString"> </mat-form-field> - <mat-form-field *ngIf="property.timestampTransformationMode === 'timeUnit'" + <mat-form-field *ngIf="cachedProperty.timestampTransformationMode === 'timeUnit'" [class.example-full-width]="selectedTimeMultiplier !== 'custom'" [class.aThirdWidth]="selectedTimeMultiplier === 'custom'"> <mat-select placeholder="Current time unit" [(value)]="selectedTimeMultiplier"> - <mat-option value="milliseconds" (click)="property.timestampTransformationMultiplier = 0"> + <mat-option value="milliseconds" (click)="cachedProperty.timestampTransformationMultiplier = 0"> Milliseconds</mat-option> - <mat-option value="second" (click)="property.timestampTransformationMultiplier = 1000">Seconds + <mat-option value="second" (click)="cachedProperty.timestampTransformationMultiplier = 1000">Seconds </mat-option> - <!-- More transformation Options, there is any use case for them? - <mat-option value="minutes" (click)="property.timestampTransformationMultiplier = 60000">Minutes</mat-option> - <mat-option value="hours" (click)="property.timestampTransformationMultiplier = 3600000">Hours</mat-option> - <mat-option value="days" (click)="property.timestampTransformationMultiplier = 86400000">Days</mat-option> - <mat-option value="custom" ><i>Custom</i></mat-option> - --> </mat-select> </mat-form-field> - <!-- To set custom time transformation multiplier -> If use: set multiplier to event - <mat-form-field class="aThirdWidth" *ngIf="selectedTimeMultiplier === 'custom' && property.timestampTransformationMode === 'timeUnit'"> - <input matInput placeholder="Set multiplier" type="number"> - </mat-form-field> - --> </div> </div> <mat-form-field *ngIf="staticValueAddedByUser()" class="doubleWidth"> <input matInput placeholder="Static Value" name="static_value" id="static_value" [matAutocomplete]="auto" - [(ngModel)]="property.staticValue"> + [(ngModel)]="cachedProperty.staticValue"> </mat-form-field> </div> \ No newline at end of file diff --git a/ui/src/app/connect/dialog/edit-event-property-primitive/edit-event-property-primitive.component.ts b/ui/src/app/connect/dialog/edit-event-property-primitive/edit-event-property-primitive.component.ts index 9d535f6..3d340a8 100644 --- a/ui/src/app/connect/dialog/edit-event-property-primitive/edit-event-property-primitive.component.ts +++ b/ui/src/app/connect/dialog/edit-event-property-primitive/edit-event-property-primitive.component.ts @@ -16,20 +16,18 @@ * */ -import {Component, DoCheck, EventEmitter, Input, OnInit, Output} from '@angular/core'; -import {Observable, Subscription} from 'rxjs'; -import {FormBuilder, FormControl, FormGroup} from '@angular/forms'; -import {DataTypesService} from '../../schema-editor/data-type.service'; -import {DomainPropertyProbabilityList} from '../../schema-editor/model/DomainPropertyProbabilityList'; -import {ShepherdService} from '../../../services/tour/shepherd.service'; -import {RestService} from '../../rest.service'; -import {UnitDescription} from '../../model/UnitDescription'; -import {UnitProviderService} from '../../schema-editor/unit-provider.service'; -import {map, startWith} from 'rxjs/operators'; -import {EventProperty} from "../../../core-model/gen/streampipes-model"; +import { Component, DoCheck, EventEmitter, Input, OnInit, Output } from '@angular/core'; +import { FormBuilder } from '@angular/forms'; +import { Subscription } from 'rxjs'; +import { EventProperty } from '../../../core-model/gen/streampipes-model'; +import { ShepherdService } from '../../../services/tour/shepherd.service'; +import { RestService } from '../../rest.service'; +import { DataTypesService } from '../../schema-editor/data-type.service'; +import { DomainPropertyProbabilityList } from '../../schema-editor/model/DomainPropertyProbabilityList'; +import { UnitProviderService } from '../../schema-editor/unit-provider.service'; @Component({ - selector: 'app-event-property-primitive', + selector: 'sp-edit-event-property-primitive', templateUrl: './edit-event-property-primitive.component.html', styleUrls: ['./edit-event-property-primitive.component.css'] }) @@ -37,7 +35,7 @@ export class EditEventPropertyPrimitiveComponent implements OnInit, DoCheck { soTimestamp = 'http://schema.org/DateTime'; - @Input() property: any; + @Input() cachedProperty: any; @Input() index: number; @Input() domainPropertyGuess: DomainPropertyProbabilityList; @@ -47,20 +45,8 @@ export class EditEventPropertyPrimitiveComponent implements OnInit, DoCheck { @Output() addPrimitive: EventEmitter<EventProperty> = new EventEmitter<EventProperty>(); @Output() addNested: EventEmitter<any> = new EventEmitter<any>(); - private propertyPrimitivForm: FormGroup; runtimeDataTypes; - private transformUnitEnable = false; - private possibleUnitTransformations: UnitDescription[] = []; - private selectUnit: UnitDescription; - private allUnits: UnitDescription[]; - private stateCtrl = new FormControl(); - - private newUnitStateCtrl = new FormControl(); - private filteredUnits: Observable<UnitDescription[]>; - private hadMesarumentUnit = false; - private oldMeasurementUnitDipsplay; - private selectedTimeMultiplier; isTimestampProperty: boolean; @@ -75,15 +61,8 @@ export class EditEventPropertyPrimitiveComponent implements OnInit, DoCheck { this.runtimeDataTypes = this.dataTypeService.getDataTypes(); - this.allUnits = this.unitProviderService.getUnits(); - this.filteredUnits = this.stateCtrl.valueChanges - .pipe( - startWith(''), - map(unit => unit ? this._filteredUnits(unit) : this.allUnits.slice()) - ); - // Set preselected value - this.selectedTimeMultiplier = "second"; + this.selectedTimeMultiplier = 'second'; } protected open = false; @@ -91,96 +70,20 @@ export class EditEventPropertyPrimitiveComponent implements OnInit, DoCheck { ngOnInit() { - // this.property.propertyNumber = this.index; - this.isTimestampProperty = this.property.domainProperties.some(dp => dp === this.soTimestamp); - if ((this.property as any).measurementUnitTmp !== undefined) { - (this.property as any).oldMeasurementUnit = (this.property as any).oldMeasurementUnit; - // TODO: use if backend deserialize URI correct - (this.property as any).measurementUnitTmp = (this.property as any).measurementUnitTmp; - this.hadMesarumentUnit = (this.property as any).hadMeasarumentUnit; - this.transformUnitEnable = (this.property as any).hadMeasarumentUnit; - const unit = this.allUnits.find(unitTmp => unitTmp.resource === (this.property as any).oldMeasurementUnit); - this.oldMeasurementUnitDipsplay = unit.label; - this.stateCtrl.setValue(unit.label); - - this.restService.getFittingUnits(unit).subscribe(result => { - this.possibleUnitTransformations = result; - // this.selectUnit = this.possibleUnitTransformations[0]; - this.selectUnit = this.allUnits.find(unitTmp => unitTmp.resource === (this.property as any).measurementUnitTmp); - this.transformUnitEnable = true - this.changeTargetUnit(this.selectUnit); - }); - // const newUnit = this.allUnits.find(unitTmp => unitTmp.resource === this.property.measurementUnitTmp); - // this.newUnitStateCtrl.setValue(newUnit); - // this.selectUnit = newUnit; - } - (this.property as any).timestampTransformationMultiplier = 1000; - + this.isTimestampProperty = this.cachedProperty.domainProperties.some(dp => dp === this.soTimestamp); + (this.cachedProperty as any).timestampTransformationMultiplier = 1000; } - compareFn(c1: any, c2:any): boolean { - return c1 && c2 ? c1.resource === c2.resource : c1 === c2; - } - ngDoCheck() { - (this.property as any).propertyNumber = this.index; - } - - private transformUnit() { - if (this.transformUnitEnable) { - this.transformUnitEnable = false; - // TODO: use if backend deserialize URI correct - // this.property.measurementUnit = this.property.oldMeasurementUnit; - (this.property as any).measurementUnitTmp = (this.property as any).oldMeasurementUnit; - (this.property as any).hadMeasarumentUnit = false; - } else { - const unit = this.allUnits.find(unitTmp => unitTmp.label === this.stateCtrl.value); - (this.property as any).hadMeasarumentUnit = true; - if (!unit) { - return; - } - - this.restService.getFittingUnits(unit).subscribe(result => { - this.possibleUnitTransformations = result; - this.selectUnit = this.possibleUnitTransformations[0]; - this.transformUnitEnable = true - this.changeTargetUnit(this.selectUnit); - }); - } - } - - private _filteredUnits(value: string): UnitDescription[] { - const filterValue = value.toLowerCase(); - const units: UnitDescription[] = this.allUnits.filter(unit => unit.label.toLowerCase().indexOf(filterValue) === 0); - const unit: UnitDescription = this.allUnits.filter(unit => unit.label.toLocaleLowerCase() === filterValue)[0]; - if (unit !== undefined) { - (this.property as any).oldMeasurementUnit = unit.resource; - (this.property as any).measurementUnitTmp = unit.resource; - // TODO: use if backend deserialize URI correct - // this.property.measurementUnit = units.resource; - } else { - (this.property as any).oldMeasurementUnit = undefined; - (this.property as any).measurementUnitTmp = undefined; - // TODO: use if backend deserialize URI correct - // this.property.measurementUnit = undefined; - } - return units; - } - - changeTargetUnit(unit: UnitDescription) { - // TODO: use if backend deserialize URI correct - // this.property.measurementUnit = unit.resource; - (this.property as any).measurementUnitTmp = unit.resource; - this.newUnitStateCtrl.setValue(unit); + (this.cachedProperty as any).propertyNumber = this.index; } staticValueAddedByUser() { - if (this.property.elementId.startsWith('http://eventProperty.de/staticValue/')) { + if (this.cachedProperty.elementId.startsWith('http://eventProperty.de/staticValue/')) { return true; } else { return false; } - } } diff --git a/ui/src/app/connect/dialog/edit-event-property/edit-event-property.component.html b/ui/src/app/connect/dialog/edit-event-property/edit-event-property.component.html index ddffa81..cb7962b 100644 --- a/ui/src/app/connect/dialog/edit-event-property/edit-event-property.component.html +++ b/ui/src/app/connect/dialog/edit-event-property/edit-event-property.component.html @@ -35,8 +35,16 @@ <div class="form-group"> <mat-form-field class="doubleWidth"> + <!-- <input matInput placeholder="Description" name="description" id="description" [(ngModel)]="property.description"> --> + <textarea matInput name="description" placeholder="Description" id="description" + [(ngModel)]="cachedProperty.description" cols="20" rows="2"></textarea> + </mat-form-field> + </div> + + <div class="form-group"> + <mat-form-field class="doubleWidth"> <input matInput placeholder="Domain Property" class="dmainProperty" name="domainproperty" id="domainproperty" - [(ngModel)]="cachedProperty.domainProperties[0]"> + [(ngModel)]="cachedProperty.domainProperties[0]"> </mat-form-field> <div *ngIf="!isEventPropertyNested"> <mat-checkbox name="timestampCheckbox" @@ -45,25 +53,17 @@ </mat-checkbox> </div> </div> - - <div class="form-group"> - <mat-form-field class="doubleWidth"> - <!-- <input matInput placeholder="Description" name="description" id="description" [(ngModel)]="property.description"> --> - <textarea matInput name="description" placeholder="Description" id="description" - [(ngModel)]="cachedProperty.description" cols="20" rows="2"></textarea> - - </mat-form-field> - </div> </form> <div *ngIf="isEventPropertyPrimitive"> - <app-event-property-primitive [isEditable]="isEditable" - [property]="cachedProperty"> - </app-event-property-primitive> + <sp-edit-event-property-primitive + [isEditable]="isEditable" + [cachedProperty]="cachedProperty"> + </sp-edit-event-property-primitive> </div> <div *ngIf="isEventPropertyList"> - <app-event-property-list [isEditable]="isEditable" [property]="cachedProperty"> - </app-event-property-list> + <sp-edit-event-property-list [isEditable]="isEditable" [property]="cachedProperty"> + </sp-edit-event-property-list> </div> </mat-dialog-content> diff --git a/ui/src/app/connect/dialog/edit-event-property/edit-event-property.component.ts b/ui/src/app/connect/dialog/edit-event-property/edit-event-property.component.ts index 179de53..9e15af2 100644 --- a/ui/src/app/connect/dialog/edit-event-property/edit-event-property.component.ts +++ b/ui/src/app/connect/dialog/edit-event-property/edit-event-property.component.ts @@ -16,20 +16,20 @@ * */ -import {Component, EventEmitter, Inject, OnInit, Output} from '@angular/core'; -import {FormBuilder, FormGroup, Validators} from '@angular/forms'; -import {MAT_DIALOG_DATA, MatDialogRef} from '@angular/material/dialog'; -import {DataTypesService} from '../../schema-editor/data-type.service'; +import { Component, EventEmitter, Inject, OnInit, Output } from '@angular/core'; +import { FormBuilder, FormGroup, Validators } from '@angular/forms'; +import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; import { EventPropertyList, EventPropertyNested, EventPropertyPrimitive, EventPropertyUnion -} from "../../../core-model/gen/streampipes-model"; +} from '../../../core-model/gen/streampipes-model'; +import { DataTypesService } from '../../schema-editor/data-type.service'; @Component({ - selector: 'app-event-property', + selector: 'sp-edit-event-property', templateUrl: './edit-event-property.component.html', styleUrls: ['./edit-event-property.component.css'] }) @@ -43,18 +43,17 @@ export class EditEventPropertyComponent implements OnInit { property: any; isEditable: boolean; - isTimestampProperty: boolean = false; + isTimestampProperty = false; isEventPropertyPrimitive: boolean; isEventPropertyNested: boolean; isEventPropertyList: boolean; private propertyForm: FormGroup; - // protected dataTypes = dataTypes; private runtimeDataTypes; constructor(@Inject(MAT_DIALOG_DATA) public data: any, - private dialogRef: MatDialogRef<EventPropertyComponent>, + private dialogRef: MatDialogRef<EditEventPropertyComponent>, private formBuilder: FormBuilder, private dataTypeService: DataTypesService) { } @@ -121,7 +120,7 @@ export class EditEventPropertyComponent implements OnInit { (this.property as any).measurementUnitTmp = (this.cachedProperty as any).measurementUnitTmp; (this.property as any).oldMeasurementUnit = (this.cachedProperty as any).oldMeasurementUnit; - (this.property as any).hadMeasarumentUnit = (this.cachedProperty as any).hadMeasarumentUnit;; + (this.property as any).hadMeasarumentUnit = (this.cachedProperty as any).hadMeasarumentUnit; (this.property as any).timestampTransformationMode = (this.cachedProperty as any).timestampTransformationMode; (this.property as any).timestampTransformationFormatString = (this.cachedProperty as any).timestampTransformationFormatString; diff --git a/ui/src/app/connect/dialog/edit-event-property-list/edit-event-property-list.component.ts b/ui/src/app/connect/dialog/unit-transformation/unit-transformation.component.css similarity index 50% copy from ui/src/app/connect/dialog/edit-event-property-list/edit-event-property-list.component.ts copy to ui/src/app/connect/dialog/unit-transformation/unit-transformation.component.css index 87238c2..1c1657f 100644 --- a/ui/src/app/connect/dialog/edit-event-property-list/edit-event-property-list.component.ts +++ b/ui/src/app/connect/dialog/unit-transformation/unit-transformation.component.css @@ -16,31 +16,29 @@ * */ -import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core'; -import {DataTypesService} from '../../schema-editor/data-type.service'; -import {EventProperty} from "../../../core-model/gen/streampipes-model"; - - -@Component({ - selector: 'app-event-property-list', - templateUrl: './edit-event-property-list.component.html', - styleUrls: ['./edit-event-property-list.component.css'] -}) -export class EditEventPropertyListComponent implements OnInit { - - constructor(private dataTypeService: DataTypesService) { } - - - @Input() property: any; - @Input() index: number; - - runtimeDataTypes; - - @Input() isEditable: boolean; - - @Output() delete: EventEmitter<EventProperty> = new EventEmitter<EventProperty>(); +.header { + border-left: thin; +} +.container { + border: dotted; +} +.doubleWidth { + width: 370px !important; +} +.divBorder { + /* margin: auto; */ + width: 380px; + /* border: solid #ccc 2px; + border-radius: 5px; */ +} - ngOnInit() { - this.runtimeDataTypes = this.dataTypeService.getDataTypes(); - } +.aThirdWidth { + width: 120px !important; +} +.onhover:hover { + background-color: darkgrey; } + +::ng-deep .cdk-overlay-pane { + width: auto !important; +} \ No newline at end of file diff --git a/ui/src/app/connect/dialog/unit-transformation/unit-transformation.component.html b/ui/src/app/connect/dialog/unit-transformation/unit-transformation.component.html new file mode 100644 index 0000000..46a559b --- /dev/null +++ b/ui/src/app/connect/dialog/unit-transformation/unit-transformation.component.html @@ -0,0 +1,49 @@ +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one or more + ~ contributor license agreements. See the NOTICE file distributed with + ~ this work for additional information regarding copyright ownership. + ~ The ASF licenses this file to You under the Apache License, Version 2.0 + ~ (the "License"); you may not use this file except in compliance with + ~ the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + ~ + --> + +<div fxLayout="row" fxLayoutAlign="start" *ngIf="showUnitTransformation"> + <div class="form-group" fxFlexAlign="center" style="width: 155px"> + <mat-form-field *ngIf="!hadMeasarumentUnit" class="example-full-width" style="width: 155px"> + <input matInput placeholder="Unit" [matAutocomplete]="auto" [formControl]="stateCtrl" + [attr.disabled]="transformUnitEnable ? '' : null"> + <mat-autocomplete #auto="matAutocomplete" [displayWith]="displayFn"> + <mat-option *ngFor="let unit of filteredUnits | async" [value]="unit.label"> + {{unit.label}} + </mat-option> + </mat-autocomplete> + </mat-form-field> + <mat-form-field *ngIf="hadMeasarumentUnit" class="example-full-width" style="width: 155px"> + <input matInput placeholder="Unit" disabled [(ngModel)]="oldMeasurementUnitDipsplay"> + </mat-form-field> + + </div> + <button mat-button (click)="transformUnit()" color="primary" class="form-group" fxFlexAlign="center" + style="min-width: 60px; max-width: 60px"> + <mat-icon *ngIf="!transformUnitEnable">arrow_forward</mat-icon> + <mat-icon *ngIf="transformUnitEnable" style="transform: rotate(180deg)">arrow_forward</mat-icon> + </button> + <mat-form-field class="example-full-width" style="width: 155px" *ngIf="transformUnitEnable"> + <mat-select placeholder="New Unit" [(ngModel)]="selectUnit" [formControl]="newUnitStateCtrl"[compareWith]="compareFn"> + <mat-option *ngFor="let unit of possibleUnitTransformations" [value]="unit" + (click)="changeTargetUnit(unit)"> + {{unit.label}} + </mat-option> + </mat-select> + </mat-form-field> +</div> + diff --git a/ui/src/app/connect/dialog/unit-transformation/unit-transformation.component.ts b/ui/src/app/connect/dialog/unit-transformation/unit-transformation.component.ts new file mode 100644 index 0000000..b8cf3c9 --- /dev/null +++ b/ui/src/app/connect/dialog/unit-transformation/unit-transformation.component.ts @@ -0,0 +1,137 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +import { Component, Input, OnInit } from '@angular/core'; +import { FormBuilder, FormControl } from '@angular/forms'; +import { Observable } from 'rxjs'; +import { map, startWith } from 'rxjs/operators'; +import { UnitDescription } from '../../model/UnitDescription'; +import { RestService } from '../../rest.service'; +import { UnitProviderService } from '../../schema-editor/unit-provider.service'; + +@Component({ + selector: 'sp-unit-transformation', + templateUrl: './unit-transformation.component.html', + styleUrls: ['./unit-transformation.component.css'] +}) +export class UnitTransformationComponent implements OnInit { + + @Input() cachedProperty: any; + @Input() showUnitTransformation: boolean; + + private transformUnitEnable = false; + private possibleUnitTransformations: UnitDescription[] = []; + private selectUnit: UnitDescription; + private allUnits: UnitDescription[]; + private stateCtrl = new FormControl(); + + private newUnitStateCtrl = new FormControl(); + private filteredUnits: Observable<UnitDescription[]>; + private hadMesarumentUnit = false; + private oldMeasurementUnitDipsplay; + + constructor(private formBuilder: FormBuilder, + private restService: RestService, + private unitProviderService: UnitProviderService) { + + this.allUnits = this.unitProviderService.getUnits(); + this.filteredUnits = this.stateCtrl.valueChanges + .pipe( + startWith(''), + map(unit => unit ? this._filteredUnits(unit) : this.allUnits.slice()) + ); + } + + protected open = false; + + + ngOnInit() { + // this.cachedProperty.propertyNumber = this.index; + if ((this.cachedProperty as any).measurementUnitTmp !== undefined) { + (this.cachedProperty as any).oldMeasurementUnit = (this.cachedProperty as any).oldMeasurementUnit; + // TODO: use if backend deserialize URI correct + (this.cachedProperty as any).measurementUnitTmp = (this.cachedProperty as any).measurementUnitTmp; + this.hadMesarumentUnit = (this.cachedProperty as any).hadMeasarumentUnit; + this.transformUnitEnable = (this.cachedProperty as any).hadMeasarumentUnit; + const unit = this.allUnits.find(unitTmp => unitTmp.resource === (this.cachedProperty as any).oldMeasurementUnit); + this.oldMeasurementUnitDipsplay = unit.label; + this.stateCtrl.setValue(unit.label); + + this.restService.getFittingUnits(unit).subscribe(result => { + this.possibleUnitTransformations = result; + // this.selectUnit = this.possibleUnitTransformations[0]; + this.selectUnit = this.allUnits.find(unitTmp => unitTmp.resource === (this.cachedProperty as any).measurementUnitTmp); + this.transformUnitEnable = true; + this.changeTargetUnit(this.selectUnit); + }); + } + } + + compareFn(c1: any, c2: any): boolean { + return c1 && c2 ? c1.resource === c2.resource : c1 === c2; + } + + private transformUnit() { + if (this.transformUnitEnable) { + this.transformUnitEnable = false; + // TODO: use if backend deserialize URI correct + // this.cachedProperty.measurementUnit = this.cachedProperty.oldMeasurementUnit; + (this.cachedProperty as any).measurementUnitTmp = (this.cachedProperty as any).oldMeasurementUnit; + (this.cachedProperty as any).hadMeasarumentUnit = false; + } else { + const unit = this.allUnits.find(unitTmp => unitTmp.label === this.stateCtrl.value); + (this.cachedProperty as any).hadMeasarumentUnit = true; + if (!unit) { + return; + } + + this.restService.getFittingUnits(unit).subscribe(result => { + this.possibleUnitTransformations = result; + this.selectUnit = this.possibleUnitTransformations[0]; + this.transformUnitEnable = true; + this.changeTargetUnit(this.selectUnit); + }); + } + } + + private _filteredUnits(value: string): UnitDescription[] { + const filterValue = value.toLowerCase(); + const units: UnitDescription[] = this.allUnits.filter(unit => unit.label.toLowerCase().indexOf(filterValue) === 0); + const unit: UnitDescription = this.allUnits.filter(unit => unit.label.toLocaleLowerCase() === filterValue)[0]; + if (unit !== undefined) { + (this.cachedProperty as any).oldMeasurementUnit = unit.resource; + (this.cachedProperty as any).measurementUnitTmp = unit.resource; + // TODO: use if backend deserialize URI correct + // this.cachedProperty.measurementUnit = units.resource; + } else { + (this.cachedProperty as any).oldMeasurementUnit = undefined; + (this.cachedProperty as any).measurementUnitTmp = undefined; + // TODO: use if backend deserialize URI correct + // this.cachedProperty.measurementUnit = undefined; + } + return units; + } + + changeTargetUnit(unit: UnitDescription) { + // TODO: use if backend deserialize URI correct + // this.cachedProperty.measurementUnit = unit.resource; + (this.cachedProperty as any).measurementUnitTmp = unit.resource; + this.newUnitStateCtrl.setValue(unit); + } +} +
