BACKGROUND SINC

This commit is contained in:
JonatanRek 2020-02-13 17:39:58 +01:00
parent f0e82de775
commit 0b8ad755a0
3 changed files with 58 additions and 51 deletions

View File

@ -38,8 +38,7 @@ Db::connect (DBHOST, DBUSER, DBPASS, DBNAME);
//Read API data //Read API data
$json = file_get_contents('php://input'); $json = file_get_contents('php://input');
$obj = json_decode($json, true); $obj = json_decode($json, true);
$logManager->write("[API] Rest API request body \n" . $json, LogRecordType::INFO); $logManager->write("[API] Rest API request body -> decodet to json \n" . json_encode($obj, JSON_PRETTY_PRINT), LogRecordType::INFO);
//$logManager->write("[API] Rest API request body -> decodet to json \n" . var_dump($obj), LogRecordType::INFO);
//zabespecit proti Ddosu //zabespecit proti Ddosu
if (isset($obj['user']) && $obj['user'] != ''){ if (isset($obj['user']) && $obj['user'] != ''){
@ -75,7 +74,6 @@ try {
$fallbackManager = new FallbackManager(RANGES); $fallbackManager = new FallbackManager(RANGES);
$fallbackManager->check(); $fallbackManager->check();
LogKeeper::purge(LOGTIMOUT); LogKeeper::purge(LOGTIMOUT);
die();
} catch (\Exception $e) { } catch (\Exception $e) {
$logManager->write("[Automation] Something happen during automation execution", LogRecordType::ERROR); $logManager->write("[Automation] Something happen during automation execution", LogRecordType::ERROR);
} }

View File

@ -64,16 +64,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 );
} }
}); });
@ -88,7 +88,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);
@ -99,9 +99,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");
@ -109,7 +109,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;
@ -117,7 +117,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();
@ -202,14 +202,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) { if (selectRoomId == null) {
selectRoomId = 'all'; 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(){
@ -221,8 +221,8 @@ if (windowLoc == "/") {
} }
} }
}); });
} }
//Room selector //Room selector
@ -239,43 +239,46 @@ $( '[name="room"]' ).change(function (e) {
}); });
} }
}); });
/*
var windowLoc = $(location).attr('pathname'); var windowLoc = $(location).attr('pathname');
windowLoc = windowLoc.substring(windowLoc.lastIndexOf("/")); windowLoc = windowLoc.substring(windowLoc.lastIndexOf("/"));
console.log(); console.log();
if (windowLoc == "/") { if (windowLoc == "/") {
var autoUpdate = setInterval(function(){ var autoUpdate = setInterval(function(){
if (pending == false) { if (pending == false) {
pending = true; pending = true;
$.ajax({ $.ajax({
url: 'ajax', url: 'ajax',
type: 'POST', type: 'POST',
dataType: 'json', dataType: 'json',
data: { data: {
"action": 'getState' "action": 'getState'
}, },
success: function(data){ success: function(data){
console.log(data); console.log(data);
for (const key in data) { for (const key in data) {
if (data.hasOwnProperty(key)) { if (data.hasOwnProperty(key)) {
const device = data[key]; const device = data[key];
$('[data-sub-device-id="'+key+'"]') $('[data-sub-device-id="'+key+'"]')
.find('.device-button-value') .find('.device-button-value')
.text(device['value']) .text(device['value'])
.attr('title',device['time']) .attr('title',device['time'])
}
}
},
error: function (request, status, error) {
console.log("ERROR ajaxChart():", request, error);
},
complete: function (){
pending = false;
}
});
}
},4000);
} }
}
},
error: function (request, status, error) {
console.log("ERROR ajaxChart():", request, error);
},
complete: function (){
pending = false;
}
});
}
},4000);
}*/
//Graphs //Graphs
@ -283,7 +286,7 @@ $('.graph-period').on('click', function (e) {
var subId = $(this).attr('data-sub-device-id'); var subId = $(this).attr('data-sub-device-id');
var period = $(this).attr('data-period'); var period = $(this).attr('data-period');
var groupBy = $(this).attr('data-group'); var groupBy = $(this).attr('data-group');
ajaxChart(subId, period, groupBy); ajaxChart(subId, period, groupBy);
}); });

View File

@ -145,6 +145,12 @@ class Ajax extends Template
echo 'no action detected'; echo 'no action detected';
break; break;
} }
} else if (
isset($_POST['action']) &&
$_POST['action'] != ''
) {
//TODO: PRO JS VRACET DATA
ECHO 'test';
} }
} }
} }