Added beginnings of new ATC framework.

This commit is contained in:
PeekabooSteam 2023-03-26 15:39:21 +01:00
parent d86a250575
commit da008c220d
5 changed files with 140 additions and 3 deletions

109
client/src/atc/atc.ts Normal file
View File

@ -0,0 +1,109 @@
import { ATCBoard } from "./atcboard";
import { ATCBoardFlight } from "./board/flight";
export interface FlightInterface {
id : string;
name : string;
}
class ATCDataHandler {
#atc:ATC;
#updateInterval:number|undefined = undefined;
#updateIntervalDelay:number = 1000;
constructor( atc:ATC ) {
this.#atc = atc;
}
startUpdates() {
this.#updateInterval = setInterval( () => {
fetch( '/api/atc/flight', {
method: 'GET',
headers: {
'Accept': '*/*',
'Content-Type': 'application/json'
}
})
.then( response => response.json() )
.then( data => {
this.#atc.setFlights( data );
});
}, this.#updateIntervalDelay );
}
stopUpdates() {
clearInterval( this.#updateInterval );
}
}
export class ATC {
#boards<T extends ATCBoard>:<T>[] = [];
#dataHandler:ATCDataHandler;
#flights:{[key:string]: FlightInterface} = {};
constructor() {
this.#dataHandler = new ATCDataHandler( this );
this.lookForBoards();
}
addBoard<T extends ATCBoard>( board:T ) {
}
lookForBoards() {
document.querySelectorAll( "ol-atc-board" ).forEach( board => {
if ( board instanceof HTMLElement ) {
this.addBoard( new ATCBoardFlight( board ) );
}
});
}
setFlights( flights:{[key:string]: any} ) {
this.#flights = flights;
}
startUpdates() {
this.#dataHandler.startUpdates();
}
stopUpdates() {
this.#dataHandler.stopUpdates();
}
}

View File

@ -0,0 +1,15 @@
export abstract class ATCBoard {
#boardElement:HTMLElement;
constructor( boardElement:HTMLElement ) {
this.#boardElement = boardElement;
}
getBoardElement() {
return this.#boardElement;
}
}

View File

@ -0,0 +1,11 @@
import { ATCBoard } from "../atcboard";
export class ATCBoardFlight extends ATCBoard {
constructor( element:HTMLElement ) {
super( element );
}
}

View File

@ -63,7 +63,7 @@ function setup() {
let atcFeatureSwitch = featureSwitches.getSwitch("atc");
if (atcFeatureSwitch?.isEnabled()) {
atc = new ATC();
// TODO: add back buttons
atc.startUpdates();
}
/* Setup event handlers */

View File

@ -1,3 +1,5 @@
<div class="ol-panel ol-dialog">
ATC
<div class="ol-panel ol-dialog ol-atc-board" data-feature-switch="atc">
<div class="atc-stripboard"></div>
</div>