Kaynağa Gözat

Added support for top and bottom lines on admin dashboard

Hugo Briand 11 yıl önce
ebeveyn
işleme
53c464186b

+ 13 - 1
Controller/CoreController.php

@@ -53,10 +53,22 @@ class CoreController extends Controller
      */
      */
     public function dashboardAction()
     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(
         return $this->render($this->getAdminPool()->getTemplate('dashboard'), array(
             'base_template'   => $this->getBaseTemplate(),
             'base_template'   => $this->getBaseTemplate(),
             'admin_pool'      => $this->container->get('sonata.admin.pool'),
             'admin_pool'      => $this->container->get('sonata.admin.pool'),
-            'blocks'          => $this->container->getParameter('sonata.admin.configuration.dashboard_blocks')
+            'blocks'          => $blocks
         ));
         ));
     }
     }
 
 

+ 21 - 0
Resources/doc/reference/dashboard.rst

@@ -274,3 +274,24 @@ In this example, you would have two ``admin_list`` blocks on your dashboard, eac
 of them containing just the respectively configured groups.
 of them containing just the respectively configured groups.
 
 
 .. _`SonataBlock documentation page`:  http://sonata-project.org/bundles/block/master/doc/index.html
 .. _`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

+ 34 - 21
Resources/views/Core/dashboard.html.twig

@@ -17,41 +17,54 @@ file that was distributed with this source code.
 
 
     {{ sonata_block_render_event('sonata.admin.dashboard.top', { 'admin_pool': admin_pool }) }}
     {{ sonata_block_render_event('sonata.admin.dashboard.top', { 'admin_pool': admin_pool }) }}
 
 
+    {% if blocks.top|length > 0 %}
+        {% set class = 'col-md-' ~ 12 // blocks.top|length %}
+        <div class="row">
+            {% for block in blocks.top %}
+                <div class="{{ class }}">
+                    {{ sonata_block_render({ 'type': block.type, 'settings': block.settings}) }}
+                </div>
+            {% endfor %}
+        </div>
+    {% endif %}
+
     <div class="row">
     <div class="row">
         {% set has_center = false %}
         {% 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-3{% else %}col-md-6{% endif %}">
+            {% for block in blocks.left %}
+                {{ sonata_block_render({ 'type': block.type, 'settings': block.settings}) }}
             {% endfor %}
             {% endfor %}
         </div>
         </div>
 
 
-        {% if has_center %}
+        {% if blocks.center|length > 0 %}
             <div class="col-md-4">
             <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 %}
                 {% endfor %}
             </div>
             </div>
         {% endif %}
         {% 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 %}
             {% endfor %}
         </div>
         </div>
     </div>
     </div>
 
 
+    {% if blocks.bottom|length > 0 %}
+        {% set class = 'col-md-' ~ 12 // blocks.bottom|length %}
+        <div class="row">
+            {% for block in blocks.bottom %}
+                <div class="{{ 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 }) }}
     {{ sonata_block_render_event('sonata.admin.dashboard.bottom', { 'admin_pool': admin_pool }) }}
 
 
 {% endblock %}
 {% endblock %}