From 89c230322ad1a33cc0e14f925146d9373c412ce6 Mon Sep 17 00:00:00 2001 From: d-buchmann Date: Wed, 28 May 2025 16:02:11 +0200 Subject: [PATCH] PoC for predefined filters in the tools sidebar menu Custom filters would need some extra work if they are to be implemented. Fixes #938. --- src/Controller/PartListsController.php | 31 +++++++++++++++++++++++++ src/Services/Trees/ToolsTreeBuilder.php | 28 ++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/src/Controller/PartListsController.php b/src/Controller/PartListsController.php index 48995228f..893fa6f9e 100644 --- a/src/Controller/PartListsController.php +++ b/src/Controller/PartListsController.php @@ -341,4 +341,35 @@ public function showAll(Request $request): Response { return $this->showListWithFilter($request,'parts/lists/all_list.html.twig'); } + + #[Route(path: '/parts/filter/less_than_desired', name: 'parts_filter_less_than_desired')] + public function showLessThanDesiredFilter(Request $request): Response + { + return $this->showListWithFilter($request, + 'parts/lists/all_list.html.twig', + function (PartFilter $filter) { + $filter->lessThanDesired->setValue(true); + }, + function (FormInterface $filterForm) { + $this->disableFormFieldAfterCreation($filterForm->get('lessThanDesired')->get('value')); + } + ); + } + + #[Route(path: '/parts/filter/custom', name: 'parts_filter_custom')] + public function showCustomFilter(Request $request): Response + { + // TODO custom filters will need custom access permission checks! + return $this->showListWithFilter($request, + 'parts/lists/all_list.html.twig', + function (PartFilter $filter) { + ; + }, + function (FormInterface $filterForm) { + ; + } + ); + } + + } diff --git a/src/Services/Trees/ToolsTreeBuilder.php b/src/Services/Trees/ToolsTreeBuilder.php index 185713060..a2be134f8 100644 --- a/src/Services/Trees/ToolsTreeBuilder.php +++ b/src/Services/Trees/ToolsTreeBuilder.php @@ -90,10 +90,38 @@ public function getTree(): array }); } + protected function getFilterNode(): array + { + $nodes = []; + + if ($this->security->isGranted('@parts.read')) { + $nodes[] = (new TreeViewNode( + $this->translator->trans('filter.less_than_desired'), + $this->urlGenerator->generate('parts_filter_less_than_desired') + ))->setIcon("fa-treeview fa-fw fa-solid fa-circle-exclamation"); + } + + if ($this->security->isGranted('@parts.read')) { + $nodes[] = (new TreeViewNode( + $this->translator->trans('filter.custom'), + $this->urlGenerator->generate('parts_filter_custom') + ))->setIcon("fa-treeview fa-fw fa-solid fa-code"); + } + return $nodes; + } + protected function getToolsNode(): array { $nodes = []; + if ($this->security->isGranted('@parts.read')) { + $nodes[] = (new TreeViewNode( + $this->translator->trans('filter.title'), + null, + $this->getFilterNode() + ))->setIcon("fa-fw fa-treeview fa-solid fa-filter"); + } + if ($this->security->isGranted('@labels.create_labels')) { $nodes[] = (new TreeViewNode( $this->translator->trans('tree.tools.tools.label_dialog'),