From 001e74bc6d28c335a725da8827640e75ec40f990 Mon Sep 17 00:00:00 2001 From: JonatanRek Date: Fri, 11 Oct 2019 17:16:24 +0200 Subject: [PATCH] Automation Restart & Deactive Button add --- app/class/AutomationManager.php | 4 ++++ app/templates/automation.phtml | 4 +++- app/templates/js/automation.js | 35 +++++++++++++++++++++++++++++++++ app/views/Ajax.php | 5 +++++ 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 app/templates/js/automation.js diff --git a/app/class/AutomationManager.php b/app/class/AutomationManager.php index e57f359..a06581b 100644 --- a/app/class/AutomationManager.php +++ b/app/class/AutomationManager.php @@ -13,6 +13,10 @@ class AutomationManager{ return Db::command ('UPDATE automation SET active = ? WHERE automation_id=?', array ($flipedValue,$automationId)); } + public function restart($automationId) { + return Db::command ('UPDATE automation SET executed = 0 WHERE automation_id=?', array ($automationId)); + } + public function create ($name, $onDays, $doCode, $ifCode, $automationId = "") { $scene = array ( 'name' => $name, diff --git a/app/templates/automation.phtml b/app/templates/automation.phtml index 0b3cbc9..f58ac4b 100644 --- a/app/templates/automation.phtml +++ b/app/templates/automation.phtml @@ -52,7 +52,9 @@ $partial->prepare('langMng',$LANGMNG); $partial->prepare('subDevices',$SUBDEVICES); $partial->render(); - } + }?> + + render(); ?> diff --git a/app/templates/js/automation.js b/app/templates/js/automation.js new file mode 100644 index 0000000..660f9d9 --- /dev/null +++ b/app/templates/js/automation.js @@ -0,0 +1,35 @@ +function restartAutomation(automationId){ + console.log("restartingAutomation" + automationId); + $.ajax({ + url: 'ajax', + type: 'POST', + data: { + "automation_id" : automationId, + "action": 'restart' + }, + success: function(data){ + console.log(data); + }, + error: function (request, status, error) { + console.log("ERROR ", request, error); + } + }); +} + +function toggleAutomation(automationId){ + console.log("togglingAutomation" + automationId); + $.ajax({ + url: 'ajax', + type: 'POST', + data: { + "automation_id" : automationId, + "action": 'deactive' + }, + success: function(data){ + console.log(data); + }, + error: function (request, status, error) { + console.log("ERROR ", request, error); + } + }); +} \ No newline at end of file diff --git a/app/views/Ajax.php b/app/views/Ajax.php index d00c6f2..7e925ab 100644 --- a/app/views/Ajax.php +++ b/app/views/Ajax.php @@ -40,6 +40,11 @@ class Ajax extends Template die(); break; + case 'restart': + AutomationManager::restart($automationId); + die(); + break; + default: echo 'no action detected'; break;