Skip to content

Commit

Permalink
Improve tree view
Browse files Browse the repository at this point in the history
  • Loading branch information
plouc committed Apr 23, 2014
1 parent 5b5307a commit 2fbd2e1
Show file tree
Hide file tree
Showing 16 changed files with 410 additions and 153 deletions.
67 changes: 30 additions & 37 deletions Admin/PageAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,53 +262,46 @@ protected function configureFormFields(FormMapper $formMapper)
*/
protected function configureSideMenu(MenuItemInterface $menu, $action, AdminInterface $childAdmin = null)
{
if (!$childAdmin && !in_array($action, array('edit'))) {
return;
}

$admin = $this->isChild() ? $this->getParent() : $this;

if ($childAdmin && $action == 'edit') {
$id = $admin->getRequest()->get('id');

$menu->addChild(
$this->trans('sidemenu.link_edit_page'),
array('uri' => $admin->generateUrl('edit', array('id' => $id)))
);
$id = $admin->getRequest()->get('id');

$menu->addChild(
$this->trans('sidemenu.link_compose_page'),
array('uri' => $admin->generateUrl('compose', array('id' => $id)))
);
$menu->addChild(
$this->trans('sidemenu.link_edit_page'),
array('uri' => $admin->generateUrl('edit', array('id' => $id)))
);

$menu->addChild(
$this->trans('sidemenu.link_compose_page'),
array('uri' => $admin->generateUrl('compose', array('id' => $id)))
);

$menu->addChild(
$this->trans('sidemenu.link_list_blocks'),
array('uri' => $admin->generateUrl('sonata.page.admin.block.list', array('id' => $id)))
);
$menu->addChild(
$this->trans('sidemenu.link_list_blocks'),
array('uri' => $admin->generateUrl('sonata.page.admin.block.list', array('id' => $id)))
);

$menu->addChild(
$this->trans('sidemenu.link_list_snapshots'),
array('uri' => $admin->generateUrl('sonata.page.admin.snapshot.list', array('id' => $id)))
);
$menu->addChild(
$this->trans('sidemenu.link_list_snapshots'),
array('uri' => $admin->generateUrl('sonata.page.admin.snapshot.list', array('id' => $id)))
);

if (!$this->getSubject()->isHybrid() && !$this->getSubject()->isInternal()) {
if (!$this->getSubject()->isHybrid() && !$this->getSubject()->isInternal()) {

try {
$menu->addChild(
$this->trans('view_page'),
array('uri' => $this->getRouteGenerator()->generate('page_slug', array('path' => $this->getSubject()->getUrl())))
);
} catch (\Exception $e) {
// avoid crashing the admin if the route is not setup correctly
try {
$menu->addChild(
$this->trans('view_page'),
array('uri' => $this->getRouteGenerator()->generate('page_slug', array('path' => $this->getSubject()->getUrl())))
);
} catch (\Exception $e) {
// avoid crashing the admin if the route is not setup correctly
// throw $e;
}
}
} elseif ($action == 'list' || $action == 'tree') {
$menu->addChild(
$this->trans('sidemenu.link_list_pages'),
array('uri' => $admin->generateUrl('list'))
);

$menu->addChild(
$this->trans('sidemenu.link_pages_tree'),
array('uri' => $admin->generateUrl('tree'))
);
}
}

Expand Down
24 changes: 22 additions & 2 deletions Controller/PageAdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ public function batchActionSnapshot($query)
return new RedirectResponse($this->admin->generateUrl('list', $this->admin->getFilterParameters()));
}

/**
* @return \Symfony\Component\HttpFoundation\Response
*/
public function listAction()
{
if (!$this->getRequest()->get('filter')) {
return new RedirectResponse($this->admin->generateUrl('tree'));
}

return parent::listAction();
}

/**
* @return \Symfony\Component\HttpFoundation\Response
*/
Expand All @@ -55,7 +67,7 @@ public function treeAction()
$pageManager = $this->get('sonata.page.manager.page');

$currentSite = null;
$siteId = $this->getRequest()->get('siteId');
$siteId = $this->getRequest()->get('site');
foreach ($sites as $site) {
if ($siteId && $site->getId() == $siteId) {
$currentSite = $site;
Expand All @@ -73,10 +85,18 @@ public function treeAction()
$pages = array();
}

return $this->render('SonataPageBundle:PageAdmin:pages_tree.html.twig', array(
$datagrid = $this->admin->getDatagrid();
$formView = $datagrid->getForm()->createView();

$this->get('twig')->getExtension('form')->renderer->setTheme($formView, $this->admin->getFilterTheme());

return $this->render('SonataPageBundle:PageAdmin:tree.html.twig', array(
'action' => 'tree',
'sites' => $sites,
'currentSite' => $currentSite,
'pages' => $pages,
'form' => $formView,
'csrf_token' => $this->getCsrfToken('sonata.batch'),
));
}

Expand Down
6 changes: 6 additions & 0 deletions Resources/config/admin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@
<call method="setTranslationDomain">
<argument>%sonata.page.admin.page.translation_domain%</argument>
</call>

<call method="setTemplates">
<argument type="collection">
<argument key="list">SonataPageBundle:PageAdmin:list.html.twig</argument>
</argument>
</call>
</service>

<service id="sonata.page.admin.block" class="%sonata.page.admin.block.class%">
Expand Down
50 changes: 50 additions & 0 deletions Resources/public/tree.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

/********************************************************************\
Page tree
\********************************************************************/
.page-tree {
list-style: none;
padding-left: 0;
margin-left: 15px;
margin-right: 15px;
}
.page-tree ul {
list-style: none;
padding-left: 30px;
}
.page-tree__item {
display: block;
padding: 7px 15px 7px 7px;
border: 1px solid #ddd;
border-radius: 2px;
position: relative;
margin-bottom: 5px;
color: #444;
}
.page-tree__item .label {
font-size: 12px;
margin-top: 2px;
border-radius: 2px;
}
.page-tree__item .label-warning {
margin-right: 5px;
}
.page-tree__item .fa-caret-right {
position: absolute;
top: 9px;
left: -22px;
color: #3c8dbc;
}
.page-tree__item:hover {
background: #eee;
color: #000;
}
.page-tree__item__is-hybrid {
margin-right: 5px;
}
.page-tree__item__edit {
font-weight: bold;
}
.page-tree__item__edit:hover {
text-decoration: underline;
}
24 changes: 24 additions & 0 deletions Resources/translations/SonataPageBundle.de.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,30 @@
<source>sidemenu.link_compose_page</source>
<target>sidemenu.link_compose_page</target>
</trans-unit>
<trans-unit id="159" resname="sidemenu.link_list_pages">
<source>sidemenu.link_list_pages</source>
<target>sidemenu.link_list_pages</target>
</trans-unit>
<trans-unit id="160" resname="sidemenu.link_pages_tree">
<source>sidemenu.link_pages_tree</source>
<target>sidemenu.link_pages_tree</target>
</trans-unit>
<trans-unit id="161" resname="breadcrumb.link_page_tree">
<source>breadcrumb.link_page_tree</source>
<target>breadcrumb.link_page_tree</target>
</trans-unit>
<trans-unit id="162" resname="pages.tree_site_label">
<source>pages.tree_site_label</source>
<target>pages.tree_site_label</target>
</trans-unit>
<trans-unit id="163" resname="pages.tree_mode">
<source>pages.tree_mode</source>
<target>pages.tree_mode</target>
</trans-unit>
<trans-unit id="164" resname="pages.list_mode">
<source>pages.list_mode</source>
<target>pages.list_mode</target>
</trans-unit>
</body>
</file>
</xliff>
24 changes: 24 additions & 0 deletions Resources/translations/SonataPageBundle.en.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,30 @@
<source>sidemenu.link_compose_page</source>
<target>Composer (beta)</target>
</trans-unit>
<trans-unit id="159" resname="sidemenu.link_list_pages">
<source>sidemenu.link_list_pages</source>
<target>Pages list</target>
</trans-unit>
<trans-unit id="160" resname="sidemenu.link_pages_tree">
<source>sidemenu.link_pages_tree</source>
<target>Tree view</target>
</trans-unit>
<trans-unit id="161" resname="breadcrumb.link_page_tree">
<source>breadcrumb.link_page_tree</source>
<target>Tree</target>
</trans-unit>
<trans-unit id="162" resname="pages.tree_site_label">
<source>pages.tree_site_label</source>
<target>Pages for site</target>
</trans-unit>
<trans-unit id="163" resname="pages.tree_mode">
<source>pages.tree_mode</source>
<target>Tree view</target>
</trans-unit>
<trans-unit id="164" resname="pages.list_mode">
<source>pages.list_mode</source>
<target>List view</target>
</trans-unit>
</body>
</file>
</xliff>
24 changes: 24 additions & 0 deletions Resources/translations/SonataPageBundle.es.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,30 @@
<source>sidemenu.link_compose_page</source>
<target>sidemenu.link_compose_page</target>
</trans-unit>
<trans-unit id="159" resname="sidemenu.link_list_pages">
<source>sidemenu.link_list_pages</source>
<target>sidemenu.link_list_pages</target>
</trans-unit>
<trans-unit id="160" resname="sidemenu.link_pages_tree">
<source>sidemenu.link_pages_tree</source>
<target>sidemenu.link_pages_tree</target>
</trans-unit>
<trans-unit id="161" resname="breadcrumb.link_page_tree">
<source>breadcrumb.link_page_tree</source>
<target>breadcrumb.link_page_tree</target>
</trans-unit>
<trans-unit id="162" resname="pages.tree_site_label">
<source>pages.tree_site_label</source>
<target>pages.tree_site_label</target>
</trans-unit>
<trans-unit id="163" resname="pages.tree_mode">
<source>pages.tree_mode</source>
<target>pages.tree_mode</target>
</trans-unit>
<trans-unit id="164" resname="pages.list_mode">
<source>pages.list_mode</source>
<target>pages.list_mode</target>
</trans-unit>
</body>
</file>
</xliff>
24 changes: 24 additions & 0 deletions Resources/translations/SonataPageBundle.fr.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,30 @@
<source>sidemenu.link_compose_page</source>
<target>Composer (beta)</target>
</trans-unit>
<trans-unit id="159" resname="sidemenu.link_list_pages">
<source>sidemenu.link_list_pages</source>
<target>Liste</target>
</trans-unit>
<trans-unit id="160" resname="sidemenu.link_pages_tree">
<source>sidemenu.link_pages_tree</source>
<target>Arbre</target>
</trans-unit>
<trans-unit id="161" resname="breadcrumb.link_page_tree">
<source>breadcrumb.link_page_tree</source>
<target>Arbre</target>
</trans-unit>
<trans-unit id="162" resname="pages.tree_site_label">
<source>pages.tree_site_label</source>
<target>Pages pour le site</target>
</trans-unit>
<trans-unit id="163" resname="pages.tree_mode">
<source>pages.tree_mode</source>
<target>arbre</target>
</trans-unit>
<trans-unit id="164" resname="pages.list_mode">
<source>pages.list_mode</source>
<target>liste</target>
</trans-unit>
</body>
</file>
</xliff>
24 changes: 24 additions & 0 deletions Resources/translations/SonataPageBundle.nl.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,30 @@
<source>sidemenu.link_compose_page</source>
<target>sidemenu.link_compose_page</target>
</trans-unit>
<trans-unit id="159" resname="sidemenu.link_list_pages">
<source>sidemenu.link_list_pages</source>
<target>sidemenu.link_list_pages</target>
</trans-unit>
<trans-unit id="160" resname="sidemenu.link_pages_tree">
<source>sidemenu.link_pages_tree</source>
<target>sidemenu.link_pages_tree</target>
</trans-unit>
<trans-unit id="161" resname="breadcrumb.link_page_tree">
<source>breadcrumb.link_page_tree</source>
<target>breadcrumb.link_page_tree</target>
</trans-unit>
<trans-unit id="162" resname="pages.tree_site_label">
<source>pages.tree_site_label</source>
<target>pages.tree_site_label</target>
</trans-unit>
<trans-unit id="163" resname="pages.tree_mode">
<source>pages.tree_mode</source>
<target>pages.tree_mode</target>
</trans-unit>
<trans-unit id="164" resname="pages.list_mode">
<source>pages.list_mode</source>
<target>pages.list_mode</target>
</trans-unit>
</body>
</file>
</xliff>
24 changes: 24 additions & 0 deletions Resources/translations/SonataPageBundle.pt_BR.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,30 @@
<source>sidemenu.link_compose_page</source>
<target>sidemenu.link_compose_page</target>
</trans-unit>
<trans-unit id="159" resname="sidemenu.link_list_pages">
<source>sidemenu.link_list_pages</source>
<target>sidemenu.link_list_pages</target>
</trans-unit>
<trans-unit id="160" resname="sidemenu.link_pages_tree">
<source>sidemenu.link_pages_tree</source>
<target>sidemenu.link_pages_tree</target>
</trans-unit>
<trans-unit id="161" resname="breadcrumb.link_page_tree">
<source>breadcrumb.link_page_tree</source>
<target>breadcrumb.link_page_tree</target>
</trans-unit>
<trans-unit id="162" resname="pages.tree_site_label">
<source>pages.tree_site_label</source>
<target>pages.tree_site_label</target>
</trans-unit>
<trans-unit id="163" resname="pages.tree_mode">
<source>pages.tree_mode</source>
<target>pages.tree_mode</target>
</trans-unit>
<trans-unit id="164" resname="pages.list_mode">
<source>pages.list_mode</source>
<target>pages.list_mode</target>
</trans-unit>
</body>
</file>
</xliff>
Loading

0 comments on commit 2fbd2e1

Please sign in to comment.