summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpolo <ordipolo@gmx.fr>2025-04-22 00:39:54 +0200
committerpolo <ordipolo@gmx.fr>2025-04-22 00:39:54 +0200
commita3ba7dde60dc1c94b7170ec28266a966e5004d33 (patch)
tree279699afbf52270780dff8d1a4756efe217c15f6
parenteb3e1eb8c8365d3b3d1d39f24314ba420255afc2 (diff)
downloadcms-a3ba7dde60dc1c94b7170ec28266a966e5004d33.zip
page menu et chemin, partie 2
-rw-r--r--public/css/nav.css2
-rw-r--r--public/js/main.js57
-rw-r--r--src/controller/ajax.php34
-rw-r--r--src/model/Menu.php6
-rw-r--r--src/model/entities/Page.php14
-rw-r--r--src/view/MenuBuilder.php9
-rw-r--r--src/view/NavBuilder.php59
7 files changed, 98 insertions, 83 deletions
diff --git a/public/css/nav.css b/public/css/nav.css
index eb78e06..50bf4af 100644
--- a/public/css/nav.css
+++ b/public/css/nav.css
@@ -1,5 +1,5 @@
1/*-- menu principal --*/ 1/*-- menu principal --*/
2.empty_nav_zone 2#nav_zone
3{ 3{
4 height: 33px; 4 height: 33px;
5} 5}
diff --git a/public/js/main.js b/public/js/main.js
index fadcfa9..f74c670 100644
--- a/public/js/main.js
+++ b/public/js/main.js
@@ -204,6 +204,7 @@ function findParent(element, tag_name){
204 return null; 204 return null;
205} 205}
206 206
207
207/* page Menu et chemins */ 208/* page Menu et chemins */
208function moveOneLevelUp(){} 209function moveOneLevelUp(){}
209function moveOneLevelDown(){} 210function moveOneLevelDown(){}
@@ -250,7 +251,6 @@ function switchMenuPositions(page_id, direction)
250 console.error('Échec de l\'inversion'); 251 console.error('Échec de l\'inversion');
251 } 252 }
252 253
253 // remplacement du menu
254 nav_zone.innerHTML = ''; 254 nav_zone.innerHTML = '';
255 nav_zone.insertAdjacentHTML('afterbegin', data.nav); 255 nav_zone.insertAdjacentHTML('afterbegin', data.nav);
256 } 256 }
@@ -265,37 +265,34 @@ function switchMenuPositions(page_id, direction)
265} 265}
266 266
267function checkMenuEntry(page_id){ 267function checkMenuEntry(page_id){
268 const nav_zone = document.getElementById("nav_zone"); // parent de <nav>
268 const clicked_menu_entry = document.getElementById(page_id); // div parente du bouton 269 const clicked_menu_entry = document.getElementById(page_id); // div parente du bouton
269 const checkbox = clicked_menu_entry.querySelector("input"); 270 const checkbox = clicked_menu_entry.querySelector("input");
270
271 let color; 271 let color;
272 if(checkbox.checked){
273 color = "#ff1d04";
274 checked = true;
275 }
276 else{
277 color = "grey";
278 checked = false;
279 }
280 272
281 // contrôle check impossible si le parent le plus ancien est unchecked 273 fetch('index.php?menu_edit=displayInMenu', {
282 // 274 method: 'POST',
283 275 headers: {
284 // sur l'élément concerné 276 'Content-Type': 'application/json'
285 clicked_menu_entry.querySelector("button").style.color = color; 277 },
286 278 body: JSON.stringify({ id: clicked_menu_entry.id, checked: checkbox.checked })
287 // même chose sur les enfants 279 })
288 /*try{ 280 .then(response => response.json())
289 const level_markup = clicked_menu_entry.querySelector('.level'); 281 .then(data => {
290 //const other_buttons = .querySelectorAll("button"); 282 if(data.success)
291 level_markup.querySelectorAll("input").forEach(input => { 283 {
292 input.checked = checked; 284 color = checkbox.checked ? "#ff1d04" : "grey";
293 }); 285 clicked_menu_entry.querySelector("button").style.color = color;
294 level_markup.querySelectorAll("button").forEach(button => { 286
295 button.style.color = color; 287 nav_zone.innerHTML = '';
296 }); 288 nav_zone.insertAdjacentHTML('afterbegin', data.nav);
297 } 289 }
298 catch(error){ 290 else {
299 console.log("pas d'enfant"); 291
300 }*/ 292 console.error('Échec de l\'inversion');
293 }
294 })
295 .catch(error => {
296 console.error('Erreur:', error);
297 });
301} \ No newline at end of file 298} \ No newline at end of file
diff --git a/src/controller/ajax.php b/src/controller/ajax.php
index c774bf3..9d1cc42 100644
--- a/src/controller/ajax.php
+++ b/src/controller/ajax.php
@@ -209,12 +209,10 @@ if($_SERVER['CONTENT_TYPE'] === 'application/json' && isset($_GET['menu_edit']))
209 // récupération des données 209 // récupération des données
210 $data = file_get_contents('php://input'); 210 $data = file_get_contents('php://input');
211 $json = json_decode($data, true); 211 $json = json_decode($data, true);
212 Director::$menu_data = new Menu($entityManager);
212 213
213 if($_GET['menu_edit'] === 'switch_positions' && isset($json['id1']) && isset($json['id2'])) 214 if($_GET['menu_edit'] === 'switch_positions' && isset($json['id1']) && isset($json['id2']))
214 { 215 {
215 //$menu = new Menu($entityManager);
216 Director::$menu_data = new Menu($entityManager);
217
218 $id1 = $json['id1']; 216 $id1 = $json['id1'];
219 $id2 = $json['id2']; 217 $id2 = $json['id2'];
220 218
@@ -232,11 +230,9 @@ if($_SERVER['CONTENT_TYPE'] === 'application/json' && isset($_GET['menu_edit']))
232 Director::$menu_data->sortChildren(true); // modifie tableau children 230 Director::$menu_data->sortChildren(true); // modifie tableau children
233 $entityManager->flush(); 231 $entityManager->flush();
234 232
235 // menu utilisant les nouvelles données 233 // nouveau menu
236 //Director::$page_path = new Path(); 234 $nav_builder = new NavBuilder();
237 $nav_builder = new NavBuilder(); // builder appelé sans envoi du noeud correspondant 235 echo json_encode(['success' => true, 'nav' => $nav_builder->render()]);
238
239 echo json_encode(['success' => true, 'path1' => '', 'path2' => '', 'nav' => $nav_builder->render()]);
240 } 236 }
241 else{ 237 else{
242 echo json_encode(['success' => false]); 238 echo json_encode(['success' => false]);
@@ -244,9 +240,29 @@ if($_SERVER['CONTENT_TYPE'] === 'application/json' && isset($_GET['menu_edit']))
244 240
245 die; 241 die;
246 } 242 }
243
244 if($_GET['menu_edit'] === 'displayInMenu' && isset($json['id']) && isset($json['checked']))
245 {
246 $id = $json['id'];
247 $checked = $json['checked'];
248
249 $page = Director::$menu_data->findPageById((int)$id);
250 if($page->isHidden() === $checked){
251 $page->setHidden(!$checked);
252 $entityManager->flush();
253
254 // nouveau menu
255 $nav_builder = new NavBuilder();
256 echo json_encode(['success' => true, 'nav' => $nav_builder->render()]);
257 }
258 else{
259 echo json_encode(['success' => false]);
260 }
261 die;
262 }
247} 263}
248 264
249// détection des requêtes de type XHR, pas d'utilité pour l'instant 265// détection des requêtes de type XHR?, pas d'utilité pour l'instant
250/*elseif(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'){ 266/*elseif(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'){
251 echo "requête XHR reçue par le serveur"; 267 echo "requête XHR reçue par le serveur";
252 die; 268 die;
diff --git a/src/model/Menu.php b/src/model/Menu.php
index 403accf..10cf3d5 100644
--- a/src/model/Menu.php
+++ b/src/model/Menu.php
@@ -38,12 +38,6 @@ class Menu extends Page
38 foreach($this->getChildren() as $page){ 38 foreach($this->getChildren() as $page){
39 $page->fillChildrenPagePath(); 39 $page->fillChildrenPagePath();
40 } 40 }
41
42 /*for($i = 0; $i < count($this->getChildren()[1]->getChildren()); $i++){
43 echo $this->getChildren()[1]->getChildren()[$i]->getEndOfPath() . ' - ';
44 echo $this->getChildren()[1]->getChildren()[$i]->getPageName() . '<br>';
45 }*/
46 //die;
47 } 41 }
48 42
49 public function getOtherPages(): array 43 public function getOtherPages(): array
diff --git a/src/model/entities/Page.php b/src/model/entities/Page.php
index c30305c..e3e60ca 100644
--- a/src/model/entities/Page.php
+++ b/src/model/entities/Page.php
@@ -34,6 +34,9 @@ class Page
34 #[ORM\Column(type: "boolean")] 34 #[ORM\Column(type: "boolean")]
35 private bool $in_menu; 35 private bool $in_menu;
36 36
37 #[ORM\Column(type: "boolean")]
38 private bool $hidden;
39
37 #[ORM\Column(type: "integer", nullable: true)] // null si hors menu 40 #[ORM\Column(type: "integer", nullable: true)] // null si hors menu
38 private ?int $position; 41 private ?int $position;
39 42
@@ -47,12 +50,13 @@ class Page
47 /*#[ORM\Column(type: "json", nullable: true)] 50 /*#[ORM\Column(type: "json", nullable: true)]
48 private ?array $metadata = null;*/ 51 private ?array $metadata = null;*/
49 52
50 public function __construct(string $name, string $eop, bool $reachable, bool $in_menu, ?int $position, ?Page $parent) 53 public function __construct(string $name, string $eop, bool $reachable, bool $in_menu, bool $hidden, ?int $position, ?Page $parent)
51 { 54 {
52 $this->name_page = $name; 55 $this->name_page = $name;
53 $this->end_of_path = $eop; 56 $this->end_of_path = $eop;
54 $this->reachable = $reachable; 57 $this->reachable = $reachable;
55 $this->in_menu = $in_menu; 58 $this->in_menu = $in_menu;
59 $this->hidden = $hidden;
56 $this->position = $position; 60 $this->position = $position;
57 $this->parent = $parent; 61 $this->parent = $parent;
58 $this->children = new ArrayCollection(); 62 $this->children = new ArrayCollection();
@@ -83,6 +87,14 @@ class Page
83 { 87 {
84 return $this->in_menu; 88 return $this->in_menu;
85 } 89 }
90 public function isHidden(): bool
91 {
92 return $this->hidden;
93 }
94 public function setHidden(bool $hidden): void
95 {
96 $this->hidden = $hidden;
97 }
86 public function getPosition(): ?int 98 public function getPosition(): ?int
87 { 99 {
88 return $this->position; 100 return $this->position;
diff --git a/src/view/MenuBuilder.php b/src/view/MenuBuilder.php
index 0fcfbe5..5a010d5 100644
--- a/src/view/MenuBuilder.php
+++ b/src/view/MenuBuilder.php
@@ -22,8 +22,6 @@ class MenuBuilder extends AbstractBuilder
22 extract($node->getNodeData()->getData()); 22 extract($node->getNodeData()->getData());
23 }*/ 23 }*/
24 24
25 // ajouter un article
26 $new_article = '';
27 if($_SESSION['admin']) 25 if($_SESSION['admin'])
28 { 26 {
29 $this->unfoldMenu(Director::$menu_data, 0 - $this->margin_left_multiplier); 27 $this->unfoldMenu(Director::$menu_data, 0 - $this->margin_left_multiplier);
@@ -47,7 +45,7 @@ class MenuBuilder extends AbstractBuilder
47 foreach($menu->getChildren() as $entry) 45 foreach($menu->getChildren() as $entry)
48 { 46 {
49 $div_style = 'margin-left: ' . $margin_left . 'px;'; 47 $div_style = 'margin-left: ' . $margin_left . 'px;';
50 $checked = $entry->IsInMenu() ? 'checked' : ''; 48 $checked = $entry->isHidden() ? '' : 'checked';
51 $this->html .= '<div id="' . $entry->getId() . '" style="' . $div_style . '"> 49 $this->html .= '<div id="' . $entry->getId() . '" style="' . $div_style . '">
52 <img class="move_entry_icon" onclick="" src="assets/arrow-left.svg"> 50 <img class="move_entry_icon" onclick="" src="assets/arrow-left.svg">
53 <img class="move_entry_icon" onclick="" src="assets/arrow-right.svg"> 51 <img class="move_entry_icon" onclick="" src="assets/arrow-right.svg">
@@ -67,14 +65,9 @@ class MenuBuilder extends AbstractBuilder
67 $this->html .= '<i>' . $entry->getPagePath() . '</i>'; 65 $this->html .= '<i>' . $entry->getPagePath() . '</i>';
68 } 66 }
69 67
70
71 // supprimer me label "visible" et griser le texte et bouton en JS à la place
72
73 /* 68 /*
74 => flèche gauche: position = position du parent + 1, parent = grand-parent, recalculer les positions 69 => flèche gauche: position = position du parent + 1, parent = grand-parent, recalculer les positions
75 => flèche droite: position = nombre d'éléments de la fraterie + 1, l'élément précédent devient le parent 70 => flèche droite: position = nombre d'éléments de la fraterie + 1, l'élément précédent devient le parent
76 => flèches haut et bas: inversement de position, comme pour les noeuds, mais dans la table page
77 => checkbox: in_menu ^= 1
78 */ 71 */
79 72
80 if(count($entry->getChildren()) > 0){ 73 if(count($entry->getChildren()) > 0){
diff --git a/src/view/NavBuilder.php b/src/view/NavBuilder.php
index 2718569..f4fb651 100644
--- a/src/view/NavBuilder.php
+++ b/src/view/NavBuilder.php
@@ -27,41 +27,44 @@ class NavBuilder extends AbstractBuilder
27 27
28 foreach($nav_data->getChildren() as $data) 28 foreach($nav_data->getChildren() as $data)
29 { 29 {
30 $li_class = ''; 30 if(!$data->isHidden()){
31 if(isset($current[$level]) && $data->getEndOfPath() === $current[$level]->getEndOfPath()){ 31 $li_class = '';
32 $li_class = 'current '; 32 if(isset($current[$level]) && $data->getEndOfPath() === $current[$level]->getEndOfPath()){
33 } 33 $li_class = 'current ';
34 }
34 35
35 $link = ''; 36 $link = '';
36 if($data->isReachable()) 37 if($data->isReachable()) // titre de catégorie du menu non clicable
37 {
38 if(str_starts_with($data->getEndOfPath(), 'http')) // lien vers autre site
39 { 38 {
40 $link .= '<a href="' . $data->getEndOfPath() . '" target="_blank">'; 39 if(str_starts_with($data->getEndOfPath(), 'http')) // lien vers autre site
40 {
41 $link .= '<a href="' . $data->getEndOfPath() . '" target="_blank">';
42 }
43 elseif($data->getEndOfPath() != '') // lien relatif
44 {
45 $link .= '<a href="' . new URL(['page' => $data->getPagePath()]) . '">';
46 }
47 }
48 else{
49 $link .= '<a>';
41 } 50 }
42 elseif($data->getEndOfPath() != '') // lien relatif 51
52 if(count($data->getChildren()) > 0) // titre de catégorie
43 { 53 {
44 $link .= '<a href="' . new URL(['page' => $data->getPagePath()]) . '">'; 54 $li_class .= $data->getParent() == null ? 'drop-down' : 'drop-right';
55
56 $nav_html .= '<li class="'. $li_class . '">' . $link . '<p>' . $data->getPageName() . '</p></a><ul class="sub-menu">' . "\n";
57 $level++;
58 $nav_html .= $this->navMainHTML($data, $current);
59 $level--;
60 $nav_html .= '</ul></li>' . "\n";
61 }
62 else
63 {
64 $nav_html .= '<li class="'. $li_class . '">' . $link . '<p>' . $data->getPageName() . '</p></a></li>' . "\n";
45 } 65 }
46 }
47 else{
48 $link .= '<a>';
49 } 66 }
50 67
51 if(count($data->getChildren()) > 0) // titre de catégorie
52 {
53 $li_class .= $data->getParent() == null ? 'drop-down' : 'drop-right';
54
55 $nav_html .= '<li class="'. $li_class . '">' . $link . '<p>' . $data->getPageName() . '</p></a><ul class="sub-menu">' . "\n";
56 $level++;
57 $nav_html .= $this->navMainHTML($data, $current);
58 $level--;
59 $nav_html .= '</ul></li>' . "\n";
60 }
61 else
62 {
63 $nav_html .= '<li class="'. $li_class . '">' . $link . '<p>' . $data->getPageName() . '</p></a></li>' . "\n";
64 }
65 } 68 }
66 return $nav_html; 69 return $nav_html;
67 } 70 }