Skip to content
Commits on Source (10)
/*
* 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";
}
}
......@@ -5,11 +5,14 @@
package fr.ldnr.starWars.controllers;
import fr.ldnr.starWars.domains.Chasseur;
import fr.ldnr.starWars.enumerations.EtatChasseur;
import fr.ldnr.starWars.services.ChasseurService;
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
......@@ -18,6 +21,7 @@ import org.springframework.web.bind.annotation.RequestParam;
public class FicheChasseurController {
private final ChasseurService chasseurService;
Integer idChasseur;
public FicheChasseurController(ChasseurService chasseurService) {
this.chasseurService = chasseurService;
......@@ -27,7 +31,26 @@ public class FicheChasseurController {
public String afficherFicheChasseur(@RequestParam Long id_chasseur, Model model) {
model.addAttribute("ficheChasseur", chasseurService.trouverParId(id_chasseur));
model.addAttribute("etat", chasseurService.listeEtatChasseur());
idChasseur = id_chasseur.intValue();
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 @@
*/
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.enumerations.EtatChasseur;
import fr.ldnr.starWars.enumerations.EtatPilote;
import fr.ldnr.starWars.services.MissionService;
import fr.ldnr.starWars.services.PiloteService;
import java.util.HashSet;
import java.util.Set;
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.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
......@@ -18,10 +28,14 @@ import org.springframework.web.bind.annotation.RequestParam;
*/
@Controller
public class FichePiloteController {
private final PiloteService piloteService;
private final MissionService missionService;
Integer idPilote;
public FichePiloteController(PiloteService piloteService) {
public FichePiloteController(PiloteService piloteService, MissionService missionService) {
this.piloteService = piloteService;
this.missionService = missionService;
}
@GetMapping("/fichePilote")
......@@ -29,9 +43,42 @@ public class FichePiloteController {
Pilote pilote = new Pilote();
pilote = piloteService.findById(Integer.valueOf(id_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";
}
@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 {
RacePilote race2 = RacePilote.valueOf(race);
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()) {
Pilote pilote = new Pilote();
pilote.setNom(nom);
......
/*
* 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.enumerations.EtatChasseur;
import fr.ldnr.starWars.services.ChasseurService;
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 Johad
*/
@Controller
public class ModifierEtatChasseurController {
private final ChasseurService chasseurService;
public ModifierEtatChasseurController(ChasseurService chasseurService) {
this.chasseurService = chasseurService;
}
@GetMapping("/modifierEtatChasseur")
public String modifierEtatPilote(Model model) {
model.addAttribute("etatChasseur", chasseurService.listeTypeChasseur());
return "modifierEtatChasseur";
}
@PostMapping("/modifierEtatChasseur")
public String modifierEtatChasseur(@RequestParam Long id_chasseur, Model model,
@RequestParam(value="etat") String etat) {
model.addAttribute("etatChasseur", chasseurService.modifierEtat(id_chasseur, EtatChasseur.valueOf(etat)));
return "modifierEtatChasseur";
}
}
///*
// * 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.enumerations.EtatChasseur;
//import fr.ldnr.starWars.services.ChasseurService;
//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 Johad
// */
//@Controller
//public class ModifierEtatChasseurController {
//
// private final ChasseurService chasseurService;
//
// public ModifierEtatChasseurController(ChasseurService chasseurService) {
// this.chasseurService = chasseurService;
// }
//
// @GetMapping("/modifierEtatChasseur")
// public String modifierEtatPilote(Model model) {
// model.addAttribute("etatChasseur", chasseurService.listeTypeChasseur());
// return "modifierEtatChasseur";
// }
//
// @PostMapping("/modifierEtatChasseur")
// public String modifierEtatChasseur(@RequestParam Long id_chasseur, Model model,
// @RequestParam(value="etat") String etat) {
//
// model.addAttribute("etatChasseur", chasseurService.modifierEtat(id_chasseur, EtatChasseur.valueOf(etat)));
// return "modifierEtatChasseur";
// }
//}
......@@ -65,6 +65,8 @@ public class NouvelleMissionController {
model.addAttribute("chasseursDispo", listChasseurs);
model.addAttribute("pilotesDispo", listPilotes);
model.addAttribute("chasseursDispo", listChasseurs);
listPiloteTemp.clear();
listChasseurTemp.clear();
return "nouvelleMission";
}
......
......@@ -20,7 +20,9 @@ import org.springframework.stereotype.Repository;
@Repository
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);
......
......@@ -33,4 +33,6 @@ public interface ChasseurService {
public Chasseur findById(Integer idChasseur);
public Iterable<EtatChasseur> listeEtatChasseur();
}
......@@ -56,6 +56,13 @@ public class ChasseurServiceImpl implements ChasseurService {
return list;
}
@Override
public Iterable<EtatChasseur> listeEtatChasseur() {
List<EtatChasseur> list = Arrays.asList(EtatChasseur.values());
return list;
}
@Override
public Iterable<Chasseur> trouverParId(Long id_chasseur) {
List<Chasseur> list = new ArrayList();
......
......@@ -19,7 +19,9 @@ public interface PiloteService {
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);
......
......@@ -79,9 +79,13 @@ public class PiloteServiceImpl implements PiloteService {
}
@Override
public Pilote findByNom(String nom) {
public List<Pilote> findByNom(String nom) {
return piloteRepository.findByNom(nom);
}
@Override
public List<Pilote> findByNomAndPrenom(String nom, String prenom) {
return piloteRepository.findByNomAndPrenom(nom, prenom);
}
@Override
public List<Pilote> findByGrade(GradePilote grade) {
......
<!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>
......@@ -15,6 +15,7 @@
<h1><span class='faulty-letter'>{</span> Fiche chasseur</h1>
</header>
<main>
<form th:action="@{/ficheChasseur}" method="post">
<table>
<tr>
<th>Id</th>
......@@ -22,11 +23,17 @@
<th>Etat chasseur</th>
</tr>
<tr th:each="chasseur: ${ficheChasseur}">
<td th:text="${chasseur.id_chasseur}"></td>
<td th:text="${chasseur.type_chasseur}"></td>
<td th:text="${chasseur.etat_chasseur}"></td>
<td th:text="${chasseur.idChasseur}"></td>
<td th:text="${chasseur.type}"></td>
<td>
<select id="etat" name="etat">
<option th:each="etat : ${etat}" th:value="${etat}" th:text="${etat}"></option>
</select>
</td>
</tr>
</table>
<input type="submit" value="Submit"/>
</form>
<a th:href="@{/listeChasseur}">Retour a la liste des chasseurs</a>
</main>
<footer>
......
......@@ -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>Age à l'inscription : <span th:text="${pilote.age}"></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>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>
<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>
<footer>
<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
<div class="box">
<label class="label" for="age">Age</label>
<input type="text" id="age" name="age"/>
<span th:text="${messageError}"></span>
</div>
<div class="button">
<input type="submit" value="Valider"/>
......
......@@ -19,20 +19,37 @@ Click nbfs://nbhost/SystemFileSystem/Templates/Other/html.html to edit this temp
<h1><span class='faulty-letter'>{</span> Liste Missions Terminées</h1>
</header>
<main>
<div>
<label for="tri mission">Selection de mission :</label>
<table>
<tr th:each="mission : ${missions}">
<td th:text="${mission.titre}"></td>
<td>
<span th:each="affectation, iterStat : ${mission.affectation}">
<span th:text="${affectation.pilote.nom}"></span>
<span th:if="${!iterStat.last}"></br></span>
</span>
</td>
<td>
<span th:each="affectation, iterStat : ${mission.affectation}">
<span th:text="${affectation.chasseur.type}"></span>
<span th:if="${!iterStat.last}"></br></span>
</span>
</td>
<td>
<span th:each="affectation, iterStat : ${mission.affectation}">
<span th:text="${affectation.mission.resultat}"></span>
<span th:if="${!iterStat.last}"></br></span>
</span>
</td>
<td>
<span th:each="affectation, iterStat : ${mission.affectation}">
<span th:text="${affectation.mission.nbHeure}"></span>
<span th:if="${!iterStat.last}"></br></span>
</span>
</td>
</tr>
<select name="mission" id="tri-mission">
<option value="">-Choisir une option-</option>
<option value="Terminée">Terminee</option>
<option value="En cours">En cours</option>
<option value="Victoire">Victoire</option>
<option value="Défaite">Defaite</option>
<option value="Entrainement">Entrainement</option>
<option value="Combat">Combat</option>
</select>
</table>
</div>
</main>
<footer>
<a href="/menu" class="menu">Retour au Menu</a>
......
......@@ -22,6 +22,7 @@ Click nbfs://nbhost/SystemFileSystem/Templates/Other/html.html to edit this temp
<ul>
<li><a href="/inscriptionPilote" class="menu">Inscription d'un nouveau pilote</a></li>
<li><a href="/listePilote" class="menu">Liste des pilotes actifs</a></li>
<li><a href="/cherchePilote" class="menu">Cherche pilote par nom</a></li>
</ul>
<h2>Chasseur</h2>
......@@ -32,7 +33,7 @@ Click nbfs://nbhost/SystemFileSystem/Templates/Other/html.html to edit this temp
<h2>Mission</h2>
<ul>
<li><a href="/nouvelleMission" class="menu">Nouvelle mission</a></li>
<li><a href="/listeMission" class="menu">Liste des missions</a></li>
<li><a href="/listeMission" class="menu">Liste des missions terminées</a></li>
<li><a href="/clotureMission" class="menu">Cloturer une mission</a></li>
</ul>
</main>
......
<!DOCTYPE html>
<!--
Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
......@@ -5,7 +6,7 @@ Click nbfs://nbhost/SystemFileSystem/Templates/Other/html.html to edit this temp
-->
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<title>nouvelle mission</title>
<title>Nouvelle Mission</title>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link rel="stylesheet" href="/style.css"/>
......@@ -27,6 +28,7 @@ Click nbfs://nbhost/SystemFileSystem/Templates/Other/html.html to edit this temp
<label for="titre">Titre</label>
<input type="text" id="titre" name="titre"/>
</div>
<button type="submit">Creer mission</button>
</div>
</form>
......@@ -52,8 +54,10 @@ Click nbfs://nbhost/SystemFileSystem/Templates/Other/html.html to edit this temp
<button type="submit">Affecter</button>
</form>
<p>Mission id : <span th:text="${idMission}"></span>
<span> est affectée aux : </span></p>
<span> est affectée aux : </span>
</p>
<table>
<tr th:each="listPiloteTemp : ${listPiloteTemps}">
......@@ -64,6 +68,7 @@ Click nbfs://nbhost/SystemFileSystem/Templates/Other/html.html to edit this temp
</tr>
</table>
<form th:if="${affectationFormVisible}" th:object="${affectation}" th:action="@{/affectation/{idMission}}" method="post">
<button type="submit" name="affectationButton">Affectation</button>
</form>
......