Skip to content

Commit

Permalink
refactor(datatable): channel index use crud overview.html.twig
Browse files Browse the repository at this point in the history
  • Loading branch information
Davidmattei committed Jul 23, 2024
1 parent 98b5b3b commit c170c12
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 80 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,29 @@
{% set label = name|humanize %}
{%- endif -%}
{%- endif -%}
<button type="{{ type|default('submit') }}" {{ block('button_attributes') }}>
{%- if icon -%}
<span class="{{ icon }}"></span>&nbsp;
{% endif %}
{{ translation_domain is same as(false) ? label : label|trans(label_translation_parameters|default({}), translation_domain) }}
</button>
{% if confirm is defined and confirm != null %}
<div class="btn-group">
<button type="button" class="{{ confirm_class|default('btn btn-outline-danger') }} dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{%- if icon -%}
<span class="{{ icon }}"></span>&nbsp;
{% endif %}
{{ translation_domain is same as(false) ? label : label|trans(label_translation_parameters|default({}), translation_domain) }}
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li>
<button type="{{ type|default('submit') }}" {{ block('button_attributes') }}>{{ confirm|trans }}</button>
</li>
</ul>
</div>
{% else %}
<button type="{{ type|default('submit') }}" {{ block('button_attributes') }}>
{%- if icon -%}
<span class="{{ icon }}"></span>&nbsp;
{% endif %}
{{ translation_domain is same as(false) ? label : label|trans(label_translation_parameters|default({}), translation_domain) }}
</button>
{% endif %}
{%- endblock submitems_widget -%}


Expand Down Expand Up @@ -614,7 +631,9 @@
<div class="panel-heading ems-handle">
{{ form_label(form) }}
<div class="btn-group pull-right">
{{- form_widget(form.remove_collection_item) -}}
<button type="button" class="btn btn-danger btn-sm remove-content-button">
<span class="fa fa-trash"></span>&nbsp;Remove
</button>
{% if collapsible %}
<div class="pull-right">
<div class="btn-group toggle-group" role="group">
Expand All @@ -629,7 +648,7 @@

<div class="panel-body {% if collapsible %}collapse{% endif %}">
<div class="row">
{% for child in form.iterator|filter(c => c.vars.name not in ['remove_collection_item', '_ems_internal_deleted']) %}
{% for child in form.iterator|filter(c => c.vars.name not in ['_ems_internal_deleted']) %}
<div class="{% if child.vars.data.fieldType.options.displayOptions.class is defined %}{{ child.vars.data.fieldType.options.displayOptions.class }}{% endif %}">
{{- form_row(child) -}}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,15 +289,20 @@
</h2>
</div>
{% endif %}
{% if toolbar is defined or (table.sortable and table.supportsTableActions) %}
{% if toolbar is defined or (table.sortable and table.supportsTableActions) or table.toolbarActions|length > 0 %}
<div class="box-header with-border">
<div class="btn-group pull-right">
{% if toolbar is defined %}
{{ toolbar }}
{% endif %}
{% for toolbarAction in table.toolbarActions %}
<a class="{{ toolbarAction.cssClass }}" href="{{ path(toolbarAction.routeName, toolbarAction.routeParams) }}">
<i class="{{ toolbarAction.icon }}"></i>&nbsp;{{ toolbarAction.labelKey|trans }}
</a>
{% endfor %}
{% if table.sortable and table.supportsTableActions %}
<button type="button" class="btn" data-toggle="modal" data-target="#{{ table.attributeName|e('html_attr') }}_modal_reorder">
<i class="fa fa-reorder"></i> {{ reorder_label|default(form.vars.reorder_label)|trans }}
<button type="button" class="btn btn-default" data-toggle="modal" data-target="#{{ table.attributeName|e('html_attr') }}_modal_reorder">
<i class="fa fa-reorder"></i>&nbsp;{{ form.reorderAction.vars.label|trans }}
</button>
{% endif %}
</div>
Expand Down Expand Up @@ -366,6 +371,13 @@
{{ toolbar }}
</div>
{% endif %}
{% for toolbarAction in table.toolbarActions %}
<div class="btn-group">
<a class="{{ toolbarAction.cssClass }}" href="{{ path(toolbarAction.routeName, toolbarAction.routeParams) }}">
<i class="{{ toolbarAction.icon }}"></i>&nbsp;{{ toolbarAction.labelKey|trans }}
</a>
</div>
{% endfor %}
</div>
{% endif %}
</div>
Expand Down Expand Up @@ -395,8 +407,8 @@
</div>
<div class="modal-footer">
<div class="btn-group">
{{ form_widget(form.reorderAction) }}
<button type="button" class="btn" data-dismiss="modal"><i class="fa fa-close"></i> {{ t('action.close', [], 'emsco-core')|trans }}</button>
{{ form_widget(form.reorderAction, { 'attr': { 'class': 'btn btn-primary' } }) }}
<button type="button" class="btn btn-default" data-dismiss="modal"><i class="fa fa-close"></i> {{ t('action.close', [], 'emsco-core')|trans }}</button>
</div>
</div>
</div>
Expand Down
41 changes: 20 additions & 21 deletions EMS/core-bundle/src/Controller/ChannelController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@

namespace EMS\CoreBundle\Controller;

use EMS\CommonBundle\Contracts\Log\LocalizedLoggerInterface;
use EMS\CoreBundle\Core\DataTable\DataTableFactory;
use EMS\CoreBundle\DataTable\Type\ChannelDataTableType;
use EMS\CoreBundle\Entity\Channel;
use EMS\CoreBundle\Form\Data\EntityTable;
use EMS\CoreBundle\Form\Data\TableAbstract;
use EMS\CoreBundle\Form\Form\ChannelType;
use EMS\CoreBundle\Form\Form\TableType;
use EMS\CoreBundle\Service\Channel\ChannelService;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Form;
use Symfony\Component\Form\SubmitButton;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

use function Symfony\Component\Translation\t;

final class ChannelController extends AbstractController
{
use CoreControllerTrait;

public function __construct(
private readonly LoggerInterface $logger,
private readonly LocalizedLoggerInterface $logger,
private readonly ChannelService $channelService,
private readonly DataTableFactory $dataTableFactory,
private readonly string $templateNamespace
Expand All @@ -38,28 +38,27 @@ public function index(Request $request): Response
'reorder_label' => t('type.reorder', ['type' => 'channel'], 'emsco-core'),
]);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
if ($form instanceof Form && ($action = $form->getClickedButton()) instanceof SubmitButton) {
switch ($action->getName()) {
case EntityTable::DELETE_ACTION:
$this->channelService->deleteByIds($table->getSelected());
break;
case TableType::REORDER_ACTION:
$newOrder = TableType::getReorderedKeys($form->getName(), $request);
$this->channelService->reorderByIds($newOrder);
break;
default:
$this->logger->error('log.controller.channel.unknown_action');
}
} else {
$this->logger->error('log.controller.channel.unknown_action');
}
match ($this->getClickedButtonName($form)) {
TableAbstract::DELETE_ACTION => $this->channelService->deleteByIds($table->getSelected()),
TableType::REORDER_ACTION => $this->channelService->reorderByIds(
ids: TableType::getReorderedKeys($form->getName(), $request)
),
default => $this->logger->messageError(t('log.error.invalid_table_action', [], 'emsco-core'))
};

return $this->redirectToRoute('ems_core_channel_index');
}

return $this->render("@$this->templateNamespace/channel/index.html.twig", [
return $this->render("@$this->templateNamespace/crud/overview.html.twig", [
'form' => $form->createView(),
'icon' => 'fa fa-eye',
'title' => t('admin.channel.overview', [], 'emsco-core'),
'breadcrumb' => [
'admin' => t('admin.label', [], 'emsco-core'),
'page' => t('admin.channel.plural', [], 'emsco-core'),
],
]);
}

Expand Down
1 change: 0 additions & 1 deletion EMS/core-bundle/src/Controller/Revision/EditController.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@ public function draftInProgress(Request $request, ContentType $contentTypeId): R

return $this->render("@$this->templateNamespace/crud/overview.html.twig", [
'form' => $form->createView(),
'contentType' => $contentTypeId,
'icon' => 'fa fa-fire',
'title' => t('revision.draft.title', ['pluralName' => $contentTypeId->getPluralName()], 'emsco-core'),
'breadcrumb' => [
Expand Down
2 changes: 0 additions & 2 deletions EMS/core-bundle/src/Controller/Revision/TrashController.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ public function trash(Request $request, ContentType $contentType): Response
}

return $this->render("@$this->templateNamespace/crud/overview.html.twig", [
'contentType' => $contentType,
'revisions' => $this->dataService->getAllDeleted($contentType),
'form' => $form->createView(),
'icon' => 'fa fa-trash',
'title' => t('revision.trash.title', ['pluralName' => $contentType->getPluralName()], 'emsco-core'),
Expand Down
2 changes: 1 addition & 1 deletion EMS/core-bundle/src/Resources/config/controllers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@

<!-- Controllers -->
<service id="EMS\CoreBundle\Controller\ChannelController" public="true">
<argument type="service" id="logger" />
<argument type="service" id="emsco.logger" />
<argument type="service" id="ems.service.channel" />
<argument type="service" id="emsco.data_table.factory" />
<argument>%ems_core.template_namespace%</argument>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,6 @@ channel:
edit:
save: Save
title: 'Edit a channel'
index:
title: 'List of channels'
menu: Channels
environment:
index:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ action:
reorder: Reorder
admin:
channel:
plural: Channels
overview: 'List of channels'
field:
public: 'Public Access'
label: 'Admin'
content_type:
plural: 'Content Types'
core:
Expand Down
16 changes: 0 additions & 16 deletions EMS/core-bundle/src/Resources/views/channel/index.html.twig

This file was deleted.

2 changes: 2 additions & 0 deletions EMS/core-bundle/src/Resources/views/crud/overview.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
</li>
{% elseif name == 'page' %}
<li>{% if icon is defined %}<i class="{{ icon }}"></i>{% endif %}&nbsp;{{ item|trans }}</li>
{% else %}
<li>{{ item|trans }}</li>
{% endif %}
{% endfor %}
</ol>
Expand Down
2 changes: 1 addition & 1 deletion EMS/core-bundle/src/Resources/views/form/forms.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@
{% endfor %}
{% if table.sortable and table.supportsTableActions %}
<button type="button" class="btn btn-default" data-toggle="modal" data-target="#{{ table.attributeName|e('html_attr') }}_modal_reorder">
<i class="fa fa-reorder"></i>&nbsp;{{ reorder_label|default(form.vars.reorder_label)|trans }}
<i class="fa fa-reorder"></i>&nbsp;{{ form.reorderAction.vars.label|trans }}
</button>
{% endif %}
</div>
Expand Down

0 comments on commit c170c12

Please sign in to comment.