fixed script

Signed-off-by: Ebbe Baß <ebbe.bass>
main
Ebbe Baß 2024-02-09 17:40:47 +01:00
parent c0ef372246
commit baf5596e3d
2 changed files with 32 additions and 67 deletions

View File

@ -55,15 +55,6 @@ def register_tube_route():
register_tube(mac_address) register_tube(mac_address)
return jsonify({'success': True, 'message': 'Tube registered successfully.'}) return jsonify({'success': True, 'message': 'Tube registered successfully.'})
# Function to retrieve registered tubes from the database
@app.route('/get_tube_list', methods=['GET'])
def get_tube_list():
cur = db.cursor()
cur.execute("SELECT * FROM tubes")
tubes = cur.fetchall()
cur.close()
return tubes
# Function to retrieve registered tubes from the database # Function to retrieve registered tubes from the database
def get_tubes(): def get_tubes():
cur = db.cursor() cur = db.cursor()

View File

@ -60,69 +60,43 @@
<script src="{{ url_for('static', filename='jquery.min.js')}}"></script> <script src="{{ url_for('static', filename='jquery.min.js')}}"></script>
<script src="{{ url_for('static', filename='bootstrap/js/bootstrap.bundle.min.js')}}"></script> <script src="{{ url_for('static', filename='bootstrap/js/bootstrap.bundle.min.js')}}"></script>
<script> <script>
$(document).ready(function () { // Function to handle tube toggle switch changes
// Function to populate the tube list function handleTubeToggle(tubeId) {
function populateTubeList() { // Replace this with your actual logic to handle the toggle switch change
$.ajax({ console.log(`Tube ${tubeId} toggle switched`);
url: "{{ url_for('get_tube_list')}}", }
method: 'GET',
success: function (data) {
$('#tubeList').empty();
for (const tube of data.tubes) {
$('#tubeList').append(`
<tr>
<td>${tube.mac_address}</td>
<td>${tube.universe}</td>
<td>${tube.dmx_address}</td>
<td>
<button class="btn btn-primary btn-sm" onclick="openTubeSettingsModal('${tube.mac_address}')">Settings</button>
</td>
</tr>
`);
}
}
});
}
// Function to open the tube settings modal // Function to handle master toggle switch change
window.openTubeSettingsModal = function (tubeId) { function handleMasterToggle() {
$('#tubeSettingsModal').modal('show'); // Replace this with your actual logic to handle the master toggle switch change
// Set the modal title console.log('Master toggle switched');
$('#tubeSettingsModalLabel').text(`Tube Settings - ${tubeId}`); }
// Populate the form with current settings // Function to handle settings modal open
$.ajax({ function openSettingsModal(tubeId) {
url: `/get_assigned_params/${tubeId}`, // Replace this with your actual logic to open the settings modal for the specified tube
method: 'GET', console.log(`Opening settings modal for Tube ${tubeId}`);
success: function (data) { }
$('#universeInput').val(data.universe);
$('#dmxAddressInput').val(data.dmx_address);
}
});
// Submit form on save button click // Assign event listeners to the toggle switches
$('#tubeSettingsForm').off('submit').on('submit', function (event) { document.addEventListener('DOMContentLoaded', function () {
event.preventDefault(); // Replace 'toggleTube1', 'toggleTube2', etc., with the actual IDs of your toggle switches
const newUniverse = $('#universeInput').val(); document.getElementById('toggleTube1').addEventListener('change', function () {
const newDmxAddress = $('#dmxAddressInput').val(); handleTubeToggle(1);
});
// Update tube settings // Add more event listeners for additional toggle switches
$.ajax({
url: `/update_tube_settings/${tubeId}`,
method: 'POST',
contentType: 'application/json',
data: JSON.stringify({universe: newUniverse, dmx_address: newDmxAddress}),
success: function () {
// Close modal and refresh tube list
$('#tubeSettingsModal').modal('hide');
populateTubeList();
}
});
});
};
// Initial population of the tube list // Assign event listener for the master toggle switch
populateTubeList(); document.getElementById('masterToggle').addEventListener('change', handleMasterToggle);
// Assign event listeners for settings buttons to open respective modals
// Replace 'settingsModalTube1', 'settingsModalTube2', etc., with the actual IDs of your modal buttons
document.getElementById('settingsModalTube1').addEventListener('click', function () {
openSettingsModal(1);
});
// Add more event listeners for additional settings buttons
}); });
</script> </script>
</body> </body>