Merge origin/master

Conflicts:
	web/WEB-INF/feuilleGardes.jsp
	web/css/mycss.css
This commit is contained in:
clementine.desrucques 2021-12-16 16:50:32 +01:00
parent 623728d3e3
commit 5287b5ff74
5 changed files with 141 additions and 38 deletions

View File

@ -29,6 +29,14 @@ public class Gardes {
this.deGarde = deGarde; this.deGarde = deGarde;
} }
public Gardes(Calendar jourGarde, int periode, Pompier pompier, boolean deGarde) {
this.jourGarde = jourGarde;
this.periode = periode;
this.pompier = pompier;
this.deGarde = deGarde;
}
public Gardes(Calendar jourGarde, int periode, Pompier pompier) { public Gardes(Calendar jourGarde, int periode, Pompier pompier) {
this.jourGarde = jourGarde; this.jourGarde = jourGarde;
this.periode = periode; this.periode = periode;

View File

@ -12,6 +12,7 @@ import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession; import jakarta.servlet.http.HttpSession;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Map; import java.util.Map;
import javax.swing.JCheckBox;
/** /**
* *
@ -28,6 +29,13 @@ public class DispoForm {
GardeMySQL vm = new GardeMySQL(); GardeMySQL vm = new GardeMySQL();
Map<String, String[]> map = request.getParameterMap(); Map<String, String[]> map = request.getParameterMap();
String[] lesNvVentil = map.get("lesActivites"); String[] lesNvVentil = map.get("lesActivites");
String[] lesNvGardes = map.get("cbGarde");
ArrayList<Integer> lesNvGardesN = new ArrayList<>();
if(lesNvGardes != null){
for(String uneGarde : lesNvGardes){
lesNvGardesN.add(Integer.parseInt(uneGarde));
}
}
int i = 0; int i = 0;
for (Gardes uneGarde : lesG) { for (Gardes uneGarde : lesG) {
int oldAct = uneGarde.getDisponibilite(); int oldAct = uneGarde.getDisponibilite();
@ -49,6 +57,64 @@ public class DispoForm {
uneGarde.setIsInBDD(true); uneGarde.setIsInBDD(true);
} }
}
boolean oldGarde = uneGarde.isDeGarde();
boolean newGarde = lesNvGardesN.contains(i)?true:false;
System.out.println("1: "+oldGarde +" "+ newGarde);
if(oldGarde!= newGarde){
uneGarde.setDeGarde(newGarde);
System.out.println("2: "+oldGarde +" "+ newGarde);
if (uneGarde.isIsInBDD()) {
vm.update(uneGarde);
}else{
vm.create(uneGarde);
uneGarde.setIsInBDD(true);
System.out.println("3: "+oldGarde +" "+ newGarde);
}
}
i++;
}
}
public void verifGarde(HttpServletRequest request) {
HttpSession maS = request.getSession();
ArrayList<Gardes> lesG = (ArrayList<Gardes>) maS.getAttribute("lesVentilInit");
GardeMySQL vm = new GardeMySQL();
Map<String, String[]> map = request.getParameterMap();
String[] lesNvVentil = map.get("cbGarde");
// JCheckBox garde = new JCheckBox();
int i = 0;
for (Gardes uneGarde : lesG) {
boolean oldAct = uneGarde.isDeGarde();
int newAct = Integer.parseInt(lesNvVentil[i]);
boolean newActO = (newAct==Integer.parseInt(lesNvVentil[i]));
if (oldAct != newActO) {
if (uneGarde.isIsInBDD()) {
if (newActO == false) {
vm.delete(uneGarde);
uneGarde.setIsInBDD(false);
uneGarde.isDeGarde();
} else {
uneGarde.isDeGarde();
vm.update(uneGarde);
}
} else {
uneGarde.isDeGarde();
vm.create(uneGarde);
uneGarde.setIsInBDD(true);
}
} }
i++; i++;
} }

View File

@ -94,6 +94,10 @@ public class GardesServlet extends HttpServlet {
//System.out.println("lesVentilInit : " + lesVentilInit); //System.out.println("lesVentilInit : " + lesVentilInit);
maSession.setAttribute("lesVentilInit", lesVentilInit); maSession.setAttribute("lesVentilInit", lesVentilInit);
// GardeMySQL dg = new GardeMySQL();
// ArrayList<Gardes> lesgardes = dg.();
// //System.out.println("lesVentilInit : " + lesVentilInit);
// maSession.setAttribute("lesVentilInit", lesVentilInit);
/* Initialisation des couleurs */ /* Initialisation des couleurs */
String[] lesCouleurs = {"blanc", "gris", "jaune"}; String[] lesCouleurs = {"blanc", "gris", "jaune"};
@ -117,6 +121,7 @@ public class GardesServlet extends HttpServlet {
// processRequest(request, response); // processRequest(request, response);
DispoForm vf = new DispoForm(); DispoForm vf = new DispoForm();
vf.verifDispo(request); vf.verifDispo(request);
getServletContext().getRequestDispatcher("/WEB-INF/pompierJSP.jsp").forward(request, response); getServletContext().getRequestDispatcher("/WEB-INF/pompierJSP.jsp").forward(request, response);
} }

View File

@ -37,31 +37,47 @@
</c:forEach> </c:forEach>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<c:set var="oldId" value="-1" scope="page"/> <c:set var="oldId" value="-1" scope="page"/>
<tr> <tr>
<c:forEach items='${sessionScope.lesVentilInit}' var="uneVentil" varStatus="status"> <c:forEach items='${sessionScope.lesVentilInit}' var="uneVentil" varStatus="status">
<c:set var="newId" value='${uneVentil.getPompier().getId()}' scope="page"/> <c:set var="newId" value='${uneVentil.getPompier().getId()}' scope="page"/>
<c:if test='${oldId != newId}' var="test" scope="page"> <c:if test='${oldId != newId}' var="test" scope="page">
</tr><tr> </tr><tr>
<td>${uneVentil.getPompier().getId()}</td> <td>${uneVentil.getPompier().getId()}</td>
<td>${uneVentil.getPompier().getNom()} ${uneVentil.getPompier().getPrenom()}</td> <td>${uneVentil.getPompier().getNom()} ${uneVentil.getPompier().getPrenom()}</td>
<c:set var="oldId" value='${newId}' scope="page"/> <c:set var="oldId" value='${newId}' scope="page"/>
</c:if> </c:if>
<c:set var="activite" value='${uneVentil.getDisponibilite()}' scope="page"/> <c:set var="activite" value='${uneVentil.getDisponibilite()}' scope="page"/>
<td> <c:set var="check" value="" scope="page"/>
<input readonly type="text" value='${activite}' name="lesActivites"class="ztVentil ${sessionScope.lesCouleurs[activite]}"/> <c:if test="${uneVentil.isDeGarde() == true}" var="test" scope="page">
<input type="checkbox" id="cbGarde"/> <c:set var="check" value="checked" scope="page"/>
</c:if>
</td> <c:choose>
</c:forEach> <c:when test="${sessionScope.lePompierConnecte.getLeStatut().getCode() eq 2}">
</tr> <td>
<input readonly type="text" value='${activite}' name="lesActivites" class="ztVentil ${sessionScope.lesCouleurs[activite]}"/>
<input type="checkbox" ${check} name="cbGarde" value="${status.count +1}">
</td>
</c:when>
<c:otherwise>
<td>
<input readonly type="text" value='${activite}' name="lesActivites" class="ztVentil ${sessionScope.lesCouleurs[activite]}"/>
<input type="checkbox" ${check} name="cbGarde" value="${status.count +1}" onclick="return false">
</td>
</c:otherwise>
</c:choose>
</tbody>
</c:forEach>
</tr>
</tbody>
</table> </table>
<div id="legendCouleur"> <div id="legendCouleur">
@ -71,27 +87,32 @@
<span>De garde : ☑</span> <span>De garde : ☑</span>
</div> </div>
<div class="text-center"> <div class="text-center">
<button type="submit" value="Valider" class="btn btn-danger"><i class="bi bi-check2"></i> Valider</button> <button type="submit" value="Valider" class="btn btn-danger"><i class="bi bi-check2"></i> Valider</button>
</div> </div>
</form> </form>
</fieldset> </fieldset>
</section> </section>
</div> </div>
</body> </body>
<script> <script>
var couleurs = ["blanc", "gris", "jaune"]; var st = (document.getElementById("statut").textContent).trim();
var lesAct = document.getElementsByClassName("ztVentil"); if (st != "chef de centre") {
for (var uneAct of lesAct) {
uneAct.onclick = function () {
var act = this.value;
var newAct = (act + 1) % 3;
var coul = couleurs[newAct];
this.classList.remove(couleurs[act]);
this.classList.add(coul);
this.value = newAct;
var couleurs = ["blanc", "gris", "jaune"];
var lesAct = document.getElementsByClassName("ztVentil");
for (var uneAct of lesAct) {
uneAct.onclick = function () {
var act = this.value;
var newAct = (act + 1) % 3;
var coul = couleurs[newAct];
this.classList.remove(couleurs[act]);
this.classList.add(coul);
this.value = newAct;
}
} }
} }
</script> </script>

View File

@ -14,7 +14,10 @@
<c:otherwise> <c:otherwise>
<h4>Bienvenue ${sessionScope.lePompierConnecte.getPrenom()} <h4>Bienvenue ${sessionScope.lePompierConnecte.getPrenom()}
${sessionScope.lePompierConnecte.getNom()} ( ${sessionScope.lePompierConnecte.getNom()} (
${sessionScope.lePompierConnecte.getLeStatut().getValeur()}) <span id="statut">
${sessionScope.lePompierConnecte.getLeStatut().getValeur()}
</span>
)
</h4> </h4>
<button type="button" class="btn btn-warning fs-4" title="Déconnexion"> <button type="button" class="btn btn-warning fs-4" title="Déconnexion">