</div>
<div data-ng-if="!isSchemaTypeDataType" class="i-sdc-form-item map-item-field" data-ng-class="{error:(parentFormObj['mapValue'+fieldsPrefixName+$index].$dirty && parentFormObj['mapValue'+fieldsPrefixName+$index].$invalid)}">
<label class="i-sdc-form-label required">Value</label>
-
+ <form class="temp-form">
+ <input type="radio" name="hasToscaFunction-{{fieldsPrefixName}}-{{$index}}" data-ng-checked="{{showToscaFunction[$index] == false}}" data-ng-click="onEnableTosca(false,$index)"/>
+ Value
+ <input type="radio" name="hasToscaFunction-{{fieldsPrefixName}}-{{$index}}" data-ng-checked="{{showToscaFunction[$index]}}" data-ng-click="onEnableTosca(true,$index)" ng-disabled="mapKeys[$index] == '' || mapKeys[$index] == null"/>
+ {{'TOSCA_FUNCTION_LABEL' | translate}}
+ </form>
<input class="i-sdc-form-input"
- ng-if="!constraints && !((schemaProperty.simpleType||schemaProperty.type) == 'boolean')"
+ ng-if="!constraints && !((schemaProperty.simpleType||schemaProperty.type) == 'boolean') && showToscaFunction[$index] == false"
data-ng-readonly="readOnly"
data-ng-model="valueObjRef[mapKeys[$index]]"
type="text"
autofocus />
<select class="i-sdc-form-select"
data-tests-id="mapValue{{fieldsPrefixName}}{{$index}}"
- ng-if="!constraints && (schemaProperty.simpleType||schemaProperty.type) == 'boolean'"
+ ng-if="!constraints && (schemaProperty.simpleType||schemaProperty.type) == 'boolean' && showToscaFunction[$index] == false"
data-ng-disabled="readOnly"
name="mapValue{{fieldsPrefixName}}{{$index}}"
data-ng-model="valueObjRef[mapKeys[$index]]"
<option value="true">true</option>
<option value="false">false</option>
</select>
+ <div data-ng-if="showToscaFunction[$index]" class="div-tosca-function">
+ <tosca-function [property]="parentProperty"
+ [component-instance-map]="componentInstanceMap"
+ [allow-clear]="false"
+ [composition-map]="true"
+ [composition-map-key]="mapKeys[$index]"
+ (on-valid-function)="onGetToscaFunction($event,mapKeys[$index])"
+ >
+ </tosca-function>
+ </div>
<select class="i-sdc-form-select"
'use strict';
import {ValidationUtils, PROPERTY_TYPES} from "app/utils";
import {DataTypesService} from "app/services";
-import {SchemaProperty} from "app/models";
+import {SchemaProperty, PropertyModel} from "app/models";
+import {InstanceFeDetails} from "app/models/instance-fe-details";
+import {ToscaGetFunction} from "app/models/tosca-get-function";
+import {SubPropertyToscaFunction} from "app/models/sub-property-tosca-function";
export interface ITypeMapScope extends ng.IScope {
parentFormObj:ng.IFormController;
schemaProperty:SchemaProperty;
+ parentProperty:PropertyModel;
+ componentInstanceMap: Map<string, InstanceFeDetails>;
isMapKeysUnique:boolean;
isSchemaTypeDataType:boolean;
valueObjRef:any;
maxLength:number;
constraints:string[];
showAddBtn: boolean;
+ showToscaFunction: Array<boolean>;
getValidationPattern(type:string):RegExp;
validateIntRange(value:string):boolean;
addMapItemFields():void;
parseToCorrectType(objectOfValues:any, locationInObj:string, type:string):void;
getNumber(num:number):Array<any>;
+ validateSubToscaFunction(key:string):boolean;
+ onEnableTosca(toscaFlag:boolean,index:number);
+ onGetToscaFunction(toscaGetFunction: ToscaGetFunction, key:string);
}
scope = {
valueObjRef: '=',//ref to map object in the parent value object
+ componentInstanceMap: '=',
schemaProperty: '=',//get the schema.property object
parentFormObj: '=',//ref to parent form (get angular form object)
fieldsPrefixName: '=',//prefix for form fields names
defaultValue: '@',//this map default value
maxLength: '=',
constraints: '=',
- showAddBtn: '=?'
+ showAddBtn: '=?',
+ parentProperty: '='
};
restrict = 'E';
scope.showAddBtn = angular.isDefined(scope.showAddBtn) ? scope.showAddBtn : true;
scope.MapKeyValidationPattern = this.MapKeyValidationPattern;
scope.isMapKeysUnique = true;
+ if (scope.mapKeys === undefined) {
+ scope.mapKeys = Object.keys(scope.valueObjRef);
+ }
+ scope.showToscaFunction = new Array(scope.mapKeys.length);
+ scope.mapKeys.forEach((key, index) => {
+ scope.showToscaFunction[index] = false;
+ if (scope.parentProperty.subPropertyToscaFunctions != null) {
+ scope.parentProperty.subPropertyToscaFunctions.forEach(SubPropertyToscaFunction => {
+ if (SubPropertyToscaFunction.subPropertyPath.indexOf(key) != -1) {
+ scope.showToscaFunction[index] = true;
+ }
+ });
+ }
+ });
//reset valueObjRef and mapKeys when schema type is changed
scope.$watchCollection('schemaProperty.type', (newData:any):void => {
};
scope.deleteMapItem = (index:number):void=> {
+ const keyToChange = scope.mapKeys[index];
delete scope.valueObjRef[scope.mapKeys[index]];
scope.mapKeys.splice(index, 1);
+ scope.showToscaFunction.splice(index, 1);
+ if (scope.parentProperty.subPropertyToscaFunctions != null) {
+ let subToscaFunctionList : Array<SubPropertyToscaFunction> = [];
+ scope.parentProperty.subPropertyToscaFunctions.forEach((SubPropertyToscaFunction, index) => {
+ if (SubPropertyToscaFunction.subPropertyPath.indexOf(keyToChange) == -1) {
+ subToscaFunctionList.push(SubPropertyToscaFunction);
+ }
+ });
+ scope.parentProperty.subPropertyToscaFunctions = subToscaFunctionList;
+ }
if (!scope.mapKeys.length) {//only when user removes all pairs of key-value fields - put the default
if (scope.mapDefaultValue) {
angular.copy(scope.mapDefaultValue, scope.valueObjRef);
}
};
+ scope.onEnableTosca = (toscaFlag:boolean,flagIndex:number):void => {
+ scope.showToscaFunction[flagIndex] = toscaFlag;
+ scope.valueObjRef[scope.mapKeys[flagIndex]] = null;
+ if (!toscaFlag) {
+ if (scope.parentProperty.subPropertyToscaFunctions != null) {
+ let subToscaFunctionList : Array<SubPropertyToscaFunction> = [];
+ scope.parentProperty.subPropertyToscaFunctions.forEach((SubPropertyToscaFunction, index) => {
+ if (SubPropertyToscaFunction.subPropertyPath.indexOf(scope.mapKeys[flagIndex]) == -1) {
+ subToscaFunctionList.push(SubPropertyToscaFunction);
+ }
+ });
+ scope.parentProperty.subPropertyToscaFunctions = subToscaFunctionList;
+ }
+ }
+ };
+
+ scope.onGetToscaFunction = (toscaGetFunction: ToscaGetFunction, key:string): void => {
+ if (scope.parentProperty.subPropertyToscaFunctions != null) {
+ scope.parentProperty.subPropertyToscaFunctions.forEach(SubPropertyToscaFunction => {
+ if (SubPropertyToscaFunction.subPropertyPath.indexOf(key) != -1) {
+ SubPropertyToscaFunction.toscaFunction = toscaGetFunction;
+ return;
+ }
+ });
+
+ }
+ if (scope.parentProperty.subPropertyToscaFunctions == null){
+ scope.parentProperty.subPropertyToscaFunctions = [];
+ }
+ let subPropertyToscaFunction = new SubPropertyToscaFunction();
+ subPropertyToscaFunction.toscaFunction = toscaGetFunction;
+ subPropertyToscaFunction.subPropertyPath = [key];
+ scope.parentProperty.subPropertyToscaFunctions.push(subPropertyToscaFunction);
+ }
+
scope.addMapItemFields = ():void => {
scope.valueObjRef[''] = null;
scope.mapKeys = Object.keys(scope.valueObjRef);
+ scope.showToscaFunction.push(false);
};
scope.parseToCorrectType = (objectOfValues:any, locationInObj:string, type:string):void => {
objectOfValues[locationInObj] = JSON.parse(objectOfValues[locationInObj]);
}
}
+
+ scope.validateSubToscaFunction = (key:string):boolean => {
+ if (scope.parentProperty.subPropertyToscaFunctions != null) {
+ scope.parentProperty.subPropertyToscaFunctions.forEach(SubPropertyToscaFunction => {
+ if (SubPropertyToscaFunction.subPropertyPath.indexOf(key) != -1) {
+ return true;
+ }
+ });
+ }
+ return false;
+ }
};
public static factory = (DataTypesService:DataTypesService,
@Input() property: PropertyBEModel;
@Input() componentInstanceMap: Map<string, InstanceFeDetails> = new Map<string, InstanceFeDetails>();
@Input() allowClear: boolean = true;
+ @Input() compositionMap: boolean = false;
+ @Input() compositionMapKey: string = "";
@Output() onValidFunction: EventEmitter<ToscaGetFunction> = new EventEmitter<ToscaGetFunction>();
@Output() onValidityChange: EventEmitter<ToscaFunctionValidationEvent> = new EventEmitter<ToscaFunctionValidationEvent>();
}
private initToscaFunction(): void {
+ if (this.compositionMap && this.property.subPropertyToscaFunctions) {
+ let keyToFind = [this.compositionMapKey];
+ let subPropertyToscaFunction = this.property.subPropertyToscaFunctions.find(subPropertyToscaFunction => this.areEqual(subPropertyToscaFunction.subPropertyPath, keyToFind));
+
+ if (subPropertyToscaFunction){
+ this.toscaFunction = subPropertyToscaFunction.toscaFunction;
+ this.toscaFunctionForm.setValue(this.toscaFunction);
+ this.toscaFunctionTypeForm.setValue(this.toscaFunction.type);
+ }
+ return;
+ }
if (this.property instanceof PropertyDeclareAPIModel && this.property.subPropertyToscaFunctions && (<PropertyDeclareAPIModel> this.property).propertiesName){
let propertiesPath = (<PropertyDeclareAPIModel> this.property).propertiesName.split("#");
if (propertiesPath.length > 1){
@Input() toscaGetFunction: ToscaGetFunction;
@Input() componentInstanceMap: Map<string, InstanceFeDetails> = new Map<string, InstanceFeDetails>();
@Input() functionType: ToscaGetFunctionType;
+ @Input() compositionMap: boolean;
+ @Input() compositionMapKey: string;
@Output() onValidFunction: EventEmitter<ToscaGetFunction> = new EventEmitter<ToscaGetFunction>();
@Output() onValidityChange: EventEmitter<ToscaGetFunctionValidationEvent> = new EventEmitter<ToscaGetFunctionValidationEvent>();
private propertyTypeToString() {
if (this.isSubProperty()){
- if (this.typeHasSchema(this.property.type) && this.property instanceof PropertyDeclareAPIModel &&
- (<PropertyDeclareAPIModel> this.property).input instanceof DerivedFEProperty) {
- if(this.isComplexType(this.property.schemaType)){
- return this.property.input.type;
+ if ((this.typeHasSchema(this.property.type) && this.property instanceof PropertyDeclareAPIModel &&
+ (<PropertyDeclareAPIModel> this.property).input instanceof DerivedFEProperty) || this.compositionMap) {
+ if(this.isComplexType(this.property.schemaType) && !this.compositionMap){
+ return (<PropertyDeclareAPIModel> this.property).input.type;
}else{
return this.property.schema.property.type;
}
private hasSameType(property: PropertyBEModel | AttributeBEModel): boolean {
if (this.typeHasSchema(this.property.type)) {
- if (this.property instanceof PropertyDeclareAPIModel && (<PropertyDeclareAPIModel> this.property).input instanceof DerivedFEProperty) {
- if(this.isComplexType(this.property.schemaType)){
- return property.type === this.property.input.type;
+ if ((this.property instanceof PropertyDeclareAPIModel && (<PropertyDeclareAPIModel> this.property).input instanceof DerivedFEProperty) || this.compositionMap) {
+ if(this.isComplexType(this.property.schemaType) && !this.compositionMap){
+ return property.type === (<PropertyDeclareAPIModel> this.property).input.type;
}else{
return property.type === this.property.schema.property.type;
}