diff --git a/client/src/atc/atc.ts b/client/src/atc/atc.ts new file mode 100644 index 00000000..8a668975 --- /dev/null +++ b/client/src/atc/atc.ts @@ -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:[] = []; + #dataHandler:ATCDataHandler; + #flights:{[key:string]: FlightInterface} = {}; + + + constructor() { + + this.#dataHandler = new ATCDataHandler( this ); + + this.lookForBoards(); + + } + + + addBoard( 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(); + + } + +} \ No newline at end of file diff --git a/client/src/atc/atcboard.ts b/client/src/atc/atcboard.ts new file mode 100644 index 00000000..32010b3e --- /dev/null +++ b/client/src/atc/atcboard.ts @@ -0,0 +1,15 @@ +export abstract class ATCBoard { + + #boardElement:HTMLElement; + + constructor( boardElement:HTMLElement ) { + + this.#boardElement = boardElement; + + } + + getBoardElement() { + return this.#boardElement; + } + +} \ No newline at end of file diff --git a/client/src/atc/board/flight.ts b/client/src/atc/board/flight.ts new file mode 100644 index 00000000..6935dfe7 --- /dev/null +++ b/client/src/atc/board/flight.ts @@ -0,0 +1,11 @@ +import { ATCBoard } from "../atcboard"; + +export class ATCBoardFlight extends ATCBoard { + + constructor( element:HTMLElement ) { + + super( element ); + + } + +} \ No newline at end of file diff --git a/client/src/index.ts b/client/src/index.ts index 2a8b52d5..da4940ba 100644 --- a/client/src/index.ts +++ b/client/src/index.ts @@ -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 */ diff --git a/client/views/atc.ejs b/client/views/atc.ejs index 68537f08..0117cc0e 100644 --- a/client/views/atc.ejs +++ b/client/views/atc.ejs @@ -1,3 +1,5 @@ -
- ATC +
+ +
+
\ No newline at end of file