2019-03-24 15:25:40 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2019-11-09 00:47:20 +01:00
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
2019-03-24 15:25:40 +01:00
|
|
|
*
|
2019-11-01 13:40:30 +01:00
|
|
|
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
|
2019-03-24 15:25:40 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* 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;
|
|
|
|
|
2019-08-12 18:04:53 +02:00
|
|
|
use App\Entity\Devices\Device;
|
2019-08-12 15:47:57 +02:00
|
|
|
use App\Entity\Parts\Category;
|
|
|
|
use App\Entity\Parts\Footprint;
|
|
|
|
use App\Entity\Parts\Manufacturer;
|
|
|
|
use App\Entity\Parts\Storelocation;
|
|
|
|
use App\Entity\Parts\Supplier;
|
2020-01-02 22:55:28 +01:00
|
|
|
use App\Services\Trees\ToolsTreeBuilder;
|
2020-01-02 18:45:41 +01:00
|
|
|
use App\Services\Trees\TreeViewGenerator;
|
2019-03-24 15:25:40 +01:00
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
2020-01-02 23:21:37 +01:00
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
2019-03-24 15:25:40 +01:00
|
|
|
use Symfony\Component\Routing\Annotation\Route;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This controller has the purpose to provide the data for all treeviews.
|
2020-01-04 20:24:09 +01:00
|
|
|
*
|
2020-01-02 18:45:41 +01:00
|
|
|
* @Route("/tree")
|
2019-03-24 15:25:40 +01:00
|
|
|
*/
|
|
|
|
class TreeController extends AbstractController
|
|
|
|
{
|
2020-01-02 18:45:41 +01:00
|
|
|
protected $treeGenerator;
|
|
|
|
|
|
|
|
public function __construct(TreeViewGenerator $treeGenerator)
|
|
|
|
{
|
|
|
|
$this->treeGenerator = $treeGenerator;
|
|
|
|
}
|
|
|
|
|
2019-03-24 15:25:40 +01:00
|
|
|
/**
|
2020-01-02 18:45:41 +01:00
|
|
|
* @Route("/tools", name="tree_tools")
|
2019-03-24 15:25:40 +01:00
|
|
|
*/
|
|
|
|
public function tools(ToolsTreeBuilder $builder)
|
|
|
|
{
|
|
|
|
$tree = $builder->getTree();
|
2020-01-04 20:24:09 +01:00
|
|
|
|
2020-01-02 23:21:37 +01:00
|
|
|
return new JsonResponse($tree);
|
2019-03-24 15:25:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-01-02 18:45:41 +01:00
|
|
|
* @Route("/category/{id}", name="tree_category")
|
|
|
|
* @Route("/categories")
|
2019-03-24 15:25:40 +01:00
|
|
|
*/
|
2020-01-02 18:45:41 +01:00
|
|
|
public function categoryTree(Category $category = null)
|
2019-03-24 15:25:40 +01:00
|
|
|
{
|
2020-01-02 18:45:41 +01:00
|
|
|
$tree = $this->treeGenerator->getTreeView(Category::class, $category);
|
2020-01-04 20:24:09 +01:00
|
|
|
|
2020-01-02 23:21:37 +01:00
|
|
|
return new JsonResponse($tree);
|
2019-03-24 15:25:40 +01:00
|
|
|
}
|
|
|
|
|
2019-03-25 12:44:44 +01:00
|
|
|
/**
|
2020-01-02 18:45:41 +01:00
|
|
|
* @Route("/footprint/{id}", name="tree_footprint")
|
|
|
|
* @Route("/footprints")
|
2019-03-25 12:44:44 +01:00
|
|
|
*/
|
2020-01-02 18:45:41 +01:00
|
|
|
public function footprintTree(Footprint $footprint = null)
|
2019-03-25 12:44:44 +01:00
|
|
|
{
|
2020-01-02 18:45:41 +01:00
|
|
|
$tree = $this->treeGenerator->getTreeView(Footprint::class, $footprint);
|
2020-01-04 20:24:09 +01:00
|
|
|
|
2020-01-02 23:21:37 +01:00
|
|
|
return new JsonResponse($tree);
|
2019-03-25 12:44:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-01-02 18:45:41 +01:00
|
|
|
* @Route("/location/{id}", name="tree_location")
|
|
|
|
* @Route("/locations")
|
2019-03-25 12:44:44 +01:00
|
|
|
*/
|
2020-01-02 18:45:41 +01:00
|
|
|
public function locationTree(Storelocation $location = null)
|
2019-03-25 12:44:44 +01:00
|
|
|
{
|
2020-01-02 18:45:41 +01:00
|
|
|
$tree = $this->treeGenerator->getTreeView(Storelocation::class, $location);
|
2020-01-04 20:24:09 +01:00
|
|
|
|
2020-01-02 23:21:37 +01:00
|
|
|
return new JsonResponse($tree);
|
2019-03-25 12:44:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-01-02 18:45:41 +01:00
|
|
|
* @Route("/manufacturer/{id}", name="tree_manufacturer")
|
|
|
|
* @Route("/manufacturers")
|
2019-03-25 12:44:44 +01:00
|
|
|
*/
|
2020-01-02 18:45:41 +01:00
|
|
|
public function manufacturerTree(Manufacturer $manufacturer = null)
|
2019-03-25 12:44:44 +01:00
|
|
|
{
|
2020-01-02 18:45:41 +01:00
|
|
|
$tree = $this->treeGenerator->getTreeView(Manufacturer::class, $manufacturer);
|
2020-01-04 20:24:09 +01:00
|
|
|
|
2020-01-02 23:21:37 +01:00
|
|
|
return new JsonResponse($tree);
|
2019-03-25 12:44:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-01-02 18:45:41 +01:00
|
|
|
* @Route("/supplier/{id}", name="tree_supplier")
|
|
|
|
* @Route("/suppliers")
|
2019-03-25 12:44:44 +01:00
|
|
|
*/
|
2020-01-02 18:45:41 +01:00
|
|
|
public function supplierTree(Supplier $supplier = null)
|
2019-03-25 12:44:44 +01:00
|
|
|
{
|
2020-01-02 18:45:41 +01:00
|
|
|
$tree = $this->treeGenerator->getTreeView(Supplier::class, $supplier);
|
2020-01-04 20:24:09 +01:00
|
|
|
|
2020-01-02 23:21:37 +01:00
|
|
|
return new JsonResponse($tree);
|
2019-03-25 12:44:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-01-02 18:45:41 +01:00
|
|
|
* @Route("/device/{id}", name="tree_device")
|
|
|
|
* @Route("/devices")
|
2019-03-25 12:44:44 +01:00
|
|
|
*/
|
2020-01-02 18:45:41 +01:00
|
|
|
public function deviceTree(Device $device = null)
|
2019-03-25 12:44:44 +01:00
|
|
|
{
|
2020-01-02 18:45:41 +01:00
|
|
|
$tree = $this->treeGenerator->getTreeView(Device::class, $device, '');
|
2020-01-04 20:24:09 +01:00
|
|
|
|
2020-01-02 23:21:37 +01:00
|
|
|
return new JsonResponse($tree);
|
2019-03-25 12:44:44 +01:00
|
|
|
}
|
2019-03-24 15:25:40 +01:00
|
|
|
}
|