Skip to content

Commit

Permalink
Device actions improvements
Browse files Browse the repository at this point in the history
* Show total methods customized for device in the list
* Improve navigation between methods in device actions tab
  • Loading branch information
sergejey committed Jun 22, 2023
1 parent 469f59a commit 22156ae
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 20 deletions.
48 changes: 33 additions & 15 deletions modules/devices/devices_edit.inc.php
Expand Up @@ -65,40 +65,44 @@

if ($this->tab == 'logic') {

$method_name = gr('method');
if (!$method_name) {
$method_name = 'logicAction';
}

$out['METHOD'] = $method_name;
$method_name = gr('method');

$object = getObject($rec['LINKED_OBJECT']);


$methods = $object->getParentMethods($object->class_id, '', 1);
$total = count($methods);
for ($i = 0; $i < $total; $i++) {
if ($methods[$i]['TITLE'] == $out['METHOD']) {
$methods[$i]['SELECTED'] = 1;
}
if ($methods[$i]['DESCRIPTION'] != '') {
$methods[$i]['DESCRIPTION'] = $methods[$i]['TITLE'] . ' - ' . $methods[$i]['DESCRIPTION'];
} else {
$methods[$i]['DESCRIPTION'] = $methods[$i]['TITLE'];
}
if (isset($object_rec['ID'])) {
$object_method = SQLSelectOne("SELECT * FROM methods WHERE TITLE='".$methods[$i]['TITLE']."' AND OBJECT_ID=".$object_rec['ID']." ORDER BY TITLE");
if (isset($object_method['ID'])) {
$methods[$i]['DESCRIPTION'].=' (*)';
if (!$method_name) {
$method_name = $object_method['TITLE'];
}
}
}

}

if (!$method_name) {
$method_name = 'logicAction';
}

$out['METHOD'] = $method_name;
$out['METHODS'] = $methods;

$method_id = $object->getMethodByName($method_name, $object->class_id, $object->id);

$method_rec = SQLSelectOne("SELECT * FROM methods WHERE ID=" . (int)$method_id);

if ($method_rec['OBJECT_ID'] != $object->id) {
$method_rec = array();
$method_rec['OBJECT_ID'] = $object->id;
$method_rec['TITLE'] = $method_name;
$method_rec['CALL_PARENT'] = 1;
$method_rec['ID'] = SQLInsert('methods', $method_rec);
$method_rec['CODE'] = '';
}

if (defined('SETTINGS_CODEEDITOR_TURNONSETTINGS')) {
Expand All @@ -108,7 +112,16 @@
}

if ($this->mode == 'update') {
global $code;

if ($method_rec['OBJECT_ID'] != $object->id) {
$method_rec = array();
$method_rec['OBJECT_ID'] = $object->id;
$method_rec['TITLE'] = $method_name;
$method_rec['CALL_PARENT'] = 1;
$method_rec['ID'] = SQLInsert('methods', $method_rec);
}

$code = gr('code');

$old_code = $method_rec['CODE'];
$method_rec['CODE'] = $code;
Expand All @@ -129,6 +142,11 @@
$out['ERR_OLD_CODE'] = $old_code;
$ok = 0;
}
} else {
if ($method_rec['ID']) {
SQLExec("DELETE FROM methods WHERE ID=".$method_rec['ID']);
}
$this->redirect("?id=".$rec['ID']."&view_mode=".$this->view_mode."&tab=".$this->tab."&method=".urlencode($method_rec['TITLE']));
}
if ($ok) {
SQLUpdate('methods', $method_rec);
Expand Down
4 changes: 4 additions & 0 deletions modules/devices/devices_search.inc.php
Expand Up @@ -156,6 +156,10 @@
if ($linked['TOTAL']) {
$res[$i]['LINKED'] = $linked['TOTAL'];
}
$methods = SQLSelectOne("SELECT COUNT(*) AS TOTAL FROM methods WHERE CODE!='' AND OBJECT_ID=".(int)$object_rec['ID']);
if ($methods['TOTAL']) {
$res[$i]['METHODS'] = $methods['TOTAL'];
}
}
$out['RESULT'] = $res;
}
Expand Down
2 changes: 1 addition & 1 deletion templates/devices/devices_edit_logic.html
Expand Up @@ -42,7 +42,7 @@
<form action="?" method="get" class="form">
<select name="method" onchange="this.form.submit();" class="form-control">
[#begin METHODS#]
<option value="[#TITLE#]" [#if SELECTED="1"#] selected[#endif#]><#LANG_METHOD#>: [#DESCRIPTION#]</option>
<option value="[#TITLE#]" [#if TITLE="<#METHOD#>"#] selected[#endif#]><#LANG_METHOD#>: [#DESCRIPTION#]</option>
[#end METHODS#]
</select>
<input type="hidden" name="id" value="<#ID#>">
Expand Down
6 changes: 2 additions & 4 deletions templates/devices/devices_search_admin.html
Expand Up @@ -170,13 +170,11 @@ <h3><a href="?view_mode=manage_rooms&location_id=[#LOCATION_ID#]">[#LOCATION_TIT
[#endif LINKED_MODULES#]
</div>
<div class="col-md-3" nowrap>
[#if "<#ACTION#>"=="admin"#]
<a href="?view_mode=edit_devices&id=[#ID#]" class="btn btn-default" title="Edit"><i class="glyphicon glyphicon-pencil"></i></a>
<a href="?view_mode=edit_devices&id=[#ID#]&tab=settings" class="btn btn-default" title="Edit"><i class="glyphicon glyphicon-wrench"></i></a>
<a href="?view_mode=edit_devices&id=[#ID#]&tab=links" class="btn btn-default" title="Edit"><i class="glyphicon glyphicon-link"></i>[#if LINKED!=""#] ([#LINKED#])[#endif#]</a>
<a href="?view_mode=edit_devices&id=[#ID#]&tab=logic" class="btn btn-default" title="Edit"><i class="glyphicon glyphicon-flash"></i></a>
<a href="?view_mode=delete_devices&id=[#ID#]&location_id=<#LOCATION_ID#>&type=<#TYPE#>&group_name=<#GROUP_NAME#>" onClick="return confirm('Are you sure? Please confirm.')" class="btn btn-default" title="Delete"><i class="glyphicon glyphicon-remove"></i></a>
[#endif ACTION#]
<a href="?view_mode=edit_devices&id=[#ID#]&tab=logic" class="btn btn-default" title="Edit"><i class="glyphicon glyphicon-flash"></i>[#if METHODS!=""#] ([#METHODS#])[#endif#]</a>
<a href="?view_mode=delete_devices&id=[#ID#]&location_id=<#LOCATION_ID#>&type=<#TYPE#>&group_name=<#GROUP_NAME#>" onClick="return confirm('Are you sure? Please confirm.')" class="btn btn-default" title="Delete"><i class="glyphicon glyphicon-remove"></i></a>
</div>
</div>
[#end RESULT#]
Expand Down

0 comments on commit 22156ae

Please sign in to comment.