Skip to content

Commit 1c8ca6c

Browse files
committed
Added an settings option to change the default behavior of including child categories or not
Fixes issue #1077
1 parent 5dbe4ba commit 1c8ca6c

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed

src/Controller/PartListsController.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
use App\Form\Filters\PartFilterType;
3737
use App\Services\Parts\PartsTableActionHandler;
3838
use App\Services\Trees\NodesListBuilder;
39+
use App\Settings\BehaviorSettings\SidebarSettings;
3940
use App\Settings\BehaviorSettings\TableSettings;
4041
use Doctrine\DBAL\Exception\DriverException;
4142
use Doctrine\ORM\EntityManagerInterface;
@@ -56,11 +57,21 @@ public function __construct(private readonly EntityManagerInterface $entityManag
5657
private readonly NodesListBuilder $nodesListBuilder,
5758
private readonly DataTableFactory $dataTableFactory,
5859
private readonly TranslatorInterface $translator,
59-
private readonly TableSettings $tableSettings
60+
private readonly TableSettings $tableSettings,
61+
private readonly SidebarSettings $sidebarSettings,
6062
)
6163
{
6264
}
6365

66+
/**
67+
* Gets the filter operator to use by default (INCLUDING_CHILDREN or =)
68+
* @return string
69+
*/
70+
private function getFilterOperator(): string
71+
{
72+
return $this->sidebarSettings->dataStructureNodesTableIncludeChildren ? 'INCLUDING_CHILDREN' : '=';
73+
}
74+
6475
#[Route(path: '/table/action', name: 'table_action', methods: ['POST'])]
6576
public function tableAction(Request $request, PartsTableActionHandler $actionHandler): Response
6677
{
@@ -203,7 +214,7 @@ public function showCategory(Category $category, Request $request): Response
203214
return $this->showListWithFilter($request,
204215
'parts/lists/category_list.html.twig',
205216
function (PartFilter $filter) use ($category) {
206-
$filter->category->setOperator('INCLUDING_CHILDREN')->setValue($category);
217+
$filter->category->setOperator($this->getFilterOperator())->setValue($category);
207218
}, function (FormInterface $filterForm) {
208219
$this->disableFormFieldAfterCreation($filterForm->get('category')->get('value'));
209220
}, [
@@ -221,7 +232,7 @@ public function showFootprint(Footprint $footprint, Request $request): Response
221232
return $this->showListWithFilter($request,
222233
'parts/lists/footprint_list.html.twig',
223234
function (PartFilter $filter) use ($footprint) {
224-
$filter->footprint->setOperator('INCLUDING_CHILDREN')->setValue($footprint);
235+
$filter->footprint->setOperator($this->getFilterOperator())->setValue($footprint);
225236
}, function (FormInterface $filterForm) {
226237
$this->disableFormFieldAfterCreation($filterForm->get('footprint')->get('value'));
227238
}, [
@@ -239,7 +250,7 @@ public function showManufacturer(Manufacturer $manufacturer, Request $request):
239250
return $this->showListWithFilter($request,
240251
'parts/lists/manufacturer_list.html.twig',
241252
function (PartFilter $filter) use ($manufacturer) {
242-
$filter->manufacturer->setOperator('INCLUDING_CHILDREN')->setValue($manufacturer);
253+
$filter->manufacturer->setOperator($this->getFilterOperator())->setValue($manufacturer);
243254
}, function (FormInterface $filterForm) {
244255
$this->disableFormFieldAfterCreation($filterForm->get('manufacturer')->get('value'));
245256
}, [
@@ -257,7 +268,7 @@ public function showStorelocation(StorageLocation $storelocation, Request $reque
257268
return $this->showListWithFilter($request,
258269
'parts/lists/store_location_list.html.twig',
259270
function (PartFilter $filter) use ($storelocation) {
260-
$filter->storelocation->setOperator('INCLUDING_CHILDREN')->setValue($storelocation);
271+
$filter->storelocation->setOperator($this->getFilterOperator())->setValue($storelocation);
261272
}, function (FormInterface $filterForm) {
262273
$this->disableFormFieldAfterCreation($filterForm->get('storelocation')->get('value'));
263274
}, [
@@ -275,7 +286,7 @@ public function showSupplier(Supplier $supplier, Request $request): Response
275286
return $this->showListWithFilter($request,
276287
'parts/lists/supplier_list.html.twig',
277288
function (PartFilter $filter) use ($supplier) {
278-
$filter->supplier->setOperator('INCLUDING_CHILDREN')->setValue($supplier);
289+
$filter->supplier->setOperator($this->getFilterOperator())->setValue($supplier);
279290
}, function (FormInterface $filterForm) {
280291
$this->disableFormFieldAfterCreation($filterForm->get('supplier')->get('value'));
281292
}, [

src/Settings/BehaviorSettings/SidebarSettings.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,11 @@ class SidebarSettings
7373
*/
7474
#[SettingsParameter(label: new TM("settings.behavior.sidebar.rootNodeRedirectsToNewEntity"))]
7575
public bool $rootNodeRedirectsToNewEntity = false;
76-
}
76+
77+
/**
78+
* @var bool Whether to include child nodes in the data structure nodes table, or only show the selected node's parts.
79+
*/
80+
#[SettingsParameter(label: new TM("settings.behavior.sidebar.data_structure_nodes_table_include_children"),
81+
description: new TM("settings.behavior.sidebar.data_structure_nodes_table_include_children.help"))]
82+
public bool $dataStructureNodesTableIncludeChildren = true;
83+
}

translations/messages.en.xlf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14232,5 +14232,17 @@ Please note, that you can not impersonate a disabled user. If you try you will g
1423214232
<target>Project has no BOM entries</target>
1423314233
</segment>
1423414234
</unit>
14235+
<unit id="pCKgjIr" name="settings.behavior.sidebar.data_structure_nodes_table_include_children">
14236+
<segment>
14237+
<source>settings.behavior.sidebar.data_structure_nodes_table_include_children</source>
14238+
<target>Tables should include children nodes by default</target>
14239+
</segment>
14240+
</unit>
14241+
<unit id="KJQHfwV" name="settings.behavior.sidebar.data_structure_nodes_table_include_children.help">
14242+
<segment>
14243+
<source>settings.behavior.sidebar.data_structure_nodes_table_include_children.help</source>
14244+
<target>If checked, the part tables for categories, footprints, etc. should include all parts of child categories. If not checked, only parts that strictly belong to the clicked node are shown.</target>
14245+
</segment>
14246+
</unit>
1423514247
</file>
1423614248
</xliff>

0 commit comments

Comments
 (0)