2019-03-24 15:25:40 +01:00
|
|
|
<?php
|
2020-02-22 18:14:36 +01:00
|
|
|
/**
|
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
|
|
|
*
|
2022-11-29 22:28:53 +01:00
|
|
|
* Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics)
|
2020-02-22 18:14:36 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published
|
|
|
|
* by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2020-01-05 15:46:58 +01:00
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2019-03-24 15:25:40 +01:00
|
|
|
namespace App\Controller;
|
|
|
|
|
2022-12-18 20:34:25 +01:00
|
|
|
use App\Entity\ProjectSystem\Project;
|
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
|
|
|
|
{
|
2022-09-18 22:59:31 +02:00
|
|
|
protected TreeViewGenerator $treeGenerator;
|
2020-01-02 18:45:41 +01:00
|
|
|
|
|
|
|
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
|
|
|
*/
|
2020-02-02 14:05:36 +01:00
|
|
|
public function tools(ToolsTreeBuilder $builder): JsonResponse
|
2019-03-24 15:25:40 +01:00
|
|
|
{
|
|
|
|
$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")
|
2022-07-31 15:50:16 +02:00
|
|
|
* @Route("/categories", name="tree_category_root")
|
2019-03-24 15:25:40 +01:00
|
|
|
*/
|
2020-02-02 14:05:36 +01:00
|
|
|
public function categoryTree(?Category $category = null): JsonResponse
|
2019-03-24 15:25:40 +01:00
|
|
|
{
|
2022-10-31 22:47:45 +01:00
|
|
|
if ($this->isGranted('@parts.read') && $this->isGranted('@categories.read')) {
|
|
|
|
$tree = $this->treeGenerator->getTreeView(Category::class, $category, 'list_parts_root');
|
|
|
|
} else {
|
|
|
|
return new JsonResponse("Access denied", 403);
|
|
|
|
}
|
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")
|
2022-07-31 15:50:16 +02:00
|
|
|
* @Route("/footprints", name="tree_footprint_root")
|
2019-03-25 12:44:44 +01:00
|
|
|
*/
|
2020-02-02 14:05:36 +01:00
|
|
|
public function footprintTree(?Footprint $footprint = null): JsonResponse
|
2019-03-25 12:44:44 +01:00
|
|
|
{
|
2022-10-31 22:47:45 +01:00
|
|
|
if ($this->isGranted('@parts.read') && $this->isGranted('@footprints.read')) {
|
|
|
|
$tree = $this->treeGenerator->getTreeView(Footprint::class, $footprint, 'list_parts_root');
|
|
|
|
} else {
|
|
|
|
return new JsonResponse("Access denied", 403);
|
|
|
|
}
|
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")
|
2022-07-31 15:50:16 +02:00
|
|
|
* @Route("/locations", name="tree_location_root")
|
2019-03-25 12:44:44 +01:00
|
|
|
*/
|
2020-02-02 14:05:36 +01:00
|
|
|
public function locationTree(?Storelocation $location = null): JsonResponse
|
2019-03-25 12:44:44 +01:00
|
|
|
{
|
2022-10-31 22:47:45 +01:00
|
|
|
if ($this->isGranted('@parts.read') && $this->isGranted('@storelocations.read')) {
|
|
|
|
$tree = $this->treeGenerator->getTreeView(Storelocation::class, $location, 'list_parts_root');
|
|
|
|
} else {
|
|
|
|
return new JsonResponse("Access denied", 403);
|
|
|
|
}
|
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")
|
2022-07-31 15:50:16 +02:00
|
|
|
* @Route("/manufacturers", name="tree_manufacturer_root")
|
2019-03-25 12:44:44 +01:00
|
|
|
*/
|
2020-02-02 14:05:36 +01:00
|
|
|
public function manufacturerTree(?Manufacturer $manufacturer = null): JsonResponse
|
2019-03-25 12:44:44 +01:00
|
|
|
{
|
2022-10-31 22:47:45 +01:00
|
|
|
if ($this->isGranted('@parts.read') && $this->isGranted('@manufacturers.read')) {
|
|
|
|
$tree = $this->treeGenerator->getTreeView(Manufacturer::class, $manufacturer, 'list_parts_root');
|
|
|
|
} else {
|
|
|
|
return new JsonResponse("Access denied", 403);
|
|
|
|
}
|
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")
|
2022-07-31 15:50:16 +02:00
|
|
|
* @Route("/suppliers", name="tree_supplier_root")
|
2019-03-25 12:44:44 +01:00
|
|
|
*/
|
2020-02-02 14:05:36 +01:00
|
|
|
public function supplierTree(?Supplier $supplier = null): JsonResponse
|
2019-03-25 12:44:44 +01:00
|
|
|
{
|
2022-10-31 22:47:45 +01:00
|
|
|
if ($this->isGranted('@parts.read') && $this->isGranted('@suppliers.read')) {
|
|
|
|
$tree = $this->treeGenerator->getTreeView(Supplier::class, $supplier, 'list_parts_root');
|
2022-11-27 16:53:44 +01:00
|
|
|
} else {
|
|
|
|
return new JsonResponse("Access denied", 403);
|
2022-10-31 22:47:45 +01:00
|
|
|
}
|
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")
|
2022-07-31 15:50:16 +02:00
|
|
|
* @Route("/devices", name="tree_device_root")
|
2019-03-25 12:44:44 +01:00
|
|
|
*/
|
2022-12-18 20:34:25 +01:00
|
|
|
public function deviceTree(?Project $device = null): JsonResponse
|
2019-03-25 12:44:44 +01:00
|
|
|
{
|
2022-10-31 22:47:45 +01:00
|
|
|
if ($this->isGranted('@devices.read')) {
|
2022-12-18 20:34:25 +01:00
|
|
|
$tree = $this->treeGenerator->getTreeView(Project::class, $device, 'devices');
|
2022-10-31 22:47:45 +01:00
|
|
|
} else {
|
|
|
|
return new JsonResponse("Access denied", 403);
|
|
|
|
}
|
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
|
|
|
}
|