mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-24 21:05:03 +02:00
Added working treeviews and buttons.
This commit is contained in:
parent
82761a3454
commit
afd45d464c
17 changed files with 547 additions and 74 deletions
|
@ -30,9 +30,16 @@
|
|||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Category;
|
||||
use App\Entity\Device;
|
||||
use App\Entity\Footprint;
|
||||
use App\Entity\Manufacturer;
|
||||
use App\Entity\Storelocation;
|
||||
use App\Entity\Supplier;
|
||||
use App\Helpers\TreeViewNode;
|
||||
use App\Services\ToolsTreeBuilder;
|
||||
use App\Services\TreeBuilder;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Form\Extension\Core\Type\LocaleType;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
/**
|
||||
|
@ -55,10 +62,11 @@ class TreeController extends AbstractController
|
|||
|
||||
/**
|
||||
* @Route("/tree/category/{id}", name="tree_category")
|
||||
* @Route("/tree/categories")
|
||||
*/
|
||||
public function categoryTree(TreeBuilder $builder, Category $category = null)
|
||||
{
|
||||
if($category != null) {
|
||||
if ($category != null) {
|
||||
$tree[] = $builder->elementToTreeNode($category);
|
||||
} else {
|
||||
$tree = $builder->typeToTree(Category::class);
|
||||
|
@ -68,7 +76,85 @@ class TreeController extends AbstractController
|
|||
return $this->json($tree, 200, [], ['skip_null_values' => true]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/tree/footprint/{id}", name="tree_footprint")
|
||||
* @Route("/tree/footprints")
|
||||
*/
|
||||
public function footprintTree(TreeBuilder $builder, Footprint $footprint = null)
|
||||
{
|
||||
if ($footprint != null) {
|
||||
$tree[] = $builder->elementToTreeNode($footprint);
|
||||
} else {
|
||||
$tree = $builder->typeToTree(Footprint::class, null);
|
||||
}
|
||||
|
||||
|
||||
return $this->json($tree, 200, [], ['skip_null_values' => true]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/tree/location/{id}", name="tree_location")
|
||||
* @Route("/tree/locations")
|
||||
*/
|
||||
public function locationTree(TreeBuilder $builder, Storelocation $location = null)
|
||||
{
|
||||
if ($location != null) {
|
||||
$tree[] = $builder->elementToTreeNode($location);
|
||||
} else {
|
||||
$tree = $builder->typeToTree(Storelocation::class, null);
|
||||
}
|
||||
|
||||
|
||||
return $this->json($tree, 200, [], ['skip_null_values' => true]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/tree/manufacturer/{id}", name="tree_manufacturer")
|
||||
* @Route("/tree/manufacturers")
|
||||
*/
|
||||
public function manufacturerTree(TreeBuilder $builder, Manufacturer $manufacturer = null)
|
||||
{
|
||||
if ($manufacturer != null) {
|
||||
$tree[] = $builder->elementToTreeNode($manufacturer);
|
||||
} else {
|
||||
$tree = $builder->typeToTree(Manufacturer::class, null);
|
||||
}
|
||||
|
||||
|
||||
return $this->json($tree, 200, [], ['skip_null_values' => true]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/tree/supplier/{id}", name="tree_supplier")
|
||||
* @Route("/tree/suppliers")
|
||||
*/
|
||||
public function supplierTree(TreeBuilder $builder, Supplier $supplier = null)
|
||||
{
|
||||
if ($supplier != null) {
|
||||
$tree[] = $builder->elementToTreeNode($supplier);
|
||||
} else {
|
||||
$tree = $builder->typeToTree(Supplier::class, null);
|
||||
}
|
||||
|
||||
|
||||
return $this->json($tree, 200, [], ['skip_null_values' => true]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/tree/device/{id}", name="tree_device")
|
||||
* @Route("/tree/devices")
|
||||
*/
|
||||
public function deviceTree(TreeBuilder $builder, Device $device = null)
|
||||
{
|
||||
if ($device != null) {
|
||||
$tree[] = $builder->elementToTreeNode($device);
|
||||
} else {
|
||||
$tree = $builder->typeToTree(Device::class, null);
|
||||
}
|
||||
|
||||
|
||||
return $this->json($tree, 200, [], ['skip_null_values' => true]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ use Doctrine\ORM\Mapping as ORM;
|
|||
/**
|
||||
* Class AttachmentType.
|
||||
*
|
||||
* @ORM\Entity()
|
||||
* @ORM\Entity(repositoryClass="App\Repository\StructuralDBElementRepository")
|
||||
* @ORM\Table(name="attachement_types")
|
||||
*/
|
||||
class AttachmentType extends StructuralDBElement
|
||||
|
|
|
@ -28,7 +28,7 @@ use Doctrine\ORM\Mapping as ORM;
|
|||
/**
|
||||
* Class AttachmentType.
|
||||
*
|
||||
* @ORM\Entity
|
||||
* @ORM\Entity(repositoryClass="App\Repository\StructuralDBElementRepository")
|
||||
* @ORM\Table(name="categories")
|
||||
*/
|
||||
class Category extends PartsContainingDBElement
|
||||
|
|
|
@ -37,7 +37,7 @@ use Doctrine\ORM\Mapping as ORM;
|
|||
/**
|
||||
* Class AttachmentType.
|
||||
*
|
||||
* @ORM\Entity()
|
||||
* @ORM\Entity(repositoryClass="App\Repository\StructuralDBElementRepository")
|
||||
* @ORM\Table(name="devices")
|
||||
*/
|
||||
class Device extends PartsContainingDBElement
|
||||
|
|
|
@ -37,7 +37,7 @@ use Doctrine\ORM\Mapping as ORM;
|
|||
/**
|
||||
* Class Footprint.
|
||||
*
|
||||
* @ORM\Entity()
|
||||
* @ORM\Entity(repositoryClass="App\Repository\StructuralDBElementRepository")
|
||||
* @ORM\Table("footprints")
|
||||
*/
|
||||
class Footprint extends PartsContainingDBElement
|
||||
|
|
|
@ -37,7 +37,7 @@ use Doctrine\ORM\Mapping as ORM;
|
|||
/**
|
||||
* Class Manufacturer.
|
||||
*
|
||||
* @ORM\Entity()
|
||||
* @ORM\Entity(repositoryClass="App\Repository\StructuralDBElementRepository")
|
||||
* @ORM\Table("manufacturers")
|
||||
*/
|
||||
class Manufacturer extends Company
|
||||
|
|
|
@ -37,7 +37,7 @@ use Doctrine\ORM\Mapping as ORM;
|
|||
/**
|
||||
* Class Storelocation.
|
||||
*
|
||||
* @ORM\Entity()
|
||||
* @ORM\Entity(repositoryClass="App\Repository\StructuralDBElementRepository")
|
||||
* @ORM\Table("storelocations")
|
||||
*/
|
||||
class Storelocation extends PartsContainingDBElement
|
||||
|
|
|
@ -36,8 +36,7 @@ use Doctrine\ORM\PersistentCollection;
|
|||
* It's allowed to have instances of root elements, but if you try to change
|
||||
* an attribute of a root element, you will get an exception!
|
||||
*
|
||||
* @ORM\MappedSuperclass()
|
||||
* //@ORM\Entity(repositoryClass="App\Repository\StructuralDBElementRepository")
|
||||
* @ORM\MappedSuperclass(repositoryClass="App\Repository\StructuralDBElementRepository")
|
||||
*/
|
||||
abstract class StructuralDBElement extends AttachmentContainingDBElement
|
||||
{
|
||||
|
@ -310,50 +309,6 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
|
|||
return implode("\n", $html);
|
||||
}
|
||||
|
||||
public function buildBootstrapTree(
|
||||
$page,
|
||||
$parameter,
|
||||
$recursive = false,
|
||||
$show_root = false,
|
||||
$use_db_root_name = true,
|
||||
$root_name = '$$'
|
||||
): array {
|
||||
if ('$$' == $root_name) {
|
||||
$root_name = _('Oberste Ebene');
|
||||
}
|
||||
|
||||
$subelements = $this->getSubelements(false);
|
||||
$nodes = array();
|
||||
|
||||
foreach ($subelements as $element) {
|
||||
$nodes[] = $element->buildBootstrapTree($page, $parameter);
|
||||
}
|
||||
|
||||
// if we are on root level?
|
||||
if (-1 == $this->getParentID()) {
|
||||
if ($show_root) {
|
||||
$tree = array(
|
||||
array('text' => $use_db_root_name ? htmlspecialchars($this->getName()) : $root_name,
|
||||
'href' => $page.'?'.$parameter.'='.$this->getID(),
|
||||
'nodes' => $nodes, ),
|
||||
);
|
||||
} else { //Dont show root node
|
||||
$tree = $nodes;
|
||||
}
|
||||
} elseif (!empty($nodes)) {
|
||||
$tree = array('text' => htmlspecialchars($this->getName()),
|
||||
'href' => $page.'?'.$parameter.'='.$this->getID(),
|
||||
'nodes' => $nodes,
|
||||
);
|
||||
} else {
|
||||
$tree = array('text' => htmlspecialchars($this->getName()),
|
||||
'href' => $page.'?'.$parameter.'='.$this->getID(),
|
||||
);
|
||||
}
|
||||
|
||||
return $tree;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a template loop for a Breadcrumb bar, representing the structural DB element.
|
||||
*
|
||||
|
|
|
@ -37,7 +37,7 @@ use Doctrine\ORM\Mapping as ORM;
|
|||
/**
|
||||
* Class Supplier.
|
||||
*
|
||||
* @ORM\Entity()
|
||||
* @ORM\Entity(repositoryClass="App\Repository\StructuralDBElementRepository")
|
||||
* @ORM\Table("suppliers")
|
||||
*/
|
||||
class Supplier extends Company
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* part-db version 0.1
|
||||
* Copyright (C) 2005 Christoph Lechner
|
||||
* http://www.cl-projects.de/.
|
||||
* http://www.cl-projects.de/
|
||||
*
|
||||
* part-db version 0.2+
|
||||
* Copyright (C) 2009 K. Jacobs and others (see authors.php)
|
||||
|
@ -25,15 +26,14 @@
|
|||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
namespace App\Controller;
|
||||
namespace App\Services;
|
||||
|
||||
use App\Entity\StructuralDBElement;
|
||||
use App\Helpers\TreeViewNode;
|
||||
use App\Repository\StructuralDBElementRepository;
|
||||
use App\Services\EntityURLGenerator;
|
||||
use App\Services\ToolsTreeBuilder;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
/**
|
||||
|
@ -59,13 +59,13 @@ class TreeBuilder
|
|||
* See EntityURLGenerator::getURL for possible types.
|
||||
* @return TreeViewNode The Node for the given Element.
|
||||
*/
|
||||
public function elementToTreeNode(StructuralDBElement $element, string $href_type = 'list_parts') : TreeViewNode
|
||||
public function elementToTreeNode(StructuralDBElement $element, ?string $href_type = 'list_parts') : TreeViewNode
|
||||
{
|
||||
$children = $element->getSubelements();
|
||||
|
||||
$children_nodes = null;
|
||||
foreach ($children as $child) {
|
||||
$children_nodes[] = $this->elementToTreeNode($child);
|
||||
$children_nodes[] = $this->elementToTreeNode($child, $href_type);
|
||||
}
|
||||
|
||||
//Check if we need to generate a href type
|
||||
|
@ -86,7 +86,7 @@ class TreeBuilder
|
|||
* See EntityURLGenerator::getURL for possible types.
|
||||
* @return TreeViewNode[] Returns an array, containing all nodes. It is empty if the given class has no elements.
|
||||
*/
|
||||
public function typeToTree(StructuralDBElement $class_name, string $href_type = 'list_parts') : array
|
||||
public function typeToTree(string $class_name, ?string $href_type = 'list_parts') : array
|
||||
{
|
||||
/**
|
||||
* @var $repo StructuralDBElementRepository
|
||||
|
@ -96,7 +96,7 @@ class TreeBuilder
|
|||
|
||||
$array = array();
|
||||
foreach ($root_nodes as $node) {
|
||||
$array = $this->elementToTreeNode($node, $href_type);
|
||||
$array[] = $this->elementToTreeNode($node, $href_type);
|
||||
}
|
||||
|
||||
return $array;
|
Loading…
Add table
Add a link
Reference in a new issue