update dashboardAPI -AGENT

This commit is contained in:
znetsixe
2026-01-13 14:29:43 +01:00
parent c99a93f73b
commit 1ea4788848
16 changed files with 1202 additions and 8393 deletions

View File

@@ -1,134 +1,88 @@
<script type="module">
<script src="/dashboardapi/menu.js"></script>
<script src="/dashboardapi/configData.js"></script>
//import * as menuUtils from "/generalfunctions/helper/menuUtils.js";
<script>
RED.nodes.registerType('dashboardapi', {
category: 'EVOLV',
color: '#4f8582',
defaults: {
name: { value: '' },
enableLog: { value: false },
logLevel: { value: 'info' },
RED.nodes.registerType('dashboardapi', {
category: 'wbd typical',
color: '#4f8582',
defaults: {
name: { value: "" },
// New defaults for configuration:
logLevel: { value: "info" },
enableLog: { value: false },
host: { value: "" },
port: { value: 0 },
bearerToken: { value: "" }
},
inputs: 1,
outputs: 1,
inputLabels: "Usage see manual",
outputLabels: ["feedback"],
icon: "font-awesome/fa-area-chart",
protocol: { value: 'http' },
host: { value: 'localhost' },
port: { value: 3000 },
bearerToken: { value: '' },
},
inputs: 1,
outputs: 1,
inputLabels: ['Input'],
outputLabels: ['grafana'],
icon: 'font-awesome/fa-area-chart',
label: function () {
// Show the name
return this.name || "dashboardapi";
},
label: function () {
return this.name || 'dashboardapi';
},
oneditprepare: function () {
const node = this;
console.log("Edit Prepare");
const elements = {
// Basic fields
name: document.getElementById("node-input-name"),
number: document.getElementById("node-input-number"),
// Logging fields
logLevelSelect: document.getElementById("node-input-logLevel"),
logCheckbox: document.getElementById("node-input-enableLog"),
// Grafana connector fields
host: document.getElementById("node-input-host"),
port: document.getElementById("node-input-port"),
bearerToken: document.getElementById("node-input-bearerToken"),
};
try {
// UI elements
menuUtils.initBasicToggles(elements);
} catch (e) {
console.log("Error fetching project settings", e);
}
},
oneditsave: function () {
const node = this;
console.log(`------------ Saving changes to node ------------`);
//save basic properties
["name", "host", "port", "bearerToken"].forEach(
(field) => {
const element = document.getElementById(`node-input-${field}`);
if (element) {
node[field] = element.value || "";
}
}
);
const logLevelElement = document.getElementById("node-input-logLevel");
node.logLevel = logLevelElement ? logLevelElement.value || "info" : "info";
oneditprepare: function () {
const waitForMenuData = () => {
if (window.EVOLV?.nodes?.dashboardapi?.loggerMenu?.initEditor) {
window.EVOLV.nodes.dashboardapi.loggerMenu.initEditor(this);
} else {
setTimeout(waitForMenuData, 50);
}
};
waitForMenuData();
},
});
oneditsave: function () {
const node = this;
if (window.EVOLV?.nodes?.dashboardapi?.loggerMenu?.saveEditor) {
window.EVOLV.nodes.dashboardapi.loggerMenu.saveEditor(node);
}
['name', 'protocol', 'host', 'port', 'bearerToken'].forEach((field) => {
const element = document.getElementById(`node-input-${field}`);
if (!element) return;
node[field] = field === 'port' ? parseInt(element.value, 10) || 3000 : element.value || '';
});
},
});
</script>
<!-- Main UI Template -->
<script type="text/html" data-template-name="dashboardapi">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input
type="text"
id="node-input-name"
placeholder="name"
style="width:70%;"
/>
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="name" style="width:70%;" />
</div>
<div class="form-row">
<label for="node-input-protocol"><i class="fa fa-exchange"></i> Protocol</label>
<select id="node-input-protocol" style="width:70%;">
<option value="http">http</option>
<option value="https">https</option>
</select>
</div>
<div class="form-row">
<label for="node-input-host"><i class="fa fa-server"></i> Grafana Host</label>
<input type="text" id="node-input-host" placeholder="Host">
<input type="text" id="node-input-host" placeholder="localhost" style="width:70%;" />
</div>
<div class="form-row">
<label for="node-input-port"><i class="fa fa-plug"></i> Grafana Port</label>
<input type="number" id="node-input-port" placeholder="Port">
<input type="number" id="node-input-port" placeholder="3000" style="width:70%;" />
</div>
<div class="form-row">
<label for="node-input-bearerToken"><i class="fa fa-key"></i> Bearer Token</label>
<input type="text" id="node-input-bearerToken" placeholder="Bearer Token">
<input type="password" id="node-input-bearerToken" placeholder="optional" style="width:70%;" />
</div>
<hr />
<!-- loglevel checkbox -->
<div class="form-row">
<label for="node-input-enableLog"
><i class="fa fa-cog"></i> Enable Log</label
>
<input
type="checkbox"
id="node-input-enableLog"
style="width:20px; vertical-align:baseline;"
/>
<span>Enable logging</span>
</div>
<div class="form-row" id="row-logLevel">
<label for="node-input-logLevel"><i class="fa fa-cog"></i> Log Level</label>
<select id="node-input-logLevel" style="width:60%;">
<option value="info">Info</option>
<option value="debug">Debug</option>
<option value="warn">Warn</option>
<option value="error">Error</option>
</select>
</div>
<div id="logger-fields-placeholder"></div>
</script>
<script type="text/html" data-help-name="dashboardapi">
@@ -146,4 +100,4 @@
These features provide flexible and controlled interactions with the Grafana API.
</p>
</script>
</script>