/// <summary> /// Generates the function definition. /// blockly block definition for action /// </summary> /// <param name="actionInfo">The action information.</param> /// <returns></returns> public string GenerateFunctionDefinition(ActionInfo actionInfo) { var strPropsDefinition = GeneratePropertyDefinitions(actionInfo); var returnType = $@"this.setOutput(true,'{actionInfo.ReturnType.TranslateToBlocklyType()}');"; var actionHash = actionInfo.CustomGetHashCode(); var blockColor = BlocklyStringToColor.ConvertToHue(actionHash); return($@" Blockly.Blocks['{actionInfo.GenerateCommandName()}'] = {{ init: function() {{ this.setColour({blockColor}); this.appendDummyInput() .appendField('{actionInfo.CommandDisplayName()}'); {strPropsDefinition} {returnType} }}//init }};//{actionInfo.ActionName} "); }
/// <summary> /// Generates the function definition. /// blockly block definition for action /// </summary> /// <param name="actionInfo">The action information.</param> /// <param name="key">key</param> /// <returns></returns> public string GenerateFunctionDefinition(ActionInfo actionInfo, string key) { var strPropsDefinition = GeneratePropertyDefinitions(actionInfo); var returnType = ""; if (actionInfo.ReturnType.id != null) { returnType = $@"this.setOutput(true,'{actionInfo.ReturnType.TranslateToBlocklyType()}');"; } else { returnType = $@"this.setOutput(true,'');"; } var actionHash = actionInfo.CustomGetHashCode(); string[] verbHasImage = new string[] { "patch", "get", "post", "put", "delete" }; bool hasImage = verbHasImage.Contains(actionInfo.Verb.ToLower()); var blockColor = BlocklyStringToColor.ConvertToHue(actionHash); string site = string.IsNullOrWhiteSpace(GenerateBlocklyFilesHostedService.InternalSiteUrl) ? "" : GenerateBlocklyFilesHostedService.InternalSiteUrl; return($@" Blockly.Blocks['{actionInfo.GenerateCommandName()}'] = {{ init: function() {{ this.setColour({blockColor}); this.appendDummyInput()" + (hasImage? $".appendField(new Blockly.FieldImage('{site}images/{actionInfo.Verb.ToLower()}.png', 90, 20, {{ alt: '{actionInfo.Verb}', flipRtl: 'FALSE' }}))" :"") + $".appendField('{actionInfo.CommandDisplayName(!hasImage)}');" + Environment.NewLine + $@"{strPropsDefinition} {returnType} }}//init }};//{actionInfo.ActionName} "); }