Show higher resolution thumbnail when hover over a table picture.

Also use thumbnails for attachment edit preview.
This commit is contained in:
Jan Böhmer 2019-10-06 15:44:19 +02:00
parent a545e04554
commit 4c7767feed
9 changed files with 35 additions and 12 deletions

View file

@ -91,9 +91,10 @@ class AttachmentDataTable implements DataTableTypeInterface
&& !$context->isExternal()
&& $this->attachmentHelper->isFileExisting($context)) {
return sprintf(
'<img alt="%s" src="%s" class="%s">',
'<img alt="%s" src="%s" data-thumbnail="%s" class="%s">',
'Part image',
$this->attachmentURLGenerator->getThumbnailURL($context),
$this->attachmentURLGenerator->getThumbnailURL($context, 'thumbnail_md'),
'img-fluid hoverpic'
);
}

View file

@ -166,9 +166,10 @@ class PartsDataTable implements DataTableTypeInterface
}
return sprintf(
'<img alt="%s" src="%s" class="%s">',
'<img alt="%s" src="%s" data-thumbnail="%s" class="%s">',
'Part image',
$this->attachmentURLGenerator->getThumbnailURL($preview_attachment),
$this->attachmentURLGenerator->getThumbnailURL($preview_attachment, 'thumbnail_md'),
'img-fluid hoverpic'
);
}

View file

@ -139,8 +139,14 @@ class AttachmentURLGenerator
return $this->urlGenerator->generate('attachment_view', ['id' => $attachment->getID()]);
}
//For builtin ressources it is not useful to create a thumbnail
//because the footprints images are small and highly optimized already.
if ($filter_name === 'thumbnail_md' && $attachment->isBuiltIn()) {
return $this->assets->getUrl($asset_path);
}
//Otherwise we can serve the relative path via Asset component
return $this->filterService->getUrlOfFilteredImage($asset_path, 'thumbnail_sm');
return $this->filterService->getUrlOfFilteredImage($asset_path, $filter_name);
}
/**
@ -151,6 +157,6 @@ class AttachmentURLGenerator
public function getDownloadURL(Attachment $attachment) : string
{
//Redirect always to download controller, which sets the correct headers for downloading:
$this->urlGenerator->generate('attachment_download', ['id' => $attachment->getID()]);
return $this->urlGenerator->generate('attachment_download', ['id' => $attachment->getID()]);
}
}

View file

@ -34,6 +34,7 @@ use App\Entity\Base\DBElement;
use App\Entity\Parts\MeasurementUnit;
use App\Entity\PriceInformations\Currency;
use App\Services\AmountFormatter;
use App\Services\Attachments\AttachmentURLGenerator;
use App\Services\EntityURLGenerator;
use App\Services\MoneyFormatter;
use App\Services\SIFormatter;
@ -56,11 +57,13 @@ class AppExtension extends AbstractExtension
protected $moneyFormatter;
protected $siformatter;
protected $amountFormatter;
protected $attachmentURLGenerator;
public function __construct(EntityURLGenerator $entityURLGenerator, AdapterInterface $cache,
SerializerInterface $serializer, TreeBuilder $treeBuilder,
MoneyFormatter $moneyFormatter,
SIFormatter $SIFormatter, AmountFormatter $amountFormatter)
SIFormatter $SIFormatter, AmountFormatter $amountFormatter,
AttachmentURLGenerator $attachmentURLGenerator)
{
$this->entityURLGenerator = $entityURLGenerator;
$this->cache = $cache;
@ -69,6 +72,7 @@ class AppExtension extends AbstractExtension
$this->moneyFormatter = $moneyFormatter;
$this->siformatter = $SIFormatter;
$this->amountFormatter = $amountFormatter;
$this->attachmentURLGenerator = $attachmentURLGenerator;
}
public function getFilters()
@ -95,7 +99,8 @@ class AppExtension extends AbstractExtension
public function getFunctions()
{
return [
new TwigFunction('generateTreeData', [$this, 'treeData'])
new TwigFunction('generateTreeData', [$this, 'treeData']),
new TwigFunction('attachment_thumbnail', [$this->attachmentURLGenerator, 'getThumbnailURL'])
];
}