Skip to content
Permalink
Browse files

Updates

* Blockly: timer setting fix
* Blockly: new section States (for operational mode conditions)
* General: Removing "spaces" for classes/objects/properties
* config.php sample update
  • Loading branch information...
sergejey committed Apr 10, 2019
1 parent c635c6d commit f5db1a87ef252fc7e2e009fe538faa2493e970df
@@ -0,0 +1,64 @@
<?php header("Content-type:application/x-javascript"); ?>
/**
* @license
* Visual Blocks Editor
*
* Copyright 2012 Google Inc.
* https://blockly.googlecode.com/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @fileoverview Variable blocks for Blockly.
* @author fraser@google.com (Neil Fraser)
*/
'use strict';

goog.provide('Blockly.Blocks.majordomo_states');

goog.require('Blockly.Blocks');

<?php
chdir(dirname(__FILE__) . '/../../../');
include_once("./config.php");
include_once("./lib/loader.php");
$session=new session("prj");
include_once("./load_settings.php");
include_once(DIR_MODULES . "control_modules/control_modules.class.php");
$objects = getObjectsByClass('OperationalModes');
foreach($objects as $object) {
$object = SQLSelectOne("SELECT * FROM objects WHERE ID=".$object['ID']);
?>

Blockly.Blocks['majordomo_<?php echo $object['TITLE']?>'] = {
init: function() {
var thisBlock = this;
this.setColour(220);
this.appendDummyInput()
.appendField('<?php echo addcslashes($object['DESCRIPTION'],"'")?>');
this.setOutput(true);
this.setTooltip('');
}
};

<?php
}
$session->save();
@@ -0,0 +1,58 @@
<?php header("Content-type:application/x-javascript"); ?>
/**
* @license
* Visual Blocks Language
*
* Copyright 2012 Google Inc.
* https://blockly.googlecode.com/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @fileoverview Generating PHP for variable blocks.
* @author fraser@google.com (Neil Fraser)
*/
'use strict';

goog.provide('Blockly.PHP.majordomo_states');

goog.require('Blockly.PHP');

<?php
chdir(dirname(__FILE__) . '/../../../../');
include_once("./config.php");
include_once("./lib/loader.php");
$session=new session("prj");
include_once("./load_settings.php");
include_once(DIR_MODULES . "control_modules/control_modules.class.php");
$objects = getObjectsByClass('OperationalModes');
foreach($objects as $object) {
$object = SQLSelectOne("SELECT * FROM objects WHERE ID=" . $object['ID']);
?>
Blockly.PHP['majordomo_<?php echo $object['TITLE']?>'] = function(block) {
var code = 'getGlobal("<?php echo $object['TITLE']?>.active")';
return [code, Blockly.PHP.ORDER_FUNCTION_CALL];
};

<?php
}
$session->save();
@@ -80,7 +80,7 @@ Blockly.PHP['majordomo_settimeout'] = function(block) {
var timer = Blockly.PHP.valueToCode(block, 'TIMER',Blockly.PHP.ORDER_NONE) || 'none';
var delay = Blockly.PHP.valueToCode(block, 'DELAY',Blockly.PHP.ORDER_NONE) || '60';
var branch = Blockly.PHP.statementToCode(block, 'DO');
branch=branch.replace(new RegExp('\n', 'g'), '');
var code = 'setTimeOut('+timer+', \''+branch+'\', (int)('+delay+'));\n';
//branch=branch.replace(new RegExp('\n', 'g'), '');
var code = '$timerCode=<<<EOT\n'+branch+'\nEOT;\nsetTimeOut('+timer+', $timerCode, (int)('+delay+'));\n';
return code;
};
@@ -22,6 +22,7 @@
<script type="text/javascript" src="blocks/majordomo.js"></script>
<script type="text/javascript" src="blocks/majordomo_objects.js"></script>
<script type="text/javascript" src="blocks/majordomo_time.js"></script>
<script type="text/javascript" src="blocks/majordomo_states.js.php"></script>
<script type="text/javascript" src="blocks/majordomo_scripts.js.php"></script>
<script type="text/javascript" src="blocks/majordomo_myblocks.js.php"></script>
<?php
@@ -34,6 +35,7 @@
<script type="text/javascript" src="generators/php/majordomo.js"></script>
<script type="text/javascript" src="generators/php/majordomo_objects.js"></script>
<script type="text/javascript" src="generators/php/majordomo_time.js"></script>
<script type="text/javascript" src="generators/php/majordomo_states.js.php"></script>
<script type="text/javascript" src="generators/php/colour.js"></script>
<script type="text/javascript" src="generators/php/lists.js"></script>
<script type="text/javascript" src="generators/php/logic.js"></script>
@@ -194,6 +196,15 @@ function init() {
</block>
</category>

<category name="<?php echo LANG_STATES;?>">
<?php
$objects=getObjectsByClass('OperationalModes');
foreach($objects as $object) {
echo "<block type=\"majordomo_".$object['TITLE']."\"></block>";
}
?>
</category>

<category name="<?php echo LANG_SECTION_OBJECTS;?>">
<block type="majordomo_getglobal">
<value name="PROPERTY">
@@ -12,6 +12,8 @@ Define('DB_NAME', 'db_terminal');
Define('DB_USER', 'root');
Define('DB_PASSWORD', '');

Define('DIR_TEMPLATES', "./templates/");
Define('DIR_MODULES', "./modules/");
Define('DEBUG_MODE', 1);
Define('UPDATES_REPOSITORY_NAME', 'smarthome');

@@ -48,9 +50,6 @@ else
}

Define('ROOT', DOC_ROOT."/");
Define('DIR_TEMPLATES', ROOT."templates/");
Define('DIR_MODULES', ROOT."modules/");

Define('ROOTHTML', "/");
Define('PROJECT_DOMAIN', isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : php_uname("n"));

@@ -66,10 +65,18 @@ Define('PROJECT_DOMAIN', isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'
/// (Optional)
//Define('DROPBOX_SHOPPING_LIST', 'c:/data/dropbox/list.txt');

//Define('USE_PROXY', '127.0.0.1:8888'); //PROXY SERVER DETAILS (optional)
//Define('USE_PROXY_AUTH', 'user:password'); //PROXY SERVER AUTH (optional)
$restart_threads=array(
'cycle_execs.php',
'cycle_main.php',
'cycle_ping.php',
'cycle_scheduler.php',
'cycle_states.php',
'cycle_webvars.php');

//Define('USE_PROXY', '127.0.0.1:8888'); //PROXY SERVER DETAILS (optional)
//Define('USE_PROXY_AUTH', 'user:password'); //PROXY SERVER AUTH (optional)

//Define('HISTORY_NO_OPTIMIZE', 1);
//Define('HISTORY_NO_OPTIMIZE', 1);

Define('GIT_URL', 'https://github.com/sergejey/majordomo/');
Define('MASTER_UPDATE_URL', GIT_URL.'archive/master.tar.gz'); // master update URL (https://github.com/sergejey/majordomo/archive/alpha.tar.gz)
@@ -134,12 +134,15 @@ function admin(&$out) {
$rec=SQLSelectOne("SELECT * FROM blockly_code WHERE SYSTEM_NAME LIKE '".DBSafe($this->system_name)."'");
$out['CODE_TYPE']=(int)$rec['CODE_TYPE'];
if ($rec['ID']) {
$out['XML']=$rec['XML'];
} elseif ($this->owner->xml) {
$out['XML']=$this->owner->xml;
if (!$rec['ID'] && $this->owner->xml) {
$rec['XML']=$this->owner->xml;
}
if (!$rec['ID']) {
$rec['CODE_TYPE']=2;
}
if ($_SERVER['REQUEST_METHOD']=='POST' && $out['TYPE']=='php') {
global $xml;
global $code;
@@ -154,18 +157,19 @@ function admin(&$out) {
if (isset(${$this->code_field."_code_type"})) {
$rec['CODE_TYPE']=(int)${$this->code_field."_code_type"};
} else {
$rec['CODE_TYPE']=1;
$rec['CODE_TYPE']=2;
}
if (!$rec['CODE_TYPE']) {
//$rec['XML']='';
}
$rec['ID']=SQLInsert('blockly_code', $rec);
$out['XML']=$rec['XML'];
$out['CODE_TYPE']=(int)$rec['CODE_TYPE'];
}
$out['XML']=$rec['XML'];
$out['CODE_TYPE']=(int)$rec['CODE_TYPE'];
$out['DEVICES']=SQLSelect("SELECT ID,TITLE,TYPE,LINKED_OBJECT FROM devices WHERE TYPE IN ('relay','dimmer','button','thermostat') ORDER BY TITLE");
if (isset($this->data_source) && !$_GET['data_source'] && !$_POST['data_source']) {
@@ -20,8 +20,8 @@
// step: default
if ($this->tab=='') {
//updating 'TITLE' (varchar, required)
global $title;
$rec['TITLE']=$title;
$rec['TITLE']=gr('title','trim');
$rec['TITLE']=str_replace(' ','',$rec['TITLE']);
if ($rec['TITLE']=='') {
$out['ERR_TITLE']=1;
$ok=0;
@@ -280,8 +280,7 @@
if ($this->mode == 'update' && $this->tab == '') {
$ok = 1;
global $title;
$rec['TITLE'] = $title;
$rec['TITLE'] = gr('title','trim');
if ($rec['TITLE'] == '') {
$out['ERR_TITLE'] = 1;
$ok = 0;
@@ -11,7 +11,7 @@
$ok=1;
//updating 'TITLE' (varchar, required)
global $title;
$rec['TITLE']=$title;
$rec['TITLE']=gr('title','trim');
if ($rec['TITLE']=='') {
$out['ERR_TITLE']=1;
$ok=0;
@@ -31,8 +31,8 @@
*/
}
//updating 'Titile' (varchar, required)
global $title;
$rec['TITLE']=$title;
$rec['TITLE']=gr('title','trim');
$rec['TITLE']=str_replace(' ','',$rec['TITLE']);
if ($rec['TITLE']=='') {
$out['ERR_TITLE']=1;
$ok=0;
@@ -16,11 +16,9 @@
// step: default
if ($this->tab == '') {
//updating 'TITLE' (varchar, required)
global $title;
$rec['TITLE'] = $title;
$rec['TITLE'] = str_replace(' ', '', trim($rec['TITLE']));
$rec['TITLE'] = gr('title','trim');
$rec['TITLE'] = str_replace(' ', '', $rec['TITLE']);
$tmp = SQLSelectOne("SELECT ID FROM objects WHERE TITLE LIKE '" . DBSafe($rec['TITLE']) . "' AND ID!=" . (int)$rec['ID']);
if ($tmp['ID']) {
@@ -122,8 +120,9 @@
}
if ($this->mode == 'update') {
global $new_property;
global $new_value;
$new_property = gr('new_property','trim');
$new_property = str_replace(' ','',$new_property);
$new_value = gr('new_value');
if ($new_property != '') {
$tmp = array();
@@ -24,8 +24,8 @@
*/
}
//updating 'Titile' (varchar, required)
global $title;
$rec['TITLE']=$title;
$rec['TITLE']=gr('title','trim');
$rec['TITLE']=str_replace(' ','',$rec['TITLE']);
if ($rec['TITLE']=='') {
$out['ERR_TITLE']=1;
$ok=0;
Oops, something went wrong.

0 comments on commit f5db1a8

Please sign in to comment.
You can’t perform that action at this time.