chg: [Factories] Refactored side-menu/header/footer construction

- better separation between systems and data for code reusability
- genericElements should be free of any application specific code for portability
remotes/origin/main
iglocska 2020-06-08 11:57:53 +02:00
parent 82b02768c2
commit 23f5b56ec8
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
5 changed files with 137 additions and 58 deletions

View File

@ -0,0 +1,55 @@
<?php
$navdata = '';
foreach ($menu['collapse'] as $k => $menuElement) {
if ($menuElement['type'] === 'single') {
$navdata .= sprintf(
'<li class="nav-item active"><a class="nav-link %s" href="%s">%s</a>',
empty($menuElement['class']) ? '' : h($menuElement['class']),
empty($menuElement['url']) ? '' : h($menuElement['url']),
empty($menuElement['text']) ? '' : h($menuElement['text'])
);
} else if ($menuElement['type'] === 'group') {
$navdataElements = '';
foreach ($menuElement['children'] as $child) {
if (!empty($child['type']) && $child['type'] === 'divider') {
$navdataElements .= '<div class="dropdown-divider"></div>';
} else {
$navdataElements .= sprintf(
'<a class="dropdown-item %s" href="%s">%s</a>',
empty($child['class']) ? '' : h($child['class']),
empty($child['url']) ? '' : h($child['url']),
empty($child['text']) ? '' : h($child['text'])
);
}
}
$navdata .= sprintf(
'<li class="nav-item dropdown">%s%s</li>',
sprintf(
'<a class="nav-link dropdown-toggle" href="#" id="%s" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">%s</a>',
'dropdown-label-' . h($k),
h($menuElement['name'])
),
sprintf(
'<div class="dropdown-menu" aria-labelledby="navbarDropdown">%s</div>',
$navdataElements
)
);
}
}
$navdata = sprintf(
'<div class="collapse navbar-collapse" id="navbarCollapse"><ul class="navbar-nav mr-auto">%s</ul></div>',
$navdata
);
$homeButton = sprintf(
'<a class="navbar-brand %s" href="%s">%s</a>',
empty($menu['home']['class']) ? '' : h($menu['home']['class']),
empty($menu['home']['url']) ? '' : h($menu['home']['url']),
empty($menu['home']['text']) ? '' : h($menu['home']['text'])
);
echo sprintf(
'<nav class="navbar navbar-expand-lg navbar-dark bg-dark">%s%s%s</nav>',
$homeButton,
'<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation"><span class="navbar-toggler-icon"></span></button>',
$navdata
);

View File

@ -89,58 +89,4 @@
)
)
);
$navdata = '';
foreach ($menu['collapse'] as $k => $menuElement) {
if ($menuElement['type'] === 'single') {
$navdata .= sprintf(
'<li class="nav-item active"><a class="nav-link %s" href="%s">%s</a>',
empty($menuElement['class']) ? '' : h($menuElement['class']),
empty($menuElement['url']) ? '' : h($menuElement['url']),
empty($menuElement['text']) ? '' : h($menuElement['text'])
);
} else if ($menuElement['type'] === 'group') {
$navdataElements = '';
foreach ($menuElement['children'] as $child) {
if (!empty($child['type']) && $child['type'] === 'divider') {
$navdataElements .= '<div class="dropdown-divider"></div>';
} else {
$navdataElements .= sprintf(
'<a class="dropdown-item %s" href="%s">%s</a>',
empty($child['class']) ? '' : h($child['class']),
empty($child['url']) ? '' : h($child['url']),
empty($child['text']) ? '' : h($child['text'])
);
}
}
$navdata .= sprintf(
'<li class="nav-item dropdown">%s%s</li>',
sprintf(
'<a class="nav-link dropdown-toggle" href="#" id="%s" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">%s</a>',
'dropdown-label-' . h($k),
h($menuElement['name'])
),
sprintf(
'<div class="dropdown-menu" aria-labelledby="navbarDropdown">%s</div>',
$navdataElements
)
);
}
}
$navdata = sprintf(
'<div class="collapse navbar-collapse" id="navbarCollapse"><ul class="navbar-nav mr-auto">%s</ul></div>',
$navdata
);
$homeButton = sprintf(
'<a class="navbar-brand %s" href="%s">%s</a>',
empty($menu['home']['class']) ? '' : h($menu['home']['class']),
empty($menu['home']['url']) ? '' : h($menu['home']['url']),
empty($menu['home']['text']) ? '' : h($menu['home']['text'])
);
echo sprintf(
'<nav class="navbar navbar-expand-lg navbar-dark bg-dark">%s%s%s</nav>',
$homeButton,
'<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation"><span class="navbar-toggler-icon"></span></button>',
$navdata
);
?>
echo $this->element('header', ['menu' => $menu]);

View File

@ -60,7 +60,85 @@ $menu = [
]
]
]
],
'Administration' => [
'Roles' => [
'label' => __('Roles'),
'url' => '/roles/index',
'children' => [
'index' => [
'url' => '/roles/index',
'label' => __('List roles')
],
'add' => [
'url' => '/roles/add',
'label' => __('Add role')
],
'view' => [
'url' => '/roles/view/{{id}}',
'label' => __('View role'),
'actions' => ['delete', 'edit', 'view']
],
'edit' => [
'url' => '/roles/edit/{{id}}',
'label' => __('Edit role'),
'actions' => ['edit', 'delete', 'view']
],
'delete' => [
'url' => '/roles/delete/{{id}}',
'label' => __('Delete role'),
'actions' => ['delete', 'edit', 'view']
]
]
],
'Users' => [
'label' => __('Users'),
'url' => '/users/index',
'children' => [
'index' => [
'url' => '/users/index',
'label' => __('List users')
],
'add' => [
'url' => '/users/add',
'label' => __('Add user')
],
'view' => [
'url' => '/users/view/{{id}}',
'label' => __('View user'),
'actions' => ['delete', 'edit', 'view']
],
'edit' => [
'url' => '/users/edit/{{id}}',
'label' => __('Edit user'),
'actions' => ['edit', 'delete', 'view']
],
'delete' => [
'url' => '/users/delete/{{id}}',
'label' => __('Delete user'),
'actions' => ['delete', 'edit', 'view']
]
]
]
],
'Cerebrate' => [
'Roles' => [
'label' => __('Roles'),
'url' => '/roles/index',
'children' => [
'index' => [
'url' => '/roles/index',
'label' => __('List roles')
],
'view' => [
'url' => '/roles/view/{{id}}',
'label' => __('View role'),
'actions' => ['delete', 'edit', 'view']
]
]
]
]
];
$children = '';
if (isset($menu[$metaGroup])) {

View File

@ -40,13 +40,13 @@ $cakeDescription = 'Cerebrate';
</head>
<body>
<header>
<?= $this->element('genericElements/header') ?>
<?= $this->element('header') ?>
</header>
<main role="main" class="container-fluid">
<div class="container-fluid">
<div class="row">
<div class="col-md-2 d-none d-md-block col-lg-1 bg-light sidebar" style="padding:0px;margin:0px;">
<?= $this->element('/genericElements/SideMenu/side_menu') ?>
<?= $this->element('side_menu') ?>
</div>
<div role="main" class="col-md-10 ml-sm-auto col-lg-11 pt-3 px-4">
<?= $this->Flash->render() ?>
@ -56,7 +56,7 @@ $cakeDescription = 'Cerebrate';
</div>
</main>
<footer class="footer">
<?= $this->element('genericElements/footer') ?>
<?= $this->element('footer') ?>
</footer>
<div id="mainModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="mediumModalLabel" aria-hidden="true"></div>
</body>