dashboard.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. Dashboard
  2. =========
  3. The Dashboard is the main landing page. By default it lists your mapped models,
  4. as defined by your ``Admin`` services. This is useful to help you start using
  5. ``SonataAdminBundle`` right away, but there is much more that you can do to take
  6. advantage of the Dashboard.
  7. The Dashboard is, by default, available at ``/admin/dashboard``, which is handled by
  8. the ``SonataAdminBundle:Core:dashboard`` controller action. The default view file for
  9. this action is ``SonataAdminBundle:Core:dashboard.html.twig``, but you can change
  10. this in your ``config.yml``:
  11. .. configuration-block::
  12. .. code-block:: yaml
  13. # app/config/config.yml
  14. sonata_admin:
  15. templates:
  16. dashboard: SonataAdminBundle:Core:dashboard.html.twig
  17. .. note::
  18. This view, like most of the ``SonataAdminBundle`` views, extends a global
  19. template file, which also contains significant parts to the page. More information
  20. about this is available in the :doc:`templates` chapter.
  21. Blocks
  22. ------
  23. The Dashboard is actually built using ``Blocks`` from ``SonataBlockBundle``. You
  24. can learn more about this bundle and how to build your own Blocks on the
  25. `SonataBlock documentation page`_.
  26. The ``Admin`` list block
  27. ------------------------
  28. The ``Admin`` list is a ``Block`` that fetches information from the ``Admin`` service's
  29. ``Pool`` and prints it in the nicely formated list you have on your default Dashboard.
  30. The ``Admin`` list is defined by the ``sonata.admin.block.admin_list`` service, which is
  31. implemented by the ``Block\AdminListBlockService`` class. It is then rendered using the
  32. ``SonataAdminBundle:Block:block_admin_list.html.twig`` template file.
  33. Feel free to take a look at these files. You'll find the code rather short and easy to
  34. understand, and it will be a great help when implementing your own blocks.
  35. Configuring the ``Admin`` list
  36. ------------------------------
  37. As you probably noticed by now, the ``Admin`` list groups ``Admin`` mappings together.
  38. There are several ways in which you can configure these groups.
  39. Using the ``Admin`` service declaration
  40. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  41. The first, and most commonly used, method is to set a group when defining your ``Admin``
  42. services:
  43. .. configuration-block::
  44. .. code-block:: xml
  45. <service id="sonata.admin.post" class="Acme\DemoBundle\Admin\PostAdmin">
  46. <tag name="sonata.admin" manager_type="orm"
  47. group="Content"
  48. label="Post"/>
  49. <argument />
  50. <argument>Acme\DemoBundle\Entity\Post</argument>
  51. <argument />
  52. </service>
  53. .. code-block:: yaml
  54. services:
  55. sonata.admin.post:
  56. class: Acme\DemoBundle\Admin\PostAdmin
  57. tags:
  58. - name: sonata.admin
  59. manager_type: orm
  60. group: "Content"
  61. label: "Post"
  62. arguments:
  63. - ~
  64. - Acme\DemoBundle\Entity\Post
  65. - ~
  66. In these examples, notice the ``group`` tag, stating that this particular ``Admin``
  67. service belongs to the ``Content`` group.
  68. .. configuration-block::
  69. .. code-block:: xml
  70. <service id="sonata.admin.post" class="Acme\DemoBundle\Admin\PostAdmin">
  71. <tag name="sonata.admin" manager_type="orm"
  72. group="acme.admin.group.content"
  73. label="acme.admin.model.post" label_catalogue="AcmeDemoBundle"/>
  74. <argument />
  75. <argument>Acme\DemoBundle\Entity\Post</argument>
  76. <argument />
  77. </service>
  78. .. code-block:: yaml
  79. services:
  80. sonata.admin.post:
  81. class: Acme\DemoBundle\Admin\PostAdmin
  82. tags:
  83. - name: sonata.admin
  84. manager_type: orm
  85. group: "acme.admin.group.content"
  86. label: "acme.admin.model.post"
  87. label_catalogue: "AcmeDemoBundle"
  88. arguments:
  89. - ~
  90. - Acme\DemoBundle\Entity\Post
  91. - ~
  92. In this example, the labels are translated by ``AcmeDemoBundle``, using the given
  93. ``label_catalogue``. So, you can use the above examples to support multiple languages
  94. in your project.
  95. .. note::
  96. You can use parameters (e.g. ``%acme_admin.group_post%``) for the group names
  97. in either scenario.
  98. Using the ``config.yml``
  99. ^^^^^^^^^^^^^^^^^^^^^^^^
  100. You can also configure the ``Admin`` list in your ``config.yml`` file. This
  101. configuration method overrides any settings defined in the Admin service
  102. declarations.
  103. .. configuration-block::
  104. .. code-block:: yaml
  105. # app/config/config.yml
  106. sonata_admin:
  107. dashboard:
  108. groups:
  109. acme.admin.group.content:
  110. label: acme.admin.group.content
  111. label_catalogue: AcmeDemoBundle
  112. items:
  113. - sonata.admin.post
  114. acme.admin.group.blog:
  115. items: ~
  116. item_adds:
  117. - sonata.admin.page
  118. roles: [ ROLE_ONE, ROLE_TWO ]
  119. acme.admin.group.misc: ~
  120. .. note::
  121. This is an academic, full configuration, example. In real cases, you will usually
  122. not need to use all the displayed options. To use a default value for any setting
  123. either leave out that key or use the ``~`` value for that option.
  124. This configuration specifies that the ``acme.admin.group.content`` group uses the
  125. ``acme.admin.group.content`` label, which is translated using the ``AcmeDemoBundle``
  126. translation catalogue (the same label and translation configuration that we declared
  127. previously, in the service definition example).
  128. It also states that the ``acme.admin.group.content`` group contains just the
  129. ``sonata.admin.post`` ``Admin`` mapping, meaning that any other ``Admin`` services
  130. declared as belonging to this group will not be displayed here.
  131. Secondly, we declare a ``acme.admin.group.blog`` group as having all its default items
  132. (i.e. the ones specified in the ``Admin`` service declarations), plus an *additional*
  133. ``sonata.admin.page`` mapping, that was not initially part of this group.
  134. We also use the ``roles`` option here, which means that only users with the ``ROLE_ONE``
  135. or ``ROLE_TWO`` privileges will be able to see this group, as opposed to the default setting
  136. which allows everyone to see a given group. Users with ``ROLE_SUPER_ADMIN`` are always
  137. able to see groups that would otherwise be hidden by this configuration option.
  138. The third group, ``acme.admin.group.misc``, is set up as a group which uses all its
  139. default values, as declared in the service declarations.
  140. Adding more Blocks
  141. ------------------
  142. Like we said before, the Dashboard comes with a default ``Admin`` list block, but
  143. you can create and add more blocks to it.
  144. .. figure:: ../images/dashboard.png
  145. :align: center
  146. :alt: Dashboard
  147. :width: 500
  148. In this screenshot, in addition to the default ``Admin`` list block on the left, we added
  149. a text block and RSS feed block on the right. The configuration for this scenario would be:
  150. .. configuration-block::
  151. .. code-block:: yaml
  152. # app/config/config.yml
  153. sonata_admin:
  154. dashboard:
  155. blocks:
  156. -
  157. position: left
  158. type: sonata.admin.block.admin_list
  159. -
  160. position: right
  161. type: sonata.block.service.text
  162. settings:
  163. content: >
  164. <h2>Welcome to the Sonata Admin</h2>
  165. <p>This is a <code>sonata.block.service.text</code> from the Block
  166. Bundle, you can create and add new block in these area by configuring
  167. the <code>sonata_admin</code> section.</p> <br /> For instance, here
  168. a RSS feed parser (<code>sonata.block.service.rss</code>):
  169. -
  170. position: right
  171. type: sonata.block.service.rss
  172. roles: [POST_READER]
  173. settings:
  174. title: Sonata Project's Feeds
  175. url: http://sonata-project.org/blog/archive.rss
  176. .. note::
  177. Blocks may accept/require additional settings to be passed in order to
  178. work properly. Refer to the associated documentation/implementation to
  179. get more information on each block's options and requirements.
  180. You can also configure the ``roles`` section to configure users that can
  181. view the block.
  182. Display two ``Admin`` list blocks with different dashboard groups
  183. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  184. The same block can have multiple instances, and be displayed multiple times
  185. across the Dashboard using different configuration settings for each instance.
  186. A particular example is the ``Admin`` list block, which can be configured to
  187. suit this scenario.
  188. .. configuration-block::
  189. .. code-block:: yaml
  190. # app/config/config.yml
  191. sonata_admin:
  192. dashboard:
  193. blocks:
  194. # display two dashboard blocks
  195. -
  196. position: left
  197. type: sonata.admin.block.admin_list
  198. settings:
  199. groups: [sonata_page1, sonata_page2]
  200. -
  201. position: right
  202. type: sonata.admin.block.admin_list
  203. settings:
  204. groups: [sonata_page3]
  205. groups:
  206. sonata_page1:
  207. items:
  208. - sonata.page.admin.myitem1
  209. sonata_page2:
  210. items:
  211. - sonata.page.admin.myitem2
  212. - sonata.page.admin.myitem3
  213. sonata_page3:
  214. items:
  215. - sonata.page.admin.myitem4
  216. In this example, you would have two ``admin_list`` blocks on your dashboard, each
  217. of them containing just the respectively configured groups.
  218. .. _`SonataBlock documentation page`: http://sonata-project.org/bundles/block/master/doc/index.html
  219. Dashboard Layout
  220. ~~~~~~~~~~~~~~~~
  221. Supported positions right now are the following:
  222. * top
  223. * left
  224. * center
  225. * right
  226. * bottom
  227. The layout is as follows:
  228. TOPTOPTOPTOPTOPTOPTOPTOPTOPTOPTOPTOP
  229. LEFTLEFTLEF CENTERCENTE RIGHTRIGHTRI
  230. LEFTLEFTLEF CENTERCENTE RIGHTRIGHTRI
  231. LEFTLEFTLEF CENTERCENTE RIGHTRIGHTRI
  232. BOTTOMBOTTOMBOTTOMBOTTOMBOTTOMBOTTOM
  233. On ``top`` and ``bottom`` positions, you can also specify an optionnal ``class`` option to set the width of the block.
  234. .. configuration-block::
  235. .. code-block:: yaml
  236. # app/config/config.yml
  237. sonata_admin:
  238. dashboard:
  239. blocks:
  240. # display one dashboard block in the top zone with a col-md-6 HTML class
  241. -
  242. position: top
  243. class: col-md-6
  244. type: sonata.admin.block.admin_list