Fixed up missing acceptance criteria of story 7

main
Fan-Wu Yang 9 years ago
parent 434017c558
commit cb50ea176c

@ -147,7 +147,7 @@ public class AddTripController extends Controller{
}
});
String[] dir = {"University","Home"};
String[] dir = {Trip.TO_UNI, Trip.TO_HOME};
ObservableList<String> dirArr = FXCollections.observableArrayList(dir);
direction.setItems(dirArr);
direction.getSelectionModel().selectFirst();

@ -10,6 +10,7 @@ import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import model.SharedTrip;
import model.Stop;
import model.Trip;
import model.TripStop;
import java.net.URL;
@ -36,6 +37,12 @@ public class SharedTripsController extends Controller{
private ObservableList<SharedTrip> sharedTrips;
@FXML
private TextField stopName;
@FXML
private ComboBox<String> directionBox;
public void showDetails(){
}
public void resetSearch(){
stopsFilter.getSelectionModel().select(0);
@ -43,26 +50,35 @@ public class SharedTripsController extends Controller{
public void search(){
sharedTrips.remove(0, sharedTrips.size());
//ignore stop
boolean ignoreStopFilter = stopsFilter.getSelectionModel().getSelectedIndex() == 0;
boolean ignoreStopNameSearch = stopName.getText().equals("") || stopName.getText() == null;
boolean ignoreStopSearch = ignoreStopFilter && ignoreStopNameSearch;
Pattern stopNamePattern = Pattern.compile(".*"+stopName.getText()+".*", Pattern.CASE_INSENSITIVE);
//ignore direction
boolean ignoreDirection = directionBox.getSelectionModel().isSelected(0);
for(SharedTrip sharedTrip: parent.getSession().getDataManager().getSharedTrips()){
//stops are equal
boolean added = false;
boolean add = false;
for (TripStop stop : sharedTrip.route) {
if (stop.equals(stopsFilter.getValue()) || ignoreStopFilter) {
sharedTrips.add(sharedTrip);
added = true;
if (ignoreStopSearch){
add = true;
break;
}
if (stop.equals(stopsFilter.getValue())) {
add = true;
break;
}
if (stopNamePattern.matcher(stop.getName()).matches()){
sharedTrips.add(sharedTrip);
added = true;
add = true;
break;
}
}
if (added){
continue;//for other filters later
if (!ignoreDirection) {
add = sharedTrip.direction.equals(directionBox.getValue());
}
if (add){
sharedTrips.add(sharedTrip);//for other filters later
}
}
}
@ -76,7 +92,7 @@ public class SharedTripsController extends Controller{
daysColumn.setCellValueFactory(p -> new SimpleStringProperty(p.getValue().getDays()));
//add all stops that have shared trips with them. TODO only display visible ones.
ObservableList<TripStop> stops = FXCollections.observableArrayList();
stops.add(new TripStop("None", ""));
stops.add(new TripStop("Any", ""));
HashMap<TripStop, Boolean> stopAdded = new HashMap<>();
for (SharedTrip trip:sharedTrips){
for(TripStop stop: trip.route){
@ -91,10 +107,13 @@ public class SharedTripsController extends Controller{
search();
});
stopName.textProperty().addListener(e-> search());
directionBox.valueProperty().addListener(e->search());
}
@Override
public void initialize(URL location, ResourceBundle resources) {
ObservableList<String> directions = FXCollections.observableArrayList();
directions.addAll("Any", Trip.TO_UNI, Trip.TO_HOME);
directionBox.setItems(directions);
}
}

@ -28,6 +28,9 @@ public class Trip {
public static int SATURDAY = 5;
public static int SUNDAY = 6;
public static String TO_UNI = "University";
public static String TO_HOME = "Home";
public enum Days{
MONDAY("Monday", 0), TUESDAY("Tuesday", 1), WEDNESDAY("Wednesday", 2), THURSDAY("THURSDAY", 3), FRIDAY("Friday", 4),
SATURDAY("SATURDAY", 5), SUNDAY("SUNDAY", 6);

@ -24,6 +24,7 @@
<RowConstraints maxHeight="40.0" minHeight="40.0" prefHeight="40.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 maxHeight="40.0" minHeight="40.0" prefHeight="40.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="Shared Trips" GridPane.columnSpan="6" GridPane.halignment="CENTER">
@ -49,6 +50,13 @@
<Button fx:id="resetSearch" mnemonicParsing="false" text="Reset Search" AnchorPane.bottomAnchor="8.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="7.0" GridPane.columnIndex="2" GridPane.columnSpan="2" GridPane.rowIndex="4" GridPane.valignment="CENTER" />
</children>
</AnchorPane>
<Label text="Direction:" GridPane.columnIndex="4" GridPane.rowIndex="3" />
<AnchorPane prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="2" GridPane.columnSpan="2" GridPane.rowIndex="6">
<children>
<Button layoutX="60.0" layoutY="2.0" mnemonicParsing="false" onAction="#showDetails" text="Details/Book" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" />
</children>
</AnchorPane>
<ComboBox fx:id="directionBox" prefWidth="150.0" GridPane.columnIndex="5" GridPane.rowIndex="3" />
</children>
</GridPane>
</children>

Binary file not shown.

@ -24,6 +24,7 @@
<RowConstraints maxHeight="40.0" minHeight="40.0" prefHeight="40.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 maxHeight="40.0" minHeight="40.0" prefHeight="40.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="Shared Trips" GridPane.columnSpan="6" GridPane.halignment="CENTER">
@ -49,6 +50,13 @@
<Button fx:id="resetSearch" mnemonicParsing="false" text="Reset Search" AnchorPane.bottomAnchor="8.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="7.0" GridPane.columnIndex="2" GridPane.columnSpan="2" GridPane.rowIndex="4" GridPane.valignment="CENTER" />
</children>
</AnchorPane>
<Label text="Direction:" GridPane.columnIndex="4" GridPane.rowIndex="3" />
<AnchorPane prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="2" GridPane.columnSpan="2" GridPane.rowIndex="6">
<children>
<Button layoutX="60.0" layoutY="2.0" mnemonicParsing="false" onAction="#showDetails" text="Details/Book" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" />
</children>
</AnchorPane>
<ComboBox fx:id="directionBox" prefWidth="150.0" GridPane.columnIndex="5" GridPane.rowIndex="3" />
</children>
</GridPane>
</children>

Loading…
Cancel
Save