Merge pull request #18844 from MauricioFauth/top-menu-refactor

Merge top_menu and breadcrumbs templates
This commit is contained in:
Maurício Meneghini Fauth 2023-12-13 21:11:22 -03:00 committed by GitHub
commit 96922d7db0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 44 deletions

View File

@ -42,3 +42,26 @@
{% endif %}
</ol>
</nav>
<div id="topmenucontainer" class="menucontainer">
<nav class="navbar navbar-expand-lg">
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-label="
{%- trans %}Toggle navigation{% notes %}Show or hide the menu using the hamburger style button{% endtrans %}" aria-controls="navbarNav" aria-expanded="false">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul id="topmenu" class="navbar-nav">
{% for tab in tabs %}
<li class="nav-item{{ tab.active ? ' active' }}">
<a class="nav-link text-nowrap disableAjax" href="{{ url(tab.route, url_params|merge(tab.args ?? [])) }}">
{{ get_icon(tab.icon, tab.text, false, true, 'TabsMode') }}
{% if tab.active %}
<span class="visually-hidden">{% trans %}(current){% notes %}Current page{% endtrans %}</span>
{% endif %}
</a>
</li>
{% endfor %}
</ul>
</div>
</nav>
</div>

View File

@ -1,22 +0,0 @@
<div id="topmenucontainer" class="menucontainer">
<nav class="navbar navbar-expand-lg">
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-label="
{%- trans %}Toggle navigation{% notes %}Show or hide the menu using the hamburger style button{% endtrans %}" aria-controls="navbarNav" aria-expanded="false">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul id="topmenu" class="navbar-nav">
{% for tab in tabs %}
<li class="nav-item{{ tab.active ? ' active' }}">
<a class="nav-link text-nowrap disableAjax" href="{{ url(tab.route, url_params|merge(tab.args ?? [])) }}">
{{ get_icon(tab.icon, tab.text, false, true, 'TabsMode') }}
{% if tab.active %}
<span class="visually-hidden">{% trans %}(current){% notes %}Current page{% endtrans %}</span>
{% endif %}
</a>
</li>
{% endfor %}
</ul>
</div>
</nav>
</div>

View File

@ -50,18 +50,20 @@ class Menu
*/
public function getDisplay(): string
{
$retval = $this->getBreadcrumbs();
$retval .= $this->getMenu();
$breadcrumbs = $this->getBreadcrumbs();
$menu = $this->getMenu();
return $retval;
return $this->template->render('menu/main', [
'server' => $breadcrumbs['server'],
'database' => $breadcrumbs['database'],
'table' => $breadcrumbs['table'],
'tabs' => $menu['tabs'],
'url_params' => $menu['url_params'],
]);
}
/**
* Returns the menu as HTML
*
* @return string HTML formatted menubar
*/
private function getMenu(): string
/** @return array{tabs: mixed[], url_params: mixed[]} */
private function getMenu(): array
{
$urlParams = [];
@ -84,7 +86,7 @@ class Menu
// Filter out any tabs that are not allowed
$tabs = array_intersect_key($tabs, $allowedTabs);
return $this->template->render('top_menu', ['tabs' => $tabs, 'url_params' => $urlParams]);
return ['tabs' => $tabs, 'url_params' => $urlParams];
}
/**
@ -135,12 +137,8 @@ class Menu
return $allowedTabs;
}
/**
* Returns the breadcrumbs as HTML
*
* @return string HTML formatted breadcrumbs
*/
private function getBreadcrumbs(): string
/** @return array{server: mixed[], database: mixed[], table: mixed[]} */
private function getBreadcrumbs(): array
{
$server = [];
$database = [];
@ -171,7 +169,7 @@ class Menu
}
if (mb_strstr($table['comment'], '; InnoDB free')) {
$table['comment'] = preg_replace('@; InnoDB free:.*?$@', '', $table['comment']);
$table['comment'] = (string) preg_replace('@; InnoDB free:.*?$@', '', $table['comment']);
}
} else {
// no table selected, display database comment if present
@ -185,11 +183,7 @@ class Menu
}
}
return $this->template->render('menu/breadcrumbs', [
'server' => $server,
'database' => $database,
'table' => $table,
]);
return ['server' => $server, 'database' => $database, 'table' => $table];
}
/**