Some Big Changes

Co-Authored-By: Xinatorus <patrik@steelants.cz>
This commit is contained in:
JonatanRek 2019-09-23 21:11:06 +02:00
parent 5e2af0fdbc
commit e74d2095c6
7 changed files with 116 additions and 88 deletions

View File

@ -1,3 +1,5 @@
var pending = false;
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker.register('serviceWorker.js')
@ -152,7 +154,14 @@ var windowLoc = $(location).attr('pathname');
windowLoc = windowLoc.substring(windowLoc.lastIndexOf("/"));
console.log();
if (windowLoc == "/") {
var selectRoomId = localStorage.getItem("selectedRoomId");
if (selectRoomId == null) {
selectRoomId = 'all';
}
console.log('Saved Selected Room ID '+ selectRoomId);
$('[name="room"]').val(selectRoomId);
$('.device-button').each(function(){
@ -164,6 +173,8 @@ if (windowLoc == "/") {
}
}
});
}
//Room selector
@ -187,6 +198,8 @@ windowLoc = windowLoc.substring(windowLoc.lastIndexOf("/"));
console.log();
if (windowLoc == "/") {
var autoUpdate = setInterval(function(){
if (pending == false) {
pending = true;
$.ajax({
url: 'ajax',
type: 'POST',
@ -208,8 +221,12 @@ if (windowLoc == "/") {
},
error: function (request, status, error) {
console.log("ERROR ajaxChart():", request, error);
},
complete: function (){
pending = false;
}
});
}
},2000);
}

View File

@ -34,14 +34,13 @@
<?php
if (isset($_POST['LogFile'])) {
$file_lines = file('./app/logs/' . $_POST['LogFile']);
echo '<pre>';
echo '<pre style="overflow: auto;">';
foreach ($file_lines as $line) {
echo $line;
}
echo '</pre>';
}
?>
</pre>
</div>
</div>

View File

@ -10,7 +10,7 @@ if ($SUBDEVICE['type'] == 'on/off') {
<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="content">
<div class="row">
<div class="row no-gutters">
<div class="col">
<h5 unselectable="on" class="fa">&#x<?php echo $DEVICE['icon'] ?></h5>
</div>
@ -19,7 +19,7 @@ if ($SUBDEVICE['type'] == 'on/off') {
</div>
</div>
<div class="row">
<div class="col" unselectable="on" >
<div class="col button-text" unselectable="on" >
<?php echo $DEVICE['name']; ?>
</div>
</div>

View File

@ -48,6 +48,7 @@ class Ajax extends Template
AutomationManager::deactive($automationId);
}
} else if (isset($_POST['subDevice']) && isset($_POST['action']) && $_POST['action'] == "chart") {
die();
//TODO lepe rozstrukturovat
$subDeviceId = $_POST['subDevice'];
$period = $_POST['period'];

View File

@ -43,8 +43,17 @@ class Home extends Template
foreach ($subDevicesData as $subDeviceKey => $subDeviceData) {
$events = RecordManager::getLastRecord($subDeviceData['subdevice_id'], 5);
$connectionError = false;
$parsedValue = "";
$niceTime = "";
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*/
@ -86,7 +95,6 @@ class Home extends Template
$niceTime = $this->ago($date2);
$connectionError = false;
$startDate = date_create($lastRecord['time']);
$interval = $startDate->diff(new DateTime());
@ -97,6 +105,9 @@ class Home extends Template
if ($lastSeen > $deviceData['sleep_time'] && $subDeviceData['type'] != "on/off") {
$connectionError = true;
}
} else {
$connectionError = true;
}
$subDevices[$subDeviceData['subdevice_id']] = [
'events'=> $events,
@ -104,9 +115,9 @@ class Home extends Template
'unit' => $subDeviceData['unit'],
'comError' => $connectionError,
'lastRecort' => [
'value' => $parsedValue,
'time' => $lastRecord['time'],
'niceTime' => $niceTime,
'value' => (empty($parsedValue) ? 0 : $parsedValue),
'time' => (empty($lastRecord['time']) ? "00:00" : $lastRecord['time']),
'niceTime' => (empty($niceTime) ? "00:00" : $niceTime),
],
];
}

View File

@ -19,7 +19,7 @@ class Log extends Template
$cdir = scandir('./app/logs/');
foreach ($cdir as $key => $value)
{
if (!in_array($value,array(".","..")))
if (!in_array($value,array(".","..", ".gitkeep")))
{
$result[$value] = $value;
}

View File

@ -10,11 +10,11 @@
"theme_color": "#182239",
"icons": [
{
"src": "/vasek/home/templates/images/icon-192x192.png",
"src": "/vasek/home/app/templates/images/icon-192x192.png",
"sizes": "192x192"
},
{
"src": "/vasek/home/templates/images/icon-512x512.png",
"src": "/vasek/home/app/templates/images/icon-512x512.png",
"sizes": "512x512"
}
],