Skip to content

Commit

Permalink
Add vehicle depot functionality to desktop client without search for …
Browse files Browse the repository at this point in the history
…fleet number and selling vehicles
  • Loading branch information
daveajlee committed Sep 4, 2023
1 parent 727d241 commit 669e844
Show file tree
Hide file tree
Showing 13 changed files with 138 additions and 83 deletions.
11 changes: 11 additions & 0 deletions desktop/src/app/game/game.model.ts
@@ -1,6 +1,7 @@
import {Scenario} from "../shared/scenario.model";
import {Route} from "../routes/route.model";
import {Message} from "../messages/message.model";
import {Vehicle} from "../vehicles/vehicle.model";

/**
* This class defines a model for the game that is currently loaded in the TraMS application.
Expand All @@ -15,6 +16,7 @@ export class Game {
public difficultyLevel: string;
public routes: Route[];
public messages: Message[];
public vehicles: Vehicle[];

/**
* Construct a new game which contains the supplied data.
Expand All @@ -35,6 +37,7 @@ export class Game {
this.difficultyLevel = difficultyLevel;
this.routes = [];
this.messages = [];
this.vehicles = [];
}

/**
Expand All @@ -45,6 +48,14 @@ export class Game {
this.routes.push(route);
}

/**
* This method adds a vehicle to the vehicles array if we are currently saving routes locally.
* @param vehicle a vehicle object with the vehicle information to add to the vehicles array.
*/
addVehicle(vehicle: Vehicle): void {
this.vehicles.push(vehicle);
}

/**
* This method adds a message to the messages array if we are currently saving messages locally.
* @param subject the subject of the message to add.
Expand Down
4 changes: 4 additions & 0 deletions desktop/src/app/messages/messages.component.html
Expand Up @@ -31,3 +31,7 @@ <h2>{{message.subject}}</h2>
</div>
</div>
</div>

<div class="col text-center">
<button class="btn btn-primary btn-lg" style="margin: 10px;" type="submit" (click)="backToManagementScreen()">Back to Management Screen</button>
</div>
7 changes: 6 additions & 1 deletion desktop/src/app/messages/messages.component.ts
Expand Up @@ -5,6 +5,7 @@ import { faShareFromSquare } from '@fortawesome/free-solid-svg-icons';
import { faTrash } from '@fortawesome/free-solid-svg-icons';
import {Message} from "./message.model";
import {GameService} from "../shared/game.service";
import {Router} from "@angular/router";

@Component({
selector: 'app-messages',
Expand All @@ -19,7 +20,7 @@ export class MessagesComponent {
displayMessages: Message[];
gameService: GameService;

constructor(private gameService2: GameService) {
constructor(private gameService2: GameService, public router: Router) {
this.displayMessages = [];
this.gameService = gameService2;
this.onInboxSelect();
Expand Down Expand Up @@ -56,4 +57,8 @@ export class MessagesComponent {
checkForTrash(message) {
return message.folder.valueOf() === "TRASH";
}

backToManagementScreen(): void {
this.router.navigate(['management']);
}
}
16 changes: 16 additions & 0 deletions desktop/src/app/scenariolist/scenariolist.component.ts
Expand Up @@ -8,6 +8,7 @@ import { SCENARIOS } from 'src/data/scenario.data';
import {SCENARIO_LANDUFF} from "../../data/scenarios/landuff.data";
import {SCENARIO_LONGTS} from "../../data/scenarios/longts.data";
import {SCENARIO_MDORF} from "../../data/scenarios/mdorf.data";
import {Vehicle} from "../vehicles/vehicle.model";

@Component({
selector: 'app-scenariolist',
Expand Down Expand Up @@ -57,12 +58,27 @@ export class ScenariolistComponent implements OnInit {
*/
onScenarioSelect(scenario: string): void {
this.gameService.setGame(new Game(this.company, this.playerName, this.startingDate, this.loadScenario(scenario), this.difficultyLevel,));
// Add the message.
this.gameService.getGame().addMessage("New Managing Director Announced",
"Congratulations - " + this.playerName + " has been appointed Managing Director of " + this.company + "!"
+ "\n\nYour targets for the coming days and months: \n" + this.formatTargets(this.loadScenario(scenario).targets)
+ "\nYour contract to run public transport services in " + scenario + " will be terminated if these targets are not met!"
+ "\n\nGood luck!",
"INBOX");
// Add the supplied vehicles.
var mySuppliedVehicles = this.loadScenario(scenario).suppliedVehicles;
for ( var i = 0; i < mySuppliedVehicles.length; i++ ) {
for ( var j = 0; j < mySuppliedVehicles[i].quantity; j++ ) {
const additionalProps = new Map<string, string>();
additionalProps.set('Model', mySuppliedVehicles[i].model.modelName);
additionalProps.set('Age', '0 months');
additionalProps.set('Standing Capacity', '' + mySuppliedVehicles[i].model.standingCapacity);
additionalProps.set('Seating Capacity', '' + mySuppliedVehicles[i].model.seatingCapacity);
additionalProps.set('Value', '' + mySuppliedVehicles[i].model.value);
this.gameService.getGame().addVehicle(new Vehicle('' + (i+j+1), mySuppliedVehicles[i].vehicleType, '',
'', '', 0, additionalProps));
}
}
this.router.navigate(['management']);
// this.scenarioService.createCompany(this.company, this.playerName, this.difficultyLevel, this.startingDate, scenario);
}
Expand Down
6 changes: 4 additions & 2 deletions desktop/src/app/vehicles/suppliedvehicle.model.ts
@@ -1,10 +1,12 @@
import {VehicleModel} from "./vehiclemodel.model";

/**
* This class defines a model for Vehicles which can be supplied as part of a scenario.
*/
export class SuppliedVehicles {

public vehicleType: string;
public model: string;
public model: VehicleModel;
public quantity: number;

/**
Expand All @@ -13,7 +15,7 @@ export class SuppliedVehicles {
* @param model the model of the supplied vehicle
* @param quantity the quantity/amount of this model and type that are supplied
*/
constructor( vehicleType: string, model: string, quantity: number) {
constructor( vehicleType: string, model: VehicleModel, quantity: number) {
this.vehicleType = vehicleType;
this.model = model;
this.quantity = quantity;
Expand Down
@@ -1,71 +1,32 @@
<!-- Show the vehicle picture -->
<img src="assets/{{ getVehiclePictureLink() }}.jpg" class="img-responsive" alt="Vehicle Picture"/>


<br/><br/>

<div class="col-sm-12">
<div class="row">

<div class="row">
<!-- Show the vehicle fleet number -->
<div class="col-sm-6">
<h3 class="text-center">Fleet Number:</h3>
</div>
<div class="col-sm-6">
<h3>{{vehicle.fleetNumber}}</h3>
</div>
</div>
<!-- Show the vehicle type -->
<div class="row">
<div class="col-sm-6">
<h3 class="text-center">Type:</h3>
</div>
<div class="col-sm-6">
<h3>{{vehicle.vehicleType}}</h3>
</div>
</div>
<!-- Show the livery -->
<div class="row">
<div class="col-sm-6">
<h3 class="text-center">Livery:</h3>
</div>
<div class="col-sm-6">
<h3>{{vehicle.livery}}</h3>
</div>
</div>
<!-- Show the allocation -->
<div class="row">
<div class="col-sm-6">
<h3 class="text-center">Allocation:</h3>
</div>
<div class="col-sm-6">
<h3>{{vehicle.allocatedTour}}</h3>
</div>
</div>
<!-- Show the extra information for this vehicle -->
<div *ngFor="let recipient of vehicle.additionalTypeInformationMap | keyvalue" class="row">
<div class="col-sm-6">
<h3 class="text-center">{{recipient.key}}:</h3>
</div>
<div class="col-sm-6">
<h3> {{recipient.value}}</h3>
</div>
<div class="col">
<!-- Show the vehicle picture -->
<img src="assets/{{ getVehiclePictureLink() }}.jpg" class="img-responsive" alt="Vehicle Picture"/>
</div>
<!-- Show the inspection status for this vehicle -->
<div class="row">
<div class="col-sm-6">
<h3 class="text-center">Inspection Status:</h3>
</div>
<div class="col-sm-6">
<h3>{{vehicle.inspectionStatus}}</h3>
</div>
</div>
<!-- Show the days until next inspection for this vehicle -->
<div class="row">
<div class="col-sm-6">
<h3 class="text-center">Days until next inspection:</h3>
</div>
<div class="col-sm-6">
<h3>{{vehicle.nextInspectionDueInDays}}</h3>
</div>
<div class="col">
<!-- Show the fleet number -->
<h3 class="text-center">Fleet Number: {{vehicle.fleetNumber}}</h3>
<!-- Show the vehicle type -->
<h3 class="text-center">Type: {{vehicle.vehicleType}}</h3>
<!-- Show the livery -->
<h3 class="text-center">Livery: {{vehicle.livery}}</h3>
<!-- Show the allocation -->
<h3 class="text-center">Allocation: {{vehicle.allocatedTour ? vehicle.allocatedTour : 'Not Assigned'}}</h3>
<!-- Show the extra information for this vehicle -->
<div *ngFor="let recipient of vehicle.additionalTypeInformationMap | keyvalue" class="row">
<h3 class="text-center">{{recipient.key}}: {{recipient.value}}</h3>
</div>
<!-- Show the inspection status for this vehicle -->
<h3 class="text-center">Inspection Status: {{vehicle.inspectionStatus}}</h3>
<!-- Show the days until next inspection for this vehicle -->
<h3 class="text-center">Days until next inspection: {{vehicle.nextInspectionDueInDays}}</h3>
</div>
</div>
<div class="col text-center">
<button class="btn btn-primary btn-lg" style="margin: 10px;" type="submit" (click)="sellVehicle(vehicle)">Sell Vehicle</button>
</div>
Expand Up @@ -4,6 +4,7 @@ import {Subscription} from 'rxjs';
import {VehiclesService} from '../vehicles.service';
import {ActivatedRoute, Params} from '@angular/router';
import {Vehicle} from '../vehicle.model';
import {GameService} from "../../shared/game.service";

@Component({
selector: 'app-vehicle-detail',
Expand All @@ -23,18 +24,22 @@ export class VehicleDetailComponent implements OnInit, OnDestroy {
/**
* Construct a new vehicle-detail component based on the supplied information.
* @param vehiclesService a service which can retrieve and format vehicle information
* @param gameService a service which can retrieve game information
* @param route a variable which contains the current vehicle that the user clicked on.
*/
constructor(private vehiclesService: VehiclesService, private route: ActivatedRoute) { }
constructor(private vehiclesService: VehiclesService, private route: ActivatedRoute, private gameService: GameService) { }

/**
* Initialise the vehicle information during construction and ensure all variables are set to the correct data.
*/
ngOnInit(): void {
// Save the stop information based on the id.
this.idSubscription = this.route.params.subscribe((params: Params) => {
this.id = +params['id'];
this.vehicle = this.vehiclesService.getVehicle(this.id);
if ( this.gameService.getGame().vehicles.length > 0 ) {
this.vehicle = this.gameService.getGame().vehicles[this.id];
} else {
this.vehicle = this.vehiclesService.getVehicle(this.id);
}
});
}

Expand All @@ -52,6 +57,9 @@ export class VehicleDetailComponent implements OnInit, OnDestroy {
return this.vehicle.vehicleType;
}

sellVehicle(vehicle: Vehicle): void {
console.log('It is currently not possible to sell vehicles for vehicle ' + vehicle.fleetNumber);
}
/*verifyMap(): void {
this.vehicle.additionalTypeInformationMap.forEach().forEach((key: string, value: string) => {
console.log(key, value);
Expand Down
26 changes: 26 additions & 0 deletions desktop/src/app/vehicles/vehiclemodel.model.ts
@@ -0,0 +1,26 @@
/**
* This class defines a model for Vehicle Models in TraMS which consist of things like seating capacity,
* standing capacity etc.
*/
export class VehicleModel {

public modelName: string;
public seatingCapacity: number;
public standingCapacity: number;
public value: number;

/**
* Construct a new VehicleModel object with the supplied data.
* @param modelName the name of the model
* @param seatingCapacity the seating capacity of this model
* @param standingCapacity the standing capacity of this model
* @param value the current selling price of this model.
*/
constructor ( modelName: string, seatingCapacity: number, standingCapacity: number, value: number ) {
this.modelName = modelName;
this.seatingCapacity = seatingCapacity;
this.standingCapacity = standingCapacity;
this.value = value;
}

}
16 changes: 11 additions & 5 deletions desktop/src/app/vehicles/vehicles.component.html
@@ -1,19 +1,22 @@
<!-- Show the header -->
<app-header></app-header>

<!-- Display a jumbotron component which explains what vehicle are and how they work in TraMS -->
<div class="jumbotron" >
<h1 class="display-4">Vehicles</h1>
<h1 class="display-4 text-center">Vehicles</h1>
<br/>
<p class="lead">Vehicles ensure that your customers can travel from A to B. Therefore you should aim to have as many vehicles as possible to ensure reliable services. But don't forget if a vehicle is not in use then you are making a loss on this vehicle!</p>
<p class="lead m-4">Vehicles ensure that your customers can travel from A to B. Therefore you should aim to have as many vehicles as possible to ensure reliable services. But don't forget if a vehicle is not in use then you are making a loss on this vehicle!</p>
<hr class="my-4">
<p>Click on a vehicle to access more information about the vehicle.</p>
<p class="m-4">Click on a vehicle to access more information about the vehicle.</p>
</div>

<!-- Display a table with a list of vehicle fleet number that are currently available in TraMS. Clicking on the fleet number
brings up the detailed information for that vehicle -->
<div class="row">
<div class="col-md-4">
<div class="col-md-4 m-4">
<input type="text" #searchtext class="form-control" placeholder="Search By Fleet Number..."/>
<br/>
<button class="btn-primary" (click)="searchByFleetNumber(searchtext.value)">Search</button>
<button class="btn btn-primary" (click)="searchByFleetNumber(searchtext.value)">Search</button>
<br/>
<br/>
<table class="table">
Expand All @@ -36,3 +39,6 @@ <h1 class="display-4">Vehicles</h1>
</div>
</div>

<div class="col text-center">
<button class="btn btn-primary btn-lg" style="margin: 10px;" type="submit" (click)="backToManagementScreen()">Back to Management Screen</button>
</div>
23 changes: 18 additions & 5 deletions desktop/src/app/vehicles/vehicles.component.ts
Expand Up @@ -5,6 +5,8 @@ import {VehiclesService} from './vehicles.service';
import {DataService} from '../shared/data.service';
import {HttpClient} from '@angular/common/http';
import {VehiclesResponse} from './vehicles-response.model';
import {GameService} from "../shared/game.service";
import {Router} from "@angular/router";

@Component({
selector: 'app-vehicles',
Expand All @@ -26,16 +28,23 @@ export class VehiclesComponent implements OnInit, OnDestroy {
* @param http an http client which can make http calls
* @param dataService which contains the HTTP connection to the server
* @param vehiclesService which formats the HTTP calls into a way which the frontend can read and render.
* @param gameService a service which retrieves game information
* @param router a router service provided by Angular
*/
constructor(private http: HttpClient, private dataService: DataService, private vehiclesService: VehiclesService ) { }
constructor(private http: HttpClient, private dataService: DataService, private vehiclesService: VehiclesService,
private gameService: GameService, private router:Router) { }

/**
* Initialise a new stops component which maintains a list of stops that can be updated and set from the server calls.
* Initialise a new vheicles component which maintains a list of vehicles that can be updated and set from the server calls.
*/
ngOnInit(): void {
this.subscription = this.vehiclesService.vehiclesChanged.subscribe((vehicles: Vehicle[]) => {
this.vehicles = vehicles;
});
if ( this.gameService.getGame().vehicles.length > 0 ) {
this.vehicles = this.gameService.getGame().vehicles;
} else {
this.subscription = this.vehiclesService.vehiclesChanged.subscribe((vehicles: Vehicle[]) => {
this.vehicles = vehicles;
});
}
}

searchByFleetNumber(searchValue: string): void {
Expand All @@ -53,4 +62,8 @@ export class VehiclesComponent implements OnInit, OnDestroy {
this.searchSubscription.unsubscribe();
}

backToManagementScreen(): void {
this.router.navigate(['management']);
}

}

0 comments on commit 669e844

Please sign in to comment.