Compare commits
2 Commits
a43d745b8f
...
406e69e5f4
| Author | SHA1 | Date |
|---|---|---|
|
|
406e69e5f4 | |
|
|
6e64f44629 |
|
|
@ -13,5 +13,6 @@
|
|||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
|
||||
<classpathentry excluding="main/java/" kind="src" path="src"/>
|
||||
<classpathentry kind="output" path="build/classes"/>
|
||||
</classpath>
|
||||
|
|
|
|||
|
|
@ -28,4 +28,15 @@
|
|||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
|
||||
</natures>
|
||||
<filteredResources>
|
||||
<filter>
|
||||
<id>1745735846816</id>
|
||||
<name></name>
|
||||
<type>30</type>
|
||||
<matcher>
|
||||
<id>org.eclipse.core.resources.regexFilterMatcher</id>
|
||||
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
|
||||
</matcher>
|
||||
</filter>
|
||||
</filteredResources>
|
||||
</projectDescription>
|
||||
|
|
|
|||
|
|
@ -8,8 +8,6 @@ import java.sql.ResultSet;
|
|||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.time.LocalDate;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Bloc extends ParamBD {
|
||||
private int id;
|
||||
|
|
@ -18,7 +16,7 @@ public class Bloc extends ParamBD {
|
|||
private LocalDate dateCreation;
|
||||
private LocalDate dateModification;
|
||||
private int ordre;
|
||||
private Map<String, Object> metadata;
|
||||
private String metadata;
|
||||
|
||||
public enum Type {
|
||||
TEXTE,
|
||||
|
|
@ -32,14 +30,14 @@ 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, String metadata) {
|
||||
this.id = id;
|
||||
this.type = type;
|
||||
this.contenu = contenu;
|
||||
this.ordre = ordre;
|
||||
this.dateCreation = LocalDate.now();
|
||||
this.dateModification = LocalDate.now();
|
||||
metadata = new HashMap<>();
|
||||
this.metadata = metadata;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
|
|
@ -90,11 +88,11 @@ public class Bloc extends ParamBD {
|
|||
this.ordre = ordre;
|
||||
}
|
||||
|
||||
public Map<String, Object> getMetadata() {
|
||||
public String getMetadata() {
|
||||
return metadata;
|
||||
}
|
||||
|
||||
public void setMetadata(Map<String, Object> metadata) {
|
||||
public void setMetadata(String metadata) {
|
||||
this.metadata = metadata;
|
||||
}
|
||||
|
||||
|
|
@ -102,7 +100,7 @@ public class Bloc extends ParamBD {
|
|||
return "Bloc{id=" + id + ", type=" + type + ", contenu='" + contenu + "', dateCreation=" + dateCreation + ", dateModification=" + dateModification + ", ordre=" + ordre + "}";
|
||||
}
|
||||
|
||||
protected static int 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, String metadata) {
|
||||
int idGenere = -1 ;
|
||||
try {
|
||||
Connection connexion = DriverManager.getConnection(bdURL, bdLogin, bdPassword);
|
||||
|
|
@ -117,7 +115,7 @@ public class Bloc extends ParamBD {
|
|||
pst.setInt(5, idP);
|
||||
pst.setInt(6, ordre);
|
||||
pst.setInt(7, idU);
|
||||
pst.setString(8, metadata.toString());
|
||||
pst.setString(8, metadata);
|
||||
pst.executeUpdate();
|
||||
|
||||
ResultSet rs = pst.getGeneratedKeys();
|
||||
|
|
|
|||
|
|
@ -9,8 +9,6 @@ import jakarta.servlet.http.HttpSession;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDate;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@WebServlet("/NouveauBloc")
|
||||
public class NouveauBloc extends HttpServlet {
|
||||
|
|
@ -42,13 +40,12 @@ public class NouveauBloc extends HttpServlet {
|
|||
String typeStr = request.getParameter("type");
|
||||
String ordreStr = request.getParameter("ordre");
|
||||
String pageIdStr = request.getParameter("pageId");
|
||||
|
||||
String metadata = request.getParameter("metadata");
|
||||
|
||||
|
||||
int ordre = Integer.parseInt(ordreStr);
|
||||
int pageId = Integer.parseInt(pageIdStr);
|
||||
Bloc.Type type = Bloc.Type.valueOf(typeStr);
|
||||
Map<String, Object> metadata = new HashMap<>();
|
||||
|
||||
int idGenere = Bloc.ajouterBloc(u.getId(), pageId, contenu, ordre, type, LocalDate.now(), metadata);
|
||||
response.setContentType("application/json");
|
||||
|
|
@ -59,5 +56,4 @@ public class NouveauBloc extends HttpServlet {
|
|||
response.sendRedirect("/Projet/");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ public class NouvellePage extends HttpServlet {
|
|||
|
||||
String titre = request.getParameter("titre");
|
||||
|
||||
if (titre == null || titre.isEmpty()) {
|
||||
if (titre == null || titre.trim().isEmpty()) {
|
||||
response.sendRedirect("AfficherPage");
|
||||
} else {
|
||||
int id = Page.ajouterPage(u.getId(), titre, LocalDate.now());
|
||||
|
|
|
|||
|
|
@ -172,7 +172,7 @@ public class Page extends ParamBD {
|
|||
page.id = id;
|
||||
}
|
||||
if(titre != null) {
|
||||
sql = " SELECT id, contenu, type, ordre"
|
||||
sql = " SELECT id, contenu, type, ordre, metadata"
|
||||
+ " FROM bloc"
|
||||
+ " WHERE page_id=?"
|
||||
+ " ORDER BY ordre"
|
||||
|
|
@ -185,10 +185,11 @@ public class Page extends ParamBD {
|
|||
int idB = rs.getInt("id");
|
||||
String contenu = rs.getString("contenu");
|
||||
String type = rs.getString("type");
|
||||
String metadata = rs.getString("metadata");
|
||||
Type typeEnum = Type.valueOf(type.toUpperCase());
|
||||
int ordre = rs.getInt("ordre");
|
||||
|
||||
Bloc bloc = new Bloc(idB, typeEnum, contenu, ordre);
|
||||
Bloc bloc = new Bloc(idB, typeEnum, contenu, ordre, metadata);
|
||||
page.listeBlocs.add(bloc);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package projet;
|
||||
|
||||
import jakarta.servlet.RequestDispatcher;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.annotation.WebServlet;
|
||||
import jakarta.servlet.http.HttpServlet;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package projet;
|
||||
|
||||
import jakarta.servlet.RequestDispatcher;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.annotation.WebServlet;
|
||||
import jakarta.servlet.http.HttpServlet;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
|
||||
|
||||
// focus sur le dernier textarea quand la page s'ouvre
|
||||
window.addEventListener('DOMContentLoaded', () => {
|
||||
const blocs = document.querySelectorAll('#md [contenteditable="true"]');
|
||||
if (blocs.length > 0) {
|
||||
|
|
@ -33,7 +31,7 @@
|
|||
ajouterBlocVideSiBesoin();
|
||||
});
|
||||
|
||||
// Fonction pour ajouter un nouvel événement à chaque textarea
|
||||
// Fonction pour ajouter un nouvel événement à chaque bloc
|
||||
function addBlocEvent(bloc) {
|
||||
|
||||
bloc.addEventListener('keydown', function(event) {
|
||||
|
|
@ -47,48 +45,48 @@
|
|||
if (texte.startsWith("/")) {
|
||||
// Gérer les commandes
|
||||
handleSlashCommand(currentBloc, texte);
|
||||
} else {
|
||||
const blocId = currentBloc.getAttribute('data-id'); // Récupère l'ID du bloc
|
||||
const type = currentBloc.getAttribute('data-type');
|
||||
const metadata = currentBloc.getAttribute('metadata');
|
||||
const params = new URLSearchParams();
|
||||
|
||||
let contenuTexte = currentBloc.innerHTML
|
||||
.replace(/<br\s*\/?>/gi, '\n') // Remplace les <br> par \n
|
||||
.replace(/<b>/gi, '**') // Remplace <b> par **
|
||||
.replace(/<\/b>/gi, '**') // Remplace </b> par **
|
||||
.replace(/<i>/gi, '*') // Remplace <i> par *
|
||||
.replace(/<\/i>/gi, '*'); // Remplace </i> par *
|
||||
params.append("contenu", contenuTexte);
|
||||
params.append("blocId", blocId);
|
||||
params.append("metadata", metadata);
|
||||
params.append("type", type);
|
||||
|
||||
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.");
|
||||
}
|
||||
});
|
||||
|
||||
ajouterBlocVideSiBesoin();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const blocId = currentBloc.getAttribute('data-id'); // Récupère l'ID du bloc
|
||||
const type = currentBloc.getAttribute('data-type');
|
||||
const metadata = currentBloc.getAttribute('metadata');
|
||||
const params = new URLSearchParams();
|
||||
|
||||
let contenuTexte = currentBloc.innerHTML
|
||||
.replace(/<br\s*\/?>/gi, '\n') // Remplace les <br> par \n
|
||||
.replace(/<b>/gi, '**') // Remplace <b> par **
|
||||
.replace(/<\/b>/gi, '**') // Remplace </b> par **
|
||||
.replace(/<i>/gi, '*') // Remplace <i> par *
|
||||
.replace(/<\/i>/gi, '*'); // Remplace </i> par *
|
||||
params.append("contenu", contenuTexte);
|
||||
params.append("blocId", blocId);
|
||||
params.append("metadata", metadata);
|
||||
params.append("type", type);
|
||||
|
||||
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.");
|
||||
}
|
||||
});
|
||||
|
||||
ajouterBlocVideSiBesoin();
|
||||
}
|
||||
});
|
||||
|
||||
bloc.addEventListener('input', function () {
|
||||
bloc.addEventListener('input', function () {
|
||||
autoResize(bloc);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function autoResize(textarea) {
|
||||
textarea.style.height = 'auto';
|
||||
textarea.style.height = textarea.scrollHeight + 'px';
|
||||
function autoResize(bloc) {
|
||||
bloc.style.height = 'auto';
|
||||
bloc.style.height = bloc.scrollHeight + 'px';
|
||||
}
|
||||
|
||||
document.querySelectorAll('#md [contenteditable="true"]').forEach(bloc => {
|
||||
|
|
@ -137,7 +135,7 @@
|
|||
newBloc.setAttribute('rows', '1');
|
||||
newBloc.setAttribute('data-type', 'TEXTE');
|
||||
newBloc.setAttribute('data-id', idGenere);
|
||||
newBloc.setAttribute('metadata', 'TEXTE');
|
||||
newBloc.setAttribute('metadata', '{}');
|
||||
|
||||
control.appendChild(newBloc);
|
||||
container.appendChild(control);
|
||||
|
|
@ -179,7 +177,7 @@
|
|||
const bloc = blocContainer.querySelector('[contenteditable="true"]');
|
||||
|
||||
if (bloc.innerText.trim() === "") {
|
||||
return; // Empêche la suppression si le textarea est vide
|
||||
return; // Empêche la suppression si le bloc est vide
|
||||
}
|
||||
|
||||
if (confirm("Voulez-vous vraiment supprimer ce bloc ?")) {
|
||||
|
|
@ -285,13 +283,15 @@
|
|||
bloc.addEventListener('input', (event) => {
|
||||
const blocId = event.target.getAttribute('data-id');
|
||||
const content = event.target.textContent; // Récupère le contenu modifié du bloc
|
||||
const type = event.target.getAttribute('data-type');
|
||||
const metadata = event.target.getAttribute('metadata'); // Récupère le metadata du bloc
|
||||
|
||||
const modif = {
|
||||
action: "update",
|
||||
blocId: blocId,
|
||||
content: content,
|
||||
metadata: metadata
|
||||
metadata: metadata,
|
||||
type: type
|
||||
};
|
||||
|
||||
socketBloc.send(JSON.stringify(modif)); // Envoi de la modification via le WebSocket
|
||||
|
|
@ -360,7 +360,6 @@
|
|||
// Nettoyage des anciennes classes
|
||||
bloc.classList.remove('is-title', 'is-title-1', 'is-title-2', 'is-title-3');
|
||||
bloc.classList.remove('is-code-block', 'is-list', 'is-toggle');
|
||||
bloc.setAttribute('placeholder', 'Tapez ici...');
|
||||
bloc.style.whiteSpace = "normal"; // reset si code
|
||||
|
||||
const type = bloc.dataset.type || 'TEXTE';
|
||||
|
|
@ -371,31 +370,26 @@
|
|||
break;
|
||||
|
||||
case 'TITRE':
|
||||
const level = bloc.dataset.level || '2';
|
||||
const level = bloc.dataset.level || '1';
|
||||
bloc.classList.add('is-title', `is-title-${level}`);
|
||||
bloc.setAttribute('placeholder', `Titre niveau ${level}`);
|
||||
break;
|
||||
|
||||
case 'LISTE':
|
||||
bloc.classList.add('is-list');
|
||||
bloc.setAttribute('placeholder', '• Élément de liste');
|
||||
break;
|
||||
|
||||
case 'CODE':
|
||||
bloc.classList.add('is-code-block');
|
||||
bloc.style.whiteSpace = "pre";
|
||||
const lang = bloc.dataset.language || 'plaintext';
|
||||
bloc.setAttribute('placeholder', `Code (${lang})`);
|
||||
bloc.dataset.language || 'plaintext';
|
||||
break;
|
||||
|
||||
case 'PAGE':
|
||||
bloc.classList.add('is-page-block');
|
||||
bloc.setAttribute('placeholder', 'Nouvelle page...');
|
||||
break;
|
||||
|
||||
case 'TOGGLE':
|
||||
bloc.classList.add('is-toggle');
|
||||
bloc.setAttribute('placeholder', 'Cliquez pour développer...');
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
@ -421,7 +415,7 @@
|
|||
case "h2":
|
||||
case "h3":
|
||||
applyBlocType(bloc, "TITRE", { level: parseInt(command[1] || "1") });
|
||||
bloc.textContent = ''; // On vide le bloc après transformation
|
||||
bloc.textContent = param; // On vide le bloc après transformation
|
||||
autoResize(bloc);
|
||||
break;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue