submenu generation implemented
All checks were successful
Build and push / Pulling repo on server (push) Successful in 19s

This commit is contained in:
Chris 2023-10-22 09:57:29 +02:00
parent 004e38b3bb
commit 81d4c09533
9 changed files with 94 additions and 14 deletions

1
web/css/flowbite.min.css vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -46,6 +46,33 @@ class Page
$this->menu_priority = 1; $this->menu_priority = 1;
} }
function addSubmenuItem($text, $action, $icon = '', $classes = '')
{
$active = $GLOBALS['url'][0];
if (!$active) $active = 'index';
if ($active == $action)
$act = 1;
else $act = 0;
$this->submenu[] = array('text' => $text, 'action' => $action, 'active' => $act, 'icon' => $icon, 'classes' => $classes);
}
function setSubmenu()
{
//run addsubmenuitem here
}
function getSubmenu($active = 0)
{
$prepare = array();
if (is_array($this->submenu))
foreach ($this->submenu as $key => $var)
$prepare[] = array('text' => $var['text'], 'base' => strtolower($this->_controller), 'action' => $var['action'], 'active' => $var['active']);
return $prepare;
}
function redirect($url) function redirect($url)
{ {
//header("Location: $url"); //header("Location: $url");

View File

@ -107,6 +107,7 @@ function getMenu()
$instance = new $file($file, 'index', false); $instance = new $file($file, 'index', false);
$instance->setMenu(); $instance->setMenu();
$instance->setSubmenu();
if($instance->maySeeThisPage()===true) if($instance->maySeeThisPage()===true)
{ {
@ -117,7 +118,7 @@ function getMenu()
{ {
while($arr[$menu_priority]) while($arr[$menu_priority])
$menu_priority++; $menu_priority++;
$arr[$menu_priority] = array('text'=>$menu_text,'image'=>$instance->menu_image, 'url'=>$file,'menu_class'=>$instance->menu_class); $arr[$menu_priority] = array('text'=>$menu_text,'image'=>$instance->menu_image, 'url'=>$file,'menu_class'=>$instance->menu_class,'submenu'=>$instance->submenu);
} }
} }
} }

View File

@ -24,7 +24,7 @@ else $url = array_filter(explode('/',ltrim(parse_url($_SERVER['REQUEST_URI'], PH
if($url==[] && $_SERVER['HTTP_HX_CURRENT_URL']) if($url==[] && $_SERVER['HTTP_HX_CURRENT_URL'])
$url = explode('/',ltrim(parse_url($_SERVER['HTTP_HX_CURRENT_URL'], PHP_URL_PATH),'/')); $url = explode('/',ltrim(parse_url($_SERVER['HTTP_HX_CURRENT_URL'], PHP_URL_PATH),'/'));
$GLOBALS['url'] = $url;
//echo print_r(['url'=>$url,'server'=>$_SERVER,'request'=>$_REQUEST,'cookie'=>$_COOKIE,'session'=>$_SESSION],true); //echo print_r(['url'=>$url,'server'=>$_SERVER,'request'=>$_REQUEST,'cookie'=>$_COOKIE,'session'=>$_SESSION],true);
$response = callHook($url); $response = callHook($url);

2
web/js/flowbite.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,5 @@
<div class="bg-red-100 border-l-4 border-red-500 text-red-700 p-4" role="alert"> <div class="bg-red-100 border-l-4 border-red-500 text-red-700 p-4" role="alert">
<p class="font-bold">404 - Not found</p> <p class="font-bold">404 - Not found</p>
<p>I have no memory of <?= escape($page) ?></p> <p>I have no memory of <?= escape($page) ?></p>
<img src="https://pictshare.net/4s9gi3.gif" alt="Gandalf: I have no memory of this place"/>
</div> </div>

View File

@ -12,6 +12,17 @@ class Login extends Page {
$this->menu_priority = 99; $this->menu_priority = 99;
} }
function setSubmenu()
{
if($_SESSION['user'])
{
$this->addSubmenuItem('Settings', '/settings', 'fas fa-cog');
$this->addSubmenuItem('Logout', '/login/logout', 'fas fa-sign-out-alt', 'bg-red-500');
}
}
function index() function index()
{ {
$this->set('hello','world'); $this->set('hello','world');
@ -28,6 +39,12 @@ class Login extends Page {
],true)); ],true));
} }
function logout()
{
session_destroy();
$this->redirect('/');
}
function validate() function validate()
{ {
$email = $_REQUEST['email']; $email = $_REQUEST['email'];

View File

@ -7,7 +7,8 @@
<title>Dogstats</title> <title>Dogstats</title>
<link href="/css/output.css" rel="stylesheet"> <link href="/css/output.css" rel="stylesheet">
<link href="/css/fontawesome.min.css" rel="stylesheet"> <link href="/css/fontawesome.min.css" rel="stylesheet">
<script src="/js/htmx.min.js"></script> <link href="/css/flowbite.min.css" rel="stylesheet">
</head> </head>
<body> <body>
@ -19,6 +20,9 @@
<i id="spinner" class="fa-solid fa-spinner"></i> <i id="spinner" class="fa-solid fa-spinner"></i>
</div> </div>
</div> </div>
<script src="/js/htmx.min.js"></script>
<script src="/js/flowbite.min.js"></script>
</body> </body>
</html> </html>

View File

@ -1,15 +1,42 @@
<header class="text-gray-600 body-font"> <header class="text-gray-600 body-font">
<div class="container mx-auto flex flex-wrap p-5 flex-col md:flex-row items-center"> <div class="container mx-auto flex flex-wrap p-5 flex-col md:flex-row items-center">
<a class="flex title-font font-medium items-center text-gray-900 mb-4 md:mb-0"> <a class="flex title-font font-medium items-center text-gray-900 mb-4 md:mb-0">
<img class="h-8 w-auto" src="/imgs/dogstats-50.png" alt=""> <img class="h-8 w-auto" src="/imgs/dogstats-50.png" alt="">
<span class="ml-3 text-xl">Dogstats</span> <span class="ml-3 text-xl">Dogstats</span>
</a> </a>
<nav class="md:ml-auto flex flex-wrap items-center text-base justify-center">
<?php foreach(getMenu() as $item) : ?> <nav class="md:ml-auto flex flex-wrap items-center text-base justify-center">
<a href="/<?= $item['url'] ?>" hx-push-url="/<?= $item['url'] ?>" hx-get="/<?= $item['url'] ?>" hx-target="#main" class="mr-5 hover:text-gray-900"><i class="<?= $item['image'] ?>"></i> <?= $item['text'] ?></a> <?php foreach(getMenu() as $item) : ?>
<?php endforeach; ?> <?php if (count($item['submenu'])) : ?>
</nav> <button id="dropdownDefaultButton-<?= $item['url'] ?>" data-dropdown-toggle="dropdown-<?= $item['url'] ?>" class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center inline-flex items-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800" type="button">
<?= $item['text'] ?>
<svg class="w-2.5 h-2.5 ml-2.5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 10 6">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m1 1 4 4 4-4" />
</svg>
</button>
<div id="dropdown-<?= $item['url'] ?>" class="z-10 hidden bg-white divide-y divide-gray-100 rounded-lg shadow w-44 dark:bg-gray-700">
<ul class="py-2 text-sm text-gray-700 dark:text-gray-200" aria-labelledby="dropdownDefaultButton-<?= $item['url'] ?>">
<?php foreach($item['submenu'] as $sub) : ?>
<li>
<a href="<?= $sub['action'] ?>" hx-push-url="<?= $sub['action'] ?>" hx-get="<?= $sub['action'] ?>" hx-target="#main" class="<?= $sub['classes']?:'' ?> block px-4 py-2">
<?php if($sub['icon']) : ?>
<i class="<?= $sub['icon'] ?>"></i>
<?php endif; ?>
<?= $sub['text'] ?>
</a>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php else : ?>
<a href="/<?= $item['url'] ?>" hx-push-url="/<?= $item['url'] ?>" hx-get="/<?= $item['url'] ?>" hx-target="#main" class="mr-5 hover:text-gray-900"><i class="<?= $item['image'] ?>"></i>
<?= $item['text'] ?>
</a>
<?php endif; ?>
<?php endforeach; ?>
</nav>
</div> </div>
</header> </header>