diff --git a/src/main/java/seedu/address/logic/commands/DeleteCommand.java b/src/main/java/seedu/address/logic/commands/DeleteCommand.java index bf713d43b3d..79d457e3bf7 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteCommand.java @@ -10,8 +10,6 @@ import seedu.address.model.Model; import seedu.address.model.person.Id; import seedu.address.model.person.Person; -import seedu.address.ui.ConfirmationBox; -import seedu.address.ui.Prompt; /** * Deletes a person identified using the email id from the address book. @@ -33,22 +31,6 @@ public class DeleteCommand extends Command { private final Id targetId; private Person personToDelete; - private Prompt confirmationBox; - - /** - * Creates a {@code DeleteCommand} with the specified target ID and a custom {@code Prompt} - * for displaying confirmation dialogs. This constructor is primarily intended for use in - * scenarios where dependency injection is desired, such as unit testing, allowing for - * the replacement of the confirmation dialog with a fake implementation. - * - * @param targetId The ID of the person to be deleted. - * @param confirmationBox The {@code Prompt} implementation to be used for displaying - * confirmation dialogs. - */ - public DeleteCommand(Id targetId, Prompt confirmationBox) { - this.targetId = targetId; - this.confirmationBox = confirmationBox; - } /** * Creates a {@code DeleteCommand} with the specified target ID and no custom {@code Prompt}. @@ -60,7 +42,6 @@ public DeleteCommand(Id targetId, Prompt confirmationBox) { */ public DeleteCommand(Id targetId) { this.targetId = targetId; - this.confirmationBox = null; } @Override @@ -72,20 +53,6 @@ public CommandResult execute(Model model) throws CommandException { String deletedInformation = ""; for (Person person : lastShownList) { if (person.getId().equals(this.targetId)) { - boolean isConfirmed; - if (confirmationBox == null) { - isConfirmed = new ConfirmationBox().display("Confirmation", - "Are you sure you want to delete this person?"); - } else { - // This branch is designed for tests only. - // In actual use this branch will not be visited. - isConfirmed = confirmationBox.display("test", "test"); - } - if (!isConfirmed) { - throw new CommandException(MESSAGE_DELETION_CANCELLED); - } - assert isConfirmed; - personToDelete = person; model.deletePerson(personToDelete); isAnyRecordDeleted = true; diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index a502152807e..d6adac3c944 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -81,7 +81,7 @@ public CommandResult execute(Model model) throws CommandException { List lastShownList = model.getFilteredPersonList(); boolean isPersonExist = false; - Person personToEdit = new Person(new Name("test"), + personToEdit = new Person(new Name("test"), new Id("test"), new Phone("123"), new HashSet()); for (int i = 0; i < lastShownList.size(); i++) { @@ -205,7 +205,7 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) { * Returns true if at least one field is edited. */ public boolean isAnyFieldEdited() { - return CollectionUtil.isAnyNonNull(name, phone); + return CollectionUtil.isAnyNonNull(name, phone, tags); //email, address, tags); } diff --git a/src/main/java/seedu/address/logic/parser/EditCommandParser.java b/src/main/java/seedu/address/logic/parser/EditCommandParser.java index 27d2ae67462..e3e9b8f41e3 100644 --- a/src/main/java/seedu/address/logic/parser/EditCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/EditCommandParser.java @@ -34,7 +34,7 @@ public class EditCommandParser implements Parser { public EditCommand parse(String args) throws ParseException { requireNonNull(args); ArgumentMultimap argMultimap = - ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE); + ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_TAG); //PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_TAG Id id; diff --git a/src/main/java/seedu/address/ui/ConfirmationBox.java b/src/main/java/seedu/address/ui/ConfirmationBox.java deleted file mode 100644 index e81ade877a8..00000000000 --- a/src/main/java/seedu/address/ui/ConfirmationBox.java +++ /dev/null @@ -1,34 +0,0 @@ -package seedu.address.ui; - -import java.util.Optional; - -import javafx.scene.control.Alert; -import javafx.scene.control.ButtonType; - - -/** - * The UI component that is responsible for asking for confirmation from users. - */ -public class ConfirmationBox implements Prompt { - /** - * Displays a modal confirmation dialog box with a specified title and message. The method blocks until the user - * responds to the dialog. - * - * @param title The title of the confirmation dialog box. This appears in the title bar of the dialog. - * @param message The message displayed to the user, asking for confirmation. - * @return {@code true} if the user clicks the OK button, {@code false} if the user clicks the Cancel button - * or closes the dialog box. - */ - @Override - public boolean display(String title, String message) { - Alert alert = new Alert(Alert.AlertType.CONFIRMATION); - alert.setTitle(title); - alert.setHeaderText(null); - alert.setContentText(message); - - Optional result = alert.showAndWait(); - return result.isPresent() && result.get() == ButtonType.OK; - } -} - - diff --git a/src/main/java/seedu/address/ui/FakeConfirmationBox.java b/src/main/java/seedu/address/ui/FakeConfirmationBox.java deleted file mode 100644 index 75df9ea8479..00000000000 --- a/src/main/java/seedu/address/ui/FakeConfirmationBox.java +++ /dev/null @@ -1,33 +0,0 @@ -package seedu.address.ui; - -/** - * A fake implementation of a confirmation box for testing purposes. This class simulates - * user responses to confirmation dialogs without displaying an actual user interface. - * It is designed to be used in unit tests to provide controlled responses to actions - * that would normally require user interaction. - */ -public class FakeConfirmationBox implements Prompt { - private boolean userResponse; - - /** - * Constructs a {@code FakeConfirmationBox} with a predetermined user response. - * - * @param userResponse the simulated response to the confirmation dialog. {@code true} to simulate - * the user confirming the action, {@code false} to simulate the user canceling the action. - */ - public FakeConfirmationBox(boolean userResponse) { - this.userResponse = userResponse; - } - - /** - * Simulates the display of a confirmation dialog and returns the predetermined user response. - * - * @param title the title of the dialog (not used). - * @param message the message of the dialog (not used). - * @return the predetermined user response to the simulated confirmation dialog. - */ - @Override - public boolean display(String title, String message) { - return userResponse; - } -} diff --git a/src/main/java/seedu/address/ui/LoginFormController.java b/src/main/java/seedu/address/ui/LoginFormController.java deleted file mode 100644 index 53cdca53ad4..00000000000 --- a/src/main/java/seedu/address/ui/LoginFormController.java +++ /dev/null @@ -1,80 +0,0 @@ -package seedu.address.ui; - -import javafx.fxml.FXML; -import javafx.scene.control.Alert; -import javafx.scene.control.Alert.AlertType; -import javafx.scene.control.PasswordField; -import javafx.scene.control.TextField; -import seedu.address.account.account.Account; -import seedu.address.logic.AccountManager; - -/** - * Represents a controller for the login form. - * Each LoginFormController is associated with a username field, a password field, and an account list. - * The LoginFormController handles the login process, including input validation and user authentication. - */ -public class LoginFormController { - @FXML - private TextField usernameField; - - @FXML - private PasswordField passwordField; - - private AccountManager accountManager; - private MainWindow mainWindow; - - /** - * Constructs a LoginFormController with the specified AccountManager and MainWindow. - * - * @param accountManager The AccountManager to be used for user authentication. - * @param mainWindow The MainWindow to be updated upon successful login. - */ - public LoginFormController(AccountManager accountManager, MainWindow mainWindow) { - this.accountManager = accountManager; - this.mainWindow = mainWindow; - } - - @FXML - private void handleLogin() { - if (accountManager.getLoginStatus()) { - showAlert("Error", "You are already logged in. Please log out first."); - return; - } - - String username = usernameField.getText(); - String password = passwordField.getText(); - - // Validate the input fields here - if (username.isEmpty() || password.isEmpty()) { - showAlert("Error", "Username and password cannot be empty"); - return; - } - - // If the input is valid, authenticate the user - String passwordHash = accountManager.getAccountList().hashPassword(password); - Account account = accountManager.getAccountList().authenticate(username, passwordHash); - if (account != null) { - // Authentication successful - showAlert("Success", "Login successful"); - accountManager.login(account); - mainWindow.fillInnerParts(); - } else { - // Authentication failed - showAlert("Error", "Login failed. Invalid username or password."); - } - } - - /** - * Displays an alert with the specified title and message. - * - * @param title The title of the alert. - * @param message The message to be displayed in the alert. - */ - private void showAlert(String title, String message) { - Alert alert = new Alert(AlertType.INFORMATION); - alert.setTitle(title); - alert.setHeaderText(null); - alert.setContentText(message); - alert.showAndWait(); - } -} diff --git a/src/main/java/seedu/address/ui/MainWindow.java b/src/main/java/seedu/address/ui/MainWindow.java index 32b593b14a4..1a8aafa9ab3 100644 --- a/src/main/java/seedu/address/ui/MainWindow.java +++ b/src/main/java/seedu/address/ui/MainWindow.java @@ -1,13 +1,9 @@ package seedu.address.ui; -import java.io.IOException; import java.util.logging.Logger; import javafx.event.ActionEvent; import javafx.fxml.FXML; -import javafx.fxml.FXMLLoader; -import javafx.scene.Parent; -import javafx.scene.Scene; import javafx.scene.control.MenuItem; import javafx.scene.control.TextInputControl; import javafx.scene.input.KeyCombination; @@ -240,41 +236,6 @@ private void handleRedo() throws AccountException, CommandException, ParseExcept } } - @FXML - private void handleRegister() { - try { - FXMLLoader loader = new FXMLLoader(getClass().getResource("/view/RegisterForm.fxml")); - RegisterFormController controller = new RegisterFormController(accountManager); - loader.setController(controller); - Parent root = loader.load(); - Stage stage = new Stage(); - stage.setScene(new Scene(root)); - stage.show(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @FXML - private void handleLogin() { - try { - if (accountManager.getLoginStatus()) { - resultDisplay.setFeedbackToUser("You have already logged in."); - return; - } - - FXMLLoader loader = new FXMLLoader(getClass().getResource("/view/LoginForm.fxml")); - LoginFormController controller = new LoginFormController(accountManager, this); - loader.setController(controller); - Parent root = loader.load(); - Stage stage = new Stage(); - stage.setScene(new Scene(root)); - stage.show(); - } catch (IOException e) { - e.printStackTrace(); - } - } - @FXML private void handleLogout() { if (!accountManager.getLoginStatus()) { diff --git a/src/main/java/seedu/address/ui/RegisterFormController.java b/src/main/java/seedu/address/ui/RegisterFormController.java deleted file mode 100644 index 53be1d89625..00000000000 --- a/src/main/java/seedu/address/ui/RegisterFormController.java +++ /dev/null @@ -1,73 +0,0 @@ -package seedu.address.ui; - -import javafx.fxml.FXML; -import javafx.scene.control.Alert; -import javafx.scene.control.Alert.AlertType; -import javafx.scene.control.PasswordField; -import javafx.scene.control.TextField; -import seedu.address.account.account.Account; -import seedu.address.account.account.Username; -import seedu.address.logic.AccountManager; - -/** - * Represents a controller for the registration form. - * Each RegisterFormController is associated with a username field, a password field, and an account list. - * The RegisterFormController handles the registration process, including input validation and user creation. - */ -public class RegisterFormController { - - @FXML - private TextField usernameField; - - @FXML - private PasswordField passwordField; - - private AccountManager accountManager; - - public RegisterFormController(AccountManager accountManager) { - this.accountManager = accountManager; - } - - @FXML - private void handleRegister() { - String username = usernameField.getText(); - String password = passwordField.getText(); - - // Validate the input fields here - if (username.isEmpty() || password.isEmpty()) { - showAlert("Error", "Username and password cannot be empty"); - return; - } - - if (!isValidUsername(username)) { - showAlert("Error", "Invalid username. Username should be 4-10 alphanumeric characters."); - return; - } - - // If the input is valid, create a new Account and add it to the AccountList - Username usernameObj = new Username(username); - String passwordHash = accountManager.getAccountList().hashPassword(password); - Account account = new Account(usernameObj, passwordHash); - - boolean success = accountManager.getAccountList().addAccount(account); - if (success) { - // Registration successful - showAlert("Success", "Registration successful"); - } else { - // Registration failed - showAlert("Error", "Registration failed. Username already exists."); - } - } - - private boolean isValidUsername(String username) { - return username != null && username.matches("[a-zA-Z0-9]{4,10}"); - } - - private void showAlert(String title, String message) { - Alert alert = new Alert(AlertType.INFORMATION); - alert.setTitle(title); - alert.setHeaderText(null); - alert.setContentText(message); - alert.showAndWait(); - } -} diff --git a/src/main/resources/view/LoginForm.fxml b/src/main/resources/view/LoginForm.fxml deleted file mode 100644 index 24220235376..00000000000 --- a/src/main/resources/view/LoginForm.fxml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - -