From 06654b0e647ec937d7442a3cb1546bd1474c07d1 Mon Sep 17 00:00:00 2001 From: ALGLAVE Ivan <ivan.alglave8@etu.univ-lorraine.fr> Date: Thu, 26 Nov 2020 10:34:04 +0100 Subject: [PATCH] Cocktails.php displays a clickable list of all the cocktails --- Cocktails.php | 22 ++++++++++++++++++---- Hierarchy.php | 29 ++++++----------------------- Home.php | 6 +++--- scripts/Functions.php | 11 +++++++---- 4 files changed, 34 insertions(+), 34 deletions(-) diff --git a/Cocktails.php b/Cocktails.php index e6d028e..eb8df4e 100644 --- a/Cocktails.php +++ b/Cocktails.php @@ -11,16 +11,30 @@ <ul> <?php - include "scripts/Functions.php"; - $ar = getRecipes(['Malibu'], [], 10, true, true); + include "Donnees.inc.php"; + $ar = $Recettes; - foreach($ar as $r) + for($i = 0; $i < count($ar); $i++) { - echo '<li>' . $r['recipe']['titre'] . ' (unsatisfied ingredients = ' . $r['score'] . ')' . '</li>'; + echo '<li onclick="notifyParent(' . $i . ');">' . $ar[$i]['titre'] . '</li>'; } ?> </ul> + + <script> + + function notifyParent(e) // Send a message to the parent window, asking to display the recipe #e + { + var data = { + event: 'recipeselect', + value: Number(e) + }; + window.top.postMessage(data, [data.event, data.value]); + } + + </script> + </body> </html> \ No newline at end of file diff --git a/Hierarchy.php b/Hierarchy.php index b0439e7..4b1c1f2 100644 --- a/Hierarchy.php +++ b/Hierarchy.php @@ -10,34 +10,17 @@ <body id="body"> - <ul id="origin_list"></ul> + <!-- HTML --> + + <!-- JAVASCRIPT --> - <script> - let n_list_origin = document.getElementById('origin_list'); - //let ingredients = getIngredients(); + <script> + - function detailIngredients() - { - let d = document.getElementsByClassName('detailed'); - let ud = document.getElementsByClassName('undetailed'); - for(let el in ud) - { - while (el.firstChild) { - el.removeChild(el.firstChild); - } - } - for(let el in d) - { - let c = getIngredients(el.value, function (data, status) - { - - }); - } - } - function notifyParent(e) + function notifyParent(e) // Send a message to the parent window, asking to display the recipe #e { var data = { event: 'recipeselect', diff --git a/Home.php b/Home.php index 4bca386..2702c22 100644 --- a/Home.php +++ b/Home.php @@ -60,12 +60,12 @@ wraper.disabled = false; } - function showRecipe(id) + function showRecipe(id) // Show the Recipe with the id 'id' in the file 'Donnees.inc.php' { embed.setAttribute('src','RecipeView.php?id_recipe=' + id); - wrapper.classList.add('active'); - content.classList.add('blur'); + wrapper.classList.add('active'); // Set the RecipeView wrapper active + content.classList.add('blur'); // Blurs the original content of the page wrapper.disabled = true; embed.focus(); diff --git a/scripts/Functions.php b/scripts/Functions.php index 0a92146..efde097 100644 --- a/scripts/Functions.php +++ b/scripts/Functions.php @@ -59,13 +59,16 @@ function getRecipes($wanted_ingredients, $unwanted_ingredients, $max_unsatisfied function getIngredients($parent_category) { include "../Donnees.inc.php"; - $res = ''; - $ingredients = $Hierarchie[$parent_category]['sous-categorie']; - foreach($ingredients as $i) + if(isset($Hierarchie[$parent_category])) { - $res .= $i . '|'; + $ingredients = $Hierarchie[$parent_category]['sous-categorie']; + + foreach($ingredients as $i) + { + $res .= $i . '|'; + } } return $res; -- GitLab