Skip to content

Commit

Permalink
Merge pull request #30 from webhdx/right_sidebar
Browse files Browse the repository at this point in the history
EZP-28131: Create extendable right sidebar
  • Loading branch information
Łukasz Serwatka authored and webhdx committed Oct 31, 2017
2 parents 78101dc + 629e3ed commit 2673fd3
Show file tree
Hide file tree
Showing 9 changed files with 269 additions and 65 deletions.
10 changes: 10 additions & 0 deletions src/bundle/Resources/config/services/menu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,13 @@ services:
public: true
tags:
- { name: knp_menu.menu_builder, method: build, alias: ezplatform_admin_ui.menu.content.sidebar_left }

EzSystems\EzPlatformAdminUi\Menu\ContentRightSidebarBuilder:
public: true
tags:
- { name: knp_menu.menu_builder, method: build, alias: ezplatform_admin_ui.menu.content.sidebar_right }

EzSystems\EzPlatformAdminUi\Menu\TrashRightSidebarBuilder:
public: true
tags:
- { name: knp_menu.menu_builder, method: build, alias: ezplatform_admin_ui.menu.trash.sidebar_right }
11 changes: 2 additions & 9 deletions src/bundle/Resources/views/admin/trash/list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,8 @@
</section>
</div>
<div class="col-sm-1 pt-4 bg-secondary ez-context-menu">
{% if can_delete %}
<button type="button"
class="btn btn-secondary btn-block{% if trash_items|length == 0 %} disabled{% endif %}"{% if trash_items|length > 0 %} data-toggle="modal" data-target="#confirmEmptyTrash"{% endif %}>
<svg class="ez-icon ez-icon-trash-empty">
<use xlink:href="{{ asset('bundles/ezplatformadminui/img/ez-icons.svg') }}#trash-empty"></use>
</svg>
{{ 'trash.empty_trash'|trans|desc('Empty Trash') }}
</button>
{% endif %}
{% set sidebar_right = knp_menu_get('ezplatform_admin_ui.menu.trash.sidebar_right', []) %}
{{ knp_menu_render(sidebar_right, {'template': '@EzPlatformAdminUi/parts/menu/sidebar_right.html.twig'}) }}
</div>
</div>
{% endblock %}
Expand Down
20 changes: 2 additions & 18 deletions src/bundle/Resources/views/content/locationview.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,9 @@
</div>
</div>
<div class="col-sm-1 pt-4 bg-secondary ez-context-menu">
<button class="btn btn-secondary btn-block" data-toggle="modal" data-target="#trash-location-modal" {% if location.depth == 1 %}disabled{% endif %}>
<svg class="ez-icon ez-icon-trash-send">
<use xlink:href="{{ asset('bundles/ezplatformadminui/img/ez-icons.svg') }}#trash-send"></use>
</svg>
{{ 'send.to.trash'|trans|desc('Send to Trash') }}</button>
<button class="btn btn-secondary btn-block btn--udw-copy" data-root-location="1">
<svg class="ez-icon ez-icon-copy">
<use xlink:href="{{ asset('bundles/ezplatformadminui/img/ez-icons.svg') }}#copy"></use>
</svg>
{{ 'copy'|trans|desc('Copy') }}
</button>
<button class="btn btn-secondary btn-block btn--udw-move" data-root-location="1" {% if location.depth == 1 %}disabled{% endif %}>
<svg class="ez-icon ez-icon-move">
<use xlink:href="{{ asset('bundles/ezplatformadminui/img/ez-icons.svg') }}#move"></use>
</svg>
{{ 'move'|trans|desc('Move') }}
</button>
{% set content_sidebar_right = knp_menu_get('ezplatform_admin_ui.menu.content.sidebar_right', [], {'location': location}) %}
{{ knp_menu_render(content_sidebar_right, {'template': '@EzPlatformAdminUi/parts/menu/sidebar_right.html.twig'}) }}

{# TODO: location trash should be rendered as a form, confirmation dialog should be impl. as a type #}
{% include 'EzPlatformAdminUiBundle:content:modal_location_trash.html.twig' with {'form': form_location_trash} %}
{{ form(form_location_copy) }}
{{ form(form_location_move) }}
Expand Down
41 changes: 41 additions & 0 deletions src/bundle/Resources/views/parts/menu/sidebar_base.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{% extends '@KnpMenu/menu.html.twig' %}

{% block root %}
{% for item in item.children %}
{{ block('item') }}
{% endfor %}
{% endblock %}

{% block item -%}
{%- if item.displayed -%}
{%- set attributes = item.attributes|merge({'class': (item.attributes.class|default('') ~ ' ' ~ default_classes|default('btn btn-dark btn-block'))|trim}) -%}
{%- set attributes = attributes|merge({'id': item.name ~ '-tab'}) -%}

{%- if item.uri is not empty %}
{% set attributes = attributes|merge({'href': item.uri}) %}
{% set element = 'a' %}
{{ block('element') }}
{%- else %}
{% set element = 'button' %}
{{ block('element') }}
{%- endif %}
{%- endif -%}
{%- endblock %}

{% block element %}
{% import 'knp_menu.html.twig' as macros %}
{% set element = element|default('a') %}
<{{ element }}{{ macros.attributes(attributes) }}>
{{ block('label') }}
</{{ element }}>
{% endblock %}

{% block label %}
{% if item.extras.icon is defined and item.extras.icon != '' %}
<svg class="ez-icon ez-icon-{{ item.extras.icon }}">
<use xmlns:xlink="http://www.w3.org/1999/xlink"
xlink:href="{{ asset('bundles/ezplatformadminui/img/ez-icons.svg') }}#{{ item.extras.icon }}"></use>
</svg>
{% endif %}
{{ parent() }}
{% endblock %}
41 changes: 3 additions & 38 deletions src/bundle/Resources/views/parts/menu/sidebar_left.html.twig
Original file line number Diff line number Diff line change
@@ -1,41 +1,6 @@
{% extends '@KnpMenu/menu.html.twig' %}

{% block root %}
{% for item in item.children %}
{{ block('item') }}
{% endfor %}
{% endblock %}
{% extends 'EzPlatformAdminUiBundle:parts/menu:sidebar_base.html.twig' %}

{% block item -%}
{%- if item.displayed -%}
{%- set attributes = item.attributes|merge({'class': (item.attributes.class|default('') ~ ' btn btn-dark btn-block')|trim}) -%}
{%- set attributes = attributes|merge({'id': item.name ~ '-tab'}) -%}

{%- if item.uri is not empty %}
{% set attributes = attributes|merge({'href': item.uri}) %}
{% set element = 'a' %}
{{ block('element') }}
{%- else %}
{% set element = 'button' %}
{{ block('element') }}
{%- endif %}
{%- endif -%}
{%- endblock %}

{% block element %}
{% import 'knp_menu.html.twig' as macros %}
{% set element = element|default('a') %}
<{{ element }}{{ macros.attributes(attributes) }}>
{{ block('label') }}
</{{ element }}>
{% endblock %}

{% block label %}
{% if item.extras.icon is defined and item.extras.icon != '' %}
<svg class="ez-icon ez-icon-{{ item.extras.icon }}">
<use xmlns:xlink="http://www.w3.org/1999/xlink"
xlink:href="{{ asset('bundles/ezplatformadminui/img/ez-icons.svg') }}#{{ item.extras.icon }}"></use>
</svg>
{% endif %}
{%- set default_classes = 'btn btn-dark btn-block' -%}
{{ parent() }}
{% endblock %}
{%- endblock %}
6 changes: 6 additions & 0 deletions src/bundle/Resources/views/parts/menu/sidebar_right.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% extends 'EzPlatformAdminUiBundle:parts/menu:sidebar_base.html.twig' %}

{% block item -%}
{%- set default_classes = 'btn btn-secondary btn-block' -%}
{{ parent() }}
{%- endblock %}
102 changes: 102 additions & 0 deletions src/lib/Menu/ContentRightSidebarBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace EzSystems\EzPlatformAdminUi\Menu;

use eZ\Publish\API\Repository\Values\Content\Location;
use EzSystems\EzPlatformAdminUi\Menu\Event\ConfigureMenuEvent;
use InvalidArgumentException;
use JMS\TranslationBundle\Model\Message;
use JMS\TranslationBundle\Translation\TranslationContainerInterface;
use Knp\Menu\ItemInterface;

/**
* KnpMenuBundle Menu Builder service implementation for AdminUI Location View contextual sidebar menu.
*
* @see https://symfony.com/doc/current/bundles/KnpMenuBundle/menu_builder_service.html
*/
class ContentRightSidebarBuilder extends AbstractBuilder implements TranslationContainerInterface
{
/* Menu items */
const ITEM__SEND_TO_TRASH = 'content__sidebar_right__send_to_trash';
const ITEM__COPY = 'content__sidebar_right__copy';
const ITEM__MOVE = 'content__sidebar_right__move';

/**
* @return string
*/
protected function getConfigureEventName(): string
{
return ConfigureMenuEvent::CONTENT_SIDEBAR_RIGHT;
}

/**
* @param array $options
*
* @return ItemInterface
*
* @throws InvalidArgumentException
*/
public function createStructure(array $options): ItemInterface
{
/** @var Location $location */
$location = $options['location'];
/** @var ItemInterface|ItemInterface[] $menu */
$menu = $this->factory->createItem('root');

$menu->setChildren([
self::ITEM__SEND_TO_TRASH => $this->createMenuItem(
self::ITEM__SEND_TO_TRASH,
[
'extras' => ['icon' => 'trash-send'],
'attributes' => [
'data-toggle' => 'modal',
'data-target' => '#trash-location-modal',
],
]
),
self::ITEM__COPY => $this->createMenuItem(
self::ITEM__COPY,
[
'extras' => ['icon' => 'copy'],
'attributes' => [
'class' => 'btn--udw-copy',
'data-root-location' => 1,
],
]
),
self::ITEM__MOVE => $this->createMenuItem(
self::ITEM__MOVE,
[
'extras' => ['icon' => 'move'],
'attributes' => [
'class' => 'btn--udw-move',
'data-root-location' => 1,
],
]
),
]);

if (1 === $location->depth) {
$menu[self::ITEM__SEND_TO_TRASH]->setAttribute('disabled', 'disabled');
$menu[self::ITEM__MOVE]->setAttribute('disabled', 'disabled');
}

return $menu;
}

/**
* @return Message[]
*/
public static function getTranslationMessages(): array
{
return [
(new Message(self::ITEM__SEND_TO_TRASH, 'menu'))->setDesc('Send to Trash'),
(new Message(self::ITEM__COPY, 'menu'))->setDesc('Copy'),
(new Message(self::ITEM__MOVE, 'menu'))->setDesc('Move'),
];
}
}
1 change: 1 addition & 0 deletions src/lib/Menu/Event/ConfigureMenuEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class ConfigureMenuEvent extends Event
const MAIN_MENU = 'ezplatform_admin_ui.menu_configure.main_menu';
const CONTENT_SIDEBAR_RIGHT = 'ezplatform_admin_ui.menu_configure.content_sidebar_right';
const CONTENT_SIDEBAR_LEFT = 'ezplatform_admin_ui.menu_configure.content_sidebar_left';
const TRASH_SIDEBAR_RIGHT = 'ezplatform_admin_ui.menu_configure.trash_sidebar_right';

/** @var FactoryInterface */
private $factory;
Expand Down
102 changes: 102 additions & 0 deletions src/lib/Menu/TrashRightSidebarBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace EzSystems\EzPlatformAdminUi\Menu;

use eZ\Publish\API\Repository\Exceptions as ApiExceptions;
use eZ\Publish\API\Repository\PermissionResolver;
use eZ\Publish\API\Repository\TrashService;
use eZ\Publish\API\Repository\Values\Content\Query;
use EzSystems\EzPlatformAdminUi\Menu\Event\ConfigureMenuEvent;
use InvalidArgumentException;
use JMS\TranslationBundle\Model\Message;
use JMS\TranslationBundle\Translation\TranslationContainerInterface;
use Knp\Menu\FactoryInterface;
use Knp\Menu\ItemInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

/**
* KnpMenuBundle Menu Builder service implementation for AdminUI Trash contextual sidebar menu.
*
* @see https://symfony.com/doc/current/bundles/KnpMenuBundle/menu_builder_service.html
*/
class TrashRightSidebarBuilder extends AbstractBuilder implements TranslationContainerInterface
{
/* Menu items */
const ITEM__EMPTY = 'trash__sidebar_right__empty_trash';

/** @var PermissionResolver */
private $permissionResolver;

/** @var TrashService */
private $trashService;

/**
* @param FactoryInterface $factory
* @param EventDispatcherInterface $eventDispatcher
* @param PermissionResolver $permissionResolver
* @param TrashService $trashService
*/
public function __construct(
FactoryInterface $factory,
EventDispatcherInterface $eventDispatcher,
PermissionResolver $permissionResolver,
TrashService $trashService
) {
parent::__construct($factory, $eventDispatcher);

$this->permissionResolver = $permissionResolver;
$this->trashService = $trashService;
}

/**
* @return string
*/
protected function getConfigureEventName(): string
{
return ConfigureMenuEvent::TRASH_SIDEBAR_RIGHT;
}

/**
* @param array $options
*
* @return ItemInterface
*
* @throws ApiExceptions\InvalidArgumentException
* @throws ApiExceptions\BadStateException
* @throws InvalidArgumentException
*/
public function createStructure(array $options): ItemInterface
{
/** @var bool $location */
$canDelete = $this->permissionResolver->hasAccess('content', 'cleantrash');
/** @var int $trashItemsCount */
$trashItemsCount = $this->trashService->findTrashItems(new Query())->count;
/** @var ItemInterface|ItemInterface[] $menu */
$menu = $this->factory->createItem('root');

$menu->addChild(
$this->createMenuItem(self::ITEM__EMPTY, [
'extras' => ['icon' => 'trash-empty'],
'attributes' => $canDelete > 0 && $trashItemsCount > 0
? ['data-toggle' => 'modal', 'data-target' => '#confirmEmptyTrash']
: ['class' => 'disabled'],
])
);

return $menu;
}

/**
* @return array
*/
public static function getTranslationMessages(): array
{
return [
(new Message(self::ITEM__EMPTY, 'menu'))->setDesc('Empty Trash'),
];
}
}

0 comments on commit 2673fd3

Please sign in to comment.