Skip to content

Commit

Permalink
Form to add allocations and page to view but backend model for alloca…
Browse files Browse the repository at this point in the history
…tions still missing.
  • Loading branch information
daveajlee committed Nov 6, 2023
1 parent 85bc1c2 commit 93f29ed
Show file tree
Hide file tree
Showing 14 changed files with 249 additions and 4 deletions.
5 changes: 5 additions & 0 deletions desktop/src/app/allocations/allocations.component.css
@@ -0,0 +1,5 @@
/* CSS options for the allocation component */
.center-button {
text-align: center;
padding-top: 10px;
}
41 changes: 41 additions & 0 deletions desktop/src/app/allocations/allocations.component.html
@@ -0,0 +1,41 @@
<!-- Show the header -->
<app-header></app-header>

<!-- Jumbotron with page title -->
<div class="jumbotron">
<h1 class="display-4 text-center">Allocate Vehicle</h1>
</div>

<!-- Show an input box where the user can choose the route number -->
<div class="form-group top-space m-5">
<label for="routeNumberList" style="font-weight: bold;">Route Number:</label>
<select class="form-control" [(ngModel)]="selectedRouteNumber" id="routeNumberList">
<option *ngFor="let item of this.getDefinedRouteNumbers()" [ngValue]="item">{{ item }}</option>
</select>
</div>

<!-- Show an input box where the user can choose the fleet number -->
<div class="form-group top-space m-5">
<label for="fleetNumberList" style="font-weight: bold;">Fleet Number:</label>
<select class="form-control" [(ngModel)]="selectedFleetNumber" id="fleetNumberList">
<option *ngFor="let item of this.getDefinedFleetNumbers()" [ngValue]="item">{{ item }}</option>
</select>
</div>

<!-- Show an input box where the user can choose the tour number -->
<div class="form-group top-space m-5">
<label for="tourNumberList" style="font-weight: bold;">Tour Number:</label>
<select class="form-control" [(ngModel)]="selectedTourNumber" id="tourNumberList">
<option *ngFor="let item of this.getDefinedTourNumbers()" [ngValue]="item">{{ item }}</option>
</select>
</div>

<!-- Submit button -->
<div class="center-button">
<button type="submit" (click)="onSaveAllocation()" class="btn btn-primary btn-lg">Save Allocation</button>
</div>

<!-- Back to Management Screen button -->
<div class="center-button">
<button class="btn btn-primary btn-lg" style="margin: 10px;" type="submit" (click)="backToManagementScreen()">Back to Management Screen</button>
</div>
21 changes: 21 additions & 0 deletions desktop/src/app/allocations/allocations.component.spec.ts
@@ -0,0 +1,21 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { AllocationsComponent } from './allocations.component';

describe('AllocationsComponent', () => {
let component: AllocationsComponent;
let fixture: ComponentFixture<AllocationsComponent>;

beforeEach(() => {
TestBed.configureTestingModule({
declarations: [AllocationsComponent]
});
fixture = TestBed.createComponent(AllocationsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
95 changes: 95 additions & 0 deletions desktop/src/app/allocations/allocations.component.ts
@@ -0,0 +1,95 @@
import { Component } from '@angular/core';
import {GameService} from "../shared/game.service";
import {Router} from "@angular/router";
import {Route} from "../routes/route.model";

@Component({
selector: 'app-allocations',
templateUrl: './allocations.component.html',
styleUrls: ['./allocations.component.css']
})
export class AllocationsComponent {

gameService: GameService;
selectedRouteNumber: string;
selectedFleetNumber: string;
selectedTourNumber: string;

/**
* Construct a new Allocations component
* @param gameService2 the game service containing the currently loaded game.
* @param router the router for navigating to other pages.
*/
constructor(private gameService2: GameService, public router: Router) {
this.gameService = gameService2;
if ( this.gameService.getGame().routes.length > 0 ) {
this.selectedRouteNumber = this.gameService.getGame().routes[0].routeNumber;
}
if ( this.gameService.getGame().vehicles.length > 0 ) {
this.selectedFleetNumber = this.gameService.getGame().vehicles[0].fleetNumber;
}
this.selectedTourNumber = "1";
}

/**
* Retrieve the list of defined route numbers.
*/
getDefinedRouteNumbers(): string[] {
var routeNumbers = [];
for ( var i = 0; i < this.gameService.getGame().routes.length; i++ ) {
routeNumbers[i] = this.gameService.getGame().routes[i].routeNumber;
}
return routeNumbers;
}

/**
* Retrieve the list of defined fleet numbers.
*/
getDefinedFleetNumbers(): string[] {
var fleetNumbers = [];
for ( var i = 0; i < this.gameService.getGame().vehicles.length; i++ ) {
fleetNumbers[i] = this.gameService.getGame().vehicles[i].fleetNumber;
}
return fleetNumbers;
}

/**
* Retrieve the list of defined tour numbers for the selected route.
*/
getDefinedTourNumbers(): string[] {
if ( this.selectedRouteNumber ) {
var selectedRouteObject: Route;
for ( var j = 0; j < this.gameService.getGame().routes.length; j++ ) {
if ( this.selectedRouteNumber == this.gameService.getGame().routes[j].routeNumber ) {
selectedRouteObject = this.gameService.getGame().routes[j];
break;
}
}
if ( selectedRouteObject ) {
// We take the first timetable at the moment.
if ( selectedRouteObject.timetables.length > 0 && selectedRouteObject.timetables[0].frequencyPatterns.length > 0 ) {
var tours = [];
for (var k = 0; k < selectedRouteObject.timetables[0].frequencyPatterns[0].numTours; k++) {
tours.push((k + 1));
}
return tours;
}
return [];
} else {
return [];
}
} else {
return [];
}
}

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

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

}
5 changes: 5 additions & 0 deletions desktop/src/app/allocationslist/allocationslist.component.css
@@ -0,0 +1,5 @@
/* CSS options for the allocation component */
.center-button {
text-align: center;
padding-top: 10px;
}
14 changes: 14 additions & 0 deletions desktop/src/app/allocationslist/allocationslist.component.html
@@ -0,0 +1,14 @@
<!-- Show the header -->
<app-header></app-header>

<!-- Jumbotron with page title -->
<div class="jumbotron">
<h1 class="display-4 text-center">Vehicle Allocations</h1>
</div>

<h1>Coming Soon!</h1>

<!-- Back to Management Screen button -->
<div class="center-button">
<button class="btn btn-primary btn-lg" style="margin: 10px;" type="submit" (click)="backToManagementScreen()">Back to Management Screen</button>
</div>
21 changes: 21 additions & 0 deletions desktop/src/app/allocationslist/allocationslist.component.spec.ts
@@ -0,0 +1,21 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { AllocationslistComponent } from './allocationslist.component';

describe('AllocationslistComponent', () => {
let component: AllocationslistComponent;
let fixture: ComponentFixture<AllocationslistComponent>;

beforeEach(() => {
TestBed.configureTestingModule({
declarations: [AllocationslistComponent]
});
fixture = TestBed.createComponent(AllocationslistComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
27 changes: 27 additions & 0 deletions desktop/src/app/allocationslist/allocationslist.component.ts
@@ -0,0 +1,27 @@
import { Component } from '@angular/core';
import {GameService} from "../shared/game.service";
import {Router} from "@angular/router";

@Component({
selector: 'app-allocationslist',
templateUrl: './allocationslist.component.html',
styleUrls: ['./allocationslist.component.css']
})
export class AllocationslistComponent {

gameService: GameService;

/**
* Construct a new Allocations list component
* @param gameService2 the game service containing the currently loaded game.
* @param router the router for navigating to other pages.
*/
constructor(private gameService2: GameService, public router: Router) {
this.gameService = gameService2;
}

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

}
4 changes: 4 additions & 0 deletions desktop/src/app/app-routing.module.ts
Expand Up @@ -18,11 +18,15 @@ import {DriverDetailComponent} from "./drivers/driver-detail/driver-detail.compo
import {OptionsComponent} from "./options/options.component";
import {DrivercreatorComponent} from "./drivercreator/drivercreator.component";
import {VehicleshowroomComponent} from "./vehicleshowroom/vehicleshowroom.component";
import {AllocationsComponent} from "./allocations/allocations.component";
import {AllocationslistComponent} from "./allocationslist/allocationslist.component";

/**
* Define the links which work in this application.
*/
const appRoutes: Routes = [
{ path: 'allocations', component: AllocationsComponent },
{ path: 'allocationsList', component: AllocationslistComponent },
{ path: 'drivers', component: DriversComponent, children: [
{ path: ':id', component: DriverDetailComponent}
] },
Expand Down
6 changes: 5 additions & 1 deletion desktop/src/app/app.module.ts
Expand Up @@ -33,6 +33,8 @@ import { DriverDetailComponent } from './drivers/driver-detail/driver-detail.com
import { OptionsComponent } from './options/options.component';
import { DrivercreatorComponent } from './drivercreator/drivercreator.component';
import { VehicleshowroomComponent } from './vehicleshowroom/vehicleshowroom.component';
import { AllocationsComponent } from './allocations/allocations.component';
import { AllocationslistComponent } from './allocationslist/allocationslist.component';

@NgModule({
declarations: [
Expand All @@ -57,7 +59,9 @@ import { VehicleshowroomComponent } from './vehicleshowroom/vehicleshowroom.comp
DriverDetailComponent,
OptionsComponent,
DrivercreatorComponent,
VehicleshowroomComponent
VehicleshowroomComponent,
AllocationsComponent,
AllocationslistComponent
],
imports: [
BrowserModule,
Expand Down
3 changes: 2 additions & 1 deletion desktop/src/app/management/management.component.html
Expand Up @@ -89,7 +89,8 @@ <h5 class="card-title text-center">Allocations</h5>
<p class="card-text text-center">Allocate or deallocate vehicles to routes.</p>
<!-- Show start button -->
<div class="col text-center">
<button class="btn btn-primary btn-lg" type="submit">Change</button>
<button class="btn btn-primary btn-lg" type="submit" (click)="onChangeAllocation()">Change</button>
<a class="btn btn-primary btn-lg button-margin" style="margin: 10px;" routerLinkActive="active" routerLink="/allocationsList" role="button">View Allocations</a>
</div>
</div>
</div>
Expand Down
4 changes: 4 additions & 0 deletions desktop/src/app/management/management.component.ts
Expand Up @@ -51,6 +51,10 @@ export class ManagementComponent implements OnInit {
onPurchaseVehicle(): void {
this.router.navigate(['vehicleshowroom']);
}

onChangeAllocation(): void {
this.router.navigate(['allocations']);
}
onResign(): void {
if(confirm("Are you sure you want to resign from " + this.gameService.getGame().companyName + "? This will end " +
"your game and any changes you have made will not be saved.")) {
Expand Down
5 changes: 4 additions & 1 deletion desktop/src/app/shared/frequencypattern.model.ts
Expand Up @@ -10,6 +10,7 @@ export class FrequencyPattern {
public startTime: string;
public endTime: string;
public frequencyInMinutes: number;
public numTours: number;

/**
* Construct a new frequency pattern which contains the supplied data.
Expand All @@ -20,17 +21,19 @@ export class FrequencyPattern {
* @param startTime the start time when the frequency begins
* @param endTime the start time when the frequency ends
* @param frequencyInMinutes the frequency that will be run in minutes.
* @param numTours the number of tours that is required for this frequency pattern.
*/

constructor( name: string, daysOfOperation: string[], startStop: string, endStop: string,
startTime: string, endTime: string, frequencyInMinutes: number ) {
startTime: string, endTime: string, frequencyInMinutes: number, numTours: number ) {
this.name = name;
this.daysOfOperation = daysOfOperation;
this.startStop = startStop;
this.endStop = endStop;
this.startTime = startTime;
this.endTime = endTime;
this.frequencyInMinutes = frequencyInMinutes;
this.numTours = numTours;
}

}
Expand Up @@ -143,7 +143,7 @@ export class TimetablecreatorComponent {
// Create frequency pattern.
var frequencyPattern = new FrequencyPattern(this.frequencyPatternName, daysOfOperation,
this.frequencyPatternStartStop, this.frequencyPatternEndStop, this.frequencyPatternStartTime,
this.frequencyPatternEndTime, this.frequencyPatternFrequency);
this.frequencyPatternEndTime, this.frequencyPatternFrequency, this.getNumberVehicles());
this.frequencyPatterns.push(frequencyPattern);
}

Expand Down

0 comments on commit 93f29ed

Please sign in to comment.