Skip to content
Snippets Groups Projects
Commit 008c87b7 authored by Boris OUYA's avatar Boris OUYA
Browse files

Merge branch 'main' into 'authentification'

# Conflicts:
#   src/com/uca/dao/_Initializer.java
#   src/main/resources/views/eleves.ftl
parents 62a90b23 11c7fa4c
No related branches found
No related tags found
1 merge request!2Date en plus propre
Showing
with 219 additions and 26 deletions
build/**
bin/**
\ No newline at end of file
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -9,5 +9,5 @@ Tables :
-gommettes (id, nom, description)
-gommetteAttribs (id, idEleve, idProf, raison)
-gommetteAttribs (id, idEleve, idProf, idGommette, dateAttribution, raison)
......@@ -23,7 +23,6 @@ public class StartServer {
}
public static void main(String[] args) {
int portNb = 8081;
//Configure Spark
staticFiles.location("/static/");
......@@ -32,6 +31,10 @@ public class StartServer {
_Initializer.Init();
// Debug:
connected = _Initializer.DEBUG_BORIS_ADMIN;
authentified = true;
//Defining our routes
displayLocalHost(portNb, "users");
get("/users", (req, res) -> {
......@@ -110,7 +113,12 @@ public class StartServer {
res.redirect("/login");
return null;
}
});
get("/eleves/gommettes",(req,res)->{
String id = req.queryParams("id");
return EleveGommetteGUI.getEleveGommettes(Integer.parseInt(id));
});
......@@ -137,6 +145,13 @@ public class StartServer {
return null;
});
post("/eleves/gommette/delete", (req,res)->{
System.out.println("deleted gommette");
Core.GommetteAttrib.delete(Integer.parseInt(req.queryParams("id")));
res.redirect("/eleves");
return null;
});
post("/eleves/delete", (req,res) ->{
Core.Eleve.delete(Integer.parseInt(req.queryParams("id")));
res.redirect("/eleves");
......
......@@ -13,11 +13,13 @@ public class GommetteAttribDAO extends _DefaultDAO<GommetteAttribEntity> {
@Override
public void pushUnsafe(GommetteAttribEntity obj) throws Exception
{
PreparedStatement stmt = this.connect.prepareStatement("update " + getDefaultTableName() + " set idEleve=?, idProf=?, raison=? where id=?;");
PreparedStatement stmt = this.connect.prepareStatement("update " + getDefaultTableName() + " set idEleve=?, idProf=?, idGommette=?, raison=?, dateAttribution=? where id=?;");
int idx = 1;
stmt.setInt (idx++, obj.getIdEleve());
stmt.setInt (idx++, obj.getIdProf());
stmt.setInt (idx++, obj.getIdGommette());
stmt.setString(idx++, obj.getRaisonAttribution());
stmt.setString(idx++, obj.getDateAttribution());
stmt.setInt (idx++, obj.getId());
stmt.executeUpdate();
}
......@@ -27,12 +29,11 @@ public class GommetteAttribDAO extends _DefaultDAO<GommetteAttribEntity> {
{
GommetteAttribEntity entity = new GommetteAttribEntity();
entity.setId(resultSet.getInt("id"));
// entity.setCouleur TODO
entity.setIdEleve(resultSet.getInt("idEleve"));
entity.setIdProf(resultSet.getInt("idProf"));
entity.setIdGommette(resultSet.getInt("idGommette"));
// entity.setDateAttrib TODO
entity.setRaisonAttribution(resultSet.getString("raison"));
entity.setDateAttribution(resultSet.getString("dateAttribution"));
return entity;
}
}
\ No newline at end of file
......@@ -7,6 +7,8 @@ import java.sql.*;
public class _Initializer {
public static ProfEntity DEBUG_BORIS_ADMIN;
public static void DropTable(String name)
{
try {
......@@ -19,6 +21,9 @@ public class _Initializer {
public static void CreateTable(String command)
{
System.out.println("Creation de la table "+command.split(" ")[0]);
command = "CREATE TABLE IF NOT EXISTS "+command;
try {
PreparedStatement statement;
......@@ -35,12 +40,13 @@ public class _Initializer {
DropTable("profs");
DropTable("eleves");
DropTable("gommettes");
CreateTable("CREATE TABLE IF NOT EXISTS users (id int primary key auto_increment, firstname varchar(100), lastname varchar(100));");
CreateTable("CREATE TABLE IF NOT EXISTS profs (id int primary key auto_increment, firstname varchar(100), lastname varchar(100), username varchar(100), password varchar(100));");
CreateTable("CREATE TABLE IF NOT EXISTS eleves (id int primary key auto_increment, firstname varchar(100), lastname varchar(100), nomClasse varchar(100), dateNaissance DATE);");
CreateTable("CREATE TABLE IF NOT EXISTS gommettes (id int primary key auto_increment, nom varchar(100), description varchar(100), couleur varchar(100));");
CreateTable("CREATE TABLE IF NOT EXISTS gommetteAttribs (id int primary key auto_increment, idEleve int, idProf int, raison varchar(500));");
DropTable("gommetteAttribs");
CreateTable("users (id int primary key auto_increment, firstname varchar(100), lastname varchar(100));");
CreateTable("profs (id int primary key auto_increment, firstname varchar(100), lastname varchar(100), username varchar(100), password varchar(100));");
CreateTable("eleves (id int primary key auto_increment, firstname varchar(100), lastname varchar(100), nomClasse varchar(100), dateNaissance varchar(100));");
CreateTable("gommettes (id int primary key auto_increment, nom varchar(100), description varchar(100), couleur varchar(100));");
CreateTable("gommetteAttribs (id int primary key auto_increment, idEleve int, idProf int, idGommette int, dateAttribution varchar(10), raison varchar(500));");
UserEntity e = Core.User.create("Le père de toto", "pas toto");
Core.User.create("Jean", "Némar");
......@@ -53,11 +59,18 @@ public class _Initializer {
Core.User.create("Terry", "Golo");
Core.User.create("Judas", "Nanas");
Core.Prof.create("Boris", "OUYA", "DaWarudo","KonoDioDa!");
Core.Prof.create("Thomas", "TAMAGNAUD", "CéMoiLul","BlockusMaster");
DEBUG_BORIS_ADMIN = Core.Prof.create("Boris", "OUYA", "DaWarudo","KonoDioDa");
ProfEntity toto = Core.Prof.create("Thomas", "TAMAGNAUD", "CéMoiLul","BlockusMaster");
GommetteEntity sagePetit = Core.Gommette.create("Brave Petit", Couleur.Vert, "S'est montré obéissant devant le prêtre");
GommetteEntity uniCorn = Core.Gommette.create("Badge Unicorne", Couleur.ArcEnCiel, "C'est magique!");
EleveEntity bibi = Core.Eleve.create("Bibi","Johnson","23/10/2018","Zarbi");
Core.GommetteAttrib.create(bibi.getId(), DEBUG_BORIS_ADMIN.getId(), sagePetit.getId(), "1/1/2000", "Aucune raison");
Core.GommetteAttrib.create(bibi.getId(), toto.getId(), uniCorn.getId(), "1/1/2001", "Our Little Poney");
//Core.Eleve.create("Bibi","Johnson","23/10/2018","Zarbi");
Core.Gommette.create("Brave Petit",Couleur.Vert,"S'est montré obéissant devant le prêtre");
}
}
package com.uca.entity;
import java.util.*;
public enum Couleur
{
ArcEnCiel("arcEnCiel"),
Rouge("rouge"),
Vert ("vert"),
Bleu ("bleu"),
Blanc("blanc");
ArcEnCiel("arcEnCiel", null),
Rouge("rouge", "FF0000"),
Vert ("vert", "00FF00"),
Bleu ("bleu", "0000FF"),
Blanc("blanc", "FFFFFF");
private String value;
private String codeHexa;
private Couleur(String value)
private Couleur(String value, String codeHexa)
{
this.value = value;
this.codeHexa = codeHexa;
}
public String getString() { return value; }
......@@ -44,7 +48,69 @@ public enum Couleur
}
}
return null;
}
private static String formatWithColor(String txt, String codeHexa)
{
return "<font color=\"#"+codeHexa+"\">"+txt+"</font>";
}
public String format(String txt)
{
if (codeHexa != null)
{
return formatWithColor(txt, codeHexa);
}
String s = "";
for(int i = 0; i < txt.length(); i++)
{
s += formatWithColor(txt.charAt(i)+"", hsvToRgb(i*27/360f, 1, 1));
}
return s;
}
// Thank to https://stackoverflow.com/questions/7896280/converting-from-hsv-hsb-in-java-to-rgb-without-using-java-awt-color-disallowe
private static String hsvToRgb(float hue, float saturation, float value) {
float r, g, b;
int h = (int)(hue * 6);
float f = hue * 6 - h;
float p = value * (1 - saturation);
float q = value * (1 - f * saturation);
float t = value * (1 - (1 - f) * saturation);
if (h == 0) {
r = value;
g = t;
b = p;
} else if (h == 1) {
r = q;
g = value;
b = p;
} else if (h == 2) {
r = p;
g = value;
b = t;
} else if (h == 3) {
r = p;
g = q;
b = value;
} else if (h == 4) {
r = t;
g = p;
b = value;
} else if (h <= 6) {
r = value;
g = p;
b = q;
} else {
throw new RuntimeException("Something went wrong when converting from HSV to RGB. Input was " + hue + ", " + saturation + ", " + value);
}
String rs = Integer.toHexString((int)(r * 255));
String gs = Integer.toHexString((int)(g * 255));
String bs = Integer.toHexString((int)(b * 255));
return rs + gs + bs;
}
}
package com.uca.gui;
import com.uca.core.*;
import freemarker.template.*;
import java.io.*;
import java.util.*;
import com.uca.entity.*;
public class AttributionInfo
{
private GommetteAttribEntity gommetteAttrib;
public GommetteAttribEntity getGommetteAttrib() { return gommetteAttrib; }
public void setGommetteAttrib(GommetteAttribEntity value) { gommetteAttrib = value; }
private GommetteEntity gommette;
public GommetteEntity getGommette() { return gommette; }
public void setGommetteAttrib(GommetteEntity value) { gommette = value; }
private ProfEntity prof;
public ProfEntity getProf() { return prof; }
public void setProf(ProfEntity value) { prof = value; }
public AttributionInfo(GommetteAttribEntity gommetteAttrib, GommetteEntity gommette, ProfEntity prof)
{
this.gommetteAttrib = gommetteAttrib;
this.gommette = gommette;
this.prof = prof;
}
}
\ No newline at end of file
package com.uca.gui;
import com.uca.core.*;
import freemarker.template.*;
import java.io.*;
import java.util.*;
import com.uca.entity.*;
public class EleveGommetteGUI
{
public static String getEleveGommettes(int id) throws IOException, TemplateException {
Map<String, Object> input = new HashMap<>();
input.put("eleve", Core.Eleve.getById(id));
List<GommetteAttribEntity> gommettesAttribs = Core.GommetteAttrib.getAll();
for(int i = gommettesAttribs.size()-1; i >= 0; i--)
{
if(gommettesAttribs.get(i).getIdEleve() != id)
{
gommettesAttribs.remove(i);
}
}
List<AttributionInfo> attributions = new ArrayList<>();
for (GommetteAttribEntity g : gommettesAttribs) {
attributions.add(new AttributionInfo(g, Core.Gommette.getById(g.getIdGommette()), Core.Prof.getById(g.getIdProf())));
}
input.put("attributions", attributions);
return DefaultGUI.getDefaultGUI(input, "eleveGommettes.ftl");
}
}
......@@ -5,6 +5,7 @@ import freemarker.template.*;
import java.io.*;
import java.util.*;
import com.uca.entity.*;
import com.uca.gui.*;
public class GommetteGUI
{
......
<#ftl encoding="utf-8">
<body xmlns="http://www.w3.org/1999/html">
<ul>
<h1> Gommettes de l'élève ${eleve.firstName} ${eleve.lastName} (classe : ${eleve.nomClasse}) </h1>
<#list attributions as attrib>
<h2>
<li>${attrib.gommette.couleur.format(attrib.gommette.nom)} :</li>
<h3>
<p> description: ${attrib.gommette.description} </p>
<p> raison: ${attrib.gommetteAttrib.raisonAttribution} </p>
<p> le ${attrib.gommetteAttrib.dateAttribution} par ${attrib.prof.firstName} ${attrib.prof.lastName} </p>
</h3>
<form action="eleves/gommette/delete" method="post">
<input type="hidden" name="id" value="${attrib.gommetteAttrib.id}">
<button type="submit" name="id">Supprimer</button>
</form>
</h2>
</#list>
</ul>
<a href="/welcome">Accueil</a>
<a href="/profs" >Liste des profs</a>
<a href="/eleves" >Liste des eleves</a>
<a href="/gommettes">Liste des gommettes</a>
</body>
</html>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment