Skip to content

Commit

Permalink
category list in admin now use common domain filter
Browse files Browse the repository at this point in the history
  • Loading branch information
grossmannmartin committed Sep 21, 2023
1 parent 64114d8 commit ca8a072
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 69 deletions.
50 changes: 9 additions & 41 deletions src/Controller/Admin/CategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,33 @@
namespace Shopsys\FrameworkBundle\Controller\Admin;

use Nette\Utils\Json;
use Shopsys\FrameworkBundle\Component\Domain\AdminDomainFilterTabsFacade;
use Shopsys\FrameworkBundle\Component\Domain\Domain;
use Shopsys\FrameworkBundle\Component\Domain\Exception\InvalidDomainIdException;
use Shopsys\FrameworkBundle\Component\Router\Security\Annotation\CsrfProtection;
use Shopsys\FrameworkBundle\Form\Admin\Category\CategoryFormType;
use Shopsys\FrameworkBundle\Model\AdminNavigation\BreadcrumbOverrider;
use Shopsys\FrameworkBundle\Model\Category\CategoryDataFactoryInterface;
use Shopsys\FrameworkBundle\Model\Category\CategoryFacade;
use Shopsys\FrameworkBundle\Model\Category\Exception\CategoryNotFoundException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class CategoryController extends AdminBaseController
{
protected const ALL_DOMAINS = 0;

/**
* @param \Shopsys\FrameworkBundle\Model\Category\CategoryFacade $categoryFacade
* @param \Shopsys\FrameworkBundle\Model\Category\CategoryDataFactoryInterface $categoryDataFactory
* @param \Shopsys\FrameworkBundle\Component\Domain\Domain $domain
* @param \Shopsys\FrameworkBundle\Model\AdminNavigation\BreadcrumbOverrider $breadcrumbOverrider
* @param \Symfony\Component\HttpFoundation\RequestStack $requestStack
* @param \Shopsys\FrameworkBundle\Component\Domain\AdminDomainFilterTabsFacade $adminDomainFilterTabsFacade
*/
public function __construct(
protected readonly CategoryFacade $categoryFacade,
protected readonly CategoryDataFactoryInterface $categoryDataFactory,
protected readonly Domain $domain,
protected readonly BreadcrumbOverrider $breadcrumbOverrider,
protected readonly RequestStack $requestStack,
protected readonly AdminDomainFilterTabsFacade $adminDomainFilterTabsFacade,
) {
}

Expand Down Expand Up @@ -128,40 +125,24 @@ public function newAction(Request $request): Response
*/
public function listAction(Request $request): Response
{
if (count($this->domain->getAll()) > 1) {
if ($request->query->has('domain')) {
$domainId = (int)$request->query->get('domain');
} else {
$domainId = (int)$this->requestStack->getSession()->get('categories_selected_domain_id', static::ALL_DOMAINS);
}
} else {
$domainId = static::ALL_DOMAINS;
}
$domainFilterNamespace = 'category';
$selectedDomainId = $this->adminDomainFilterTabsFacade->getSelectedDomainId($domainFilterNamespace);

if ($domainId !== static::ALL_DOMAINS) {
try {
$this->domain->getDomainConfigById($domainId);
} catch (InvalidDomainIdException $ex) {
$domainId = static::ALL_DOMAINS;
}
}

$this->requestStack->getSession()->set('categories_selected_domain_id', $domainId);

if ($domainId === static::ALL_DOMAINS) {
if ($selectedDomainId === null) {
$categoriesWithPreloadedChildren = $this->categoryFacade->getAllCategoriesWithPreloadedChildren(
$request->getLocale(),
);
} else {
$categoriesWithPreloadedChildren = $this->categoryFacade->getVisibleCategoriesWithPreloadedChildrenForDomain(
$domainId,
$selectedDomainId,
$request->getLocale(),
);
}

return $this->render('@ShopsysFramework/Admin/Content/Category/list.html.twig', [
'categoriesWithPreloadedChildren' => $categoriesWithPreloadedChildren,
'isForAllDomains' => ($domainId === static::ALL_DOMAINS),
'domainFilterNamespace' => $domainFilterNamespace,
'isForAllDomains' => ($selectedDomainId === null),
]);
}

Expand Down Expand Up @@ -207,19 +188,6 @@ public function deleteAction(int $id): Response
return $this->redirectToRoute('admin_category_list');
}

/**
* @return \Symfony\Component\HttpFoundation\Response
*/
public function listDomainTabsAction(): Response
{
$domainId = $this->requestStack->getSession()->get('categories_selected_domain_id', static::ALL_DOMAINS);

return $this->render('@ShopsysFramework/Admin/Content/Category/domainTabs.html.twig', [
'domainConfigs' => $this->domain->getAll(),
'selectedDomainId' => $domainId,
]);
}

/**
* @Route("/category/branch/{domainId}/{id}", requirements={"domainId" = "\d+", "id" = "\d+"}, condition="request.isXmlHttpRequest()")
* @param int $domainId
Expand Down
27 changes: 0 additions & 27 deletions src/Resources/views/Admin/Content/Category/domainTabs.html.twig

This file was deleted.

2 changes: 1 addition & 1 deletion src/Resources/views/Admin/Content/Category/list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{% endblock %}

{% block main_content %}
{{ render(controller('Shopsys\\FrameworkBundle\\Controller\\Admin\\CategoryController::listDomainTabsAction')) }}
{{ render(controller('Shopsys\\FrameworkBundle\\Controller\\Admin\\DomainFilterController::domainFilterTabsAction', { namespace: domainFilterNamespace })) }}

{% macro categoryTreeItem(categoriesWithPreloadedChildren, isFirstLevel) %}
{% import _self as self %}
Expand Down

0 comments on commit ca8a072

Please sign in to comment.