Skip to content

Commit

Permalink
Save and view allocations in new desktop client. Delete is not yet im…
Browse files Browse the repository at this point in the history
…plemented.
  • Loading branch information
daveajlee committed Nov 8, 2023
1 parent 93f29ed commit 8b693a3
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 2 deletions.
22 changes: 22 additions & 0 deletions desktop/src/app/allocations/allocation.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* This class defines allocations in TraMS.
*/
export class Allocation {

public routeNumber: string;
public fleetNumber: string;
public tourNumber: string;

/**
* Construct a new Allocation object which contains the supplied data.
* @param routeNumber the route number of the assignment.
* @param fleetNumber the fleet number of the assignment.
* @param tourNumber the tour number of the assignment.
*/
constructor(routeNumber: string, fleetNumber: string, tourNumber: string) {
this.routeNumber = routeNumber;
this.fleetNumber = fleetNumber;
this.tourNumber = tourNumber;
}

}
3 changes: 2 additions & 1 deletion desktop/src/app/allocations/allocations.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Component } from '@angular/core';
import {GameService} from "../shared/game.service";
import {Router} from "@angular/router";
import {Route} from "../routes/route.model";
import {Allocation} from "./allocation.model";

@Component({
selector: 'app-allocations',
Expand Down Expand Up @@ -84,7 +85,7 @@ export class AllocationsComponent {
}

onSaveAllocation(): void {
alert('I want to use vehicle ' + this.selectedFleetNumber + ' for ' + this.selectedRouteNumber + '/' + this.selectedTourNumber);
this.gameService.getGame().addAllocation(new Allocation(this.selectedRouteNumber, this.selectedFleetNumber, this.selectedTourNumber));
this.router.navigate(['management']);
}

Expand Down
20 changes: 19 additions & 1 deletion desktop/src/app/allocationslist/allocationslist.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,25 @@
<h1 class="display-4 text-center">Vehicle Allocations</h1>
</div>

<h1>Coming Soon!</h1>
<table class="table">
<thead>
<tr>
<th scope="col">Route Number</th>
<th scope="col">Fleet Number</th>
<th scope="col">Tour Number</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<tr *ngFor="let allocationEl of allocations, let i = index">
<td> {{allocationEl.routeNumber}} </td>
<td> {{allocationEl.fleetNumber}} </td>
<td> {{allocationEl.tourNumber}} </td>
<td><button class="btn btn-danger" style="margin: 5px;" type="submit" (click)="deleteAllocation()">Delete</button></td>
</tr>
</tbody>

</table>

<!-- Back to Management Screen button -->
<div class="center-button">
Expand Down
14 changes: 14 additions & 0 deletions desktop/src/app/allocationslist/allocationslist.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Component } from '@angular/core';
import {GameService} from "../shared/game.service";
import {Router} from "@angular/router";
import {Allocation} from "../allocations/allocation.model";

@Component({
selector: 'app-allocationslist',
Expand All @@ -10,6 +11,7 @@ import {Router} from "@angular/router";
export class AllocationslistComponent {

gameService: GameService;
allocations: Allocation[];

/**
* Construct a new Allocations list component
Expand All @@ -18,6 +20,18 @@ export class AllocationslistComponent {
*/
constructor(private gameService2: GameService, public router: Router) {
this.gameService = gameService2;
this.allocations = this.gameService.getGame().allocations;
}

/**
* Initialise a new allocations component which maintains a list of allocations.
*/
ngOnInit(): void {
this.allocations = this.gameService.getGame().allocations;
}

deleteAllocation(): void {
alert('Coming Soon!');
}

backToManagementScreen(): void {
Expand Down
11 changes: 11 additions & 0 deletions desktop/src/app/game/game.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {Route} from "../routes/route.model";
import {Message} from "../messages/message.model";
import {Vehicle} from "../vehicles/vehicle.model";
import {Driver} from "../drivers/driver.model";
import {Allocation} from "../allocations/allocation.model";

/**
* This class defines a model for the game that is currently loaded in the TraMS application.
Expand All @@ -19,6 +20,7 @@ export class Game {
public messages: Message[];
public vehicles: Vehicle[];
public drivers: Driver[];
public allocations: Allocation[];

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

/**
Expand All @@ -67,6 +70,14 @@ export class Game {
this.drivers.push(driver);
}

/**
* This method adds an allocation to the allocations array if we are currently saving allocations locally.
* @param allocation a allocation object with the allocation information to add to the allocations array.
*/
addAllocation(allocation: Allocation): void {
this.allocations.push(allocation);
}

/**
* 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

0 comments on commit 8b693a3

Please sign in to comment.