diff options
| -rw-r--r-- | public/css/modif_page.css | 20 | ||||
| -rw-r--r-- | public/js/modif_page.js | 29 | ||||
| -rw-r--r-- | src/controller/PageManagementController.php | 37 | ||||
| -rw-r--r-- | src/model/entities/Node.php | 2 | ||||
| -rw-r--r-- | src/model/entities/NodeData.php | 20 | ||||
| -rw-r--r-- | src/router.php | 3 | ||||
| -rw-r--r-- | src/view/MainBuilder.php | 5 | ||||
| -rw-r--r-- | src/view/templates/modify_block.php | 23 | ||||
| -rw-r--r-- | src/view/templates/modify_page.php | 5 |
9 files changed, 121 insertions, 23 deletions
diff --git a/public/css/modif_page.css b/public/css/modif_page.css index 8095766..4e38f1b 100644 --- a/public/css/modif_page.css +++ b/public/css/modif_page.css | |||
| @@ -53,16 +53,20 @@ | |||
| 53 | justify-content: space-evenly; | 53 | justify-content: space-evenly; |
| 54 | flex-wrap: wrap; | 54 | flex-wrap: wrap; |
| 55 | } | 55 | } |
| 56 | .edit_page_zone p, .edit_block_zone p, .edit_page_zone form | 56 | .new_block |
| 57 | { | 57 | { |
| 58 | margin: 5px; | 58 | max-width: 300px; |
| 59 | } | 59 | } |
| 60 | |||
| 61 | .new_block #bloc_title | 60 | .new_block #bloc_title |
| 62 | { | 61 | { |
| 63 | width: 70%; | 62 | width: 70%; |
| 64 | max-width: 300px; | 63 | max-width: 300px; |
| 65 | } | 64 | } |
| 65 | .explanations | ||
| 66 | { | ||
| 67 | font-style: italic; | ||
| 68 | font-size: smaller; | ||
| 69 | } | ||
| 66 | 70 | ||
| 67 | .modify_block img | 71 | .modify_block img |
| 68 | { | 72 | { |
| @@ -76,17 +80,21 @@ | |||
| 76 | { | 80 | { |
| 77 | background-color: white; | 81 | background-color: white; |
| 78 | margin: 8px 0; | 82 | margin: 8px 0; |
| 79 | padding: 5px; | ||
| 80 | } | 83 | } |
| 81 | .modify_one_block > * | 84 | .modify_one_block p |
| 82 | { | 85 | { |
| 83 | /*text-wrap: nowrap;*/ | 86 | margin: 0px; |
| 84 | } | 87 | } |
| 85 | .modify_one_block > div | 88 | .modify_one_block > div |
| 86 | { | 89 | { |
| 90 | padding: 4px; | ||
| 87 | display: flex; | 91 | display: flex; |
| 88 | align-items: center; | 92 | align-items: center; |
| 89 | } | 93 | } |
| 94 | .modify_one_block > div > * | ||
| 95 | { | ||
| 96 | margin: 4px; | ||
| 97 | } | ||
| 90 | .block_options | 98 | .block_options |
| 91 | { | 99 | { |
| 92 | flex-wrap: wrap; | 100 | flex-wrap: wrap; |
diff --git a/public/js/modif_page.js b/public/js/modif_page.js index ee2004b..bf269ee 100644 --- a/public/js/modif_page.js +++ b/public/js/modif_page.js | |||
| @@ -176,6 +176,35 @@ function switchBlocsPositions(bloc_id, direction) { | |||
| 176 | }); | 176 | }); |
| 177 | } | 177 | } |
| 178 | 178 | ||
| 179 | function articlesOrderSelect(bloc_id){ | ||
| 180 | const articles_order_select = document.getElementById('articles_order_select_' + bloc_id).value; | ||
| 181 | |||
| 182 | fetch('index.php?bloc_edit=change_articles_order', { | ||
| 183 | method: 'POST', | ||
| 184 | headers: { 'Content-Type': 'application/json' }, | ||
| 185 | body: JSON.stringify({ id: bloc_id, chrono_order: articles_order_select }) | ||
| 186 | }) | ||
| 187 | .then(response => response.json()) | ||
| 188 | .then(data => { | ||
| 189 | if(data.success){ | ||
| 190 | // inverser l'ordre des articles!! | ||
| 191 | const parent = document.getElementById(bloc_id).querySelector(".section_child"); | ||
| 192 | const articles = Array.from(parent.querySelectorAll("article")); | ||
| 193 | articles.reverse().forEach(article => { | ||
| 194 | parent.appendChild(article); // déplace dans le DOM, ne copie pas | ||
| 195 | }); | ||
| 196 | |||
| 197 | console.log('ordre ' + articles_order_select); | ||
| 198 | } | ||
| 199 | else{ | ||
| 200 | console.log("Erreur au changement de l'ordre d'affichage côté serveur"); | ||
| 201 | } | ||
| 202 | }) | ||
| 203 | .catch(error => { | ||
| 204 | console.error('Erreur:', error); | ||
| 205 | }); | ||
| 206 | } | ||
| 207 | |||
| 179 | function changePresentation(bloc_id){ | 208 | function changePresentation(bloc_id){ |
| 180 | const presentation = document.getElementById('presentation_select_' + bloc_id).value; | 209 | const presentation = document.getElementById('presentation_select_' + bloc_id).value; |
| 181 | 210 | ||
diff --git a/src/controller/PageManagementController.php b/src/controller/PageManagementController.php index e811a6a..27bf2c2 100644 --- a/src/controller/PageManagementController.php +++ b/src/controller/PageManagementController.php | |||
| @@ -85,10 +85,7 @@ class PageManagementController | |||
| 85 | $page); | 85 | $page); |
| 86 | $node->useDefaultAttributes(); // fichiers CSS et JS | 86 | $node->useDefaultAttributes(); // fichiers CSS et JS |
| 87 | 87 | ||
| 88 | $data = new NodeData([ | 88 | $data = new NodeData(['description' => trim(htmlspecialchars($_POST["page_description"]))], $node); |
| 89 | // pas de titre, il est dans $page | ||
| 90 | 'description' => trim(htmlspecialchars($_POST["page_description"]))], | ||
| 91 | $node); | ||
| 92 | 89 | ||
| 93 | $bulk_data = $entityManager | 90 | $bulk_data = $entityManager |
| 94 | ->createQuery('SELECT n FROM App\Entity\Image n WHERE n.file_name LIKE :name') | 91 | ->createQuery('SELECT n FROM App\Entity\Image n WHERE n.file_name LIKE :name') |
| @@ -162,9 +159,7 @@ class PageManagementController | |||
| 162 | } | 159 | } |
| 163 | 160 | ||
| 164 | $block = new Node($_POST["bloc_select"], [], $position, $main, $page); | 161 | $block = new Node($_POST["bloc_select"], [], $position, $main, $page); |
| 165 | $data = new NodeData( | 162 | $data = new NodeData(['title' => trim(htmlspecialchars($_POST["bloc_title"]))], $block); |
| 166 | ['title' => trim(htmlspecialchars($_POST["bloc_title"]))], | ||
| 167 | $block); | ||
| 168 | 163 | ||
| 169 | // valeurs par défaut | 164 | // valeurs par défaut |
| 170 | if($_POST["bloc_select"] === 'post_block'){ | 165 | if($_POST["bloc_select"] === 'post_block'){ |
| @@ -268,6 +263,33 @@ class PageManagementController | |||
| 268 | die; | 263 | die; |
| 269 | } | 264 | } |
| 270 | 265 | ||
| 266 | static public function changeArticlesOrder(EntityManager $entityManager, array $json): void | ||
| 267 | { | ||
| 268 | if(isset($json['id']) && isset($json['chrono_order'])){ | ||
| 269 | $director = new Director($entityManager, false); | ||
| 270 | $director->findNodeById($json['id']); | ||
| 271 | |||
| 272 | if($json['chrono_order'] === 'chrono'){ | ||
| 273 | $chrono_order = true; | ||
| 274 | } | ||
| 275 | elseif($json['chrono_order'] === 'antichrono'){ | ||
| 276 | $chrono_order = false; | ||
| 277 | } | ||
| 278 | else{ | ||
| 279 | echo json_encode(['success' => false]); | ||
| 280 | die; | ||
| 281 | } | ||
| 282 | $director->getNode()->getNodeData()->setChronoOrder($chrono_order); | ||
| 283 | $entityManager->flush(); | ||
| 284 | |||
| 285 | echo json_encode(['success' => true, 'chrono_order' => $json['chrono_order']]); | ||
| 286 | } | ||
| 287 | else{ | ||
| 288 | echo json_encode(['success' => false]); | ||
| 289 | } | ||
| 290 | die; | ||
| 291 | } | ||
| 292 | |||
| 271 | static public function changePresentation(EntityManager $entityManager, array $json): void | 293 | static public function changePresentation(EntityManager $entityManager, array $json): void |
| 272 | { | 294 | { |
| 273 | if(isset($json['id']) && isset($json['presentation'])){ | 295 | if(isset($json['id']) && isset($json['presentation'])){ |
| @@ -276,7 +298,6 @@ class PageManagementController | |||
| 276 | 298 | ||
| 277 | if(in_array($json['presentation'], array_keys(Blocks::$presentations))){ | 299 | if(in_array($json['presentation'], array_keys(Blocks::$presentations))){ |
| 278 | $director->getNode()->getNodeData()->setPresentation($json['presentation']); | 300 | $director->getNode()->getNodeData()->setPresentation($json['presentation']); |
| 279 | |||
| 280 | $entityManager->flush(); | 301 | $entityManager->flush(); |
| 281 | 302 | ||
| 282 | $response_data = ['success' => true, 'presentation' => $json['presentation']]; | 303 | $response_data = ['success' => true, 'presentation' => $json['presentation']]; |
diff --git a/src/model/entities/Node.php b/src/model/entities/Node.php index c5df8d1..08961e0 100644 --- a/src/model/entities/Node.php +++ b/src/model/entities/Node.php | |||
| @@ -174,7 +174,7 @@ class Node | |||
| 174 | 174 | ||
| 175 | // cas particulier des news: utilise les dates au lieu des positions (les positions existent mais sont ignorées) | 175 | // cas particulier des news: utilise les dates au lieu des positions (les positions existent mais sont ignorées) |
| 176 | if($this->getName() === 'news_block'){ | 176 | if($this->getName() === 'news_block'){ |
| 177 | $this->sortNews($this->getNodeData()->getData()['chrono'] ?? false); // faux = ordre chronologique | 177 | $this->sortNews($this->getNodeData()->getChronoOrder() ?? false); // faux = ordre chronologique |
| 178 | } | 178 | } |
| 179 | else{ | 179 | else{ |
| 180 | $this->sortChildren(false); | 180 | $this->sortChildren(false); |
diff --git a/src/model/entities/NodeData.php b/src/model/entities/NodeData.php index 99dda83..0d42f3a 100644 --- a/src/model/entities/NodeData.php +++ b/src/model/entities/NodeData.php | |||
| @@ -30,7 +30,10 @@ class NodeData | |||
| 30 | #[ORM\Column(type: "string", length: 255, nullable: true)] | 30 | #[ORM\Column(type: "string", length: 255, nullable: true)] |
| 31 | private ?string $presentation; | 31 | private ?string $presentation; |
| 32 | 32 | ||
| 33 | #[ORM\Column(type: "integer", length: 255, nullable: true)] | 33 | #[ORM\Column(type: "boolean", length: 255, nullable: true)] |
| 34 | private ?bool $chrono_order = null; | ||
| 35 | |||
| 36 | #[ORM\Column(type: "integer", nullable: true)] | ||
| 34 | private ?int $grid_cols_min_width = null; // pour le mode grille | 37 | private ?int $grid_cols_min_width = null; // pour le mode grille |
| 35 | 38 | ||
| 36 | // liaison avec table intermédiaire | 39 | // liaison avec table intermédiaire |
| @@ -42,7 +45,7 @@ class NodeData | |||
| 42 | )] | 45 | )] |
| 43 | private Collection $images; | 46 | private Collection $images; |
| 44 | 47 | ||
| 45 | public function __construct(array $data, Node $node, Collection $images = new ArrayCollection, string $presentation = null) | 48 | public function __construct(array $data, Node $node, Collection $images = new ArrayCollection, ?string $presentation = null, ?bool $chrono_order = null) |
| 46 | { | 49 | { |
| 47 | $this->data = $data; | 50 | $this->data = $data; |
| 48 | $this->node = $node; | 51 | $this->node = $node; |
| @@ -50,6 +53,7 @@ class NodeData | |||
| 50 | if(!empty($presentation) && $presentation === 'grid'){ | 53 | if(!empty($presentation) && $presentation === 'grid'){ |
| 51 | $this->grid_cols_min_width = 250; | 54 | $this->grid_cols_min_width = 250; |
| 52 | } | 55 | } |
| 56 | $this->chrono_order = $chrono_order ?? null; | ||
| 53 | } | 57 | } |
| 54 | 58 | ||
| 55 | public function getId(): int | 59 | public function getId(): int |
| @@ -60,7 +64,7 @@ class NodeData | |||
| 60 | { | 64 | { |
| 61 | return $this->data; | 65 | return $this->data; |
| 62 | } | 66 | } |
| 63 | /*public function setData(array $data): void | 67 | /*public function setData(array $data): void // entrée = tableau associatif |
| 64 | { | 68 | { |
| 65 | $this->data = $data; | 69 | $this->data = $data; |
| 66 | }*/ | 70 | }*/ |
| @@ -74,6 +78,8 @@ class NodeData | |||
| 74 | unset($this->data[$key]); | 78 | unset($this->data[$key]); |
| 75 | } | 79 | } |
| 76 | } | 80 | } |
| 81 | |||
| 82 | // spécifique aux blocs contenant des articles | ||
| 77 | public function getPresentation(): ?string | 83 | public function getPresentation(): ?string |
| 78 | { | 84 | { |
| 79 | return $this->presentation; | 85 | return $this->presentation; |
| @@ -91,6 +97,14 @@ class NodeData | |||
| 91 | { | 97 | { |
| 92 | $this->grid_cols_min_width = $columns; | 98 | $this->grid_cols_min_width = $columns; |
| 93 | } | 99 | } |
| 100 | public function getChronoOrder(): bool | ||
| 101 | { | ||
| 102 | return $this->chrono_order ?? false; | ||
| 103 | } | ||
| 104 | public function setChronoOrder(bool $reverse_order): void | ||
| 105 | { | ||
| 106 | $this->chrono_order = $reverse_order; | ||
| 107 | } | ||
| 94 | 108 | ||
| 95 | /*public function setNode(Node $node): void | 109 | /*public function setNode(Node $node): void |
| 96 | { | 110 | { |
diff --git a/src/router.php b/src/router.php index 8c33d6e..773a25c 100644 --- a/src/router.php +++ b/src/router.php | |||
| @@ -186,6 +186,9 @@ elseif($_SERVER['REQUEST_METHOD'] === 'POST'){ | |||
| 186 | elseif($request->query->get('bloc_edit') === 'switch_blocs_positions'){ | 186 | elseif($request->query->get('bloc_edit') === 'switch_blocs_positions'){ |
| 187 | PageManagementController::SwitchBlocsPositions($entityManager, $json); | 187 | PageManagementController::SwitchBlocsPositions($entityManager, $json); |
| 188 | } | 188 | } |
| 189 | elseif($request->query->get('bloc_edit') === 'change_articles_order'){ | ||
| 190 | PageManagementController::changeArticlesOrder($entityManager, $json); | ||
| 191 | } | ||
| 189 | elseif($request->query->get('bloc_edit') === 'change_presentation'){ | 192 | elseif($request->query->get('bloc_edit') === 'change_presentation'){ |
| 190 | PageManagementController::changePresentation($entityManager, $json); | 193 | PageManagementController::changePresentation($entityManager, $json); |
| 191 | } | 194 | } |
diff --git a/src/view/MainBuilder.php b/src/view/MainBuilder.php index 2510b08..e4f91f3 100644 --- a/src/view/MainBuilder.php +++ b/src/view/MainBuilder.php | |||
| @@ -71,6 +71,11 @@ class MainBuilder extends AbstractBuilder | |||
| 71 | // ceci pourrait être déplacé au début des blocs | 71 | // ceci pourrait être déplacé au début des blocs |
| 72 | $bloc_edit = ''; | 72 | $bloc_edit = ''; |
| 73 | foreach($node->getChildren() as $child_node){ | 73 | foreach($node->getChildren() as $child_node){ |
| 74 | // ordre des articles 'news' | ||
| 75 | if($child_node->getName() === 'news_block'){ | ||
| 76 | $order = $child_node->getNodeData()->getChronoOrder() ? 'chrono' : 'antichrono'; | ||
| 77 | } | ||
| 78 | |||
| 74 | ob_start(); | 79 | ob_start(); |
| 75 | require self::VIEWS_PATH . 'modify_block.php'; | 80 | require self::VIEWS_PATH . 'modify_block.php'; |
| 76 | $bloc_edit .= ob_get_clean(); | 81 | $bloc_edit .= ob_get_clean(); |
diff --git a/src/view/templates/modify_block.php b/src/view/templates/modify_block.php index 22a2932..b44327f 100644 --- a/src/view/templates/modify_block.php +++ b/src/view/templates/modify_block.php | |||
| @@ -19,13 +19,26 @@ | |||
| 19 | </div> | 19 | </div> |
| 20 | </div> | 20 | </div> |
| 21 | <?php | 21 | <?php |
| 22 | if($child_node->getName() === 'news_block'){ | ||
| 23 | ?> | ||
| 24 | <div class="news_order"> | ||
| 25 | <label>Ordre des articles</label> | ||
| 26 | <select id="articles_order_select_<?= $child_node->getId() ?>" onchange="articlesOrderSelect(<?= $child_node->getId() ?>)"> | ||
| 27 | <option value="antichrono" <?= $order === 'antichrono' ? 'selected' : '' ?>>Antichronologique</option> | ||
| 28 | <option value="chrono" <?= $order === 'chrono' ? 'selected' : '' ?>>Chronologique</option> | ||
| 29 | </select> | ||
| 30 | </div> | ||
| 31 | <?php | ||
| 32 | } | ||
| 22 | if($child_node->getNodeData()->getPresentation() !== null){ | 33 | if($child_node->getNodeData()->getPresentation() !== null){ |
| 23 | ?> | 34 | ?> |
| 24 | <div class="grid_options"><p> | 35 | <div class="grid_options"> |
| 25 | <label for="presentation_select_<?= $child_node->getId() ?>">Présentation</label> | 36 | <div> |
| 26 | <select id="presentation_select_<?= $child_node->getId() ?>" onchange="changePresentation(<?= $child_node->getId() ?>)"> | 37 | <label for="presentation_select_<?= $child_node->getId() ?>">Présentation</label> |
| 27 | <?= $this->makePresentationOptions($child_node->getNodeData()->getPresentation()) ?> | 38 | <select id="presentation_select_<?= $child_node->getId() ?>" onchange="changePresentation(<?= $child_node->getId() ?>)"> |
| 28 | </select> | 39 | <?= $this->makePresentationOptions($child_node->getNodeData()->getPresentation()) ?> |
| 40 | </select> | ||
| 41 | </div> | ||
| 29 | <div id="cols_min_width_edit_<?= $child_node->getId() ?>" class="<?= ($child_node->getNodeData()->getPresentation() === 'grid' ? '' : 'hidden') ?>"> | 42 | <div id="cols_min_width_edit_<?= $child_node->getId() ?>" class="<?= ($child_node->getNodeData()->getPresentation() === 'grid' ? '' : 'hidden') ?>"> |
| 30 | <label for="cols_min_width_select_<?= $child_node->getId() ?>">Largeur minimum </label> | 43 | <label for="cols_min_width_select_<?= $child_node->getId() ?>">Largeur minimum </label> |
| 31 | <input type="number" id="cols_min_width_select_<?= $child_node->getId() ?>" onchange="changeColsMinWidth(<?= $child_node->getId() ?>)" min="150" max="400" value="<?= $child_node->getNodeData()->getColsMinWidth() ?>"> pixels | 44 | <input type="number" id="cols_min_width_select_<?= $child_node->getId() ?>" onchange="changeColsMinWidth(<?= $child_node->getId() ?>)" min="150" max="400" value="<?= $child_node->getNodeData()->getColsMinWidth() ?>"> pixels |
diff --git a/src/view/templates/modify_page.php b/src/view/templates/modify_page.php index 5ab1a95..fbcbf20 100644 --- a/src/view/templates/modify_page.php +++ b/src/view/templates/modify_page.php | |||
| @@ -44,6 +44,11 @@ | |||
| 44 | <input type="hidden" name="bloc_title_hidden"> | 44 | <input type="hidden" name="bloc_title_hidden"> |
| 45 | <input type="submit" value="Valider"></p> | 45 | <input type="submit" value="Valider"></p> |
| 46 | </form> | 46 | </form> |
| 47 | <div class="explanations"> | ||
| 48 | <p><b>Articles libres</b>: textes riches générés par l'éditeur et librement positionnables</p> | ||
| 49 | <p><b>Actualilés</b>: contenus structurés avec titre, aperçu, date et possédant une page dédiée</p> | ||
| 50 | <p><b>Galerie</b>: photos parcourables en mode plein écran (cette fonctionalité n'est pas encore disponible)</p> | ||
| 51 | </div> | ||
| 47 | </div> | 52 | </div> |
| 48 | <div class="modify_block"> | 53 | <div class="modify_block"> |
| 49 | <p>Modifier un bloc</p> | 54 | <p>Modifier un bloc</p> |
