diff --git a/flows/pomp/index.php b/flows/pomp/index.php new file mode 100644 index 0000000..75e8836 --- /dev/null +++ b/flows/pomp/index.php @@ -0,0 +1,181 @@ + $_POST['assetId'] ?? '', + 'assetName' => $_POST['assetName'] ?? '', + 'param1' => $_POST['param1'] ?? '', + 'param2' => $_POST['param2'] ?? '' +]; + +$deployResponse = ''; +$newFileName = ''; +$envUrl = ''; + +// Alert tonen als template versie hoger is dan laatste deploy +$newVersionAlert = checkNewTemplateVersionAlert($templatePath, $deployDir); + +// Deploy knop verwerken +if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['deploy']) && $selectedEnv) { + $templateVersion = getVersionFromTemplate($templatePath); + + $placeholders = [ + 'id' => $parameters['assetId'], + 'name' => $parameters['assetName'], + 'version' => $templateVersion, + 'param1' => $parameters['param1'], + 'param2' => $parameters['param2'] + ]; + + $flowJson = renderTemplate($templatePath, $placeholders); + $newFileName = generateNextDeployFileName($templateVersion); + file_put_contents($deployDir.'/'.$newFileName, $flowJson); + + // Zoek de URL van de geselecteerde omgeving + foreach ($environments as $env) { + if (($env['ip'] ?? '') === $selectedEnv) { + $envUrl = $env['url'] ?? ''; + break; + } + } + + if ($envUrl) { + $deployResponse = deployFlowToUrl($deployDir.'/'.$newFileName, $envUrl); + } else { + $deployResponse = 'Geselecteerde omgeving niet gevonden of URL ontbreekt!'; + } +} + +// Overzicht van deploys met versies +$deploys = getDeploysWithVersions($deployDir); + +/** + * Deploy naar specifieke Node-RED URL + */ +function deployFlowToUrl(string $flowPath, string $url): string { + if (!file_exists($flowPath)) return "Flowbestand niet gevonden: $flowPath"; + + $flowJson = file_get_contents($flowPath); + + $ch = curl_init(rtrim($url, '/') . '/flows'); // Zorg dat er geen dubbele slashes komen + curl_setopt_array($ch, [ + CURLOPT_POST => true, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_HTTPHEADER => ['Content-Type: application/json'], + CURLOPT_POSTFIELDS => $flowJson, + ]); + $response = curl_exec($ch); + $error = curl_error($ch); + curl_close($ch); + + return $error ?: $response; +} +?> + +
+ +
+

Pomp flow

+
+ + + + + + + + + $newFileName gedeployed naar $envUrl!", 'success') ?> +
+ + + +
+
+
Parameters voor deploy
+ +
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ + +
+
+
+ + +
+
+
Overzicht van deploys
+ +
+ + + + + + + + + + + + + + + + + +
BestandVersieBekijk
+ Bekijk +
+
+ +

Geen deploys gevonden.

+ +
+
+
diff --git a/flows/pomp/template.json.tpl b/flows/pomp/template.json.tpl new file mode 100644 index 0000000..598cab1 --- /dev/null +++ b/flows/pomp/template.json.tpl @@ -0,0 +1,59 @@ +[ + { + "id": "inject1", + "type": "inject", + "name": "Start – {{name}} v{{version}}", + "props": [ { "p": "payload" } ], + "repeat": "", + "crontab": "", + "once": false, + "onceDelay": 0.1, + "topic": "", + "payload": "{{id}}", + "payloadType": "str", + "wires": [["function1"]], + "version": 9 + }, + { + "id": "function1", + "type": "function", + "name": "Verwerk asset data v{{version}}", + "func": "msg.payload = { \"asset_id\": \"{{id}}\", \"asset_name\": \"{{name}}\", \"version\": {{version}}, \"timestamp\": Date.now() }; return msg;", + "outputs": 1, + "wires": [["change1","debug1","http1"]] + }, + { + "id": "change1", + "type": "change", + "name": "Voeg status toe v{{version}}", + "rules": [ { "t": "set", "p": "payload.status", "pt": "msg", "to": "active", "tot": "str" } ], + "wires": [["debug1"]] + }, + { + "id": "http1", + "type": "http request", + "name": "Stuur naar API v{{version}}", + "method": "POST", + "ret": "txt", + "url": "http://localhost:3000/api/asset", + "tls": "", + "persist": false, + "proxy": "", + "authType": "", + "wires": [["debug1"]] + }, + { + "id": "debug1", + "type": "debug", + "name": "Output debug v{{version}}", + "active": true, + "tosidebar": true, + "console": false, + "tostatus": false, + "complete": "payload", + "targetType": "msg", + "statusVal": "", + "statusType": "auto", + "wires": [] + } +] diff --git a/flows/pomp/version0_202510050852.json b/flows/pomp/version0_202510050852.json new file mode 100644 index 0000000..06d7405 Binary files /dev/null and b/flows/pomp/version0_202510050852.json differ diff --git a/flows/pomp/version8_202510050842.json b/flows/pomp/version8_202510050842.json new file mode 100644 index 0000000..3e73f21 --- /dev/null +++ b/flows/pomp/version8_202510050842.json @@ -0,0 +1,59 @@ +[ + { + "id": "inject1", + "type": "inject", + "name": "Start – 1234 v8", + "props": [ { "p": "payload" } ], + "repeat": "", + "crontab": "", + "once": false, + "onceDelay": 0.1, + "topic": "", + "payload": "123", + "payloadType": "str", + "wires": [["function1"]], + "version": 8 + }, + { + "id": "function1", + "type": "function", + "name": "Verwerk asset data v8", + "func": "msg.payload = { \"asset_id\": \"123\", \"asset_name\": \"1234\", \"version\": 8, \"timestamp\": Date.now() }; return msg;", + "outputs": 1, + "wires": [["change1","debug1","http1"]] + }, + { + "id": "change1", + "type": "change", + "name": "Voeg status toe v8", + "rules": [ { "t": "set", "p": "payload.status", "pt": "msg", "to": "active", "tot": "str" } ], + "wires": [["debug1"]] + }, + { + "id": "http1", + "type": "http request", + "name": "Stuur naar API v8", + "method": "POST", + "ret": "txt", + "url": "http://localhost:3000/api/asset", + "tls": "", + "persist": false, + "proxy": "", + "authType": "", + "wires": [["debug1"]] + }, + { + "id": "debug1", + "type": "debug", + "name": "Output debug v8", + "active": true, + "tosidebar": true, + "console": false, + "tostatus": false, + "complete": "payload", + "targetType": "msg", + "statusVal": "", + "statusType": "auto", + "wires": [] + } +]