Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
173 changes: 89 additions & 84 deletions DepartureBoardWeb/ClientApp/src/app/Pages/boards/boards.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import { AngularFirestore } from "@angular/fire/compat/firestore";
import { DepartureService } from "src/app/Services/departure.service";
import { StationLookupService } from "src/app/Services/station-lookup.service";
import { Departure } from "src/app/models/departure.model";
import {BehaviorSubject, Subscription} from "rxjs";
import {BehaviorSubject, combineLatest, Subscription} from "rxjs";
import { switchMap } from "rxjs/operators";
import {ServiceStatus} from "../singleboard/singleboard";
import { AnnouncementService } from "src/app/Services/announcement.service";
import {BoardModernRgb} from "./board-modern-rgb/board-modern-rgb";
Expand Down Expand Up @@ -176,26 +177,29 @@ export class BoardsComponent implements OnInit, OnDestroy {
return;
}

this.departureService
.GetDepartures(
this.stationCode,
this.displays,
this.useArrivals,
this.platform,
null,
this.toCrsCode
)
.subscribe(
(response) => {
ToggleConfig.LoadingBar.next(false);
this.isLoading = false;
this.ProcessDepartures(response);
},
() => {
ToggleConfig.LoadingBar.next(false);
this.isLoading = false;
}
);
this.subscriptions.push(
this.departureService
.GetDepartures(
this.stationCode,
this.displays,
this.useArrivals,
this.platform,
null,
this.toCrsCode
)
.subscribe(
(response) => {
ToggleConfig.LoadingBar.next(false);
this.isLoading = false;
this.ProcessDepartures(response);
},
(error) => {
console.error('Error fetching departures:', error);
ToggleConfig.LoadingBar.next(false);
this.isLoading = false;
}
)
);
}

ProcessDepartures(data: Departure[]) {
Expand Down Expand Up @@ -237,71 +241,70 @@ export class BoardsComponent implements OnInit, OnDestroy {
}

GetCustomData() {
this.subscriptions.push(
this.auth.user$.subscribe((user) => {
this.subscriptions.push(
this.afs
.collection(`customDepartures/${user.uid}/departures`)
.doc(this.stationCode)
.valueChanges()
.subscribe(
(departureData: any) => {
ToggleConfig.LoadingBar.next(false);
this.isLoading = false;
console.debug(departureData);
const data = departureData.jsonData;
this.noBoardsDisplay = !data;
this.stationName = data.stationName;
document.title =
(data.stationName || this.stationCode) +
" - Departures - Departure Board";
const firestoreData$ = this.auth.user$.pipe(
switchMap((user) =>
this.afs
.collection(`customDepartures/${user.uid}/departures`)
.doc(this.stationCode)
.valueChanges()
)
);

const departures: any[] = data.departures;
let validDepartures: any[] = new Array();
// Removes expired departures
if (departureData.hideExpired == true || false) {
for (let i = 0; i < departures.length; i++) {
if (
Object(departures)[i]["expectedDeparture"] &&
new Date(Object(departures)[i]["expectedDeparture"]) <
new Date()
) {
console.log(
`Departure has already gone past date ${
Object(departures)[i]["expectedDeparture"]
} - ${<string>Object(departures)[i]["destination"]}`
);
} else if (
Object(departures)[i]["aimedDeparture"] &&
new Date(Object(departures)[i]["aimedDeparture"]) <
new Date()
) {
console.log(
`Departure has already gone past date ${
Object(departures)[i]["aimedDeparture"]
} - ${<string>Object(departures)[i]["destination"]}`
);
} else {
validDepartures.push(departures[i]);
}
}
} else {
validDepartures = departures;
}
this.subscriptions.push(
combineLatest([firestoreData$, this.customDepartureSequence]).subscribe(
([departureData, startIndex]: [any, number]) => {
ToggleConfig.LoadingBar.next(false);
this.isLoading = false;
console.debug(departureData);
const data = departureData.jsonData;
this.noBoardsDisplay = !data;
this.stationName = data.stationName;
document.title =
(data.stationName || this.stationCode) +
" - Departures - Departure Board";

this.subscriptions.push(this.customDepartureSequence.subscribe(startIndex => {
const index = departureData.manualControl ? startIndex : 0;
this.ProcessDepartures(validDepartures.slice(index, this.displays));
}));
},
(error) => {
ToggleConfig.LoadingBar.next(false);
this.isLoading = false;
console.log(error);
const departures: any[] = data.departures;
let validDepartures: any[] = new Array();
// Removes expired departures
if (departureData.hideExpired == true || false) {
for (let i = 0; i < departures.length; i++) {
if (
Object(departures)[i]["expectedDeparture"] &&
new Date(Object(departures)[i]["expectedDeparture"]) <
new Date()
) {
console.log(
`Departure has already gone past date ${
Object(departures)[i]["expectedDeparture"]
} - ${<string>Object(departures)[i]["destination"]}`
);
} else if (
Object(departures)[i]["aimedDeparture"] &&
new Date(Object(departures)[i]["aimedDeparture"]) <
new Date()
) {
console.log(
`Departure has already gone past date ${
Object(departures)[i]["aimedDeparture"]
} - ${<string>Object(departures)[i]["destination"]}`
);
} else {
validDepartures.push(departures[i]);
}
)
);
})
}
} else {
validDepartures = departures;
}

const index = departureData.manualControl ? startIndex : 0;
this.ProcessDepartures(validDepartures.slice(index, index + this.displays));
},
(error) => {
console.error('Error fetching custom departures:', error);
ToggleConfig.LoadingBar.next(false);
this.isLoading = false;
}
)
);
}

Expand Down Expand Up @@ -346,7 +349,9 @@ export class BoardsComponent implements OnInit, OnDestroy {
ngOnDestroy() {
clearTimeout(this.refresher);
this.subscriptions.forEach((s) => s.unsubscribe());
this.announcementSub();
if (this.announcementSub) {
this.announcementSub();
}
}

isNumber(value: string | number): boolean {
Expand Down
Loading