mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
N°1370 Portal ManageBrick : add "display_modes" XML node to set the display modes in brick tile and details views
SVN:trunk[5643]
This commit is contained in:
@@ -53,6 +53,9 @@ class ManageBrick extends PortalBrick
|
||||
protected $aFields;
|
||||
protected $aExportFields;
|
||||
protected $bShowTabCounts;
|
||||
/**
|
||||
* @var string default display mode for the brick's tile
|
||||
*/
|
||||
protected $sDisplayType;
|
||||
protected $iGroupLimit;
|
||||
protected $bGroupShowOthers;
|
||||
@@ -62,38 +65,47 @@ class ManageBrick extends PortalBrick
|
||||
'decorationCssClass' => 'fa fa-id-card-o fa-2x',
|
||||
'tileTemplate' => 'itop-portal-base/portal/src/views/bricks/manage/tile-badge.html.twig',
|
||||
'layoutTemplate' => 'itop-portal-base/portal/src/views/bricks/manage/layout-table.html.twig',
|
||||
'layoutDisplayType' => 'default',
|
||||
'layoutDisplayType' => ManageBrick::DISPLAY_MODE_TABLE,
|
||||
'need_details' => true,
|
||||
),
|
||||
'top-list' => array(
|
||||
'decorationCssClass' => 'fa fa-signal fa-rotate-270 fa-2x',
|
||||
'tileTemplate' => 'itop-portal-base/portal/src/views/bricks/manage/tile-top-list.html.twig',
|
||||
'layoutTemplate' => 'itop-portal-base/portal/src/views/bricks/manage/layout-table.html.twig',
|
||||
'layoutDisplayType' => 'default',
|
||||
'layoutDisplayType' => ManageBrick::DISPLAY_MODE_TABLE,
|
||||
'need_details' => true,
|
||||
),
|
||||
'pie-chart' => array(
|
||||
'decorationCssClass' => 'fa fa-pie-chart fa-2x',
|
||||
'tileTemplate' => 'itop-portal-base/portal/src/views/bricks/manage/tile-chart.html.twig',
|
||||
'layoutTemplate' => 'itop-portal-base/portal/src/views/bricks/manage/layout-chart.html.twig',
|
||||
'layoutDisplayType' => 'pie-chart',
|
||||
'layoutDisplayType' => ManageBrick::DISPLAY_MODE_PIE,
|
||||
'need_details' => false,
|
||||
),
|
||||
'bar-chart' => array(
|
||||
'decorationCssClass' => 'fa fa-bar-chart fa-2x',
|
||||
'tileTemplate' => 'itop-portal-base/portal/src/views/bricks/manage/tile-chart.html.twig',
|
||||
'layoutTemplate' => 'itop-portal-base/portal/src/views/bricks/manage/layout-chart.html.twig',
|
||||
'layoutDisplayType' => 'bar-chart',
|
||||
'layoutDisplayType' => ManageBrick::DISPLAY_MODE_BAR,
|
||||
'need_details' => false,
|
||||
),
|
||||
'default' => array(
|
||||
'decorationCssClass' => 'fa fa-pencil-square fa-2x',
|
||||
'tileTemplate' => self::DEFAULT_TILE_TEMPLATE_PATH,
|
||||
'layoutTemplate' => 'itop-portal-base/portal/src/views/bricks/manage/layout-table.html.twig',
|
||||
'layoutDisplayType' => 'default',
|
||||
'layoutDisplayType' => ManageBrick::DISPLAY_MODE_TABLE,
|
||||
'need_details' => true,
|
||||
),
|
||||
);
|
||||
protected $aAvailableDisplayModes = array();
|
||||
const DISPLAY_MODE_TABLE = 'default';
|
||||
const DISPLAY_MODE_PIE = 'pie-chart';
|
||||
const DISPLAY_MODE_BAR = 'bar-chart';
|
||||
const DISPLAY_MODES_ALLOWED = array(
|
||||
ManageBrick::DISPLAY_MODE_TABLE,
|
||||
ManageBrick::DISPLAY_MODE_PIE,
|
||||
ManageBrick::DISPLAY_MODE_BAR
|
||||
);
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -217,20 +229,6 @@ class ManageBrick extends PortalBrick
|
||||
return $this->bGroupShowOthers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function ListLayoutDisplayTypes()
|
||||
{
|
||||
$aLayoutDisplayTypes = array();
|
||||
foreach ($this->aPresentationData as $aPresentationDatum)
|
||||
{
|
||||
$aLayoutDisplayTypes[$aPresentationDatum['layoutDisplayType']] = true;
|
||||
}
|
||||
|
||||
return array_keys($aLayoutDisplayTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the oql of the brick
|
||||
*
|
||||
@@ -434,6 +432,19 @@ class ManageBrick extends PortalBrick
|
||||
return (isset($this->aGrouping['areas'])) ? $this->aGrouping['areas'] : false;
|
||||
}
|
||||
|
||||
public function AddAvailableDisplayMode($sModeId)
|
||||
{
|
||||
$this->aAvailableDisplayModes[] = $sModeId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function GetAvailablesDisplayModes()
|
||||
{
|
||||
return $this->aAvailableDisplayModes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true is the groupings $sGroupingName properties exists and is of the form attribute => attribute_code.
|
||||
* This is supposed to be called by the IsGroupingTabsByDistinctValues / IsGroupingAreasByDistinctValues function.
|
||||
@@ -527,11 +538,39 @@ class ManageBrick extends PortalBrick
|
||||
$this->SetOpeningMode($sOpeningMode);
|
||||
break;
|
||||
|
||||
case 'display_type':
|
||||
$this->sDisplayType = $oBrickSubNode->GetText();
|
||||
$aDisplayParameterForType = $this->GetPresentationDataForDisplayType($this->sDisplayType);
|
||||
$this->SetTileTemplatePath($aDisplayParameterForType['tileTemplate']);
|
||||
$this->SetPageTemplatePath($aDisplayParameterForType['layoutTemplate']);
|
||||
case 'display_modes':
|
||||
foreach ($oBrickSubNode->GetNodes('./*') as $oDisplayNode)
|
||||
{
|
||||
switch ($oDisplayNode->nodeName)
|
||||
{
|
||||
case 'availables';
|
||||
foreach ($oDisplayNode->childNodes as $oModeNode)
|
||||
{
|
||||
if (!$oModeNode->hasAttribute('id'))
|
||||
{
|
||||
throw new DOMFormatException('ManageBrick : display mode must have a unique ID attribute',
|
||||
null, null, $oModeNode);
|
||||
}
|
||||
|
||||
$sModeId = $oModeNode->getAttribute('id');
|
||||
if (!in_array($sModeId, ManageBrick::DISPLAY_MODES_ALLOWED))
|
||||
{
|
||||
throw new DOMFormatException('ManageBrick : display mode has an invalid value',
|
||||
null, null, $oModeNode);
|
||||
}
|
||||
|
||||
$this->AddAvailableDisplayMode($sModeId);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'default';
|
||||
$this->sDisplayType = $oDisplayNode->nodeValue;
|
||||
$aDisplayParameterForType = $this->GetPresentationDataForDisplayType($this->sDisplayType);
|
||||
$this->SetTileTemplatePath($aDisplayParameterForType['tileTemplate']);
|
||||
$this->SetPageTemplatePath($aDisplayParameterForType['layoutTemplate']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'fields':
|
||||
@@ -653,6 +692,19 @@ class ManageBrick extends PortalBrick
|
||||
throw new DOMFormatException('BrowseBrick : must have a valid <class|oql> tag', null, null, $oMDElement);
|
||||
}
|
||||
|
||||
// Display modes : at least one selected
|
||||
$sDefaultDetailDisplayMode = (isset($this->sDisplayType))
|
||||
? $this->aPresentationData[$this->sDisplayType]['layoutDisplayType']
|
||||
: 'default';
|
||||
$bHasAvailableDisplayModes = (count($this->GetAvailablesDisplayModes()) > 0);
|
||||
$bIsDefaultDisplayModeInAvailableModes = in_array($sDefaultDetailDisplayMode,
|
||||
$this->GetAvailablesDisplayModes());
|
||||
if (!$bHasAvailableDisplayModes || (!$bIsDefaultDisplayModeInAvailableModes))
|
||||
{
|
||||
// legacy : setting to default
|
||||
$this->AddAvailableDisplayMode($sDefaultDetailDisplayMode);
|
||||
}
|
||||
|
||||
// Checking if specified fields, if not we put those from the details zlist
|
||||
if (empty($this->aFields))
|
||||
{
|
||||
|
||||
@@ -4,14 +4,16 @@
|
||||
{% block pMainHeaderTitle %}{{ oBrick.GetTitle()|dict_s }} ({{ iCount }}) {% endblock %}
|
||||
|
||||
{% block pMainHeaderActions %}
|
||||
<div class="btn-group btn_group_explicit">
|
||||
{% for sDisplay in oBrick.ListLayoutDisplayTypes %}
|
||||
<a href="{{ app.url_generator.generate('p_manage_brick', {'sBrickId': sBrickId, 'sDisplayType': sDisplay}) }}{% if app['combodo.portal.instance.routes'][oBrick.GetRouteName]['hash'] is defined %}#{{ app['combodo.portal.instance.routes'][oBrick.GetRouteName]['hash'] }}{% endif %}"
|
||||
id="btn_tab_for_{{ sDisplay }}"
|
||||
class="btn btn-default {% if sDisplay == oBrick.GetPresentationDataForDisplayType(sDisplayType).layoutDisplayType %}active{% endif %}">
|
||||
{{ ('Brick:Portal:Manage:DisplayType:' ~ sDisplay)|dict_s }}
|
||||
</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% if oBrick.GetAvailablesDisplayModes|length > 1 %}
|
||||
<div class="btn-group btn_group_explicit">
|
||||
{% for sDisplay in oBrick.GetAvailablesDisplayModes %}
|
||||
<a href="{{ app.url_generator.generate('p_manage_brick', {'sBrickId': sBrickId, 'sDisplayType': sDisplay}) }}{% if app['combodo.portal.instance.routes'][oBrick.GetRouteName]['hash'] is defined %}#{{ app['combodo.portal.instance.routes'][oBrick.GetRouteName]['hash'] }}{% endif %}"
|
||||
id="btn_tab_for_{{ sDisplay }}"
|
||||
class="btn btn-default {% if sDisplay == oBrick.GetPresentationDataForDisplayType(sDisplayType).layoutDisplayType %}active{% endif %}">
|
||||
{{ ('Brick:Portal:Manage:DisplayType:' ~ sDisplay)|dict_s }}
|
||||
</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
|
||||
@@ -1173,6 +1173,12 @@
|
||||
<title>
|
||||
<default>Brick:Portal:OngoingRequests:Title</default>
|
||||
</title>
|
||||
<display_modes>
|
||||
<availables>
|
||||
<mode id="default"/>
|
||||
</availables>
|
||||
<default>default</default>
|
||||
</display_modes>
|
||||
<description>Brick:Portal:OngoingRequests:Title+</description>
|
||||
<decoration_class>
|
||||
<default>fc fc-ongoing-request fc-2x</default>
|
||||
@@ -1232,6 +1238,12 @@
|
||||
<title>
|
||||
<default>Brick:Portal:ClosedRequests:Title</default>
|
||||
</title>
|
||||
<display_modes>
|
||||
<availables>
|
||||
<mode id="default"/>
|
||||
</availables>
|
||||
<default>default</default>
|
||||
</display_modes>
|
||||
<description></description>
|
||||
<decoration_class>
|
||||
<default>fc fc-closed-request fc-2x</default>
|
||||
|
||||
Reference in New Issue
Block a user