Skip to content

Commit

Permalink
Show stop information when running the desktop client locally
Browse files Browse the repository at this point in the history
  • Loading branch information
daveajlee committed Sep 18, 2023
1 parent d39b0fa commit 80777f1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
23 changes: 16 additions & 7 deletions desktop/src/app/stops/stop-detail/stop-detail.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {HttpClient} from '@angular/common/http';
import {RealTimeInfo} from './realtimeinfos.model';
import {Subscription} from 'rxjs';
import {StopTimesResponse} from "./stoptimes-response.model";
import {GameService} from "../../shared/game.service";

@Component({
selector: 'app-stop-detail',
Expand Down Expand Up @@ -43,32 +44,40 @@ export class StopDetailComponent implements OnInit, OnDestroy {
* @param http a http client which can retrieve data via http calls from the server.
* @param stopsService a service which can retrieve and format stop information
* @param route a variable which contains the current stop that the user clicked on.
* @param gameService a service which retrieves game information
* @param router a navigational aid from Angular
* @param dom a variable which ensures that security settings allow iframes.
*/
constructor(private http: HttpClient, private stopsService: StopsService, private route: ActivatedRoute,
private router: Router, private dom: DomSanitizer) { }
private gameService: GameService, private router: Router, private dom: DomSanitizer) { }

/**
* Initialise the stop information during construction and ensure all variables are set to the correct data.
*/
ngOnInit(): void {
// Save the stop information based on the id.
if ( this.gameService.getGame().scenario.stopDistances ) {

} else {

}
this.idSubscription = this.route.params.subscribe((params: Params) => {
this.id = +params['id'];
this.stop = this.stopsService.getStop(this.id);
this.mapUrl = this.dom.bypassSecurityTrustResourceUrl('http://www.openstreetmap.org/export/embed.html?bbox='
+ (this.stop.longitude - 0.003) + ',' + (this.stop.latitude - 0.003) + ',' + (this.stop.longitude + 0.003) +
',' + (this.stop.latitude + 0.003) + '&layer=mapnik');
if ( this.gameService.getGame().scenario.stopDistances ) {
this.stop = new Stop('' + this.id, this.gameService.getGame().scenario.stopDistances[this.id].split(":")[0], 0, 0)
} else {
this.stop = this.stopsService.getStop(this.id);
this.mapUrl = this.dom.bypassSecurityTrustResourceUrl('http://www.openstreetmap.org/export/embed.html?bbox='
+ (this.stop.longitude - 0.003) + ',' + (this.stop.latitude - 0.003) + ',' + (this.stop.longitude + 0.003) +
',' + (this.stop.latitude + 0.003) + '&layer=mapnik');
}
});
// Determine current date & time
const time = new Date(Date.now());
const month = time.getMonth() + 1;
let monthStr = String(month);
if ( month < 10 ) { monthStr = '0' + month; }
const dayOfMonth = time.getDate();
let dayOfMonthStr = String(dayOfMonth);
if ( dayOfMonth < 10 ) { dayOfMonthStr = '0' + dayOfMonth; }
this.today = time.getFullYear() + '-' + monthStr + '-' + dayOfMonth;
this.hours = this.leftPadZero(time.getHours());
this.minutes = this.leftPadZero(time.getMinutes());
Expand Down
20 changes: 15 additions & 5 deletions desktop/src/app/stops/stops.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {DataService} from '../shared/data.service';
import {StopsService} from './stops.service';
import {Stop} from './stop.model';
import {Subscription} from 'rxjs';
import {GameService} from "../shared/game.service";

@Component({
selector: 'app-stops',
Expand All @@ -21,18 +22,27 @@ export class StopsComponent implements OnInit, OnDestroy {
/**
* Create a new stops component which constructs a data service and a stop service to retreive data from the server.
* @param dataService which contains the HTTP connection to the server
* @param gameService a service which retrieves game information
* @param stopsService which formats the HTTP calls into a way which the frontend can read and render.
*/
constructor(private dataService: DataService, private stopsService: StopsService) { }
constructor(private dataService: DataService, private gameService: GameService, private stopsService: StopsService) { }

/**
* Initialise a new stops component which maintains a list of stops that can be updated and set from the server calls.
*/
ngOnInit(): void {
this.subscription = this.stopsService.stopsChanged.subscribe((stops: Stop[]) => {
this.stops = stops;
});
this.stops = this.stopsService.getStops();
if ( this.gameService.getGame().scenario.stopDistances ) {
this.stops = [];
var allStops = this.gameService.getGame().scenario.stopDistances;
for ( var i = 0; i < allStops.length; i++ ) {
this.stops.push(new Stop('' + i, allStops[i].split(":")[0], 0, 0));
}
} else {
this.subscription = this.stopsService.stopsChanged.subscribe((stops: Stop[]) => {
this.stops = stops;
});
this.stops = this.stopsService.getStops();
}
}

/**
Expand Down

0 comments on commit 80777f1

Please sign in to comment.