Skip to content

Commit

Permalink
Merge pull request sonata-project#2084 from Bladrak/dashboardLayout
Browse files Browse the repository at this point in the history
Added support for top and bottom lines on admin dashboard
  • Loading branch information
rande committed Apr 23, 2014
2 parents 972ceda + 0f19530 commit ff936ec
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 22 deletions.
14 changes: 13 additions & 1 deletion Controller/CoreController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,22 @@ protected function getBaseTemplate()
*/
public function dashboardAction()
{
$blocks = array(
'top' => array(),
'left' => array(),
'center' => array(),
'right' => array(),
'bottom' => array()
);

foreach ($this->container->getParameter('sonata.admin.configuration.dashboard_blocks') as $block) {
$blocks[$block['position']][] = $block;
}

return $this->render($this->getAdminPool()->getTemplate('dashboard'), array(
'base_template' => $this->getBaseTemplate(),
'admin_pool' => $this->container->get('sonata.admin.pool'),
'blocks' => $this->container->getParameter('sonata.admin.configuration.dashboard_blocks')
'blocks' => $blocks
));
}

Expand Down
1 change: 1 addition & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public function getConfigTreeBuilder()
->prototype('variable')->defaultValue(array())->end()
->end()
->scalarNode('position')->defaultValue('right')->end()
->scalarNode('class')->defaultValue('col-md-4')->end()
->end()
->end()
->end()
Expand Down
37 changes: 37 additions & 0 deletions Resources/doc/reference/dashboard.rst
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,40 @@ In this example, you would have two ``admin_list`` blocks on your dashboard, eac
of them containing just the respectively configured groups.

.. _`SonataBlock documentation page`: http://sonata-project.org/bundles/block/master/doc/index.html

Dashboard Layout
~~~~~~~~~~~~~~~~

Supported positions right now are the following:

* top
* left
* center
* right
* bottom

The layout is as follows:

TOPTOPTOPTOPTOPTOPTOPTOPTOPTOPTOPTOP

LEFTLEFTLEF CENTERCENTE RIGHTRIGHTRI
LEFTLEFTLEF CENTERCENTE RIGHTRIGHTRI
LEFTLEFTLEF CENTERCENTE RIGHTRIGHTRI

BOTTOMBOTTOMBOTTOMBOTTOMBOTTOMBOTTOM

On ``top`` and ``bottom`` positions, you can also specify an optionnal ``class`` option to set the width of the block.

.. configuration-block::

.. code-block:: yaml
# app/config/config.yml
sonata_admin:
dashboard:
blocks:
# display one dashboard block in the top zone with a col-md-6 HTML class
-
position: top
class: col-md-6
type: sonata.admin.block.admin_list
53 changes: 32 additions & 21 deletions Resources/views/Core/dashboard.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,52 @@ file that was distributed with this source code.

{{ sonata_block_render_event('sonata.admin.dashboard.top', { 'admin_pool': admin_pool }) }}

{% if blocks.top|length > 0 %}
<div class="row">
{% for block in blocks.top %}
<div class="{{ block.class }}">
{{ sonata_block_render({ 'type': block.type, 'settings': block.settings}) }}
</div>
{% endfor %}
</div>
{% endif %}

<div class="row">
{% set has_center = false %}
{% for block in blocks %}
{% if block.position == 'center' %}
{% set has_center = true %}
{% endif %}
{% endfor %}

<div class="{% if has_center %}col-md-3{% else %}col-md-6{% endif %}">
{% for block in blocks %}
{% if block.position == 'left' %}
{{ sonata_block_render({ 'type': block.type, 'settings': block.settings}) }}
{% endif %}

<div class="{% if blocks.center|length > 0 %}col-md-4{% else %}col-md-6{% endif %}">
{% for block in blocks.left %}
{{ sonata_block_render({ 'type': block.type, 'settings': block.settings}) }}
{% endfor %}
</div>

{% if has_center %}
{% if blocks.center|length > 0 %}
<div class="col-md-4">
{% for block in blocks %}
{% if block.position == 'center' %}
{{ sonata_block_render({ 'type': block.type, 'settings': block.settings}) }}
{% endif %}
{% for block in blocks.center %}
{{ sonata_block_render({ 'type': block.type, 'settings': block.settings}) }}
{% endfor %}
</div>
{% endif %}

<div class="{% if has_center %}col-md-4{% else %}col-md-6{% endif %}">
{% for block in blocks %}
{% if block.position == 'right' %}
{{ sonata_block_render({ 'type': block.type, 'settings': block.settings}) }}
{% endif %}
<div class="{% if blocks.center|length > 0 %}col-md-4{% else %}col-md-6{% endif %}">
{% for block in blocks.right %}
{{ sonata_block_render({ 'type': block.type, 'settings': block.settings}) }}
{% endfor %}
</div>
</div>

{% if blocks.bottom|length > 0 %}
<div class="row">
{% for block in blocks.bottom %}
<div class="{{ block.class }}">
{{ sonata_block_render({ 'type': block.type, 'settings': block.settings}) }}
</div>
{% endfor %}
</div>
{% endif %}



{{ sonata_block_render_event('sonata.admin.dashboard.bottom', { 'admin_pool': admin_pool }) }}

{% endblock %}

0 comments on commit ff936ec

Please sign in to comment.