mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-25 03:08:51 +02:00
Group label profiles by their supported element on admin page.
This commit is contained in:
parent
f16dec51b6
commit
747962884a
3 changed files with 81 additions and 2 deletions
|
@ -28,7 +28,7 @@ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
||||||
use Symfony\Component\Validator\Constraints as Assert;
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Entity(repositoryClass="App\Repository\NamedDBElementRepository")
|
* @ORM\Entity(repositoryClass="App\Repository\LabelProfileRepository")
|
||||||
* @ORM\Table(name="label_profiles")
|
* @ORM\Table(name="label_profiles")
|
||||||
* @ORM\EntityListeners({"App\EntityListeners\TreeCacheInvalidationListener"})
|
* @ORM\EntityListeners({"App\EntityListeners\TreeCacheInvalidationListener"})
|
||||||
* @UniqueEntity({"name", "options.supported_element"})
|
* @UniqueEntity({"name", "options.supported_element"})
|
||||||
|
|
74
src/Repository/LabelProfileRepository.php
Normal file
74
src/Repository/LabelProfileRepository.php
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||||
|
*
|
||||||
|
* Copyright (C) 2019 - 2020 Jan Böhmer (https://github.com/jbtronics)
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Repository;
|
||||||
|
|
||||||
|
use App\Entity\LabelSystem\LabelOptions;
|
||||||
|
use App\Entity\LabelSystem\LabelProfile;
|
||||||
|
use App\Helpers\Trees\TreeViewNode;
|
||||||
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||||
|
|
||||||
|
class LabelProfileRepository extends NamedDBElementRepository
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Gets a tree of TreeViewNode elements. The root elements has $parent as parent.
|
||||||
|
* The treeview is generic, that means the href are null and ID values are set.
|
||||||
|
*
|
||||||
|
* @return TreeViewNode[]
|
||||||
|
*/
|
||||||
|
public function getGenericNodeTree(): array
|
||||||
|
{
|
||||||
|
$result = [];
|
||||||
|
|
||||||
|
foreach (LabelOptions::SUPPORTED_ELEMENTS as $type) {
|
||||||
|
$type_children = [];
|
||||||
|
$entities = $this->findForSupportedElement($type);
|
||||||
|
foreach ($entities as $entity) {
|
||||||
|
/** @var LabelProfile $entity */
|
||||||
|
$node = new TreeViewNode($entity->getName(), null, null);
|
||||||
|
$node->setId($entity->getID());
|
||||||
|
$type_children[] = $node;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($type_children)) {
|
||||||
|
//Use default label e.g. 'part_label'. $$ marks that it will be translated in TreeViewGenerator
|
||||||
|
$tmp = new TreeViewNode('$$' . $type . '.label', null, $type_children);
|
||||||
|
|
||||||
|
$result[] = $tmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find all LabelProfiles that can be used with the given type
|
||||||
|
* @param string $type See LabelOptions::SUPPORTED_ELEMENTS for valid values.
|
||||||
|
* @param array $order_by The way the results should be sorted. By default ordered by
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function findForSupportedElement(string $type, array $order_by = ['name' => 'ASC']): array
|
||||||
|
{
|
||||||
|
if (!in_array($type, LabelOptions::SUPPORTED_ELEMENTS)) {
|
||||||
|
throw new \InvalidArgumentException('Invalid supported_element type given.');
|
||||||
|
}
|
||||||
|
return $this->findBy(['options.supported_element' => $type], $order_by);
|
||||||
|
}
|
||||||
|
}
|
|
@ -118,10 +118,15 @@ class TreeViewGenerator
|
||||||
$item->addTag((string) \count($item->getNodes()));
|
$item->addTag((string) \count($item->getNodes()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! empty($href_type)) {
|
if (! empty($href_type) && $item->getId() !== null) {
|
||||||
$entity = $this->em->getPartialReference($class, $item->getId());
|
$entity = $this->em->getPartialReference($class, $item->getId());
|
||||||
$item->setHref($this->urlGenerator->getURL($entity, $href_type));
|
$item->setHref($this->urlGenerator->getURL($entity, $href_type));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Translate text if text starts with $$
|
||||||
|
if (substr($item->getText(), 0, 2) === '$$') {
|
||||||
|
$item->setText($this->translator->trans(substr($item->getText(), 2)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return array_merge($head, $generic);
|
return array_merge($head, $generic);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue