Show the count of the sub categories in the entity admin treeview.

This commit is contained in:
Jan Böhmer 2019-04-05 18:35:06 +02:00
parent 650b388a1d
commit d04a8626cb
5 changed files with 34 additions and 0 deletions

View file

@ -513,6 +513,11 @@ span.highlight {
padding-bottom: 3px;
}
.treeview .badge {
margin-left: auto;
line-height: 1.42857143;
}
/*****************************
* Pagination bar
*****************************/

View file

@ -140,6 +140,11 @@ $(document).on("ajaxUI:start ajaxUI:reload", function() {
enableLinks: false,
showIcon: false,
showBorder: true,
showTags: true,
//@ts-ignore
wrapNode: true,
//@ts-ignore
tagsClass: 'badge badge-secondary badge-pill pull-right',
expandIcon: "fas fa-plus fa-fw fa-treeview", collapseIcon: "fas fa-minus fa-fw fa-treeview",
onNodeSelected: function(event, data) {
if(data.href) {

View file

@ -42,6 +42,8 @@ class TreeViewNode
protected $state;
protected $tags;
/**
* Creates a new TreeView node with the given parameters.
* @param string $text The text that is shown in the node. (e.g. the name of the node)
@ -144,4 +146,21 @@ class TreeViewNode
return $this;
}
public function getTags() : ?array
{
return $this->tags;
}
public function addTag(string $new_tag) : self
{
//Lazy loading tags
if ($this->tags == null) {
$this->tags = array();
}
$this->tags[] = $new_tag;
return $this;
}
}

View file

@ -84,6 +84,10 @@ class TreeBuilder
$tree_node = new TreeViewNode($element->getName(), $href, $children_nodes);
if($children_nodes != null) {
$tree_node->addTag((string) count($children_nodes));
}
//Check if we need to select the current part
if ($selectedElement !== null && $element->getID() === $selectedElement->getID()) {
$tree_node->setSelected(true);

View file

@ -4,6 +4,7 @@
<div class="row">
<div class="col-4">
<div class="treeview-sm" id="tree" data-tree-data="{{ generateTreeData(entity) }}">
</div>