aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/directives/property-types/type-map/type-map-directive.ts
diff options
context:
space:
mode:
authorimamSidero <imam.hussain@est.tech>2023-01-11 18:13:25 +0000
committerMichael Morris <michael.morris@est.tech>2023-01-13 13:22:26 +0000
commita8d208b231237fc9f05f83c2b33fa207d58f1480 (patch)
treee58cac7c4a5e81e5fd042ed244539d4981947434 /catalog-ui/src/app/directives/property-types/type-map/type-map-directive.ts
parentaa92493c97b43075c18696d79f7d1bf62aa4805a (diff)
Provide tosca function as map primitive type entry values in composition view
Providing the capability to add tosca function as the primitive type entry values of map in composition view Issue-ID: SDC-4319 Signed-off-by: Imam hussain <imam.hussain@est.tech> Change-Id: I5cf67bc94ac5c72be6a962e07160329cd07d302c
Diffstat (limited to 'catalog-ui/src/app/directives/property-types/type-map/type-map-directive.ts')
-rw-r--r--catalog-ui/src/app/directives/property-types/type-map/type-map-directive.ts87
1 files changed, 85 insertions, 2 deletions
diff --git a/catalog-ui/src/app/directives/property-types/type-map/type-map-directive.ts b/catalog-ui/src/app/directives/property-types/type-map/type-map-directive.ts
index ceb2fa0bb9..ce8b997035 100644
--- a/catalog-ui/src/app/directives/property-types/type-map/type-map-directive.ts
+++ b/catalog-ui/src/app/directives/property-types/type-map/type-map-directive.ts
@@ -24,11 +24,16 @@
'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;
@@ -41,6 +46,7 @@ export interface ITypeMapScope extends ng.IScope {
maxLength:number;
constraints:string[];
showAddBtn: boolean;
+ showToscaFunction: Array<boolean>;
getValidationPattern(type:string):RegExp;
validateIntRange(value:string):boolean;
@@ -49,6 +55,9 @@ export interface ITypeMapScope extends ng.IScope {
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);
}
@@ -62,6 +71,7 @@ export class TypeMapDirective implements ng.IDirective {
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
@@ -69,7 +79,8 @@ export class TypeMapDirective implements ng.IDirective {
defaultValue: '@',//this map default value
maxLength: '=',
constraints: '=',
- showAddBtn: '=?'
+ showAddBtn: '=?',
+ parentProperty: '='
};
restrict = 'E';
@@ -82,6 +93,20 @@ export class TypeMapDirective implements ng.IDirective {
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 => {
@@ -153,8 +178,19 @@ export class TypeMapDirective implements ng.IDirective {
};
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);
@@ -163,9 +199,45 @@ export class TypeMapDirective implements ng.IDirective {
}
};
+ 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 => {
@@ -173,6 +245,17 @@ export class TypeMapDirective implements ng.IDirective {
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,