- Navigation header array structure now is the same as the structure of the navigation menu array

- Implemented the sort logic and added the "sort" attribute to sort menu and header entries for the NavigationWidget
- Added the private method _sortArray to the NavigationLib to sort menu and header entries
- Added the "target" attribute to be used with the attribute "link" to build the link of a menu or header entry
- Now the header menu supports icons on the left side of the entry description
This commit is contained in:
Paolo
2018-06-20 18:12:38 +02:00
parent 3542ff539f
commit b65521199d
5 changed files with 126 additions and 26 deletions
+43 -16
View File
@@ -1,64 +1,91 @@
<?php
// --------------------------------------------------------------------------------------------------------------------
// Header menu
$config['navigation_header'] = array(
'*' => array(
'FH-Complete' => site_url(''),
'Vilesci' => base_url('vilesci'),
'CIS' => CIS_ROOT
'fhcomplete' => array(
'link' => site_url(''),
'icon' => '',
'description' => 'FH-Complete',
'sort' => 1
),
'vilesci' => array(
'link' => base_url('vilesci'),
'icon' => '',
'description' => 'Vilesci',
'sort' => 2
),
'cis' => array(
'link' => CIS_ROOT,
'icon' => '',
'description' => 'CIS',
'sort' => 3
)
)
);
// --------------------------------------------------------------------------------------------------------------------
// Left side menu
$config['navigation_menu'] = array();
$config['navigation_menu']['Vilesci/index'] = array(
'Dashboard' => array(
'dashboard' => array(
'link' => '#',
'description' => 'Dashboard',
'icon' => 'dashboard'
'icon' => 'dashboard',
'sort' => 1
),
'Lehre' => array(
'lehre' => array(
'link' => '#',
'icon' => 'graduation-cap',
'description' => 'Lehre',
'expand' => true,
'sort' => 2,
'children'=> array(
'CIS' => array(
'cis' => array(
'link' => CIS_ROOT,
'icon' => '',
'description' => 'CIS',
'expand' => true
'expand' => true,
'sort' => 1
),
'Infocenter' => array(
'infocenter' => array(
'link' => site_url('system/infocenter/InfoCenter'),
'icon' => 'info',
'description' => 'Infocenter',
'expand' => true
'expand' => true,
'sort' => 2
),
)
),
'Administration' => array(
'administration' => array(
'link' => '#',
'icon' => 'gear',
'description' => 'Administration',
'expand' => false,
'sort' => 3,
'children'=> array(
'Vilesci' => array(
'vilesci' => array(
'link' => base_url('vilesci'),
'icon' => '',
'description' => 'Vilesci',
'expand' => true
'expand' => true,
'sort' => 1
),
'Extensions' => array(
'extensions' => array(
'link' => site_url('system/extensions/Manager'),
'icon' => 'cubes',
'description' => 'Extensions Manager',
'expand' => true
'expand' => true,
'sort' => 2
)
)
)
);
$config['navigation_menu']['system/infocenter/InfoCenter/index'] = array(
'freigegeben' => array(
'link' => site_url('system/infocenter/InfoCenter/freigegeben'),
+7 -6
View File
@@ -9,7 +9,7 @@
* @license GPLv3
* @since Version 1.0.0
*/
/**
* Message Helper
*
@@ -35,7 +35,7 @@ function success($retval, $code = null, $msg_indx_prefix = 'fhc_')
$success->fhcCode = $code;
if (!is_null($code)) $success->msg = lang($msg_indx_prefix . $code);
$success->retval = $retval;
return $success;
}
@@ -51,7 +51,7 @@ function error($retval = '', $code = null, $msg_indx_prefix = 'fhc_')
$error->fhcCode = $code;
if (!is_null($code)) $error->msg = lang($msg_indx_prefix . $code);
$error->retval = $retval;
return $error;
}
@@ -64,7 +64,7 @@ function isSuccess($result)
{
return true;
}
return false;
}
@@ -78,15 +78,16 @@ function hasData($result)
{
return true;
}
return false;
}
/**
* Checks if the result represents an error
* Wrapper function of isSuccess, more readable code
* Bob Dylan: ...there's no success like failure. And that failure's no success at all.
*/
function isError($result)
{
return !isSuccess($result);
}
}
+39 -2
View File
@@ -97,6 +97,8 @@ class NavigationLib
}
}
$this->_sortArray($menuArray);
return $menuArray;
}
@@ -150,6 +152,8 @@ class NavigationLib
}
}
$this->_sortArray($headerArray);
return $headerArray;
}
@@ -158,17 +162,20 @@ class NavigationLib
*/
public function oneLevel(
$description, $link = '#', $children = null, $icon = '', $expand = false,
$subscriptDescription = null, $subscriptLinkClass = null, $subscriptLinkValue = null)
$subscriptDescription = null, $subscriptLinkClass = null, $subscriptLinkValue = null, $target = '',
$sort = null)
{
return array(
'description' => $description,
'link' => $link,
'target' => $target,
'children'=> $children,
'icon' => $icon,
'expand' => $expand,
'subscriptDescription' => $subscriptDescription,
'subscriptLinkClass' => $subscriptLinkClass,
'subscriptLinkValue' => $subscriptLinkValue
'subscriptLinkValue' => $subscriptLinkValue,
'sort' => $sort
);
}
@@ -350,4 +357,34 @@ class NavigationLib
return $navigationPage;
}
/**
* Sorts using the sort element present in the array
*/
private function _sortArray(&$array)
{
uasort($array, function($a, $b) {
// If the element sort is not present then the default value is 999
$sortA = 999;
if (isset($a['sort'])) $sortA = $a['sort'];
// If the element sort is not present then the default value is 999
$sortB = 999;
if (isset($b['sort'])) $sortB = $b['sort'];
return $sortA - $sortB; // < 0 => lt, == 0 => equal, > 0 => gt
});
// Sort also the children
foreach ($array as $key => $value)
{
if (isset($value['children']) && is_array($value['children']) && count($value['children']) > 0)
{
// NOTE: keep this way to give the element by reference, $value has a different reference!
// otherwise the children will not be sorted
$this->_sortArray($array[$key]['children']); // recursive call
}
}
}
}
+19
View File
@@ -33,3 +33,22 @@
font-weight: bold;
text-decoration: underline;
}
.navbar-brand {
float: left;
height: 50px;
padding-top: 15px;
padding-right: 20px;
padding-left: 7px;
font-size: 18px;
line-height: 20px;
}
.navbar-brand-icon {
float: left;
height: 50px;
padding-top: 15px;
padding-right: 12px;
padding-left: 7px;
font-size: 16px;
}
+18 -2
View File
@@ -31,7 +31,20 @@ var FHC_NavigationWidget = {
if (FHC_AjaxClient.hasData(data))
{
jQuery.each(FHC_AjaxClient.getData(data), function(i, e) {
$(".menu-header-items").append('<a class="navbar-brand" href="' + e + '">' + i + '</a>');
var headerEntry = '';
if (e['icon'] != 'undefined' && e['icon'] != '')
{
headerEntry += '<i class="navbar-brand-icon fa fa-' + e['icon'] + ' fa-fw"></i>';
}
var target = '';
if (e['target'] != null) target = e['target'];
headerEntry += '<a class="navbar-brand" href="' + e['link'] + '" target=' + target + '>' + e['description'] + '</a>';
$(".menu-header-items").append(headerEntry);
});
}
}
@@ -116,7 +129,10 @@ var FHC_NavigationWidget = {
strMenu += '<span>';
}
strMenu += '<a href="' + item['link'] + '"' + expanded + '>';
var target = '';
if (item['target'] != null) target = item['target'];
strMenu += '<a href="' + item['link'] + '"' + expanded + ' target="' + target + '">';
if (item['icon'] != 'undefined')
{