Some Big Changes
Co-Authored-By: Xinatorus <patrik@steelants.cz>
This commit is contained in:
parent
5e2af0fdbc
commit
e74d2095c6
@ -1,3 +1,5 @@
|
|||||||
|
var pending = false;
|
||||||
|
|
||||||
if ('serviceWorker' in navigator) {
|
if ('serviceWorker' in navigator) {
|
||||||
window.addEventListener('load', () => {
|
window.addEventListener('load', () => {
|
||||||
navigator.serviceWorker.register('serviceWorker.js')
|
navigator.serviceWorker.register('serviceWorker.js')
|
||||||
@ -14,16 +16,16 @@ if ('serviceWorker' in navigator) {
|
|||||||
$('select[name="atSelector"]').change(function(e) {
|
$('select[name="atSelector"]').change(function(e) {
|
||||||
console.log($(this).val());
|
console.log($(this).val());
|
||||||
if( $(this).val() == 'time') {
|
if( $(this).val() == 'time') {
|
||||||
|
|
||||||
$('input[name="atTime"]').prop( "disabled", false );
|
$('input[name="atTime"]').prop( "disabled", false );
|
||||||
|
|
||||||
$('select[name="atDeviceValueInt"]').prop( "disabled", true );
|
$('select[name="atDeviceValueInt"]').prop( "disabled", true );
|
||||||
$('input[name="atDeviceValue"]').prop( "disabled", true );
|
$('input[name="atDeviceValue"]').prop( "disabled", true );
|
||||||
} else if( $(this).val() == 'atDeviceValue') {
|
} else if( $(this).val() == 'atDeviceValue') {
|
||||||
|
|
||||||
$('select[name="atDeviceValue"]').prop( "disabled", false );
|
$('select[name="atDeviceValue"]').prop( "disabled", false );
|
||||||
$('input[name="atDeviceValueInt"]').prop( "disabled", false );
|
$('input[name="atDeviceValueInt"]').prop( "disabled", false );
|
||||||
|
|
||||||
$('input[name="atTime"]').prop( "disabled", true );
|
$('input[name="atTime"]').prop( "disabled", true );
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -38,7 +40,7 @@ $("div.square-content").on('touchend', function (e){
|
|||||||
$("div.square-content").on('touchstart', function (eTarget) {
|
$("div.square-content").on('touchstart', function (eTarget) {
|
||||||
navigator.vibrate([500]);
|
navigator.vibrate([500]);
|
||||||
var id = '';
|
var id = '';
|
||||||
|
|
||||||
var windowLoc = $(location).attr('pathname');
|
var windowLoc = $(location).attr('pathname');
|
||||||
windowLoc = windowLoc.substring(windowLoc.lastIndexOf("/"));
|
windowLoc = windowLoc.substring(windowLoc.lastIndexOf("/"));
|
||||||
console.log(windowLoc);
|
console.log(windowLoc);
|
||||||
@ -49,9 +51,9 @@ $("div.square-content").on('touchstart', function (eTarget) {
|
|||||||
} else if (windowLoc == "/automation") {
|
} else if (windowLoc == "/automation") {
|
||||||
id = $(this).attr('id').replace('automation-', '');
|
id = $(this).attr('id').replace('automation-', '');
|
||||||
}
|
}
|
||||||
|
|
||||||
var subId = $(this).attr('data-sub-device-id');
|
var subId = $(this).attr('data-sub-device-id');
|
||||||
|
|
||||||
touch++;
|
touch++;
|
||||||
if(touch == 2 && touchSubId == subId){
|
if(touch == 2 && touchSubId == subId){
|
||||||
console.log("Detail");
|
console.log("Detail");
|
||||||
@ -59,7 +61,7 @@ $("div.square-content").on('touchstart', function (eTarget) {
|
|||||||
$("#modal-detail-"+subId).removeClass('modal-container-hiden').show();
|
$("#modal-detail-"+subId).removeClass('modal-container-hiden').show();
|
||||||
ajaxChart(subId);
|
ajaxChart(subId);
|
||||||
} else if (windowLoc == "/scene") {
|
} else if (windowLoc == "/scene") {
|
||||||
|
|
||||||
} else if (windowLoc == "/automation") {
|
} else if (windowLoc == "/automation") {
|
||||||
}
|
}
|
||||||
touch = 0;
|
touch = 0;
|
||||||
@ -67,7 +69,7 @@ $("div.square-content").on('touchstart', function (eTarget) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
touchSubId = subId;
|
touchSubId = subId;
|
||||||
|
|
||||||
pressTimer = window.setTimeout(function (e) {
|
pressTimer = window.setTimeout(function (e) {
|
||||||
console.log("Setting");
|
console.log("Setting");
|
||||||
$("#modal-setting-"+id).removeClass('modal-container-hiden').show();
|
$("#modal-setting-"+id).removeClass('modal-container-hiden').show();
|
||||||
@ -152,7 +154,14 @@ var windowLoc = $(location).attr('pathname');
|
|||||||
windowLoc = windowLoc.substring(windowLoc.lastIndexOf("/"));
|
windowLoc = windowLoc.substring(windowLoc.lastIndexOf("/"));
|
||||||
console.log();
|
console.log();
|
||||||
if (windowLoc == "/") {
|
if (windowLoc == "/") {
|
||||||
|
|
||||||
var selectRoomId = localStorage.getItem("selectedRoomId");
|
var selectRoomId = localStorage.getItem("selectedRoomId");
|
||||||
|
|
||||||
|
if (selectRoomId == null) {
|
||||||
|
selectRoomId = 'all';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
console.log('Saved Selected Room ID '+ selectRoomId);
|
console.log('Saved Selected Room ID '+ selectRoomId);
|
||||||
$('[name="room"]').val(selectRoomId);
|
$('[name="room"]').val(selectRoomId);
|
||||||
$('.device-button').each(function(){
|
$('.device-button').each(function(){
|
||||||
@ -164,6 +173,8 @@ if (windowLoc == "/") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Room selector
|
//Room selector
|
||||||
@ -187,29 +198,35 @@ windowLoc = windowLoc.substring(windowLoc.lastIndexOf("/"));
|
|||||||
console.log();
|
console.log();
|
||||||
if (windowLoc == "/") {
|
if (windowLoc == "/") {
|
||||||
var autoUpdate = setInterval(function(){
|
var autoUpdate = setInterval(function(){
|
||||||
$.ajax({
|
if (pending == false) {
|
||||||
url: 'ajax',
|
pending = true;
|
||||||
type: 'POST',
|
$.ajax({
|
||||||
dataType: 'json',
|
url: 'ajax',
|
||||||
data: {
|
type: 'POST',
|
||||||
"action": 'getState'
|
dataType: 'json',
|
||||||
},
|
data: {
|
||||||
success: function(data){
|
"action": 'getState'
|
||||||
console.log(data);
|
},
|
||||||
for (const key in data) {
|
success: function(data){
|
||||||
if (data.hasOwnProperty(key)) {
|
console.log(data);
|
||||||
const device = data[key];
|
for (const key in data) {
|
||||||
$('[data-sub-device-id="'+key+'"]')
|
if (data.hasOwnProperty(key)) {
|
||||||
.find('.device-button-value')
|
const device = data[key];
|
||||||
.text(device['value'])
|
$('[data-sub-device-id="'+key+'"]')
|
||||||
.attr('title',device['time'])
|
.find('.device-button-value')
|
||||||
|
.text(device['value'])
|
||||||
|
.attr('title',device['time'])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
error: function (request, status, error) {
|
||||||
|
console.log("ERROR ajaxChart():", request, error);
|
||||||
|
},
|
||||||
|
complete: function (){
|
||||||
|
pending = false;
|
||||||
}
|
}
|
||||||
},
|
});
|
||||||
error: function (request, status, error) {
|
}
|
||||||
console.log("ERROR ajaxChart():", request, error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},2000);
|
},2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,14 +34,13 @@
|
|||||||
<?php
|
<?php
|
||||||
if (isset($_POST['LogFile'])) {
|
if (isset($_POST['LogFile'])) {
|
||||||
$file_lines = file('./app/logs/' . $_POST['LogFile']);
|
$file_lines = file('./app/logs/' . $_POST['LogFile']);
|
||||||
echo '<pre>';
|
echo '<pre style="overflow: auto;">';
|
||||||
foreach ($file_lines as $line) {
|
foreach ($file_lines as $line) {
|
||||||
echo $line;
|
echo $line;
|
||||||
}
|
}
|
||||||
echo '</pre>';
|
echo '</pre>';
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
</pre>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ if ($SUBDEVICE['type'] == 'on/off') {
|
|||||||
<div class="square">
|
<div class="square">
|
||||||
<div class="square-content <?php echo (($SUBDEVICE['comError'] == 1 || $DEVICE['approved'] == 0) ? "is-inactive" : "") ;?>" id="device-<?php echo $DEVICEID ?>" data-sub-device-id="<?php echo $SUBDEVICEID;?>">
|
<div class="square-content <?php echo (($SUBDEVICE['comError'] == 1 || $DEVICE['approved'] == 0) ? "is-inactive" : "") ;?>" id="device-<?php echo $DEVICEID ?>" data-sub-device-id="<?php echo $SUBDEVICEID;?>">
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<div class="row">
|
<div class="row no-gutters">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<h5 unselectable="on" class="fa">&#x<?php echo $DEVICE['icon'] ?></h5>
|
<h5 unselectable="on" class="fa">&#x<?php echo $DEVICE['icon'] ?></h5>
|
||||||
</div>
|
</div>
|
||||||
@ -19,7 +19,7 @@ if ($SUBDEVICE['type'] == 'on/off') {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col" unselectable="on" >
|
<div class="col button-text" unselectable="on" >
|
||||||
<?php echo $DEVICE['name']; ?>
|
<?php echo $DEVICE['name']; ?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -48,6 +48,7 @@ class Ajax extends Template
|
|||||||
AutomationManager::deactive($automationId);
|
AutomationManager::deactive($automationId);
|
||||||
}
|
}
|
||||||
} else if (isset($_POST['subDevice']) && isset($_POST['action']) && $_POST['action'] == "chart") {
|
} else if (isset($_POST['subDevice']) && isset($_POST['action']) && $_POST['action'] == "chart") {
|
||||||
|
die();
|
||||||
//TODO lepe rozstrukturovat
|
//TODO lepe rozstrukturovat
|
||||||
$subDeviceId = $_POST['subDevice'];
|
$subDeviceId = $_POST['subDevice'];
|
||||||
$period = $_POST['period'];
|
$period = $_POST['period'];
|
||||||
|
@ -43,58 +43,69 @@ class Home extends Template
|
|||||||
foreach ($subDevicesData as $subDeviceKey => $subDeviceData) {
|
foreach ($subDevicesData as $subDeviceKey => $subDeviceData) {
|
||||||
|
|
||||||
$events = RecordManager::getLastRecord($subDeviceData['subdevice_id'], 5);
|
$events = RecordManager::getLastRecord($subDeviceData['subdevice_id'], 5);
|
||||||
//TODO: skontrolovat zdali se jedná o poslední (opravdu nejaktuálnější) záznam
|
|
||||||
$lastRecord = $events[0];
|
|
||||||
$parsedValue = round($lastRecord['value']);
|
|
||||||
|
|
||||||
/*Value Parsing*/
|
|
||||||
if ($subDeviceData['type'] == "on/off") {
|
|
||||||
$parsedValue = ($parsedValue == 1 ? 'ON' : 'OFF');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($subDeviceData['type'] == "door") {
|
|
||||||
$replacementTrue = 'Closed';
|
|
||||||
$replacementFalse = 'Opened';
|
|
||||||
foreach ($events as $key => $value) {
|
|
||||||
$events[$key]['value'] = ($value['value'] == 1 ? $replacementTrue : $replacementFalse);
|
|
||||||
}
|
|
||||||
$parsedValue = ($parsedValue == 1 ? $replacementTrue : $replacementFalse);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($subDeviceData['type'] == "light") {
|
|
||||||
$replacementTrue = 'Light';
|
|
||||||
$replacementFalse = 'Dark';
|
|
||||||
foreach ($events as $key => $value) {
|
|
||||||
if ($parsedValue != 1){
|
|
||||||
//Analog Reading
|
|
||||||
$events[$key]['value'] = ($value['value'] <= 810 ? $replacementTrue : $replacementFalse);
|
|
||||||
} else {
|
|
||||||
//Digital Reading
|
|
||||||
$events[$key]['value'] = ($value['value'] == 0 ? $replacementTrue : $replacementFalse);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($parsedValue != 1){
|
|
||||||
//Analog Reading
|
|
||||||
$parsedValue = ($parsedValue <= 810 ? $replacementTrue : $replacementFalse);
|
|
||||||
} else {
|
|
||||||
//Digital Reading
|
|
||||||
$parsedValue = ($parsedValue == 0 ? $replacementTrue : $replacementFalse);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$date2 = new DateTime($lastRecord['time']);
|
|
||||||
|
|
||||||
$niceTime = $this->ago($date2);
|
|
||||||
|
|
||||||
$connectionError = false;
|
$connectionError = false;
|
||||||
|
$parsedValue = "";
|
||||||
|
$niceTime = "";
|
||||||
|
|
||||||
$startDate = date_create($lastRecord['time']);
|
|
||||||
$interval = $startDate->diff(new DateTime());
|
|
||||||
$hours = $interval->format('%h');
|
|
||||||
$minutes = $interval->format('%i');
|
|
||||||
$lastSeen = ($hours * 60 + $minutes);
|
|
||||||
|
|
||||||
if ($lastSeen > $deviceData['sleep_time'] && $subDeviceData['type'] != "on/off") {
|
if (sizeof($events) > 1) {
|
||||||
|
|
||||||
|
//TODO: skontrolovat zdali se jedná o poslední (opravdu nejaktuálnější) záznam
|
||||||
|
$lastRecord = $events[0];
|
||||||
|
|
||||||
|
$parsedValue = round($lastRecord['value']);
|
||||||
|
|
||||||
|
/*Value Parsing*/
|
||||||
|
if ($subDeviceData['type'] == "on/off") {
|
||||||
|
$parsedValue = ($parsedValue == 1 ? 'ON' : 'OFF');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($subDeviceData['type'] == "door") {
|
||||||
|
$replacementTrue = 'Closed';
|
||||||
|
$replacementFalse = 'Opened';
|
||||||
|
foreach ($events as $key => $value) {
|
||||||
|
$events[$key]['value'] = ($value['value'] == 1 ? $replacementTrue : $replacementFalse);
|
||||||
|
}
|
||||||
|
$parsedValue = ($parsedValue == 1 ? $replacementTrue : $replacementFalse);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($subDeviceData['type'] == "light") {
|
||||||
|
$replacementTrue = 'Light';
|
||||||
|
$replacementFalse = 'Dark';
|
||||||
|
foreach ($events as $key => $value) {
|
||||||
|
if ($parsedValue != 1){
|
||||||
|
//Analog Reading
|
||||||
|
$events[$key]['value'] = ($value['value'] <= 810 ? $replacementTrue : $replacementFalse);
|
||||||
|
} else {
|
||||||
|
//Digital Reading
|
||||||
|
$events[$key]['value'] = ($value['value'] == 0 ? $replacementTrue : $replacementFalse);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($parsedValue != 1){
|
||||||
|
//Analog Reading
|
||||||
|
$parsedValue = ($parsedValue <= 810 ? $replacementTrue : $replacementFalse);
|
||||||
|
} else {
|
||||||
|
//Digital Reading
|
||||||
|
$parsedValue = ($parsedValue == 0 ? $replacementTrue : $replacementFalse);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$date2 = new DateTime($lastRecord['time']);
|
||||||
|
|
||||||
|
$niceTime = $this->ago($date2);
|
||||||
|
|
||||||
|
|
||||||
|
$startDate = date_create($lastRecord['time']);
|
||||||
|
$interval = $startDate->diff(new DateTime());
|
||||||
|
$hours = $interval->format('%h');
|
||||||
|
$minutes = $interval->format('%i');
|
||||||
|
$lastSeen = ($hours * 60 + $minutes);
|
||||||
|
|
||||||
|
if ($lastSeen > $deviceData['sleep_time'] && $subDeviceData['type'] != "on/off") {
|
||||||
|
$connectionError = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
$connectionError = true;
|
$connectionError = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,9 +115,9 @@ class Home extends Template
|
|||||||
'unit' => $subDeviceData['unit'],
|
'unit' => $subDeviceData['unit'],
|
||||||
'comError' => $connectionError,
|
'comError' => $connectionError,
|
||||||
'lastRecort' => [
|
'lastRecort' => [
|
||||||
'value' => $parsedValue,
|
'value' => (empty($parsedValue) ? 0 : $parsedValue),
|
||||||
'time' => $lastRecord['time'],
|
'time' => (empty($lastRecord['time']) ? "00:00" : $lastRecord['time']),
|
||||||
'niceTime' => $niceTime,
|
'niceTime' => (empty($niceTime) ? "00:00" : $niceTime),
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ class Log extends Template
|
|||||||
$cdir = scandir('./app/logs/');
|
$cdir = scandir('./app/logs/');
|
||||||
foreach ($cdir as $key => $value)
|
foreach ($cdir as $key => $value)
|
||||||
{
|
{
|
||||||
if (!in_array($value,array(".","..")))
|
if (!in_array($value,array(".","..", ".gitkeep")))
|
||||||
{
|
{
|
||||||
$result[$value] = $value;
|
$result[$value] = $value;
|
||||||
}
|
}
|
||||||
|
@ -10,11 +10,11 @@
|
|||||||
"theme_color": "#182239",
|
"theme_color": "#182239",
|
||||||
"icons": [
|
"icons": [
|
||||||
{
|
{
|
||||||
"src": "/vasek/home/templates/images/icon-192x192.png",
|
"src": "/vasek/home/app/templates/images/icon-192x192.png",
|
||||||
"sizes": "192x192"
|
"sizes": "192x192"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"src": "/vasek/home/templates/images/icon-512x512.png",
|
"src": "/vasek/home/app/templates/images/icon-512x512.png",
|
||||||
"sizes": "512x512"
|
"sizes": "512x512"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
Loading…
Reference in New Issue
Block a user