From 96c6abb406c4cf5d8f3ae4d01cc371d25327eb5d Mon Sep 17 00:00:00 2001 From: Eunsub Kim Date: Mon, 23 Mar 2015 14:43:19 +0900 Subject: [PATCH] set attribute block --- public/bundle.js | 39 ++++++++++++++++++++++++++++++++++++-- public/js/blocks/ui.js | 35 ++++++++++++++++++++++++++++++++++ public/js/tpl/blockly.html | 4 ++++ 3 files changed, 76 insertions(+), 2 deletions(-) diff --git a/public/bundle.js b/public/bundle.js index 5bc4ab0..80418b2 100644 --- a/public/bundle.js +++ b/public/bundle.js @@ -2094,6 +2094,25 @@ Blockly.Blocks['ui_text'] = { }; +Blockly.Blocks['ui_set_attr'] = { + + init: function() { + this.setColour(30); + this.appendDummyInput().appendField('Set Attribute' + name); + + this.appendDummyInput().appendField('name:') + .appendField(new Blockly.FieldTextInput('name', null), 'NAME'); + + this.appendValueInput('ATTR').appendField('attr:'); + this.appendValueInput('VALUE').appendField('value:'); + this.setInputsInline(true); + this.setPreviousStatement(true); + return this.setNextStatement(true); + + + }, + +}; Blockly.Blocks['ui_button'] = { init: function() { @@ -2112,6 +2131,22 @@ Blockly.Blocks['ui_button'] = { }, }; +Blockly.JavaScript['ui_set_attr'] = function(block){ + var attr = Blockly.JavaScript.valueToCode(block, 'ATTR', Blockly.JavaScript.ORDER_NONE) || "''"; + var value = Blockly.JavaScript.valueToCode(block, 'VALUE', Blockly.JavaScript.ORDER_NONE) || "''"; + var name = block.getFieldValue('NAME'); + + + var data = { + rocon_id: name, + attr: eval(attr), + value: eval(value) + }; + var code = _.template('$engine.publish("to-rocon-ui", "std_msgs/String", {data: <%= data %>});')({ + data: "'" + JSON.stringify(data) + "'" + }); + return code; +}; Blockly.JavaScript['ui_button'] = function(block){ var text = Blockly.JavaScript.valueToCode(block, 'TEXT', Blockly.JavaScript.ORDER_NONE) || "''"; var name = block.getFieldValue('NAME'); @@ -2279,7 +2314,7 @@ Blockly.JavaScript['defer'] = function(block) { }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) },{"../config":"/Users/eskim/current/cento_authoring/public/js/config.json"}],"/Users/eskim/current/cento_authoring/public/js/config.json":[function(require,module,exports){ -module.exports=module.exports=module.exports=module.exports=module.exports=module.exports=module.exports=module.exports={ +module.exports=module.exports=module.exports=module.exports=module.exports=module.exports=module.exports=module.exports=module.exports=module.exports=module.exports=module.exports=module.exports=module.exports={ "action_color": 100, "undo_check_interval": 1000, "undo_max_size": 100 @@ -3316,7 +3351,7 @@ module.exports = { }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) },{}],"/Users/eskim/current/cento_authoring/public/js/schema/service_form.json":[function(require,module,exports){ -module.exports=module.exports=module.exports=module.exports=module.exports=module.exports=module.exports=module.exports={ +module.exports=module.exports=module.exports=module.exports=module.exports=module.exports=module.exports=module.exports=module.exports=module.exports=module.exports=module.exports=module.exports=module.exports={ "title": "Create Service", "type": "object", "properties": { diff --git a/public/js/blocks/ui.js b/public/js/blocks/ui.js index 156edc1..c7ba81a 100644 --- a/public/js/blocks/ui.js +++ b/public/js/blocks/ui.js @@ -66,6 +66,25 @@ Blockly.Blocks['ui_text'] = { }; +Blockly.Blocks['ui_set_attr'] = { + + init: function() { + this.setColour(30); + this.appendDummyInput().appendField('Set Attribute' + name); + + this.appendDummyInput().appendField('name:') + .appendField(new Blockly.FieldTextInput('name', null), 'NAME'); + + this.appendValueInput('ATTR').appendField('attr:'); + this.appendValueInput('VALUE').appendField('value:'); + this.setInputsInline(true); + this.setPreviousStatement(true); + return this.setNextStatement(true); + + + }, + +}; Blockly.Blocks['ui_button'] = { init: function() { @@ -84,6 +103,22 @@ Blockly.Blocks['ui_button'] = { }, }; +Blockly.JavaScript['ui_set_attr'] = function(block){ + var attr = Blockly.JavaScript.valueToCode(block, 'ATTR', Blockly.JavaScript.ORDER_NONE) || "''"; + var value = Blockly.JavaScript.valueToCode(block, 'VALUE', Blockly.JavaScript.ORDER_NONE) || "''"; + var name = block.getFieldValue('NAME'); + + + var data = { + rocon_id: name, + attr: eval(attr), + value: eval(value) + }; + var code = _.template('$engine.publish("to-rocon-ui", "std_msgs/String", {data: <%= data %>});')({ + data: "'" + JSON.stringify(data) + "'" + }); + return code; +}; Blockly.JavaScript['ui_button'] = function(block){ var text = Blockly.JavaScript.valueToCode(block, 'TEXT', Blockly.JavaScript.ORDER_NONE) || "''"; var name = block.getFieldValue('NAME'); diff --git a/public/js/tpl/blockly.html b/public/js/tpl/blockly.html index d84209e..6714346 100644 --- a/public/js/tpl/blockly.html +++ b/public/js/tpl/blockly.html @@ -364,6 +364,10 @@

List

+ + + +