Skip to content

Commit ac53e70

Browse files
committed
Updates
* Devices: link on properties. * Devices: ability to copy settings to multiple devices. * Property history: paging added, export to file added.
1 parent 2d08164 commit ac53e70

File tree

7 files changed

+159
-67
lines changed

7 files changed

+159
-67
lines changed

Diff for: languages/default.php

+1
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,7 @@
11201120
// DEVICES
11211121
'DEVICES_MODULE_TITLE' => 'Simple Devices',
11221122

1123+
'DEVICES_COPY_SETTINGS' => 'Copy settings',
11231124
'DEVICES_LINKED_WARNING' => 'Please note that when linking to existing object, it will be assigned to the new class.',
11241125

11251126
'DEVICES_RELAY' => 'Relay/Switch',

Diff for: languages/ru.php

+1
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,7 @@
11171117

11181118
// DEVICES
11191119
'DEVICES_MODULE_TITLE' => 'Простые устройства',
1120+
'DEVICES_COPY_SETTINGS' => 'Копировать настройки',
11201121
'DEVICES_LINKED_WARNING' => 'Внимание: выбор существующего объекта приведёт к привязке его к новому классу.',
11211122
'DEVICES_RELAY' => 'Реле/Управляемый выключатель',
11221123
'DEVICES_DIMMER' => 'Освещение (Диммер)',

Diff for: modules/devices/devices_edit.inc.php

+67-60
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@
1414
$out['NO_NAV'] = 1;
1515
}
1616

17-
if ($rec['LINKED_OBJECT']!='') {
18-
$object_rec = SQLSelectOne("SELECT ID FROM objects WHERE TITLE='".$rec['LINKED_OBJECT']."'");
17+
if ($rec['LINKED_OBJECT'] != '') {
18+
$object_rec = SQLSelectOne("SELECT ID FROM objects WHERE TITLE='" . $rec['LINKED_OBJECT'] . "'");
1919
if ($object_rec['ID']) {
20-
$properties = SQLSelect("SELECT pvalues.*, properties.TITLE as PROPERTY FROM pvalues LEFT JOIN properties ON properties.ID=pvalues.PROPERTY_ID WHERE pvalues.OBJECT_ID=".$object_rec['ID']." AND pvalues.LINKED_MODULES!='' ORDER BY UPDATED DESC");
20+
$properties = SQLSelect("SELECT pvalues.*, properties.TITLE as PROPERTY FROM pvalues LEFT JOIN properties ON properties.ID=pvalues.PROPERTY_ID WHERE pvalues.OBJECT_ID=" . $object_rec['ID'] . " AND pvalues.LINKED_MODULES!='' ORDER BY UPDATED DESC");
2121
$total = count($properties);
22-
if ($total>0) {
23-
for($i=0;$i<$total;$i++) {
24-
$linked_modules=explode(',',$properties[$i]['LINKED_MODULES']);
25-
$properties[$i]['VALUE']=htmlspecialchars($properties[$i]['VALUE']);
26-
$properties[$i]['LINKED_MODULES']=array();
27-
foreach($linked_modules as $module) {
28-
$properties[$i]['LINKED_MODULES'][]=array('MODULE'=>$module,'PROPERTY'=>$properties[$i]['PROPERTY'],'OBJECT'=>$rec['LINKED_OBJECT']);
22+
if ($total > 0) {
23+
for ($i = 0; $i < $total; $i++) {
24+
$linked_modules = explode(',', $properties[$i]['LINKED_MODULES']);
25+
$properties[$i]['VALUE'] = htmlspecialchars($properties[$i]['VALUE']);
26+
$properties[$i]['LINKED_MODULES'] = array();
27+
foreach ($linked_modules as $module) {
28+
$properties[$i]['LINKED_MODULES'][] = array('MODULE' => $module, 'PROPERTY' => $properties[$i]['PROPERTY'], 'OBJECT' => $rec['LINKED_OBJECT']);
2929
}
30-
$out['LINKED_PROPERTIES']=$properties;
30+
$out['LINKED_PROPERTIES'] = $properties;
3131
}
3232
}
3333
}
@@ -67,27 +67,27 @@
6767

6868
$method_name = gr('method');
6969
if (!$method_name) {
70-
$method_name='logicAction';
70+
$method_name = 'logicAction';
7171
}
7272

73-
$out['METHOD']=$method_name;
73+
$out['METHOD'] = $method_name;
7474

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

7777

78-
$methods = $object->getParentMethods($object->class_id,'',1);
79-
$total=count($methods);
80-
for($i=0;$i<$total;$i++) {
81-
if ($methods[$i]['TITLE']==$out['METHOD']) {
82-
$methods[$i]['SELECTED']=1;
78+
$methods = $object->getParentMethods($object->class_id, '', 1);
79+
$total = count($methods);
80+
for ($i = 0; $i < $total; $i++) {
81+
if ($methods[$i]['TITLE'] == $out['METHOD']) {
82+
$methods[$i]['SELECTED'] = 1;
8383
}
84-
if ($methods[$i]['DESCRIPTION']!='') {
85-
$methods[$i]['DESCRIPTION'] = $methods[$i]['TITLE'].' - '.$methods[$i]['DESCRIPTION'];
84+
if ($methods[$i]['DESCRIPTION'] != '') {
85+
$methods[$i]['DESCRIPTION'] = $methods[$i]['TITLE'] . ' - ' . $methods[$i]['DESCRIPTION'];
8686
} else {
8787
$methods[$i]['DESCRIPTION'] = $methods[$i]['TITLE'];
8888
}
8989
}
90-
$out['METHODS']=$methods;
90+
$out['METHODS'] = $methods;
9191

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

@@ -100,35 +100,35 @@
100100
$method_rec['CALL_PARENT'] = 1;
101101
$method_rec['ID'] = SQLInsert('methods', $method_rec);
102102
}
103-
104-
if(defined('SETTINGS_CODEEDITOR_TURNONSETTINGS')) {
105-
$out['SETTINGS_CODEEDITOR_TURNONSETTINGS'] = SETTINGS_CODEEDITOR_TURNONSETTINGS;
106-
$out['SETTINGS_CODEEDITOR_UPTOLINE'] = SETTINGS_CODEEDITOR_UPTOLINE;
107-
$out['SETTINGS_CODEEDITOR_SHOWERROR'] = SETTINGS_CODEEDITOR_SHOWERROR;
108-
}
109-
103+
104+
if (defined('SETTINGS_CODEEDITOR_TURNONSETTINGS')) {
105+
$out['SETTINGS_CODEEDITOR_TURNONSETTINGS'] = SETTINGS_CODEEDITOR_TURNONSETTINGS;
106+
$out['SETTINGS_CODEEDITOR_UPTOLINE'] = SETTINGS_CODEEDITOR_UPTOLINE;
107+
$out['SETTINGS_CODEEDITOR_SHOWERROR'] = SETTINGS_CODEEDITOR_SHOWERROR;
108+
}
109+
110110
if ($this->mode == 'update') {
111111
global $code;
112-
113-
$old_code=$method_rec['CODE'];
114-
$method_rec['CODE'] = $code;
115-
112+
113+
$old_code = $method_rec['CODE'];
114+
$method_rec['CODE'] = $code;
115+
116116
$ok = 1;
117117
if ($method_rec['CODE'] != '') {
118118
$errors = php_syntax_error($method_rec['CODE']);
119-
120-
if ($errors) {
121-
$out['ERR_LINE'] = preg_replace('/[^0-9]/', '', substr(stristr($errors, 'php on line '), 0, 18))-2;
122-
$out['ERR_CODE'] = 1;
123-
$errorStr = explode('Parse error: ', htmlspecialchars(strip_tags(nl2br($errors))));
124-
$errorStr = explode('Errors parsing', $errorStr[1]);
125-
$errorStr = explode(' in ', $errorStr[0]);
126-
//var_dump($errorStr);
127-
$out['ERRORS'] = $errorStr[0];
128-
$out['ERR_FULL'] = $errorStr[0].' '.$errorStr[1];
129-
$out['ERR_OLD_CODE'] = $old_code;
130-
$ok = 0;
131-
}
119+
120+
if ($errors) {
121+
$out['ERR_LINE'] = preg_replace('/[^0-9]/', '', substr(stristr($errors, 'php on line '), 0, 18)) - 2;
122+
$out['ERR_CODE'] = 1;
123+
$errorStr = explode('Parse error: ', htmlspecialchars(strip_tags(nl2br($errors))));
124+
$errorStr = explode('Errors parsing', $errorStr[1]);
125+
$errorStr = explode(' in ', $errorStr[0]);
126+
//var_dump($errorStr);
127+
$out['ERRORS'] = $errorStr[0];
128+
$out['ERR_FULL'] = $errorStr[0] . ' ' . $errorStr[1];
129+
$out['ERR_OLD_CODE'] = $old_code;
130+
$ok = 0;
131+
}
132132
}
133133
if ($ok) {
134134
SQLUpdate('methods', $method_rec);
@@ -155,15 +155,22 @@
155155
if ($rec['LINKED_OBJECT'] && is_array($properties)) {
156156
$res_properties = array();
157157
$onchanges = array();
158+
$apply_others = gr('apply_others');
158159
foreach ($properties as $k => $v) {
159160
if ($v['_CONFIG_TYPE']) {
160161
if ($this->mode == 'update') {
161162
global ${$k . '_value'};
162163
if (isset(${$k . '_value'})) {
163164
if (is_array(${$k . '_value'})) {
164-
setGlobal($rec['LINKED_OBJECT'] . '.' . $k, implode(',',${$k . '_value'}));
165+
$value = implode(',', ${$k . '_value'});
165166
} else {
166-
setGlobal($rec['LINKED_OBJECT'] . '.' . $k, trim(${$k . '_value'}));
167+
$value = trim(${$k . '_value'});
168+
}
169+
setGlobal($rec['LINKED_OBJECT'] . '.' . $k, $value);
170+
if (is_array($apply_others)) {
171+
foreach($apply_others as $other_dev) {
172+
setGlobal($other_dev . '.' . $k, $value);
173+
}
167174
}
168175
}
169176
$out['OK'] = 1;
@@ -176,7 +183,7 @@
176183
$v['CONFIG_TYPE'] = $v['_CONFIG_TYPE'];
177184
$v['VALUE'] = getGlobal($rec['LINKED_OBJECT'] . '.' . $k);
178185
if ($v['CONFIG_TYPE'] == 'select' || $v['CONFIG_TYPE'] == 'multi_select') {
179-
$selected_options = explode(',',gg($rec['LINKED_OBJECT'] . '.' . $k));
186+
$selected_options = explode(',', gg($rec['LINKED_OBJECT'] . '.' . $k));
180187
$tmp = explode(',', $v['_CONFIG_OPTIONS']);
181188
$total = count($tmp);
182189
for ($i = 0; $i < $total; $i++) {
@@ -188,7 +195,7 @@
188195
$title = $value;
189196
}
190197
$option = array('VALUE' => $value, 'TITLE' => $title);
191-
if (in_array($value,$selected_options)) $option['SELECTED']=1;
198+
if (in_array($value, $selected_options)) $option['SELECTED'] = 1;
192199
$v['OPTIONS'][] = $option;
193200
}
194201
} elseif ($v['CONFIG_TYPE'] == 'style_image') {
@@ -431,10 +438,10 @@
431438
$object_rec['DESCRIPTION'] = $rec['TITLE'];
432439
$object_rec['LOCATION_ID'] = $rec['LOCATION_ID'];
433440
$class_changed = 0;
434-
441+
435442
$class_2b_changed = 1;
436443
$tmp_class_id = $object_rec['CLASS_ID'];
437-
while(IsSet($tmp_class_id)) {
444+
while (isset($tmp_class_id)) {
438445
if ($tmp_class_id == $class_id) {
439446
$class_2b_changed = 0;
440447
break;
@@ -456,9 +463,9 @@
456463
}
457464

458465
if ($added && is_array($type_details['PROPERTIES'])) {
459-
foreach($type_details['PROPERTIES'] as $property=>$details) {
460-
if (IsSet($details['_CONFIG_DEFAULT'])) {
461-
setGlobal($object_rec['TITLE'] . '.'.$property, $details['_CONFIG_DEFAULT']);
466+
foreach ($type_details['PROPERTIES'] as $property => $details) {
467+
if (isset($details['_CONFIG_DEFAULT'])) {
468+
setGlobal($object_rec['TITLE'] . '.' . $property, $details['_CONFIG_DEFAULT']);
462469
}
463470
}
464471
}
@@ -479,7 +486,7 @@
479486
$this->addDeviceToSourceTable($out['SOURCE_TABLE'], $out['SOURCE_TABLE_ID'], $rec['ID']);
480487
}
481488

482-
$this->homebridgeSync($rec['ID'],1);
489+
$this->homebridgeSync($rec['ID'], 1);
483490

484491
if ($added) {
485492
$this->redirect("?view_mode=edit_devices&id=" . $rec['ID'] . "&tab=settings");
@@ -499,7 +506,7 @@
499506
}
500507

501508
if (!$rec['LOCATION_ID']) {
502-
$rec['LOCATION_ID']=gr('location_id','int');
509+
$rec['LOCATION_ID'] = gr('location_id', 'int');
503510
}
504511

505512

@@ -511,8 +518,8 @@
511518
if ($v['TITLE']) {
512519
$types[] = array('NAME' => $k, 'TITLE' => $v['TITLE']);
513520
}
514-
if ($k==$rec['TYPE'] && $rec['TYPE']!='') {
515-
$out['TYPE_TITLE']=$v['TITLE'];
521+
if ($k == $rec['TYPE'] && $rec['TYPE'] != '') {
522+
$out['TYPE_TITLE'] = $v['TITLE'];
516523
}
517524
}
518525

@@ -533,11 +540,11 @@
533540
if ($rec['LOCATION_ID']) {
534541
$location_rec = SQLSelectOne("SELECT ID,TITLE FROM locations WHERE ID=" . $rec['LOCATION_ID']);
535542
$out['LOCATION_TITLE'] = processTitle($location_rec['TITLE']);
536-
$other_devices = SQLSelect("SELECT ID, TITLE, ARCHIVED FROM devices WHERE LOCATION_ID=" . (int)$rec['LOCATION_ID']." ORDER BY TITLE");
543+
$other_devices = SQLSelect("SELECT ID, TITLE, ARCHIVED FROM devices WHERE LOCATION_ID=" . (int)$rec['LOCATION_ID'] . " ORDER BY TITLE");
537544
$out['OTHER_DEVICES'] = $other_devices;
538545
}
539546

540547
if ($rec['TYPE']) {
541-
$other_devices_type = SQLSelect("SELECT ID, TITLE, ARCHIVED FROM devices WHERE TYPE='" . $rec['TYPE'] . "' ORDER BY TITLE");
548+
$other_devices_type = SQLSelect("SELECT ID, TITLE, ARCHIVED, LINKED_OBJECT FROM devices WHERE TYPE='" . $rec['TYPE'] . "' ORDER BY TITLE");
542549
$out['OTHER_DEVICES_TYPE'] = $other_devices_type;
543550
}

Diff for: pChart/index.php

+66-1
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,39 @@
204204
exit;
205205
}
206206

207+
if ($_GET['export']) {
208+
$data = SQLSelect("SELECT * FROM $history_table WHERE VALUE_ID='" . $pvalue['ID'] . "' ORDER BY ADDED");
209+
//dprint($data);
210+
211+
$csv = implode("\t", array('ADDED','VALUE')) . PHP_EOL;
212+
foreach ($data as $row) {
213+
$csv .= $row['ADDED']."\t".$row['VALUE'];
214+
$csv .= PHP_EOL;
215+
}
216+
217+
$filename = 'data_'.date('Y-m-d-H_i_s').'.txt';
218+
$now = gmdate("D, d M Y H:i:s");
219+
//header("Expires: Tue, 03 Jul 2001 06:00:00 GMT");
220+
//header("Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate");
221+
//header("Last-Modified: {$now} GMT");
222+
223+
// force download
224+
header("Content-Type: application/force-download");
225+
header("Content-Type: application/octet-stream");
226+
header("Content-Type: application/download");
227+
228+
// disposition / encoding on response body
229+
header("Content-Disposition: attachment;filename={$filename}");
230+
header("Content-Transfer-Encoding: binary");
231+
232+
echo $csv;
233+
234+
235+
exit;
236+
237+
// ID, VALUE, SOURCE, ADDED
238+
}
239+
207240
echo "<html><head>";
208241
$roothtml = ROOTHTML;
209242
echo <<<FF
@@ -272,13 +305,43 @@
272305
exit;
273306
}
274307
}
308+
309+
275310
$history = array_reverse($history);
311+
312+
/*
276313
if (!$_GET['full']) {
277314
$history = array_slice($history, 0, 25);
278315
$total_values = count($history);
279316
}
317+
*/
318+
require(ROOT.'3rdparty/Paginator/Paginator.php');
319+
$page=(int)$_GET['page'];
320+
if (!$page) $page=1;
321+
322+
$on_page=20;
323+
//$limit=(($page-1)*$on_page).','.$on_page;
324+
$start_offset = (($page-1)*$on_page);
325+
//$urlPattern='?page=(:num)';
326+
$url = $_SERVER['REQUEST_URI'];
327+
$url = preg_replace('/&page=\d+/','',$url);
328+
$urlPattern=$url.'&page=(:num)';
329+
$paginator = new JasonGrimes\Paginator($total_values, $on_page, $page, $urlPattern);
330+
331+
$history = array_slice($history,$start_offset,$on_page);
332+
$total_values = count($history);
333+
334+
echo "<div class='row'><div class='col-md-1'>&nbsp;</div>";
335+
echo "<div class='col-md-5'>";
336+
echo $paginator;
337+
echo "</div>";
338+
echo "<div class='col-md-5 text-right pagination'>";
339+
echo "<a href=\"".$_SERVER['REQUEST_URI'] . "&type=1&export=1\" class='btn btn-default'><i class='glyphicon glyphicon-export'></i> ".LANG_EXPORT."</a>";
340+
echo "</div>";
341+
echo "<div class='col-md-1'>&nbsp;</div></div>";
342+
280343
echo "<table class='table table-striped'>";
281-
echo "<thead><tr><th>T</th><th>V</th><th>Src</th><th>&nbsp;</th></tr></thead>";
344+
echo "<thead><tr><th>".LANG_ADDED."</th><th>".LANG_VALUE."</th><th>Src</th><th>&nbsp;</th></tr></thead>";
282345
for ($i = 0; $i < $total_values; $i++) {
283346
//echo date('Y-m-d H:i:s', $history[$i]['UNX']);
284347
echo "<tr><td>";
@@ -305,9 +368,11 @@
305368
echo "</tr>";
306369
}
307370
echo "</table>";
371+
/*
308372
if (!$_GET['full']) {
309373
echo ' <br/><a href="' . $_SERVER['REQUEST_URI'] . '&type=1&full=1" class="btn btn-default btn-warning">Load all values</a> ';
310374
}
375+
*/
311376

312377
echo "</div></body></html>";
313378
exit;

Diff for: templates/blockly_code/blockly_code.html

-1
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,6 @@ <h4 class="modal-title">Восстановить код</h4>
543543
}
544544
$('#[#CODE_FIELD#]').val(result_code);
545545
$('#xml_code').val(JSON.stringify(devices_data));
546-
//alert(result_code);
547546
}
548547
function renderView() {
549548
$("#devices_table tr").remove();

Diff for: templates/devices/action_admin.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
<div>
115115
<b><#LANG_PROPERTIES#></b>:
116116
[#begin LINKED_PROPERTIES#]
117-
<br/>[#PROPERTY#]:
117+
<br/><a href="<#ROOTHTML#>panel/linkedobject.html?op=redirect&object=<#LINKED_OBJECT#>&sub=properties">[#PROPERTY#]</a>:
118118
[#VALUE#]
119119
[#begin LINKED_MODULES#]
120120
<a href="?(panel:{action=[#MODULE#]})&md=[#MODULE#]&go_linked_object=[#OBJECT#]&go_linked_property=[#PROPERTY#]" class="label label-success">[#MODULE#]</a>

0 commit comments

Comments
 (0)