Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve bulk actions #10477

Merged
merged 2 commits into from
Jul 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Sylius/Behat/Page/Admin/Crud/IndexPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public function filter(): void

public function bulkDelete(): void
{
$this->getElement('bulk_actions', ['%text%' => 'Bulk actions'])->pressButton('Delete');
$this->getElement('bulk_actions')->pressButton('Delete');
$this->getElement('confirmation_button')->click();
}

Expand All @@ -152,7 +152,7 @@ protected function getTableAccessor(): TableAccessorInterface
protected function getDefinedElements(): array
{
return array_merge(parent::getDefinedElements(), [
'bulk_actions' => '.accordion:contains("%text%")',
'bulk_actions' => '.sylius-grid-nav__bulk',
'confirmation_button' => '#confirmation-button',
'filter' => 'button:contains("Filter")',
'table' => '.table',
Expand Down
2 changes: 2 additions & 0 deletions src/Sylius/Bundle/UiBundle/Resources/private/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import './sylius-bulk-action-require-confirmation';
import './sylius-form-collection';
import './sylius-require-confirmation';
import './sylius-toggle';
import './sylius-check-all';

$(document).ready(() => {
$('#sidebar').addClass('visible');
Expand Down Expand Up @@ -54,6 +55,7 @@ $(document).ready(() => {
$('[data-requires-confirmation]').requireConfirmation();
$('[data-bulk-action-requires-confirmation]').bulkActionRequireConfirmation();
$('[data-toggles]').toggleElement();
$('[data-js-bulk-checkboxes]').checkAll();

$('.special.cards .image').dimmer({
on: 'hover',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

import $ from 'jquery';

$.fn.extend({
checkAll() {
this.each((idx, el) => {
const $checkboxAll = $(el);
const $checkboxes = $($checkboxAll.attr('data-js-bulk-checkboxes'));
const $buttons = $($checkboxAll.attr('data-js-bulk-buttons'));

const isAnyChecked = () => {
let checked = false;
$checkboxes.each((i, checkbox) => {
if (checkbox.checked) checked = true;
});
return checked;
};

const buttonsPropRefresh = () => {
$buttons.find('button').prop('disabled', !isAnyChecked());
};

$checkboxAll.on('change', () => {
$checkboxes.prop('checked', $(this).is(':checked'));
buttonsPropRefresh();
});

$checkboxes.on('change', () => {
$checkboxAll.prop('checked', isAnyChecked());
buttonsPropRefresh();
});

buttonsPropRefresh();
});
},
});
18 changes: 18 additions & 0 deletions src/Sylius/Bundle/UiBundle/Resources/private/sass/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,19 @@ th {
}
.sylius-grid-wrapper {
.sylius-grid-nav {
.sylius-grid-nav__bulk,
.sylius-grid-nav__pagination,
.sylius-grid-nav__perpage {
padding-bottom: 1rem;
}
}

.sylius-grid-nav__bulk {
.ui.red.labeled.icon.button:disabled {
background: #b9babb !important;
}
}

.sylius-grid-table-wrapper {
overflow-x: auto;
margin-bottom: 1rem;
Expand All @@ -138,12 +146,22 @@ th {
margin-left: -1rem;
margin-right: -1rem;

.sylius-grid-nav__bulk,
.sylius-grid-nav__pagination,
.sylius-grid-nav__perpage {
padding-left: 1rem;
padding-right: 1rem;
}

.sylius-grid-nav__bulk {
display: flex;

.button {
padding-top: 0.99em !important;
padding-bottom: 0.99em !important;
}
}

.sylius-grid-nav__pagination {
flex-grow: 1;
}
Expand Down
36 changes: 13 additions & 23 deletions src/Sylius/Bundle/UiBundle/Resources/views/Grid/_default.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -34,37 +34,27 @@
</div>
{% endif %}

{% if data|length > 0 and definition.actionGroups.bulk is defined and definition.getEnabledActions('bulk')|length > 0 %}
<div class="ui hidden divider"></div>
<div class="ui styled fluid accordion">
<div class="title active">
<i class="dropdown icon"></i>
{{ 'sylius.ui.bulk_actions'|trans }}
</div>
<div class="content active">
{% for action in definition.getEnabledActions('bulk') %}
{{ sylius_grid_render_bulk_action(grid, action, null) }}
{% endfor %}
</div>
</div>
{% endif %}

<div class="ui hidden divider"></div>
<div class="sylius-grid-wrapper">
{% if definition.limits|length > 1 and data|length > min(definition.limits) %}
<div class="sylius-grid-nav">
<div class="sylius-grid-nav__pagination">
{{ pagination.simple(data) }}
<div class="sylius-grid-nav">
{% if data|length > 0 and definition.actionGroups.bulk is defined and definition.getEnabledActions('bulk')|length > 0 %}
<div class="sylius-grid-nav__bulk">
{% for action in definition.getEnabledActions('bulk') %}
{{ sylius_grid_render_bulk_action(grid, action, null) }}
{% endfor %}
</div>
{% endif %}
<div class="sylius-grid-nav__pagination">
{{ pagination.simple(data) }}
</div>
{% if definition.limits|length > 1 and data|length > min(definition.limits) %}
<div class="sylius-grid-nav__perpage">
<div class="ui fluid one menu sylius-paginate">
{{ pagination.perPage(data, definition.limits) }}
</div>
</div>
</div>
{% else %}
{{ pagination.simple(data) }}
{% endif %}
{% endif %}
</div>

{% if data|length > 0 %}
<div class="ui segment spaceless sylius-grid-table-wrapper">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
{% import '@SyliusUi/Macro/sorting.html.twig' as sorting %}

{% if definition.actionGroups.bulk is defined and definition.getEnabledActions('bulk')|length > 0 %}
<th></th>
<th class="center aligned">
<input data-js-bulk-checkboxes=".bulk-select-checkbox" data-js-bulk-buttons=".sylius-grid-nav__bulk" type="checkbox">
</th>
{% endif %}

{% for field in definition.fields|sort_by('position') %}
Expand All @@ -22,7 +24,7 @@
{% macro row(grid, definition, row) %}
<tr class="item">
{% if definition.actionGroups.bulk is defined and definition.getEnabledActions('bulk')|length > 0 %}
<td><input class="bulk-select-checkbox" type="checkbox" value="{{ row.id }}" /></td>
<td class="center aligned"><input class="bulk-select-checkbox" type="checkbox" value="{{ row.id }}" /></td>
{% endif %}
{% for field in definition.enabledFields|sort_by('position') %}
<td>{{ sylius_grid_render_field(grid, field, row) }}</td>
Expand Down