Commit 6cd21159 authored by Josselin ENET's avatar Josselin ENET

Updated existing classes

Added things to existing classes to prepare for the implementation of
new fonctionalities.
parent b6b3dbe2
......@@ -2,9 +2,12 @@ package fr.unantes.software.construction.ui;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
public class AdminHomeController extends SceneController {
......@@ -12,35 +15,89 @@ public class AdminHomeController extends SceneController {
public AdminHomeController(GUI gui) { super(gui); }
public Scene createScene() {
gui.setTitle("Admin Home");
GridPane root = new GridPane();
//user management section title
Text userManagementText = new Text("User Management");
userManagementText.setUnderline(true);
userManagementText.setFont(new Font(18));
// remove button
Button removeButton = new Button();
removeButton.setText("Remove");
removeButton.setOnAction(event -> {
Button removeUserButton = new Button();
removeUserButton.setText("Remove");
removeUserButton.setOnAction(event -> {
gui.setController(new AdminUserRemovalController(gui));
});
// add button
Button addButton = new Button();
addButton.setText("Add");
addButton.setOnAction(event -> {
Button addUserButton = new Button();
addUserButton.setText("Add");
addUserButton.setOnAction(event -> {
gui.setController(new AdminUserAdditionController(gui));
});
// modify button
Button modifyButton = new Button();
modifyButton.setText("Modify");
modifyButton.setOnAction(event -> {
Button modifyUserButton = new Button();
modifyUserButton.setText("Modify");
modifyUserButton.setOnAction(event -> {
gui.setController(new AdminUserModificationController(gui));
});
root.add(addButton, 0, 0);
root.add(removeButton, 0, 1);
root.add(modifyButton, 0, 2);
//travel management section title
Text travelManagementText = new Text("Travel Management");
travelManagementText.setUnderline(true);
travelManagementText.setFont(new Font(18));
// modify button
Button modifyTravelButton = new Button();
modifyTravelButton.setText("Modify");
modifyTravelButton.setOnAction(event -> {
gui.setController(new AdminTravelModificationController(gui));
});
// remove button
Button removeTravelButton = new Button();
removeTravelButton.setText("Remove");
removeTravelButton.setOnAction(event -> {
gui.setController(new AdminTravelRemovalController(gui));
});
//agent reservation section title
Text agentReservationText = new Text("Agent Reservation");
agentReservationText.setUnderline(true);
agentReservationText.setFont(new Font(18));
// reserve button
Button reserveTravelButton = new Button();
reserveTravelButton.setText("Reserve");
reserveTravelButton.setOnAction(event -> {
gui.setController(new AdminTravelReservationController(gui));
});
root.add(userManagementText, 0, 0);
root.setMargin(userManagementText, new Insets(2));
root.add(addUserButton, 0, 1);
root.setMargin(addUserButton, new Insets(2));
root.add(removeUserButton, 0, 2);
root.setMargin(removeUserButton, new Insets(2));
root.add(modifyUserButton, 0, 3);
root.setMargin(modifyUserButton, new Insets(2));
root.add(travelManagementText, 0, 5);
root.setMargin(travelManagementText, new Insets(2));
root.add(removeTravelButton, 0, 6);
root.setMargin(removeTravelButton, new Insets(2));
root.add(modifyTravelButton, 0, 7);
root.setMargin(modifyTravelButton, new Insets(2));
root.add(agentReservationText, 0, 9);
root.setMargin(agentReservationText, new Insets(2));
root.add(reserveTravelButton, 0, 11);
root.setMargin(reserveTravelButton, new Insets(2));
Scene result = new Scene(root,400,250);
Scene result = new Scene(root,400,300);
return result;
}
......
......@@ -50,7 +50,7 @@ public class AdminUserAdditionController extends SceneController {
addButton.setOnAction(event -> {
RadioButton selectedRadioButton = (RadioButton) groupRadioButtons.getSelectedToggle();
if (selectedRadioButton == null) {
AlertHandler.showAlert(ERROR, "Pas de rôle sélectionné.");
AlertHandler.showAlert(ERROR, "No role selected.");
}
else {
String name = nameTextField.getText();
......@@ -86,13 +86,13 @@ public class AdminUserAdditionController extends SceneController {
public void handleAdd(String name, String username, String role, String password) {
if (name.equals("")) {
AlertHandler.showAlert(ERROR, "Pas de nom précisé.");
AlertHandler.showAlert(ERROR, "No name specified.");
}
else if (username.equals("")) {
AlertHandler.showAlert(ERROR, "Pas de pseudo précisé.");
AlertHandler.showAlert(ERROR, "No username specified.");
}
else if (password.equals("")) {
AlertHandler.showAlert(ERROR, "Pas de mot de passe précisé.");
AlertHandler.showAlert(ERROR, "No password specified.");
}
else {
Person user;
......@@ -107,11 +107,11 @@ public class AdminUserAdditionController extends SceneController {
additionRegistered = gui.getUsersDB().addUser(user, password, username);
}
catch (IllegalArgumentException e) {
AlertHandler.showAlert(ERROR, "Utilisateur déjà présent.");
AlertHandler.showAlert(ERROR, "User already registered.");
}
if (additionRegistered) {
AlertHandler.showAlert(INFORMATION, "Utilisateur ajouté.");
AlertHandler.showAlert(INFORMATION, "User successfully registered.");
}
}
}
......
......@@ -77,7 +77,7 @@ public class AdminUserModificationController extends SceneController {
modifyButton.setOnAction(event -> {
Person selectedUser = (Person) usersComboBox.getValue();
if (selectedUser == null) {
AlertHandler.showAlert(ERROR, "Pas d'utilisateur sélectionné.");
AlertHandler.showAlert(ERROR, "No user selected.");
}
else {
boolean newRole = roleCheckbox.isSelected();
......@@ -109,10 +109,10 @@ public class AdminUserModificationController extends SceneController {
public void handleModify(Person modifiedUser, boolean newRole, String newPassword) {
if (modifiedUser.equals(gui.getCurrentUser())) {
AlertHandler.showAlert(ERROR, "Impossible de modifier l'utilisateur connecté.");
AlertHandler.showAlert(ERROR, "Impossible to modify the current user.");
}
else if (newRole == false && newPassword.equals("")) {
AlertHandler.showAlert(ERROR, "Pas de modification selectionnée.");
AlertHandler.showAlert(ERROR, "No modification selected.");
}
else {
if (newRole) {
......@@ -127,7 +127,7 @@ public class AdminUserModificationController extends SceneController {
} else {
gui.getUsersDB().changeUserPassword(new Agent(modifiedUser.getName()), newPassword);
}
AlertHandler.showAlert(INFORMATION, "Utilisateur modifié.");
AlertHandler.showAlert(INFORMATION, "User successfully modified.");
}
}
}
......
......@@ -61,7 +61,7 @@ public class AdminUserRemovalController extends SceneController {
removeButton.setOnAction(event -> {
Person selectedUser = (Person) usersComboBox.getValue();
if (selectedUser == null) {
AlertHandler.showAlert(ERROR, "Pas d'utilisateur sélectionné.");
AlertHandler.showAlert(ERROR, "No user selected.");
}
else {
handleRemove(selectedUser);
......@@ -94,20 +94,16 @@ public class AdminUserRemovalController extends SceneController {
public void handleRemove(Person user) {
if (user.equals(gui.getCurrentUser())) {
AlertHandler.showAlert(ERROR, "Impossible de supprimer l'utilisateur connecté.");
AlertHandler.showAlert(ERROR, "Impossible to delete the current user.");
}
else {
if (gui.getUsersDB().removeUser(user)) {
AlertHandler.showAlert(INFORMATION, "Utilisateur supprimé.");
AlertHandler.showAlert(INFORMATION, "User successfully deleted.");
}
else {
AlertHandler.showAlert(ERROR, "Cet utilisateur n'existe pas.");
AlertHandler.showAlert(ERROR, "This user does not exist.");
}
}
}
public String getTitle() {
return "User Removal";
}
}
package fr.unantes.software.construction.ui;
import fr.unantes.software.construction.calendar.Calendar;
import fr.unantes.software.construction.calendar.Travel;
import fr.unantes.software.construction.people.Agent;
import javafx.scene.Scene;
import javafx.scene.control.ComboBox;
import javafx.scene.control.*;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.util.Callback;
import static javafx.scene.text.TextAlignment.CENTER;
import java.io.InvalidClassException;
import java.util.List;
import static javafx.scene.control.Alert.AlertType.ERROR;
import static javafx.scene.control.Alert.AlertType.INFORMATION;
public class AgentHomeController extends SceneController {
......@@ -14,19 +23,100 @@ public class AgentHomeController extends SceneController {
}
public Scene createScene() {
gui.setTitle("Agent Home");
GridPane root = new GridPane();
// combo box de l'adresse de départ
ComboBox departComboBox = new ComboBox();
//Travel reservation section title
Text travelReservationText = new Text("Travel Reservation");
travelReservationText.setUnderline(true);
travelReservationText.setFont(new Font(18));
//travels combo box
ComboBox travelsComboBox = new ComboBox();
updateComboBox(travelsComboBox);
Label lbTravelsComboBox = new Label("Travel:");
lbTravelsComboBox.setLabelFor(travelsComboBox);
Callback<ListView<Travel>, ListCell<Travel>> cellFactory = new Callback<ListView<Travel>, ListCell<Travel>>() {
@Override
public ListCell<Travel> call(ListView<Travel> l) {
return new ListCell<Travel>() {
@Override
protected void updateItem(Travel item, boolean empty) {
super.updateItem(item, empty);
if (item == null || empty) {
setGraphic(null);
} else {
setText(item.getFirstStep().getStartCity().getName()+" - "+item.getLastStep().getDestinationCity().getName());
}
}
} ;
}
};
travelsComboBox.setCellFactory(cellFactory);
ListCell<Travel> buttonCell = new ListCell<Travel>() {
@Override
protected void updateItem(Travel item, boolean empty) {
super.updateItem(item, empty);
if (item != null) {
setText(item.getFirstStep().getStartCity().getName()+" - "+item.getLastStep().getDestinationCity().getName());
} else {
setText(null);
}
}
};
travelsComboBox.setButtonCell(buttonCell);
// combo box de l'adresse d'arrivée
ComboBox arriveeComboBox = new ComboBox();
// reserve button
Button reserveButton = new Button();
reserveButton.setText("Reserve");
reserveButton.setOnAction(event -> {
Travel selectedTravel = (Travel) travelsComboBox.getValue();
if (selectedTravel == null) {
AlertHandler.showAlert(ERROR, "No travel selected.");
}
else {
handleReserve(selectedTravel);
updateComboBox(travelsComboBox);
}
});
root.add(departComboBox, 0, 0);
root.add(arriveeComboBox, 0, 0);
// booked travels button
Button bookedTravelsButton = new Button();
bookedTravelsButton.setText("Your Travels");
bookedTravelsButton.setOnAction(event -> {
gui.setController(new AgentBookedTravelsController(gui));
});
root.add(travelReservationText, 0,0);
root.add(lbTravelsComboBox,0,2);
root.add(travelsComboBox, 1, 2);
root.add(reserveButton, 0, 4);
root.add(bookedTravelsButton, 0, 6);
Scene result = new Scene(root,400,250);
return result;
}
private void updateComboBox(ComboBox usersComboBox) {
List<Travel> travelsList = gui.getTravelsDB().getAllTravel();
ObservableListImplementation<Travel> travelsObservableList = new ObservableListImplementation<>(travelsList);
usersComboBox.setItems(travelsObservableList);
}
public void handleReserve(Travel travel) {
Calendar userCalendar = new Calendar();
try {
userCalendar = (Calendar) gui.getCurrentUser().getCalendarAssociation().get();
} catch (InvalidClassException e) {
e.printStackTrace();
}
if (userCalendar.getTravelAssociation().contains(travel)) {
AlertHandler.showAlert(ERROR, "You have already booked this travel.");
}
else {
gui.getCurrentUser().addTravelTo(travel, (Agent) gui.getCurrentUser());
AlertHandler.showAlert(INFORMATION, "Travel booked.");
}
}
}
package fr.unantes.software.construction.ui;
import fr.unantes.software.construction.calendar.AllTravels;
import fr.unantes.software.construction.people.Admin;
import fr.unantes.software.construction.people.Agent;
import fr.unantes.software.construction.people.Person;
import fr.unantes.software.construction.security.UserManager;
import javafx.application.Application;
......@@ -12,14 +14,19 @@ public class GUI extends Application {
private SceneController controller;
private UserManager usersDB;
private Person currentUser;
private AllTravels travelsDB;
@Override
public void start(Stage stage) throws Exception {
this.stage = stage;
usersDB = new UserManager();
//test user
usersDB.addUser(new Admin("Robert"), "oui", "hulk");
travelsDB = new AllTravels();
//test users
usersDB.addUser(new Admin("Robert"), "kebab1", "roro");
usersDB.addUser(new Agent("David"), "oui", "king");
controller = new LoginFormController(this);
stage.setScene(controller.createScene());
stage.setTitle("Login");
......@@ -32,6 +39,10 @@ public class GUI extends Application {
}
public SceneController getController() {
return controller;
}
public UserManager getUsersDB() {
return usersDB;
}
......@@ -47,4 +58,8 @@ public class GUI extends Application {
public void setTitle(String title) {
stage.setTitle(title);
}
public AllTravels getTravelsDB() {
return travelsDB;
}
}
\ No newline at end of file
......@@ -51,22 +51,22 @@ public class LoginFormController extends SceneController {
}
private void handleSubmission(String username, String password) {
@Override
public void handleSubmission(String username, String password) {
if (username.equals("")) {
AlertHandler.showAlert(ERROR, "Veuillez entrer un nom d'utilisateur.");
AlertHandler.showAlert(ERROR, "Please specify an username.");
}
else if (password.equals("")) {
AlertHandler.showAlert(ERROR, "Veuillez entrer un mot de passe.");
AlertHandler.showAlert(ERROR, "Please specify a password.");
}
else if (!gui.getUsersDB().hasUser(username)) {
AlertHandler.showAlert(ERROR, "Cet utilisateur n'existe pas.");
AlertHandler.showAlert(ERROR, "This user does not exist.");
}
else {
Person user = gui.getUsersDB().getUser(username);
if (!gui.getUsersDB().validatePassword(user, password)) {
AlertHandler.showAlert(ERROR, "Mot de passe incorrect.");
AlertHandler.showAlert(ERROR, "Incorrect password.");
}
else {
SceneController newController;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment