parent
c0ef372246
commit
baf5596e3d
|
@ -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()
|
||||||
|
|
|
@ -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
|
|
||||||
$.ajax({
|
|
||||||
url: `/get_assigned_params/${tubeId}`,
|
|
||||||
method: 'GET',
|
|
||||||
success: function (data) {
|
|
||||||
$('#universeInput').val(data.universe);
|
|
||||||
$('#dmxAddressInput').val(data.dmx_address);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Function to handle settings modal open
|
||||||
|
function openSettingsModal(tubeId) {
|
||||||
|
// Replace this with your actual logic to open the settings modal for the specified tube
|
||||||
|
console.log(`Opening settings modal for Tube ${tubeId}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assign event listeners to the toggle switches
|
||||||
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
|
// Replace 'toggleTube1', 'toggleTube2', etc., with the actual IDs of your toggle switches
|
||||||
|
document.getElementById('toggleTube1').addEventListener('change', function () {
|
||||||
|
handleTubeToggle(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Submit form on save button click
|
// Add more event listeners for additional toggle switches
|
||||||
$('#tubeSettingsForm').off('submit').on('submit', function (event) {
|
|
||||||
event.preventDefault();
|
|
||||||
const newUniverse = $('#universeInput').val();
|
|
||||||
const newDmxAddress = $('#dmxAddressInput').val();
|
|
||||||
|
|
||||||
// Update tube settings
|
// Assign event listener for the master toggle switch
|
||||||
$.ajax({
|
document.getElementById('masterToggle').addEventListener('change', handleMasterToggle);
|
||||||
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 listeners for settings buttons to open respective modals
|
||||||
populateTubeList();
|
// 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>
|
||||||
|
|
Loading…
Reference in New Issue