diff --git a/Projet/metadata.md b/Projet/metadata.md index b0f6bd1..4b0af8f 100644 --- a/Projet/metadata.md +++ b/Projet/metadata.md @@ -1,49 +1,63 @@ #Structure Générale de metadata { - "type": "TITRE", - "metadata": { - ... // dépend du type - } + "type": "TITRE", + "metadata": { + ... // dépend du type + } } #Détail par type ##TEXTE { - "type": "TEXTE", - "metadata": {} + "type": "TEXTE", + "metadata": {} } ##TITRE { - "type": "TITRE", - "metadata": { - "level": 1 // ou 2, 3... - } + "type": "TITRE", + "metadata": { + "level": 1 // ou 2, 3... + } } ##LISTE { - "type": "LISTE", - "metadata": { - "style": "bullet" // ou "numbered" - } + "type": "LISTE", + "metadata": { + "style": "bullet" // ou "numbered" + } } ##CODE { - "type": "CODE", - "metadata": { - "language": "javascript", // ou "python", "html", etc. - } + "type": "CODE", + "metadata": { + "language": "javascript", // ou "python", "html", etc. + } } ##PAGE { - "type": "PAGE", - "metadata": { - "pageId": "123", // ID de la page cible - "title": "Nom de la page liée" - } + "type": "PAGE", + "metadata": { + "pageId": "123", // ID de la page cible + "title": "Nom de la page liée", + "from" : "125" // ID de la page + } } +##SEPARATEUR +{ + "type": "SEPARATEUR", + "metadata": {} +} + +##CITATION +{ + "type": "CITATION", + "metadata": { + "type": 'danger', 'info' ou 'normal' + } +} diff --git a/Projet/projet.sql b/Projet/projet.sql index a847d56..dabf43a 100644 --- a/Projet/projet.sql +++ b/Projet/projet.sql @@ -1,3 +1,6 @@ +CREATE DATABASE IF NOT EXISTS projet; +USE projet; + DROP TABLE IF EXISTS bloc; DROP TABLE IF EXISTS partage; DROP TABLE IF EXISTS page; @@ -18,19 +21,21 @@ CREATE TABLE page ( date_modification DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, auteur_id INT NOT NULL, droits ENUM('LECTURE', 'ECRITURE', 'ADMIN') NOT NULL, - FOREIGN KEY (auteur_id) REFERENCES utilisateur(id) ON DELETE CASCADE + page_parent_id INT DEFAULT NULL, + FOREIGN KEY (auteur_id) REFERENCES utilisateur(id) ON DELETE CASCADE, + FOREIGN KEY (page_parent_id) REFERENCES page(id) ON DELETE SET NULL ); CREATE TABLE bloc ( id INT PRIMARY KEY AUTO_INCREMENT, - type ENUM('TEXTE', 'LISTE', 'TITRE', 'CODE', 'PAGE') NOT NULL DEFAULT 'TEXTE', + type ENUM('TEXTE', 'LISTE', 'TITRE', 'CODE', 'PAGE', 'SEPARATEUR', 'CITATION') NOT NULL DEFAULT 'TEXTE', contenu TEXT, date_creation DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, date_modification DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, page_id INT NOT NULL, ordre INT NOT NULL, auteur_id INT NOT NULL, - metadata JSON NOT NULL DEFAULT '{}', + metadata JSON NOT NULL, FOREIGN KEY (page_id) REFERENCES page(id) ON DELETE CASCADE, FOREIGN KEY (auteur_id) REFERENCES utilisateur(id) ON DELETE CASCADE ); diff --git a/Projet/src/main/java/projet/Bloc.java b/Projet/src/main/java/projet/Bloc.java index 8410a51..fe0db78 100644 --- a/Projet/src/main/java/projet/Bloc.java +++ b/Projet/src/main/java/projet/Bloc.java @@ -23,7 +23,9 @@ public class Bloc extends ParamBD { LISTE, TITRE, CODE, - PAGE + PAGE, + SEPARATEUR, + CITATION } public Bloc() { diff --git a/Projet/src/main/java/projet/BlocRenderer.java b/Projet/src/main/java/projet/BlocRenderer.java new file mode 100644 index 0000000..49e2dd2 --- /dev/null +++ b/Projet/src/main/java/projet/BlocRenderer.java @@ -0,0 +1,34 @@ +package projet; + +public interface BlocRenderer { + + String renderTexte(String contenu); + String renderListe(String contenu); + String renderTitre(String contenu); + String renderCode(String contenu); + String renderPage(String contenu); + String renderSeparateur(); + String renderCitation(String contenu); + + default String render(Bloc bloc) { + switch (bloc.getType()) { + case TEXTE: + return renderTexte(bloc.getContenu()); + case LISTE: + return renderListe(bloc.getContenu()); + case TITRE: + return renderTitre(bloc.getContenu()); + case CODE: + return renderCode(bloc.getContenu()); + case PAGE: + return renderPage(bloc.getContenu()); + case SEPARATEUR: + return renderSeparateur(); + case CITATION: + return renderCitation(bloc.getContenu()); + default: + throw new IllegalArgumentException("Type de bloc inconnu : " + bloc.getType()); + } + } +} + diff --git a/Projet/src/main/java/projet/NouvellePageDirect.java b/Projet/src/main/java/projet/NouvellePageDirect.java new file mode 100644 index 0000000..36aa179 --- /dev/null +++ b/Projet/src/main/java/projet/NouvellePageDirect.java @@ -0,0 +1,60 @@ +package projet; + +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpSession; + +import java.io.IOException; +import java.time.LocalDate; + +@WebServlet("/NouvellePageDirect") +public class NouvellePageDirect extends HttpServlet { + private static final long serialVersionUID = 1L; + + public NouvellePageDirect() { + super(); + } + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + HttpSession session = request.getSession(); + Utilisateur u = (Utilisateur) session.getAttribute("utilisateur"); + + if(u != null) { + response.sendRedirect("AfficherPage"); + }else { + response.sendRedirect("/Projet/"); + } + } + + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + HttpSession session = request.getSession(); + Utilisateur u = (Utilisateur) session.getAttribute("utilisateur"); + + response.setContentType("application/json"); + response.setCharacterEncoding("UTF-8"); + + if(u != null) { + request.setCharacterEncoding("UTF-8"); + + String titre = request.getParameter("titre"); + String pageIdStr = request.getParameter("pageId"); + + if (titre == null || titre.trim().isEmpty()) { + response.getWriter().write("{\"error\": \"Titre vide\"}"); + } else { + int pageId = Integer.parseInt(pageIdStr); + int id = Page.ajouterPage(u.getId(), titre, LocalDate.now(), pageId); + if (id != -1) { + response.getWriter().write("{\"id\": " + id + "," + "\"pageId\": " + pageId + "}"); + } else { + response.getWriter().write("{\"error\": \"Erreur de création\"}"); + } + } + } else { + response.getWriter().write("{\"error\": \"Utilisateur non connecté\"}"); + } + } +} diff --git a/Projet/src/main/java/projet/Page.java b/Projet/src/main/java/projet/Page.java index d3edf9e..ba86754 100644 --- a/Projet/src/main/java/projet/Page.java +++ b/Projet/src/main/java/projet/Page.java @@ -144,6 +144,42 @@ public class Page extends ParamBD { return idGenere; } + protected static int ajouterPage(int idU, String t, LocalDate dl, int idParent) { + int idGenere = -1; + + try { + Connection connexion = DriverManager.getConnection(bdURL, bdLogin, bdPassword); + String sql = " INSERT INTO page(titre, date_creation, date_modification, auteur_id, droits, page_parent_id)" + + " VALUES (?, ?, ?, ?, ?, ?)" + + ";"; + PreparedStatement pst = connexion.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); + pst.setString(1, t); + pst.setDate(2, Date.valueOf(dl)); + pst.setDate(3, Date.valueOf(dl)); + pst.setInt(4, idU); + pst.setString(5, "ADMIN"); + pst.setInt(6, idParent); + pst.executeUpdate(); + + ResultSet rs = pst.getGeneratedKeys(); + if (rs.next()) { + idGenere = rs.getInt(1); + } + + rs.close(); + pst.close(); + connexion.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + + if (idGenere != -1) { + Bloc.ajouterBlocVide(idU, idGenere); + } + + return idGenere; + } + protected static Page getPageById(int idU, int id) { Page page = new Page(); String titre = null; diff --git a/Projet/src/main/webapp/WEB-INF/AfficherPage.jsp b/Projet/src/main/webapp/WEB-INF/AfficherPage.jsp index 9f08814..b760fab 100644 --- a/Projet/src/main/webapp/WEB-INF/AfficherPage.jsp +++ b/Projet/src/main/webapp/WEB-INF/AfficherPage.jsp @@ -7,71 +7,70 @@ -
- - -
- -
- - -
- - -
-

${page.titre}

- +
+ + +
+ +
+ + +
+ + +
+

${page.titre}

+ +
+
+ +
+
+
${bloc.contenu}
+
+
+ +
+
+
+
+
+ +

Pas encore de page choisie.

+
+
+
+ + +
+ +
-
- -
-
-
${bloc.contenu}
-
-
- -
-
-
-
- - -

Pas encore de page choisie.

-
- -
- - -
- -
-
diff --git a/Projet/src/main/webapp/WEB-INF/Footer.jsp b/Projet/src/main/webapp/WEB-INF/Footer.jsp index 4993f3a..19940eb 100644 --- a/Projet/src/main/webapp/WEB-INF/Footer.jsp +++ b/Projet/src/main/webapp/WEB-INF/Footer.jsp @@ -8,6 +8,6 @@ - + \ No newline at end of file diff --git a/Projet/src/main/webapp/WEB-INF/Header.jsp b/Projet/src/main/webapp/WEB-INF/Header.jsp index eb4c0d0..82cd7d3 100644 --- a/Projet/src/main/webapp/WEB-INF/Header.jsp +++ b/Projet/src/main/webapp/WEB-INF/Header.jsp @@ -8,6 +8,9 @@ +