diff --git a/src/Crud/AbstractCrudConfig.php b/src/Crud/AbstractCrudConfig.php index e2fba701..3ddb353f 100644 --- a/src/Crud/AbstractCrudConfig.php +++ b/src/Crud/AbstractCrudConfig.php @@ -135,7 +135,7 @@ public function getShowActions(): array $this->getPath(CrudConfigInterface::INDEX), Icon::new('list') ) - ->setCssClass('btn btn-secondary btn-sm me-1') + ->setCssClass('btn btn-secondary btn-sm ms-1') ->setRole(sprintf('ROLE_%s_%s', $this->getName(), CrudConfigInterface::INDEX)); $actions[CrudConfigInterface::ACTION_EDIT] = EditAction::new( @@ -143,7 +143,7 @@ public function getShowActions(): array $this->getPath(CrudConfigInterface::EDIT), Icon::new('edit') ) - ->setCssClass('btn btn-secondary btn-sm me-1') + ->setCssClass('btn btn-secondary btn-sm ms-1') ->setRole(sprintf('ROLE_%s_%s', $this->getName(), CrudConfigInterface::EDIT)); $actions[CrudConfigInterface::ACTION_DELETE] = DeleteAction::new( @@ -151,7 +151,7 @@ public function getShowActions(): array $this->getPath(CrudConfigInterface::DELETE), Icon::new('trash-alt') ) - ->setCssClass('btn btn-danger btn-sm me-1') + ->setCssClass('btn btn-danger btn-sm ms-1') ->setConfirmModal(true) ->setRole(sprintf('ROLE_%s_%s', $this->getName(), CrudConfigInterface::DELETE)); diff --git a/src/Dto/Action/DropdownAction.php b/src/Dto/Action/DropdownAction.php index 9b92f2a6..2cd7eae7 100644 --- a/src/Dto/Action/DropdownAction.php +++ b/src/Dto/Action/DropdownAction.php @@ -3,6 +3,7 @@ namespace Lle\CruditBundle\Dto\Action; use Lle\CruditBundle\Contracts\ActionInterface; +use Lle\CruditBundle\Dto\Icon; use Lle\CruditBundle\Dto\Path; class DropdownAction extends AbstractAction @@ -10,12 +11,13 @@ class DropdownAction extends AbstractAction protected array $actions; /** - * @param array|AbstractAction[] $actions + * @param array $actions */ - public static function new(string $label, array $actions): static + public static function new(string $label, array $actions, ?Icon $icon = null): static { return (new static($label)) - ->setActions($actions); + ->setActions($actions) + ->setIcon($icon); } public function __construct(string $label) diff --git a/src/Resources/views/brick/links/actions/_actions.html.twig b/src/Resources/views/brick/links/actions/_actions.html.twig index e69de29b..8dd68456 100644 --- a/src/Resources/views/brick/links/actions/_actions.html.twig +++ b/src/Resources/views/brick/links/actions/_actions.html.twig @@ -0,0 +1,53 @@ +{% set params = action.path.params %} +{% if view.data.resource and action.setResource is defined%} + {% do action.setResource(view.data.resource) %} +{% endif %} + +{% set id = app.request.attributes.get('id') %} +{% if id %} + {% set params = action.path.params|merge({id: id}) %} +{% endif %} + +{% if action.modal %} + {% include action.modal with {action: action, id: 'modal_' ~ action.id, params: params} %} +{% endif %} + +{% set disabled = action.disabled or not + ((action.path.role is null or is_granted(action.path.role, view.data.resource)) + and (action.role is null or is_granted(action.role, view.data.resource))) +%} + +{% if not (disabled and crudit_hide_if_disabled(action)) %} + {% block actions_item %} + + + {% if action.icon %} + + {% endif %} + {% if not action.hideLabel %} + {{ action.label|trans(domain=view.config.translation_domain) }} + {% endif %} + + + {% endblock %} +{% endif %} \ No newline at end of file diff --git a/src/Resources/views/brick/links/actions/_dropdown_actions.html.twig b/src/Resources/views/brick/links/actions/_dropdown_actions.html.twig index c6a2d677..1fb0f122 100644 --- a/src/Resources/views/brick/links/actions/_dropdown_actions.html.twig +++ b/src/Resources/views/brick/links/actions/_dropdown_actions.html.twig @@ -1,58 +1,82 @@ - +{% endif %} diff --git a/src/Resources/views/brick/links/actions/_kebab_dropdown_actions.html.twig b/src/Resources/views/brick/links/actions/_kebab_dropdown_actions.html.twig index c34137d2..b5a34965 100644 --- a/src/Resources/views/brick/links/actions/_kebab_dropdown_actions.html.twig +++ b/src/Resources/views/brick/links/actions/_kebab_dropdown_actions.html.twig @@ -1,10 +1,10 @@ diff --git a/src/Resources/views/brick/list_items/_actions.html.twig b/src/Resources/views/brick/list_items/_actions.html.twig index b6f0dce1..feabb24d 100644 --- a/src/Resources/views/brick/list_items/_actions.html.twig +++ b/src/Resources/views/brick/list_items/_actions.html.twig @@ -1,79 +1,26 @@
- ITEM -{# {% set hasDropdown = false %}#} -{# {% for action in view.config.actions %}#} -{# {% do action.setResource(line.resource) %}#} -{# {% if not action.dropdown %}#} -{# {% set params = { 'id': line.resource.id } %}#} -{# {% if action.modal %}#} -{# {% include action.modal with {action: action, id: 'modal_' ~ action.id ~ line.resource.id } %}#} -{# {% endif %}#} -{# {% set disabled = action.disabled or not#} -{# ((action.path.role is null or is_granted(action.path.role, line.resource))#} -{# and (action.role is null or is_granted(action.role, line.resource)))#} -{# %}#} + {% set has_dropdown = false %} + {% block links_actions %} + {% for action in view.config.actions %} + {% if crudit_is_dropdown_action(action) %} + {% block dropdown_actions %} + {{ include('@LleCrudit/brick/list_items/actions/_dropdown_actions.html.twig', {dropdown_action: action, view: view}) }} + {% endblock %} + {% elseif not action.dropdown %} + {% block actions %} + {{ include('@LleCrudit/brick/list_items/actions/_actions.html.twig', {action: action, view: view}) }} + {% endblock %} + {% else %} + {% set has_dropdown = true %} + {% endif %} + {% endfor %} -{# {% if not (disabled and crudit_hide_if_disabled(action)) %}#} -{# #} -{# #} -{# {% if action.icon %}{% endif %}#} -{# {% if not action.hideLabel and not action.icon %}{{ action.label|trans(domain=view.config.translation_domain) }}{% endif %}#} -{# #} -{# #} -{# {% endif %}#} -{# {% endif %}#} -{# {% if action.dropdown %}#} -{# {% set hasDropdown = true %}#} -{# {% endif %}#} -{# {% endfor %}#} - -{# {% if hasDropdown %}#} -{# #} -{# {% endif %}#} + {% if has_dropdown %} + {% block kebab_dropdown_actions %} + {{ include('@LleCrudit/brick/list_items/actions/_kebab_dropdown_actions.html.twig', {view: view}) }} + {% endblock %} + {% endif %} + {% endblock %}
diff --git a/src/Resources/views/brick/list_items/_footer.html.twig b/src/Resources/views/brick/list_items/_footer.html.twig index dd6e985c..23b73a75 100644 --- a/src/Resources/views/brick/list_items/_footer.html.twig +++ b/src/Resources/views/brick/list_items/_footer.html.twig @@ -7,21 +7,21 @@ {% endif %} {% endfor %} - FOOTER -{# {% if view.config.actions|length %}#} -{# {% set hasActions = false %}#} -{# {% for action in view.config.actions %}#} -{# {% if#} -{# (action.path.role is null or is_granted(action.path.role))#} -{# and (action.role is null or is_granted(action.role))#} -{# %}#} -{# {% set hasActions = true %}#} -{# {% endif %}#} -{# {% endfor %}#} -{# {% if hasActions %}#} -{# {{ 'crudit.action'|trans(domain=view.config.translation_domain) }}#} -{# {% endif %}#} -{# {% endif %}#} + {% if view.config.actions|length %} + {% set hasActions = false %} + {% for action in view.config.actions %} + {% if + not crudit_is_dropdown_action(action) + and (action.path.role is null or is_granted(action.path.role)) + and (action.role is null or is_granted(action.role)) + %} + {% set hasActions = true %} + {% endif %} + {% endfor %} + {% if hasActions %} + {{ 'crudit.action'|trans(domain=view.config.translation_domain) }} + {% endif %} + {% endif %} {% if view.data.totals %} diff --git a/src/Resources/views/brick/list_items/actions/_actions.html.twig b/src/Resources/views/brick/list_items/actions/_actions.html.twig new file mode 100644 index 00000000..918121a8 --- /dev/null +++ b/src/Resources/views/brick/list_items/actions/_actions.html.twig @@ -0,0 +1,49 @@ +{% set params = { 'id': line.resource.id } %} + +{% if action.modal %} + {% include action.modal with {action: action, id: 'modal_' ~ action.id ~ line.resource.id } %} +{% endif %} + +{% set disabled = action.disabled or not + ((action.path.role is null or is_granted(action.path.role, line.resource)) + and (action.role is null or is_granted(action.role, line.resource))) +%} + +{% if not (disabled and crudit_hide_if_disabled(action)) %} + {% block actions_item %} + + + {% if action.icon %} + + {% endif %} + {% if not action.hideLabel and not action.icon %} + {{ action.label|trans(domain=view.config.translation_domain) }} + {% endif %} + + + {% endblock %} +{% endif %} diff --git a/src/Resources/views/brick/list_items/actions/_dropdown_actions.html.twig b/src/Resources/views/brick/list_items/actions/_dropdown_actions.html.twig new file mode 100644 index 00000000..45d49c77 --- /dev/null +++ b/src/Resources/views/brick/list_items/actions/_dropdown_actions.html.twig @@ -0,0 +1,74 @@ +{% set disabled = + dropdown_action.disabled or not + (dropdown_action.role is null or is_granted(dropdown_action.role, line.resource)) +%} + +{% if not (disabled and crudit_hide_if_disabled(dropdown_action)) %} + +{% endif %} diff --git a/src/Resources/views/brick/list_items/actions/_kebab_dropdown_actions.html.twig b/src/Resources/views/brick/list_items/actions/_kebab_dropdown_actions.html.twig new file mode 100644 index 00000000..5c5876fb --- /dev/null +++ b/src/Resources/views/brick/list_items/actions/_kebab_dropdown_actions.html.twig @@ -0,0 +1,44 @@ + diff --git a/src/Resources/views/brick/list_items/index.html.twig b/src/Resources/views/brick/list_items/index.html.twig index 1a38fa18..36c78886 100644 --- a/src/Resources/views/brick/list_items/index.html.twig +++ b/src/Resources/views/brick/list_items/index.html.twig @@ -70,19 +70,24 @@ {% endif %} {% endfor %} {% if view.config.actions|length %} - IDK -{# {% set hasActions = false %}#} -{# {% for action in view.config.actions %}#} -{# {% if#} -{# (action.path.role is null or is_granted(action.path.role))#} -{# and (action.role is null or is_granted(action.role))#} -{# %}#} -{# {% set hasActions = true %}#} -{# {% endif %}#} -{# {% endfor %}#} -{# {% if hasActions %}#} -{# {{ 'crudit.action'|trans(domain=view.config.translation_domain) }}#} -{# {% endif %}#} + {% set hasActions = false %} + {% for action in view.config.actions %} + {% if + ( + not crudit_is_dropdown_action(action) + and (action.path.role is null or is_granted(action.path.role)) + and (action.role is null or is_granted(action.role)) + ) or ( + crudit_is_dropdown_action(action) + and (action.role is null or is_granted(action.role)) + ) + %} + {% set hasActions = true %} + {% endif %} + {% endfor %} + {% if hasActions %} + {{ 'crudit.action'|trans(domain=view.config.translation_domain) }} + {% endif %} {% endif %} diff --git a/src/Resources/views/brick/map/index.html.twig b/src/Resources/views/brick/map/index.html.twig deleted file mode 100644 index 8cb39df1..00000000 --- a/src/Resources/views/brick/map/index.html.twig +++ /dev/null @@ -1,53 +0,0 @@ -{# basic config : lat / lng / zoom #} -{% set zoom = view.options['zoom'] |default(6) %} -{% set lat = view.options['lat'] |default(46) %} -{% set lng = view.options['lng'] |default(2.5) %} - -{# layer as geourls #} -{% set geojsons = view.options['geojsons'] |default(null) %} - -{# this map is a item map #} - -{% set item = view.data.resource.resource |default(null) %} -{% set editable = view.options['editable'] | default(false) %} - -{% if item %} - {% set centrefield_lat = view.options['lat_field'] %} - {% set centrefield_lng = view.options['lng_field'] %} - {% if editable %} - {% set edit_url = path(view.options['edit_route'], {"id": item.id}) %} - {% endif %} - - {% set polylinefield = view.options['poly_field']|default(null) %} - - {% set lat = attribute(item, centrefield_lat) %} - {% set lng = attribute(item, centrefield_lng) %} - - {% if polylinefield %} - {% set polyline = attribute(item, polylinefield) %} - {% endif %} -{% endif %} - -
-