Permalink
Browse files

Updates

* Usability update and some fixes
  • Loading branch information...
sergejey committed Jan 28, 2019
1 parent 9f4c879 commit ecbd69cd41f78a25af0488caad36eb85a7b0e12e
@@ -217,6 +217,7 @@ function usual(&$out)
if ($device && $command) {
$result = $this->sendCommand($device, $command);
$this->readValues($device);
if ($result) {
echo "OK: ".$result;
} else {
@@ -537,6 +538,9 @@ function sendCommand($id, $command, $custom = false)
}
if ($device['ID']) {
$url = 'http://' . $device['IP'] . '/' . $device['PASSWORD'] . '/?' . ($custom ? '' : 'cmd=') . $command;
if ($this->config['API_DEBUG']) {
DebMes("Sending command: $url", 'megad');
}
return getURL($url, 0);
} else {
return 0;
@@ -571,7 +575,7 @@ function restoreDeviceStatus($device_id)
$properties = SQLSelect("SELECT * FROM megadproperties WHERE DEVICE_ID=" . $device_id);
$total = count($properties);
for ($i = 0; $i < $total; $i++) {
if ($properties[$i]['COMMAND'] == 'output') {
if ($properties[$i]['COMMAND'] == 'output' && $properties[$i]['CURRENT_VALUE_STRING']) {
$this->sendCommand($properties[$i]['DEVICE_ID'], $properties[$i]['NUM'] . ':' . $properties[$i]['CURRENT_VALUE_STRING']);
if ($i < ($total - 1)) {
usleep(5000);
@@ -746,6 +750,7 @@ function dbInstall($data)
megadproperties: DEF varchar(255) NOT NULL DEFAULT ''
megadproperties: MISC varchar(255) NOT NULL DEFAULT ''
megadproperties: SKIP_DEFAULT int(3) NOT NULL DEFAULT '0'
megadproperties: COMMENT varchar(255) NOT NULL DEFAULT ''
megadproperties: UPDATED datetime
EOD;
parent::dbInstall($data);
@@ -190,6 +190,7 @@
$property['NUM'] = gr('num', 'int');
$property['ADD_NUM'] = gr('add_num', 'int');
$property['SKIP_DEFAULT'] = gr('skip_default', 'int');
$property['COMMENT'] = gr('comment');
$property['COMMAND'] = gr('command');
if (!$property['ID']) {
$property['DEVICE_ID']=$rec['ID'];
@@ -219,31 +220,36 @@
}
$out['PROPERTY_ID']=$property_id;
if ($this->mode == 'update') {
$this->readValues($rec['ID']);
//$this->readValues($rec['ID']);
}
} else {
$properties = SQLSelect("SELECT * FROM megadproperties WHERE DEVICE_ID='" . $rec['ID'] . "' ORDER BY NUM, COMMAND_INDEX, COMMAND");
$total = count($properties);
for ($i = 0; $i < $total; $i++) {
if ($properties[$i]['LINKED_OBJECT']!='') {
$object_rec=SQLSelectOne("SELECT * FROM objects WHERE TITLE='".$properties[$i]['LINKED_OBJECT']."'");
if ($object_rec['DESCRIPTION']!='') {
$properties[$i]['LINKED_OBJECT'].=' - '.$object_rec['DESCRIPTION'];
}
}
$properties = SQLSelect("SELECT * FROM megadproperties WHERE DEVICE_ID='" . $rec['ID'] . "' ORDER BY NUM, COMMAND_INDEX, COMMAND");
$total = count($properties);
for ($i = 0; $i < $total; $i++) {
if ($properties[$i]['ID']==$out['PROPERTY_ID']) {
$properties[$i]['SELECTED']=1;
}
if ($properties[$i]['LINKED_OBJECT']!='') {
$object_rec=SQLSelectOne("SELECT * FROM objects WHERE TITLE='".$properties[$i]['LINKED_OBJECT']."'");
if ($object_rec['DESCRIPTION']!='') {
$properties[$i]['LINKED_OBJECT'].=' - '.$object_rec['DESCRIPTION'];
}
}
$out['PROPERTIES'] = $properties;
}
$out['PROPERTIES'] = $properties;
}
if ($this->mode == 'clear') {
SQLExec("DELETE FROM megadproperties WHERE DEVICE_ID=".$rec['ID']);
$this->readValues($rec['ID']);
$this->readConfig($rec['ID']);
$this->redirect("?view_mode=" . $this->view_mode . "&tab=" . $this->tab . "&id=" . $rec['ID']);
}
if ($this->mode == 'getdata') {
$this->readValues($rec['ID']);
$this->readConfig($rec['ID']);
$this->redirect("?view_mode=" . $this->view_mode . "&tab=" . $this->tab . "&id=" . $rec['ID']);
}
@@ -80,7 +80,7 @@
}
$i2c_properties=SQLSelect("SELECT * FROM megadproperties WHERE DEVICE_ID='".$record['ID']."' AND COMMAND LIKE 'i2c%' ORDER BY NUM");
if ($i2c_properties[0]['ID']) {
if ($stateData!='' && $i2c_properties[0]['ID']) {
include_once(DIR_MODULES.$this->name.'/libs/i2c_com.class.php');
include_once(DIR_MODULES.$this->name.'/libs/i2c_functions.inc.php');
foreach($i2c_properties as $property) {
@@ -12,6 +12,21 @@
<!-- table megaddevices edit -->
[#if VIEW_MODE="edit_megaddevices"#]
[#if ID!=""#]

<script type="application/javascript">
function switchMegaDDevice(device_id, port, port_value, result_id) {
var url='<#ROOTHTML#>ajax/megad.html?device='+device_id+'&command='+encodeURIComponent(port+':'+port_value);
$('#'+result_id).html('...');
$.ajax({
url: url
}).done(function(data) {
$('#'+result_id).html(data);
});
return false;
}
</script>


<p><a href="?">&lt;&lt;&lt; <#LANG_BACK#></a></p>
[#if TITLE!=""#]<h4>[#TITLE#]</h4>[#endif TITLE#]
<ul class="nav nav-tabs">
@@ -11,30 +11,20 @@
</p>


<form action="?" method="post">

<table cellpadding="5" class="table table-stripped">
<tr>
<td valign="top"><#LANG_PORT#></td>
<td valign="top"><#LANG_TYPE#></td>
<td valign="top">ECMD</td>
<td valign="top"><#LANG_CURRENT_VALUE#></td>
<td valign="top"><#LANG_LINKED_OBJECT#></td>
<td valign="top"><#LANG_DETAILS#></td>
<td valign="top"><#LANG_UPDATED#></td>
<td>&nbsp;</td>

</tr>

<script type="application/javascript">
function switchDevice<#ID#>(port, port_value) {
var url='<#ROOTHTML#>ajax/megad.html?device=<#ID#>&command='+encodeURIComponent(port+':'+port_value);
$.ajax({
url: url
}).done(function(data) {
alert('RESULT: '+data);
});
return false;
}
</script>

[#begin PROPERTIES#]
<tr>
@@ -51,14 +41,20 @@
[#if TYPE="255"#]NC[#endif#]
#-->
[#if COMMAND="output"#]
<a href="#" onclick="return switchDevice[#DEVICE_ID#]([#NUM#],1);">ON</a> |
<a href="#" onclick="return switchDevice[#DEVICE_ID#]([#NUM#],0);">OFF</a>
<a href="#" onclick="return switchMegaDDevice([#DEVICE_ID#],[#NUM#],1,'result[#ID#]');">ON</a> |
<a href="#" onclick="return switchMegaDDevice([#DEVICE_ID#],[#NUM#],0,'result[#ID#]');">OFF</a>
<span id="result[#ID#]"></span>
[#endif#]
</td>
<td>[#ECMD#]</td>
<td valign="top" align="center">[#CURRENT_VALUE_STRING#]&nbsp;</td>
<td valign="top" align="center">
<div class="dynamic_content" id="value[#ID#]">
<span id="current_value[#ID#]">[#CURRENT_VALUE_STRING#]</span>
<!--/dynamic_content--></div>
</td>
<td valign="top">[#LINKED_OBJECT#]</td>
<td valign="top">[#UPDATED#]</td>
<td valign="top">[#COMMENT#]</td>
<td valign="top"><div class="dynamic_content" id="updated[#ID#]">[#UPDATED#]<!--/dynamic_content--></div></td>
<td>
<a href="?view_mode=<#VIEW_MODE#>&id=<#ID#>&tab=<#TAB#>&property_id=[#ID#]" class="btn btn-default"><i class="glyphicon glyphicon-edit"></i></a>
<a href="http://<#IP#>/<#PASSWORD#>/?pt=[#NUM#]" class="btn btn-default" target="_blank"><i class="glyphicon glyphicon-wrench"></i></a>
@@ -67,16 +63,3 @@
</tr>
[#end PROPERTIES#]
</table>
<!--#
&nbsp;<br/>
<input type="submit" name="submit" value="<#LANG_SUBMIT#>" class="btn btn-default">
<input type="hidden" name="id" value="<#ID#>">
<input type="hidden" name="view_mode" value="<#VIEW_MODE#>">
<input type="hidden" name="edit_mode" value="<#EDIT_MODE#>">
<input type="hidden" name="mode" value="update">
<input type="hidden" name="data_source" value="<#DATA_SOURCE#>">
<input type="hidden" name="tab" value="<#TAB#>">
#-->

</form>
@@ -1,4 +1,8 @@

<div class="row">


<div class="col-md-8">
<!-- Table 'megaddevices' edit -->
<form action="?" method="post" enctype="multipart/form-data" name="frmEdit" class="form-horizontal">
[#if OK#]
@@ -29,6 +33,13 @@
</div>
[#endif#]

<div class="form-group">
<label class="col-lg-3 control-label">
<#LANG_NOTES#>:
</label>
<div class="col-lg-4"><input type="text" class="form-control" name="comment" value="[#PROPERTY_COMMENT#]"></div>
</div>

[#if NEW_PROPERTY!="1"#]
<div class="form-group">
<label class="col-lg-3 control-label">
@@ -77,6 +88,29 @@
</select>
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">
<#LANG_VALUE#>:
</label>
<div class="col-lg-4">
<div class="dynamic_content" id="value[#PROPERTY_ID#]">
<span id="current_value[#PROPERTY_ID#]">[#PROPERTY_CURRENT_VALUE_STRING#]</span>
<!--/dynamic_content-->
</div>
</div>
</div>
[#if PROPERTY_COMMAND="output"#]
<div class="form-group">
<label class="col-lg-3 control-label">
&nbsp;
</label>
<div class="col-lg-4">
<a href="#" onclick="return switchMegaDDevice([#PROPERTY_DEVICE_ID#],[#PROPERTY_NUM#],1,'switchResult[#PROPERTY_ID#]');">ON</a> |
<a href="#" onclick="return switchMegaDDevice([#PROPERTY_DEVICE_ID#],[#PROPERTY_NUM#],0,'switchResult[#PROPERTY_ID#]');">OFF</a>
<span id="switchResult[#PROPERTY_ID#]"></span>
</div>
</div>
[#endif#]

[#if NEW_PROPERTY!="1"#]
<div class="form-group">
@@ -128,3 +162,20 @@
</div>
</fieldset>
</form>
</div>

<div class="col-md-4">
<table class="table">
[#begin PROPERTIES#]
<tr>
<td[#if SELECTED#] style="background-color:lightgreen"[#endif#]>
<a href="?view_mode=<#VIEW_MODE#>&id=<#ID#>&tab=<#TAB#>&property_id=[#ID#]">P [#NUM#].[#COMMAND_INDEX#]</a>
</td>
<td[#if SELECTED#] style="background-color:lightgreen"[#endif#]>[#COMMENT#]</td>
</tr>
[#end PROPERTIES#]
</table>
</div>


</div>

0 comments on commit ecbd69c

Please sign in to comment.