mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-23 02:09:03 +02:00
Put sidebar trees under a root node.
This commit is contained in:
parent
e05d707918
commit
c6970505c7
5 changed files with 44 additions and 10 deletions
|
@ -47,6 +47,7 @@ use App\Entity\Base\AbstractNamedDBElement;
|
|||
use App\Entity\Base\AbstractStructuralDBElement;
|
||||
use App\Helpers\Trees\TreeViewNode;
|
||||
use App\Helpers\Trees\TreeViewNodeIterator;
|
||||
use App\Helpers\Trees\TreeViewNodeState;
|
||||
use App\Repository\StructuralDBElementRepository;
|
||||
use App\Services\EntityURLGenerator;
|
||||
use App\Services\UserCacheKeyGenerator;
|
||||
|
@ -84,12 +85,14 @@ class TreeViewGenerator
|
|||
*
|
||||
* @return TreeViewNode[] an array of TreeViewNode[] elements of the root elements
|
||||
*/
|
||||
public function getTreeView(string $class, ?AbstractStructuralDBElement $parent = null, string $href_type = 'list_parts', ?AbstractDBElement $selectedElement = null): array
|
||||
public function getTreeView(string $class, ?AbstractStructuralDBElement $parent = null, string $mode = 'list_parts', ?AbstractDBElement $selectedElement = null): array
|
||||
{
|
||||
$head = [];
|
||||
|
||||
$href_type = $mode;
|
||||
|
||||
//When we use the newEdit type, add the New Element node.
|
||||
if ('newEdit' === $href_type) {
|
||||
if ('newEdit' === $mode) {
|
||||
//Generate the url for the new node
|
||||
$href = $this->urlGenerator->createURL(new $class());
|
||||
$new_node = new TreeViewNode($this->translator->trans('entity.tree.new'), $href);
|
||||
|
@ -105,6 +108,10 @@ class TreeViewGenerator
|
|||
$href_type = 'edit';
|
||||
}
|
||||
|
||||
if ($mode === 'list_parts_root') {
|
||||
$href_type = 'list_parts';
|
||||
}
|
||||
|
||||
$generic = $this->getGenericTree($class, $parent);
|
||||
$treeIterator = new TreeViewNodeIterator($generic);
|
||||
$recursiveIterator = new \RecursiveIteratorIterator($treeIterator, \RecursiveIteratorIterator::SELF_FIRST);
|
||||
|
@ -129,6 +136,12 @@ class TreeViewGenerator
|
|||
}
|
||||
}
|
||||
|
||||
if ($mode === 'list_parts_root') {
|
||||
$root_node = new TreeViewNode($this->translator->trans('tree.root_node.text'), null, $generic);
|
||||
$root_node->setExpanded(true);
|
||||
$generic = [$root_node];
|
||||
}
|
||||
|
||||
return array_merge($head, $generic);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue