mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 01:25:55 +02:00
Added links to part_lists on part info page.
This commit is contained in:
parent
2040178460
commit
429a4ebd17
5 changed files with 76 additions and 33 deletions
|
@ -125,7 +125,7 @@ $(document).on("ajaxUI:reload", function () {
|
|||
//Use bootstrap tooltips for the most tooltips
|
||||
$(document).on("ajaxUI:start ajaxUI:reload", function () {
|
||||
$(".tooltip").remove();
|
||||
$('a[title], button[title], span[title], h6[title]')
|
||||
$('a[title], button[title], span[title], h6[title], i.fas[title]')
|
||||
//@ts-ignore
|
||||
.tooltip("hide").tooltip({container: "body", placement: "auto", boundary: 'window'});
|
||||
});
|
||||
|
|
|
@ -102,12 +102,6 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
|
|||
*/
|
||||
protected $comment = '';
|
||||
|
||||
/**
|
||||
* @var int
|
||||
* @ORM\Column(type="integer", nullable=true)
|
||||
*/
|
||||
protected $parent_id;
|
||||
|
||||
/**
|
||||
* @var bool If this property is set, this element can not be selected for part properties.
|
||||
* Useful if this element should be used only for grouping, sorting.
|
||||
|
@ -166,24 +160,21 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
|
|||
|| $this->parent->isChildOf($another_element); //Otherwise, check recursivley
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this element is an root element (has no parent)
|
||||
* @return bool True if the this element is an root element.
|
||||
*/
|
||||
public function isRoot() : bool
|
||||
{
|
||||
return $this->parent === null;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* Getters
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* Get the parent-ID
|
||||
*
|
||||
* @return integer * the ID of the parent element
|
||||
* * NULL means, the parent is the root node
|
||||
* * the parent ID of the root node is -1
|
||||
*/
|
||||
protected function getParentID(): int
|
||||
{
|
||||
return $this->parent_id ?? self::ID_ROOT_ELEMENT; //Null means root element
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the parent of this element.
|
||||
*
|
||||
|
@ -259,6 +250,25 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
|
|||
return implode($delimeter, $this->full_path_strings);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the path to this element (including the element itself)
|
||||
* @return self[] An array with all (recursivily) parent elements (including this one),
|
||||
* ordered from the lowest levels (root node) first to the highest level (the element itself)
|
||||
*/
|
||||
public function getPathArray(): array
|
||||
{
|
||||
$tmp = [];
|
||||
$tmp[] = $this;
|
||||
|
||||
//We only allow 20 levels depth
|
||||
while (!end($tmp)->isRoot() && count($tmp) < 20) {
|
||||
$tmp[] = end($tmp)->parent;
|
||||
}
|
||||
|
||||
return array_reverse($tmp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all subelements of this element.
|
||||
*
|
||||
|
|
|
@ -77,9 +77,19 @@ class EntityURLGenerator
|
|||
{
|
||||
$class = get_class($entity);
|
||||
|
||||
//Check if we have an mapping for the given class
|
||||
//Check if we have an direct mapping for the given class
|
||||
if (!array_key_exists($class, $map)) {
|
||||
throw new EntityNotSupported('The given entity is not supported yet!');
|
||||
//Check if we need to check inheritance by looping through our map
|
||||
foreach ($map as $key => $value) {
|
||||
if (is_a($entity, $key)) {
|
||||
return $map[$key];
|
||||
}
|
||||
}
|
||||
|
||||
throw new EntityNotSupported(sprintf(
|
||||
'The given entity is not supported yet! Passed class type: %s',
|
||||
get_class($entity)
|
||||
));
|
||||
}
|
||||
|
||||
return $map[$class];
|
||||
|
@ -144,7 +154,10 @@ class EntityURLGenerator
|
|||
}
|
||||
|
||||
//Otherwise throw an error
|
||||
throw new EntityNotSupported('The given entity is not supported yet!');
|
||||
throw new EntityNotSupported(sprintf(
|
||||
'The given entity is not supported yet! Passed class type: %s',
|
||||
get_class($entity)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
{% import "helper.twig" as helper %}
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-3">
|
||||
{% if part.masterPictureAttachment and part.masterPictureAttachment.picture %}
|
||||
|
@ -7,7 +9,10 @@
|
|||
{% endif %}
|
||||
</div>
|
||||
<div class="col-md-9">
|
||||
<h5 class="text-muted pt-2" title="{% trans %}manufacturer.label{% endtrans %}">{{ part.manufacturer.name ?? ""}}
|
||||
<h5 class="text-muted pt-2" title="{% trans %}manufacturer.label{% endtrans %}">
|
||||
{% if part.manufacturer %}
|
||||
<a href="{{ part.manufacturer | entityURL('list_parts') }}">{{ part.manufacturer.name}}</a>
|
||||
{% endif %}
|
||||
{% if part.manufacturerProductUrl %}
|
||||
<small>
|
||||
<a class="link-external" href="{{ part.manufacturerProductUrl }}" target="_blank">{{ part.manufacturerProductNumber }}</a>
|
||||
|
@ -23,14 +28,10 @@
|
|||
{% endif %}
|
||||
</h3>
|
||||
<h6 class="text-muted"><span title="{% trans %}description.label{% endtrans %}">{{ part.description|bbCode }}</span></h6>
|
||||
<h6 class="" title="{% trans %}category.label{% endtrans %}">
|
||||
<i class="fas fa-tag fa-fw"></i>
|
||||
<span class="text-muted">{{ part.category.fullPath ?? "-"}}</span>
|
||||
<h6 class="">
|
||||
<i class="fas fa-tag fa-fw" title="{% trans %}category.label{% endtrans %}"></i>
|
||||
<span class="text-muted">{{ helper.structural_entity_link(part.category) }}</span>
|
||||
</h6>
|
||||
{# <h6 class="" title="{% trans %}storelocation.label{% endtrans %}">
|
||||
<i class="fas fa-cube fa-fw"></i>
|
||||
<span class="text-muted">{{ part.storelocation.fullPath ?? "-"}}</span>
|
||||
</h6> #}
|
||||
<h6><i class="fas fa-shapes fa-fw"></i>
|
||||
<span class="text-muted">
|
||||
<span title="{% trans %}instock.label{% endtrans %}">{{ part.amountSum | amountFormat(part.partUnit) }}</span>
|
||||
|
@ -38,9 +39,9 @@
|
|||
<span title="{% trans %}mininstock.label{% endtrans %}">{{ part.minAmount | amountFormat(part.partUnit) }}</span>
|
||||
</span>
|
||||
</h6>
|
||||
<h6 class="" title="{% trans %}footprint.label{% endtrans %}">
|
||||
<i class="fas fa-microchip fa-fw" ></i>
|
||||
<span class="text-muted">{{ part.footprint.fullPath ?? "-"}}</span>
|
||||
<h6 class="">
|
||||
<i class="fas fa-microchip fa-fw" title="{% trans %}footprint.label{% endtrans %}"></i>
|
||||
<span class="text-muted">{{ helper.structural_entity_link(part.footprint) }}</span>
|
||||
</h6>
|
||||
<h6>
|
||||
<i class="fas fa-money-bill-alt fa-fw"></i>
|
||||
|
|
|
@ -73,4 +73,23 @@
|
|||
{{ ("m_status." ~ status) | trans }}
|
||||
</span>
|
||||
{% endif %}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro structural_entity_link(entity, link_type = "list_parts") %}
|
||||
{# @var entity \App\Entity\Base\StructuralDBElement #}
|
||||
{% if entity %}
|
||||
<ul class="structural_link d-inline">
|
||||
{% for e in entity.pathArray %}
|
||||
<li>
|
||||
{% if link_type is not empty %}
|
||||
<a href="{{ e | entityURL(link_type) }}">{{ e.name }}</a>
|
||||
{% else %}
|
||||
{{ e.name }}
|
||||
{% endif %}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
-
|
||||
{% endif %}
|
||||
{% endmacro %}
|
Loading…
Add table
Add a link
Reference in a new issue