mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-12-06 19:19:29 +00:00
Use ElementTypeNameGenerator where possible
This commit is contained in:
parent
e95197b069
commit
c372109a2f
5 changed files with 37 additions and 60 deletions
|
|
@ -75,17 +75,17 @@ final readonly class ElementTypeNameGenerator
|
||||||
|
|
||||||
if ($this->synonymsSettings->isSynonymDefinedForType($type)) {
|
if ($this->synonymsSettings->isSynonymDefinedForType($type)) {
|
||||||
if ($plural) {
|
if ($plural) {
|
||||||
$syn = $this->synonymsSettings->getSingularSynonymForType($type, $locale);
|
|
||||||
} else {
|
|
||||||
$syn = $this->synonymsSettings->getPluralSynonymForType($type, $locale);
|
$syn = $this->synonymsSettings->getPluralSynonymForType($type, $locale);
|
||||||
|
} else {
|
||||||
|
$syn = $this->synonymsSettings->getSingularSynonymForType($type, $locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($syn === null) {
|
if ($syn === null) {
|
||||||
//Try to fall back to english
|
//Try to fall back to english
|
||||||
if ($plural) {
|
if ($plural) {
|
||||||
$syn = $this->synonymsSettings->getSingularSynonymForType($type, 'en');
|
|
||||||
} else {
|
|
||||||
$syn = $this->synonymsSettings->getPluralSynonymForType($type, 'en');
|
$syn = $this->synonymsSettings->getPluralSynonymForType($type, 'en');
|
||||||
|
} else {
|
||||||
|
$syn = $this->synonymsSettings->getSingularSynonymForType($type, 'en');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ use App\Entity\UserSystem\Group;
|
||||||
use App\Entity\UserSystem\User;
|
use App\Entity\UserSystem\User;
|
||||||
use App\Helpers\Trees\TreeViewNode;
|
use App\Helpers\Trees\TreeViewNode;
|
||||||
use App\Services\Cache\UserCacheKeyGenerator;
|
use App\Services\Cache\UserCacheKeyGenerator;
|
||||||
use App\Services\Misc\DataSourceSynonymResolver;
|
use App\Services\ElementTypeNameGenerator;
|
||||||
use Symfony\Bundle\SecurityBundle\Security;
|
use Symfony\Bundle\SecurityBundle\Security;
|
||||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||||
use Symfony\Contracts\Cache\ItemInterface;
|
use Symfony\Contracts\Cache\ItemInterface;
|
||||||
|
|
@ -57,7 +57,7 @@ class ToolsTreeBuilder
|
||||||
protected TagAwareCacheInterface $cache,
|
protected TagAwareCacheInterface $cache,
|
||||||
protected UserCacheKeyGenerator $keyGenerator,
|
protected UserCacheKeyGenerator $keyGenerator,
|
||||||
protected Security $security,
|
protected Security $security,
|
||||||
protected readonly DataSourceSynonymResolver $synonymResolver,
|
private readonly ElementTypeNameGenerator $elementTypeNameGenerator,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -167,90 +167,67 @@ class ToolsTreeBuilder
|
||||||
|
|
||||||
if ($this->security->isGranted('read', new AttachmentType())) {
|
if ($this->security->isGranted('read', new AttachmentType())) {
|
||||||
$nodes[] = (new TreeViewNode(
|
$nodes[] = (new TreeViewNode(
|
||||||
$this->translator->trans('tree.tools.edit.attachment_types'),
|
$this->elementTypeNameGenerator->typeLabelPlural(AttachmentType::class),
|
||||||
$this->urlGenerator->generate('attachment_type_new')
|
$this->urlGenerator->generate('attachment_type_new')
|
||||||
))->setIcon('fa-fw fa-treeview fa-solid fa-file-alt');
|
))->setIcon('fa-fw fa-treeview fa-solid fa-file-alt');
|
||||||
}
|
}
|
||||||
if ($this->security->isGranted('read', new Category())) {
|
if ($this->security->isGranted('read', new Category())) {
|
||||||
$nodes[] = (new TreeViewNode(
|
$nodes[] = (new TreeViewNode(
|
||||||
$this->synonymResolver->displayNamePlural(
|
$this->elementTypeNameGenerator->typeLabelPlural(Category::class),
|
||||||
'category',
|
|
||||||
'tree.tools.edit.categories',
|
|
||||||
$this->translator->getLocale()
|
|
||||||
),
|
|
||||||
$this->urlGenerator->generate('category_new')
|
$this->urlGenerator->generate('category_new')
|
||||||
))->setIcon('fa-fw fa-treeview fa-solid fa-tags');
|
))->setIcon('fa-fw fa-treeview fa-solid fa-tags');
|
||||||
}
|
}
|
||||||
if ($this->security->isGranted('read', new Project())) {
|
if ($this->security->isGranted('read', new Project())) {
|
||||||
$nodes[] = (new TreeViewNode(
|
$nodes[] = (new TreeViewNode(
|
||||||
$this->synonymResolver->displayNamePlural(
|
$this->elementTypeNameGenerator->typeLabelPlural(Project::class),
|
||||||
'project',
|
|
||||||
'tree.tools.edit.projects',
|
|
||||||
$this->translator->getLocale()),
|
|
||||||
$this->urlGenerator->generate('project_new')
|
$this->urlGenerator->generate('project_new')
|
||||||
))->setIcon('fa-fw fa-treeview fa-solid fa-archive');
|
))->setIcon('fa-fw fa-treeview fa-solid fa-archive');
|
||||||
}
|
}
|
||||||
if ($this->security->isGranted('read', new Supplier())) {
|
if ($this->security->isGranted('read', new Supplier())) {
|
||||||
$nodes[] = (new TreeViewNode(
|
$nodes[] = (new TreeViewNode(
|
||||||
$this->synonymResolver->displayNamePlural(
|
$this->elementTypeNameGenerator->typeLabelPlural(Supplier::class),
|
||||||
'supplier',
|
|
||||||
'tree.tools.edit.suppliers',
|
|
||||||
$this->translator->getLocale()
|
|
||||||
),
|
|
||||||
$this->urlGenerator->generate('supplier_new')
|
$this->urlGenerator->generate('supplier_new')
|
||||||
))->setIcon('fa-fw fa-treeview fa-solid fa-truck');
|
))->setIcon('fa-fw fa-treeview fa-solid fa-truck');
|
||||||
}
|
}
|
||||||
if ($this->security->isGranted('read', new Manufacturer())) {
|
if ($this->security->isGranted('read', new Manufacturer())) {
|
||||||
$nodes[] = (new TreeViewNode(
|
$nodes[] = (new TreeViewNode(
|
||||||
$this->synonymResolver->displayNamePlural(
|
$this->elementTypeNameGenerator->typeLabelPlural(Manufacturer::class),
|
||||||
'manufacturer',
|
|
||||||
'tree.tools.edit.manufacturer',
|
|
||||||
$this->translator->getLocale()
|
|
||||||
),
|
|
||||||
$this->urlGenerator->generate('manufacturer_new')
|
$this->urlGenerator->generate('manufacturer_new')
|
||||||
))->setIcon('fa-fw fa-treeview fa-solid fa-industry');
|
))->setIcon('fa-fw fa-treeview fa-solid fa-industry');
|
||||||
}
|
}
|
||||||
if ($this->security->isGranted('read', new StorageLocation())) {
|
if ($this->security->isGranted('read', new StorageLocation())) {
|
||||||
$nodes[] = (new TreeViewNode(
|
$nodes[] = (new TreeViewNode(
|
||||||
$this->synonymResolver->displayNamePlural(
|
$this->elementTypeNameGenerator->typeLabelPlural(StorageLocation::class),
|
||||||
'storagelocation',
|
|
||||||
'tree.tools.edit.storelocation',
|
|
||||||
$this->translator->getLocale()
|
|
||||||
),
|
|
||||||
$this->urlGenerator->generate('store_location_new')
|
$this->urlGenerator->generate('store_location_new')
|
||||||
))->setIcon('fa-fw fa-treeview fa-solid fa-cube');
|
))->setIcon('fa-fw fa-treeview fa-solid fa-cube');
|
||||||
}
|
}
|
||||||
if ($this->security->isGranted('read', new Footprint())) {
|
if ($this->security->isGranted('read', new Footprint())) {
|
||||||
$nodes[] = (new TreeViewNode(
|
$nodes[] = (new TreeViewNode(
|
||||||
$this->synonymResolver->displayNamePlural(
|
$this->elementTypeNameGenerator->typeLabelPlural(Footprint::class),
|
||||||
'footprint',
|
|
||||||
'tree.tools.edit.footprint',
|
|
||||||
$this->translator->getLocale()
|
|
||||||
),
|
|
||||||
$this->urlGenerator->generate('footprint_new')
|
$this->urlGenerator->generate('footprint_new')
|
||||||
))->setIcon('fa-fw fa-treeview fa-solid fa-microchip');
|
))->setIcon('fa-fw fa-treeview fa-solid fa-microchip');
|
||||||
}
|
}
|
||||||
if ($this->security->isGranted('read', new Currency())) {
|
if ($this->security->isGranted('read', new Currency())) {
|
||||||
$nodes[] = (new TreeViewNode(
|
$nodes[] = (new TreeViewNode(
|
||||||
$this->translator->trans('tree.tools.edit.currency'),
|
$this->elementTypeNameGenerator->typeLabelPlural(Currency::class),
|
||||||
$this->urlGenerator->generate('currency_new')
|
$this->urlGenerator->generate('currency_new')
|
||||||
))->setIcon('fa-fw fa-treeview fa-solid fa-coins');
|
))->setIcon('fa-fw fa-treeview fa-solid fa-coins');
|
||||||
}
|
}
|
||||||
if ($this->security->isGranted('read', new MeasurementUnit())) {
|
if ($this->security->isGranted('read', new MeasurementUnit())) {
|
||||||
$nodes[] = (new TreeViewNode(
|
$nodes[] = (new TreeViewNode(
|
||||||
$this->translator->trans('tree.tools.edit.measurement_unit'),
|
$this->elementTypeNameGenerator->typeLabelPlural(MeasurementUnit::class),
|
||||||
$this->urlGenerator->generate('measurement_unit_new')
|
$this->urlGenerator->generate('measurement_unit_new')
|
||||||
))->setIcon('fa-fw fa-treeview fa-solid fa-balance-scale');
|
))->setIcon('fa-fw fa-treeview fa-solid fa-balance-scale');
|
||||||
}
|
}
|
||||||
if ($this->security->isGranted('read', new LabelProfile())) {
|
if ($this->security->isGranted('read', new LabelProfile())) {
|
||||||
$nodes[] = (new TreeViewNode(
|
$nodes[] = (new TreeViewNode(
|
||||||
$this->translator->trans('tree.tools.edit.label_profile'),
|
$this->elementTypeNameGenerator->typeLabelPlural(LabelProfile::class),
|
||||||
$this->urlGenerator->generate('label_profile_new')
|
$this->urlGenerator->generate('label_profile_new')
|
||||||
))->setIcon('fa-fw fa-treeview fa-solid fa-qrcode');
|
))->setIcon('fa-fw fa-treeview fa-solid fa-qrcode');
|
||||||
}
|
}
|
||||||
if ($this->security->isGranted('read', new PartCustomState())) {
|
if ($this->security->isGranted('read', new PartCustomState())) {
|
||||||
$nodes[] = (new TreeViewNode(
|
$nodes[] = (new TreeViewNode(
|
||||||
$this->translator->trans('tree.tools.edit.part_custom_state'),
|
$this->elementTypeNameGenerator->typeLabelPlural(PartCustomState::class),
|
||||||
$this->urlGenerator->generate('part_custom_state_new')
|
$this->urlGenerator->generate('part_custom_state_new')
|
||||||
))->setIcon('fa-fw fa-treeview fa-solid fa-tools');
|
))->setIcon('fa-fw fa-treeview fa-solid fa-tools');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ use App\Helpers\Trees\TreeViewNodeIterator;
|
||||||
use App\Repository\NamedDBElementRepository;
|
use App\Repository\NamedDBElementRepository;
|
||||||
use App\Services\Cache\ElementCacheTagGenerator;
|
use App\Services\Cache\ElementCacheTagGenerator;
|
||||||
use App\Services\Cache\UserCacheKeyGenerator;
|
use App\Services\Cache\UserCacheKeyGenerator;
|
||||||
|
use App\Services\ElementTypeNameGenerator;
|
||||||
use App\Services\EntityURLGenerator;
|
use App\Services\EntityURLGenerator;
|
||||||
use App\Services\Misc\DataSourceSynonymResolver;
|
use App\Services\Misc\DataSourceSynonymResolver;
|
||||||
use App\Settings\BehaviorSettings\SidebarSettings;
|
use App\Settings\BehaviorSettings\SidebarSettings;
|
||||||
|
|
@ -67,7 +68,8 @@ class TreeViewGenerator
|
||||||
protected TranslatorInterface $translator,
|
protected TranslatorInterface $translator,
|
||||||
private readonly UrlGeneratorInterface $router,
|
private readonly UrlGeneratorInterface $router,
|
||||||
private readonly SidebarSettings $sidebarSettings,
|
private readonly SidebarSettings $sidebarSettings,
|
||||||
protected readonly DataSourceSynonymResolver $synonymResolver
|
protected readonly DataSourceSynonymResolver $synonymResolver,
|
||||||
|
private readonly ElementTypeNameGenerator $elementTypeNameGenerator
|
||||||
) {
|
) {
|
||||||
$this->rootNodeEnabled = $this->sidebarSettings->rootNodeEnabled;
|
$this->rootNodeEnabled = $this->sidebarSettings->rootNodeEnabled;
|
||||||
$this->rootNodeExpandedByDefault = $this->sidebarSettings->rootNodeExpanded;
|
$this->rootNodeExpandedByDefault = $this->sidebarSettings->rootNodeExpanded;
|
||||||
|
|
@ -213,17 +215,7 @@ class TreeViewGenerator
|
||||||
|
|
||||||
protected function entityClassToRootNodeString(string $class): string
|
protected function entityClassToRootNodeString(string $class): string
|
||||||
{
|
{
|
||||||
$locale = $this->translator->getLocale();
|
return $this->elementTypeNameGenerator->typeLabelPlural($class);
|
||||||
|
|
||||||
return match ($class) {
|
|
||||||
Category::class => $this->synonymResolver->displayNamePlural('category', $locale),
|
|
||||||
StorageLocation::class => $this->synonymResolver->displayNamePlural('storelocation', $locale),
|
|
||||||
Footprint::class => $this->synonymResolver->displayNamePlural('footprint', $locale),
|
|
||||||
Manufacturer::class => $this->synonymResolver->displayNamePlural('manufacturer', $locale),
|
|
||||||
Supplier::class => $this->synonymResolver->displayNamePlural('supplier', $locale),
|
|
||||||
Project::class => $this->synonymResolver->displayNamePlural('project', $locale),
|
|
||||||
default => $this->translator->trans('tree.root_node.text'),
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function entityClassToRootNodeIcon(string $class): ?string
|
protected function entityClassToRootNodeIcon(string $class): ?string
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,8 @@ final class EntityExtension extends AbstractExtension
|
||||||
|
|
||||||
/* Gets a human readable label for the type of the given entity */
|
/* Gets a human readable label for the type of the given entity */
|
||||||
new TwigFunction('entity_type_label', fn(object|string $entity): string => $this->nameGenerator->getLocalizedTypeLabel($entity)),
|
new TwigFunction('entity_type_label', fn(object|string $entity): string => $this->nameGenerator->getLocalizedTypeLabel($entity)),
|
||||||
|
new TwigFunction('type_label', fn(object|string $entity): string => $this->nameGenerator->typeLabel($entity)),
|
||||||
|
new TwigFunction('type_label_p', fn(object|string $entity): string => $this->nameGenerator->typeLabelPlural($entity)),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,12 @@
|
||||||
|
|
||||||
{# Format is [mode, route, label, show_condition] #}
|
{# Format is [mode, route, label, show_condition] #}
|
||||||
{% set data_sources = [
|
{% set data_sources = [
|
||||||
['categories', path('tree_category_root'), 'category.labelp', is_granted('@categories.read') and is_granted('@parts.read'), 'category'],
|
['categories', path('tree_category_root'), '@category@@', is_granted('@categories.read') and is_granted('@parts.read')],
|
||||||
['locations', path('tree_location_root'), 'storelocation.labelp', is_granted('@storelocations.read') and is_granted('@parts.read'), 'storagelocation'],
|
['locations', path('tree_location_root'), '@storage_location@@', is_granted('@storelocations.read') and is_granted('@parts.read'), ],
|
||||||
['footprints', path('tree_footprint_root'), 'footprint.labelp', is_granted('@footprints.read') and is_granted('@parts.read'), 'footprint'],
|
['footprints', path('tree_footprint_root'), '@footprint@@', is_granted('@footprints.read') and is_granted('@parts.read')],
|
||||||
['manufacturers', path('tree_manufacturer_root'), 'manufacturer.labelp', is_granted('@manufacturers.read') and is_granted('@parts.read'), 'manufacturer'],
|
['manufacturers', path('tree_manufacturer_root'), '@manufacturer@@', is_granted('@manufacturers.read') and is_granted('@parts.read'), 'manufacturer'],
|
||||||
['suppliers', path('tree_supplier_root'), 'supplier.labelp', is_granted('@suppliers.read') and is_granted('@parts.read'), 'supplier'],
|
['suppliers', path('tree_supplier_root'), '@supplier@@', is_granted('@suppliers.read') and is_granted('@parts.read'), 'supplier'],
|
||||||
['projects', path('tree_device_root'), 'project.labelp', is_granted('@projects.read'), 'project'],
|
['projects', path('tree_device_root'), '@project@@', is_granted('@projects.read'), 'project'],
|
||||||
['tools', path('tree_tools'), 'tools.label', true, 'tool'],
|
['tools', path('tree_tools'), 'tools.label', true, 'tool'],
|
||||||
] %}
|
] %}
|
||||||
|
|
||||||
|
|
@ -21,12 +21,18 @@
|
||||||
{% for source in data_sources %}
|
{% for source in data_sources %}
|
||||||
{% if source[3] %} {# show_condition #}
|
{% if source[3] %} {# show_condition #}
|
||||||
<li>
|
<li>
|
||||||
|
{% if source[2] starts with '@' %}
|
||||||
|
{% set label = type_label_p(source[2]|replace({'@': ''})) %}
|
||||||
|
{% else %}
|
||||||
|
{% set label = source[2]|trans %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<button class="tree-btns dropdown-item"
|
<button class="tree-btns dropdown-item"
|
||||||
data-mode="{{ source[0] }}"
|
data-mode="{{ source[0] }}"
|
||||||
data-url="{{ source[1] }}"
|
data-url="{{ source[1] }}"
|
||||||
data-text="{{ get_data_source_name_plural(source[4], source[2]) }}"
|
data-text="{{ label }}"
|
||||||
{{ stimulus_action('elements/sidebar_tree', 'changeDataSource') }}
|
{{ stimulus_action('elements/sidebar_tree', 'changeDataSource') }}
|
||||||
>{{ get_data_source_name_plural(source[4], source[2]) }}</button>
|
>{{ label }}</button>
|
||||||
</li>
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue