Преглед изворни кода

fix item by page + status checkbox

feature/symfony6.1
Charly пре 1 година
родитељ
комит
250268e18e
4 измењених фајлова са 56 додато и 6421 уклоњено
  1. +47
    -36
      Controller/AbstractAdminController.php
  2. +8
    -8
      Resources/assets/app/adminlte/index/index.js
  3. +1
    -0
      Resources/views/adminlte/crud/field/toggle.html.twig
  4. +0
    -6377
      composer.lock

+ 47
- 36
Controller/AbstractAdminController.php Прегледај датотеку

@@ -66,8 +66,6 @@ abstract class AbstractAdminController extends EaAbstractCrudController
abstract public function getRepositoryQuery(): RepositoryQueryInterface;




public function configureResponseParameters(KeyValueStore $responseParameters): KeyValueStore
{
if ($responseParameters->get('global_actions')) {
@@ -184,9 +182,15 @@ abstract class AbstractAdminController extends EaAbstractCrudController
if ($requestListMaxResults) {
$this->getRequestStack()->getSession()->set($paramSessionListMaxResults, $requestListMaxResults);
}
$maxResults = $this->getRequestStack()->getSession()->get($paramSessionListMaxResults) ? $this->get('session')->get(

$maxResults = $this->getRequestStack()->getSession()->get(
$paramSessionListMaxResults
) : 30;
) ? $this->requestStack->getSession()->get($paramSessionListMaxResults) : 30;
// $maxResults = $this->getRequestStack()->getSession()->get($paramSessionListMaxResults) ? $this->get(
// 'session'
// )->get(
// $paramSessionListMaxResults
// ) : 30;

$crud->setPaginatorPageSize($maxResults);
}
@@ -247,7 +251,10 @@ abstract class AbstractAdminController extends EaAbstractCrudController
$queryBuilder = $this->createSortQueryBuilder($context->getSearch(), $context->getEntity(), $fields, $filters);
$paginator = $this->container->get(PaginatorFactory::class)->create($queryBuilder);

$entities = $this->container->get(EntityFactory::class)->createCollection($context->getEntity(), $paginator->getResults());
$entities = $this->container->get(EntityFactory::class)->createCollection(
$context->getEntity(),
$paginator->getResults()
);
$this->container->get(EntityFactory::class)->processFieldsForAll($entities, $fields);

$sortableForm = $this->createFormBuilder(array('entities', $paginator->getResults()))
@@ -320,12 +327,11 @@ abstract class AbstractAdminController extends EaAbstractCrudController
}

public function duplicate(
AdminContext $context,
EntityComponent $entityComponent,
TranslatorAdmin $translatorAdmin,
AdminContext $context,
EntityComponent $entityComponent,
TranslatorAdmin $translatorAdmin,
EntityManagerInterface $em
)
{
) {
if (!$this->isGranted(
Permission::EA_EXECUTE_ACTION,
['action' => ActionDefinition::DUPLICATE, 'entity' => $context->getEntity()]
@@ -361,12 +367,11 @@ abstract class AbstractAdminController extends EaAbstractCrudController
}

public function createIndexRepositoryQuery(
SearchDto $searchDto,
EntityDto $entityDto,
FieldCollection $fields,
SearchDto $searchDto,
EntityDto $entityDto,
FieldCollection $fields,
FilterCollection $filters
): RepositoryQueryInterface
{
): RepositoryQueryInterface {
$repositoryQuery = $this->container->get(EntityRepository::class)->createRepositoryQuery(
$this->getRepositoryQuery(),
$searchDto,
@@ -401,18 +406,22 @@ abstract class AbstractAdminController extends EaAbstractCrudController
$filterManager = $this->getFilterManager();

$this->filtersForm->handleRequest($searchDto->getRequest());
$this->isRepositoryQueryFiltered = $filterManager->handleFiltersForm($repositoryQuery, $this->filtersForm, $fields, $entityDto);
$this->isRepositoryQueryFiltered = $filterManager->handleFiltersForm(
$repositoryQuery,
$this->filtersForm,
$fields,
$entityDto
);
return $repositoryQuery;
}


public function createSortRepositoryQuery(
SearchDto $searchDto,
EntityDto $entityDto,
FieldCollection $fields,
SearchDto $searchDto,
EntityDto $entityDto,
FieldCollection $fields,
FilterCollection $filters
): RepositoryQueryInterface
{
): RepositoryQueryInterface {
$repositoryQuery = $this->createIndexRepositoryQuery($searchDto, $entityDto, $fields, $filters);
if ($this->isInstanceOf(StatusInterface::class)) {
$repositoryQuery->filterIsOnline();
@@ -422,34 +431,33 @@ abstract class AbstractAdminController extends EaAbstractCrudController
}

public function createIndexQueryBuilder(
SearchDto $searchDto,
EntityDto $entityDto,
FieldCollection $fields,
SearchDto $searchDto,
EntityDto $entityDto,
FieldCollection $fields,
FilterCollection $filters
): QueryBuilder
{
): QueryBuilder {
$repositoryQuery = $this->createIndexRepositoryQuery($searchDto, $entityDto, $fields, $filters);
return $repositoryQuery->getQueryBuilder();
}

public function createSortQueryBuilder(
SearchDto $searchDto,
EntityDto $entityDto,
FieldCollection $fields,
SearchDto $searchDto,
EntityDto $entityDto,
FieldCollection $fields,
FilterCollection $filters
): QueryBuilder
{
): QueryBuilder {
$repositoryQuery = $this->createSortRepositoryQuery($searchDto, $entityDto, $fields, $filters);
return $repositoryQuery->getQueryBuilder();
}

public function edit(AdminContext $context)
{
$response = parent::edit($context);;
$context->getRequest()->setMethod('PATCH');
$response = parent::edit($context);

// on vide le flash bag si édition en ajax (notification déjà affichée en Javascript)
if ($context->getRequest()->isXmlHttpRequest()) {
$this->get('session')->getFlashBag()->clear();
$this->requestStack->getSession()->getFlashBag()->clear();
}

return $response;
@@ -561,7 +569,7 @@ abstract class AbstractAdminController extends EaAbstractCrudController
'label' => false,
'html_attributes' => array(
'data-toggle' => 'tooltip',
'title' =>$this->translatorAdmin->transAction('detail'),
'title' => $this->translatorAdmin->transAction('detail'),
),
]
);
@@ -626,7 +634,7 @@ abstract class AbstractAdminController extends EaAbstractCrudController
ActionDefinition::SAVE_AND_CONTINUE,
[
'class' => 'btn btn-info float-right action-save-continue',
'label' =>$this->translatorAdmin->transAction('save_and_continue'),
'label' => $this->translatorAdmin->transAction('save_and_continue'),
]
);

@@ -844,7 +852,10 @@ abstract class AbstractAdminController extends EaAbstractCrudController
return $event->getResponse();
}

if (!$this->isGranted(Permission::EA_EXECUTE_ACTION, ['action' => Action::DELETE, 'entity' => $context->getEntity()])) {
if (!$this->isGranted(
Permission::EA_EXECUTE_ACTION,
['action' => Action::DELETE, 'entity' => $context->getEntity()]
)) {
throw new ForbiddenActionException($context);
}
if (!$context->getEntity()->isAccessible()) {

+ 8
- 8
Resources/assets/app/adminlte/index/index.js Прегледај датотеку

@@ -1,10 +1,8 @@


$(document).ready(function() {
lcCrudIndexToggle() ;
lcCrudIndexBatchActions() ;
$(document).ready(function () {
lcCrudIndexToggle();
lcCrudIndexBatchActions();
lcCrudIndexInitFilter();
}) ;
});

function lcCrudIndexToggle() {
const toggles = document.querySelectorAll('.custom-switch input[type="checkbox"]');
@@ -13,7 +11,8 @@ function lcCrudIndexToggle() {
const toggle = this;
const newValue = this.checked;
const oldValue = !newValue;
const toggleUrl = this.closest('.custom-switch').dataset.url + "&newValue=" + newValue.toString();
const csrfToken = this.closest('.custom-switch').querySelector('.token').value;
const toggleUrl = this.closest('.custom-switch').dataset.url + "&newValue=" + newValue.toString() + "&csrfToken=" + csrfToken;

let toggleRequest = $.ajax({type: "POST", url: toggleUrl, data: {}, dataType: 'json'});

@@ -21,7 +20,8 @@ function lcCrudIndexToggle() {
SovNotification.add('success', 'La propriété a bien été mise à jour.');
});

toggleRequest.fail(function () {
toggleRequest.fail(function (response) {
console.log(response);
toggle.checked = oldValue;
toggle.disabled = true;
toggle.closest('.checkbox-switch').classList.add('disabled');

+ 1
- 0
Resources/views/adminlte/crud/field/toggle.html.twig Прегледај датотеку

@@ -8,5 +8,6 @@
<input type="checkbox" class="custom-control-input" id="{{ id_toggle }}" {{ field.value ? 'checked' }}>
<label class="custom-control-label" for="{{ id_toggle }}" >
</label>
<input class="token" type="hidden" name="token" value="{{ csrf_token('ea-toggle') }}">
</div>
{% endblock toggle %}

+ 0
- 6377
composer.lock
Разлика између датотеке није приказан због своје велике величине
Прегледај датотеку


Loading…
Откажи
Сачувај