diff --git a/src/app/form-builder/gridster/gridster-datafield/gridster-data-field.component.ts b/src/app/form-builder/gridster/gridster-datafield/gridster-data-field.component.ts
index 5d5d497..c8c1dfe 100644
--- a/src/app/form-builder/gridster/gridster-datafield/gridster-data-field.component.ts
+++ b/src/app/form-builder/gridster/gridster-datafield/gridster-data-field.component.ts
@@ -6,6 +6,7 @@ import {GridsterFieldToEngineFieldService} from '../../../modeler/gridster-field
import {Subscription} from 'rxjs';
import moment from 'moment';
import {DataField, EnumerationField, MultichoiceField} from '@netgrif/components-core';
+import {FieldListService} from '../../field-list/field-list.service';
@Component({
selector: 'nab-gridster-datafield',
@@ -20,7 +21,9 @@ export class GridsterDataFieldComponent implements OnInit, OnDestroy {
engineField: DataField
;
private _gridsterSubscription: Subscription;
- constructor(private _gridsterService: GridsterService, private _transformService: GridsterFieldToEngineFieldService) {
+ constructor(private _gridsterService: GridsterService,
+ private _transformService: GridsterFieldToEngineFieldService,
+ public fieldListService: FieldListService) {
}
ngOnDestroy(): void {
diff --git a/src/app/form-builder/gridster/gridster.service.ts b/src/app/form-builder/gridster/gridster.service.ts
index c45ac97..5406d3a 100644
--- a/src/app/form-builder/gridster/gridster.service.ts
+++ b/src/app/form-builder/gridster/gridster.service.ts
@@ -18,7 +18,7 @@ import {
DataType,
DataVariable,
Expression, I18nWithDynamic,
- LayoutType,
+ LayoutType, Property,
Template,
Transition,
TransitionLayout
@@ -26,7 +26,7 @@ import {
import {BehaviorSubject, ReplaySubject, Subject} from 'rxjs';
import {DataFieldUtils} from '../data-field-utils';
import {SelectedTransitionService} from '../../modeler/selected-transition.service';
-import {FieldListService} from '../field-list/field-list.service';
+import {ComponentDef, FieldListService, PropertyDef} from '../field-list/field-list.service';
import {ModelerConfig} from '../../modeler/modeler-config';
import {debounceTime} from 'rxjs/operators';
@@ -196,7 +196,7 @@ export class GridsterService {
return dataVariable;
}
- public addDataRef(dataVariable: DataVariable, componentRows: number, componentCols: number, componentName: string, item: GridsterItem) {
+ public addDataRef(dataVariable: DataVariable, componentRows: number, componentCols: number, componentName: string, item: GridsterItem): DataRef {
const dataRef = new DataRef(dataVariable.id);
dataRef.layout.x = item.x;
dataRef.layout.y = item.y;
@@ -241,12 +241,20 @@ export class GridsterService {
}
private addNewDataRef(data: DataVariable, event: DragEvent, item: GridsterItem): DataRef {
- return this.addDataRef(
+ const newDataRef = this.addDataRef(
data,
+event.dataTransfer.getData('rows'),
+event.dataTransfer.getData('cols'),
event.dataTransfer.getData('ref_component'),
item);
+ const properties: Array = JSON.parse(event.dataTransfer.getData('properties'));
+ if (!!properties) {
+ for (const property of properties) {
+ newDataRef.component.properties.push(new Property(property.name, property.defaultValue));
+ }
+ }
+ this.options.api.optionsChanged();
+ return newDataRef;
}
private createId(type: string) {
diff --git a/src/app/modeler/data-mode/data-detail/data-detail.component.html b/src/app/modeler/data-mode/data-detail/data-detail.component.html
index fcbb243..8bd0376 100644
--- a/src/app/modeler/data-mode/data-detail/data-detail.component.html
+++ b/src/app/modeler/data-mode/data-detail/data-detail.component.html
@@ -98,8 +98,13 @@
Component Name
-
+
+
+
+ {{componentDef.title}}
+
+
@@ -111,7 +116,12 @@
Key
+ [value]="property.key" [matAutocomplete]="propertyAutocomplete">
+
+
+ {{propertyDef.name}}
+
+
Value
diff --git a/src/app/modeler/data-mode/data-detail/data-detail.component.ts b/src/app/modeler/data-mode/data-detail/data-detail.component.ts
index 42aa612..4c3f60e 100644
--- a/src/app/modeler/data-mode/data-detail/data-detail.component.ts
+++ b/src/app/modeler/data-mode/data-detail/data-detail.component.ts
@@ -25,6 +25,12 @@ import {HistoryService} from '../../services/history/history.service';
import {Observable} from 'rxjs';
import {map, startWith, tap} from 'rxjs/operators';
import {ModelerUtils} from '../../modeler-utils';
+import {
+ ComponentDef,
+ DataRefDef,
+ FieldListService,
+ PropertyDef
+} from '../../../form-builder/field-list/field-list.service';
import {MatAutocompleteSelectedEvent} from '@angular/material/autocomplete';
import {MatChipInputEvent} from '@angular/material/chips';
@@ -47,6 +53,7 @@ export class DataDetailComponent implements OnDestroy {
counterEnumMap = 0;
formControlRef: FormControl;
+ componentNameFormCtrl: FormControl;
transitionOptions: Array;
filteredOptions: Observable>;
typeArray: Array = [
@@ -75,6 +82,7 @@ export class DataDetailComponent implements OnDestroy {
public constructor(
private _masterService: DataMasterDetailService,
private _modelService: ModelService,
+ private _fieldListService: FieldListService,
private dialog: MatDialog,
private _router: Router,
private _actionMode: ActionsModeService,
@@ -82,6 +90,7 @@ export class DataDetailComponent implements OnDestroy {
private _historyService: HistoryService
) {
this.formControlRef = new FormControl();
+ this.componentNameFormCtrl = new FormControl();
this.transitionOptions = this.createTransOptions();
this._masterService.getSelected$().subscribe(obj => {
if (this.historyDataSave?.save) {
@@ -147,7 +156,7 @@ export class DataDetailComponent implements OnDestroy {
});
}
- setValue($event, variable: string, index?: number): void {
+ public setValue($event, variable: string, index?: number): void {
switch (variable) {
case 'id': {
this.item.id = $event.target.value;
@@ -217,7 +226,12 @@ export class DataDetailComponent implements OnDestroy {
break;
}
case 'property_key': {
- this.item.component.properties[index].key = $event.target.value as string;
+ if ($event instanceof MatAutocompleteSelectedEvent) {
+ this.item.component.properties[index].key = $event.option.value as string;
+ this.setPropertyDefaultValue($event, index, this.item);
+ } else {
+ this.item.component.properties[index].key = $event.target.value as string;
+ }
break;
}
case 'property_value': {
@@ -387,6 +401,36 @@ export class DataDetailComponent implements OnDestroy {
return index;
}
+ get filteredComponents(): Array {
+ const componentDefs: DataRefDef = this._fieldListService.fieldListArray.find(type => type.type === this.item.type);
+ if (!componentDefs) {
+ return [];
+ }
+ return componentDefs.components.filter(def => def.name !== undefined && def.title.toLowerCase().includes(this.item.component.name));
+ }
+
+ public filteredProperties(dataVariable: DataVariable, propertyName: string): Array {
+ const componentDefs: DataRefDef = this._fieldListService.fieldListArray.find(type => type.type === dataVariable.type);
+ if (!componentDefs) {
+ return [];
+ }
+ const propertyDefs: ComponentDef = componentDefs.components.find(compDef => {
+ return (!dataVariable.component.name && !compDef.name) || (!!dataVariable.component.name && !!compDef.name && dataVariable.component.name === compDef.name);
+ });
+ if (!propertyDefs || !propertyDefs.properties) {
+ return [];
+ }
+ const existingProperties = dataVariable.component.properties.map(compProperty => compProperty.key);
+ return propertyDefs.properties.filter(propDef => propDef.name.includes(propertyName) && !existingProperties.includes(propDef.name));
+ }
+
+ public setPropertyDefaultValue($event: MatAutocompleteSelectedEvent, index: number, dataVariable: DataVariable): void {
+ dataVariable.component.properties[index].value = this._fieldListService.fieldListArray
+ .find(type => type.type === dataVariable.type)?.components
+ .find(compDef => (!dataVariable.component.name && !compDef.name) || (!!dataVariable.component.name && !!compDef.name && dataVariable.component.name === compDef.name))?.properties
+ .find(propDef => propDef.name === $event.option.value).defaultValue;
+ }
+
protected readonly DataType = DataType;
protected readonly Boolean = Boolean;
protected readonly DataFieldUtils = DataFieldUtils;