Skip to content

Commit

Permalink
Controllers should start with sonata prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
onEXHovia committed Dec 16, 2024
1 parent dba76df commit 4c8d076
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 23 deletions.
4 changes: 2 additions & 2 deletions assets/js/controllers/filter_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { controlValue, convertQueryStringToObject } from '../utils';

export default class extends Controller {
static targets = ['form', 'group', 'advanced', 'submitter'];
static outlets = ['filter-list'];
static outlets = ['sonata-filter-list'];
static values = {
defaultValues: Object,
};
Expand Down Expand Up @@ -90,7 +90,7 @@ export default class extends Controller {

hideFilter({ params }) {
this.toggleFilter(params.id, false);
this.filterListOutlet.disable(params.id);
this.sonataFilterListOutlet.disable(params.id);
}

get visibleGroups() {
Expand Down
4 changes: 2 additions & 2 deletions assets/js/controllers/filter_list_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Controller } from '@hotwired/stimulus';

export default class extends Controller {
static targets = ['counter', 'field'];
static outlets = ['filter'];
static outlets = ['sonata-filter'];
static classes = ['active'];

connect() {
Expand All @@ -35,7 +35,7 @@ export default class extends Controller {
const state = field.classList.contains(this.activeClass);
field.classList.toggle(this.activeClass, !state);

this.filterOutlet.toggleFilter(field.dataset.filter, !state);
this.sonataFilterOutlet.toggleFilter(field.dataset.filter, !state);
this.updateCounter();
}

Expand Down
22 changes: 15 additions & 7 deletions assets/js/stimulus.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,21 @@
* file that was distributed with this source code.
*/

// eslint-disable-next-line import/no-extraneous-dependencies
import { definitionsFromContext } from '@hotwired/stimulus-webpack-helpers';
import { startStimulusApp } from '@symfony/stimulus-bridge';

// eslint-disable-next-line import/prefer-default-export
export const sonataApplication = startStimulusApp(
require.context(
'@symfony/stimulus-bridge/lazy-controller-loader!./controllers',
true,
/\.[jt]sx?$/
)
);
export const sonataApplication = startStimulusApp();

const definitions = definitionsFromContext(require.context(
'@symfony/stimulus-bridge/lazy-controller-loader!./controllers',
true,
/\.[jt]sx?$/
));

definitions.forEach((definition) => {
definition.identifier = `sonata-${definition.identifier}`;
});

sonataApplication.load(definitions);
2 changes: 1 addition & 1 deletion src/Resources/public/app.js

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions src/Resources/views/CRUD/base_list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,13 @@ file that was distributed with this source code.
{# NEXT_MAJOR: Remove |default(filter.option('show_filter')) #}
{% set displayableFilters = admin.datagrid.filters|filter(filter => filter.showFilter|default(filter.option('show_filter')) is not same as (false)) %}
{%- if displayableFilters|length %}
<ul class="nav navbar-nav navbar-right" id="filter-list-{{ admin.uniqid() }}" {{ stimulus_controller('filter_list', {}, { 'active': 'active' }, { 'filter': '#filter-container-' ~ admin.uniqid() }) }}>
<ul class="nav navbar-nav navbar-right" id="filter-list-{{ admin.uniqid() }}" {{ stimulus_controller('sonata-filter-list', {}, { 'active': 'active' }, { 'sonata-filter': '#filter-container-' ~ admin.uniqid() }) }}>

<li class="dropdown sonata-actions">
<a href="#" class="dropdown-toggle sonata-ba-action" data-toggle="dropdown">
<i class="fas fa-filter" aria-hidden="true"></i>
{{ 'link_filters'|trans({}, 'SonataAdminBundle') }}
<span class="badge" {{ stimulus_target('filter_list', 'counter') }}></span>
<span class="badge" {{ stimulus_target('sonata-filter-list', 'counter') }}></span>
<b class="caret"></b>
</a>

Expand All @@ -274,7 +274,7 @@ file that was distributed with this source code.
{# NEXT_MAJOR: Remove |default(filter.option('show_filter')) #}
{% set filterDisplayed = filter.isActive() or filter.showFilter|default(filter.option('show_filter')) is same as (true) %}
<li>
<a href="#" class="sonata-toggle-filter sonata-ba-action{% if filterDisplayed %} active{% endif %}" data-filter="filter-{{ admin.uniqid }}-{{ filter.name }}" {{ stimulus_target('filter_list', 'field') }} {{ stimulus_action('filter_list', 'toggle', 'click') }}>
<a href="#" class="sonata-toggle-filter sonata-ba-action{% if filterDisplayed %} active{% endif %}" data-filter="filter-{{ admin.uniqid }}-{{ filter.name }}" {{ stimulus_target('sonata-filter-list', 'field') }} {{ stimulus_action('sonata-filter-list', 'toggle', 'click') }}>
<i class="far"></i>
{% if filter.label is not same as(false) %}
{% if filter.translationDomain is same as(false) %}
Expand All @@ -299,16 +299,16 @@ file that was distributed with this source code.
{% form_theme form get_admin_template('filter', admin.code) %}

<div class="col-xs-12 col-md-12 sonata-filters-box"
id="filter-container-{{ admin.uniqid() }}" {{ stimulus_controller('filter', { 'defaultValues': admin.defaultFilterParameters|json_encode }, {}, { 'filter-list': '#filter-list-' ~ admin.uniqid() }) }} {% if not admin.datagrid.hasDisplayableFilters %}hidden{% endif %}>
id="filter-container-{{ admin.uniqid() }}" {{ stimulus_controller('sonata-filter', { 'defaultValues': admin.defaultFilterParameters|json_encode }, {}, { 'sonata-filter-list': '#filter-list-' ~ admin.uniqid() }) }} {% if not admin.datagrid.hasDisplayableFilters %}hidden{% endif %}>
<div class="box box-primary" >
<div class="box-body">
<form
class="sonata-filter-form form-horizontal {{ admin.isChild and 1 == admin.datagrid.filters|length ? 'hide' : '' }}"
action="{{ admin.generateUrl(action|default('list')) }}"
method="GET"
role="form"
{{ stimulus_target('filter', 'form') }}
{{ stimulus_action('filter', 'prepareSubmit', 'submit') }}>
{{ stimulus_target('sonata-filter', 'form') }}
{{ stimulus_action('sonata-filter', 'prepareSubmit', 'submit') }}>
{{ form_errors(form) }}

<div class="row">
Expand All @@ -318,7 +318,7 @@ file that was distributed with this source code.
{# NEXT_MAJOR: Remove |default(filter.option('show_filter')) #}
{% set filterDisplayed = filter.isActive() or filter.showFilter|default(filter.option('show_filter')) is same as (true) %}
{% set filterCanBeDisplayed = filter.option('show_filter') is not same as(false) %}
<div class="form-group {% block sonata_list_filter_group_class %}{% endblock %}" id="filter-{{ admin.uniqid }}-{{ filter.name }}" {{ stimulus_target('filter', 'group') }} {% if not filterDisplayed %}hidden{% endif %}>
<div class="form-group {% block sonata_list_filter_group_class %}{% endblock %}" id="filter-{{ admin.uniqid }}-{{ filter.name }}" {{ stimulus_target('sonata-filter', 'group') }} {% if not filterDisplayed %}hidden{% endif %}>
{% if filter.label is not same as(false) %}
<label for="{{ form[filter.formName].children['value'].vars.id }}" class="col-sm-3 control-label">
{% if filter.translationDomain is same as(false) %}
Expand All @@ -329,7 +329,7 @@ file that was distributed with this source code.
</label>
{% endif %}
{% set attr = form[filter.formName].children['type'].vars.attr|default({}) %}
<div class="col-sm-4 advanced-filter" {{ stimulus_target('filter', 'advanced') }} {% if not field_value(form[filter.formName].children['type']) %}hidden{% endif %}>
<div class="col-sm-4 advanced-filter" {{ stimulus_target('sonata-filter', 'advanced') }} {% if not field_value(form[filter.formName].children['type']) %}hidden{% endif %}>
{{ form_widget(form[filter.formName].children['type'], {'attr': attr}) }}
</div>

Expand All @@ -340,7 +340,7 @@ file that was distributed with this source code.
{% if filterCanBeDisplayed %}
<div class="col-sm-1">
<label class="control-label">
<a href="#" class="sonata-ba-action" {{ stimulus_action('filter', 'hideFilter', 'click', { 'id': 'filter-' ~ admin.uniqid ~ '-' ~ filter.name }) }}>
<a href="#" class="sonata-ba-action" {{ stimulus_action('sonata-filter', 'hideFilter', 'click', { 'id': 'filter-' ~ admin.uniqid ~ '-' ~ filter.name }) }}>
<i class="fas fa-minus-circle" aria-hidden="true"></i>
</a>
</label>
Expand All @@ -361,7 +361,7 @@ file that was distributed with this source code.
{{ form_rest(form) }}

<div class="form-group">
<button type="submit" class="btn btn-primary" {{ stimulus_target('filter', 'submitter') }}>
<button type="submit" class="btn btn-primary" {{ stimulus_target('sonata-filter', 'submitter') }}>
<i class="fas fa-filter" aria-hidden="true"></i> {{ 'btn_filter'|trans({}, 'SonataAdminBundle') }}
</button>

Expand All @@ -372,7 +372,7 @@ file that was distributed with this source code.

{% if withAdvancedFilter %}
<div class="form-group">
<a href="#" {{ stimulus_action('filter', 'toggleAdvanced', 'click') }}>
<a href="#" {{ stimulus_action('sonata-filter', 'toggleAdvanced', 'click') }}>
<i class="fas fa-cogs" aria-hidden="true"></i>
{{ 'btn_advanced_filters'|trans({}, 'SonataAdminBundle') }}
</a>
Expand Down

0 comments on commit 4c8d076

Please sign in to comment.