diff --git a/assets/controllers/elements/tree_controller.js b/assets/controllers/elements/tree_controller.js index 6fbc3ed9..9c19c3be 100644 --- a/assets/controllers/elements/tree_controller.js +++ b/assets/controllers/elements/tree_controller.js @@ -66,7 +66,7 @@ export default class extends Controller { levels: 1, showTags: this._showTags, data: data, - showIcon: false, + showIcon: true, onNodeSelected: (event) => { const node = event.detail.node; if (node.href) { diff --git a/src/Helpers/Trees/TreeViewNode.php b/src/Helpers/Trees/TreeViewNode.php index 4366b733..d174c8eb 100644 --- a/src/Helpers/Trees/TreeViewNode.php +++ b/src/Helpers/Trees/TreeViewNode.php @@ -60,6 +60,8 @@ final class TreeViewNode implements JsonSerializable private $id; + private $icon; + /** * Creates a new TreeView node with the given parameters. * @@ -233,6 +235,24 @@ final class TreeViewNode implements JsonSerializable return $this; } + /** + * @return string|null + */ + public function getIcon(): ?string + { + return $this->icon; + } + + /** + * @param string|null $icon + */ + public function setIcon(?string $icon): void + { + $this->icon = $icon; + } + + + public function jsonSerialize(): array { $ret = [ @@ -259,6 +279,10 @@ final class TreeViewNode implements JsonSerializable $ret['selectable'] = false; } + if ($this->icon != null) { + $ret['icon'] = $this->icon; + } + return $ret; } } diff --git a/src/Services/Trees/TreeViewGenerator.php b/src/Services/Trees/TreeViewGenerator.php index 193b0f14..94665e8e 100644 --- a/src/Services/Trees/TreeViewGenerator.php +++ b/src/Services/Trees/TreeViewGenerator.php @@ -156,6 +156,8 @@ class TreeViewGenerator if (($mode === 'list_parts_root' || $mode === 'devices') && $this->rootNodeEnabled) { $root_node = new TreeViewNode($this->entityClassToRootNodeString($class), null, $generic); $root_node->setExpanded($this->rootNodeExpandedByDefault); + $root_node->setIcon($this->entityClassToRootNodeIcon($class)); + $generic = [$root_node]; } @@ -182,6 +184,27 @@ class TreeViewGenerator } } + protected function entityClassToRootNodeIcon(string $class): ?string + { + $icon = "fa-fw fa-treeview fa-solid "; + switch ($class) { + case Category::class: + return $icon . 'fa-tags'; + case Storelocation::class: + return $icon . 'fa-cube'; + case Footprint::class: + return $icon . 'fa-microchip'; + case Manufacturer::class: + return $icon . 'fa-industry'; + case Supplier::class: + return $icon . 'fa-truck'; + case Device::class: + return $icon . 'fa-archive'; + default: + return null; + } + } + /** * /** * Gets a tree of TreeViewNode elements. The root elements has $parent as parent. diff --git a/yarn.lock b/yarn.lock index ac239b39..5f44458a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1345,9 +1345,9 @@ integrity sha512-Q8kGjqwPqER+CtpQudbH+3Zgs2X4zb6pBAlr6NsKTXadg45pAOvxI9i4QpuHbwSzR2+x87HUm+rot9F/Pe8rxA== "@jbtronics/bs-treeview@^1.0.1": - version "1.0.3" - resolved "https://registry.yarnpkg.com/@jbtronics/bs-treeview/-/bs-treeview-1.0.3.tgz#19a176fc84fbee5c7cc86c190ee351f480bdaf3d" - integrity sha512-9KU5bnrZr5saEfkTvUY5/sg1AS1tf5OvDiQmjHSnfygtVW77FI91jyuMOmn/7gGwPypPYI354wlMVvlgf9HroA== + version "1.0.4" + resolved "https://registry.yarnpkg.com/@jbtronics/bs-treeview/-/bs-treeview-1.0.4.tgz#aecd128c295ebd1af904d9a77f17dbf77a772b8f" + integrity sha512-ofhMY+4w0xYHcMPyw53EzWABzrzX2ecm50hhD9Kbb6h1/XsmLzVvHLIG9FYJ3eaIR0nTYF9a5L7mS14Qr/JChQ== "@jridgewell/gen-mapping@^0.1.0": version "0.1.1"