mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-21 09:38:48 +02:00
Compare commits
3 Commits
develop
...
feature/62
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a5d9b15dfe | ||
|
|
ad6497aa8c | ||
|
|
18c341d8cd |
@@ -1305,6 +1305,14 @@ class Config
|
|||||||
'source_of_value' => '',
|
'source_of_value' => '',
|
||||||
'show_in_conf_sample' => false,
|
'show_in_conf_sample' => false,
|
||||||
],
|
],
|
||||||
|
'navigation_menu.sorted_popup_user_menu_items' => [
|
||||||
|
'type' => 'array',
|
||||||
|
'description' => 'Sort user menu items after setup on page load',
|
||||||
|
'default' => [],
|
||||||
|
'value' => false,
|
||||||
|
'source_of_value' => '',
|
||||||
|
'show_in_conf_sample' => false,
|
||||||
|
],
|
||||||
'quick_create.enabled' => [
|
'quick_create.enabled' => [
|
||||||
'type' => 'bool',
|
'type' => 'bool',
|
||||||
'description' => 'Whether or not the quick create is enabled',
|
'description' => 'Whether or not the quick create is enabled',
|
||||||
|
|||||||
@@ -21,13 +21,14 @@ namespace Combodo\iTop\Application\UI\Base\Component\PopoverMenu;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
use Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenuItem\PopoverMenuItem;
|
||||||
use Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenuItem\PopoverMenuItemFactory;
|
use Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenuItem\PopoverMenuItemFactory;
|
||||||
use Dict;
|
use Dict;
|
||||||
|
use iPopupMenuExtension;
|
||||||
use JSPopupMenuItem;
|
use JSPopupMenuItem;
|
||||||
use MetaModel;
|
use MetaModel;
|
||||||
use SeparatorPopupMenuItem;
|
use SeparatorPopupMenuItem;
|
||||||
use URLPopupMenuItem;
|
use URLPopupMenuItem;
|
||||||
use iPopupMenuExtension;
|
|
||||||
use UserRights;
|
use UserRights;
|
||||||
use utils;
|
use utils;
|
||||||
|
|
||||||
@@ -56,31 +57,69 @@ class PopoverMenuFactory
|
|||||||
->SetHorizontalPosition(PopoverMenu::ENUM_HORIZONTAL_POSITION_ALIGN_OUTER_RIGHT)
|
->SetHorizontalPosition(PopoverMenu::ENUM_HORIZONTAL_POSITION_ALIGN_OUTER_RIGHT)
|
||||||
->SetVerticalPosition(PopoverMenu::ENUM_VERTICAL_POSITION_ABOVE);
|
->SetVerticalPosition(PopoverMenu::ENUM_VERTICAL_POSITION_ABOVE);
|
||||||
|
|
||||||
|
$aUserMenuItems = [];
|
||||||
|
|
||||||
// Allowed portals
|
// Allowed portals
|
||||||
$aAllowedPortalsItems = static::PrepareAllowedPortalsItemsForUserMenu();
|
$aAllowedPortalsItems = static::PrepareAllowedPortalsItemsForUserMenu();
|
||||||
if (!empty($aAllowedPortalsItems)) {
|
self::AddPopoverMenuItems($aAllowedPortalsItems, $aUserMenuItems);
|
||||||
$oMenu->AddSection('allowed_portals')
|
|
||||||
->SetItems('allowed_portals', $aAllowedPortalsItems);
|
|
||||||
}
|
|
||||||
|
|
||||||
// User related pages
|
// User related pages
|
||||||
$oMenu->AddSection('user_related')
|
self::AddPopoverMenuItems(static::PrepareUserRelatedItemsForUserMenu(), $aUserMenuItems);
|
||||||
->SetItems('user_related', static::PrepareUserRelatedItemsForUserMenu());
|
|
||||||
|
|
||||||
// API: iPopupMenuExtension::MENU_USER_ACTIONS
|
// API: iPopupMenuExtension::MENU_USER_ACTIONS
|
||||||
$aAPIItems = static::PrepareAPIItemsForUserMenu($oMenu);
|
$aAPIItems = static::PrepareAPIItemsForUserMenu($oMenu);
|
||||||
if (count($aAPIItems) > 0) {
|
self::AddPopoverMenuItems($aAPIItems, $aUserMenuItems);
|
||||||
$oMenu->AddSection('popup_menu_extension-menu_user_actions')
|
|
||||||
->SetItems('popup_menu_extension-menu_user_actions', $aAPIItems);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Misc links
|
// Misc links
|
||||||
$oMenu->AddSection('misc')
|
/*$oMenu->AddSection('misc')
|
||||||
->SetItems('misc', static::PrepareMiscItemsForUserMenu());
|
->SetItems('misc', static::PrepareMiscItemsForUserMenu());*/
|
||||||
|
self::AddPopoverMenuItems(static::PrepareMiscItemsForUserMenu(), $aUserMenuItems);
|
||||||
|
|
||||||
|
self::SortPopoverMenuItems($aUserMenuItems);
|
||||||
|
|
||||||
|
$oMenu->AddSection('misc')
|
||||||
|
->AddItems('misc', $aUserMenuItems);
|
||||||
return $oMenu;
|
return $oMenu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param PopoverMenuItem[] $aPopoverMenuItem
|
||||||
|
* @param PopoverMenuItem[] $aUserMenuItems
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private static function AddPopoverMenuItems(array $aPopoverMenuItem, array &$aUserMenuItems) : void {
|
||||||
|
foreach ($aPopoverMenuItem as $oPopoverMenuItem){
|
||||||
|
$aUserMenuItems[$oPopoverMenuItem->GetUID()] = $oPopoverMenuItem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param PopoverMenuItem[] $aPopoverMenuItem
|
||||||
|
* @param PopoverMenuItem[] $aUserMenuItems
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private static function SortPopoverMenuItems(array &$aUserMenuItems) : void {
|
||||||
|
$aSortedMenusFromConfig = MetaModel::GetConfig()->Get('navigation_menu.sorted_popup_user_menu_items');
|
||||||
|
if (!is_array($aSortedMenusFromConfig) || empty($aSortedMenusFromConfig)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$aSortedMenus = [];
|
||||||
|
foreach ($aSortedMenusFromConfig as $sMenuUID){
|
||||||
|
if (array_key_exists($sMenuUID, $aUserMenuItems)){
|
||||||
|
$aSortedMenus[]=$aUserMenuItems[$sMenuUID];
|
||||||
|
unset($aUserMenuItems[$sMenuUID]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($aUserMenuItems as $oMenu){
|
||||||
|
$aSortedMenus[]=$oMenu;
|
||||||
|
}
|
||||||
|
$aUserMenuItems = $aSortedMenus;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the allowed portals items for the current user
|
* Return the allowed portals items for the current user
|
||||||
*
|
*
|
||||||
@@ -273,4 +312,4 @@ class PopoverMenuFactory
|
|||||||
|
|
||||||
return $oMenu;
|
return $oMenu;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,96 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace UI\Base\Component\PopoverMenu;
|
||||||
|
|
||||||
|
use Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenuFactory;
|
||||||
|
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @runTestsInSeparateProcesses
|
||||||
|
* @preserveGlobalState disabled
|
||||||
|
* @backupGlobals disabled
|
||||||
|
*/
|
||||||
|
class PopoverMenuFactoryTest extends ItopDataTestCase {
|
||||||
|
|
||||||
|
public function MakeUserMenuForNavigationMenuProvider(){
|
||||||
|
$aNotSortedMenuUIDs = [
|
||||||
|
'portal_itop_portal',
|
||||||
|
'UI_Preferences',
|
||||||
|
'UI_Help',
|
||||||
|
'UI_AboutBox'
|
||||||
|
];
|
||||||
|
|
||||||
|
return [
|
||||||
|
'no conf' => [
|
||||||
|
'aConf' => null,
|
||||||
|
'aExpectedMenuUIDs' => $aNotSortedMenuUIDs
|
||||||
|
],
|
||||||
|
'not an array conf' => [
|
||||||
|
'aConf' => "wrong conf",
|
||||||
|
'aExpectedMenuUIDs' => $aNotSortedMenuUIDs
|
||||||
|
],
|
||||||
|
'default conf' => [
|
||||||
|
'aConf' => [],
|
||||||
|
'aExpectedMenuUIDs' => $aNotSortedMenuUIDs
|
||||||
|
],
|
||||||
|
'same order in conf' => [
|
||||||
|
'aConf' => [
|
||||||
|
'portal:itop-portal',
|
||||||
|
'UI:Preferences',
|
||||||
|
'UI:Help',
|
||||||
|
'UI:AboutBox',
|
||||||
|
],
|
||||||
|
'aExpectedMenuUIDs' => $aNotSortedMenuUIDs
|
||||||
|
],
|
||||||
|
'first menus sorted and last one missing in conf' => [
|
||||||
|
'aConf' => [
|
||||||
|
"portal:itop-portal",
|
||||||
|
"UI:Preferences",
|
||||||
|
],
|
||||||
|
'aExpectedMenuUIDs' => $aNotSortedMenuUIDs
|
||||||
|
],
|
||||||
|
'some menus but not all sorted' => [
|
||||||
|
'aConf' => [
|
||||||
|
'UI:Preferences',
|
||||||
|
'UI:AboutBox',
|
||||||
|
],
|
||||||
|
'aExpectedMenuUIDs' => [
|
||||||
|
'UI_Preferences',
|
||||||
|
'UI_AboutBox',
|
||||||
|
'portal_itop_portal',
|
||||||
|
'UI_Help',
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'all user menu sorted' => [
|
||||||
|
'aConf' => [
|
||||||
|
'UI:Preferences',
|
||||||
|
'UI:AboutBox',
|
||||||
|
'portal:itop-portal',
|
||||||
|
'UI:Help',
|
||||||
|
],
|
||||||
|
'aExpectedMenuUIDs' => [
|
||||||
|
'UI_Preferences',
|
||||||
|
'UI_AboutBox',
|
||||||
|
'portal_itop_portal',
|
||||||
|
'UI_Help',
|
||||||
|
]
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @dataProvider MakeUserMenuForNavigationMenuProvider
|
||||||
|
*/
|
||||||
|
public function testMakeUserMenuForNavigationMenu($aConf, $aExpectedMenuUIDs){
|
||||||
|
if (! is_null($aConf)){
|
||||||
|
\MetaModel::GetConfig()->Set('navigation_menu.sorted_popup_user_menu_items', $aConf);
|
||||||
|
}
|
||||||
|
|
||||||
|
$aRes = PopoverMenuFactory::MakeUserMenuForNavigationMenu()->GetSections();
|
||||||
|
$this->assertTrue(array_key_exists('misc', $aRes));
|
||||||
|
$aUIDsWithDummyRandoString = array_keys($aRes['misc']['aItems']);
|
||||||
|
//replace ibo-popover-menu--item-6464cdca5ecf4214716943--UI_AboutBox by UI_AboutBox (for ex)
|
||||||
|
$aUIDs = preg_replace('/ibo-popover-menu--item-([^\-]+)--/', '', $aUIDsWithDummyRandoString);
|
||||||
|
$this->assertEquals($aExpectedMenuUIDs, $aUIDs);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user