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;
}
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) {
this.jourGarde = jourGarde;
this.periode = periode;

View File

@ -12,6 +12,7 @@ import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.Map;
import javax.swing.JCheckBox;
/**
*
@ -28,6 +29,13 @@ public class DispoForm {
GardeMySQL vm = new GardeMySQL();
Map<String, String[]> map = request.getParameterMap();
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;
for (Gardes uneGarde : lesG) {
int oldAct = uneGarde.getDisponibilite();
@ -49,6 +57,64 @@ public class DispoForm {
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++;
}

View File

@ -94,6 +94,10 @@ public class GardesServlet extends HttpServlet {
//System.out.println("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 */
String[] lesCouleurs = {"blanc", "gris", "jaune"};
@ -117,6 +121,7 @@ public class GardesServlet extends HttpServlet {
// processRequest(request, response);
DispoForm vf = new DispoForm();
vf.verifDispo(request);
getServletContext().getRequestDispatcher("/WEB-INF/pompierJSP.jsp").forward(request, response);
}

View File

@ -31,37 +31,53 @@
<tr>
<c:forEach var="i" begin="0" end="6" step="1">
<c:forEach items='${sessionScope.lesPeriodes}' var="unePeriode" varStatus="status">
<td class="text-center">${unePeriode.getCode()}</td>
</c:forEach>
</c:forEach>
</tr>
</thead>
<tbody>
<c:set var="oldId" value="-1" scope="page"/>
<tr>
<c:forEach items='${sessionScope.lesVentilInit}' var="uneVentil" varStatus="status">
<c:set var="newId" value='${uneVentil.getPompier().getId()}' scope="page"/>
<c:if test='${oldId != newId}' var="test" scope="page">
</tr><tr>
<td>${uneVentil.getPompier().getId()}</td>
<td>${uneVentil.getPompier().getNom()} ${uneVentil.getPompier().getPrenom()}</td>
<tbody>
<c:set var="oldId" value='${newId}' scope="page"/>
</c:if>
<c:set var="activite" value='${uneVentil.getDisponibilite()}' scope="page"/>
<td>
<input readonly type="text" value='${activite}' name="lesActivites"class="ztVentil ${sessionScope.lesCouleurs[activite]}"/>
<input type="checkbox" id="cbGarde"/>
</td>
</c:forEach>
</tr>
<c:set var="oldId" value="-1" scope="page"/>
<tr>
</tbody>
<c:forEach items='${sessionScope.lesVentilInit}' var="uneVentil" varStatus="status">
<c:set var="newId" value='${uneVentil.getPompier().getId()}' scope="page"/>
<c:if test='${oldId != newId}' var="test" scope="page">
</tr><tr>
<td>${uneVentil.getPompier().getId()}</td>
<td>${uneVentil.getPompier().getNom()} ${uneVentil.getPompier().getPrenom()}</td>
<c:set var="oldId" value='${newId}' scope="page"/>
</c:if>
<c:set var="activite" value='${uneVentil.getDisponibilite()}' scope="page"/>
<c:set var="check" value="" scope="page"/>
<c:if test="${uneVentil.isDeGarde() == true}" var="test" scope="page">
<c:set var="check" value="checked" scope="page"/>
</c:if>
<c:choose>
<c:when test="${sessionScope.lePompierConnecte.getLeStatut().getCode() eq 2}">
<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>
</c:forEach>
</tr>
</tbody>
</table>
<div id="legendCouleur">
@ -71,27 +87,32 @@
<span>De garde : ☑</span>
</div>
<div class="text-center">
<button type="submit" value="Valider" class="btn btn-danger"><i class="bi bi-check2"></i> Valider</button>
</div>
<div class="text-center">
<button type="submit" value="Valider" class="btn btn-danger"><i class="bi bi-check2"></i> Valider</button>
</div>
</form>
</fieldset>
</section>
</div>
</body>
<script>
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;
var st = (document.getElementById("statut").textContent).trim();
if (st != "chef de centre") {
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>

View File

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