diff --git a/src/app/p_services/admin/lifeCycleManagement/service-rule-design/service-rule-design.component.ts b/src/app/p_services/admin/lifeCycleManagement/service-rule-design/service-rule-design.component.ts index e3214ec0ebfcbab24324908d9c3383d08dc1859b..852d361b15ef72b40eabc11c7bf89f265567fe0f 100644 --- a/src/app/p_services/admin/lifeCycleManagement/service-rule-design/service-rule-design.component.ts +++ b/src/app/p_services/admin/lifeCycleManagement/service-rule-design/service-rule-design.component.ts @@ -250,7 +250,7 @@ export class ServiceRuleDesignComponent implements OnInit { this.workspace.charsListSet = this.workspace.charsListSet.concat( this.charsListArray ); this.workspace.charsListBoolean = this.charsListBoolean; - + this.workspace.specService = this.specService; this.charvarsAllFunction(this.workspace); //calling this function here causes a preloading of the blocks in the model in a synchronous manner. Asynchronously it is recalled later in the blockly toolbar @@ -527,6 +527,8 @@ export class ServiceRuleDesignComponent implements OnInit { var xmlList = []; var chars: ServiceSpecRelationship[] = workspace.serviceSpecRel; + + if (Blockly.Blocks['getServiceRefName']) { for (var i = 0; i < chars.length; i++) { var blockText = '<block type="getServiceRefName">' + @@ -556,10 +558,112 @@ export class ServiceRuleDesignComponent implements OnInit { xmlList.push(block); + + + + // if (Blockly.Blocks['setServiceRefProps']) { + // for (var i = 0; i < chars.length; i++) { + + // var options = []; + // var serviceRefSpec; + // var servRef = chars[i]; + + // workspace.specService.retrieveServiceSpecification({id: servRef.id, servRef , xmlList }).subscribe( + // data => serviceRefSpec = data, + // error => console.error(error), + // () => { + + // var xmlx = xmlList; + // var serviceRefChars: ServiceSpecCharacteristic[] = serviceRefSpec.serviceSpecCharacteristic; + // for (var j = 0; j < serviceRefChars.length; j++) { + // options.push([ serviceRefChars[j].name, serviceRefChars[j].name ]); + // } + // console.log(servRef); + + // var sortedArray: string[] = options.sort((n1,n2) => { + // if (n1 > n2) { + // return 1; + // } + + // if (n1 < n2) { + // return -1; + // } + + // return 0; + // }); + + // Blockly.Blocks['setServiceRefProps'] = { + // init: function() { + // this.appendDummyInput() + // .appendField("Service") + // .appendField(new Blockly.FieldLabelSerializable(""), "ASERVICEREFNAME"); + // this.appendDummyInput() + // .appendField(new Blockly.FieldLabelSerializable(""), "ASERVICEREFUUID") + // .appendField(new Blockly.FieldLabelSerializable(""), "NAMELBL") + // .appendField(new Blockly.FieldDropdown( sortedArray ), "OPTIONEDVALUE"); + + + // this.appendValueInput("AVALUE") + // .setCheck("String") + // .setAlign(Blockly.ALIGN_RIGHT) + // .appendField("value"); + + + // this.setInputsInline( true ); + // this.setPreviousStatement(true, null); + // this.setNextStatement(true, null); + // this.setColour(160); + // this.setTooltip("Set values to characteristics of a refernced service."); + // this.setHelpUrl(""); + + // }, + + // }; + // } + // ) + + // var blockText = '<block type="setServiceRefProps">' + + // '<field name="ASERVICEREFNAME">'+ servRef.name +'</field>' + + // '<field name="ASERVICEREFUUID">'+ servRef.uuid +'</field>' + + // '</block>'; + // var block = Blockly.Xml.textToDom(blockText); + // xmlList.push(block); + + + // } + // } + + + + + if (Blockly.Blocks['setServiceRefCharacteristicValues']) { + for (var i = 0; i < chars.length; i++) { + + var blockText = '<block type="setServiceRefCharacteristicValues">' + + '<field name="ASERVICEREFNAME">' + chars[i].name + '</field>' + + '<field name="ASERVICEREFUUID">' + chars[i].uuid + '</field>' + + '</block>'; + var block = Blockly.Xml.textToDom(blockText); + xmlList.push(block); + + } + } + + + if (Blockly.Blocks['serviceRefCharacteristic']) { + var blockText = '<block type="serviceRefCharacteristic">' + + '<field name="ACHARACTERISTICNAME"></field>' + + '<field name="AVALUE"></field>' + + '</block>'; + var block = Blockly.Xml.textToDom(blockText); + xmlList.push(block); + } + return xmlList; }; + /** @@ -567,7 +671,7 @@ export class ServiceRuleDesignComponent implements OnInit { * @param {!Blockly.Workspace} workspace The workspace this flyout is for. * @return {!Array.<!Element>} Array of XML block elements. */ - resourceSpecRelsFunction = function(workspace: any) { + resourceSpecRelsFunction = function(workspace: any) { var xmlList = []; var chars: ResourceSpecificationRef[] = workspace.resourceserviceSpecRef; @@ -581,7 +685,7 @@ export class ServiceRuleDesignComponent implements OnInit { } } - blockText = '<block type="createresourcewhen"></block>'; + blockText = '<block type="createResourceRefIf"></block>'; block = Blockly.Xml.textToDom(blockText); xmlList.push(block); @@ -1416,6 +1520,103 @@ export class ServiceRuleDesignComponent implements OnInit { }; + + // Blockly.Java['setServiceRefProps'] = function(block: any) { + // // Variable getter. + // console.log('setServiceRefProps'); + + + // //var acharname='""'; + // var servicename = block.getFieldValue('ASERVICEREFNAME'); + // servicename = Blockly.Java.quote_( servicename ); + // var servicerefuuid = block.getFieldValue('ASERVICEREFUUID'); + // servicerefuuid = Blockly.Java.quote_( servicerefuuid ); + + // console.log( servicename ); + + + // // var acharname = Blockly.Java.valueToCode(block, 'characteristicName', + // // Blockly.Java.ORDER_ASSIGNMENT) || '""'; + // var acharname = block.getFieldValue('OPTIONEDVALUE'); + // console.log( acharname ); + + + // var aVALUE = Blockly.Java.valueToCode(block, 'AVALUE', + // Blockly.Java.ORDER_ASSIGNMENT) || '""'; + + // console.log( aVALUE ); + + // var code = 'setServiceRefPropValue(' + servicename +', '+acharname +', '+aVALUE +');\n'; + + + // return code; + // }; + + + + Blockly.Java['serviceRefCharacteristic'] = function(block: any) { + // Variable getter. + console.log('serviceRefCharacteristic'); + + var acharname = Blockly.Java.valueToCode(block, 'ACHARACTERISTICNAME', + Blockly.Java.ORDER_ASSIGNMENT) || '""'; + console.log( acharname ); + + var aVALUE = Blockly.Java.valueToCode(block, 'AVALUE', + Blockly.Java.ORDER_ASSIGNMENT) || '""'; + + console.log( aVALUE ); + + var code: any = { "charname" : acharname, "charvalue" : aVALUE }; + + code = JSON.stringify( code, null ); + return [code, Blockly.Java.ORDER_ATOMIC]; + }; + + Blockly.Java['setServiceRefCharacteristicValues'] = function(block: any) { + // Variable getter. + console.log('setServiceRefCharacteristicValues'); + + + //var acharname='""'; + var servicename = block.getFieldValue('ASERVICEREFNAME'); + servicename = Blockly.Java.quote_( servicename ); + var servicerefuuid = block.getFieldValue('ASERVICEREFUUID'); + servicerefuuid = Blockly.Java.quote_( servicerefuuid ); + + console.log( servicename ); + + + var acharname = Blockly.Java.valueToCode(block, 'characteristicName', + Blockly.Java.ORDER_ASSIGNMENT) || '""'; + + console.log( acharname ); + + + var cvs = Blockly.Java.valueToCode(block, 'CHARVALUES', Blockly.Java.ORDER_NONE) || null ; + console.log( cvs ); + var objects = JSON.parse( cvs ); + console.log( objects ); + + var code = 'java.util.HashMap<String,String> charvals = new java.util.HashMap<>();\n'; + + var varray = '['; + + if (objects){ + objects.forEach(element => { + var charname = element.charname; + var avalue = element.charvalue; + code += 'charvals.put(' + charname + ',' +avalue + ');\n'; + }); + } + varray += ']'; + + code += 'setServiceRefCharacteristicsValues(' + servicename +', charvals);\n'; + + + return code; + }; + } diff --git a/src/assets/blockly/custom_blocks.js b/src/assets/blockly/custom_blocks.js index 51d44d03862e662826f4ead578e8937d2795a5f3..14cddac32a75a38a32662fe41f3cfc45ffd8cafd 100644 --- a/src/assets/blockly/custom_blocks.js +++ b/src/assets/blockly/custom_blocks.js @@ -1224,6 +1224,22 @@ Blockly.Blocks['example_variable_typed'] = { } }; + Blockly.Blocks['createResourceRefIf'] = { + init: function() { + this.appendValueInput("RESOURCE_NAME") + .setCheck("String") + .appendField("Create Ref Resource"); + this.appendValueInput("CONDITION") + .setCheck("Boolean") + .appendField("if"); + this.setInputsInline(true); + this.setPreviousStatement(true, null); + this.setNextStatement(true, null); + this.setColour(230); + this.setTooltip("Create a resource when a condition validates to true during the creation process."); + this.setHelpUrl(""); + } + }; @@ -1356,4 +1372,94 @@ Blockly.Blocks['example_variable_typed'] = { this.updateShape(); } }; + + + + + // Blockly.Blocks['setServiceRefProps'] = { + // init: function() { + // this.appendDummyInput() + // .appendField("Service") + // .appendField(new Blockly.FieldLabelSerializable(""), "ASERVICEREFNAME"); + // this.appendDummyInput() + // .appendField(new Blockly.FieldLabelSerializable(""), "ASERVICEREFUUID") + // .appendField(new Blockly.FieldLabelSerializable(""), "NAMELBL") + // .appendField(new Blockly.FieldLabelSerializable(""), "OPTIONEDVALUE"); + + + + // this.appendValueInput("AVALUE") + // .setCheck("String") + // .setAlign(Blockly.ALIGN_RIGHT) + // .appendField("value"); + + + // this.setInputsInline( true ); + // this.setPreviousStatement(true, null); + // this.setNextStatement(true, null); + // this.setColour(colourtexts); + // this.setTooltip("Set values to characteristics of a refernced service."); + // this.setHelpUrl(""); + + // }, + + // }; + + + + Blockly.Blocks['serviceRefCharacteristic'] = { + init: function() { + + this.appendValueInput("ACHARACTERISTICNAME") + .setCheck("String") + .setAlign(Blockly.ALIGN_RIGHT) + .appendField("Name"); + + + this.appendValueInput("AVALUE") + .setCheck("String") + .setAlign(Blockly.ALIGN_RIGHT) + .appendField("value"); + + + this.setInputsInline( true ); + this.setOutput(true, 'String'); + this.setColour(colourtexts); + this.setTooltip("Set values to characteristics of a refernced service."); + this.setHelpUrl(""); + + }, + + }; + + + Blockly.Blocks['setServiceRefCharacteristicValues'] = { + init: function() { + this.appendDummyInput() + .appendField("Service") + .appendField(new Blockly.FieldLabelSerializable(""), "ASERVICEREFNAME"); + this.appendDummyInput() + .appendField(new Blockly.FieldLabelSerializable(""), "ASERVICEREFUUID"); + + + + this.appendValueInput("CHARVALUES") + .setCheck("Array") + .setAlign(Blockly.ALIGN_RIGHT) + .appendField("Characteristics"); + + + this.setInputsInline( false ); + this.setPreviousStatement(true, null); + this.setNextStatement(true, null); + this.setColour(colourtexts); + this.setTooltip("Set values to characteristics of a refernced service."); + this.setHelpUrl(""); + + }, + + + + + }; \ No newline at end of file