Compare commits
3 Commits
d090c8e645
...
1f2a7ff052
| Author | SHA1 | Date | |
|---|---|---|---|
| 1f2a7ff052 | |||
| 17b514505b | |||
| 75ff33ce36 |
8
.idea/.gitignore
generated
vendored
Normal file
8
.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
8
.idea/flowmanager.iml
generated
Normal file
8
.idea/flowmanager.iml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="WEB_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/flowmanager.iml" filepath="$PROJECT_DIR$/.idea/flowmanager.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
22
.idea/php.xml
generated
Normal file
22
.idea/php.xml
generated
Normal file
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="MessDetectorOptionsConfiguration">
|
||||
<option name="transferred" value="true" />
|
||||
</component>
|
||||
<component name="PHPCSFixerOptionsConfiguration">
|
||||
<option name="transferred" value="true" />
|
||||
</component>
|
||||
<component name="PHPCodeSnifferOptionsConfiguration">
|
||||
<option name="highlightLevel" value="WARNING" />
|
||||
<option name="transferred" value="true" />
|
||||
</component>
|
||||
<component name="PhpProjectSharedConfiguration" php_language_level="7.4">
|
||||
<option name="suggestChangeDefaultLanguageLevel" value="false" />
|
||||
</component>
|
||||
<component name="PhpStanOptionsConfiguration">
|
||||
<option name="transferred" value="true" />
|
||||
</component>
|
||||
<component name="PsalmOptionsConfiguration">
|
||||
<option name="transferred" value="true" />
|
||||
</component>
|
||||
</project>
|
||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -5,43 +5,6 @@ $deployDir = __DIR__;
|
||||
include __DIR__ . '/../../include/include_header.php';
|
||||
include __DIR__ . '/../../include/include_functions.php';
|
||||
|
||||
// --- Parameters ophalen of defaults ---
|
||||
$parameters = [
|
||||
'assetId' => $_POST['assetId'] ?? '',
|
||||
'assetName' => $_POST['assetName'] ?? '',
|
||||
'param1' => $_POST['param1'] ?? '',
|
||||
'param2' => $_POST['param2'] ?? ''
|
||||
];
|
||||
|
||||
// Node-RED omgevingen
|
||||
$envFile = __DIR__ . '/../../settings/environments.json';
|
||||
$environments = getNodeRedEnvironments($envFile);
|
||||
$selectedEnv = $_POST['environment'] ?? '';
|
||||
|
||||
// Alert template-versie
|
||||
$newVersionAlert = checkNewTemplateVersionAlert($templatePath, $deployDir);
|
||||
|
||||
// Overzicht deploys
|
||||
$deploys = getDeploysWithVersions($deployDir);
|
||||
|
||||
$deployResponse = '';
|
||||
$newFileName = '';
|
||||
$envUrl = '';
|
||||
$successMessage = '';
|
||||
|
||||
// Deploy verwerken
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['deploy'])) {
|
||||
$deployResult = deployFlow($parameters, $templatePath, $deployDir, $environments, $selectedEnv);
|
||||
|
||||
if ($deployResult['success']) {
|
||||
$deployResponse = $deployResult['response'];
|
||||
$newFileName = $deployResult['file'];
|
||||
$envUrl = $deployResult['envUrl'];
|
||||
$successMessage = renderAlert($deployResult['message'], 'success');
|
||||
} else {
|
||||
$successMessage = renderAlert($deployResult['message'], 'danger');
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<main class="container py-5">
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
"payload": "{{id}}",
|
||||
"payloadType": "str",
|
||||
"wires": [["function1"]],
|
||||
"version": 1,
|
||||
"version": 3,
|
||||
"url": "http://{{ip}}:3000/api/asset"
|
||||
},
|
||||
{
|
||||
|
||||
60
flows/pomp/version1_202510091414.json
Normal file
60
flows/pomp/version1_202510091414.json
Normal file
@@ -0,0 +1,60 @@
|
||||
[
|
||||
{
|
||||
"id": "inject1",
|
||||
"type": "inject",
|
||||
"name": "Start – tqqtqt v1",
|
||||
"props": [ { "p": "payload" } ],
|
||||
"repeat": "",
|
||||
"crontab": "",
|
||||
"once": false,
|
||||
"onceDelay": 0.1,
|
||||
"topic": "",
|
||||
"payload": "test",
|
||||
"payloadType": "str",
|
||||
"wires": [["function1"]],
|
||||
"version": 1,
|
||||
"url": "http://127.0.0.1:1880:3000/api/asset"
|
||||
},
|
||||
{
|
||||
"id": "function1",
|
||||
"type": "function",
|
||||
"name": "Verwerk asset data v1",
|
||||
"func": "msg.payload = { \"asset_id\": \"test\", \"asset_name\": \"tqqtqt\", \"version\": 1, \"timestamp\": Date.now() }; return msg;",
|
||||
"outputs": 1,
|
||||
"wires": [["change1","debug1","http1"]]
|
||||
},
|
||||
{
|
||||
"id": "change1",
|
||||
"type": "change",
|
||||
"name": "Voeg status toe v1",
|
||||
"rules": [ { "t": "set", "p": "payload.status", "pt": "msg", "to": "active", "tot": "str" } ],
|
||||
"wires": [["debug1"]]
|
||||
},
|
||||
{
|
||||
"id": "http1",
|
||||
"type": "http request",
|
||||
"name": "Stuur naar API v1",
|
||||
"method": "POST",
|
||||
"ret": "txt",
|
||||
"url": "http://127.0.0.1:1880:3000/api/asset",
|
||||
"tls": "",
|
||||
"persist": false,
|
||||
"proxy": "",
|
||||
"authType": "",
|
||||
"wires": [["debug1"]]
|
||||
},
|
||||
{
|
||||
"id": "debug1",
|
||||
"type": "debug",
|
||||
"name": "Output debug v1",
|
||||
"active": true,
|
||||
"tosidebar": true,
|
||||
"console": false,
|
||||
"tostatus": false,
|
||||
"complete": "payload",
|
||||
"targetType": "msg",
|
||||
"statusVal": "",
|
||||
"statusType": "auto",
|
||||
"wires": []
|
||||
}
|
||||
]
|
||||
60
flows/pomp/version1_202510091418.json
Normal file
60
flows/pomp/version1_202510091418.json
Normal file
@@ -0,0 +1,60 @@
|
||||
[
|
||||
{
|
||||
"id": "inject1",
|
||||
"type": "inject",
|
||||
"name": "Start – jsjsjsjsjsjs v1",
|
||||
"props": [ { "p": "payload" } ],
|
||||
"repeat": "",
|
||||
"crontab": "",
|
||||
"once": false,
|
||||
"onceDelay": 0.1,
|
||||
"topic": "",
|
||||
"payload": "tetetet",
|
||||
"payloadType": "str",
|
||||
"wires": [["function1"]],
|
||||
"version": 1,
|
||||
"url": "http://127.0.0.1:1880:3000/api/asset"
|
||||
},
|
||||
{
|
||||
"id": "function1",
|
||||
"type": "function",
|
||||
"name": "Verwerk asset data v1",
|
||||
"func": "msg.payload = { \"asset_id\": \"tetetet\", \"asset_name\": \"jsjsjsjsjsjs\", \"version\": 1, \"timestamp\": Date.now() }; return msg;",
|
||||
"outputs": 1,
|
||||
"wires": [["change1","debug1","http1"]]
|
||||
},
|
||||
{
|
||||
"id": "change1",
|
||||
"type": "change",
|
||||
"name": "Voeg status toe v1",
|
||||
"rules": [ { "t": "set", "p": "payload.status", "pt": "msg", "to": "active", "tot": "str" } ],
|
||||
"wires": [["debug1"]]
|
||||
},
|
||||
{
|
||||
"id": "http1",
|
||||
"type": "http request",
|
||||
"name": "Stuur naar API v1",
|
||||
"method": "POST",
|
||||
"ret": "txt",
|
||||
"url": "http://127.0.0.1:1880:3000/api/asset",
|
||||
"tls": "",
|
||||
"persist": false,
|
||||
"proxy": "",
|
||||
"authType": "",
|
||||
"wires": [["debug1"]]
|
||||
},
|
||||
{
|
||||
"id": "debug1",
|
||||
"type": "debug",
|
||||
"name": "Output debug v1",
|
||||
"active": true,
|
||||
"tosidebar": true,
|
||||
"console": false,
|
||||
"tostatus": false,
|
||||
"complete": "payload",
|
||||
"targetType": "msg",
|
||||
"statusVal": "",
|
||||
"statusType": "auto",
|
||||
"wires": []
|
||||
}
|
||||
]
|
||||
60
flows/pomp/version3_202510091419.json
Normal file
60
flows/pomp/version3_202510091419.json
Normal file
@@ -0,0 +1,60 @@
|
||||
[
|
||||
{
|
||||
"id": "inject1",
|
||||
"type": "inject",
|
||||
"name": "Start – mathijs v3",
|
||||
"props": [ { "p": "payload" } ],
|
||||
"repeat": "",
|
||||
"crontab": "",
|
||||
"once": false,
|
||||
"onceDelay": 0.1,
|
||||
"topic": "",
|
||||
"payload": "kwkwkwkwk",
|
||||
"payloadType": "str",
|
||||
"wires": [["function1"]],
|
||||
"version": 3,
|
||||
"url": "http://127.0.0.1:1880:3000/api/asset"
|
||||
},
|
||||
{
|
||||
"id": "function1",
|
||||
"type": "function",
|
||||
"name": "Verwerk asset data v3",
|
||||
"func": "msg.payload = { \"asset_id\": \"kwkwkwkwk\", \"asset_name\": \"mathijs\", \"version\": 3, \"timestamp\": Date.now() }; return msg;",
|
||||
"outputs": 1,
|
||||
"wires": [["change1","debug1","http1"]]
|
||||
},
|
||||
{
|
||||
"id": "change1",
|
||||
"type": "change",
|
||||
"name": "Voeg status toe v3",
|
||||
"rules": [ { "t": "set", "p": "payload.status", "pt": "msg", "to": "active", "tot": "str" } ],
|
||||
"wires": [["debug1"]]
|
||||
},
|
||||
{
|
||||
"id": "http1",
|
||||
"type": "http request",
|
||||
"name": "Stuur naar API v3",
|
||||
"method": "POST",
|
||||
"ret": "txt",
|
||||
"url": "http://127.0.0.1:1880:3000/api/asset",
|
||||
"tls": "",
|
||||
"persist": false,
|
||||
"proxy": "",
|
||||
"authType": "",
|
||||
"wires": [["debug1"]]
|
||||
},
|
||||
{
|
||||
"id": "debug1",
|
||||
"type": "debug",
|
||||
"name": "Output debug v3",
|
||||
"active": true,
|
||||
"tosidebar": true,
|
||||
"console": false,
|
||||
"tostatus": false,
|
||||
"complete": "payload",
|
||||
"targetType": "msg",
|
||||
"statusVal": "",
|
||||
"statusType": "auto",
|
||||
"wires": []
|
||||
}
|
||||
]
|
||||
@@ -14,15 +14,60 @@
|
||||
// *** DEFAULT SETTINGS FLOW ***
|
||||
// ------------------------------------------------------
|
||||
|
||||
// --- Parameters ophalen of defaults ---
|
||||
$parameters = [
|
||||
'assetId' => $_POST['assetId'] ?? '',
|
||||
'assetName' => $_POST['assetName'] ?? '',
|
||||
'param1' => $_POST['param1'] ?? '',
|
||||
'param2' => $_POST['param2'] ?? ''
|
||||
];
|
||||
|
||||
// Node-RED omgevingen
|
||||
$envFile = __DIR__ . '/../settings/environments.json';
|
||||
$environments = getNodeRedEnvironments($envFile);
|
||||
$selectedEnv = $_POST['environment'] ?? '';
|
||||
|
||||
// Alert template-versie
|
||||
$newVersionAlert = checkNewTemplateVersionAlert($templatePath, $deployDir);
|
||||
|
||||
// Overzicht deploys
|
||||
$deploys = getDeploysWithVersions($deployDir);
|
||||
|
||||
// Init variabelen
|
||||
$deployResponse = '';
|
||||
$newFileName = '';
|
||||
$envUrl = '';
|
||||
$successMessage = '';
|
||||
|
||||
// Deploy verwerken
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['deploy'])) {
|
||||
$deployResult = deployFlow($parameters, $templatePath, $deployDir, $environments, $selectedEnv);
|
||||
|
||||
if ($deployResult['success']) {
|
||||
$deployResponse = $deployResult['response'];
|
||||
$newFileName = $deployResult['file'];
|
||||
$envUrl = $deployResult['envUrl'];
|
||||
$successMessage = renderAlert($deployResult['message'], 'success');
|
||||
} else {
|
||||
$successMessage = renderAlert($deployResult['message'], 'danger');
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------
|
||||
// *** HELPERS ***
|
||||
// ------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Verkrijg een overzicht van alle Node-RED omgevingen
|
||||
*
|
||||
* @param string $envFile Pad naar JSON-bestand met omgevingen
|
||||
* @return array
|
||||
*/
|
||||
function getNodeRedEnvironments(string $envFile): array {
|
||||
function getNodeRedEnvironments(string $envFile): array
|
||||
{
|
||||
$json = @file_get_contents($envFile);
|
||||
if (!$json) return [];
|
||||
|
||||
$data = json_decode($json, true);
|
||||
return is_array($data) ? $data : [];
|
||||
}
|
||||
@@ -33,13 +78,15 @@ function getNodeRedEnvironments(string $envFile): array {
|
||||
* @param string $dir
|
||||
* @return array
|
||||
*/
|
||||
function findVersionedJsonFilesInDir(string $dir): array {
|
||||
function findVersionedJsonFilesInDir(string $dir): array
|
||||
{
|
||||
$matches = [];
|
||||
foreach (scandir($dir) as $file) {
|
||||
if (preg_match('/^version\d+_\d{12}\.json$/', $file)) {
|
||||
$matches[] = ['name' => $file];
|
||||
}
|
||||
}
|
||||
|
||||
usort($matches, fn($a, $b) => strcmp($a['name'], $b['name']));
|
||||
return $matches;
|
||||
}
|
||||
@@ -50,7 +97,8 @@ function findVersionedJsonFilesInDir(string $dir): array {
|
||||
* @param string $dir
|
||||
* @return string|null
|
||||
*/
|
||||
function findLatestDeployFile(string $dir): ?string {
|
||||
function findLatestDeployFile(string $dir): ?string
|
||||
{
|
||||
$files = findVersionedJsonFilesInDir($dir);
|
||||
return !empty($files) ? end($files)['name'] : null;
|
||||
}
|
||||
@@ -61,8 +109,10 @@ function findLatestDeployFile(string $dir): ?string {
|
||||
* @param string $filePath
|
||||
* @return int
|
||||
*/
|
||||
function getVersionFromJson(string $filePath): int {
|
||||
function getVersionFromJson(string $filePath): int
|
||||
{
|
||||
if (!file_exists($filePath)) return 0;
|
||||
|
||||
$json = json_decode(file_get_contents($filePath), true);
|
||||
return $json[0]['version'] ?? 0;
|
||||
}
|
||||
@@ -73,8 +123,10 @@ function getVersionFromJson(string $filePath): int {
|
||||
* @param string $templatePath
|
||||
* @return int
|
||||
*/
|
||||
function getVersionFromTemplate(string $templatePath): int {
|
||||
function getVersionFromTemplate(string $templatePath): int
|
||||
{
|
||||
if (!file_exists($templatePath)) return 0;
|
||||
|
||||
preg_match('/"version"\s*:\s*(\d+)/', file_get_contents($templatePath), $m);
|
||||
return $m[1] ?? 0;
|
||||
}
|
||||
@@ -86,10 +138,11 @@ function getVersionFromTemplate(string $templatePath): int {
|
||||
* @param string $deployDir
|
||||
* @return string|null
|
||||
*/
|
||||
function checkNewTemplateVersionAlert(string $templatePath, string $deployDir): ?string {
|
||||
function checkNewTemplateVersionAlert(string $templatePath, string $deployDir): ?string
|
||||
{
|
||||
$templateVersion = getVersionFromTemplate($templatePath);
|
||||
$latestDeployFile = findLatestDeployFile($deployDir);
|
||||
$latestVersion = $latestDeployFile ? getVersionFromJson($deployDir.'/'.$latestDeployFile) : 0;
|
||||
$latestVersion = $latestDeployFile ? getVersionFromJson($deployDir . '/' . $latestDeployFile) : 0;
|
||||
|
||||
if ($templateVersion > $latestVersion) {
|
||||
return "<div class='alert alert-warning'>
|
||||
@@ -97,6 +150,7 @@ function checkNewTemplateVersionAlert(string $templatePath, string $deployDir):
|
||||
(Template v$templateVersion > Laatste deploy v$latestVersion)
|
||||
</div>";
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -106,8 +160,9 @@ function checkNewTemplateVersionAlert(string $templatePath, string $deployDir):
|
||||
* @param int $version
|
||||
* @return string
|
||||
*/
|
||||
function generateNextDeployFileName(int $version): string {
|
||||
return "version{$version}_".date('YmdHi').".json";
|
||||
function generateNextDeployFileName(int $version): string
|
||||
{
|
||||
return "version{$version}_" . date('YmdHi') . ".json";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,11 +172,13 @@ function generateNextDeployFileName(int $version): string {
|
||||
* @param array $placeholders
|
||||
* @return string
|
||||
*/
|
||||
function renderTemplate(string $templatePath, array $placeholders): string {
|
||||
function renderTemplate(string $templatePath, array $placeholders): string
|
||||
{
|
||||
$content = file_get_contents($templatePath);
|
||||
foreach ($placeholders as $key => $value) {
|
||||
$content = str_replace("{{{$key}}}", $value, $content);
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
@@ -132,7 +189,8 @@ function renderTemplate(string $templatePath, array $placeholders): string {
|
||||
* @param string $type
|
||||
* @return string
|
||||
*/
|
||||
function renderAlert(string $message, string $type = 'info'): string {
|
||||
function renderAlert(string $message, string $type = 'info'): string
|
||||
{
|
||||
return "<div class='alert alert-{$type}'>$message</div>";
|
||||
}
|
||||
|
||||
@@ -142,12 +200,14 @@ function renderAlert(string $message, string $type = 'info'): string {
|
||||
* @param string $dir
|
||||
* @return array
|
||||
*/
|
||||
function getDeploysWithVersions(string $dir): array {
|
||||
function getDeploysWithVersions(string $dir): array
|
||||
{
|
||||
$files = findVersionedJsonFilesInDir($dir);
|
||||
return array_map(function($f) use ($dir) {
|
||||
|
||||
return array_map(function ($f) use ($dir) {
|
||||
return [
|
||||
'name' => $f['name'],
|
||||
'version' => getVersionFromJson($dir.'/'.$f['name'])
|
||||
'version' => getVersionFromJson($dir . '/' . $f['name'])
|
||||
];
|
||||
}, array_reverse($files));
|
||||
}
|
||||
@@ -163,7 +223,8 @@ function getDeploysWithVersions(string $dir): array {
|
||||
* @param string $url Node-RED URL
|
||||
* @return string HTTP status code of foutmelding
|
||||
*/
|
||||
function deployFlowToUrl(string $flowPath, string $url): string {
|
||||
function deployFlowToUrl(string $flowPath, string $url): string
|
||||
{
|
||||
if (!file_exists($flowPath)) {
|
||||
return '<div class="alert alert-danger" role="alert">
|
||||
<strong>Fout:</strong> Flowbestand niet gevonden: ' . htmlspecialchars($flowPath) . '
|
||||
@@ -197,7 +258,8 @@ function deployFlowToUrl(string $flowPath, string $url): string {
|
||||
* @param string $selectedEnv Geselecteerde omgeving (IP)
|
||||
* @return array Resultaat van de deploy
|
||||
*/
|
||||
function deployFlow(array $parameters, string $templatePath, string $deployDir, array $environments, string $selectedEnv): array {
|
||||
function deployFlow(array $parameters, string $templatePath, string $deployDir, array $environments, string $selectedEnv): array
|
||||
{
|
||||
$result = [
|
||||
'success' => false,
|
||||
'message' => '',
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
<?php
|
||||
|
||||
include '../include/include_header.php';
|
||||
|
||||
// Laad opgeslagen omgevingen (optioneel uit een JSON-bestand)
|
||||
$env_file = 'environments.json';
|
||||
$environments = [];
|
||||
|
||||
if(file_exists($env_file)) {
|
||||
$environments = json_decode(file_get_contents($env_file), true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user