Skip to content
Commits on Source (16)
...@@ -48,8 +48,8 @@ public class BootstrapData implements CommandLineRunner { ...@@ -48,8 +48,8 @@ public class BootstrapData implements CommandLineRunner {
@Override @Override
public void run(String... args) throws Exception { public void run(String... args) throws Exception {
Pilote pilote1 = new Pilote(); Pilote pilote1 = new Pilote();
pilote1.setNom("MAMA"); pilote1.setNom("GONÇALVES");
pilote1.setPrenom("Apprenti1"); pilote1.setPrenom("Yoda");
pilote1.setAge(100); pilote1.setAge(100);
pilote1.setRace(RacePilote.CHALACTEENS); pilote1.setRace(RacePilote.CHALACTEENS);
pilote1.setEtat(EtatPilote.DISPONIBLE); pilote1.setEtat(EtatPilote.DISPONIBLE);
...@@ -58,8 +58,8 @@ public class BootstrapData implements CommandLineRunner { ...@@ -58,8 +58,8 @@ public class BootstrapData implements CommandLineRunner {
pilote1.setEtat(EtatPilote.DISPONIBLE); pilote1.setEtat(EtatPilote.DISPONIBLE);
Pilote pilote2 = new Pilote(); Pilote pilote2 = new Pilote();
pilote2.setNom("WOW"); pilote2.setNom("SKYWALKER");
pilote2.setPrenom("Combattant1"); pilote2.setPrenom("Luke");
pilote2.setAge(17); pilote2.setAge(17);
pilote2.setRace(RacePilote.CHISS); pilote2.setRace(RacePilote.CHISS);
pilote2.setType(TypePilote.APPRENTI); pilote2.setType(TypePilote.APPRENTI);
...@@ -67,17 +67,17 @@ public class BootstrapData implements CommandLineRunner { ...@@ -67,17 +67,17 @@ public class BootstrapData implements CommandLineRunner {
pilote2.setEtat(EtatPilote.DISPONIBLE); pilote2.setEtat(EtatPilote.DISPONIBLE);
Pilote pilote3 = new Pilote(); Pilote pilote3 = new Pilote();
pilote3.setNom("WIW"); pilote3.setNom("DUREL");
pilote3.setPrenom("Combattant2"); pilote3.setPrenom("Obi-Wan");
pilote3.setAge(29); pilote3.setAge(777);
pilote3.setRace(RacePilote.ITHORIENS); pilote3.setRace(RacePilote.ITHORIENS);
pilote3.setType(TypePilote.COMBATTANT); pilote3.setType(TypePilote.COMBATTANT);
pilote3.setGrade(GradePilote.CAPITAINE); pilote3.setGrade(GradePilote.CAPITAINE);
pilote3.setEtat(EtatPilote.BLESSE); pilote3.setEtat(EtatPilote.BLESSE);
Pilote pilote4 = new Pilote(); Pilote pilote4 = new Pilote();
pilote4.setNom("WEW"); pilote4.setNom("FIAH");
pilote4.setPrenom("Combattant3"); pilote4.setPrenom("Princesse");
pilote4.setAge(29); pilote4.setAge(29);
pilote4.setRace(RacePilote.MIRALUKAS); pilote4.setRace(RacePilote.MIRALUKAS);
pilote4.setType(TypePilote.APPRENTI); pilote4.setType(TypePilote.APPRENTI);
...@@ -85,8 +85,8 @@ public class BootstrapData implements CommandLineRunner { ...@@ -85,8 +85,8 @@ public class BootstrapData implements CommandLineRunner {
pilote4.setEtat(EtatPilote.MORT_AU_COMBAT); pilote4.setEtat(EtatPilote.MORT_AU_COMBAT);
Pilote pilote5 = new Pilote(); Pilote pilote5 = new Pilote();
pilote5.setNom("WUW"); pilote5.setNom("BOUILLON-RENAUD");
pilote5.setPrenom("Combattant4"); pilote5.setPrenom("Han");
pilote5.setAge(77); pilote5.setAge(77);
pilote5.setRace(RacePilote.NAGAIS); pilote5.setRace(RacePilote.NAGAIS);
pilote5.setType(TypePilote.COMBATTANT); pilote5.setType(TypePilote.COMBATTANT);
...@@ -94,8 +94,8 @@ public class BootstrapData implements CommandLineRunner { ...@@ -94,8 +94,8 @@ public class BootstrapData implements CommandLineRunner {
pilote5.setEtat(EtatPilote.DISPONIBLE); pilote5.setEtat(EtatPilote.DISPONIBLE);
Pilote pilote6 = new Pilote(); Pilote pilote6 = new Pilote();
pilote6.setNom("DUREL"); pilote6.setNom("ROOROO");
pilote6.setPrenom("Johad"); pilote6.setPrenom("C-3PO");
pilote6.setAge(22); pilote6.setAge(22);
pilote6.setRace(RacePilote.HUMAINS); pilote6.setRace(RacePilote.HUMAINS);
pilote6.setType(TypePilote.COMBATTANT); pilote6.setType(TypePilote.COMBATTANT);
...@@ -103,10 +103,10 @@ public class BootstrapData implements CommandLineRunner { ...@@ -103,10 +103,10 @@ public class BootstrapData implements CommandLineRunner {
pilote6.setEtat(EtatPilote.BLESSE); pilote6.setEtat(EtatPilote.BLESSE);
Pilote pilote7 = new Pilote(); Pilote pilote7 = new Pilote();
pilote7.setNom("DUREL"); pilote7.setNom("NGUKNGUK");
pilote7.setPrenom("Johad2"); pilote7.setPrenom("Chewbacca");
pilote7.setAge(22); pilote7.setAge(17);
pilote7.setRace(RacePilote.HUMAINS); pilote7.setRace(RacePilote.QUERMIENS);
pilote7.setType(TypePilote.APPRENTI); pilote7.setType(TypePilote.APPRENTI);
pilote7.setGrade(GradePilote.OFFICIER); pilote7.setGrade(GradePilote.OFFICIER);
pilote7.setEtat(EtatPilote.DISPONIBLE); pilote7.setEtat(EtatPilote.DISPONIBLE);
......
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package fr.ldnr.starWars.controllers;
import fr.ldnr.starWars.services.PiloteService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
/**
*
* @author stag
*/
@Controller
public class CherchePiloteController {
PiloteService piloteService;
public CherchePiloteController(PiloteService piloteService) {
this.piloteService = piloteService;
}
@GetMapping("/cherchePilote")
public String cherchePilote(Model model) {
return "cherchePilote";
}
@PostMapping("/cherchePilote")
public String cherchePilote(Model model,
@RequestParam(value = "nom") String nom) {
model.addAttribute("pilotes", piloteService.findByNom(nom));
return "cherchePilote";
}
}
...@@ -6,6 +6,7 @@ package fr.ldnr.starWars.controllers; ...@@ -6,6 +6,7 @@ package fr.ldnr.starWars.controllers;
import fr.ldnr.starWars.calculs.Calculs; import fr.ldnr.starWars.calculs.Calculs;
import fr.ldnr.starWars.domains.Affectation; import fr.ldnr.starWars.domains.Affectation;
import fr.ldnr.starWars.domains.Chasseur;
import fr.ldnr.starWars.domains.Mission; import fr.ldnr.starWars.domains.Mission;
import fr.ldnr.starWars.domains.Pilote; import fr.ldnr.starWars.domains.Pilote;
import fr.ldnr.starWars.enumerations.GradePilote; import fr.ldnr.starWars.enumerations.GradePilote;
...@@ -41,6 +42,9 @@ public class ClotureMission { ...@@ -41,6 +42,9 @@ public class ClotureMission {
public String clotureMission(Model model) { public String clotureMission(Model model) {
model.addAttribute("resultatMission", missionService.resultatMission()); model.addAttribute("resultatMission", missionService.resultatMission());
model.addAttribute("missions", missionService.findByStatut(StatutMission.ENCOUR)); model.addAttribute("missions", missionService.findByStatut(StatutMission.ENCOUR));
if (missionService.findByStatut(StatutMission.ENCOUR).isEmpty()) {
model.addAttribute("errorMissionNull", "Il n'y pas mission en cours");
}
return "clotureMission"; return "clotureMission";
} }
...@@ -49,7 +53,6 @@ public class ClotureMission { ...@@ -49,7 +53,6 @@ public class ClotureMission {
@RequestParam(value = "heures") String heures, @RequestParam(value = "heures") String heures,
@RequestParam(value = "resultats") String resultats, @RequestParam(value = "resultats") String resultats,
@RequestParam(value = "missions") String missions) { @RequestParam(value = "missions") String missions) {
model.addAttribute("missions", missionService.findByStatut(StatutMission.ENCOUR));
// recuperate Mission from db by Id // recuperate Mission from db by Id
Integer idMission = (Integer.valueOf(missions)); Integer idMission = (Integer.valueOf(missions));
...@@ -63,6 +66,8 @@ public class ClotureMission { ...@@ -63,6 +66,8 @@ public class ClotureMission {
// persister missionRecupere dans la db // persister missionRecupere dans la db
missionService.save(missionRecupere); missionService.save(missionRecupere);
model.addAttribute("missions", missionService.findByStatut(StatutMission.ENCOUR));
model.addAttribute("resultatMission", missionService.resultatMission());
// boucle tous les pilotes dans la Mission // boucle tous les pilotes dans la Mission
Set<Pilote> pilotes = new HashSet<>(); // Create a set to store pilotes in the Mission Set<Pilote> pilotes = new HashSet<>(); // Create a set to store pilotes in the Mission
...@@ -74,6 +79,20 @@ public class ClotureMission { ...@@ -74,6 +79,20 @@ public class ClotureMission {
} }
} }
model.addAttribute("pilotes", pilotes);
// boucle tous les chasseurs dans la Mission
Set<Chasseur> chasseurs = new HashSet<>(); // Create a set to store pilotes in the Mission
for (Affectation affectation : missionRecupere.getAffectation()) {
Chasseur chasseur = affectation.getChasseur();
if (chasseur != null) {
chasseurs.add(chasseur);
}
}
model.addAttribute("chasseurs", chasseurs);
for (Pilote pilote : pilotes) { for (Pilote pilote : pilotes) {
// ---------- DÉBUT CALCUL NB HEURE ET PUIS UPDATE GRADE OU TYPE // ---------- DÉBUT CALCUL NB HEURE ET PUIS UPDATE GRADE OU TYPE
//calculNbHeure //calculNbHeure
...@@ -99,6 +118,7 @@ public class ClotureMission { ...@@ -99,6 +118,7 @@ public class ClotureMission {
pilote.setType(newType); pilote.setType(newType);
System.out.println("newType : " + newType); System.out.println("newType : " + newType);
// update status to disponible?
// then update to db // then update to db
piloteService.save(pilote); piloteService.save(pilote);
// ---------- FIN CALCUL NB HEURE ET PUIS UPDATE GRADE OU TYPE // ---------- FIN CALCUL NB HEURE ET PUIS UPDATE GRADE OU TYPE
......
...@@ -5,11 +5,14 @@ ...@@ -5,11 +5,14 @@
package fr.ldnr.starWars.controllers; package fr.ldnr.starWars.controllers;
import fr.ldnr.starWars.domains.Chasseur; import fr.ldnr.starWars.domains.Chasseur;
import fr.ldnr.starWars.enumerations.EtatChasseur;
import fr.ldnr.starWars.services.ChasseurService; import fr.ldnr.starWars.services.ChasseurService;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
/** /**
* *
* @author stag * @author stag
...@@ -18,6 +21,7 @@ import org.springframework.web.bind.annotation.RequestParam; ...@@ -18,6 +21,7 @@ import org.springframework.web.bind.annotation.RequestParam;
public class FicheChasseurController { public class FicheChasseurController {
private final ChasseurService chasseurService; private final ChasseurService chasseurService;
Integer idChasseur;
public FicheChasseurController(ChasseurService chasseurService) { public FicheChasseurController(ChasseurService chasseurService) {
this.chasseurService = chasseurService; this.chasseurService = chasseurService;
...@@ -27,7 +31,26 @@ public class FicheChasseurController { ...@@ -27,7 +31,26 @@ public class FicheChasseurController {
public String afficherFicheChasseur(@RequestParam Long id_chasseur, Model model) { public String afficherFicheChasseur(@RequestParam Long id_chasseur, Model model) {
model.addAttribute("ficheChasseur", chasseurService.trouverParId(id_chasseur)); model.addAttribute("ficheChasseur", chasseurService.trouverParId(id_chasseur));
model.addAttribute("etat", chasseurService.listeEtatChasseur());
idChasseur = id_chasseur.intValue();
return "ficheChasseur"; return "ficheChasseur";
} }
@PostMapping("/ficheChasseur")
public String afficherFicheChasseur(Model model,
@RequestParam(value = "etat") String etat) {
// model.getAttribute("id_chasseur");
EtatChasseur etat2 = EtatChasseur.valueOf(etat);
Chasseur chasseur = chasseurService.findById(idChasseur);
chasseur.setEtat(etat2);
chasseurService.save(chasseur);
System.out.println("chasseur : " + chasseur);
model.addAttribute("ficheChasseur", chasseurService.trouverParId(idChasseur.longValue()));
model.addAttribute("etat", chasseurService.listeEtatChasseur());
return "ficheChasseur";
}
} }
...@@ -4,11 +4,21 @@ ...@@ -4,11 +4,21 @@
*/ */
package fr.ldnr.starWars.controllers; package fr.ldnr.starWars.controllers;
import fr.ldnr.starWars.calculs.Calculs;
import fr.ldnr.starWars.domains.Affectation;
import fr.ldnr.starWars.domains.Chasseur;
import fr.ldnr.starWars.domains.Mission;
import fr.ldnr.starWars.domains.Pilote; import fr.ldnr.starWars.domains.Pilote;
import fr.ldnr.starWars.enumerations.EtatChasseur;
import fr.ldnr.starWars.enumerations.EtatPilote;
import fr.ldnr.starWars.services.MissionService;
import fr.ldnr.starWars.services.PiloteService; import fr.ldnr.starWars.services.PiloteService;
import java.util.HashSet;
import java.util.Set;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
...@@ -18,10 +28,14 @@ import org.springframework.web.bind.annotation.RequestParam; ...@@ -18,10 +28,14 @@ import org.springframework.web.bind.annotation.RequestParam;
*/ */
@Controller @Controller
public class FichePiloteController { public class FichePiloteController {
private final PiloteService piloteService; private final PiloteService piloteService;
private final MissionService missionService;
Integer idPilote;
public FichePiloteController(PiloteService piloteService) { public FichePiloteController(PiloteService piloteService, MissionService missionService) {
this.piloteService = piloteService; this.piloteService = piloteService;
this.missionService = missionService;
} }
@GetMapping("/fichePilote") @GetMapping("/fichePilote")
...@@ -29,9 +43,42 @@ public class FichePiloteController { ...@@ -29,9 +43,42 @@ public class FichePiloteController {
Pilote pilote = new Pilote(); Pilote pilote = new Pilote();
pilote = piloteService.findById(Integer.valueOf(id_pilote)); pilote = piloteService.findById(Integer.valueOf(id_pilote));
model.addAttribute("pilote", pilote); model.addAttribute("pilote", pilote);
Set<Mission> missions = new HashSet<>(); // Create a set to store pilotes in the Mission
for (Affectation affectation : pilote.getAffectation()) {
Mission mission = affectation.getMission();
if (mission != null) {
missions.add(mission);
}
}
//System.out.println("list de missions : + " + missions);
model.addAttribute("missions", missions);
Calculs calculs = new Calculs(missionService);
int nbHeure = calculs.calculNbHeure(pilote);
model.addAttribute("nbHeure", nbHeure);
System.out.println("");
idPilote = Integer.valueOf(id_pilote);
model.addAttribute("ficheChasseur", piloteService.findById(idPilote));
model.addAttribute("etat", piloteService.listEtat());
return "fichePilote"; return "fichePilote";
} }
@PostMapping("/fichePilote")
public String afficherFichepilote(Model model,
@RequestParam(value = "etat") String etat) {
// model.getAttribute("id_chasseur");
EtatPilote etat2 = EtatPilote.valueOf(etat);
Pilote pilote = piloteService.findById(idPilote);
pilote.setEtat(etat2);
piloteService.save(pilote);
System.out.println("chasseur : " + pilote);
model.addAttribute("pilote", piloteService.findById(idPilote));
model.addAttribute("etat", piloteService.listEtat());
return "fichePilote";
}
} }
...@@ -46,6 +46,11 @@ public class InscriptionPiloteController { ...@@ -46,6 +46,11 @@ public class InscriptionPiloteController {
RacePilote race2 = RacePilote.valueOf(race); RacePilote race2 = RacePilote.valueOf(race);
Integer age2 = Integer.valueOf(age); Integer age2 = Integer.valueOf(age);
if (age2 < 10 || age2 > 800) {
model.addAttribute("messageError", "Vous êtes trop jeune ou vieux. Nous n'acceptions que les rebelles entre 10 et 800 ans.");
return "inscriptionPilote";
}
if (!nom.isEmpty()) { if (!nom.isEmpty()) {
Pilote pilote = new Pilote(); Pilote pilote = new Pilote();
pilote.setNom(nom); pilote.setNom(nom);
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
*/ */
package fr.ldnr.starWars.controllers; package fr.ldnr.starWars.controllers;
import fr.ldnr.starWars.enumerations.StatutMission;
import fr.ldnr.starWars.services.MissionService; import fr.ldnr.starWars.services.MissionService;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
...@@ -23,6 +24,7 @@ public class ListeMissionController { ...@@ -23,6 +24,7 @@ public class ListeMissionController {
@GetMapping("/listeMission") @GetMapping("/listeMission")
public String listeMission(Model model) { public String listeMission(Model model) {
// model.addAttribute("missions", missionService.findByStatut(StatutMission.TERMINE));
model.addAttribute("missions", missionService.findAll()); model.addAttribute("missions", missionService.findAll());
return "listeMission"; return "listeMission";
......
/* ///*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license // * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template // * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/ // */
package fr.ldnr.starWars.controllers; //package fr.ldnr.starWars.controllers;
//
import fr.ldnr.starWars.enumerations.EtatChasseur; //import fr.ldnr.starWars.enumerations.EtatChasseur;
import fr.ldnr.starWars.services.ChasseurService; //import fr.ldnr.starWars.services.ChasseurService;
import org.springframework.stereotype.Controller; //import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; //import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping; //import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; //import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam; //import org.springframework.web.bind.annotation.RequestParam;
//
/** ///**
* // *
* @author Johad // * @author Johad
*/ // */
@Controller //@Controller
public class ModifierEtatChasseurController { //public class ModifierEtatChasseurController {
//
private final ChasseurService chasseurService; // private final ChasseurService chasseurService;
//
public ModifierEtatChasseurController(ChasseurService chasseurService) { // public ModifierEtatChasseurController(ChasseurService chasseurService) {
this.chasseurService = chasseurService; // this.chasseurService = chasseurService;
} // }
//
@GetMapping("/modifierEtatChasseur") // @GetMapping("/modifierEtatChasseur")
public String modifierEtatPilote(Model model) { // public String modifierEtatPilote(Model model) {
model.addAttribute("etatChasseur", chasseurService.listeTypeChasseur()); // model.addAttribute("etatChasseur", chasseurService.listeTypeChasseur());
return "modifierEtatChasseur"; // return "modifierEtatChasseur";
} // }
//
@PostMapping("/modifierEtatChasseur") // @PostMapping("/modifierEtatChasseur")
public String modifierEtatChasseur(@RequestParam Long id_chasseur, Model model, // public String modifierEtatChasseur(@RequestParam Long id_chasseur, Model model,
@RequestParam(value="etat") String etat) { // @RequestParam(value="etat") String etat) {
//
model.addAttribute("etatChasseur", chasseurService.modifierEtat(id_chasseur, EtatChasseur.valueOf(etat))); // model.addAttribute("etatChasseur", chasseurService.modifierEtat(id_chasseur, EtatChasseur.valueOf(etat)));
return "modifierEtatChasseur"; // return "modifierEtatChasseur";
} // }
} //}
...@@ -52,19 +52,16 @@ public class NouvelleMissionController { ...@@ -52,19 +52,16 @@ public class NouvelleMissionController {
this.affectationService = affectationService; this.affectationService = affectationService;
} }
@RequestMapping("/nouvelleMission") @RequestMapping("/nouvelleMission")
public String getMission(Model model) { public String getMission(Model model) {
model.addAttribute("typeMissions", missionService.listMission()); model.addAttribute("typeMissions", missionService.listMission());
model.addAttribute("mission", new Mission()); model.addAttribute("mission", new Mission());
model.addAttribute("affectationFormVisible", false); // Initially hidden
// Update the table with Pilot and Plane info // Update the table with Pilot and Plane info
List<Pilote> listPilotes = piloteService.findByEtat(EtatPilote.DISPONIBLE); // List<Pilote> listPilotes = piloteService.findByEtat(EtatPilote.DISPONIBLE);
List<Chasseur> listChasseurs = chasseurService.findByEtat(EtatChasseur.OPERATIONNEL); // List<Chasseur> listChasseurs = chasseurService.findByEtat(EtatChasseur.OPERATIONNEL);
model.addAttribute("pilotesDispo", listPilotes);
model.addAttribute("chasseursDispo", listChasseurs); // model.addAttribute("pilotesDispo", listPilotes);
model.addAttribute("pilotesDispo", listPilotes); // model.addAttribute("chasseursDispo", listChasseurs);
model.addAttribute("chasseursDispo", listChasseurs);
return "nouvelleMission"; return "nouvelleMission";
} }
...@@ -73,25 +70,33 @@ public class NouvelleMissionController { ...@@ -73,25 +70,33 @@ public class NouvelleMissionController {
public String nouvelleMissionSubmit(Model model, public String nouvelleMissionSubmit(Model model,
@RequestParam(value = "titre") String titre, @RequestParam(value = "titre") String titre,
@RequestParam(value = "typeMissions") String typeMissions) { @RequestParam(value = "typeMissions") String typeMissions) {
// for display
// model.addAttribute("typeMissions", missionService.listMission());
List<Pilote> listPilotes = piloteService.findByEtat(EtatPilote.DISPONIBLE);
List<Chasseur> listChasseurs = chasseurService.findByEtat(EtatChasseur.OPERATIONNEL);
if (listPilotes.isEmpty() || listChasseurs.isEmpty()) {
model.addAttribute("errorMissionPasDeRessources", "Impossible de créer une mission, pilote ou chasseur non disponible");
return "nouvelleMission";
}
model.addAttribute("pilotesDispo", listPilotes);
model.addAttribute("chasseursDispo", listChasseurs);
// Save the mission to the database // Save the mission to the database
Mission mission = new Mission(); Mission mission = new Mission();
mission.setTitre(titre); mission.setTitre(titre);
mission.setType(TypeMission.valueOf(typeMissions)); mission.setType(TypeMission.valueOf(typeMissions));
mission.setStatut(StatutMission.ENCOUR); mission.setStatut(StatutMission.ENCOUR);
System.out.println("CHECK : " + mission);
model.addAttribute("typeMissions", missionService.listMission());
List<Pilote> listPilotes = piloteService.findByEtat(EtatPilote.DISPONIBLE);
List<Chasseur> listChasseurs = chasseurService.findByEtat(EtatChasseur.OPERATIONNEL);
model.addAttribute("pilotesDispo", listPilotes);
model.addAttribute("chasseursDispo", listChasseurs);
missionService.save(mission); missionService.save(mission);
idMission = mission.getIdMission(); idMission = mission.getIdMission();
//System.out.println("CHECK2 : " + idMission); listPiloteTemp.clear();
listChasseurTemp.clear();
// ATTENTION, BUG WHEN WE REFRESH THE PAGE, IT'LL KEEP ADDING THE AFFECTATION (LIKE PUSHING BUTTON AFFECTATION) // ATTENTION, BUG WHEN WE REFRESH THE PAGE, IT'LL KEEP ADDING THE AFFECTATION (LIKE PUSHING BUTTON AFFECTATION)
return "nouvelleMission"; return "nouvelleMission";
} }
@PostMapping("/affectation") @PostMapping("/affectation/{idMission}")
// Handle Affectation form submission // Handle Affectation form submission
//@PostMapping("/affectation/{idMission}") //@PostMapping("/affectation/{idMission}")
// public String affectationSubmit(@PathVariable Long missionId, @ModelAttribute Affectation affectation, Model model) { // public String affectationSubmit(@PathVariable Long missionId, @ModelAttribute Affectation affectation, Model model) {
...@@ -99,29 +104,16 @@ public class NouvelleMissionController { ...@@ -99,29 +104,16 @@ public class NouvelleMissionController {
@RequestParam(value = "piloteSelect") String piloteSelect, @RequestParam(value = "piloteSelect") String piloteSelect,
@RequestParam(value = "chasseurSelect") String chasseurSelect) { @RequestParam(value = "chasseurSelect") String chasseurSelect) {
// Update the table with Pilot and Plane info
model.addAttribute("typeMissions", missionService.listMission());
List<Pilote> listPilotes = piloteService.findByEtat(EtatPilote.DISPONIBLE);
List<Chasseur> listChasseurs = chasseurService.findByEtat(EtatChasseur.OPERATIONNEL);
model.addAttribute("pilotesDispo", listPilotes);
model.addAttribute("chasseursDispo", listChasseurs);
System.out.println("CHECK " + piloteSelect);
// recuperate Pilote from db // recuperate Pilote from db
Integer idPilote = (Integer.valueOf(piloteSelect)); Integer idPilote = (Integer.valueOf(piloteSelect));
Pilote piloteRecupere = piloteService.findById(idPilote); Pilote piloteRecupere = piloteService.findById(idPilote);
System.out.println("CHECK PILOTE RECUPEREE : " + piloteRecupere);
// recuperate Chasseur from db // recuperate Chasseur from db
Integer idChasseur = (Integer.valueOf(chasseurSelect)); Integer idChasseur = (Integer.valueOf(chasseurSelect));
//System.out.println("CHECK chasseurSelect : " + chasseurSelect);
Chasseur chasseurRecupere = chasseurService.findById(idChasseur); Chasseur chasseurRecupere = chasseurService.findById(idChasseur);
System.out.println("CHECK Chasseur RECUPEREE : " + chasseurRecupere);
// recuperate Chasseur from db // recuperate Mission from db
Mission missionRecupere = missionService.findById(idMission); Mission missionRecupere = missionService.findById(idMission);
System.out.println("CHECK Mission RECUPEREE : " + missionRecupere);
//System.out.println("id Mission : " + idMission);
// create et remplir affectation // create et remplir affectation
Affectation affectation = new Affectation(); Affectation affectation = new Affectation();
...@@ -129,31 +121,30 @@ public class NouvelleMissionController { ...@@ -129,31 +121,30 @@ public class NouvelleMissionController {
affectation.setPilote(piloteRecupere); affectation.setPilote(piloteRecupere);
affectation.setMission(missionRecupere); affectation.setMission(missionRecupere);
affectationService.save(affectation); affectationService.save(affectation);
System.out.println("affectation : " + affectation);
piloteRecupere.getAffectation().add(affectation); piloteRecupere.getAffectation().add(affectation);
chasseurRecupere.getAffectation().add(affectation); chasseurRecupere.getAffectation().add(affectation);
missionRecupere.getAffectation().add(affectation); missionRecupere.getAffectation().add(affectation);
piloteRecupere.setEtat(EtatPilote.EN_MISSION);
chasseurRecupere.setEtat(EtatChasseur.EN_MISSION);
piloteService.save(piloteRecupere); piloteService.save(piloteRecupere);
chasseurService.save(chasseurRecupere); chasseurService.save(chasseurRecupere);
missionService.save(missionRecupere); missionService.save(missionRecupere);
listPiloteTemp.add(piloteRecupere); listPiloteTemp.add(piloteRecupere);
listChasseurTemp.add(chasseurRecupere); listChasseurTemp.add(chasseurRecupere);
System.out.println("check listPiloteTemp : " + listPiloteTemp); // System.out.println("check listPiloteTemp : " + listPiloteTemp);
System.out.println("check listChasseurTemp : " + listChasseurTemp); // System.out.println("check listChasseurTemp : " + listChasseurTemp);
model.addAttribute("listPiloteTemps", listPiloteTemp); model.addAttribute("listPiloteTemps", listPiloteTemp);
model.addAttribute("listChasseurTemps", listChasseurTemp); model.addAttribute("listChasseurTemps", listChasseurTemp);
model.addAttribute("idMission", idMission); model.addAttribute("idMission", idMission);
model.addAttribute("missionToDisplay", missionService.findById(idMission)); // Update the table with Pilot and Plane info
// model.addAttribute("typeMissions", missionService.listMission());
// Affectation a = new Affectation(); List<Pilote> listPilotes = piloteService.findByEtat(EtatPilote.DISPONIBLE);
// a.setChasseur(chasseurRecupere); List<Chasseur> listChasseurs = chasseurService.findByEtat(EtatChasseur.OPERATIONNEL);
// a.setPilote(piloteRecupere); model.addAttribute("pilotesDispo", listPilotes);
// a.setMission(missionRecupere); model.addAttribute("chasseursDispo", listChasseurs);
// piloteRecupere.getAffectation().add(a);
// System.out.println("apres ajouter affectation : " + piloteRecupere.getAffectation().toString());
//
return "nouvelleMission"; return "nouvelleMission";
} }
......
...@@ -20,7 +20,9 @@ import org.springframework.stereotype.Repository; ...@@ -20,7 +20,9 @@ import org.springframework.stereotype.Repository;
@Repository @Repository
public interface PiloteRepository extends CrudRepository<Pilote, Long> { public interface PiloteRepository extends CrudRepository<Pilote, Long> {
Pilote findByNom(String nom); List<Pilote> findByNom(String nom);
List<Pilote> findByNomAndPrenom(String nom, String prenom);
List<Pilote> findByEtat(EtatPilote etat); List<Pilote> findByEtat(EtatPilote etat);
......
...@@ -33,4 +33,6 @@ public interface ChasseurService { ...@@ -33,4 +33,6 @@ public interface ChasseurService {
public Chasseur findById(Integer idChasseur); public Chasseur findById(Integer idChasseur);
public Iterable<EtatChasseur> listeEtatChasseur();
} }
...@@ -56,6 +56,13 @@ public class ChasseurServiceImpl implements ChasseurService { ...@@ -56,6 +56,13 @@ public class ChasseurServiceImpl implements ChasseurService {
return list; return list;
} }
@Override
public Iterable<EtatChasseur> listeEtatChasseur() {
List<EtatChasseur> list = Arrays.asList(EtatChasseur.values());
return list;
}
@Override @Override
public Iterable<Chasseur> trouverParId(Long id_chasseur) { public Iterable<Chasseur> trouverParId(Long id_chasseur) {
List<Chasseur> list = new ArrayList(); List<Chasseur> list = new ArrayList();
......
...@@ -19,7 +19,9 @@ public interface PiloteService { ...@@ -19,7 +19,9 @@ public interface PiloteService {
public Iterable<Pilote> findAll(); public Iterable<Pilote> findAll();
public Pilote findByNom(String nom); public List<Pilote> findByNom(String nom);
public List<Pilote> findByNomAndPrenom(String nom, String prenom);
public List<Pilote> findByEtat(EtatPilote etat); public List<Pilote> findByEtat(EtatPilote etat);
......
...@@ -79,9 +79,13 @@ public class PiloteServiceImpl implements PiloteService { ...@@ -79,9 +79,13 @@ public class PiloteServiceImpl implements PiloteService {
} }
@Override @Override
public Pilote findByNom(String nom) { public List<Pilote> findByNom(String nom) {
return piloteRepository.findByNom(nom); return piloteRepository.findByNom(nom);
} }
@Override
public List<Pilote> findByNomAndPrenom(String nom, String prenom) {
return piloteRepository.findByNomAndPrenom(nom, prenom);
}
@Override @Override
public List<Pilote> findByGrade(GradePilote grade) { public List<Pilote> findByGrade(GradePilote grade) {
......
...@@ -98,7 +98,7 @@ button{ ...@@ -98,7 +98,7 @@ button{
margin-left : auto; margin-left : auto;
margin-right : auto; margin-right : auto;
} }
main::before { body::before {
content: ""; content: "";
position: absolute; position: absolute;
top: 0; top: 0;
...@@ -165,6 +165,11 @@ select{ ...@@ -165,6 +165,11 @@ select{
color: yellow; color: yellow;
} }
.affectation{
display: flex;
flex-direction: column;
}
.radio { .radio {
padding: 0.3rem 0.5rem; padding: 0.3rem 0.5rem;
......
<!DOCTYPE html>
<!--
Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
Click nbfs://nbhost/SystemFileSystem/Templates/Other/html.html to edit this template
-->
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<title>Cherche pilote</title>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link rel="stylesheet" href="/style.css"/>
</head>
<body>
<header>
<h1><span class='faulty-letter'>{</span> Cherche pilote par nom</h1>
</header>
<form th:action="@{/cherchePilote}" method="post">
<div>
<label for="nom">Saisir nom de pilote : </label>
<input type="text" id="nom" name="nom"/>
</div>
<div>
<input type="submit" value="Submit"/>
</div>
</form>
</br>
</br>
<table>
<tr>
<th>Id pilote</th>
<th>Nom</th>
<th>Prenom</th>
<th>Age</th>
<th>Race</th>
<th>Grade</th>
<th>Type</th>
<th>Etat</th>
</tr>
<tr th:each="pilote : ${pilotes}">
<td>
<a th:href="'/fichePilote?id_pilote=' + ${pilote.idPilote}" th:text="${pilote.idPilote}">
</a>
</td>
<td th:text="${pilote.nom}"></td>
<td th:text="${pilote.prenom}"></td>
<td th:text="${pilote.age}"></td>
<td th:text="${pilote.race}"></td>
<td th:text="${pilote.grade}"></td>
<td th:text="${pilote.type}"></td>
<td th:text="${pilote.etat}"></td>
</tr>
</table>
</br>
</br>
<footer>
<a href="/menu" class="menu">Retour au Menu</a>
</footer>
</body>
</html>
...@@ -14,8 +14,8 @@ Click nbfs://nbhost/SystemFileSystem/Templates/Other/html.html to edit this temp ...@@ -14,8 +14,8 @@ Click nbfs://nbhost/SystemFileSystem/Templates/Other/html.html to edit this temp
<header> <header>
<h1><span class='faulty-letter'>{</span> Cloture Mission</h1> <h1><span class='faulty-letter'>{</span> Cloture Mission</h1>
</header> </header>
<p th:text="${errorMissionNull}"></p>
<form class='mission' action="/clotureMission" method="post"> <form class='mission' th:action="@{/clotureMission}" method="post">
<div class='box'> <div class='box'>
<label for="missions">Choisir une mission :</label> <label for="missions">Choisir une mission :</label>
<select id="missions" name="missions"> <select id="missions" name="missions">
...@@ -32,9 +32,26 @@ Click nbfs://nbhost/SystemFileSystem/Templates/Other/html.html to edit this temp ...@@ -32,9 +32,26 @@ Click nbfs://nbhost/SystemFileSystem/Templates/Other/html.html to edit this temp
<option th:each="resultat : ${resultatMission}" th:value="${resultat}" th:text="${resultat}"></option> <option th:each="resultat : ${resultatMission}" th:value="${resultat}" th:text="${resultat}"></option>
</select> </select>
</div> </div>
<!--
<div>
<p> List pilote(s) dans la mission: </p>
<div th:each="pilote : ${pilotes}">
<p th:text="${pilote.nom}"></p>
</div>
<p> List chasseur(s) dans la mission: </p>
<div th:each="chasseur : ${chasseurs}">
<p th:text="${chasseur.type}"></p>
</div>
</div>
-->
</br>
<div>
<input type="submit" value="Submit"/> <input type="submit" value="Submit"/>
<input type="reset" value="Annuler"/> <input type="reset" value="Annuler"/>
</div>
</form> </form>
</br>
</br>
<footer> <footer>
<a href="/menu" class="menu">Retour au Menu</a> <a href="/menu" class="menu">Retour au Menu</a>
</footer> </footer>
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
<h1><span class='faulty-letter'>{</span> Fiche chasseur</h1> <h1><span class='faulty-letter'>{</span> Fiche chasseur</h1>
</header> </header>
<main> <main>
<form th:action="@{/ficheChasseur}" method="post">
<table> <table>
<tr> <tr>
<th>Id</th> <th>Id</th>
...@@ -22,11 +23,17 @@ ...@@ -22,11 +23,17 @@
<th>Etat chasseur</th> <th>Etat chasseur</th>
</tr> </tr>
<tr th:each="chasseur: ${ficheChasseur}"> <tr th:each="chasseur: ${ficheChasseur}">
<td th:text="${chasseur.id_chasseur}"></td> <td th:text="${chasseur.idChasseur}"></td>
<td th:text="${chasseur.type_chasseur}"></td> <td th:text="${chasseur.type}"></td>
<td th:text="${chasseur.etat_chasseur}"></td> <td>
<select id="etat" name="etat">
<option th:each="etat : ${etat}" th:value="${etat}" th:text="${etat}"></option>
</select>
</td>
</tr> </tr>
</table> </table>
<input type="submit" value="Submit"/>
</form>
<a th:href="@{/listeChasseur}">Retour a la liste des chasseurs</a> <a th:href="@{/listeChasseur}">Retour a la liste des chasseurs</a>
</main> </main>
<footer> <footer>
......
...@@ -8,8 +8,8 @@ Click nbfs://nbhost/SystemFileSystem/Templates/Other/html.html to edit this temp ...@@ -8,8 +8,8 @@ Click nbfs://nbhost/SystemFileSystem/Templates/Other/html.html to edit this temp
<title>fiche pilote</title> <title>fiche pilote</title>
<meta charset="UTF-8"/> <meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/> <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link rel="stylesheet" href="/style.css"> <link rel="stylesheet" href="/style.css"/>
<link href="https://fonts.cdnfonts.com/css/star-wars" rel="stylesheet"> <link href="https://fonts.cdnfonts.com/css/star-wars" rel="stylesheet"/>
<style> <style>
@import url('https://fonts.cdnfonts.com/css/star-wars'); @import url('https://fonts.cdnfonts.com/css/star-wars');
</style> </style>
...@@ -24,10 +24,28 @@ Click nbfs://nbhost/SystemFileSystem/Templates/Other/html.html to edit this temp ...@@ -24,10 +24,28 @@ Click nbfs://nbhost/SystemFileSystem/Templates/Other/html.html to edit this temp
<p>Race : <span th:text="${pilote.race}"></span></p> <p>Race : <span th:text="${pilote.race}"></span></p>
<p>Age à l'inscription : <span th:text="${pilote.age}"></span></p> <p>Age à l'inscription : <span th:text="${pilote.age}"></span></p>
<p>Etat : <span th:text="${pilote.etat}"></span></p> <p>Etat : <span th:text="${pilote.etat}"></span></p>
<p>Nombre d'heures de vol : </p> <p>Nombre d'heures de vol :
<span th:text="${nbHeure}"></span>
</p>
<p>Grade : <span th:text="${pilote.grade}"></span></p> <p>Grade : <span th:text="${pilote.grade}"></span></p>
<p>Liste des missions</p> <p>Liste des missions :
<tr th:each="mission : ${missions}">
<td th:text="${mission.titre}"></td>
<td th:text="${mission.type}"></td>
<td th:text="${mission.resultat}"></td>
<td th:text="${mission.statut}"></td>
</tr>
</p>
<p>Rang pilote : <span th:text="${pilote.type}"></span></p> <p>Rang pilote : <span th:text="${pilote.type}"></span></p>
<form th:action="@{/fichePilote}" method="post">
<p> Modifier état :
<select id="etat" name="etat">
<option th:each="etat : ${etat}" th:value="${etat}" th:text="${etat}"></option>
</select>
</p>
<input type="submit" value="Submit"/>
</form>
</main> </main>
<footer> <footer>
<a href="/menu" class="menu">Retour au Menu</a> <a href="/menu" class="menu">Retour au Menu</a>
......
...@@ -42,6 +42,7 @@ Click nbfs://nbhost/SystemFileSystem/Templates/Other/html.html to edit this temp ...@@ -42,6 +42,7 @@ Click nbfs://nbhost/SystemFileSystem/Templates/Other/html.html to edit this temp
<div class="box"> <div class="box">
<label class="label" for="age">Age</label> <label class="label" for="age">Age</label>
<input type="text" id="age" name="age"/> <input type="text" id="age" name="age"/>
<span th:text="${messageError}"></span>
</div> </div>
<div class="button"> <div class="button">
<input type="submit" value="Valider"/> <input type="submit" value="Valider"/>
......