Skip to content

Commit

Permalink
[shopsys] added order filter by domain in admin (#2796)
Browse files Browse the repository at this point in the history
  • Loading branch information
grossmannmartin authored Sep 21, 2023
2 parents bb60a07 + 6b568d7 commit a159284
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 196 deletions.
68 changes: 13 additions & 55 deletions app/src/Controller/Admin/BlogArticleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,78 +9,49 @@
use App\Model\Blog\Article\BlogArticleFacade;
use App\Model\Blog\Article\BlogArticleGridFactory;
use Shopsys\FrameworkBundle\Component\ConfirmDelete\ConfirmDeleteResponseFactory;
use Shopsys\FrameworkBundle\Component\Domain\AdminDomainTabsFacade;
use Shopsys\FrameworkBundle\Component\Domain\Domain;
use Shopsys\FrameworkBundle\Component\Domain\Exception\InvalidDomainIdException;
use Shopsys\FrameworkBundle\Component\Domain\AdminDomainFilterTabsFacade;
use Shopsys\FrameworkBundle\Component\Router\Security\Annotation\CsrfProtection;
use Shopsys\FrameworkBundle\Controller\Admin\AdminBaseController;
use Shopsys\FrameworkBundle\Model\AdminNavigation\BreadcrumbOverrider;
use Shopsys\FrameworkBundle\Model\Article\Exception\ArticleNotFoundException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Routing\Annotation\Route;

class BlogArticleController extends AdminBaseController
{
private const ALL_DOMAINS = 0;
private const SESSION_BLOG_ARTICLES_SELECTED_DOMAIN_ID = 'blog_articles_selected_domain_id';

/**
* @param \App\Model\Blog\Article\BlogArticleFacade $blogArticleFacade
* @param \App\Model\Blog\Article\BlogArticleDataFactory $blogArticleDataFactory
* @param \Shopsys\FrameworkBundle\Component\Domain\AdminDomainTabsFacade $adminDomainTabsFacade
* @param \Shopsys\FrameworkBundle\Model\AdminNavigation\BreadcrumbOverrider $breadcrumbOverrider
* @param \Shopsys\FrameworkBundle\Component\ConfirmDelete\ConfirmDeleteResponseFactory $confirmDeleteResponseFactory
* @param \App\Model\Blog\Article\BlogArticleGridFactory $blogArticleGridFactory
* @param \Symfony\Component\HttpFoundation\Session\SessionInterface $session
* @param \Shopsys\FrameworkBundle\Component\Domain\Domain $domain
* @param \Shopsys\FrameworkBundle\Component\Domain\AdminDomainFilterTabsFacade $adminDomainFilterTabsFacade
*/
public function __construct(
private BlogArticleFacade $blogArticleFacade,
private BlogArticleDataFactory $blogArticleDataFactory,
private AdminDomainTabsFacade $adminDomainTabsFacade,
private BreadcrumbOverrider $breadcrumbOverrider,
private ConfirmDeleteResponseFactory $confirmDeleteResponseFactory,
private BlogArticleGridFactory $blogArticleGridFactory,
private SessionInterface $session,
private Domain $domain,
private readonly BlogArticleFacade $blogArticleFacade,
private readonly BlogArticleDataFactory $blogArticleDataFactory,
private readonly BreadcrumbOverrider $breadcrumbOverrider,
private readonly ConfirmDeleteResponseFactory $confirmDeleteResponseFactory,
private readonly BlogArticleGridFactory $blogArticleGridFactory,
private readonly AdminDomainFilterTabsFacade $adminDomainFilterTabsFacade,
) {
}

/**
* @Route("/blog/article/list/", name="admin_blogarticle_list")
* @param \Symfony\Component\HttpFoundation\Request $request
* @return \Symfony\Component\HttpFoundation\Response
*/
public function listAction(Request $request): Response
public function listAction(): Response
{
if (count($this->domain->getAll()) > 1) {
if ($request->query->has('domain')) {
$domainId = (int)$request->query->get('domain');
} else {
$domainId = (int)$this->session->get(self::SESSION_BLOG_ARTICLES_SELECTED_DOMAIN_ID, self::ALL_DOMAINS);
}
} else {
$domainId = self::ALL_DOMAINS;
}
$domainFilterNamespace = 'blog-article';
$selectedDomainId = $this->adminDomainFilterTabsFacade->getSelectedDomainId($domainFilterNamespace);

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

$this->session->set(self::SESSION_BLOG_ARTICLES_SELECTED_DOMAIN_ID, $domainId);

$grid = $this->blogArticleGridFactory->create($domainId);
$blogArticlesCountOnSelectedDomain = $this->blogArticleFacade->getAllArticlesCountByDomainId($this->adminDomainTabsFacade->getSelectedDomainId());
$grid = $this->blogArticleGridFactory->create($selectedDomainId);

return $this->render('Admin/Content/Blog/Article/list.html.twig', [
'gridView' => $grid->createView(),
'blogArticlesCountOnSelectedDomain' => $blogArticlesCountOnSelectedDomain,
'domainFilterNamespace' => $domainFilterNamespace,
]);
}

Expand Down Expand Up @@ -202,17 +173,4 @@ public function deleteConfirmAction(int $id): Response

return $this->confirmDeleteResponseFactory->createDeleteResponse($message, 'admin_blogarticle_delete', $id);
}

/**
* @return \Symfony\Component\HttpFoundation\Response
*/
public function listDomainTabsAction(): Response
{
$domainId = $this->session->get(self::SESSION_BLOG_ARTICLES_SELECTED_DOMAIN_ID, self::ALL_DOMAINS);

return $this->render('Admin/Content/Blog/Article/domainTabs.html.twig', [
'domainConfigs' => $this->domain->getAll(),
'selectedDomainId' => $domainId,
]);
}
}
67 changes: 18 additions & 49 deletions app/src/Controller/Admin/BlogCategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,28 @@
use App\Model\Blog\Category\BlogCategoryFacade;
use App\Model\Blog\Category\Exception\BlogCategoryNotFoundException;
use Nette\Utils\Json;
use Shopsys\FrameworkBundle\Component\Domain\Domain;
use Shopsys\FrameworkBundle\Component\Domain\Exception\InvalidDomainIdException;
use Shopsys\FrameworkBundle\Component\Domain\AdminDomainFilterTabsFacade;
use Shopsys\FrameworkBundle\Component\Router\Security\Annotation\CsrfProtection;
use Shopsys\FrameworkBundle\Controller\Admin\AdminBaseController;
use Shopsys\FrameworkBundle\Model\AdminNavigation\BreadcrumbOverrider;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Routing\Annotation\Route;

class BlogCategoryController extends AdminBaseController
{
private const ALL_DOMAINS = 0;
private const SESSION_BLOG_CATEGORIES_SELECTED_DOMAIN_ID = 'blog_categories_selected_domain_id';

/**
* @param \App\Model\Blog\Category\BlogCategoryFacade $blogCategoryFacade
* @param \App\Model\Blog\Category\BlogCategoryDataFactory $blogCategoryDataFactory
* @param \Symfony\Component\HttpFoundation\Session\SessionInterface $session
* @param \Shopsys\FrameworkBundle\Component\Domain\Domain $domain
* @param \Shopsys\FrameworkBundle\Model\AdminNavigation\BreadcrumbOverrider $breadcrumbOverrider
* @param \Shopsys\FrameworkBundle\Component\Domain\AdminDomainFilterTabsFacade $adminDomainFilterTabsFacade
*/
public function __construct(
private BlogCategoryFacade $blogCategoryFacade,
private BlogCategoryDataFactory $blogCategoryDataFactory,
private SessionInterface $session,
private Domain $domain,
private BreadcrumbOverrider $breadcrumbOverrider,
private readonly BlogCategoryFacade $blogCategoryFacade,
private readonly BlogCategoryDataFactory $blogCategoryDataFactory,
private readonly BreadcrumbOverrider $breadcrumbOverrider,
private readonly AdminDomainFilterTabsFacade $adminDomainFilterTabsFacade,
) {
}

Expand Down Expand Up @@ -128,35 +121,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->session->get(self::SESSION_BLOG_CATEGORIES_SELECTED_DOMAIN_ID, self::ALL_DOMAINS);
}
} else {
$domainId = self::ALL_DOMAINS;
}

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

$this->session->set(self::SESSION_BLOG_CATEGORIES_SELECTED_DOMAIN_ID, $domainId);
$domainFilterNamespace = 'blog-category';
$selectedDomainId = $this->adminDomainFilterTabsFacade->getSelectedDomainId($domainFilterNamespace);

if ($domainId === self::ALL_DOMAINS) {
$blogCategoriesWithPreloadedChildren = $this->blogCategoryFacade->getAllBlogCategoriesWithPreloadedChildren($request->getLocale());
if ($selectedDomainId === null) {
$blogCategoriesWithPreloadedChildren = $this->blogCategoryFacade->getAllBlogCategoriesWithPreloadedChildren(
$request->getLocale(),
);
} else {
$blogCategoriesWithPreloadedChildren = $this->blogCategoryFacade->getVisibleBlogCategoriesWithPreloadedChildrenOnDomain($domainId, $request->getLocale());
$blogCategoriesWithPreloadedChildren = $this->blogCategoryFacade->getVisibleBlogCategoriesWithPreloadedChildrenOnDomain(
$selectedDomainId,
$request->getLocale(),
);
}

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

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

/**
* @return \Symfony\Component\HttpFoundation\Response
*/
public function listDomainTabsAction(): Response
{
$domainId = $this->session->get(self::SESSION_BLOG_CATEGORIES_SELECTED_DOMAIN_ID, self::ALL_DOMAINS);

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

/**
* @Route("/blog/category/branch/{domainId}/{id}", requirements={"domainId" = "\d+", "id" = "\d+"}, condition="request.isXmlHttpRequest()", name="admin_blogcategory_loadbranchjson")
* @param int $domainId
Expand Down
44 changes: 16 additions & 28 deletions app/src/Controller/Admin/CategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@

use App\Component\Form\FormBuilderHelper;
use App\Model\CategorySeo\ReadyCategorySeoMixFacade;
use Shopsys\FrameworkBundle\Component\Domain\AdminDomainFilterTabsFacade;
use Shopsys\FrameworkBundle\Component\Domain\Domain;
use Shopsys\FrameworkBundle\Component\Domain\Exception\InvalidDomainIdException;
use Shopsys\FrameworkBundle\Controller\Admin\CategoryController as BaseCategoryController;
use Shopsys\FrameworkBundle\Model\AdminNavigation\BreadcrumbOverrider;
use Shopsys\FrameworkBundle\Model\Category\CategoryDataFactoryInterface;
use Shopsys\FrameworkBundle\Model\Category\CategoryFacade;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

Expand All @@ -27,18 +26,18 @@ class CategoryController extends BaseCategoryController
/**
* @param \App\Model\Category\CategoryFacade $categoryFacade
* @param \App\Model\Category\CategoryDataFactory $categoryDataFactory
* @param \Symfony\Component\HttpFoundation\RequestStack $requestStack
* @param \Shopsys\FrameworkBundle\Component\Domain\Domain $domain
* @param \Shopsys\FrameworkBundle\Model\AdminNavigation\BreadcrumbOverrider $breadcrumbOverrider
* @param \Shopsys\FrameworkBundle\Component\Domain\AdminDomainFilterTabsFacade $adminDomainFilterTabsFacade
* @param \App\Component\Form\FormBuilderHelper $formBuilderHelper
* @param \App\Model\CategorySeo\ReadyCategorySeoMixFacade $categorySeoMixFacade
*/
public function __construct(
CategoryFacade $categoryFacade,
CategoryDataFactoryInterface $categoryDataFactory,
RequestStack $requestStack,
Domain $domain,
BreadcrumbOverrider $breadcrumbOverrider,
AdminDomainFilterTabsFacade $adminDomainFilterTabsFacade,
private readonly FormBuilderHelper $formBuilderHelper,
private readonly ReadyCategorySeoMixFacade $categorySeoMixFacade,
) {
Expand All @@ -47,7 +46,7 @@ public function __construct(
$categoryDataFactory,
$domain,
$breadcrumbOverrider,
$requestStack,
$adminDomainFilterTabsFacade,
);
}

Expand All @@ -58,35 +57,24 @@ public function __construct(
*/
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;
}

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);
$domainFilterNamespace = 'category';
$selectedDomainId = $this->adminDomainFilterTabsFacade->getSelectedDomainId($domainFilterNamespace);

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

return $this->render('/Admin/Content/Category/list.html.twig', [
'categoriesWithPreloadedChildren' => $categoriesWithPreloadedChildren,
'isForAllDomains' => ($domainId === static::ALL_DOMAINS),
'isForAllDomains' => ($selectedDomainId === null),
'domainFilterNamespace' => $domainFilterNamespace,
'disabledFormFields' => $this->formBuilderHelper->hasFormDisabledFields(),
'getAllCategoryIdsInSeoMixes' => $this->categorySeoMixFacade->getAllCategoryIdsInSeoMixes(),
]);
Expand Down
13 changes: 6 additions & 7 deletions app/src/Model/Blog/Article/BlogArticleGridFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,19 @@ class BlogArticleGridFactory
* @param \Shopsys\FrameworkBundle\Component\Domain\Domain $domain
*/
public function __construct(
private BlogArticleRepository $blogArticleRepository,
private GridFactory $gridFactory,
private Domain $domain,
private readonly BlogArticleRepository $blogArticleRepository,
private readonly GridFactory $gridFactory,
private readonly Domain $domain,
) {
}

/**
* @param int $domainId
* @throws \Shopsys\FrameworkBundle\Component\Grid\Exception\DuplicateColumnIdException
* @param int|null $domainId
* @return \Shopsys\FrameworkBundle\Component\Grid\Grid
*/
public function create(int $domainId): Grid
public function create(?int $domainId): Grid
{
if ($domainId === 0) {
if ($domainId === null) {
$locale = $this->domain->getLocale();
$queryBuilder = $this->blogArticleRepository->getAllBlogArticlesByLocaleQueryBuilder(
$locale,
Expand Down
27 changes: 0 additions & 27 deletions app/templates/Admin/Content/Blog/Article/domainTabs.html.twig

This file was deleted.

2 changes: 1 addition & 1 deletion app/templates/Admin/Content/Blog/Article/list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{% endblock %}

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

{{ gridView.render() }}
{% endblock %}
Loading

0 comments on commit a159284

Please sign in to comment.