mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-25 19:48:49 +02:00
N°2847 - Rework iTopWebPage layout (WIP Part VI)
- iTopWebPage: Restore "open search" feature - iTopWebPage: Change all resources URL to absolute in order to benefit from the "duplicate removal" benefits - iTopWebPage: Remove obsolete method IsMenuPaneVisible() - Config: Add new parameters quick_create.enabled / global_search.enabled / breadcrumb.enabled - utils: Add new GetAppRevisionNumber() method - Introduce iUIBlock interface for UI layouts, components, ... - Introduce BlockRenderer to properly render blocks - Add "render_block" function to TwigHelper to render blocks directly from TWIG - Refactor layouts and components into proper block classes to fit the new architecture
This commit is contained in:
222
sources/application/UI/Layout/NavigationMenu/NavigationMenu.php
Normal file
222
sources/application/UI/Layout/NavigationMenu/NavigationMenu.php
Normal file
@@ -0,0 +1,222 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2013-2020 Combodo SARL
|
||||
*
|
||||
* This file is part of iTop.
|
||||
*
|
||||
* iTop is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* iTop is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Layout\NavigationMenu;
|
||||
|
||||
|
||||
use ApplicationContext;
|
||||
use ApplicationMenu;
|
||||
use appUserPreferences;
|
||||
use Combodo\iTop\Application\Branding;
|
||||
use Combodo\iTop\Application\UI\Component\PopoverMenu\PopoverMenu;
|
||||
use Combodo\iTop\Application\UI\UIBlock;
|
||||
use Dict;
|
||||
use MetaModel;
|
||||
use UserRights;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* Class NavigationMenu
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Layout\NavigationMenu
|
||||
* @internal
|
||||
* @since 2.8.0
|
||||
*/
|
||||
class NavigationMenu extends UIBlock
|
||||
{
|
||||
const BLOCK_CODE = 'ibo-navigation-menu';
|
||||
|
||||
const HTML_TEMPLATE_REL_PATH = 'layouts/navigation-menu/layout';
|
||||
const JS_TEMPLATE_REL_PATH = 'layouts/navigation-menu/layout';
|
||||
const JS_FILES_REL_PATH = [
|
||||
'js/layouts/navigation-menu.js',
|
||||
];
|
||||
|
||||
/** @var string $sAppRevisionNumber */
|
||||
protected $sAppRevisionNumber;
|
||||
/** @var string $sAppSquareIconUrl */
|
||||
protected $sAppSquareIconUrl;
|
||||
/** @var string $sAppFullIconUrl */
|
||||
protected $sAppFullIconUrl;
|
||||
/** @var string $sAppIconLink */
|
||||
protected $sAppIconLink;
|
||||
/** @var array $aMenuGroups */
|
||||
protected $aMenuGroups;
|
||||
/** @var array $aUserData */
|
||||
protected $aUserData;
|
||||
/** @var \Combodo\iTop\Application\UI\Component\PopoverMenu\PopoverMenu $oUserMenu */
|
||||
private $oUserMenu;
|
||||
/** @var bool $bIsExpanded */
|
||||
protected $bIsExpanded;
|
||||
|
||||
/**
|
||||
* NavigationMenu constructor.
|
||||
*
|
||||
* @param string|null $sId
|
||||
* @param \ApplicationContext $oAppContext
|
||||
* @param \Combodo\iTop\Application\UI\Component\PopoverMenu\PopoverMenu $oUserMenu
|
||||
*
|
||||
* @throws \CoreException
|
||||
* @throws \CoreUnexpectedValue
|
||||
* @throws \DictExceptionMissingString
|
||||
* @throws \MySQLException
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function __construct($sId, ApplicationContext $oAppContext, PopoverMenu $oUserMenu)
|
||||
{
|
||||
parent::__construct($sId);
|
||||
|
||||
$this->sAppRevisionNumber = utils::GetAppRevisionNumber();
|
||||
$this->sAppSquareIconUrl = Branding::GetSquareMainLogoAbsoluteUrl();
|
||||
$this->sAppFullIconUrl = Branding::GetFullMainLogoAbsoluteUrl();
|
||||
$this->sAppIconLink = MetaModel::GetConfig()->Get('app_icon_url');
|
||||
$this->aMenuGroups = ApplicationMenu::GetMenuGroups($oAppContext->GetAsHash());
|
||||
$this->oUserMenu = $oUserMenu;
|
||||
|
||||
$this->ComputeExpandedState();
|
||||
$this->ComputeUserData();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetAppRevisionNumber()
|
||||
{
|
||||
return $this->sAppRevisionNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetAppSquareIconUrl()
|
||||
{
|
||||
return $this->sAppSquareIconUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetAppFullIconUrl()
|
||||
{
|
||||
return $this->sAppFullIconUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetAppIconLink()
|
||||
{
|
||||
return $this->sAppIconLink;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function GetMenuGroups()
|
||||
{
|
||||
return $this->aMenuGroups;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function GetUserData()
|
||||
{
|
||||
return $this->aUserData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Combodo\iTop\Application\UI\Component\PopoverMenu\PopoverMenu
|
||||
*/
|
||||
public function GetUserMenu()
|
||||
{
|
||||
return $this->oUserMenu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the menu is expanded
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function IsExpanded()
|
||||
{
|
||||
return $this->bIsExpanded;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function GetSubBlocks()
|
||||
{
|
||||
return [$this->oUserMenu->GetId() => $this->oUserMenu];
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute if the menu is expanded or collapsed
|
||||
*
|
||||
* @return $this
|
||||
* @throws \CoreException
|
||||
* @throws \CoreUnexpectedValue
|
||||
* @throws \MySQLException
|
||||
*/
|
||||
protected function ComputeExpandedState()
|
||||
{
|
||||
$bIsExpanded = false;
|
||||
// Check if menu should be opened only if we re not in demo mode
|
||||
if (false === MetaModel::GetConfig()->Get('demo_mode'))
|
||||
{
|
||||
if (utils::ReadParam('force_menu_pane', null) === 0)
|
||||
{
|
||||
$bIsExpanded = false;
|
||||
}
|
||||
elseif (appUserPreferences::GetPref('menu_pane', 'closed') === 'opened')
|
||||
{
|
||||
$bIsExpanded = true;
|
||||
}
|
||||
}
|
||||
|
||||
$this->bIsExpanded = $bIsExpanded;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the user data displayed in the menu (organization, name, picture, ...)
|
||||
*
|
||||
* @return $this
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function ComputeUserData()
|
||||
{
|
||||
$aData = [
|
||||
'sOrganization' => UserRights::GetContactOrganizationFriendlyname(),
|
||||
'sFirstname' => UserRights::GetContactFirstname(),
|
||||
'sPictureUrl' => UserRights::GetContactPicture(),
|
||||
];
|
||||
|
||||
// Logon message
|
||||
$sLogonMessageDictCode = (UserRights::IsAdministrator()) ? 'UI:LoggedAsMessage+Admin' : 'UI:LoggedAsMessage';
|
||||
$aData['sLogonMessage'] = Dict::Format($sLogonMessageDictCode, UserRights::GetUser());
|
||||
|
||||
$this->aUserData = $aData;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user