Skip to content

Commit

Permalink
replace with jQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
dublUayaychtee committed Aug 23, 2023
1 parent 93a5d17 commit b7f54d9
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions admin_interface/admin_interface/static/js/dashboard.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
// Code for the dashboard

// Creates a html table https://stackoverflow.com/questions/15164655/generate-html-table-from-2d-javascript-array
function createTable(tableData, name) {
var table = document.createElement('table');
function createTableBody(tableData) {
var tableBody = document.createElement('tbody');

// Set ID so we can find it again later using getElementById
table.id = name;

tableData.forEach(function (rowData) {
var row = document.createElement('tr');

Expand All @@ -19,9 +15,7 @@ function createTable(tableData, name) {

tableBody.appendChild(row);
});

table.appendChild(tableBody);
return table;
return tableBody;
// document.body.appendChild(table);
}

Expand All @@ -34,9 +28,9 @@ $(document).ready(function () {
var _version = "none";

// Get all editable elements
let countdown_elm = document.getElementById("mission_time");
let subtitle_elm = document.getElementById("subtitle");
let promo_elm = document.getElementById("promoImage");
// let countdown_elm = document.getElementById("mission_time");
// let subtitle_elm = document.getElementById("subtitle");
// let promo_elm = document.getElementById("promoImage");

socket.on("updateSensorData", function (msg) {
console.log("Received sensorData :: " + msg.date + " :: " + msg.version);
Expand All @@ -50,13 +44,14 @@ $(document).ready(function () {
}

// Update updatable elements
countdown_elm.textContent = msg.date;
subtitle_elm.textContent = msg.next_meeting;
promoImage.src = msg.promo_path;
$("#mission_time").text = msg.date;
$("#subtitle").text = msg.next_meeting;
$("#promoImage").src = msg.promo_path;

// Update table
let discord_elm = document.getElementById("discord_table");
discord_elm.parentNode.replaceChild(createTable(msg.discord, "discord_table"), discord_elm);
// let discord_elm = document.getElementById("discord_table");
// discord_elm.parentNode.replaceChild(createTable(msg.discord, "discord_table"), discord_elm);
$("#discord_table > tbody").replaceWith(createTableBody(msg.discord));
});

socket.on("reconnect", (socket) => {
Expand Down

1 comment on commit b7f54d9

@dublUayaychtee
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jQuery is already used, so I replaced some regular JS with jQuery

Please sign in to comment.