Added assigned speeds, alts, select unit.

This commit is contained in:
PeekabooSteam
2023-04-20 14:22:16 +01:00
parent 79f616cf8d
commit 3124a0f6b5
5 changed files with 184 additions and 66 deletions

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
// })
// });
}