N°3182 - Add support for MenuGroup CSS icon in the XML datamodel

- Introduce itop_design v1.8
- Default CSS classes are 'fas fa-ellipsis-v' from FontAwesome
- New tags <style><decoration_classes>xxx yyy</decoration_classes></style> under the <menu xsi:type="MenuGroup"> tag
This commit is contained in:
Molkobain
2020-07-18 10:26:45 +02:00
parent 0516862632
commit 10a14a3844
4 changed files with 64 additions and 4 deletions

View File

@@ -225,11 +225,12 @@ class ApplicationMenu
}
$sMenuGroupIdx = $aMenuGroup['index'];
/** @var \MenuGroup $oMenuNode */
$oMenuNode = static::GetMenuNode($sMenuGroupIdx);
$aMenuGroups[] = [
'sId' => $oMenuNode->GetMenuID(),
'sIconCssClasses' => 'fas fa-fw fa-home', // TODO: Get the classes from the datamodel
'sIconCssClasses' => $oMenuNode->GetDecorationClasses(),
'sTitle' => $oMenuNode->GetTitle(),
'aSubMenuNodes' => static::GetSubMenuNodes($sMenuGroupIdx, $aExtraParams),
];
@@ -822,18 +823,42 @@ abstract class MenuNode
*/
class MenuGroup extends MenuNode
{
/** @var string DEFAULT_DECORATION_CLASSES */
const DEFAULT_DECORATION_CLASSES = 'fas fa-ellipsis-v';
/** @var string The CSS classes used to display the menu group's icon */
protected $sDecorationClasses = self::DEFAULT_DECORATION_CLASSES;
/**
* Create a top-level menu group and inserts it into the application's main menu
*
* @param string $sMenuId Unique identifier of the menu (used to identify the menu for bookmarking, and for getting the labels from the dictionary)
* @param float $fRank Number used to order the list, the groups are sorted based on this value
* @param string|null $sDecorationClasses CSS classes used to display the menu group's icon
* @param string $sEnableClass Name of class of object
* @param integer $iActionCode Either UR_ACTION_READ, UR_ACTION_MODIFY, UR_ACTION_DELETE, UR_ACTION_BULKREAD, UR_ACTION_BULKMODIFY or UR_ACTION_BULKDELETE
* @param integer $iAllowedResults Expected "rights" for the action: either UR_ALLOWED_YES, UR_ALLOWED_NO, UR_ALLOWED_DEPENDS or a mix of them...
* @param string $sEnableStimulus
*/
public function __construct($sMenuId, $fRank, $sEnableClass = null, $iActionCode = null, $iAllowedResults = UR_ALLOWED_YES, $sEnableStimulus = null)
public function __construct($sMenuId, $fRank, $sDecorationClasses = null, $sEnableClass = null, $iActionCode = null, $iAllowedResults = UR_ALLOWED_YES, $sEnableStimulus = null)
{
parent::__construct($sMenuId, -1 /* no parent, groups are at root level */, $fRank, $sEnableClass, $iActionCode, $iAllowedResults, $sEnableStimulus);
if(!empty($sDecorationClasses))
{
$this->sDecorationClasses = $sDecorationClasses;
}
}
/**
* Return the CSS classes used for decorating the menu group (typically the icon in the navigation menu)
*
* @return string
* @since 2.8.0
*/
public function GetDecorationClasses()
{
return $this->sDecorationClasses;
}
/**

View File

@@ -2179,6 +2179,13 @@ EOF
break;
case 'MenuGroup':
$oStyleNode = $oMenu->GetOptionalElement('style');
// Note: We use '' as the default value to ease the MenuGroup::__construct() call as we would have to make a different processing to not put the quotes around the parameter in case of null.
$sDecorationClasses = ($oStyleNode === null) ? '' : $oStyleNode->GetChildText('decoration_classes', '');
$sNewMenu = "new MenuGroup('$sMenuId', $fRank, '$sDecorationClasses' {$sOptionalEnableParams});";
break;
default:
$sNewMenu = "new $sMenuClass('$sMenuId', $fRank {$sOptionalEnableParams});";
}

View File

@@ -17,7 +17,7 @@
* You should have received a copy of the GNU Affero General Public License
*/
define('ITOP_DESIGN_LATEST_VERSION', '1.7'); // iTop >= 2.7.0
define('ITOP_DESIGN_LATEST_VERSION', '1.8'); // iTop >= 2.8.0
/**
* Utility to upgrade the format of a given XML datamodel to the latest version
@@ -87,6 +87,12 @@ class iTopDesignFormat
'1.7' => array(
'previous' => '1.6',
'go_to_previous' => 'From17To16',
'next' => '1.8',
'go_to_next' => 'From17To18',
),
'1.8' => array(
'previous' => '1.7',
'go_to_previous' => 'From18To17',
'next' => null,
'go_to_next' => null,
),
@@ -757,6 +763,28 @@ class iTopDesignFormat
$this->RemoveNodeFromXPath($sPath);
}
/**
* Upgrade the format from version 1.7 to 1.8
* @param \ModelFactory $oFactory
* @return void (Errors are logged)
*/
protected function From17To18($oFactory)
{
// Nothing
}
/**
* Downgrade the format from version 1.8 to 1.7
* @param \ModelFactory $oFactory
* @return void (Errors are logged)
*/
protected function From18To17($oFactory)
{
// -- 3182 - Remove style node from MenuGroup
$sPath = "/itop_design/menus/menu[@xsi:type='MenuGroup']/style";
$this->RemoveNodeFromXPath($sPath);
}
/**
* @param string $sPath
*

View File

@@ -1,4 +1,4 @@
<a class="ibo-navigation-menu--menu-group" data-role="ibo-navigation-menu--menu-group" data-menu-group-id="{{ aMenuGroup.sId }}" href="#">
<span class="ibo-navigation-menu--menu-group-icon {{ aMenuGroup.sIconCssClasses }}" title="{{ aMenuGroup.sTitle }}"></span>
<span class="ibo-navigation-menu--menu-group-icon fa-fw {{ aMenuGroup.sIconCssClasses }}" title="{{ aMenuGroup.sTitle }}"></span>
<span class="ibo-navigation-menu--menu-group-title">{{ aMenuGroup.sTitle }}</span>
</a>