FTP to GIT sync

This commit is contained in:
JonatanRek 2019-08-24 13:13:04 +02:00
parent 1ea7e600c2
commit aa8235c1bf
12 changed files with 169 additions and 85 deletions

View File

@ -3,11 +3,11 @@ class DeviceManager{
public static $devices; public static $devices;
function getAllDevices () { function getAllDevices () {
return Db::loadAll ("SELECT * FROM devices"); return Db::loadAll ("SELECT * FROM devices WHERE approved != ?", Array(2));
} }
function getAllDevicesInRoom ($roomId = "") { function getAllDevicesInRoom ($roomId = "") {
return Db::loadAll ("SELECT * FROM devices WHERE room_id = ?", Array($roomId)); return Db::loadAll ("SELECT * FROM devices WHERE room_id = ? AND approved != ?", Array($roomId, 2));
} }
function getOtherDevices(){ function getOtherDevices(){

View File

@ -70,5 +70,11 @@ class RecordManager{
Db::command ('DELETE FROM records WHERE time < ADDDATE(NOW(), INTERVAL -? DAY);', array($day)); Db::command ('DELETE FROM records WHERE time < ADDDATE(NOW(), INTERVAL -? DAY);', array($day));
} }
} }
//TODO: zkontrolovat jestli neco nezbilo po smazaní
public static function cleanSubdeviceRecords ($subDeviceId) {
Db::command ('DELETE FROM records WHERE subdevice_id = ?);', array($subDeviceId));
}
} }
?> ?>

View File

@ -1,55 +1,61 @@
<?php <?php
class SubDeviceManager class SubDeviceManager
{ {
public static $devices; public static $devices;
public function getAllSubDevices($deviceId) public function getAllSubDevices($deviceId)
{ {
return Db::loadAll("SELECT * FROM subdevices WHERE device_id = ?", array($deviceId)); return Db::loadAll("SELECT * FROM subdevices WHERE device_id = ?", array($deviceId));
} }
public function getSubDeviceMaster($subDeviceId) public function getSubDeviceMaster($subDeviceId)
{ {
return Db::loadOne("SELECT * FROM devices WHERE device_id = (SELECT device_id FROM subdevices WHERE subdevice_id = ?)", array($subDeviceId)); return Db::loadOne("SELECT * FROM devices WHERE device_id = (SELECT device_id FROM subdevices WHERE subdevice_id = ?)", array($subDeviceId));
} }
public function getSubDeviceByMaster($deviceId, $subDeviceType = null) public function getSubDeviceByMaster($deviceId, $subDeviceType = null)
{ {
if ($subDeviceType == null) { if ($subDeviceType == null) {
return Db::loadOne("SELECT * FROM subdevices WHERE device_id = ?;", array($deviceId)); return Db::loadOne("SELECT * FROM subdevices WHERE device_id = ?;", array($deviceId));
} else { } else {
return Db::loadOne("SELECT * FROM subdevices WHERE device_id = ? AND type = ?;", array($deviceId, $subDeviceType)); return Db::loadOne("SELECT * FROM subdevices WHERE device_id = ? AND type = ?;", array($deviceId, $subDeviceType));
} }
} }
public function getSubDeviceByMasterAndType($deviceId, $subDeviceType = null) public function getSubDeviceByMasterAndType($deviceId, $subDeviceType = null)
{ {
if (!empty($subDeviceType)) { if (!empty($subDeviceType)) {
return Db::loadOne("SELECT * FROM subdevices WHERE device_id = ?;", array($deviceId)); return Db::loadOne("SELECT * FROM subdevices WHERE device_id = ?;", array($deviceId));
} else { } else {
return Db::loadOne("SELECT * FROM subdevices WHERE device_id = ? AND type = ?;", array($deviceId, $subDeviceType)); return Db::loadOne("SELECT * FROM subdevices WHERE device_id = ? AND type = ?;", array($deviceId, $subDeviceType));
} }
} }
public function getSubDevice($subDeviceId) public function getSubDevice($subDeviceId)
{ {
return Db::loadOne("SELECT * FROM subdevices WHERE subdevice_id = ?;", array($subDeviceId)); return Db::loadOne("SELECT * FROM subdevices WHERE subdevice_id = ?;", array($subDeviceId));
} }
//check if dubdevice exist //check if dubdevice exist
public function create($deviceId, $type, $unit) public function create($deviceId, $type, $unit)
{ {
$record = array( $record = array(
'device_id' => $deviceId, 'device_id' => $deviceId,
'type' => $type, 'type' => $type,
'unit' => $unit, 'unit' => $unit,
); );
try { try {
Db::add('subdevices', $record); Db::add('subdevices', $record);
} catch (PDOException $error) { } catch (PDOException $error) {
echo $error->getMessage(); echo $error->getMessage();
die(); die();
} }
} }
public function remove($subDeviceId)
{
RecordManager::cleanSubdeviceRecords($subDeviceId);
return Db::loadAll("DELETE FROM subdevices WHERE subdevice_id = ?", array($subDeviceId));
}
} }

View File

@ -2953,4 +2953,19 @@ h6 {
.is-inactive { .is-inactive {
opacity: .4; opacity: .4;
} }
.noselect {
-webkit-touch-callout: none; /* iOS Safari */
-webkit-user-select: none; /* Safari */
-khtml-user-select: none; /* Konqueror HTML */
-moz-user-select: none; /* Firefox */
-ms-user-select: none; /* Internet Explorer/Edge */
user-select: none; /* Non-prefixed version, currently
supported by Chrome and Opera */
-moz-user-select: none; /* Firefox */
-ms-user-select: none; /* Internet Explorer */
-khtml-user-select: none; /* KHTML browsers (e.g. Konqueror) */
-webkit-user-select: none; /* Chrome, Safari, and Opera */
-webkit-touch-callout: none; /* Disable Android and iOS callouts*/
}
/*# sourceMappingURL=main.css.map */ /*# sourceMappingURL=main.css.map */

View File

@ -30,8 +30,7 @@
</div> </div>
</div> </div>
<div class="col-md-9 main-body"> <div class="col-md-9 main-body">
<a href="#modal" class="button is-primary m-1">Add Device</a> <a onClick="$('#modal').removeClass('modal-container-hiden').show();" class="button is-primary m-1">Add Device</a>
<a id="remove" class="button m-1"><i class="fa fa-trash" aria-hidden="true"></i></a>
<div class="row no-gutters"> <div class="row no-gutters">
<?php foreach ($DASHBOARD as $dashboardItemId => $dashboardItemData) { <?php foreach ($DASHBOARD as $dashboardItemId => $dashboardItemData) {
$partialDeviceButton = new Partial('dashboardButton'); $partialDeviceButton = new Partial('dashboardButton');
@ -45,7 +44,9 @@
<div class="modal-container modal-container-hiden" id="modal"> <div class="modal-container modal-container-hiden" id="modal">
<div class="modal"> <div class="modal">
<a href=""><i class="fa fa-times close"></i></a> <div class="close">
<i class="fa fa-times"></i>
</div>
<h4 class="mb-4">Modal bitch</h4> <h4 class="mb-4">Modal bitch</h4>
<form method="post" action="controls/dashboard.php"> <form method="post" action="controls/dashboard.php">
<div class="field px-2"> <div class="field px-2">

View File

@ -0,0 +1,54 @@
<div class="col-12 col-md-6 col-xl-4 square-wrap">
<div class="rectangle-2">
<div class="square-content double <?php echo ($AUTOMATIONDATA['active'] == 0 ? 'paused' : ''); ?>" id="automation-<?php echo $AUTOMATIONID; ?>">
<div class="row">
<div class="col-1">
<h5 class="fa">
<?php
//echo $AUTOMATIONDATA['ifSomething'];
switch ($AUTOMATIONDATA['ifSomething']) {
case 'sunSet':
echo'&#xf186';
break;
case 'sunRise':
echo'&#xf185 ';
break;
case 'inHome':
echo'&#xf090';
break;
case 'outHome':
echo'&#xf08b';
break;
case 'outDevice':
echo'&#xf2db';
break;
default:
echo'&#xf017';
break;
}
?>
</h5>
</div>
<div class="col">
<h5 class="text-right break-all">
<?php
if (!in_array($AUTOMATIONDATA['ifSomething'], ["sunRise", "sunSet"])) {
echo $AUTOMATIONDATA['ifSomething'];
}
?>
</h5>
</div>
</div>
<div class="row">
<div class="col">
<?php echo implode(', ',$AUTOMATIONDATA['onDays']);?>
</div>
</div>
</div>
</div>
</div>

View File

@ -1,8 +1,7 @@
<div class="col-4 col-sm-3 col-xl-2 square-wrap"> <div class="col-4 col-sm-3 col-xl-2 square-wrap">
<div class="square"> <div class="square">
<div class="square-content" id="device-<?php echo $DASHBOARDITEMDATA['masterId'] ?>" onClick="ajaxPost('./ajax.php',{subDevice_id:'<?php echo $DASHBOARDITEMDATA['id']; ?>'}, this);"> <div class="square-content" id="device-<?php echo $DASHBOARDITEMDATA['masterId'] ?>" onClick="ajaxPost('ajax',{subDevice_id:'<?php echo $DASHBOARDITEMDATA['id']; ?>'}, this);">
<div class="content"> <div class="content">
<div class="delete">delete</div>
<div class="row"> <div class="row">
<div class="col"> <div class="col">
<h5 class="fa">&#x<?php echo $DASHBOARDITEMDATA['icon'] ?></h5> <h5 class="fa">&#x<?php echo $DASHBOARDITEMDATA['icon'] ?></h5>

View File

@ -0,0 +1,22 @@
<div class="col-12 col-md-6 col-xl-4 square-wrap noselect">
<div class="rectangle-2">
<div class="square-content double" id="scene-<?php echo $SCENEID ?>" onClick="ajaxPost('ajax',{scene_id:'<?php echo $SCENEID; ?>'}, this);" >
<div class="row">
<div class="col-1">
<h5 class="fa noselect">
&#x<?php echo $SCENEDATA['icon']; ?>
</h5>
</div>
<div class="col">
<h5 class="text-right break-all noselect">
<?php echo $SCENEDATA['name']; ?>
</h5>
</div>
</div>
<div class="row">
<div class="col">
</div>
</div>
</div>
</div>
</div>

View File

@ -30,40 +30,23 @@
</div> </div>
</div> </div>
<div class="col-md-9 main-body"> <div class="col-md-9 main-body">
<a class="button is-primary m-2" onClick="$('#modal').removeClass('modal-container-hiden').show();"><?php echo $LANG['t_createScene'];?></a> <a class="button is-primary m-1" onClick="$('#modal').removeClass('modal-container-hiden').show();"><?php echo $LANG['t_createScene'];?></a>
<div class="row no-gutters"> <div class="row no-gutters">
<?php foreach ($SCENES as $sceneId => $sceneData) { ?> <?php foreach ($SCENES as $sceneId => $sceneData) {
<div class="col-12 col-md-6 col-xl-4 square-wrap"> //BUTTON
<div class="rectangle-2"> $partialScenButton = new Partial('sceneButton');
<div class="square-content double" id="scene-<?php echo $sceneId ?>" onClick="ajaxPost('ajax',{scene_id:'<?php echo $sceneId; ?>'}, this);" > $partialScenButton->prepare('lang', $LANG);
<div class="row"> $partialScenButton->prepare('sceneId', $sceneId);
<div class="col-1"> $partialScenButton->prepare('sceneData', $sceneData);
<h5 class="fa">
&#x<?php echo $sceneData['icon']; ?> $partialScenButton->render();
</h5>
</div>
<div class="col">
<h5 class="text-right break-all">
<?php echo $sceneData['name']; ?>
</h5>
</div>
</div>
<div class="row">
<div class="col">
</div>
</div>
</div>
</div>
</div>
<?php
// Edit // Edit
$partialSceneEdit = new Partial('sceneEdit'); $partialSceneEdit = new Partial('sceneEdit');
$partialSceneEdit->prepare('lang',$LANG); $partialSceneEdit->prepare('lang',$LANG);
$partialSceneEdit->prepare('sceneId',$sceneId); $partialSceneEdit->prepare('sceneId',$sceneId);
$partialSceneEdit->prepare('scene',$sceneData); $partialSceneEdit->prepare('scene',$sceneData);
$partialSceneEdit->render(); $partialSceneEdit->render();
?> ?>
<?php } ?> <?php } ?>
@ -77,11 +60,13 @@
$partial->prepare('setStateFormDevices',$SETSTATEFORMDEVICES ); $partial->prepare('setStateFormDevices',$SETSTATEFORMDEVICES );
$partial->prepare('sceneIcon',$SCENEICON ); $partial->prepare('sceneIcon',$SCENEICON );
$partial->prepare('SceneName',$SCENENAME ); $partial->prepare('SceneName',$SCENENAME );
$partial->render(); $partial->render();
} else { } else {
$partial = new Partial('sceneCreate'); $partial = new Partial('sceneCreate');
$partial->prepare('lang',$LANG); $partial->prepare('lang',$LANG);
$partial->prepare('subDevices',$SUBDEVICES); $partial->prepare('subDevices',$SUBDEVICES);
$partial->render(); $partial->render();
} }
$partial = new Partial('footer'); $partial = new Partial('footer');

View File

@ -27,9 +27,6 @@
<div class="nav-item"> <div class="nav-item">
<a href="scene"><i class="fa fa-terminal" aria-hidden="true"></i><span><?php echo $LANG['m_scenes']?></span></a> <a href="scene"><i class="fa fa-terminal" aria-hidden="true"></i><span><?php echo $LANG['m_scenes']?></span></a>
</div> </div>
<div class="nav-item">
<a href="rooms"><i class="fa fa-terminal" aria-hidden="true"></i><span>ROOMS</span></a>
</div>
</div> </div>
</div> </div>
<div class="col-md-9 main-body"> <div class="col-md-9 main-body">
@ -53,8 +50,9 @@
</div> </div>
</div> </div>
<div class="col-12 col-sm-9 mx-auto mt-4"> <div class="col-12 col-sm-9 mx-auto mt-4">
<div class="label">Testovavcí Nastavení</div>
<div class="field"> <div class="field">
<button id="enable-features" class="button">Enable Alpha Feature</button> <a href="rooms" class="button">ROOMS</a>
</div> </div>
</div> </div>
</div> </div>

View File

@ -93,10 +93,7 @@ class Home extends Template
} }
$subDevices[$subDeviceData['subdevice_id']] = [ $subDevices[$subDeviceData['subdevice_id']] = [
'data' => $data,
'events'=> $events, 'events'=> $events,
'labels' => $labels,
'range' => RANGES[$subDevice['type']],
'type' => $subDeviceData['type'], 'type' => $subDeviceData['type'],
'unit' => $subDeviceData['unit'], 'unit' => $subDeviceData['unit'],
'comError' => $connectionError, 'comError' => $connectionError,
@ -125,6 +122,7 @@ class Home extends Template
'room' => $deviceData['room_id'], 'room' => $deviceData['room_id'],
'token' => $deviceData['token'], 'token' => $deviceData['token'],
'sleepTime' => $deviceData['sleep_time'], 'sleepTime' => $deviceData['sleep_time'],
'approved' => $deviceData['approved'],
'permission' => $permissionArray, 'permission' => $permissionArray,
'owner' => $deviceData['owner'], 'owner' => $deviceData['owner'],
'userIsAdmin' => $userIsDeviceAdmin, 'userIsAdmin' => $userIsDeviceAdmin,

View File

@ -27,7 +27,7 @@ class Scene extends Template
$scenes[$sceneData['scene_id']] = [ $scenes[$sceneData['scene_id']] = [
"name" => $sceneData['name'], "name" => $sceneData['name'],
"icon" => $sceneData['icon'], "icon" => $sceneData['icon'],
"do_something" => $doSomething, "doSomething" => $doSomething,
]; ];
} }