Skip to content

Commit 22156ae

Browse files
committed
Device actions improvements
* Show total methods customized for device in the list * Improve navigation between methods in device actions tab
1 parent 469f59a commit 22156ae

4 files changed

Lines changed: 40 additions & 20 deletions

File tree

modules/devices/devices_edit.inc.php

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,40 +65,44 @@
6565

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

68-
$method_name = gr('method');
69-
if (!$method_name) {
70-
$method_name = 'logicAction';
71-
}
7268

73-
$out['METHOD'] = $method_name;
69+
$method_name = gr('method');
7470

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

77-
7873
$methods = $object->getParentMethods($object->class_id, '', 1);
7974
$total = count($methods);
8075
for ($i = 0; $i < $total; $i++) {
81-
if ($methods[$i]['TITLE'] == $out['METHOD']) {
82-
$methods[$i]['SELECTED'] = 1;
83-
}
8476
if ($methods[$i]['DESCRIPTION'] != '') {
8577
$methods[$i]['DESCRIPTION'] = $methods[$i]['TITLE'] . ' - ' . $methods[$i]['DESCRIPTION'];
8678
} else {
8779
$methods[$i]['DESCRIPTION'] = $methods[$i]['TITLE'];
8880
}
81+
if (isset($object_rec['ID'])) {
82+
$object_method = SQLSelectOne("SELECT * FROM methods WHERE TITLE='".$methods[$i]['TITLE']."' AND OBJECT_ID=".$object_rec['ID']." ORDER BY TITLE");
83+
if (isset($object_method['ID'])) {
84+
$methods[$i]['DESCRIPTION'].=' (*)';
85+
if (!$method_name) {
86+
$method_name = $object_method['TITLE'];
87+
}
88+
}
89+
}
90+
8991
}
92+
93+
if (!$method_name) {
94+
$method_name = 'logicAction';
95+
}
96+
97+
$out['METHOD'] = $method_name;
9098
$out['METHODS'] = $methods;
9199

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

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

96104
if ($method_rec['OBJECT_ID'] != $object->id) {
97-
$method_rec = array();
98-
$method_rec['OBJECT_ID'] = $object->id;
99-
$method_rec['TITLE'] = $method_name;
100-
$method_rec['CALL_PARENT'] = 1;
101-
$method_rec['ID'] = SQLInsert('methods', $method_rec);
105+
$method_rec['CODE'] = '';
102106
}
103107

104108
if (defined('SETTINGS_CODEEDITOR_TURNONSETTINGS')) {
@@ -108,7 +112,16 @@
108112
}
109113

110114
if ($this->mode == 'update') {
111-
global $code;
115+
116+
if ($method_rec['OBJECT_ID'] != $object->id) {
117+
$method_rec = array();
118+
$method_rec['OBJECT_ID'] = $object->id;
119+
$method_rec['TITLE'] = $method_name;
120+
$method_rec['CALL_PARENT'] = 1;
121+
$method_rec['ID'] = SQLInsert('methods', $method_rec);
122+
}
123+
124+
$code = gr('code');
112125

113126
$old_code = $method_rec['CODE'];
114127
$method_rec['CODE'] = $code;
@@ -129,6 +142,11 @@
129142
$out['ERR_OLD_CODE'] = $old_code;
130143
$ok = 0;
131144
}
145+
} else {
146+
if ($method_rec['ID']) {
147+
SQLExec("DELETE FROM methods WHERE ID=".$method_rec['ID']);
148+
}
149+
$this->redirect("?id=".$rec['ID']."&view_mode=".$this->view_mode."&tab=".$this->tab."&method=".urlencode($method_rec['TITLE']));
132150
}
133151
if ($ok) {
134152
SQLUpdate('methods', $method_rec);

modules/devices/devices_search.inc.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@
156156
if ($linked['TOTAL']) {
157157
$res[$i]['LINKED'] = $linked['TOTAL'];
158158
}
159+
$methods = SQLSelectOne("SELECT COUNT(*) AS TOTAL FROM methods WHERE CODE!='' AND OBJECT_ID=".(int)$object_rec['ID']);
160+
if ($methods['TOTAL']) {
161+
$res[$i]['METHODS'] = $methods['TOTAL'];
162+
}
159163
}
160164
$out['RESULT'] = $res;
161165
}

templates/devices/devices_edit_logic.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
<form action="?" method="get" class="form">
4343
<select name="method" onchange="this.form.submit();" class="form-control">
4444
[#begin METHODS#]
45-
<option value="[#TITLE#]" [#if SELECTED="1"#] selected[#endif#]><#LANG_METHOD#>: [#DESCRIPTION#]</option>
45+
<option value="[#TITLE#]" [#if TITLE="<#METHOD#>"#] selected[#endif#]><#LANG_METHOD#>: [#DESCRIPTION#]</option>
4646
[#end METHODS#]
4747
</select>
4848
<input type="hidden" name="id" value="<#ID#>">

templates/devices/devices_search_admin.html

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,11 @@ <h3><a href="?view_mode=manage_rooms&location_id=[#LOCATION_ID#]">[#LOCATION_TIT
170170
[#endif LINKED_MODULES#]
171171
</div>
172172
<div class="col-md-3" nowrap>
173-
[#if "<#ACTION#>"=="admin"#]
174173
<a href="?view_mode=edit_devices&id=[#ID#]" class="btn btn-default" title="Edit"><i class="glyphicon glyphicon-pencil"></i></a>
175174
<a href="?view_mode=edit_devices&id=[#ID#]&tab=settings" class="btn btn-default" title="Edit"><i class="glyphicon glyphicon-wrench"></i></a>
176175
<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>
177-
<a href="?view_mode=edit_devices&id=[#ID#]&tab=logic" class="btn btn-default" title="Edit"><i class="glyphicon glyphicon-flash"></i></a>
178-
<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>
179-
[#endif ACTION#]
176+
<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>
177+
<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>
180178
</div>
181179
</div>
182180
[#end RESULT#]

0 commit comments

Comments
 (0)