From 0f497d215de8e16739263e2718bd39640a6cc4d8 Mon Sep 17 00:00:00 2001 From: polo Date: Thu, 8 May 2025 22:58:04 +0200 Subject: modif page, renommage et suppression, du responsive design, modif dans Director, notif toast --- public/css/foot.css | 39 +++++++++++++++++++++--------- public/css/main.css | 53 ++++++++++++++++++++++++++++++++--------- public/css/trombinoscope.css | 35 ++++++++++++++++++++++++--- public/js/main.js | 29 ++++++++++++++++++++++ src/controller/Director.php | 26 ++++++++++++-------- src/controller/ajax.php | 39 ++++++++++++++++++++++++++++-- src/controller/post.php | 34 ++++++++++++++++++++++---- src/model/Position.php | 4 ++-- src/model/entities/NodeData.php | 4 ++-- src/view/FooterBuilder.php | 28 +++++++++++++++------- src/view/MainBuilder.php | 26 +++++++++++++++++--- src/view/templates/footer.php | 3 ++- 12 files changed, 263 insertions(+), 57 deletions(-) diff --git a/public/css/foot.css b/public/css/foot.css index 038d33b..023a0f2 100644 --- a/public/css/foot.css +++ b/public/css/foot.css @@ -6,7 +6,7 @@ footer background-color: #B7E9FE; /*width: 1200px;*/ margin: auto; - padding: 0 20px; + /*padding: 0 20px;*/ } footer > div @@ -39,7 +39,7 @@ footer > div /*max-width: 45%;*/ /*margin-right: 10px;*/ /*margin: 16px 0;*/ /* = p */ - padding: 10px; + padding: 15px; list-style: none; /* retirer les puces */ font-size: small; text-align: right; @@ -69,6 +69,11 @@ footer > div margin: 0 3px; }*/ +.contact +{ + padding: 0 15px; +} + .footer_logo img { max-width: 288px; @@ -85,6 +90,7 @@ footer > div footer > div { flex-direction: column; + align-items: center; } } @@ -95,6 +101,17 @@ footer > div } /* zone admin */ +.admin_buttons_zone +{ + margin: 5px; + display: flex; + flex-wrap: wrap; + align-items: center; +} +.admin_buttons_zone p +{ + margin: 0; +} .logged_out { /*display: none;*/ @@ -107,23 +124,17 @@ footer > div } .empty_admin_zone { - height: 32px; + height: 70px; } .logged_in { - height: 32px; - width: 1200px; + /*height: 70px;*/ + width: 100%; margin: auto; background-color: #ffff00; position: fixed; bottom: 0px; } -.logged_in > p -{ - margin: 5px 0; - display: flex; - justify-content: center; -} .logged_in button { margin-left: 5px; @@ -132,6 +143,7 @@ footer > div border: lightgrey 2px outset; border-radius: 4px; background-color: white; + margin: 2px; } .logged_in button:hover { @@ -139,6 +151,11 @@ footer > div background-color: #ffff00; border-radius: 4px; } +.modif_mode +{ + background-color: #ffae1a; /* orange clair soupe de poisson */ +} + .toast { visibility: hidden; diff --git a/public/css/main.css b/public/css/main.css index 93a7bcf..870082a 100644 --- a/public/css/main.css +++ b/public/css/main.css @@ -11,15 +11,25 @@ section > h3 margin: 0; text-align: center; } -section > p /* boutons spéciaux mode admin */ -{ - /*margin-left: 15px;*/ -} .grid_columns { display: grid; grid-template-columns: repeat(3, 1fr); } +@media screen and (max-width: 800px) +{ + .grid_columns + { + grid-template-columns: repeat(2, 1fr); + } +} +@media screen and (max-width: 550px) +{ + .grid_columns + { + display: block; + } +} .galery_photos { display: flex; @@ -148,23 +158,35 @@ article a:hover flex-wrap: wrap; font-size: smaller; }*/ -.new_bloc +.edit_bloc_zone { background-color: white; padding: 10px; - margin: 10px 20px; - + margin: 10px 15px; + display: flex; + justify-content: space-evenly; + flex-wrap: wrap; } -.new_bloc p +.edit_bloc_zone p { margin: 5px; } +.new_bloc, .modify_bloc +{ + /*background-color: white; + padding: 10px; + margin: 10px 20px;*/ +} +.new_bloc p +{ + /*margin: 5px;*/ +} .new_bloc #bloc_title { - width: 100%; + width: 70%; max-width: 300px; } -.new_bloc form select, .new_bloc form input[type=submit] +.new_bloc form select, .new_bloc form input[type=submit], .modify_bloc form input[type=submit] { color: #ff1d04; font-size: medium; @@ -176,9 +198,18 @@ select:hover { cursor: pointer; } -.new_bloc form input[type=submit]:hover +.new_bloc form input[type=submit]:hover, .modify_bloc form input[type=submit]:hover { background-color: #ffff00; border-radius: 4px; cursor: pointer; +} +.modify_bloc > div +{ + display: flex; + align-items: baseline; +} +.modify_bloc img +{ + vertical-align: middle; } \ No newline at end of file diff --git a/public/css/trombinoscope.css b/public/css/trombinoscope.css index 357e6b0..cee2666 100644 --- a/public/css/trombinoscope.css +++ b/public/css/trombinoscope.css @@ -1,10 +1,39 @@ +/* css personnalissé à cette page, +.grid_columns utilise un nombre de colonnes spécifique */ article img { border-radius: 50%; } - .grid_columns { - /* écrase les 3 colonnes par défaut */ - grid-template-columns: repeat(4, 1fr); + grid-template-columns: repeat(4, 1fr); +} +@media screen and (max-width: 900px) +{ + .grid_columns + { + grid-template-columns: repeat(3, 1fr); + } +} +@media screen and (max-width: 650px) +{ + .grid_columns + { + grid-template-columns: repeat(2, 1fr); + } +} +@media screen and (max-width: 550px) +{ + .grid_columns + { + display: grid; + grid-template-columns: repeat(2, 1fr); + } +} +@media screen and (max-width: 350px) +{ + .grid_columns + { + display: block; + } } \ No newline at end of file diff --git a/public/js/main.js b/public/js/main.js index e278325..802bbbe 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -202,4 +202,33 @@ function findParent(element, tag_name){ element = element.parentElement; } return null; +} + + +/* -- mode Modification d'une page -- */ +function renamePageBloc(bloc_id){ + const input = document.getElementById("bloc_rename_" + bloc_id); + const title = document.getElementById(bloc_id).querySelector("h3"); + + fetch('index.php?bloc_edit=rename_page_bloc', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({bloc_title: input.value, bloc_id: bloc_id}) + }) + .then(response => response.json()) + .then(data => { + if(data.success){ + title.innerHTML = data.title; + console.log(data.title); + toastNotify('Le bloc a été renommé: ' + data.title); + } + else{ + console.error('Erreur au renommage du titre.'); + } + }) + .catch(error => { + console.error('Erreur:', error); + }); } \ No newline at end of file diff --git a/src/controller/Director.php b/src/controller/Director.php index 56a90cb..b154432 100644 --- a/src/controller/Director.php +++ b/src/controller/Director.php @@ -36,6 +36,7 @@ class Director return $this->article; } + // affichage d'une page ordinaire public function makeRootNode(string $id = ''): void { // on récupère toutes les entrées @@ -91,6 +92,12 @@ class Director } } + // le basique + public function findNodeById(int $id): void + { + $this->node = $this->entityManager->find('App\Entity\Node', $id); + } + // récupération d'un article pour modification public function makeArticleNode(string $id = '', bool $get_section = false): bool { @@ -112,7 +119,8 @@ class Director if($get_section){ $this->article = $bulk_data[0]; - $this->makeSectionNode($bulk_data[0]->getParent()->getId()); + $this->findNodeById($bulk_data[0]->getParent()->getId()); + $this->makeSectionNode(); } else{ $this->article = $bulk_data[0]; @@ -122,31 +130,30 @@ class Director } // récupération des articles d'un bloc
à la création d'un article - public function makeSectionNode(int $section_id): bool + public function makeSectionNode(): bool { - $section = $this->entityManager->find('App\Entity\Node', (string)$section_id); - $bulk_data = $this->entityManager ->createQuery('SELECT n FROM App\Entity\Node n WHERE n.parent = :parent') - ->setParameter('parent', $section) + ->setParameter('parent', $this->node) ->getResult(); foreach($bulk_data as $article){ - $section->addChild($article); // pas de flush, on ne va pas écrire dans la BDD à chaque nouvelle page + $this->node->addChild($article); // pas de flush, on ne va pas écrire dans la BDD à chaque nouvelle page } - $this->node = $section; return true; } - public function findNodeByName(string $name): void + public function findUniqueNodeByName(string $name): void // = unique en BDD, donc sans "page" associée { $bulk_data = $this->entityManager ->createQuery('SELECT n FROM App\Entity\Node n WHERE n.name_node = :name') ->setParameter('name', $name) ->getResult(); $this->node = $bulk_data[0]; - echo $this->page->getPageName() . ' '; + } + public function findItsChildren(): void + { $bulk_data = $this->entityManager ->createQuery('SELECT n FROM App\Entity\Node n WHERE n.parent = :parent AND n.page = :page') ->setParameter('parent', $this->node) @@ -154,7 +161,6 @@ class Director ->getResult(); foreach($bulk_data as $child){ $this->node->addChild($child); - echo $child->getName() . ' '; } } } diff --git a/src/controller/ajax.php b/src/controller/ajax.php index a20bd87..a6786d9 100644 --- a/src/controller/ajax.php +++ b/src/controller/ajax.php @@ -35,7 +35,8 @@ if($_SERVER['CONTENT_TYPE'] === 'application/json' && isset($_GET['action'])) if($id[0] === 'n') { $section_id = (int)substr($id, 1); // id du bloc
- $director->makeSectionNode($section_id); + $director->findNodeById($section_id); + $director->makeSectionNode(); $node = $director->getNode(); // =
if(is_array($content)){ @@ -205,6 +206,8 @@ if(strpos($_SERVER['CONTENT_TYPE'], 'multipart/form-data') !== false && isset($_ die; } + +/* -- page Menu et chemins -- */ if($_SERVER['CONTENT_TYPE'] === 'application/json' && isset($_GET['menu_edit'])) { // récupération des données @@ -347,7 +350,39 @@ if($_SERVER['CONTENT_TYPE'] === 'application/json' && isset($_GET['menu_edit'])) } } -// détection des requêtes de type XHR?, pas d'utilité pour l'instant + +/* -- mode Modification d'une page -- */ +if($_SERVER['CONTENT_TYPE'] === 'application/json' && isset($_GET['bloc_edit'])) +{ + // récupération des données + $data = file_get_contents('php://input'); + $json = json_decode($data, true); + + // renommage d'un bloc + if($_GET['bloc_edit'] === 'rename_page_bloc') + { + if(isset($json['bloc_title']) && $json['bloc_title'] !== null && isset($json['bloc_id']) && is_int($json['bloc_id'])){ + $director = new Director($entityManager); + $director->findNodeById($json['bloc_id']); + + // le titre (du JSON en BDD) est récupéré sous forme de tableau, modifié et renvoyé + $data = $director->getNode()->getNodeData()->getData(); + $data['title'] = htmlspecialchars($json['bloc_title']); + $director->getNode()->getNodeData()->setData($data); + + $entityManager->flush(); + echo json_encode(['success' => true, 'title' => $data['title']]); + } + else{ + echo json_encode(['success' => false]); + } + die; + } + +} + + +// détection des requêtes de type XHR?, pas d'utilité à priori /*elseif(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'){ echo "requête XHR reçue par le serveur"; die; diff --git a/src/controller/post.php b/src/controller/post.php index 76ac72b..d437423 100644 --- a/src/controller/post.php +++ b/src/controller/post.php @@ -15,10 +15,13 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) /* -- mode Modification d'une page -- */ // ajout d'un bloc dans une page - if(isset($_POST['bloc_title']) && isset($_POST['bloc_select'])){ + if(isset($_POST['bloc_title']) && $_POST['bloc_title'] !== null && isset($_POST['bloc_select']) && $_POST['bloc_select'] !== null + && isset($_POST['bloc_title_hidden']) && $_POST['bloc_title_hidden'] === '') // contrôle anti-robot avec input hidden + { $director = new Director($entityManager, true); // on a besoin de page_path qui dépend de menu_data $page = Director::$page_path->getLast(); - $director->findNodeByName('main'); + $director->findUniqueNodeByName('main'); + $director->findItsChildren(); $main = $director->getNode(); $position = count($main->getChildren()) + 1; // position dans la fraterie @@ -37,7 +40,30 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) $entityManager->flush(); header("Location: " . new URL(['page' => $_GET['page'], 'action' => 'modif_page'])); } + // suppression d'un bloc de page + elseif(isset($_POST['delete_bloc_id']) && $_POST['delete_bloc_id'] !== null + && isset($_POST['delete_bloc_hidden']) && $_POST['delete_bloc_hidden'] === '') // contrôle anti-robot avec input hidden + { + $director = new Director($entityManager, true); + $director->findUniqueNodeByName('main'); + $director->findItsChildren(); + //$director->findNodeById((int)$_POST['delete_bloc_id']); + $main = $director->getNode(); + $bloc; + foreach($main->getChildren() as $child){ + if($child->getId() === (int)$_POST['delete_bloc_id']){ + $bloc = $child; + break; + } + } + $main->removeChild($bloc); // réindex le tableau $children au passage + $main->reindexPositions(); + $entityManager->remove($bloc); // suppression en BDD + $entityManager->flush(); + header("Location: " . new URL(['page' => $_GET['page'], 'action' => 'modif_page'])); + } + /* -- page Menu et chemins -- */ @@ -60,7 +86,7 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) $parent = Director::$menu_data; } $parent->addChild($page); // true pour réindexer les positions en BDD - $parent->reindex(); + $parent->reindexPositions(); $entityManager->persist($page); $entityManager->flush(); @@ -76,7 +102,7 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) } $parent->removeChild($page); // suppression de $children avant de trier - $parent->reindex(); + $parent->reindexPositions(); $entityManager->remove($page); // suppression en BDD $entityManager->flush(); diff --git a/src/model/Position.php b/src/model/Position.php index b5040df..8035481 100644 --- a/src/model/Position.php +++ b/src/model/Position.php @@ -30,12 +30,12 @@ trait Position } if($reindexation){ - $this->reindex(); + $this->reindexPositions(); } } // nouvelles positions (tableau $children => BDD) - public function reindex(): void + public function reindexPositions(): void { $i = 1; foreach($this->children as $child){ diff --git a/src/model/entities/NodeData.php b/src/model/entities/NodeData.php index ddf6083..aaffb6a 100644 --- a/src/model/entities/NodeData.php +++ b/src/model/entities/NodeData.php @@ -47,11 +47,11 @@ class NodeData { return $this->data; } - /*public function setData(array $data): void + public function setData(array $data): void { $this->data = $data; } - public function setNode(Node $node): void + /*public function setNode(Node $node): void { $this->node = $node; }*/ diff --git a/src/view/FooterBuilder.php b/src/view/FooterBuilder.php index 8678f56..084e122 100644 --- a/src/view/FooterBuilder.php +++ b/src/view/FooterBuilder.php @@ -27,9 +27,19 @@ class FooterBuilder extends AbstractBuilder //$zone_admin = ''; if($_SESSION['admin']) { - $div_admin = 'logged_in'; $empty_admin_zone = 'empty_admin_zone'; - $link_edit_page = new URL(['page' => CURRENT_PAGE, 'action' => 'modif_page']); + if(MainBuilder::$modif_mode){ + $mode = 'modification de page'; + $div_admin = 'logged_in modif_mode'; + $link_edit_page = new URL(['page' => CURRENT_PAGE]); + $link_edit_label = 'Sortir du mode modification'; + } + else{ + $mode = 'administrateur'; + $div_admin = 'logged_in'; + $link_edit_page = new URL(['page' => CURRENT_PAGE, 'action' => 'modif_page']); + $link_edit_label = 'Modifier la page'; + } $link_new_page = new URL(['page' => 'nouvelle_page']); $link_change_paths = new URL(['page' => 'menu_chemins']); @@ -39,12 +49,14 @@ class FooterBuilder extends AbstractBuilder $link_logout = new URL(['page' => CURRENT_PAGE, 'action' => 'deconnexion']); isset($_GET['id']) ? $link_logout->addParams(['id' => $_GET['id']]) : ''; - $zone_admin = '

Vous êtes en mode administrateur.' . "\n" . - '' . "\n" . - '' . "\n" . - '' . "\n" . - '' . "\n" . - '

' . "\n"; + $zone_admin = '
+

Vous êtes en mode ' . $mode . ".

\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '
' . "\n"; } else { diff --git a/src/view/MainBuilder.php b/src/view/MainBuilder.php index fbdfbdd..4664c17 100644 --- a/src/view/MainBuilder.php +++ b/src/view/MainBuilder.php @@ -69,8 +69,9 @@ class MainBuilder extends AbstractBuilder ' . "\n";*/ // ajout d'un nouveau bloc - $this->html .= '
-

Ajouter un bloc dans la page:

+ $this->html .= '
+
+

Ajouter un bloc de page

@@ -78,11 +79,30 @@ class MainBuilder extends AbstractBuilder +

' . "\n"; + $this->html .= '
+

Modifier un bloc

'; foreach($node->getChildren() as $child_node){ - //$this->html .= + // renommage d'un bloc + $this->html .= '
+

+ + '. "\n"; + // déplacement d'un bloc + $this->html .= ' + ' . "\n"; + // suppression d'un bloc + $this->html .= '

+ + +

+
+
'. "\n"; } + $this->html .= "
+
\n"; } } diff --git a/src/view/templates/footer.php b/src/view/templates/footer.php index 52cb1b5..8f6d465 100644 --- a/src/view/templates/footer.php +++ b/src/view/templates/footer.php @@ -7,11 +7,12 @@

-
+
+ \ No newline at end of file -- cgit v1.2.3