diff --git a/src/main/java/controller/Controller.java b/src/main/java/controller/Controller.java index 5d2e4df..c1d259a 100644 --- a/src/main/java/controller/Controller.java +++ b/src/main/java/controller/Controller.java @@ -59,7 +59,7 @@ public static String createNewUser(String firstName, String lastName, String Bir preparedStatement.setString(4, userType); preparedStatement.setString(5, password); preparedStatement.executeUpdate(); - userCreationStatus = "User sucessfully created"; + userCreationStatus = "User successfully created"; } catch (SQLException e) { e.printStackTrace(); userCreationStatus = "User creation failed"; @@ -90,7 +90,7 @@ public static String createNewMission(String title, String description, String d preparedStatement.setString(3, date); preparedStatement.setInt(4, idUser); preparedStatement.executeUpdate(); - missionCreationStatus = "Mission sucessfully created"; + missionCreationStatus = "Mission successfully created"; } catch (SQLException e) { e.printStackTrace(); missionCreationStatus = "Mission creation failed"; @@ -113,4 +113,40 @@ public static ArrayList getMissionsOfNeeder(int idNeeder){ } return missions; } + + public static ArrayList getMissionsToValidate() { + ArrayList missions = new ArrayList(); + try { + String getMissionsRequest = "SELECT * FROM MISSIONS WHERE Status = 'Pending'"; + ResultSet missionsRS = bdd.state.executeQuery(getMissionsRequest); + while (missionsRS.next()) { + Mission mission = new Mission(missionsRS.getInt("IdMission"), missionsRS.getString("Title"), missionsRS.getString("Description"), missionsRS.getString("Date"), missionsRS.getInt("IdNeeder"), missionsRS.getString("Status")); + missions.add(mission); + } + } + catch (SQLException e) { + e.printStackTrace(); + } + return missions; + } + + public static void acceptMission(int idMission) { + try { + String acceptMissionQuery = "UPDATE MISSIONS SET Status = 'Accepted' WHERE IdMission = '" + idMission + "'"; + bdd.state.executeUpdate(acceptMissionQuery); + } + catch (SQLException e) { + e.printStackTrace(); + } + } + + public static void refuseMission(int idMission) { + try { + String refuseMissionQuery = "UPDATE MISSIONS SET Status = 'Refused' WHERE IdMission = '" + idMission + "'"; + bdd.state.executeUpdate(refuseMissionQuery); + } + catch (SQLException e) { + e.printStackTrace(); + } + } } diff --git a/src/main/java/model/Status.java b/src/main/java/model/Status.java index 6e5f142..8ec02b9 100644 --- a/src/main/java/model/Status.java +++ b/src/main/java/model/Status.java @@ -7,7 +7,7 @@ public enum Status { Refused(3), Done(4); - private int value; + private final int value; Status(int value) { this.value = value; diff --git a/src/main/java/view/SignUpView.java b/src/main/java/view/SignUpView.java index 74fba2f..c4110d1 100644 --- a/src/main/java/view/SignUpView.java +++ b/src/main/java/view/SignUpView.java @@ -3,17 +3,20 @@ import controller.Controller; import javax.swing.*; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; +import java.awt.*; import java.sql.SQLException; import java.util.Arrays; -import java.util.Objects; public class SignUpView { + public static void create() { JFrame frame = new JFrame("SignUpFrame"); - frame.setSize(900, 600); + frame.setExtendedState(JFrame.MAXIMIZED_BOTH); // Mettre en plein écran frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - //Create all the components. + // Créer tous les composants JPanel typePanel = new JPanel(); JPanel formPanel = new JPanel(); JPanel namePanel = new JPanel(); @@ -28,23 +31,27 @@ public static void create() { JPasswordField passwordField = new JPasswordField(); JLabel labelConfirmPassword = new JLabel("Confirm Password"); JPasswordField confirmPasswordField = new JPasswordField(); - JButton validateButton = new JButton("Validate"); + JButton validateButton = new JButton("Sign Up"); + JLabel passwordMismatchLabel = new JLabel("Passwords do not match"); + passwordMismatchLabel.setForeground(Color.RED); // Couleur du texte en rouge + passwordMismatchLabel.setVisible(false); // Cacher le message au départ JCheckBox checkBoxIsNeeder = new JCheckBox("Needer"); JCheckBox checkBoxIsVolunteer = new JCheckBox("Volunteer"); JCheckBox checkBoxIsValidator = new JCheckBox("Validator"); - //Set the components properties. - labelTitle.setFont(labelTitle.getFont().deriveFont(20.0f)); + // Propriétés des composants + labelTitle.setFont(labelTitle.getFont().deriveFont(24.0f)); typePanel.setLayout(new BoxLayout(typePanel, BoxLayout.X_AXIS)); formPanel.setLayout(new BoxLayout(formPanel, BoxLayout.Y_AXIS)); - frame.getContentPane().add(formPanel, "North"); - frame.getContentPane().add(validateButton, "South"); + frame.getContentPane().add(formPanel, BorderLayout.CENTER); + frame.getContentPane().add(validateButton, BorderLayout.SOUTH); namePanel.setLayout(new BoxLayout(namePanel, BoxLayout.X_AXIS)); labelFirstName.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10)); labelLastName.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10)); + checkBoxIsNeeder.setSelected(true); // Cocher par défaut + validateButton.setEnabled(false); // Désactiver le bouton de validation - - //Add the components to the panel. + // Ajouter les composants au panneau typePanel.add(checkBoxIsNeeder); typePanel.add(checkBoxIsVolunteer); typePanel.add(checkBoxIsValidator); @@ -54,7 +61,6 @@ public static void create() { namePanel.add(labelLastName); namePanel.add(textFieldLastName); - formPanel.add(labelTitle); formPanel.add(namePanel); formPanel.add(typePanel); @@ -64,8 +70,19 @@ public static void create() { formPanel.add(passwordField); formPanel.add(labelConfirmPassword); formPanel.add(confirmPasswordField); + formPanel.add(passwordMismatchLabel); // Ajouter le label d'incohérence + + // Ajouter des espacements + formPanel.add(Box.createVerticalStrut(10)); + + // Ajouter un panneau pour aligner le bouton au centre + JPanel buttonPanel = new JPanel(); + buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER)); + buttonPanel.add(validateButton); + + // Ajouter le panneau de boutons à la fin du formulaire + formPanel.add(buttonPanel); - //Add event listeners. checkBoxIsNeeder.addActionListener(actionEvent -> { if (checkBoxIsNeeder.isSelected()) { checkBoxIsVolunteer.setSelected(false); @@ -87,13 +104,44 @@ public static void create() { } }); - confirmPasswordField.addActionListener(actionEvent -> { - if (!Objects.equals(Arrays.toString(passwordField.getPassword()), Arrays.toString(confirmPasswordField.getPassword()))) { - JOptionPane.showMessageDialog(frame, "Passwords don't match"); + // Ajouter des écouteurs d'événements + DocumentListener documentListener = new DocumentListener() { + @Override + public void insertUpdate(DocumentEvent e) { + checkIfFieldsAreFilled(); + } + + @Override + public void removeUpdate(DocumentEvent e) { + checkIfFieldsAreFilled(); } - }); - validateButton.addActionListener( actionEvent -> { + @Override + public void changedUpdate(DocumentEvent e) { + checkIfFieldsAreFilled(); + } + + private void checkIfFieldsAreFilled() { + String firstName = textFieldFirstName.getText(); + String lastName = textFieldLastName.getText(); + String email = textFieldEmail.getText(); + char[] password = passwordField.getPassword(); + char[] confirmPassword = confirmPasswordField.getPassword(); + + boolean fieldsFilled = !firstName.isEmpty() && !lastName.isEmpty() && !email.isEmpty() && + password.length > 0 && confirmPassword.length > 0; + + validateButton.setEnabled(fieldsFilled && Arrays.equals(password, confirmPassword)); + } + }; + + textFieldFirstName.getDocument().addDocumentListener(documentListener); + textFieldLastName.getDocument().addDocumentListener(documentListener); + textFieldEmail.getDocument().addDocumentListener(documentListener); + passwordField.getDocument().addDocumentListener(documentListener); + confirmPasswordField.getDocument().addDocumentListener(documentListener); + + validateButton.addActionListener(actionEvent -> { try { String ret = Controller.createNewUser(textFieldFirstName.getText(), textFieldLastName.getText(), @@ -104,12 +152,12 @@ public static void create() { checkBoxIsVolunteer.isSelected(), checkBoxIsValidator.isSelected() ); - if (ret.equals("User created")) { - JOptionPane.showMessageDialog(frame, ret); + if (ret.equals("User successfully created")) { + JOptionPane.showMessageDialog(frame, "User created successfully"); frame.dispose(); LogInView.create(); } else if (ret.equals("User already exists")) { - JOptionPane.showMessageDialog(frame, "Travel to Login Page", ret,1); + JOptionPane.showMessageDialog(frame, "User already exists. Redirecting to Login Page"); frame.dispose(); LogInView.create(); } @@ -118,9 +166,7 @@ public static void create() { } }); - - - //Display the window. + // Afficher la fenêtre. frame.setVisible(true); } } diff --git a/src/main/java/view/ViewValidator.java b/src/main/java/view/ViewValidator.java index 093cdc4..ac66cd0 100644 --- a/src/main/java/view/ViewValidator.java +++ b/src/main/java/view/ViewValidator.java @@ -1,6 +1,100 @@ package view; +import controller.Controller; +import model.Mission; + +import javax.swing.*; +import java.awt.*; +import java.util.ArrayList; + public class ViewValidator { public static void create() { + JFrame frame = new JFrame("ValidatorFrame"); + frame.setExtendedState(JFrame.MAXIMIZED_BOTH); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + JPanel mainPanel = new JPanel(); + mainPanel.setLayout(new BorderLayout()); + + JPanel topPanel = new JPanel(); + topPanel.setLayout(new FlowLayout(FlowLayout.CENTER)); + JLabel labelTitle = new JLabel("Missions to Validate", JLabel.CENTER); + topPanel.add(labelTitle); + + JPanel missionPanel = new JPanel(); + missionPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); + missionPanel.setLayout(new GridLayout(0, 2, 10, 10)); // Utilisation de GridLayout avec espacement + + ArrayList missions = Controller.getMissionsToValidate(); + + for (Mission mission : missions) { + JPanel missionCard = new JPanel(); + missionCard.setLayout(new BorderLayout()); + missionCard.setBorder(BorderFactory.createLineBorder(Color.GRAY, 1)); + + JPanel infoMissionPanel = new JPanel(); + infoMissionPanel.setLayout(new BoxLayout(infoMissionPanel, BoxLayout.Y_AXIS)); + + JLabel labelID = new JLabel("ID: " + mission.getIdMission()); + JLabel labelTitleM = new JLabel("Title: " + mission.getTitle()); + JLabel descriptionLabel = new JLabel("Desc: " + mission.getDescription()); + if (descriptionLabel.getText().length() > 100) { + descriptionLabel.setText(descriptionLabel.getText().substring(0, 100) + "..."); + } + JLabel labelDateTime = new JLabel("Date: " + mission.getDateTime()); + JLabel labelStatus = new JLabel("Status: " + mission.getStatus()); + + infoMissionPanel.add(labelID); + infoMissionPanel.add(labelTitleM); + infoMissionPanel.add(descriptionLabel); + infoMissionPanel.add(labelDateTime); + infoMissionPanel.add(labelStatus); + + missionCard.add(infoMissionPanel, BorderLayout.CENTER); + + JPanel buttonPanel = new JPanel(); + JButton buttonAccept = new JButton("Accept"); + JButton buttonRefuse = new JButton("Refuse"); + buttonAccept.setBackground(Color.GREEN); + buttonRefuse.setBackground(Color.RED); + buttonPanel.add(buttonAccept); + buttonPanel.add(buttonRefuse); + + missionCard.add(buttonPanel, BorderLayout.SOUTH); + + buttonAccept.addActionListener(e -> { + Controller.acceptMission(mission.getIdMission()); + frame.dispose(); + ViewValidator.create(); + }); + + buttonRefuse.addActionListener(e -> { + Controller.refuseMission(mission.getIdMission()); + frame.dispose(); + ViewValidator.create(); + }); + + missionPanel.add(missionCard); + } + + JScrollPane scrollPane = new JScrollPane(missionPanel); + scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); + + JPanel bottomPanel = new JPanel(); + bottomPanel.setLayout(new FlowLayout(FlowLayout.CENTER)); + JButton buttonLogout = new JButton("Logout"); + buttonLogout.addActionListener(e -> { + LogInView.create(); + frame.dispose(); + }); + bottomPanel.add(buttonLogout); + + mainPanel.add(topPanel, BorderLayout.NORTH); + mainPanel.add(scrollPane, BorderLayout.CENTER); + mainPanel.add(bottomPanel, BorderLayout.SOUTH); + + frame.getContentPane().add(mainPanel); + + frame.setVisible(true); } }