mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-20 17:15:51 +02:00
Do not throw an exception during rendering of log detail page, if element has no time travel URL
This commit is contained in:
parent
e68827bf3b
commit
efc152e3c8
3 changed files with 18 additions and 5 deletions
|
@ -106,7 +106,7 @@ class EntityURLGenerator
|
|||
/**
|
||||
* Gets the URL to view the given element at a given timestamp.
|
||||
*/
|
||||
public function timeTravelURL(AbstractDBElement $entity, DateTime $dateTime): string
|
||||
public function timeTravelURL(AbstractDBElement $entity, \DateTimeInterface $dateTime): string
|
||||
{
|
||||
$map = [
|
||||
Part::class => 'part_info',
|
||||
|
@ -161,7 +161,7 @@ class EntityURLGenerator
|
|||
}
|
||||
|
||||
//Otherwise throw an error
|
||||
throw new EntityNotSupportedException('The given entity is not supported yet!');
|
||||
throw new EntityNotSupportedException('The given entity is not supported yet! Passed class type: '.get_class($entity));
|
||||
}
|
||||
|
||||
public function viewURL(Attachment $entity): string
|
||||
|
|
|
@ -34,6 +34,7 @@ use App\Entity\Parts\Supplier;
|
|||
use App\Entity\PriceInformations\Currency;
|
||||
use App\Entity\UserSystem\Group;
|
||||
use App\Entity\UserSystem\User;
|
||||
use App\Exceptions\EntityNotSupportedException;
|
||||
use App\Services\ElementTypeNameGenerator;
|
||||
use App\Services\EntityURLGenerator;
|
||||
use App\Services\Trees\TreeViewGenerator;
|
||||
|
@ -72,7 +73,7 @@ final class EntityExtension extends AbstractExtension
|
|||
/* Returns the URL to the given entity */
|
||||
new TwigFunction('entity_url', [$this, 'generateEntityURL']),
|
||||
/* Returns the URL to the given entity in timetravel mode */
|
||||
new TwigFunction('timetravel_url', [$this->entityURLGenerator, 'timetravelURL']),
|
||||
new TwigFunction('timetravel_url', [$this, 'timeTravelURL']),
|
||||
/* Generates a JSON array of the given tree */
|
||||
new TwigFunction('tree_data', [$this, 'treeData']),
|
||||
|
||||
|
@ -81,6 +82,15 @@ final class EntityExtension extends AbstractExtension
|
|||
];
|
||||
}
|
||||
|
||||
public function timeTravelURL(AbstractDBElement $element, \DateTimeInterface $dateTime): ?string
|
||||
{
|
||||
try {
|
||||
return $this->entityURLGenerator->timeTravelURL($element, $dateTime);
|
||||
} catch (EntityNotSupportedException $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function treeData(AbstractDBElement $element, string $type = 'newEdit'): string
|
||||
{
|
||||
$tree = $this->treeBuilder->getTreeView(get_class($element), null, $type, $element);
|
||||
|
|
|
@ -32,10 +32,13 @@
|
|||
<i class="fas fa-fw fa-backward" title="{% trans %}log.undo.revert{% endtrans %}"></i> {{ 'log.undo.revert.short' | trans }}
|
||||
</button>
|
||||
|
||||
{% set url = timetravel_url(target_element, entry.timestamp) %}
|
||||
|
||||
{# View button #}
|
||||
{% if target_element and ((attribute(entry, 'oldDataInformation') is defined and entry.oldDataInformation)
|
||||
or entry is instanceof('App\\Entity\\LogSystem\\CollectionElementDeleted')) %}
|
||||
<a class="btn btn-outline-secondary" href="{{ timetravel_url(target_element, entry.timestamp)}}"><i class="fas fa-fw fa-eye"></i>
|
||||
or entry is instanceof('App\\Entity\\LogSystem\\CollectionElementDeleted'))
|
||||
and url is not null %}
|
||||
<a class="btn btn-outline-secondary" href="{{ url }}"><i class="fas fa-fw fa-eye"></i>
|
||||
{% trans %}log.view_version{% endtrans %}
|
||||
</a>
|
||||
{% endif %}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue