Merge pull request #198 from Pax1601/194-atc-tower-assign-altitude

Added assigned speeds, alts, select unit.
This commit is contained in:
PeekabooSteam 2023-04-20 14:23:57 +01:00 committed by GitHub
commit 06f10cd399
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 184 additions and 66 deletions

View File

@ -84,8 +84,8 @@
.ol-strip-board-headers :nth-child(6),
.ol-strip-board-strip :nth-child(6) {
.ol-strip-board-headers :last-child,
.ol-strip-board-strip :last-child {
width:20px;
}
@ -98,12 +98,17 @@
text-align: center;
}
[data-board-type="tower"] .ol-strip-board-strip > :first-child {
[data-board-type="tower"] .ol-strip-board-strip a {
color:white;
}
[data-board-type="tower"] .ol-strip-board-strip > :nth-child(2) {
text-align: left;
}
[data-board-type="tower"] .ol-strip-board-strip :nth-child(3) input {
width:25px;
[data-board-type="tower"] .ol-strip-board-strip :nth-child(3) input,
[data-board-type="tower"] .ol-strip-board-strip :nth-child(5) input {
width:30px;
}
[data-board-type="tower"] .ol-strip-board-strip :nth-child(3) {
@ -111,6 +116,19 @@
}
[data-altitude-assigned] [data-point="assignedAltitude"] input,
[data-speed-assigned] [data-point="assignedSpeed"] input {
background-color:#ffffffbb;
color: black;
font-weight: var( --font-weight-bolder );
}
[data-warning-altitude] [data-point="altitude"],
[data-warning-speed] [data-point="speed"] {
background:#cc0000;
border-radius: var( --border-radius-sm );
}
.ol-strip-board-strip > [data-point="name"] {
@ -172,5 +190,6 @@
}
[data-board-type="tower"] {
top:100px;
right:10px;
top:10px;
}

View File

@ -26,26 +26,56 @@ function uuidv4() {
function Flight( name, boardId, unitId ) {
this.id = uuidv4();
this.boardId = boardId;
this.name = name;
this.status = "unknown";
this.takeoffTime = -1;
this.unitId = parseInt( unitId );
this.assignedAltitude = 0;
this.assignedSpeed = 0;
this.id = uuidv4();
this.boardId = boardId;
this.name = name;
this.status = "unknown";
this.takeoffTime = -1;
this.unitId = parseInt( unitId );
}
Flight.prototype.getData = function() {
return {
"id" : this.id,
"boardId" : this.boardId,
"name" : this.name,
"status" : this.status,
"takeoffTime" : this.takeoffTime,
"unitId" : this.unitId
"assignedAltitude" : this.assignedAltitude,
"assignedSpeed" : this.assignedSpeed,
"id" : this.id,
"boardId" : this.boardId,
"name" : this.name,
"status" : this.status,
"takeoffTime" : this.takeoffTime,
"unitId" : this.unitId
};
}
Flight.prototype.setAssignedAltitude = function( assignedAltitude ) {
if ( isNaN( assignedAltitude ) ) {
return "Altitude must be a number"
}
this.assignedAltitude = parseInt( assignedAltitude );
return true;
}
Flight.prototype.setAssignedSpeed = function( assignedSpeed ) {
if ( isNaN( assignedSpeed ) ) {
return "Speed must be a number"
}
this.assignedSpeed = parseInt( assignedSpeed );
return true;
}
Flight.prototype.setOrder = function( order ) {
this.order = order;
@ -156,6 +186,26 @@ app.patch( "/flight/:flightId", ( req, res ) => {
res.status( 400 ).send( `Unrecognised flight ID (given: "${req.params.flightId}")` );
}
if ( req.body.hasOwnProperty( "assignedAltitude" ) ) {
const altitudeChangeSuccess = flight.setAssignedAltitude( req.body.assignedAltitude );
if ( altitudeChangeSuccess !== true ) {
res.status( 400 ).send( altitudeChangeSuccess );
}
}
if ( req.body.hasOwnProperty( "assignedSpeed" ) ) {
const speedChangeSuccess = flight.setAssignedSpeed( req.body.assignedSpeed );
if ( speedChangeSuccess !== true ) {
res.status( 400 ).send( speedChangeSuccess );
}
}
if ( req.body.status ) {
const statusChangeSuccess = flight.setStatus( req.body.status );

View File

@ -3,13 +3,15 @@ import { ATCBoardGround } from "./board/ground";
import { ATCBoardTower } from "./board/tower";
export interface FlightInterface {
id : string;
boardId : string;
name : string;
order : number;
status : "unknown";
takeoffTime : number;
unitId : number;
assignedSpeed: any;
assignedAltitude : any;
id : string;
boardId : string;
name : string;
order : number;
status : "unknown";
takeoffTime : number;
unitId : number;
}
@ -19,7 +21,7 @@ class ATCDataHandler {
#flights:{[key:string]: FlightInterface} = {};
#updateInterval:number|undefined = undefined;
#updateIntervalDelay:number = 1000;
#updateIntervalDelay:number = 2500; // Wait between unit update requests
constructor( atc:ATC ) {
@ -43,23 +45,29 @@ class ATCDataHandler {
startUpdates() {
this.#updateInterval = setInterval( () => {
fetch( '/api/atc/flight', {
method: 'GET',
headers: {
'Accept': '*/*',
'Content-Type': 'application/json'
}
})
.then( response => response.json() )
.then( data => {
this.setFlights( data );
});
const aBoardIsVisible = this.#atc.getBoards().some( board => board.boardIsVisible() );
if ( aBoardIsVisible ) {
fetch( '/api/atc/flight', {
method: 'GET',
headers: {
'Accept': '*/*',
'Content-Type': 'application/json'
}
})
.then( response => response.json() )
.then( data => {
this.setFlights( data );
});
}
}, this.#updateIntervalDelay );
}
@ -106,6 +114,11 @@ export class ATC {
}
getBoards() {
return this.#boards;
}
getDataHandler() {
return this.#dataHandler;
}

View File

@ -45,6 +45,19 @@ export abstract class ATCBoard {
this.#stripBoardElement = <HTMLElement>this.getBoardElement().querySelector( ".ol-strip-board-strips" );
this.#clockElement = <HTMLElement>this.getBoardElement().querySelector( ".ol-strip-board-clock" );
new MutationObserver( () => {
if ( this.boardIsVisible() ) {
this.startUpdates();
} else {
this.stopUpdates();
}
}).observe( this.getBoardElement(), {
"attributes": true,
"childList": false,
"subtree": false
});
new Sortable( this.getStripBoardElement(), {
"handle": ".handle",
@ -90,7 +103,7 @@ export abstract class ATCBoard {
this.#setupAddFlight();
//this.#_setupDemoData();
// this.#_setupDemoData();
}
@ -152,6 +165,11 @@ export abstract class ATCBoard {
}
boardIsVisible() {
return ( !this.getBoardElement().classList.contains( "hide" ) );
}
calculateTimeToGo( fromTimestamp:number, toTimestamp:number ) {
let timestamp = ( toTimestamp - fromTimestamp ) / 1000;
@ -386,6 +404,10 @@ export abstract class ATCBoard {
startUpdates() {
if ( !this.boardIsVisible() ) {
return;
}
this.#updateInterval = setInterval( () => {
this.update();
@ -417,7 +439,6 @@ export abstract class ATCBoard {
}
protected update() {
console.warn( "No custom update method defined." );
}
@ -431,6 +452,20 @@ export abstract class ATCBoard {
}
updateFlight( flightId:string, reqBody:object ) {
return fetch( '/api/atc/flight/' + flightId, {
method: 'PATCH',
headers: {
'Accept': '*/*',
'Content-Type': 'application/json'
},
"body": JSON.stringify( reqBody )
});
}
#_setupDemoData() {
fetch( '/api/atc/flight/', {
@ -446,31 +481,32 @@ export abstract class ATCBoard {
})
});
fetch( '/api/atc/flight/', {
method: 'POST',
headers: {
'Accept': '*/*',
'Content-Type': 'application/json'
},
"body": JSON.stringify({
"boardId" : this.getBoardId(),
"name" : this.getBoardId() + " 2",
"unitId" : 1
})
});
// fetch( '/api/atc/flight/', {
// method: 'POST',
// headers: {
// 'Accept': '*/*',
// 'Content-Type': 'application/json'
// },
// "body": JSON.stringify({
// "boardId" : this.getBoardId(),
// "name" : this.getBoardId() + " 2",
// "unitId" : 2
// })
// });
fetch( '/api/atc/flight/', {
method: 'POST',
headers: {
'Accept': '*/*',
'Content-Type': 'application/json'
},
"body": JSON.stringify({
"boardId" : this.getBoardId(),
"name" : this.getBoardId() + " 3",
"unitId" : 1
})
});
// fetch( '/api/atc/flight/', {
// method: 'POST',
// headers: {
// 'Accept': '*/*',
// 'Content-Type': 'application/json'
// },
// "body": JSON.stringify({
// "boardId" : this.getBoardId(),
// "name" : this.getBoardId() + " 3",
// "unitId" : 9
// })
// });
}

View File

@ -1,7 +1,7 @@
<%- include('atc/board.ejs', {
"boardId": "strip-board-tower",
"boardType": "tower",
"headers": [ "Flight", "a-Alt", "alt" ]
"headers": [ "Flight", "a. Alt", "alt", "a. Speed", "Speed" ]
}) %>
<%- include('atc/board.ejs', {