Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
* Light Control Panel theme by default
* Simple Devices: schedule UI update
* Minor fixes
  • Loading branch information
sergejey committed Jan 9, 2022
1 parent 9bcb27b commit 6b713d6
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 8 deletions.
13 changes: 11 additions & 2 deletions modules/devices/devices.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -481,14 +481,14 @@ function processSubscription($event, &$details)
if ($diff < 0 || $diff >= 10 * 60) {
continue;
}
//DebMes("Checking point: ".json_encode($rec,JSON_PRETTY_PRINT),'devices_schedule');
$tmlr = strtotime($rec['LATEST_RUN']);
$diff_run = time() - $tmlr;
if ($diff_run <= 20*60) {
//DebMes("Skipping point (diff_run: $diff_run): ".json_encode($rec,JSON_PRETTY_PRINT),'devices_schedule');
continue;
}

if (!checkAccess('spoint', $rec['ID'])) continue;

$linked_object = $rec['LINKED_OBJECT'];
unset($rec['LINKED_OBJECT']);
$rec['LATEST_RUN'] = date('Y-m-d H:i:s');
Expand Down Expand Up @@ -592,6 +592,10 @@ function admin(&$out)
$this->manage_groups($out);
}

if ($this->view_mode == 'schedule') {
$this->manage_schedule($out);
}

if ($this->view_mode == 'edit_devices') {
$this->edit_devices($out, $this->id);
}
Expand Down Expand Up @@ -629,6 +633,11 @@ function manage_groups(&$out)
require(dirname(__FILE__) . '/devices_manage_groups.inc.php');
}

function manage_schedule(&$out)
{
require(dirname(__FILE__) . '/devices_manage_schedule.inc.php');
}

/**
* FrontEnd
*
Expand Down
48 changes: 48 additions & 0 deletions modules/devices/devices_manage_schedule.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

$out['ALL_DEVICES'] = SQLSelect("SELECT ID, TITLE FROM devices ORDER BY TITLE");

$days=array(
array('VALUE'=>0,'TITLE'=>LANG_WEEK_SUN),
array('VALUE'=>1,'TITLE'=>LANG_WEEK_MON),
array('VALUE'=>2,'TITLE'=>LANG_WEEK_TUE),
array('VALUE'=>3,'TITLE'=>LANG_WEEK_WED),
array('VALUE'=>4,'TITLE'=>LANG_WEEK_THU),
array('VALUE'=>5,'TITLE'=>LANG_WEEK_FRI),
array('VALUE'=>6,'TITLE'=>LANG_WEEK_SAT),
);

//$point=SQLSelectOne("SELECT * FROM devices_scheduler_points WHERE ID=".(int)$point_id);
//$devices = SQLSelect("SELECT devices.* FROM devices")
$tmp = array_map('current',SQLSelect("SELECT DEVICE_ID FROM devices_scheduler_points GROUP BY DEVICE_ID"));
if (is_array($tmp)) {
$devices = SQLSelect("SELECT * FROM devices WHERE ID IN (".implode(',',$tmp).") ORDER BY devices.TITLE");
$total = count($devices);
for($i=0;$i<$total;$i++) {
$points=SQLSelect("SELECT * FROM devices_scheduler_points WHERE DEVICE_ID=".(int)$devices[$i]['ID']);
foreach($points as &$point_item) {
$point_days=explode(',',$point_item['SET_DAYS']);
$point_days_title=array();
foreach($days as $k=>$v) {
if (in_array($v['VALUE'],$point_days)) {
$point_days_title[]=$v['TITLE'];
}
}
$rule=SQLSelectOne("SELECT ID FROM security_rules WHERE OBJECT_TYPE='spoint' AND OBJECT_ID=".$point_item['ID']);
if ($rule['ID']) {
$point_item['HAS_RULE']=1;
}
/*
foreach($out['SHOW_METHODS'] as $method) {
if ($method['NAME']==$point_item['LINKED_METHOD']) {
$point_item['LINKED_METHOD']=$method['DESCRIPTION'];
break;
}
}
*/
$point_item['SET_DAYS']=implode(', ',$point_days_title);
}
$devices[$i]['POINTS']=$points;
}
$out['DEVICES']=$devices;
}
4 changes: 4 additions & 0 deletions modules/devices/devices_schedule.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@
}
}
$point_item['SET_DAYS']=implode(', ',$point_days_title);
$rule=SQLSelectOne("SELECT ID FROM security_rules WHERE OBJECT_TYPE='spoint' AND OBJECT_ID=".$point_item['ID']);
if ($rule['ID']) {
$point_item['HAS_RULE']=1;
}
}
$out['POINTS']=$points;
}
Expand Down
6 changes: 5 additions & 1 deletion modules/panel.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ function run()
global $session;
Define('ALTERNATIVE_TEMPLATES', 'templates_alt');

if (isset($_COOKIE['theme'])) $out['PANEL_THEME']=$_COOKIE['theme'];
if (isset($_COOKIE['theme'])) {
$out['PANEL_THEME']=$_COOKIE['theme'];
} else {
$out['PANEL_THEME']='light';
}

if (gr('toggleLeftPanel')) {
if (gg('HideLeftPanelAdmin')) {
Expand Down
3 changes: 3 additions & 0 deletions modules/plans/plans.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ function edit_plans(&$out, $id)
function getPreview($id) {
$out = array();
$rec=SQLSelectOne("SELECT * FROM plans WHERE ID=".(int)$id);

if (!$rec['ID']) return "Plan ID=$id not found.";

$states = SQLSelect("SELECT * FROM plan_states WHERE PLAN_ID=".(int)$rec['ID']);
foreach($states as &$state) {
$this->processState($state);
Expand Down
17 changes: 17 additions & 0 deletions templates/devices/action_admin.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
[#if VIEW_MODE!="edit_devices"#]
<ul class="nav nav-tabs">
<li [#if VIEW_MODE=""#]class="active"[#endif VIEW_MODE#]><a href="?"><#LANG_DEVICES#></a></li>
<li [#if VIEW_MODE="schedule"#]class="active"[#endif VIEW_MODE#]><a href="?view_mode=schedule"><#LANG_DEVICES_SCHEDULE#></a></li>
<li [#if VIEW_MODE="manage_rooms"#]class="active"[#endif VIEW_MODE#]><a href="?view_mode=manage_rooms"><#LANG_ROOMS#></a></li>
<li [#if VIEW_MODE="manage_groups"#]class="active"[#endif VIEW_MODE#]><a href="?view_mode=manage_groups"><#LANG_GROUPS#></a></li>
</ul>
<div>&nbsp;</div>
[#endif VIEW_MODE#]

<!-- action usual -->
<!-- table devices search -->
Expand All @@ -9,6 +18,14 @@
[#inc devices_mange_groups.html#]
[#endif VIEW_MODE#]

[#if VIEW_MODE="schedule"#]
[#inc devices_schedule.html#]
[#endif VIEW_MODE#]

[#if VIEW_MODE="manage_rooms"#]
[#module name="locations" action="admin"#]
[#endif VIEW_MODE#]

[#if VIEW_MODE="quick_edit"#]
[#inc devices_quick_edit.html#]
[#endif VIEW_MODE#]
Expand Down
14 changes: 13 additions & 1 deletion templates/devices/devices_edit_schedule.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
</thead>
[#begin POINTS#]
<tr>
<td>[#SET_TIME#]</td>
<td>[#SET_TIME#]
[#if HAS_RULE#]
<i class="glyphicon glyphicon-lock"></i>
[#endif#]
</td>
<td>[#SET_DAYS#]</td>
<td>[#LINKED_METHOD#]</td>
<td>[#LATEST_RUN#]</td>
Expand Down Expand Up @@ -61,6 +65,14 @@
[#end DAYS#]
</div>
</div>
[#if POINT_ID!=""#]
<div class="form-group">
<label class="control-label col-sm-2"><#LANG_ACCESS_CONTROL#>:<#LANG_HCB#>access_control<#LANG_HCE#></label>
<div class="col-sm-4">
<a href="?(panel:{action=security_rules})&object_type=spoint&object_id=<#POINT_ID#>&print=1" onClick="return openModalTWindow('security', '<#LANG_ACCESS_CONTROL#>', this.href, 800, 600);" target=_blank><#LANG_SET#></a>
</div>
</div>
[#endif POINT_ID#]
<div class="form-group">
<label class="control-label col-sm-2">&nbsp;</label>
<div class="col-sm-4">
Expand Down
3 changes: 0 additions & 3 deletions templates/devices/devices_mange_groups.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@
<input type="hidden" name="id" value="<#ID#>">
</form>
[#else GROUP_ID#]
<p>
<a href="?">&lt;&lt;&lt; <#LANG_BACK#></a>
</p>
<p>
<a href="?view_mode=<#VIEW_MODE#>&id=new" class="btn btn-default"><i class="glyphicon glyphicon-plus"></i> <#LANG_ADD#></a>
</p>
Expand Down
46 changes: 46 additions & 0 deletions templates/devices/devices_schedule.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<p><a href="#" class="btn btn-default" id="new_schedule_link" onclick="$('#new_schedule_link').hide();$('#new_schedule').show();"><i class="glyphicon glyphicon-plus"></i> <#LANG_ADD#></a>
<div id="new_schedule" style="display:none">
<form method="get" action="?">
<div class="form-group">
<select name="id" onchange="this.form.submit();" class="form-control">
<option value="0"><#LANG_DEVICES#></option>
[#begin ALL_DEVICES#]
<option value="[#ID#]">[#TITLE#]</option>
[#end ALL_DEVICES#]
</select>
</div>
<input type="hidden" name="view_mode" value="edit_devices">
<input type="hidden" name="tab" value="schedule">
</form>
</div>
</p>

<table class="table">
[#begin DEVICES#]
<tr>
<td><a href="?view_mode=edit_devices&id=[#ID#]&tab=schedule">[#TITLE#]</a></td>
<td>

<table class="table table-striped">
[#begin POINTS#]
<tr>
<td>
<a href="?id=<#DEVICES.ID#>&view_mode=edit_devices&tab=schedule&point_id=[#ID#]">[#SET_TIME#]</a>
[#if HAS_RULE#]
<i class="glyphicon glyphicon-lock"></i>
[#endif#]
</td>
<td>[#SET_DAYS#]</td>
<td>[#LINKED_METHOD#]</td>
<td>
<a href="?id=<#DEVICES.ID#>&view_mode=edit_devices&tab=schedule&point_id=[#ID#]" class="btn btn-default btn-sm"><#LANG_EDIT#></a>
<a href="?id=<#DEVICES.ID#>&view_mode=edit_devices&tab=schedule&delete_id=[#ID#]" onclick="return confirm('<#LANG_ARE_YOU_SURE#>');" class="btn btn-default btn-sm"><#LANG_DELETE#></a>
</td>
</tr>
[#end POINTS#]
</table>

</td>
</tr>
[#end DEVICES#]
</table>
2 changes: 1 addition & 1 deletion templates/devices/devices_search_admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

<div class="form-group ">
<select name="location_id" class="form-control" onchange="this.form.submit();">
<option value=""><#LANG_LOCATION#>
<option value=""><#LANG_ROOMS#>
[#begin LOCATIONS#]<option value="[#ID#]"[#if ID="<#LOCATION_ID#>"#] selected[#endif#]>[#TITLE#] ([#TOTAL#])
[#end LOCATIONS#]
<option value="manage_locations">[ <#LANG_ADD#> / <#LANG_EDIT#> ]</option>
Expand Down
2 changes: 2 additions & 0 deletions templates/panel_js_scripts.html
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@
filterModules();
});

$('.sp-container').remove();

}
});
return false;
Expand Down

0 comments on commit 6b713d6

Please sign in to comment.