Compare commits

...

3 Commits

Author SHA1 Message Date
72b08b631d
commander update 2024-08-12 19:31:04 +02:00
ac6d94d4a3
commander update 2024-08-12 19:15:35 +02:00
54659389e1
commander: fix tables 2024-08-12 18:55:25 +02:00
2 changed files with 53 additions and 16 deletions

View File

@ -38,6 +38,12 @@
<button id="login">login</button>
</div>
<main>
<div id="refresh" class="btn">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-clockwise" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M8 3a5 5 0 1 0 4.546 2.914.5.5 0 0 1 .908-.417A6 6 0 1 1 8 2z"/>
<path d="M8 4.466V.534a.25.25 0 0 1 .41-.192l2.36 1.966c.12.1.12.284 0 .384L8.41 4.658A.25.25 0 0 1 8 4.466"/>
</svg>
</div>
<table>
<thead>
<tr>
@ -72,8 +78,11 @@
const serverURL = 'ws://10.254.0.1:8080/';
var conn = false;
var boats = [];
var boatsLocked = [];
loginEl.addEventListener('click', login);
document.getElementById('refresh').addEventListener('click', refreshAll);
function login(e)
{
@ -86,7 +95,13 @@
function onOpen(e)
{
conn.send(passEl.value + ";4675;" + Math.floor(new Date().getTime()/1000.0));
refreshAll()
}
function refreshAll()
{
reqBoats();
reqLockedBoats();
reqClients();
}
@ -100,7 +115,16 @@
switch (data)
{
case 'boats':
boatjesEl.innerHTML = "";
addBoats(msg);
addBoats(boatsLocked);
boats = msg;
break;
case 'lockedBoats':
boatjesEl.innerHTML = "";
addBoats(boats);
addBoats(msg);
boatsLocked = msg;
passEl.parentElement.style.display = 'none';
break;
case 'clients':
@ -117,6 +141,11 @@
conn.send(passEl.value + ";boats");
}
function reqLockedBoats()
{
conn.send(passEl.value + ";locked");
}
function reqClients()
{
conn.send(passEl.value + ";clients");
@ -124,7 +153,6 @@
function addBoats(boats)
{
boatjesEl.innerHTML = "";
boats = boats.split(':');
for (let boat in boats)
{
@ -169,7 +197,7 @@
boatCells[3].append(lockBtn);
for (cell in boatCells)
{
boatRow.append(cell);
boatRow.append(boatCells[cell]);
}
boatjesEl.append(boatRow);
}
@ -192,22 +220,34 @@
}
}
function getDataFomEl(el)
{
while (el.tagName != "BODY" && el.dataset['id'] == null)
{
el = el.parentElement;
}
return el.dataset;
}
function kickClient(e)
{
console.log("kickClient", e);
// conn.send(passEl.value + ";kick;" + client);
let client = getDataFomEl(e.target);
console.log("kickClient", client);
conn.send(passEl.value + ";kick;" + client['id']);
}
function unlockBoat(e)
{
console.log("unlockBoat", e);
// conn.send(passEl.value + ";kick;" + client);
let boat = getDataFomEl(e.target);
console.log("unlockBoat", boat);
conn.send(passEl.value + ";unlock;" + boat['id']);
}
function lockBoat(e)
{
console.log("lockBoat", e);
// conn.send(passEl.value + ";kick;" + client);
let boat = getDataFomEl(e.target);
console.log("lockBoat", boat);
conn.send(passEl.value + ";lock;" + boat['id']);
}
function addClient(client)
@ -236,8 +276,9 @@
clientCells[3].append(kickBtn);
for (cell in clientCells)
{
clientRow.append(cell);
clientRow.append(clientCells[cell]);
}
clientsEl.append(clientRow);
}
else
{

View File

@ -69,7 +69,7 @@ async def take_controll(client, boat):
async def free_boat(boat):
"""make boat available for next client"""
for client in Clients:
if client["boat"]['id'] == boat:
if client["boat"] is not None and client["boat"]['id'] == boat:
client["boat"] = None
break
for b in Boats:
@ -81,7 +81,7 @@ async def free_boat(boat):
async def lock_boat(boat):
"""lock a boat so client can't take controll over it"""
for client in Clients:
if client["boat"]['id'] == boat:
if client["boat"] is not None and client["boat"]['id'] == boat:
client["boat"] = None
break
for b in Boats:
@ -136,7 +136,7 @@ async def on_message(message, client):
print("WARN: controll cmd (" + client['id'] + ") to None: " + data[2])
elif client['boat']['lastMsg'] + BOAT_DATA_INTERVAL_MAX < datetime.timestamp(datetime.now()):
# print("INFO: controll cmd (" + client['id'] + ") to " + client['boat']['name'] + ": " + data[2])
sendToBoat(client['boat'], "d:" + data[2] + "\n")
await sendToBoat(client['boat'], "d:" + data[2] + "\n")
client['boat']['lastMsg'] = datetime.timestamp(datetime.now())
elif data[1] == "getlog" and client['id'] == ADMIN_ID:
await getlog(client, data)
@ -153,10 +153,6 @@ async def new_client(clientId, ws):
if clie['id'] == client['id']:
clie['state'] = 'terminated'
Clients.append(client)
if client['id'] == ADMIN_ID:
await echo_boats(client)
await echo_locked_boats(client)
await echo_clients(client)
return client
async def new_boat(boatId, name, ws):