mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-28 04:30:08 +02:00
Show type icon in the breadcrumb of part lists.
This commit is contained in:
parent
87913ba3b5
commit
44b288b807
3 changed files with 93 additions and 14 deletions
|
@ -42,9 +42,20 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Twig;
|
||||
|
||||
use App\Entity\Attachments\Attachment;
|
||||
use App\Entity\Base\AbstractDBElement;
|
||||
use App\Entity\Devices\Device;
|
||||
use App\Entity\LabelSystem\LabelProfile;
|
||||
use App\Entity\Parts\Category;
|
||||
use App\Entity\Parts\Footprint;
|
||||
use App\Entity\Parts\Manufacturer;
|
||||
use App\Entity\Parts\MeasurementUnit;
|
||||
use App\Entity\Parts\Part;
|
||||
use App\Entity\Parts\Storelocation;
|
||||
use App\Entity\Parts\Supplier;
|
||||
use App\Entity\PriceInformations\Currency;
|
||||
use App\Entity\UserSystem\Group;
|
||||
use App\Entity\UserSystem\User;
|
||||
use App\Services\AmountFormatter;
|
||||
use App\Services\Attachments\AttachmentURLGenerator;
|
||||
use App\Services\EntityURLGenerator;
|
||||
|
@ -116,6 +127,12 @@ class AppExtension extends AbstractExtension
|
|||
new TwigTest('instanceof', static function ($var, $instance) {
|
||||
return $var instanceof $instance;
|
||||
}),
|
||||
new TwigTest('entity', static function ($var) {
|
||||
return $var instanceof AbstractDBElement;
|
||||
}),
|
||||
new TwigTest('object', static function ($var) {
|
||||
return is_object($var);
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -125,9 +142,31 @@ class AppExtension extends AbstractExtension
|
|||
new TwigFunction('generateTreeData', [$this, 'treeData']),
|
||||
new TwigFunction('attachment_thumbnail', [$this->attachmentURLGenerator, 'getThumbnailURL']),
|
||||
new TwigFunction('ext_to_fa_icon', [$this->FAIconGenerator, 'fileExtensionToFAType']),
|
||||
new TwigFunction('entity_type', [$this, 'getEntityType']),
|
||||
];
|
||||
}
|
||||
|
||||
public function getEntityType($entity): ?string
|
||||
{
|
||||
$map = [
|
||||
Part::class => 'part',
|
||||
Footprint::class => 'footprint',
|
||||
Storelocation::class => 'storelocation',
|
||||
Manufacturer::class => 'manufacturer',
|
||||
Category::class => 'category',
|
||||
Device::class => 'device',
|
||||
Attachment::class => 'attachment',
|
||||
Supplier::class => 'supplier',
|
||||
User::class => 'user',
|
||||
Group::class => 'group',
|
||||
Currency::class => 'currency',
|
||||
MeasurementUnit::class => 'measurement_unit',
|
||||
LabelProfile::class => 'label_profile',
|
||||
];
|
||||
|
||||
return $map[get_class($entity)] ?? null;
|
||||
}
|
||||
|
||||
public function treeData(AbstractDBElement $element, string $type = 'newEdit'): string
|
||||
{
|
||||
$tree = $this->treeBuilder->getTreeView(get_class($element), null, $type, $element);
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
<button class="accordion-button" data-bs-toggle="collapse" data-bs-target="#entityInfo">
|
||||
{% if entity.masterPictureAttachment is not null and attachment_manager.isFileExisting(entity.masterPictureAttachment) %}
|
||||
<img class="hoverpic ms-0 me-0 d-inline" {{ stimulus_controller('elements/hoverpic') }} data-thumbnail="{{ entity.masterPictureAttachment | entityURL('file_view') }}" src="{{ attachment_thumbnail(entity.masterPictureAttachment, 'thumbnail_sm') }}">
|
||||
{% else %}
|
||||
{{ helper.entity_icon(entity, "me-1") }}
|
||||
{% endif %}
|
||||
{{ header_label | trans }}: <b>{{ entity.name }}</b>
|
||||
</button>
|
||||
|
|
|
@ -71,20 +71,58 @@
|
|||
{% endif %}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro breadcrumb_entity_link(entity, link_type = "list_parts") %}
|
||||
<nav aria-label="breadcrumb">
|
||||
<ol class="breadcrumb py-2 px-3 rounded" style="background-color: var(--bs-gray-200);">
|
||||
{% for e in entity.pathArray %}
|
||||
<li class="breadcrumb-item {% if loop.last %}active{% endif %}">
|
||||
{% if link_type is not empty and not loop.last and e.id is not null %}
|
||||
<a href="{{ e | entityURL(link_type) }}">{{ e.name }}</a>
|
||||
{% else %}
|
||||
{{ e.name }}
|
||||
{% endif %}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ol>
|
||||
</nav>
|
||||
{% macro entity_icon(entity_or_type, classes = "", style = "") %}
|
||||
{% set map = {
|
||||
"attachment_type": ["fa-solid fa-file-alt", "attachment_type.label"],
|
||||
"category": ["fa-solid fa-tags", "category.label"],
|
||||
"currency": ["fa-solid fa-coins", "currency.label"],
|
||||
"device": ["fa-solid fa-archive", "device.label"],
|
||||
"footprint": ["fa-solid fa-microchip", "footprint.label"],
|
||||
"group": ["fa-solid fa-users", "group.label"],
|
||||
"label_profile": ["fa-solid fa-qrcode", "label_profile.label"],
|
||||
"manufacturer": ["fa-solid fa-industry", "manufacturer.label"],
|
||||
"measurement_unit": ["fa-solid fa-balance-scale", "measurement_unit.label"],
|
||||
"storelocation": ["fa-solid fa-cube", "storelocation.label"],
|
||||
"supplier": ["fa-solid fa-truck", "supplier.label"],
|
||||
"user": ["fa-solid fa-user", "user.label"],
|
||||
} %}
|
||||
|
||||
{% if entity_or_type is entity %}
|
||||
{% set type = entity_type(entity_or_type) %}
|
||||
{% else %}
|
||||
{% set type = entity_or_type %}
|
||||
{% endif %}
|
||||
|
||||
{% if type is not null and map[type] is defined %}
|
||||
{% set icon = map[type][0] %}
|
||||
{% set label = map[type][1] %}
|
||||
{% else %}
|
||||
{% set icon = "fa-solid fa-question" %}
|
||||
{% set label = "Unknown type " ~ type %}
|
||||
{% endif %}
|
||||
|
||||
<i class="fa-fw {{ icon }} {{ classes }}" style="{{ style }}" title="{{ label | trans }}"></i>
|
||||
{% endmacro %}
|
||||
|
||||
{% macro breadcrumb_entity_link(entity, link_type = "list_parts", icon = "") %}
|
||||
<nav aria-label="breadcrumb">
|
||||
<ol class="breadcrumb py-2 px-3 rounded" style="background-color: var(--bs-gray-200);">
|
||||
{% if icon is not empty %}
|
||||
<i class="{{ icon }} fa-fw me-1" style="line-height: inherit;"></i>
|
||||
{% else %}
|
||||
{{ _self.entity_icon(entity, "me-1", "line-height: inherit;") }}
|
||||
{% endif %}
|
||||
{% for e in entity.pathArray %}
|
||||
<li class="breadcrumb-item {% if loop.last %}active{% endif %}">
|
||||
{% if link_type is not empty and not loop.last and e.id is not null %}
|
||||
<a href="{{ e | entityURL(link_type) }}">{{ e.name }}</a>
|
||||
{% else %}
|
||||
{{ e.name }}
|
||||
{% endif %}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ol>
|
||||
</nav>
|
||||
{% endmacro %}
|
||||
|
||||
{% macro bool_icon(bool) %}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue