Nouvelle mage
This commit is contained in:
parent
3933d81f8f
commit
749bd2c8e2
|
|
@ -1,6 +1,7 @@
|
||||||
DROP TABLE IF EXISTS bloc;
|
DROP TABLE IF EXISTS bloc;
|
||||||
|
DROP TABLE IF EXISTS partage;
|
||||||
DROP TABLE IF EXISTS page;
|
DROP TABLE IF EXISTS page;
|
||||||
DROP TABLE IF EXISTS messages;
|
DROP TABLE IF EXISTS message;
|
||||||
DROP TABLE IF EXISTS utilisateur;
|
DROP TABLE IF EXISTS utilisateur;
|
||||||
|
|
||||||
CREATE TABLE utilisateur (
|
CREATE TABLE utilisateur (
|
||||||
|
|
@ -14,7 +15,7 @@ CREATE TABLE page (
|
||||||
id INT PRIMARY KEY AUTO_INCREMENT,
|
id INT PRIMARY KEY AUTO_INCREMENT,
|
||||||
titre VARCHAR(200) NOT NULL,
|
titre VARCHAR(200) NOT NULL,
|
||||||
date_creation DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
date_creation DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
date_modification DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
date_modification DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
auteur_id INT NOT NULL,
|
auteur_id INT NOT NULL,
|
||||||
droits ENUM('LECTURE', 'ECRITURE', 'ADMIN') NOT NULL,
|
droits ENUM('LECTURE', 'ECRITURE', 'ADMIN') NOT NULL,
|
||||||
FOREIGN KEY (auteur_id) REFERENCES utilisateur(id) ON DELETE CASCADE
|
FOREIGN KEY (auteur_id) REFERENCES utilisateur(id) ON DELETE CASCADE
|
||||||
|
|
@ -22,10 +23,10 @@ CREATE TABLE page (
|
||||||
|
|
||||||
CREATE TABLE bloc (
|
CREATE TABLE bloc (
|
||||||
id INT PRIMARY KEY AUTO_INCREMENT,
|
id INT PRIMARY KEY AUTO_INCREMENT,
|
||||||
type ENUM('TEXTE', 'LISTE', 'TITRE', 'CODE', 'PAGE') NOT NULL,
|
type ENUM('TEXTE', 'LISTE', 'TITRE', 'CODE', 'PAGE') NOT NULL DEFAULT 'TEXTE',
|
||||||
contenu TEXT,
|
contenu TEXT,
|
||||||
date_creation DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
date_creation DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
date_modification DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
date_modification DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
page_id INT NOT NULL,
|
page_id INT NOT NULL,
|
||||||
ordre INT NOT NULL,
|
ordre INT NOT NULL,
|
||||||
auteur_id INT NOT NULL,
|
auteur_id INT NOT NULL,
|
||||||
|
|
@ -34,33 +35,26 @@ CREATE TABLE bloc (
|
||||||
FOREIGN KEY (auteur_id) REFERENCES utilisateur(id) ON DELETE CASCADE
|
FOREIGN KEY (auteur_id) REFERENCES utilisateur(id) ON DELETE CASCADE
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE messages (
|
CREATE TABLE message (
|
||||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
login VARCHAR(100) NOT NULL,
|
login VARCHAR(100) NOT NULL,
|
||||||
contenu TEXT,
|
contenu TEXT,
|
||||||
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
|
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||||
);
|
);
|
||||||
|
|
||||||
DELIMITER //
|
CREATE TABLE partage (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
page_id INT NOT NULL,
|
||||||
|
utilisateur_id INT NOT NULL,
|
||||||
|
droits ENUM('LECTURE', 'ECRITURE') NOT NULL DEFAULT 'LECTURE',
|
||||||
|
date_partage DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
FOREIGN KEY (page_id) REFERENCES page(id) ON DELETE CASCADE,
|
||||||
|
FOREIGN KEY (utilisateur_id) REFERENCES utilisateur(id) ON DELETE CASCADE,
|
||||||
|
UNIQUE(page_id, utilisateur_id) -- Empêche les doublons de partage
|
||||||
|
);
|
||||||
|
|
||||||
CREATE TRIGGER trg_bloc_maj
|
|
||||||
BEFORE UPDATE ON bloc
|
|
||||||
FOR EACH ROW
|
|
||||||
BEGIN
|
|
||||||
SET NEW.date_modification = NOW();
|
|
||||||
END;
|
|
||||||
//
|
|
||||||
|
|
||||||
DELIMITER ;
|
CREATE INDEX idx_page_auteur ON page(auteur_id);
|
||||||
|
CREATE INDEX idx_bloc_page ON bloc(page_id);
|
||||||
|
CREATE INDEX idx_partages_user ON partage(utilisateur_id);
|
||||||
|
|
||||||
DELIMITER //
|
|
||||||
|
|
||||||
CREATE TRIGGER trg_page_maj
|
|
||||||
BEFORE UPDATE ON page
|
|
||||||
FOR EACH ROW
|
|
||||||
BEGIN
|
|
||||||
SET NEW.date_modification = NOW();
|
|
||||||
END;
|
|
||||||
//
|
|
||||||
|
|
||||||
DELIMITER ;
|
|
||||||
|
|
|
||||||
|
|
@ -24,11 +24,16 @@ public class AfficherPage extends HttpServlet {
|
||||||
|
|
||||||
if(u != null) {
|
if(u != null) {
|
||||||
u.chargerPages();
|
u.chargerPages();
|
||||||
|
u.chargerPagesPartagees();
|
||||||
ArrayList<Page> listePages = u.getListePages();
|
ArrayList<Page> listePages = u.getListePages();
|
||||||
|
ArrayList<Page> listePagesPartagees = u.getListePagesPartagees();
|
||||||
ArrayList<Message> listeMessages = Message.getListeMessages();
|
ArrayList<Message> listeMessages = Message.getListeMessages();
|
||||||
|
ArrayList<Utilisateur> listeUtilisateurs = Utilisateur.getListeUtilisateurs();
|
||||||
|
|
||||||
request.setAttribute("listePages", listePages);
|
request.setAttribute("listePages", listePages);
|
||||||
|
request.setAttribute("listePagesPartagees", listePagesPartagees);
|
||||||
request.setAttribute("listeMessages", listeMessages);
|
request.setAttribute("listeMessages", listeMessages);
|
||||||
|
request.setAttribute("listeUtilisateurs", listeUtilisateurs);
|
||||||
|
|
||||||
if (idStr != null ) {
|
if (idStr != null ) {
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,9 @@ import java.sql.Connection;
|
||||||
import java.sql.Date;
|
import java.sql.Date;
|
||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -31,9 +33,6 @@ public class Bloc extends ParamBD {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bloc(int id, Type type, String contenu, int ordre) {
|
public Bloc(int id, Type type, String contenu, int ordre) {
|
||||||
if (contenu == null || contenu.isEmpty()) {
|
|
||||||
throw new IllegalArgumentException("Le contenu ne peut pas être vide.");
|
|
||||||
}
|
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.contenu = contenu;
|
this.contenu = contenu;
|
||||||
|
|
@ -103,13 +102,14 @@ public class Bloc extends ParamBD {
|
||||||
return "Bloc{id=" + id + ", type=" + type + ", contenu='" + contenu + "', dateCreation=" + dateCreation + ", dateModification=" + dateModification + ", ordre=" + ordre + "}";
|
return "Bloc{id=" + id + ", type=" + type + ", contenu='" + contenu + "', dateCreation=" + dateCreation + ", dateModification=" + dateModification + ", ordre=" + ordre + "}";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void ajouterBloc(int idU, int idP, String contenu, int ordre, Type type, LocalDate dl, Map<String, Object> metadata) {
|
protected static int ajouterBloc(int idU, int idP, String contenu, int ordre, Type type, LocalDate dl, Map<String, Object> metadata) {
|
||||||
|
int idGenere = -1 ;
|
||||||
try {
|
try {
|
||||||
Connection connexion = DriverManager.getConnection(bdURL, bdLogin, bdPassword);
|
Connection connexion = DriverManager.getConnection(bdURL, bdLogin, bdPassword);
|
||||||
String sql = " INSERT INTO bloc(type, contenu, date_creation, date_modification, page_id, ordre, auteur_id, metadata)"
|
String sql = " INSERT INTO bloc(type, contenu, date_creation, date_modification, page_id, ordre, auteur_id, metadata)"
|
||||||
+ " VALUES (?, ?, ?, ?, ?, ?, ?, ?)"
|
+ " VALUES (?, ?, ?, ?, ?, ?, ?, ?)"
|
||||||
+ ";";
|
+ ";";
|
||||||
PreparedStatement pst = connexion.prepareStatement(sql);
|
PreparedStatement pst = connexion.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
|
||||||
pst.setString(1, type.name());
|
pst.setString(1, type.name());
|
||||||
pst.setString(2, contenu);
|
pst.setString(2, contenu);
|
||||||
pst.setDate(3, Date.valueOf(dl));
|
pst.setDate(3, Date.valueOf(dl));
|
||||||
|
|
@ -120,6 +120,37 @@ public class Bloc extends ParamBD {
|
||||||
pst.setString(8, metadata.toString());
|
pst.setString(8, metadata.toString());
|
||||||
pst.executeUpdate();
|
pst.executeUpdate();
|
||||||
|
|
||||||
|
ResultSet rs = pst.getGeneratedKeys();
|
||||||
|
if (rs.next()) {
|
||||||
|
idGenere = rs.getInt(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
rs.close();
|
||||||
|
pst.close();
|
||||||
|
connexion.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return idGenere;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static void ajouterBlocVide(int idU, int idP) {
|
||||||
|
try {
|
||||||
|
Connection connexion = DriverManager.getConnection(bdURL, bdLogin, bdPassword);
|
||||||
|
String sql = "INSERT INTO bloc(type, page_id, ordre, auteur_id, contenu, metadata)"
|
||||||
|
+ " VALUES (?, ?, ?, ?, '', '{}');";
|
||||||
|
PreparedStatement pst = connexion.prepareStatement(sql);
|
||||||
|
|
||||||
|
Type type = Type.TEXTE;
|
||||||
|
int ordre = 0;
|
||||||
|
|
||||||
|
pst.setString(1, type.name());
|
||||||
|
pst.setInt(2, idP);
|
||||||
|
pst.setInt(3, ordre);
|
||||||
|
pst.setInt(4, idU);
|
||||||
|
|
||||||
|
pst.executeUpdate();
|
||||||
pst.close();
|
pst.close();
|
||||||
connexion.close();
|
connexion.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
|
@ -127,6 +158,7 @@ public class Bloc extends ParamBD {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void updateBloc(int idBloc, String nouveauContenu) {
|
public static void updateBloc(int idBloc, String nouveauContenu) {
|
||||||
try {
|
try {
|
||||||
Connection connexion = DriverManager.getConnection(bdURL, bdLogin, bdPassword);
|
Connection connexion = DriverManager.getConnection(bdURL, bdLogin, bdPassword);
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ public class Message extends ParamBD{
|
||||||
protected static void ajouterMessage(String login, String contenu) {
|
protected static void ajouterMessage(String login, String contenu) {
|
||||||
try {
|
try {
|
||||||
Connection connexion = DriverManager.getConnection(bdURL, bdLogin, bdPassword);
|
Connection connexion = DriverManager.getConnection(bdURL, bdLogin, bdPassword);
|
||||||
String sql = " INSERT INTO messages(contenu, login)"
|
String sql = " INSERT INTO message(contenu, login)"
|
||||||
+ " VALUES (?, ?)"
|
+ " VALUES (?, ?)"
|
||||||
+ ";";
|
+ ";";
|
||||||
PreparedStatement pst = connexion.prepareStatement(sql);
|
PreparedStatement pst = connexion.prepareStatement(sql);
|
||||||
|
|
@ -59,7 +59,7 @@ public class Message extends ParamBD{
|
||||||
try {
|
try {
|
||||||
Connection connexion = DriverManager.getConnection(bdURL, bdLogin, bdPassword);
|
Connection connexion = DriverManager.getConnection(bdURL, bdLogin, bdPassword);
|
||||||
String sql = " SELECT login, contenu"
|
String sql = " SELECT login, contenu"
|
||||||
+ " FROM messages"
|
+ " FROM message"
|
||||||
+ ";";
|
+ ";";
|
||||||
PreparedStatement pst = connexion.prepareStatement(sql);
|
PreparedStatement pst = connexion.prepareStatement(sql);
|
||||||
ResultSet rs = pst.executeQuery();
|
ResultSet rs = pst.executeQuery();
|
||||||
|
|
@ -79,4 +79,19 @@ public class Message extends ParamBD{
|
||||||
|
|
||||||
return messages;
|
return messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static void effacerMessage() {
|
||||||
|
try {
|
||||||
|
Connection connexion = DriverManager.getConnection(bdURL, bdLogin, bdPassword);
|
||||||
|
String sql = " DELETE FROM message"
|
||||||
|
+ ";";
|
||||||
|
PreparedStatement pst = connexion.prepareStatement(sql);
|
||||||
|
pst.executeUpdate();
|
||||||
|
|
||||||
|
pst.close();
|
||||||
|
connexion.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
package projet;
|
package projet;
|
||||||
|
|
||||||
import jakarta.servlet.RequestDispatcher;
|
|
||||||
import jakarta.servlet.ServletException;
|
import jakarta.servlet.ServletException;
|
||||||
import jakarta.servlet.annotation.WebServlet;
|
import jakarta.servlet.annotation.WebServlet;
|
||||||
import jakarta.servlet.http.HttpServlet;
|
import jakarta.servlet.http.HttpServlet;
|
||||||
|
|
@ -26,8 +25,7 @@ public class NouveauBloc extends HttpServlet {
|
||||||
Utilisateur u = (Utilisateur) session.getAttribute("utilisateur");
|
Utilisateur u = (Utilisateur) session.getAttribute("utilisateur");
|
||||||
|
|
||||||
if(u != null) {
|
if(u != null) {
|
||||||
RequestDispatcher rd = request.getRequestDispatcher("AfficherPage.jsp");
|
response.sendRedirect("AfficherPage");
|
||||||
rd.forward(request, response);
|
|
||||||
}else {
|
}else {
|
||||||
response.sendRedirect("/Projet/");
|
response.sendRedirect("/Projet/");
|
||||||
}
|
}
|
||||||
|
|
@ -45,18 +43,18 @@ public class NouveauBloc extends HttpServlet {
|
||||||
String ordreStr = request.getParameter("ordre");
|
String ordreStr = request.getParameter("ordre");
|
||||||
String pageIdStr = request.getParameter("pageId");
|
String pageIdStr = request.getParameter("pageId");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int ordre = Integer.parseInt(ordreStr);
|
int ordre = Integer.parseInt(ordreStr);
|
||||||
int pageId = Integer.parseInt(pageIdStr);
|
int pageId = Integer.parseInt(pageIdStr);
|
||||||
Bloc.Type type = Bloc.Type.valueOf(typeStr);
|
Bloc.Type type = Bloc.Type.valueOf(typeStr);
|
||||||
Map<String, Object> metadata = new HashMap<>();
|
Map<String, Object> metadata = new HashMap<>();
|
||||||
|
|
||||||
if (contenu == null || contenu.isEmpty()) {
|
int idGenere = Bloc.ajouterBloc(u.getId(), pageId, contenu, ordre, type, LocalDate.now(), metadata);
|
||||||
response.sendRedirect("AfficherPage");
|
response.setContentType("application/json");
|
||||||
} else {
|
response.setCharacterEncoding("UTF-8");
|
||||||
|
response.getWriter().write("{\"idGenere\": " + idGenere + "}");
|
||||||
|
|
||||||
Bloc.ajouterBloc(u.getId(), pageId, contenu, ordre, type, LocalDate.now(), metadata);
|
|
||||||
response.sendRedirect("AfficherPage");
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
response.sendRedirect("/Projet/");
|
response.sendRedirect("/Projet/");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
package projet;
|
package projet;
|
||||||
|
|
||||||
import jakarta.servlet.RequestDispatcher;
|
|
||||||
import jakarta.servlet.ServletException;
|
import jakarta.servlet.ServletException;
|
||||||
import jakarta.servlet.annotation.WebServlet;
|
import jakarta.servlet.annotation.WebServlet;
|
||||||
import jakarta.servlet.http.HttpServlet;
|
import jakarta.servlet.http.HttpServlet;
|
||||||
|
|
@ -24,8 +23,7 @@ public class NouvellePage extends HttpServlet {
|
||||||
Utilisateur u = (Utilisateur) session.getAttribute("utilisateur");
|
Utilisateur u = (Utilisateur) session.getAttribute("utilisateur");
|
||||||
|
|
||||||
if(u != null) {
|
if(u != null) {
|
||||||
RequestDispatcher rd = request.getRequestDispatcher("AfficherPage.jsp");
|
response.sendRedirect("AfficherPage");
|
||||||
rd.forward(request, response);
|
|
||||||
}else {
|
}else {
|
||||||
response.sendRedirect("/Projet/");
|
response.sendRedirect("/Projet/");
|
||||||
}
|
}
|
||||||
|
|
@ -44,7 +42,9 @@ public class NouvellePage extends HttpServlet {
|
||||||
response.sendRedirect("AfficherPage");
|
response.sendRedirect("AfficherPage");
|
||||||
} else {
|
} else {
|
||||||
int id = Page.ajouterPage(u.getId(), titre, LocalDate.now());
|
int id = Page.ajouterPage(u.getId(), titre, LocalDate.now());
|
||||||
if (id !=-1) response.sendRedirect("AfficherPage?id=" + id);
|
if (id !=-1) {
|
||||||
|
response.sendRedirect("AfficherPage?id=" + id);
|
||||||
|
}
|
||||||
else response.sendRedirect("AfficherPage");
|
else response.sendRedirect("AfficherPage");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import projet.Bloc.Type;
|
||||||
|
|
||||||
public class Page extends ParamBD {
|
public class Page extends ParamBD {
|
||||||
private int id;
|
private int id;
|
||||||
|
private int auteur_id;
|
||||||
private String titre;
|
private String titre;
|
||||||
private LocalDate dateCreation;
|
private LocalDate dateCreation;
|
||||||
private LocalDate dateModification;
|
private LocalDate dateModification;
|
||||||
|
|
@ -31,19 +32,21 @@ public class Page extends ParamBD {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Page(int id, String titre, LocalDate dateCreation, LocalDate dateModification, Droit droits) {
|
public Page(int id, int auteur_id, String titre, LocalDate dateCreation, LocalDate dateModification, Droit droits) {
|
||||||
if (titre == null || titre.isEmpty()) {
|
if (titre == null || titre.isEmpty()) {
|
||||||
throw new IllegalArgumentException("Le contenu ne peut pas être vide.");
|
throw new IllegalArgumentException("Le contenu ne peut pas être vide.");
|
||||||
}
|
}
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
this.auteur_id = auteur_id;
|
||||||
this.titre = titre;
|
this.titre = titre;
|
||||||
this.dateCreation = dateCreation;
|
this.dateCreation = dateCreation;
|
||||||
this.dateModification = dateModification;
|
this.dateModification = dateModification;
|
||||||
this.droits = droits;
|
this.droits = droits;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Page(int id, String titre) {
|
public Page(int id, int auteur_id, String titre) {
|
||||||
this(id, titre, null, null, Droit.ADMIN); // Appelle le constructeur avec droits = null
|
this.id = id;
|
||||||
|
this.titre = titre;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
|
|
@ -54,6 +57,14 @@ public class Page extends ParamBD {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getAuteur_id() {
|
||||||
|
return auteur_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAuteur_id(int auteur_id) {
|
||||||
|
this.auteur_id = auteur_id;
|
||||||
|
}
|
||||||
|
|
||||||
public String getTitre() {
|
public String getTitre() {
|
||||||
return titre;
|
return titre;
|
||||||
}
|
}
|
||||||
|
|
@ -126,6 +137,10 @@ public class Page extends ParamBD {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (idGenere != -1) {
|
||||||
|
Bloc.ajouterBlocVide(idU, idGenere);
|
||||||
|
}
|
||||||
|
|
||||||
return idGenere;
|
return idGenere;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -140,14 +155,21 @@ public class Page extends ParamBD {
|
||||||
sql = " SELECT titre"
|
sql = " SELECT titre"
|
||||||
+ " FROM page"
|
+ " FROM page"
|
||||||
+ " WHERE id=? AND auteur_id = ?"
|
+ " WHERE id=? AND auteur_id = ?"
|
||||||
|
+ " UNION"
|
||||||
|
+ " SELECT titre"
|
||||||
|
+ " FROM partage"
|
||||||
|
+ " JOIN page ON partage.page_id = page.id"
|
||||||
|
+ " WHERE partage.utilisateur_id = ?"
|
||||||
+ ";";
|
+ ";";
|
||||||
pst = connexion.prepareStatement(sql);
|
pst = connexion.prepareStatement(sql);
|
||||||
pst.setInt(1, id);
|
pst.setInt(1, id);
|
||||||
pst.setInt(2, idU);
|
pst.setInt(2, idU);
|
||||||
|
pst.setInt(3, idU);
|
||||||
rs = pst.executeQuery();
|
rs = pst.executeQuery();
|
||||||
while(rs.next()) {
|
while(rs.next()) {
|
||||||
titre = rs.getString("titre");
|
titre = rs.getString("titre");
|
||||||
page.titre = titre;
|
page.titre = titre;
|
||||||
|
page.id = id;
|
||||||
}
|
}
|
||||||
if(titre != null) {
|
if(titre != null) {
|
||||||
sql = " SELECT id, contenu, type, ordre"
|
sql = " SELECT id, contenu, type, ordre"
|
||||||
|
|
@ -170,6 +192,9 @@ public class Page extends ParamBD {
|
||||||
page.listeBlocs.add(bloc);
|
page.listeBlocs.add(bloc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
rs.close();
|
||||||
|
pst.close();
|
||||||
|
connexion.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
@ -189,6 +214,29 @@ public class Page extends ParamBD {
|
||||||
pst.setInt(2, idU);
|
pst.setInt(2, idU);
|
||||||
pst.executeUpdate();
|
pst.executeUpdate();
|
||||||
|
|
||||||
|
pst.close();
|
||||||
|
connexion.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void partagerPage(int idPage, int idU, int idP) {
|
||||||
|
try {
|
||||||
|
Connection connexion = DriverManager.getConnection(bdURL, bdLogin, bdPassword);
|
||||||
|
String sql = " INSERT INTO partage (page_id, utilisateur_id)"
|
||||||
|
+ " SELECT ?, ?"
|
||||||
|
+ " FROM page"
|
||||||
|
+ " WHERE id = ? AND auteur_id = ?"
|
||||||
|
+ ";";
|
||||||
|
PreparedStatement pst = connexion.prepareStatement(sql);
|
||||||
|
|
||||||
|
pst.setInt(1, idPage);
|
||||||
|
pst.setInt(2, idP);
|
||||||
|
pst.setInt(3, idPage);
|
||||||
|
pst.setInt(4, idU);
|
||||||
|
pst.executeUpdate();
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,7 @@ public class SupprimerBloc extends HttpServlet {
|
||||||
Utilisateur u = (Utilisateur) session.getAttribute("utilisateur");
|
Utilisateur u = (Utilisateur) session.getAttribute("utilisateur");
|
||||||
|
|
||||||
if(u != null) {
|
if(u != null) {
|
||||||
RequestDispatcher rd = request.getRequestDispatcher("AfficherPage.jsp");
|
response.sendRedirect("AfficherPage");
|
||||||
rd.forward(request, response);
|
|
||||||
}else {
|
}else {
|
||||||
response.sendRedirect("/Projet/");
|
response.sendRedirect("/Projet/");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,7 @@ public class SupprimerPage extends HttpServlet {
|
||||||
Utilisateur u = (Utilisateur) session.getAttribute("utilisateur");
|
Utilisateur u = (Utilisateur) session.getAttribute("utilisateur");
|
||||||
|
|
||||||
if(u != null) {
|
if(u != null) {
|
||||||
RequestDispatcher rd = request.getRequestDispatcher("AfficherPage.jsp");
|
response.sendRedirect("AfficherPage");
|
||||||
rd.forward(request, response);
|
|
||||||
}else {
|
}else {
|
||||||
response.sendRedirect("/Projet/");
|
response.sendRedirect("/Projet/");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,7 @@ public class Tchat {
|
||||||
|
|
||||||
@OnMessage
|
@OnMessage
|
||||||
public void onMessage(String message, Session senderSession) throws IOException {
|
public void onMessage(String message, Session senderSession) throws IOException {
|
||||||
System.out.println(message);
|
|
||||||
String[] parts = message.split(" : ", 2);
|
String[] parts = message.split(" : ", 2);
|
||||||
System.out.println(parts[0].trim());
|
|
||||||
System.out.println(parts[1].trim());
|
|
||||||
System.out.println("");
|
|
||||||
if (parts.length == 2) {
|
if (parts.length == 2) {
|
||||||
String login = parts[0].trim();
|
String login = parts[0].trim();
|
||||||
String contenu = parts[1].trim();
|
String contenu = parts[1].trim();
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ public class Utilisateur extends ParamBD {
|
||||||
private String login;
|
private String login;
|
||||||
private Privilege privilege;
|
private Privilege privilege;
|
||||||
private ArrayList<Page> listePages;
|
private ArrayList<Page> listePages;
|
||||||
|
private ArrayList<Page> listePagesPartagees;
|
||||||
|
|
||||||
public enum Privilege {
|
public enum Privilege {
|
||||||
ADMIN,
|
ADMIN,
|
||||||
|
|
@ -25,6 +26,14 @@ public class Utilisateur extends ParamBD {
|
||||||
GUEST
|
GUEST
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Utilisateur(int id, String login) {
|
||||||
|
if (login == null || login.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("Le pseudo ne peut pas être vide.");
|
||||||
|
}
|
||||||
|
this.id = id;
|
||||||
|
this.login = login;
|
||||||
|
}
|
||||||
|
|
||||||
public Utilisateur(int id, String login, Privilege privilege) {
|
public Utilisateur(int id, String login, Privilege privilege) {
|
||||||
if (login == null || login.isEmpty()) {
|
if (login == null || login.isEmpty()) {
|
||||||
throw new IllegalArgumentException("Le pseudo ne peut pas être vide.");
|
throw new IllegalArgumentException("Le pseudo ne peut pas être vide.");
|
||||||
|
|
@ -42,14 +51,6 @@ public class Utilisateur extends ParamBD {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Privilege getprivilege() {
|
|
||||||
return privilege;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setprivilege(Privilege privilege) {
|
|
||||||
this.privilege = privilege;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLogin() {
|
public String getLogin() {
|
||||||
return login;
|
return login;
|
||||||
}
|
}
|
||||||
|
|
@ -58,8 +59,8 @@ public class Utilisateur extends ParamBD {
|
||||||
this.login = login;
|
this.login = login;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Privilege getPrivilege() {
|
public String getPrivilege() {
|
||||||
return privilege;
|
return privilege.name();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPrivilege(Privilege privilege) {
|
public void setPrivilege(Privilege privilege) {
|
||||||
|
|
@ -78,10 +79,18 @@ public class Utilisateur extends ParamBD {
|
||||||
return "Utilisateur{id=" + id + ", login='" + login + "', privilege=" + privilege + "}";
|
return "Utilisateur{id=" + id + ", login='" + login + "', privilege=" + privilege + "}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ArrayList<Page> getListePagesPartagees() {
|
||||||
|
return listePagesPartagees;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setListePagesPartagees(ArrayList<Page> listePagesPartagees) {
|
||||||
|
this.listePagesPartagees = listePagesPartagees;
|
||||||
|
}
|
||||||
|
|
||||||
protected void chargerPages(){
|
protected void chargerPages(){
|
||||||
try {
|
try {
|
||||||
Connection connexion = DriverManager.getConnection(bdURL, bdLogin, bdPassword);
|
Connection connexion = DriverManager.getConnection(bdURL, bdLogin, bdPassword);
|
||||||
String sql = " SELECT id, titre, date_creation, date_modification, droits"
|
String sql = " SELECT id, auteur_id, titre, date_creation, date_modification, droits"
|
||||||
+ " FROM page"
|
+ " FROM page"
|
||||||
+ " WHERE auteur_id="
|
+ " WHERE auteur_id="
|
||||||
+ this.id
|
+ this.id
|
||||||
|
|
@ -92,13 +101,41 @@ public class Utilisateur extends ParamBD {
|
||||||
listePages = new ArrayList<Page>();
|
listePages = new ArrayList<Page>();
|
||||||
while(rs.next()) {
|
while(rs.next()) {
|
||||||
int idPage = rs.getInt("id");
|
int idPage = rs.getInt("id");
|
||||||
|
int auteur_id = rs.getInt("auteur_id");
|
||||||
String titre = rs.getString("titre");
|
String titre = rs.getString("titre");
|
||||||
LocalDate date_creation = rs.getDate("date_creation").toLocalDate();
|
LocalDate date_creation = rs.getDate("date_creation").toLocalDate();
|
||||||
LocalDate date_modification = rs.getDate("date_modification").toLocalDate();
|
LocalDate date_modification = rs.getDate("date_modification").toLocalDate();
|
||||||
String droits = rs.getString("droits");
|
String droits = rs.getString("droits");
|
||||||
Droit droitsEnum = Droit.valueOf(droits.toUpperCase());
|
Droit droitsEnum = Droit.valueOf(droits.toUpperCase());
|
||||||
|
|
||||||
listePages.add(new Page(idPage, titre, date_creation, date_modification, droitsEnum));
|
listePages.add(new Page(idPage, auteur_id, titre, date_creation, date_modification, droitsEnum));
|
||||||
|
}
|
||||||
|
rs.close();
|
||||||
|
st.close();
|
||||||
|
connexion.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void chargerPagesPartagees(){
|
||||||
|
try {
|
||||||
|
Connection connexion = DriverManager.getConnection(bdURL, bdLogin, bdPassword);
|
||||||
|
String sql = " SELECT page.id, titre"
|
||||||
|
+ " FROM partage"
|
||||||
|
+ " JOIN page ON partage.page_id = page.id"
|
||||||
|
+ " WHERE utilisateur_id="
|
||||||
|
+ this.id
|
||||||
|
+ ";";
|
||||||
|
Statement st = connexion.createStatement();
|
||||||
|
ResultSet rs = st.executeQuery(sql);
|
||||||
|
|
||||||
|
listePagesPartagees = new ArrayList<Page>();
|
||||||
|
while(rs.next()) {
|
||||||
|
int idPage = rs.getInt("id");
|
||||||
|
String titre = rs.getString("titre");
|
||||||
|
|
||||||
|
listePagesPartagees.add(new Page(idPage, this.id, titre));
|
||||||
}
|
}
|
||||||
rs.close();
|
rs.close();
|
||||||
st.close();
|
st.close();
|
||||||
|
|
@ -159,8 +196,8 @@ public class Utilisateur extends ParamBD {
|
||||||
return u;
|
return u;
|
||||||
}
|
}
|
||||||
|
|
||||||
sql = "INSERT INTO utilisateur (login, mot_de_passe) "
|
sql = "INSERT INTO utilisateur (login, mot_de_passe, privilege)"
|
||||||
+ " VALUES (?, ?)"
|
+ " VALUES (?, ?, 'USER')"
|
||||||
+ ";";
|
+ ";";
|
||||||
pst = connexion.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
|
pst = connexion.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
|
||||||
pst.setString(1, login);
|
pst.setString(1, login);
|
||||||
|
|
@ -182,4 +219,30 @@ public class Utilisateur extends ParamBD {
|
||||||
}
|
}
|
||||||
return u;
|
return u;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static ArrayList<Utilisateur> getListeUtilisateurs() {
|
||||||
|
ArrayList<Utilisateur> listeUtilisateur = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
Connection connexion = DriverManager.getConnection(bdURL, bdLogin, bdPassword);
|
||||||
|
String sql = " SELECT id, login"
|
||||||
|
+ " FROM utilisateur"
|
||||||
|
+ ";";
|
||||||
|
Statement st = connexion.createStatement();
|
||||||
|
ResultSet rs = st.executeQuery(sql);
|
||||||
|
|
||||||
|
while(rs.next()) {
|
||||||
|
int id = rs.getInt("id");
|
||||||
|
String login = rs.getString("login");
|
||||||
|
|
||||||
|
Utilisateur u = new Utilisateur(id, login);
|
||||||
|
listeUtilisateur.add(u);
|
||||||
|
}
|
||||||
|
rs.close();
|
||||||
|
st.close();
|
||||||
|
connexion.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return listeUtilisateur;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,40 +18,46 @@
|
||||||
<div class="column is-half">
|
<div class="column is-half">
|
||||||
<c:choose>
|
<c:choose>
|
||||||
<c:when test="${not empty page.titre}">
|
<c:when test="${not empty page.titre}">
|
||||||
|
<div class="is-flex is-justify-content-space-between is-align-items-center mb-4">
|
||||||
<h2 class="block">${page.titre}</h2>
|
<h2 class="block">${page.titre}</h2>
|
||||||
|
<div class="dropdown is-right">
|
||||||
|
<div class="dropdown-trigger">
|
||||||
|
<button class="button" aria-haspopup="true" aria-controls="dropdown-menu3">
|
||||||
|
<span><i class="fa-solid fa-share-nodes"></i></span>
|
||||||
|
<span class="icon is-small">
|
||||||
|
<i class="fas fa-angle-down" aria-hidden="true"></i>
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="dropdown-menu" id="dropdown-menu3" role="menu">
|
||||||
|
<div class="dropdown-content">
|
||||||
|
<c:forEach var="u" items="${listeUtilisateurs}">
|
||||||
|
<c:if test="${u.id != utilisateur.id}">
|
||||||
|
<a href="Partage?idP=${u.id}&idPage=${page.id}" class="dropdown-item">${u.login}</a>
|
||||||
|
</c:if>
|
||||||
|
</c:forEach>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="block" id="md">
|
<div class="block" id="md">
|
||||||
<c:forEach var="bloc" items="${page.listeBlocs}">
|
<c:forEach var="bloc" items="${page.listeBlocs}">
|
||||||
<div class="field is-grouped is-align-items-flex-start bloc-container" data-id="${bloc.id}">
|
<div class="field is-grouped is-align-items-flex-start bloc-container">
|
||||||
<div class="control is-expanded">
|
<div class="control is-expanded">
|
||||||
<textarea
|
<div
|
||||||
class="textarea is-primary"
|
class="textarea is-primary editor"
|
||||||
|
contenteditable="true"
|
||||||
rows="1"
|
rows="1"
|
||||||
data-id="${bloc.id}"
|
data-id="${bloc.id}"
|
||||||
data-ordre="${bloc.ordre}"
|
data-ordre="${bloc.ordre}"
|
||||||
data-type="${bloc.type}"
|
data-type="${bloc.type}"
|
||||||
>${bloc.contenu}</textarea>
|
>${bloc.contenu}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<button class="delete is-danger delete-bloc-btn" data-id="${bloc.id}"></button>
|
<button class="delete is-danger delete-bloc-btn" data-id="${bloc.id}"></button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</c:forEach>
|
</c:forEach>
|
||||||
|
|
||||||
<div class="field is-grouped is-align-items-flex-start bloc-container" data-id="${bloc.id}">
|
|
||||||
<div class="control is-expanded">
|
|
||||||
<textarea
|
|
||||||
class="textarea is-primary"
|
|
||||||
rows="1"
|
|
||||||
data-id="${bloc.id}"
|
|
||||||
data-ordre="${bloc.ordre}"
|
|
||||||
data-type="${bloc.type}"
|
|
||||||
placeholder = "Tapez ici...";
|
|
||||||
></textarea>
|
|
||||||
</div>
|
|
||||||
<div class="control">
|
|
||||||
<button class="delete is-danger delete-bloc-btn" data-id="${bloc.id}"></button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</c:when>
|
</c:when>
|
||||||
<c:otherwise>
|
<c:otherwise>
|
||||||
|
|
@ -61,197 +67,10 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- La colonne pour le Tchat -->
|
<!-- La colonne pour le Tchat -->
|
||||||
<div class="column is-one-quarter is-flex is-flex-direction-column">
|
<div class="column is-one-quarter">
|
||||||
<jsp:include page="Tchat.jsp" />
|
<jsp:include page="Tchat.jsp" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
|
||||||
// focus sur le dernier textarea quand la page s'ouvre
|
|
||||||
window.addEventListener('DOMContentLoaded', () => {
|
|
||||||
const textareas = document.querySelectorAll('textarea');
|
|
||||||
if (textareas.length > 0) {
|
|
||||||
textareas[textareas.length - 1].focus(); // focus sur le dernier
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Fonction pour ajouter un nouvel événement à chaque textarea
|
|
||||||
function addTextareaEvent(textarea) {
|
|
||||||
|
|
||||||
textarea.addEventListener('keydown', function(event) {
|
|
||||||
|
|
||||||
if (event.key === 'Enter' && !event.shiftKey) {
|
|
||||||
event.preventDefault(); // Empêcher le saut de ligne par défaut
|
|
||||||
|
|
||||||
const allTextareas = document.querySelectorAll('#md textarea');
|
|
||||||
const lastTextarea = allTextareas[allTextareas.length - 1];
|
|
||||||
|
|
||||||
if (lastTextarea.value.trim() !== "") {
|
|
||||||
// Envoi d'un nouveau bloc au serveur
|
|
||||||
const params = new URLSearchParams();
|
|
||||||
params.append("contenu", lastTextarea.value);
|
|
||||||
params.append("type", "TEXTE"); // Tu peux le changer dynamiquement
|
|
||||||
params.append("ordre", allTextareas.length);
|
|
||||||
params.append("pageId", new URLSearchParams(window.location.search).get("id"));
|
|
||||||
|
|
||||||
fetch("/Projet/NouveauBloc", {
|
|
||||||
method: "POST",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/x-www-form-urlencoded"
|
|
||||||
},
|
|
||||||
body: params
|
|
||||||
}).then(response => {
|
|
||||||
if (!response.ok) {
|
|
||||||
console.error("Erreur lors de l'ajout du bloc.");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Créer un nouveau textarea seulement si le dernier n'est pas vide
|
|
||||||
const newTextarea = document.createElement('textarea');
|
|
||||||
newTextarea.classList.add('textarea', 'is-primary');
|
|
||||||
newTextarea.placeholder = "Tapez ici...";
|
|
||||||
newTextarea.rows = "1";
|
|
||||||
newTextarea.dataset.type = "TEXTE";
|
|
||||||
|
|
||||||
document.getElementById('md').appendChild(newTextarea);
|
|
||||||
addTextareaEvent(newTextarea);
|
|
||||||
autoResize(newTextarea);
|
|
||||||
newTextarea.focus();
|
|
||||||
} else {
|
|
||||||
// Envoi d'un update de bloc au serveur
|
|
||||||
event.preventDefault();
|
|
||||||
const currentTextarea = event.target;
|
|
||||||
const blocId = currentTextarea.getAttribute('data-id'); // Récupère l'ID du bloc
|
|
||||||
const params = new URLSearchParams();
|
|
||||||
params.append("contenu", currentTextarea.value);
|
|
||||||
params.append("blocId", blocId);
|
|
||||||
|
|
||||||
fetch("/Projet/ModifBloc", {
|
|
||||||
method: "POST",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/x-www-form-urlencoded"
|
|
||||||
},
|
|
||||||
body: params
|
|
||||||
}).then(response => {
|
|
||||||
if (!response.ok) {
|
|
||||||
console.error("Erreur lors de la mise à jour du bloc.");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
lastTextarea.focus();
|
|
||||||
}
|
|
||||||
} else if (event.key === 'Enter' && event.shiftKey) { // Si Shift + Entrée est pressé
|
|
||||||
event.preventDefault();
|
|
||||||
const cursorPosition = textarea.selectionStart;
|
|
||||||
const textBefore = textarea.value.substring(0, cursorPosition);
|
|
||||||
const textAfter = textarea.value.substring(cursorPosition);
|
|
||||||
textarea.value = textBefore + "\n" + textAfter;
|
|
||||||
textarea.selectionStart = textarea.selectionEnd = cursorPosition + 1;
|
|
||||||
autoResize(textarea);
|
|
||||||
textarea.focus();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
textarea.addEventListener('input', function () {
|
|
||||||
autoResize(textarea);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function autoResize(textarea) {
|
|
||||||
textarea.style.height = 'auto';
|
|
||||||
textarea.style.height = textarea.scrollHeight + 'px';
|
|
||||||
}
|
|
||||||
|
|
||||||
document.querySelectorAll('#md textarea').forEach(t => {
|
|
||||||
addTextareaEvent(t);
|
|
||||||
autoResize(t)
|
|
||||||
});
|
|
||||||
|
|
||||||
function addDeleteBloc(button) {
|
|
||||||
button.addEventListener('click', function () {
|
|
||||||
const blocId = button.dataset.id;
|
|
||||||
const blocContainer = button.closest('.bloc-container');
|
|
||||||
const textarea = blocContainer.querySelector('textarea');
|
|
||||||
|
|
||||||
if (textarea.value.trim() === "") {
|
|
||||||
return; // Empêche la suppression si le textarea est vide
|
|
||||||
}
|
|
||||||
|
|
||||||
if (confirm("Voulez-vous vraiment supprimer ce bloc ?")) {
|
|
||||||
const params = new URLSearchParams();
|
|
||||||
params.append("blocId", blocId);
|
|
||||||
|
|
||||||
fetch("/Projet/SupprimerBloc", {
|
|
||||||
method: "POST",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/x-www-form-urlencoded"
|
|
||||||
},
|
|
||||||
body: params
|
|
||||||
}).then(response => {
|
|
||||||
if (response.ok) {
|
|
||||||
blocContainer.remove(); // Supprime visuellement le bloc
|
|
||||||
} else {
|
|
||||||
console.error("Erreur lors de la suppression du bloc.");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
document.querySelectorAll('.delete-bloc-btn').forEach(t => {
|
|
||||||
addDeleteBloc(t);
|
|
||||||
});
|
|
||||||
|
|
||||||
function addDeletePage(button) {
|
|
||||||
button.addEventListener('click', function () {
|
|
||||||
const pageId = button.dataset.id;
|
|
||||||
|
|
||||||
if (confirm("Voulez-vous vraiment supprimer cette page ?")) {
|
|
||||||
const params = new URLSearchParams();
|
|
||||||
params.append("pageId", pageId);
|
|
||||||
|
|
||||||
fetch("/Projet/SupprimerPage", {
|
|
||||||
method: "POST",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/x-www-form-urlencoded"
|
|
||||||
},
|
|
||||||
body: params
|
|
||||||
}).then(response => {
|
|
||||||
if (response.ok) {
|
|
||||||
location.reload();
|
|
||||||
} else {
|
|
||||||
console.error("Erreur lors de la suppression du bloc.");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
document.querySelectorAll('.delete-page-btn').forEach(t => {
|
|
||||||
addDeletePage(t);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Pour le Tchat
|
|
||||||
const socket = new WebSocket("ws://" + window.location.host + "/Projet/ws/tchat");
|
|
||||||
|
|
||||||
socket.onmessage = function(event) {
|
|
||||||
const container = document.querySelector(".messages-container");
|
|
||||||
const p = document.createElement("p");
|
|
||||||
p.textContent = event.data;
|
|
||||||
container.appendChild(p);
|
|
||||||
container.scrollTop = container.scrollHeight;
|
|
||||||
};
|
|
||||||
|
|
||||||
document.querySelector("input[name='contenu']").addEventListener("keydown", function(event) {
|
|
||||||
const login = document.getElementById("user-login").textContent;
|
|
||||||
if (event.key === "Enter") {
|
|
||||||
const message = this.value;
|
|
||||||
if (message.trim() !== "") {
|
|
||||||
socket.send(login + " : " + message);
|
|
||||||
this.value = "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
<jsp:include page="Footer.jsp" />
|
<jsp:include page="Footer.jsp" />
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
height="24">
|
height="24">
|
||||||
</a>
|
</a>
|
||||||
</footer>
|
</footer>
|
||||||
</main>
|
</main>
|
||||||
|
<script src="script.js?v=<%= System.currentTimeMillis() %>"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
@ -6,33 +6,8 @@
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>${param.titre}</title>
|
<title>${param.titre}</title>
|
||||||
<link href="bulma.css" rel="stylesheet">
|
<link href="bulma.css" rel="stylesheet">
|
||||||
<style>
|
<link rel="stylesheet" href="styles.css">
|
||||||
.textarea {
|
<script src="https://kit.fontawesome.com/39474be7e2.js" crossorigin="anonymous"></script>
|
||||||
resize: none; /* Empêche le redimensionnement par l'utilisateur */
|
|
||||||
overflow-y: hidden; /* Masquer la barre de défilement verticale */
|
|
||||||
border: none;
|
|
||||||
outline: none;
|
|
||||||
}
|
|
||||||
.tchat-container {
|
|
||||||
flex-grow: 1;
|
|
||||||
max-height: 100%;
|
|
||||||
height: 100%;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
}
|
|
||||||
.messages-container {
|
|
||||||
flex-grow: 1;
|
|
||||||
overflow-y: auto;
|
|
||||||
margin-bottom: 0.5rem;
|
|
||||||
padding: 0.5rem;
|
|
||||||
border: 1px solid #ddd;
|
|
||||||
border-radius: 4px;
|
|
||||||
background: #f9f9f9;
|
|
||||||
}
|
|
||||||
.tchat-container input[type="text"] {
|
|
||||||
margin-top: auto;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<nav class="navbar has-shadow is-white" aria-label="main navigation">
|
<nav class="navbar has-shadow is-white" aria-label="main navigation">
|
||||||
|
|
@ -49,11 +24,14 @@
|
||||||
</div>
|
</div>
|
||||||
</c:if>
|
</c:if>
|
||||||
<c:choose>
|
<c:choose>
|
||||||
<c:when test="${not empty sessionScope.utilisateur}">
|
<c:when test="${not empty utilisateur}">
|
||||||
<a class="navbar-item" href="Deconnexion">Se déconnecter</a>
|
<c:if test="${utilisateur.privilege == 'ADMIN'}">
|
||||||
|
<a class="navbar-item" href="SupprimerMessage">Supprimer les messages</a>
|
||||||
|
</c:if>
|
||||||
|
<a class="navbar-item" href="Deconnexion"><i class="fa-solid fa-right-from-bracket"></i></a>
|
||||||
</c:when>
|
</c:when>
|
||||||
<c:otherwise>
|
<c:otherwise>
|
||||||
<a class="navbar-item" href="">Se connecter</a>
|
<a class="navbar-item" href=""><i class="fa-solid fa-right-to-bracket"></i></a>
|
||||||
<a class="navbar-item" href="">S'inscrire</a>
|
<a class="navbar-item" href="">S'inscrire</a>
|
||||||
</c:otherwise>
|
</c:otherwise>
|
||||||
</c:choose>
|
</c:choose>
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,13 @@
|
||||||
|
|
||||||
</li>
|
</li>
|
||||||
</c:forEach>
|
</c:forEach>
|
||||||
|
<hr>
|
||||||
|
<c:forEach var="pagePartagees" items="${listePagesPartagees}">
|
||||||
|
<li>
|
||||||
|
<i class="fa-solid fa-share-nodes is-pulled-right"></i>
|
||||||
|
<a href="AfficherPage?id=${pagePartagees.id}">${pagePartagees.titre}</a>
|
||||||
|
</li>
|
||||||
|
</c:forEach>
|
||||||
<li>
|
<li>
|
||||||
<form action="NouvellePage" method="POST">
|
<form action="NouvellePage" method="POST">
|
||||||
<input
|
<input
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
pageEncoding="UTF-8"%>
|
pageEncoding="UTF-8"%>
|
||||||
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
|
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
|
||||||
|
|
||||||
<div class="tchat-container is-flex is-flex-direction-column">
|
<div class="tchat-container">
|
||||||
<h2 class="block">Tchat</h2>
|
<h2 class="block">Tchat</h2>
|
||||||
<div class="messages-container" id="Messages" style="height: 60vh;">
|
<div class="messages-container" id="Messages" style="height: 60vh;">
|
||||||
<c:forEach var="message" items="${listeMessages}">
|
<c:forEach var="message" items="${listeMessages}">
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue