Skip to content

Commit

Permalink
set attribute block
Browse files Browse the repository at this point in the history
  • Loading branch information
eskim committed Mar 23, 2015
1 parent 83a02b7 commit 96c6abb
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 2 deletions.
39 changes: 37 additions & 2 deletions public/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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');
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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": {
Expand Down
35 changes: 35 additions & 0 deletions public/js/blocks/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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');
Expand Down
4 changes: 4 additions & 0 deletions public/js/tpl/blockly.html
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,10 @@ <h3>List</h3>
<block type="text" />
</value>
</block>
<block type="ui_set_attr">
<value name="ATTR"><block type="text" /></value>
<value name="VALUE"><block type="text" /></value>
</block>
<block type="prezi_next_with_channel" />
<block type="prezi_prev_with_channel" />
<block type="prezi_move_with_channel" />
Expand Down

0 comments on commit 96c6abb

Please sign in to comment.