diff --git a/assets/ts_src/event_listeners.ts b/assets/ts_src/event_listeners.ts index 46632576..47e9f785 100644 --- a/assets/ts_src/event_listeners.ts +++ b/assets/ts_src/event_listeners.ts @@ -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'}); }); diff --git a/src/Entity/Base/StructuralDBElement.php b/src/Entity/Base/StructuralDBElement.php index 2aa1d0c6..ffe09e12 100644 --- a/src/Entity/Base/StructuralDBElement.php +++ b/src/Entity/Base/StructuralDBElement.php @@ -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. * diff --git a/src/Services/EntityURLGenerator.php b/src/Services/EntityURLGenerator.php index 1123bb78..04a8f143 100644 --- a/src/Services/EntityURLGenerator.php +++ b/src/Services/EntityURLGenerator.php @@ -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) + )); } /** diff --git a/templates/Parts/info/_main_infos.html.twig b/templates/Parts/info/_main_infos.html.twig index 9bccda15..fdcc99e2 100644 --- a/templates/Parts/info/_main_infos.html.twig +++ b/templates/Parts/info/_main_infos.html.twig @@ -1,3 +1,5 @@ +{% import "helper.twig" as helper %} +
{% if part.masterPictureAttachment and part.masterPictureAttachment.picture %} @@ -7,7 +9,10 @@ {% endif %}
-
{{ part.manufacturer.name ?? ""}} +
+ {% if part.manufacturer %} + {{ part.manufacturer.name}} + {% endif %} {% if part.manufacturerProductUrl %} {{ part.manufacturerProductNumber }} @@ -23,14 +28,10 @@ {% endif %}
{{ part.description|bbCode }}
-
- - {{ part.category.fullPath ?? "-"}} +
+ + {{ helper.structural_entity_link(part.category) }}
- {#
- - {{ part.storelocation.fullPath ?? "-"}} -
#}
{{ part.amountSum | amountFormat(part.partUnit) }} @@ -38,9 +39,9 @@ {{ part.minAmount | amountFormat(part.partUnit) }}
-
- - {{ part.footprint.fullPath ?? "-"}} +
+ + {{ helper.structural_entity_link(part.footprint) }}
diff --git a/templates/helper.twig b/templates/helper.twig index 5bdcda6d..8678d29b 100644 --- a/templates/helper.twig +++ b/templates/helper.twig @@ -73,4 +73,23 @@ {{ ("m_status." ~ status) | trans }} {% endif %} +{% endmacro %} + +{% macro structural_entity_link(entity, link_type = "list_parts") %} + {# @var entity \App\Entity\Base\StructuralDBElement #} + {% if entity %} + + {% else %} + - + {% endif %} {% endmacro %} \ No newline at end of file