User can not view rides they have shared

main
Fan-Wu Yang 9 years ago
parent e4ed24f12d
commit 3cec10ffc6

@ -57,6 +57,10 @@ public class BaseController extends Controller {
changeScene(SceneCode.MY_TRIPS);
}
public void sharedRides() throws Exception{
changeScene(SceneCode.SHARED_RIDES);
}
public void setContent(Parent parent1){
//remove all children that do not belong to the original fxml
while (base.getChildren().size() > childNum) {

@ -4,15 +4,15 @@ import controllers.BaseController;
import controllers.Controller;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import model.DataManager;
import model.SceneCode;
import model.Session;
import model.*;
import utils.DataManagerSerialiser;
import java.io.IOException;
@ -45,11 +45,47 @@ public class Main extends Application {
DataManagerSerialiser dataManagerSerialiser = new DataManagerSerialiser();
DataManager dataManager = dataManagerSerialiser.load();
this.session.setDataManager(dataManager);
} catch (IOException e){
} catch (Exception e){
//this exception is for when the files is formatted wrong.
this.session.setDataManager(new DataManager());
Ride ride = new Ride("Nissan March", "Baby Blue", "EPU001", 2004, 5);
Stop stop1 = new Stop("1 Avonhead Road");
Stop stop2 = new Stop("100 Yaldhurst Road");
Stop stop3 = new Stop("120 Maidstone Road");
Stop stop4 = new Stop("1 University Drive");
Stop stop5 = new Stop("1 Homestead Lane");
ObservableList<Stop> routeList1 = FXCollections.observableArrayList();
routeList1.add(stop1);
routeList1.add(stop4);
Route route1 = new Route("Home to University", routeList1);
ObservableList<Stop> routeList2 = FXCollections.observableArrayList();
routeList2.addAll(stop2, stop3, stop5);
Route route2 = new Route("Friends Route", routeList2);
boolean[] days = {false, true, true, false, true, false , false};
TripStop tripStop1 = new TripStop("1 Avonhead Road", "9:00");
TripStop tripStop4 = new TripStop("1 University Drive", "9:15");
ObservableList<TripStop> tripStops = FXCollections.observableArrayList();
tripStops.addAll(tripStop1, tripStop4);
Trip trip = new Trip("Home to Uni", tripStops, "University", ride, days, true, "30-12-2017");
this.session.getDataManager().addRides(ride);
this.session.getDataManager().addStop(stop1);
this.session.getDataManager().addStop(stop2);
this.session.getDataManager().addStop(stop3);
this.session.getDataManager().addStop(stop4);
this.session.getDataManager().addStop(stop5);
this.session.getDataManager().addRoute(route1);
this.session.getDataManager().addRoute(route2);
this.session.getDataManager().addTrip(trip);
}
//set up stage

@ -77,7 +77,11 @@ public class MyTripsController extends Controller{
if (selectedTrip.ride.getNumSeats() > seats){
parent.getSession().getDataManager().addSharedTrip(new SharedTrip(selectedTrip));
popUp(Alert.AlertType.CONFIRMATION, "SUCCESS!", "Trip has been successfully shared", "The trip can now be seen by other users when there are seats available.");
//TODO change scene
try {
changeScene(SceneCode.SHARED_RIDES);
} catch (Exception e) {
e.printStackTrace();
}
} else{
popUp(Alert.AlertType.WARNING, "WARNING!", "Error in Seats Available Input.", "You cannot share more seats than you have available (remember you need one for you to drive in).");
}

@ -0,0 +1,38 @@
package controllers;
import javafx.beans.property.SimpleStringProperty;
import javafx.fxml.FXML;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import model.SharedTrip;
import java.net.URL;
import java.util.ResourceBundle;
/**
* Created by Gondr on 28/05/2017.
*/
public class SharedTripsController extends Controller{
@FXML
private TableView<SharedTrip> sharedTripsTable;
@FXML
private TableColumn<SharedTrip, String> tripNameColumn;
@FXML
private TableColumn<SharedTrip, String> directionColumn;
@FXML
private TableColumn<SharedTrip, String> daysColumn;
@Override
public void runLater(){
sharedTripsTable.setItems(parent.getSession().getDataManager().getSharedTrips());
tripNameColumn.setCellValueFactory(p -> new SimpleStringProperty(p.getValue().name));
directionColumn.setCellValueFactory(p -> new SimpleStringProperty(p.getValue().direction));
daysColumn.setCellValueFactory(p -> new SimpleStringProperty(p.getValue().getDays()));
}
@Override
public void initialize(URL location, ResourceBundle resources) {
}
}

@ -15,7 +15,7 @@ public enum SceneCode {
MAIN("main", false), BASE("base", false),
//screens after login
HOME("home"),ADD_RIDE("addride"),MY_RIDES("myrides"), ADD_STOPS("addstops"), MY_STOPS("mystops"), ADD_ROUTE("addroute"),
MY_ROUTES("myroutes"), ADD_TRIP("addtrip"), MY_TRIPS("mytrips");
MY_ROUTES("myroutes"), ADD_TRIP("addtrip"), MY_TRIPS("mytrips"), SHARED_RIDES("sharedtrips");
private String path;
private boolean loadMenu;

@ -9,4 +9,17 @@ public class SharedTrip extends Trip {
super(trip.name, trip.route, trip.direction, trip.ride, trip.days, trip.reoccur, trip.endDate);
}
public String getDays(){
String daysString = "";
for (int i = 0; i < 7; i++){
if (days[i] == true){
daysString += Days.getValue(i).dayName + ", ";
}
}
if (daysString.length() != 0){
daysString = daysString.substring(0, daysString.length() - 2);
}
return daysString;
}
}

@ -28,6 +28,39 @@ public class Trip {
public static int SATURDAY = 5;
public static int SUNDAY = 6;
public enum Days{
MONDAY("Monday", 0), TUESDAY("Tuesday", 1), WEDNESDAY("Wednesday", 2), THURSDAY("THURSDAY", 3), FRIDAY("Friday", 4),
SATURDAY("SATURDAY", 5), SUNDAY("SUNDAY", 6);
public String dayName;
public int dayIndex;
Days(String dayName, int dayIndex){
this.dayName = dayName;
this.dayIndex = dayIndex;
}
public static Days getValue(int dayIndex){
switch(dayIndex){
case 0:
return MONDAY;
case 1:
return TUESDAY;
case 2:
return WEDNESDAY;
case 3:
return THURSDAY;
case 4:
return FRIDAY;
case 5:
return SATURDAY;
case 6:
return SUNDAY;
}
return null;
}
}
public Trip(String name, ObservableList<TripStop> route, String direction, Ride ride, boolean[] days, boolean reoccur, String endDate){
this.name = name;
this.route = route;

@ -52,6 +52,11 @@
<Button mnemonicParsing="false" onAction="#myTrips" text="Trips" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" />
</children>
</AnchorPane>
<AnchorPane>
<children>
<Button mnemonicParsing="false" onAction="#sharedRides" text="Shared Rides" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" />
</children>
</AnchorPane>
</children>
</VBox>
</children>

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="controllers.SharedTripsController">
<children>
<GridPane layoutX="213.0" layoutY="99.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="300.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="300.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="300.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="50.0" minHeight="50.0" prefHeight="50.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="40.0" minHeight="40.0" prefHeight="40.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="348.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="Shared Trips" GridPane.columnSpan="3" GridPane.halignment="CENTER">
<font>
<Font size="18.0" />
</font>
</Label>
<TableView fx:id="sharedTripsTable" prefHeight="200.0" prefWidth="200.0" GridPane.columnSpan="3" GridPane.rowIndex="2">
<columns>
<TableColumn fx:id="tripNameColumn" prefWidth="75.0" text="Trip Name" />
<TableColumn fx:id="directionColumn" prefWidth="75.0" text="Direction" />
<TableColumn fx:id="daysColumn" prefWidth="75.0" text="Days" />
</columns>
</TableView>
</children>
</GridPane>
</children>
</AnchorPane>

Binary file not shown.

@ -52,6 +52,11 @@
<Button mnemonicParsing="false" onAction="#myTrips" text="Trips" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" />
</children>
</AnchorPane>
<AnchorPane>
<children>
<Button mnemonicParsing="false" onAction="#sharedRides" text="Shared Rides" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" />
</children>
</AnchorPane>
</children>
</VBox>
</children>

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="controllers.SharedTripsController">
<children>
<GridPane layoutX="213.0" layoutY="99.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="300.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="300.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="300.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="50.0" minHeight="50.0" prefHeight="50.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="40.0" minHeight="40.0" prefHeight="40.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="348.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="Shared Trips" GridPane.columnSpan="3" GridPane.halignment="CENTER">
<font>
<Font size="18.0" />
</font>
</Label>
<TableView fx:id="sharedTripsTable" prefHeight="200.0" prefWidth="200.0" GridPane.columnSpan="3" GridPane.rowIndex="2">
<columns>
<TableColumn fx:id="tripNameColumn" prefWidth="75.0" text="Trip Name" />
<TableColumn fx:id="directionColumn" prefWidth="75.0" text="Direction" />
<TableColumn fx:id="daysColumn" prefWidth="75.0" text="Days" />
</columns>
</TableView>
</children>
</GridPane>
</children>
</AnchorPane>

@ -1 +1 @@
[{"model":"a","colour":"a","licensePlate":"a","year":1996,"numSeats":5}]
[{"model":"Nissan March","colour":"Baby Blue","licensePlate":"EPU001","year":2004,"numSeats":5}]

@ -1 +1 @@
[{"name":"asdf","serialisedStops":[{"address":"54 fwqfqwf"}]}]
[{"name":"Home to University","serialisedStops":[{"address":"1 Avonhead Road"},{"address":"1 University Drive"}]},{"name":"Friends Route","serialisedStops":[{"address":"100 Yaldhurst Road"},{"address":"120 Maidstone Road"},{"address":"1 Homestead Lane"}]}]

@ -1 +1 @@
[{"serialisedRoute":[{"serialiseTime":"3:00","serialiseName":"54 fwqfqwf"}],"direction":"University","ride":{"model":"a","colour":"a","licensePlate":"a","year":1996,"numSeats":5},"days":[true,false,false,true,false,true,false],"reoccur":true,"endDate":"2017-06-08","name":"safsdf"}]
[{"serialisedRoute":[{"serialiseTime":"9:00","serialiseName":"1 Avonhead Road"},{"serialiseTime":"9:15","serialiseName":"1 University Drive"}],"direction":"University","ride":{"model":"Nissan March","colour":"Baby Blue","licensePlate":"EPU001","year":2004,"numSeats":5},"days":[false,true,true,false,true,false,false],"reoccur":true,"endDate":"30-12-2017","name":"Home to Uni"}]

@ -1 +1 @@
[{"address":"54 fwqfqwf"}]
[{"address":"1 Avonhead Road"},{"address":"100 Yaldhurst Road"},{"address":"120 Maidstone Road"},{"address":"1 University Drive"},{"address":"1 Homestead Lane"}]

@ -1 +1 @@
[{"serialisedRoute":[{"serialiseTime":"3:00","serialiseName":"54 fwqfqwf"}],"direction":"University","ride":{"model":"a","colour":"a","licensePlate":"a","year":1996,"numSeats":5},"days":[true,false,false,true,false,true,false],"reoccur":true,"endDate":"2017-06-08","name":"safsdf"}]
[{"serialisedRoute":[{"serialiseTime":"9:00","serialiseName":"1 Avonhead Road"},{"serialiseTime":"9:15","serialiseName":"1 University Drive"}],"direction":"University","ride":{"model":"Nissan March","colour":"Baby Blue","licensePlate":"EPU001","year":2004,"numSeats":5},"days":[false,true,true,false,true,false,false],"reoccur":true,"endDate":"30-12-2017","name":"Home to Uni"}]
Loading…
Cancel
Save