123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419 |
- 'use strict';
- goog.provide('Blockly.Blocks.nbiot');
- goog.require('Blockly.Blocks');
- Blockly.Blocks.nbiot.HUE="#6da383";
- Blockly.Blocks['NBIoT_setup'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(new Blockly.FieldImage("./../blockly/media/nbiot_header.png", 100, 40, "0"));
- this.appendDummyInput()
- .appendField(Blockly.Msg.NBIOT_SETUP);
- this.setColour(Blockly.Blocks.nbiot.HUE);
- this.setTooltip("");
- this.setHelpUrl("");
- },
- }
- Blockly.Blocks['NBIoT_http'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(new Blockly.FieldImage("./../blockly/media/nbiot_header.png", 100, 40, "0"));
- this.appendDummyInput()
- .appendField(Blockly.Msg.NBIOT_HTTP_TITLE);
- this.appendDummyInput()
- .appendField(Blockly.Msg.NBIOT_HTTP_APIKEY)
- .appendField(new Blockly.FieldTextInput("yourCloudEventAPIKey"),"APIKEY")
- this.appendValueInput("ADD"+0)
- .appendField(Blockly.Msg.NBIOT_HTTP_DATA)
- .appendField(new Blockly.FieldTextInput("default"), "DATA_DEFAULT"+0)
- .setAlign(Blockly.ALIGN_RIGHT);
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- this.itemCount_ = 1;
- this.updateShape_();
- this.setMutator(new Blockly.Mutator(['NBIoT_create_with_item']));
- this.setColour(Blockly.Blocks.nbiot.HUE);
- this.setTooltip("");
- this.setHelpUrl("");
- },
- mutationToDom: function() {
- var container = document.createElement('mutation');
- container.setAttribute('items', this.itemCount_);
- return container;
- },
- domToMutation: function(xmlElement) {
- this.itemCount_ = parseInt(xmlElement.getAttribute('items'), 10);
- this.updateShape_();
- },
- decompose: function(workspace) {
- var containerBlock = workspace.newBlock('NBIoT_create_with_container');
- containerBlock.initSvg();
- var connection = containerBlock.getInput('STACK').connection;
- for (var i = 0; i < this.itemCount_; i++) {
- var itemBlock = workspace.newBlock('NBIoT_create_with_item');
- itemBlock.initSvg();
- connection.connect(itemBlock.previousConnection);
- connection = itemBlock.nextConnection;
- }
- return containerBlock;
- },
- compose: function(containerBlock) {
- var itemBlock = containerBlock.getInputTargetBlock('STACK');
- var connections = [];
- while (itemBlock) {
- connections.push(itemBlock.valueConnection_);
- itemBlock = itemBlock.nextConnection &&
- itemBlock.nextConnection.targetBlock();
- }
- for (var i = 0; i < this.itemCount_; i++) {
- var connection = this.getInput('ADD' + i).connection.targetConnection;
- if (connection && connections.indexOf(connection) == -1) {
- connection.disconnect();
- }
- }
- this.itemCount_ = connections.length;
- this.updateShape_();
- for (var i = 0; i < this.itemCount_; i++) {
- Blockly.Mutator.reconnect(connections[i], this, 'ADD' + i);
- }
- },
- saveConnections: function(containerBlock) {
- var itemBlock = containerBlock.getInputTargetBlock('STACK');
- var i = 0;
- while (itemBlock) {
- var input = this.getInput('ADD' + i);
- itemBlock.valueConnection_ = input && input.connection.targetConnection;
- i++;
- itemBlock = itemBlock.nextConnection &&
- itemBlock.nextConnection.targetBlock();
- }
- },
- updateShape_: function() {
- for (var i = 0; i < this.itemCount_; i++) {
- if (!this.getInput('ADD' + i)) {
- var input = this.appendValueInput("ADD"+i)
- .appendField(Blockly.Msg.NBIOT_HTTP_DATA)
- .appendField(new Blockly.FieldTextInput("default"), "DATA_DEFAULT"+i)
- .setAlign(Blockly.ALIGN_RIGHT);
- }
- }
- while (this.getInput('ADD' + i)) {
- this.removeInput('ADD' + i);
- i++;
- }
- },
- onchange: function() {
- var text_content = this.getFieldValue("APIKEY");
- if (text_content.length > 50) {
- this.setFieldValue(text_content.substring(0,50),"APIKEY")
- }
- }
- };
- Blockly.Blocks['NBIoT_create_with_container'] = {
- init: function() {
- this.setColour(Blockly.Blocks.nbiot.HUE);
- this.appendDummyInput()
- .appendField(Blockly.Msg.BLYNK_CREATE_WITH_CONTAINER_TITLE_ADD);
- this.appendStatementInput('STACK');
- this.setTooltip('');
- this.contextMenu = false;
- }
- };
- Blockly.Blocks['NBIoT_create_with_item'] = {
- init: function() {
- this.setColour(Blockly.Blocks.nbiot.HUE);
- this.appendDummyInput()
- .appendField(Blockly.Msg.BLYNK_CREATE_WITH_ITEM_TITLE);
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- this.setTooltip('');
- this.contextMenu = false;
- }
- };
- Blockly.Blocks['NBIoT_enable'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(Blockly.Msg.NBIOT_ENABLE);
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- this.setColour(Blockly.Blocks.nbiot.HUE);
- this.setTooltip("");
- this.setHelpUrl("");
- },
- }
- Blockly.Blocks['NBIoT_http_thingspeak'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(new Blockly.FieldImage("./../blockly/media/nbiot_header.png", 100, 40, "0"));
- this.appendDummyInput()
- .appendField(Blockly.Msg.NBIOT_HTTP_THINGSPEAK_TITLE);
- this.appendDummyInput()
- .appendField(Blockly.Msg.NBIOT_HTTP_THINGSPEAK_APIKEY)
- .appendField(new Blockly.FieldTextInput("yourEventAPIKey"),"APIKEY")
- this.appendValueInput("ADD"+0)
- .appendField(Blockly.Msg.NBIOT_HTTP_DATA)
- // .appendField(new Blockly.FieldTextInput("default"), "DATA_DEFAULT"+0)
- .setAlign(Blockly.ALIGN_RIGHT);
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- this.itemCount_ = 1;
- this.updateShape_();
- this.setMutator(new Blockly.Mutator(['NBIoT_create_with_item']));
- this.setColour(Blockly.Blocks.nbiot.HUE);
- this.setTooltip("");
- this.setHelpUrl("");
- },
- mutationToDom: function() {
- var container = document.createElement('mutation');
- container.setAttribute('items', this.itemCount_);
- return container;
- },
- domToMutation: function(xmlElement) {
- this.itemCount_ = parseInt(xmlElement.getAttribute('items'), 10);
- this.updateShape_();
- },
- decompose: function(workspace) {
- var containerBlock = workspace.newBlock('NBIoT_create_with_container');
- containerBlock.initSvg();
- var connection = containerBlock.getInput('STACK').connection;
- for (var i = 0; i < this.itemCount_; i++) {
- var itemBlock = workspace.newBlock('NBIoT_create_with_item');
- itemBlock.initSvg();
- connection.connect(itemBlock.previousConnection);
- connection = itemBlock.nextConnection;
- }
- return containerBlock;
- },
- compose: function(containerBlock) {
- var itemBlock = containerBlock.getInputTargetBlock('STACK');
- var connections = [];
- while (itemBlock) {
- connections.push(itemBlock.valueConnection_);
- itemBlock = itemBlock.nextConnection &&
- itemBlock.nextConnection.targetBlock();
- }
- for (var i = 0; i < this.itemCount_; i++) {
- var connection = this.getInput('ADD' + i).connection.targetConnection;
- if (connection && connections.indexOf(connection) == -1) {
- connection.disconnect();
- }
- }
- this.itemCount_ = connections.length;
- this.updateShape_();
- for (var i = 0; i < this.itemCount_; i++) {
- Blockly.Mutator.reconnect(connections[i], this, 'ADD' + i);
- }
- },
- saveConnections: function(containerBlock) {
- var itemBlock = containerBlock.getInputTargetBlock('STACK');
- var i = 0;
- while (itemBlock) {
- var input = this.getInput('ADD' + i);
- itemBlock.valueConnection_ = input && input.connection.targetConnection;
- i++;
- itemBlock = itemBlock.nextConnection &&
- itemBlock.nextConnection.targetBlock();
- }
- },
- updateShape_: function() {
- for (var i = 0; i < this.itemCount_; i++) {
- if (!this.getInput('ADD' + i)) {
- var input = this.appendValueInput("ADD"+i)
- .appendField(Blockly.Msg.NBIOT_HTTP_DATA)
- // .appendField(new Blockly.FieldTextInput("default"), "DATA_DEFAULT"+i)
- .setAlign(Blockly.ALIGN_RIGHT);
- }
- }
- while (this.getInput('ADD' + i)) {
- this.removeInput('ADD' + i);
- i++;
- }
- },
- onchange: function() {
- /** set limitation of AUTH input length */
- var text_content = this.getFieldValue("APIKEY");
- if (text_content.length > 50) {
- this.setFieldValue(text_content.substring(0,50),"APIKEY")
- }
- }
- };
- Blockly.Blocks['NBIoT_http_IFTTT'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(new Blockly.FieldImage("./../blockly/media/nbiot_header.png", 130, 40, "0"));
- this.appendDummyInput()
- .appendField(Blockly.Msg.NBIOT_HTTP_IFTTT_TITLE);
- this.appendDummyInput()
- .appendField(Blockly.Msg.NBIOT_HTTP_IFTTT_APIKEY)
- .appendField(new Blockly.FieldTextInput("yourEventAPIKey"),"APIKEY")
- this.appendDummyInput()
- .appendField(Blockly.Msg.NBIOT_HTTP_IFTTT_EVENT)
- .appendField(new Blockly.FieldTextInput("yourEventName"),"EVENT")
- this.appendValueInput("ADD"+0)
- .appendField(Blockly.Msg.NBIOT_HTTP_DATA+"0")
- // .appendField(new Blockly.FieldTextInput("default"), "DATA_DEFAULT"+0)
- .setAlign(Blockly.ALIGN_RIGHT);
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- this.itemCount_ = 1;
- this.updateShape_();
- this.setMutator(new Blockly.Mutator(['NBIoT_create_with_item']));
- this.setColour(Blockly.Blocks.nbiot.HUE);
- this.setTooltip("");
- this.setHelpUrl("");
- },
- mutationToDom: function() {
- var container = document.createElement('mutation');
- container.setAttribute('items', this.itemCount_);
- return container;
- },
- domToMutation: function(xmlElement) {
- this.itemCount_ = parseInt(xmlElement.getAttribute('items'), 10);
- this.updateShape_();
- },
- decompose: function(workspace) {
- var containerBlock = workspace.newBlock('NBIoT_create_with_container');
- containerBlock.initSvg();
- var connection = containerBlock.getInput('STACK').connection;
- for (var i = 0; i < this.itemCount_; i++) {
- var itemBlock = workspace.newBlock('NBIoT_create_with_item');
- itemBlock.initSvg();
- connection.connect(itemBlock.previousConnection);
- connection = itemBlock.nextConnection;
- }
- return containerBlock;
- },
- compose: function(containerBlock) {
- var itemBlock = containerBlock.getInputTargetBlock('STACK');
- // Count number of inputs.
- var connections = [];
- while (itemBlock) {
- connections.push(itemBlock.valueConnection_);
- itemBlock = itemBlock.nextConnection &&
- itemBlock.nextConnection.targetBlock();
- }
- // Disconnect any children that don't belong.
- for (var i = 0; i < this.itemCount_; i++) {
- var connection = this.getInput('ADD' + i).connection.targetConnection;
- if (connection && connections.indexOf(connection) == -1) {
- connection.disconnect();
- }
- }
- this.itemCount_ = connections.length;
- this.updateShape_();
- // Reconnect any child blocks.
- for (var i = 0; i < this.itemCount_; i++) {
- Blockly.Mutator.reconnect(connections[i], this, 'ADD' + i);
- }
- },
- saveConnections: function(containerBlock) {
- var itemBlock = containerBlock.getInputTargetBlock('STACK');
- var i = 0;
- while (itemBlock) {
- var input = this.getInput('ADD' + i);
- itemBlock.valueConnection_ = input && input.connection.targetConnection;
- i++;
- itemBlock = itemBlock.nextConnection &&
- itemBlock.nextConnection.targetBlock();
- }
- },
- updateShape_: function() {
- for (var i = 0; i < this.itemCount_; i++) {
- if (!this.getInput('ADD' + i)) {
- var input = this.appendValueInput("ADD"+i)
- .appendField(Blockly.Msg.NBIOT_HTTP_DATA)
- // .appendField(new Blockly.FieldTextInput("default"), "DATA_DEFAULT"+i)
- .setAlign(Blockly.ALIGN_RIGHT);
- }
- }
- while (this.getInput('ADD' + i)) {
- this.removeInput('ADD' + i);
- i++;
- }
- },
- onchange: function() {
- var text_content = this.getFieldValue("APIKEY");
- if (text_content.length > 50) {
- this.setFieldValue(text_content.substring(0,50),"APIKEY")
- }
- }
- };
- Blockly.Blocks['NBIoT_network_connected'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(Blockly.Msg.NBIOT_NETWORK_CONNECTED)
- this.setColour(Blockly.Blocks.nbiot.HUE);
- this.setOutput(true);
- }
- }
- Blockly.Blocks['NBIoT_powered_on'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(Blockly.Msg.NBIOT_IS_POWERON)
- this.setColour(Blockly.Blocks.nbiot.HUE);
- this.setOutput(true);
- }
- }
- Blockly.Blocks['NBIoT_network_IP'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(Blockly.Msg.NBIOT_NETWORK_IP)
- this.setColour(Blockly.Blocks.nbiot.HUE);
- this.setOutput(true, Blockly.Types.TEXT.output);
- },
- getBlockType: function() {
- return Blockly.Types.TEXT;
- }
- }
- Blockly.Blocks['NBIoT_http_cococloud_get'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(Blockly.Msg.NBIOT_HTTP_CLOUD_GET)
- this.appendDummyInput()
- .appendField(Blockly.Msg.NBIOT_HTTP_APIKEY)
- .appendField(new Blockly.FieldTextInput("yourCloudEventAPIKey"),"APIKEY")
- // this.setColour(Blockly.Blocks.nbiot.HUE);
- // this.setPreviousStatement(true);
- // this.setNextStatement(true);
- this.setOutput(true);
- }
- }
|