-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mario
committed
Dec 8, 2024
1 parent
63c869f
commit aa78611
Showing
6 changed files
with
251 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Shows status messages in the message box | ||
function showMessage(message, type = "success") { | ||
const messageBox = document.getElementById("message-box"); | ||
messageBox.textContent = message; | ||
messageBox.className = `message-box ${type}`; | ||
|
||
// Removes message after 5 seconds | ||
setTimeout(() => { | ||
messageBox.textContent = ""; | ||
messageBox.className = "message-box"; | ||
}, 5000); | ||
} | ||
|
||
// Displays a loading spinner | ||
function toggleLoadingSpinner(show) { | ||
const spinner = document.getElementById('loading-spinner'); | ||
if (show) { | ||
spinner.style.display = 'block'; | ||
} else { | ||
spinner.style.display = 'none'; | ||
} | ||
} | ||
|
||
// Loads current settings from the API and populates the form | ||
function loadSettings() { | ||
toggleLoadingSpinner(true); | ||
fetch('/api/config') | ||
.then(response => response.json()) | ||
.then(data => { | ||
const config = data[0] || {}; | ||
document.getElementById('client-id').value = config.client_id || ''; | ||
document.getElementById('connection-timeout').value = config.connection_timeout || ''; | ||
document.getElementById('data-format').value = config.data_format || 'json'; | ||
document.getElementById('insecure-skip-verify').checked = config.insecure_skip_verify || false; | ||
document.getElementById('password').value = config.password || ''; | ||
document.getElementById('qos').value = config.qos || 0; | ||
document.getElementById('servers').value = config.servers ? config.servers.join(', ') : ''; | ||
document.getElementById('tls-ca').value = config.tls_ca || ''; | ||
document.getElementById('username').value = config.username || ''; | ||
toggleLoadingSpinner(false); | ||
}) | ||
.catch(error => { | ||
toggleLoadingSpinner(false); | ||
showMessage("Fehler beim Laden der Einstellungen!", "error"); | ||
}); | ||
} | ||
|
||
// Send the updated settings to the API | ||
document.getElementById('settings-form').addEventListener('submit', function(event) { | ||
event.preventDefault(); // Prevents the default form submission | ||
|
||
const settings = { | ||
client_id: document.getElementById('client-id').value.trim(), | ||
connection_timeout: document.getElementById('connection-timeout').value.trim(), | ||
data_format: document.getElementById('data-format').value, | ||
insecure_skip_verify: document.getElementById('insecure-skip-verify').checked, | ||
password: document.getElementById('password').value.trim(), | ||
qos: parseInt(document.getElementById('qos').value), | ||
servers: document.getElementById('servers').value.split(',').map(s => s.trim()), | ||
tls_ca: document.getElementById('tls-ca').value.trim(), | ||
username: document.getElementById('username').value.trim() | ||
}; | ||
|
||
// Send settings data to the API | ||
toggleLoadingSpinner(true); | ||
fetch('/api/save-config', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
body: JSON.stringify(settings) | ||
}) | ||
.then(response => response.json()) | ||
.then(data => { | ||
toggleLoadingSpinner(false); | ||
showMessage(data.message, "success"); | ||
}) | ||
.catch(error => { | ||
toggleLoadingSpinner(false); | ||
showMessage("Fehler beim Speichern der Einstellungen!", "error"); | ||
}); | ||
}); | ||
|
||
// Load settings on page load | ||
window.onload = loadSettings; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<!DOCTYPE html> | ||
<html lang="de"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Telegraf MQTT Config - Einstellungen</title> | ||
<link rel="stylesheet" href="static/styles.css"> | ||
<link rel="icon" href="static/favicon.ico" type="image/x-icon"> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<h1>MQTT Konfiguration Einstellungen</h1> | ||
|
||
<!-- Message Box for status messages --> | ||
<div id="message-box" class="message-box"></div> | ||
|
||
<form id="settings-form"> | ||
<label for="client-id">Client ID:</label> | ||
<input type="text" id="client-id" name="client_id" required> | ||
|
||
<label for="connection-timeout">Verbindungstimeout (in Sekunden):</label> | ||
<input type="text" id="connection-timeout" name="connection_timeout" required> | ||
|
||
<label for="data-format">Datenformat:</label> | ||
<select id="data-format" name="data_format"> | ||
<option value="json">JSON</option> | ||
<option value="influx">InfluxDB Line Protocol</option> | ||
</select> | ||
|
||
<label for="insecure-skip-verify">Insecure Skip Verify:</label> | ||
<input type="checkbox" id="insecure-skip-verify" name="insecure_skip_verify"> | ||
|
||
<label for="password">Passwort:</label> | ||
<input type="password" id="password" name="password" required> | ||
|
||
<label for="qos">QoS:</label> | ||
<select id="qos" name="qos"> | ||
<option value="0">0</option> | ||
<option value="1">1</option> | ||
<option value="2">2</option> | ||
</select> | ||
|
||
<label for="servers">MQTT Server (Comma separated):</label> | ||
<input type="text" id="servers" name="servers" required> | ||
|
||
<label for="tls-ca">TLS CA Datei:</label> | ||
<input type="text" id="tls-ca" name="tls_ca"> | ||
|
||
<label for="username">Benutzername:</label> | ||
<input type="text" id="username" name="username" required> | ||
|
||
<button type="submit" class="save-btn">Speichern</button> | ||
</form> | ||
</div> | ||
|
||
<!-- Loading Spinner --> | ||
<div id="loading-spinner" class="spinner" style="display: none;"></div> | ||
|
||
<script src="static/settings.js"></script> | ||
</body> | ||
</html> |