diff --git a/sources/application/WebPage/iTopWebPage.php b/sources/application/WebPage/iTopWebPage.php index f941d9c14b..6e6e49a9a6 100644 --- a/sources/application/WebPage/iTopWebPage.php +++ b/sources/application/WebPage/iTopWebPage.php @@ -19,6 +19,7 @@ use Combodo\iTop\Application\TwigBase\Twig\TwigHelper; +use Combodo\iTop\Application\UI\Base\Component\Alert\AlertFactory; use Combodo\iTop\Application\UI\Base\Component\Breadcrumbs\Breadcrumbs; use Combodo\iTop\Application\UI\Base\Component\Panel\PanelFactory; use Combodo\iTop\Application\UI\Base\iUIBlock; @@ -671,6 +672,7 @@ JS $sBannerHtml = ''; // Call the extensions to add content to the page, warning they can also add styles or scripts through as they have access to the \iTopWebPage + /** @var \iPageUIExtension $oExtensionInstance */ foreach (MetaModel::EnumPlugins('iPageUIExtension') as $oExtensionInstance) { $sBannerHtml .= $oExtensionInstance->GetBannerHtml($this); @@ -693,6 +695,7 @@ JS $oBanner = new UIContentBlock(); // Call the extensions to add content to the page, warning they can also add styles or scripts through as they have access to the \iTopWebPage + /** @var \iPageUIBlockExtension $oExtensionInstance */ foreach (MetaModel::EnumPlugins('iPageUIBlockExtension') as $oExtensionInstance) { $oBlock = $oExtensionInstance->GetBannerBlock(); @@ -717,63 +720,8 @@ JS { $sHeaderHtml = ''; - //TODO: NB the whole section needs to be refactored - - if (UserRights::IsAdministrator() && ExecutionKPI::IsEnabled()) - { - // TODO 3.0.0: Don't forget this dude! - $sHeaderHtml .= '
'.ExecutionKPI::GetDescription().'
'; - } - - // TODO 3.0.0: Don't forget this! - if (utils::IsArchiveMode()) - { - $sIcon = ''; - $this->AddApplicationMessage(Dict::S('UI:ArchiveMode:Banner'), $sIcon, Dict::S('UI:ArchiveMode:Banner+')); - } - - // TODO 3.0.0: Move this in the Header method - $sRestrictions = ''; - if (!MetaModel::DBHasAccess(ACCESS_ADMIN_WRITE)) - { - if (!MetaModel::DBHasAccess(ACCESS_ADMIN_WRITE)) - { - $sRestrictions = Dict::S('UI:AccessRO-All'); - } - } - elseif (!MetaModel::DBHasAccess(ACCESS_USER_WRITE)) - { - $sRestrictions = Dict::S('UI:AccessRO-Users'); - } - if (strlen($sRestrictions) > 0) - { - $sIcon = - << - - - -EOF; - - $sAdminMessage = trim(MetaModel::GetConfig()->Get('access_message')); - if (strlen($sAdminMessage) > 0) - { - $sRestrictions .= ' '.$sAdminMessage; - } - $this->AddApplicationMessage($sRestrictions, $sIcon); - } - - // TODO 3.0.0: Move this in the header method - $sApplicationMessages = ''; - foreach ($this->m_aMessages as $aMessage) - { - $sHtmlIcon = $aMessage['icon'] ? $aMessage['icon'] : ''; - $sHtmlMessage = $aMessage['message']; - $sTitleAttr = $aMessage['tip'] ? 'title="'.htmlentities($aMessage['tip'], ENT_QUOTES, self::PAGES_CHARSET).'"' : ''; - $sApplicationMessages .= '
'.$sHtmlIcon.''.$sHtmlMessage.'
'; - } - // Call the extensions to add content to the page, warning they can also add styles or scripts through as they have access to the \iTopWebPage + /** @var \iPageUIExtension $oExtensionInstance */ foreach (MetaModel::EnumPlugins('iPageUIExtension') as $oExtensionInstance) { $sHeaderHtml .= $oExtensionInstance->GetNorthPaneHtml($this); @@ -782,10 +730,71 @@ EOF; return $sHeaderHtml; } + /** + * Render the header UIBlock which can come from both iTop itself and from extensions + * + * @see \iPageUIExtension::GetHeaderHtml() + * @internal + * + * @return iUIBlock + * @since 3.0.0 + */ protected function RenderHeaderBlock() { $oHeader = new UIContentBlock(); + + // Log KPIs + if (UserRights::IsAdministrator() && ExecutionKPI::IsEnabled()){ + $oKPIAlert = AlertFactory::MakeForInformation('KPIs', ExecutionKPI::GetDescription()) + ->SetIsClosable(false) + ->SetIsCollapsible(false); + $oHeader->AddSubBlock($oKPIAlert); + } + + // Archive mode + if (utils::IsArchiveMode()) { + $oArchiveAlert = AlertFactory::MakeForInformation(Dict::S('UI:ArchiveMode:Banner'), '') + ->SetIsClosable(false) + ->SetIsCollapsible(false); + $oHeader->AddSubBlock($oArchiveAlert); + } + + // Access mode + $sRestrictionMessage =''; + if (!MetaModel::DBHasAccess(ACCESS_ADMIN_WRITE)) { + $sRestrictionMessage = Dict::S('UI:AccessRO-All'); + } + elseif (!MetaModel::DBHasAccess(ACCESS_USER_WRITE)) { + $sRestrictionMessage = Dict::S('UI:AccessRO-Users'); + } + + if (!empty($sRestrictionMessage)) { + $sAdminMessage = trim(MetaModel::GetConfig()->Get('access_message')); + $sRestrictionTitle = empty($sAdminMessage) ? '' : $sAdminMessage; + + $oRestrictionAlert = AlertFactory::MakeForWarning($sRestrictionTitle, $sRestrictionMessage) + ->SetIsClosable(false) + ->SetIsCollapsible(false); + $oHeader->AddSubBlock($oRestrictionAlert); + } + + // Misc. app. messages + foreach ($this->m_aMessages as $aMessage) + { + $sMessageForHtml = $aMessage['message']; + if($aMessage['tip']) { + $sTooltipForHtml = utils::HtmlEntities($aMessage['tip']); + $sMessageForHtml = <<$sMessageForHtml +HTML; + } + // Note: Message icon has been ignored during 3.0 migration. If we want them back, we should find a proper way to integrate them, not just putting an tag + $oAppMessageAlert = AlertFactory::MakeForInformation('', $sMessageForHtml); + $oHeader->AddSubBlock($oAppMessageAlert); + } + // Call the extensions to add content to the page, warning they can also add styles or scripts through as they have access to the \iTopWebPage + /** @var \iPageUIBlockExtension $oExtensionInstance */ foreach (MetaModel::EnumPlugins('iPageUIBlockExtension') as $oExtensionInstance) { $oBlock = $oExtensionInstance->GetNorthPaneBlock(); @@ -811,6 +820,7 @@ EOF; $sFooterHtml = ''; // Call the extensions to add content to the page, warning they can also add styles or scripts through as they have access to the \iTopWebPage + /** @var \iPageUIExtension $oExtensionInstance */ foreach (MetaModel::EnumPlugins('iPageUIExtension') as $oExtensionInstance) { $sFooterHtml .= $oExtensionInstance->GetSouthPaneHtml($this); } @@ -832,6 +842,7 @@ EOF; $oFooter = new UIContentBlock(); // Call the extensions to add content to the page, warning they can also add styles or scripts through as they have access to the \iTopWebPage + /** @var \iPageUIBlockExtension $oExtensionInstance */ foreach (MetaModel::EnumPlugins('iPageUIBlockExtension') as $oExtensionInstance) { $oBlock = $oExtensionInstance->GetSouthPaneBlock(); if ($oBlock) { diff --git a/templates/pages/backoffice/extension-blocks/banner.html.twig b/templates/pages/backoffice/extension-blocks/banner.html.twig index 6a2f20552b..cd4c48fd14 100644 --- a/templates/pages/backoffice/extension-blocks/banner.html.twig +++ b/templates/pages/backoffice/extension-blocks/banner.html.twig @@ -1,12 +1,10 @@ {# @copyright Copyright (C) 2010-2020 Combodo SARL #} {# @license http://opensource.org/licenses/AGPL-3.0 #} {% apply spaceless %} - -
+
{% if aLayouts.sBanner is not empty %} {{ aLayouts.sBanner|raw }} {% endif %} {{ render_block(aLayouts.oBanner, {aPage: aPage}) }}
- {% endapply %} \ No newline at end of file diff --git a/templates/pages/backoffice/extension-blocks/header.html.twig b/templates/pages/backoffice/extension-blocks/header.html.twig index d5eab52736..e4bf276f87 100644 --- a/templates/pages/backoffice/extension-blocks/header.html.twig +++ b/templates/pages/backoffice/extension-blocks/header.html.twig @@ -1,12 +1,10 @@ {# @copyright Copyright (C) 2010-2020 Combodo SARL #} {# @license http://opensource.org/licenses/AGPL-3.0 #} {% apply spaceless %} -
{% if aLayouts.sHeader is not empty %} {{ aLayouts.sHeader|raw }} {% endif %} {{ render_block(aLayouts.oHeader, {aPage: aPage}) }}
- {% endapply %} \ No newline at end of file