N°1370 Portal AggregatePageBrick : integrate dashboard brick extension

SVN:trunk[5644]
This commit is contained in:
Pierre Goiffon
2018-04-12 14:28:41 +00:00
parent 80e6ba2d96
commit 24e669c65b
6 changed files with 297 additions and 0 deletions

View File

@@ -82,6 +82,11 @@ Dict::Add('EN US', 'English', 'English', array(
'Brick:Portal:UserProfile:Photo:Title' => 'Photo',
));
// AggregatePageBrick
Dict::Add('FR FR', 'French', 'Français', array(
'Brick:Portal:AggregatePage:DefaultTitle' => 'Dashboard',
));
// BrowseBrick brick
Dict::Add('EN US', 'English', 'English', array(
'Brick:Portal:Browse:Name' => 'Browse throught items',

View File

@@ -82,6 +82,11 @@ Dict::Add('FR FR', 'French', 'Français', array(
'Brick:Portal:UserProfile:Photo:Title' => 'Photo',
));
// AggregatePageBrick
Dict::Add('FR FR', 'French', 'Français', array(
'Brick:Portal:AggregatePage:DefaultTitle' => 'Tableau de bord',
));
// BrowseBrick brick
Dict::Add('FR FR', 'French', 'Français', array(
'Brick:Portal:Browse:Name' => 'Navigation dans les éléments',

View File

@@ -0,0 +1,138 @@
<?php
// Copyright (c) 2010-2018 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
// along with iTop. If not, see <http://www.gnu.org/licenses/>
//
namespace Combodo\iTop\Portal\Controller;
use Combodo\iTop\Portal\Helper\ApplicationHelper;
use Silex\Application;
use Symfony\Component\HttpFoundation\Request;
class AggregatePageBrickController
{
/**
* @param \Symfony\Component\HttpFoundation\Request $oRequest
* @param \Silex\Application $oApp
* @param string $sBrickId
*
* @return response
* @throws \Exception
*/
public function DisplayAction(Request $oRequest, Application $oApp, $sBrickId)
{
/** @var \Combodo\iTop\Portal\Brick\AggregatePageBrick $oBrick */
$oBrick = ApplicationHelper::GetLoadedBrickFromId($oApp, $sBrickId);
$aPortalInstanceBricks = $oApp['combodo.portal.instance.conf']['bricks'];
$aAggregatePageBricksConf = $oBrick->GetAggregatePageBricks();
$aAggregatePageBricks = $this->GetOrderedAggregatePageBricksObjectsById($aPortalInstanceBricks,
$aAggregatePageBricksConf);
$aTilesRendering = $this->GetBricksTileRendering($oRequest, $oApp, $aAggregatePageBricks);
$sLayoutTemplate = $oBrick->GetPageTemplatePath();
$aData = array(
'oBrick' => $oBrick,
'aggregatepage_bricks' => $aAggregatePageBricks,
'aTilesRendering' => $aTilesRendering,
);
$oResponse = $oApp['twig']->render($sLayoutTemplate, $aData);
return $oResponse;
}
/**
* @param \Combodo\iTop\Portal\Brick\PortalBrick[] $aPortalInstanceBricks
* @param array $aAggregatePageBricksConf
*
* @return array
* @throws \Exception
*/
private function GetOrderedAggregatePageBricksObjectsById($aPortalInstanceBricks, $aAggregatePageBricksConf)
{
$aAggregatePageBricks = array();
foreach ($aAggregatePageBricksConf as $sBrickId => $iBrickRank)
{
$oPortalBrick = $this->GetBrickFromId($aPortalInstanceBricks, $sBrickId);
if (!isset($oPortalBrick))
{
throw new \Exception("AggregatePageBrick : non existing brick '$sBrickId'");
}
$aAggregatePageBricks[] = $oPortalBrick;
}
return $aAggregatePageBricks;
}
/**
* @param \Combodo\iTop\Portal\Brick\PortalBrick[] $aBrickList
* @param string $sBrickId
*
* @return \Combodo\iTop\Portal\Brick\PortalBrick found brick using the given id, null if not found
*/
private function GetBrickFromId($aBrickList, $sBrickId)
{
$aFilteredBricks = array_filter(
$aBrickList,
function ($oSearchBrick) use ($sBrickId) {
return ($oSearchBrick->GetId() == $sBrickId);
}
);
$oFoundBrick = null;
if (count($aFilteredBricks) > 0)
{
$oFoundBrick = reset($aFilteredBricks);
}
return $oFoundBrick;
}
/**
* @param \Symfony\Component\HttpFoundation\Request $oRequest
* @param \Silex\Application $oApp
* @param \Combodo\iTop\Portal\Brick\PortalBrick[] $aBricks
*
* @return array rendering for each included tile (key = brick id, value = rendering)
*/
private function GetBricksTileRendering(Request $oRequest, Application $oApp, $aBricks)
{
$aTilesRendering = array();
foreach ($aBricks as $oBrick)
{
if ($oBrick->GetTileControllerAction() !== null)
{
$aControllerActionParts = explode('::', $oBrick->GetTileControllerAction());
if (count($aControllerActionParts) !== 2)
{
$oApp->abort(500,
'Tile controller action must be of form "\Namespace\ControllerClass::FunctionName" for brick "'.$oBrick->GetId().'"');
}
$sControllerName = $aControllerActionParts[0];
$sControllerAction = $aControllerActionParts[1];
$oController = new $sControllerName($oRequest, $oApp, $oBrick->GetId());
$aTilesRendering[$oBrick->GetId()] = $oController->$sControllerAction($oRequest, $oApp,
$oBrick->GetId());
}
}
return $aTilesRendering;
}
}

View File

@@ -0,0 +1,97 @@
<?php
// Copyright (c) 2010-2018 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
// along with iTop. If not, see <http://www.gnu.org/licenses/>
//
namespace Combodo\iTop\Portal\Brick;
use Combodo\iTop\DesignElement;
use Dict;
class AggregatePageBrick extends PortalBrick
{
const DEFAULT_DECORATION_CLASS_HOME = 'fa fa-dashboard';
const DEFAULT_DECORATION_CLASS_NAVIGATION_MENU = 'fa fa-dashboard fa-2x';
const DEFAULT_PAGE_TEMPLATE_PATH = 'itop-portal-base/portal/src/views/bricks/aggregate-page/layout.html.twig';
static $sRouteName = 'p_aggregatepage_brick';
/**
* @var string[] list of bricks to use, ordered by rank (key=id, value=rank)
*/
private $aAggregatePageBricks = array();
/**
* AggregatePageBrick constructor.
*/
function __construct()
{
parent::__construct();
$this->SetTitle(Dict::S('Brick:Portal:AggregatePage:DefaultTitle'));
}
/**
* @param \Combodo\iTop\DesignElement $oMDElement
*
* @return \Combodo\iTop\Portal\Brick\PortalBrick|void
* @throws \DOMFormatException
*/
public function LoadFromXml(DesignElement $oMDElement)
{
parent::LoadFromXml($oMDElement);
foreach ($oMDElement->GetNodes('./*') as $oBrickSubNode)
{
switch ($oBrickSubNode->nodeName)
{
case 'aggregate_page_bricks':
foreach ($oBrickSubNode->GetNodes('./aggregate_page_brick') as $oAggregatePageBrickNode)
{
if (!$oAggregatePageBrickNode->hasAttribute('id'))
{
throw new \DOMFormatException('AggregatePageBrick : must have an id attribute', null,
null, $oAggregatePageBrickNode);
}
$sBrickName = $oAggregatePageBrickNode->getAttribute('id');
$iBrickRank = static::DEFAULT_RANK;
$oOptionalNode = $oAggregatePageBrickNode->GetOptionalElement('rank');
if ($oOptionalNode !== null)
{
$iBrickRank = $oOptionalNode->GetText();
}
$this->aAggregatePageBricks[$sBrickName] = $iBrickRank;
}
}
}
asort($this->aAggregatePageBricks);
}
/**
* @return string[]
*/
public function GetAggregatePageBricks()
{
return $this->aAggregatePageBricks;
}
}

View File

@@ -0,0 +1,34 @@
<?php
// Copyright (c) 2010-2018 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
// along with iTop. If not, see <http://www.gnu.org/licenses/>
//
namespace Combodo\iTop\Portal\Router;
class AggregatePageBrickRouter extends AbstractRouter
{
static $aRoutes = array(
array(
'pattern' => '/aggregate-page/{sBrickId}',
'callback' => 'Combodo\\iTop\\Portal\\Controller\\AggregatePageBrickController::DisplayAction',
'bind' => 'p_aggregatepage_brick',
'asserts' => array(),
'values' => array()
),
);
}

View File

@@ -0,0 +1,18 @@
{# itop-portal-base/portal/src/views/bricks/aggregate-page/layout.html.twig #}
{% extends 'itop-portal-base/portal/src/views/bricks/layout.html.twig' %}
{% block pPageBodyClass %}{{ parent() }} page_aggregate_page_brick home{% endblock %}
{% block pMainHeaderTitle %}{{ oBrick.GetTitle()|dict_s }}{% endblock %}
{% block pMainContent %}
<section class="tiles_wrapper">
{% for brick in aggregatepage_bricks %}
{% if aTilesRendering[brick.GetId] is defined %}
{{ aTilesRendering[brick.GetId]|raw }}
{% else %}
{% include '' ~ brick.GetTileTemplatePath with {brick: brick} %}
{% endif %}
{% endfor %}
</section>
{% endblock %}