mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-22 09:53:35 +02:00
Show higher resolution thumbnail when hover over a table picture.
Also use thumbnails for attachment edit preview.
This commit is contained in:
parent
a545e04554
commit
4c7767feed
9 changed files with 35 additions and 12 deletions
|
@ -532,10 +532,12 @@ class AjaxUI {
|
||||||
//Set the correct title in the table.
|
//Set the correct title in the table.
|
||||||
let title = $('#part-card-header-src');
|
let title = $('#part-card-header-src');
|
||||||
$('#part-card-header').html(title.html());
|
$('#part-card-header').html(title.html());
|
||||||
|
$(document).trigger('ajaxUI:dt_loaded');
|
||||||
|
|
||||||
//Attach event listener to update links after new page selection:
|
//Attach event listener to update links after new page selection:
|
||||||
$('#dt').on('draw.dt', function() {
|
$('#dt').on('draw.dt', function() {
|
||||||
ajaxUI.registerLinks();
|
ajaxUI.registerLinks();
|
||||||
|
$(document).trigger('ajaxUI:dt_loaded');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -304,6 +304,15 @@ $(document).on("ajaxUI:reload ajaxUI:start", function () {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the higher resolution version of hover pictures.
|
||||||
|
*/
|
||||||
|
$(document).on("ajaxUI:reload ajaxUI:start ajaxUI:dt_loaded", function () {
|
||||||
|
$(".hoverpic[data-thumbnail]").mouseenter(function() {
|
||||||
|
$(this).attr('src', $(this).data('thumbnail'));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Register the button which is used to
|
* Register the button which is used to
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -13,8 +13,7 @@ liip_imagine:
|
||||||
|
|
||||||
thumbnail_md:
|
thumbnail_md:
|
||||||
quality: 75
|
quality: 75
|
||||||
filters:
|
|
||||||
filters:
|
filters:
|
||||||
thumbnail:
|
thumbnail:
|
||||||
size: [300, 300]
|
size: [250, 250]
|
||||||
mode: inset
|
mode: inset
|
||||||
|
|
|
@ -91,9 +91,10 @@ class AttachmentDataTable implements DataTableTypeInterface
|
||||||
&& !$context->isExternal()
|
&& !$context->isExternal()
|
||||||
&& $this->attachmentHelper->isFileExisting($context)) {
|
&& $this->attachmentHelper->isFileExisting($context)) {
|
||||||
return sprintf(
|
return sprintf(
|
||||||
'<img alt="%s" src="%s" class="%s">',
|
'<img alt="%s" src="%s" data-thumbnail="%s" class="%s">',
|
||||||
'Part image',
|
'Part image',
|
||||||
$this->attachmentURLGenerator->getThumbnailURL($context),
|
$this->attachmentURLGenerator->getThumbnailURL($context),
|
||||||
|
$this->attachmentURLGenerator->getThumbnailURL($context, 'thumbnail_md'),
|
||||||
'img-fluid hoverpic'
|
'img-fluid hoverpic'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -166,9 +166,10 @@ class PartsDataTable implements DataTableTypeInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
return sprintf(
|
return sprintf(
|
||||||
'<img alt="%s" src="%s" class="%s">',
|
'<img alt="%s" src="%s" data-thumbnail="%s" class="%s">',
|
||||||
'Part image',
|
'Part image',
|
||||||
$this->attachmentURLGenerator->getThumbnailURL($preview_attachment),
|
$this->attachmentURLGenerator->getThumbnailURL($preview_attachment),
|
||||||
|
$this->attachmentURLGenerator->getThumbnailURL($preview_attachment, 'thumbnail_md'),
|
||||||
'img-fluid hoverpic'
|
'img-fluid hoverpic'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,8 +139,14 @@ class AttachmentURLGenerator
|
||||||
return $this->urlGenerator->generate('attachment_view', ['id' => $attachment->getID()]);
|
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
|
//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
|
public function getDownloadURL(Attachment $attachment) : string
|
||||||
{
|
{
|
||||||
//Redirect always to download controller, which sets the correct headers for downloading:
|
//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()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -34,6 +34,7 @@ use App\Entity\Base\DBElement;
|
||||||
use App\Entity\Parts\MeasurementUnit;
|
use App\Entity\Parts\MeasurementUnit;
|
||||||
use App\Entity\PriceInformations\Currency;
|
use App\Entity\PriceInformations\Currency;
|
||||||
use App\Services\AmountFormatter;
|
use App\Services\AmountFormatter;
|
||||||
|
use App\Services\Attachments\AttachmentURLGenerator;
|
||||||
use App\Services\EntityURLGenerator;
|
use App\Services\EntityURLGenerator;
|
||||||
use App\Services\MoneyFormatter;
|
use App\Services\MoneyFormatter;
|
||||||
use App\Services\SIFormatter;
|
use App\Services\SIFormatter;
|
||||||
|
@ -56,11 +57,13 @@ class AppExtension extends AbstractExtension
|
||||||
protected $moneyFormatter;
|
protected $moneyFormatter;
|
||||||
protected $siformatter;
|
protected $siformatter;
|
||||||
protected $amountFormatter;
|
protected $amountFormatter;
|
||||||
|
protected $attachmentURLGenerator;
|
||||||
|
|
||||||
public function __construct(EntityURLGenerator $entityURLGenerator, AdapterInterface $cache,
|
public function __construct(EntityURLGenerator $entityURLGenerator, AdapterInterface $cache,
|
||||||
SerializerInterface $serializer, TreeBuilder $treeBuilder,
|
SerializerInterface $serializer, TreeBuilder $treeBuilder,
|
||||||
MoneyFormatter $moneyFormatter,
|
MoneyFormatter $moneyFormatter,
|
||||||
SIFormatter $SIFormatter, AmountFormatter $amountFormatter)
|
SIFormatter $SIFormatter, AmountFormatter $amountFormatter,
|
||||||
|
AttachmentURLGenerator $attachmentURLGenerator)
|
||||||
{
|
{
|
||||||
$this->entityURLGenerator = $entityURLGenerator;
|
$this->entityURLGenerator = $entityURLGenerator;
|
||||||
$this->cache = $cache;
|
$this->cache = $cache;
|
||||||
|
@ -69,6 +72,7 @@ class AppExtension extends AbstractExtension
|
||||||
$this->moneyFormatter = $moneyFormatter;
|
$this->moneyFormatter = $moneyFormatter;
|
||||||
$this->siformatter = $SIFormatter;
|
$this->siformatter = $SIFormatter;
|
||||||
$this->amountFormatter = $amountFormatter;
|
$this->amountFormatter = $amountFormatter;
|
||||||
|
$this->attachmentURLGenerator = $attachmentURLGenerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFilters()
|
public function getFilters()
|
||||||
|
@ -95,7 +99,8 @@ class AppExtension extends AbstractExtension
|
||||||
public function getFunctions()
|
public function getFunctions()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
new TwigFunction('generateTreeData', [$this, 'treeData'])
|
new TwigFunction('generateTreeData', [$this, 'treeData']),
|
||||||
|
new TwigFunction('attachment_thumbnail', [$this->attachmentURLGenerator, 'getThumbnailURL'])
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if attach.picture %}
|
{% if attach.picture %}
|
||||||
<a href="{{ attach | entityURL('file_view') }}" target="_blank" data-no-ajax>
|
<a href="{{ attach | entityURL('file_view') }}" target="_blank" data-no-ajax>
|
||||||
<img class="img-fluid img-thumbnail thumbnail-sm" src="{{ attach | entityURL('file_view') }}" alt="{% trans %}attachment.preview.alt{% endtrans %}" />
|
<img class="img-fluid img-thumbnail thumbnail-sm" src="{{ attachment_thumbnail(attach, 'thumbnail_md') }}" alt="{% trans %}attachment.preview.alt{% endtrans %}" />
|
||||||
</a>
|
</a>
|
||||||
{% else %}
|
{% else %}
|
||||||
<a href="{{ attach | entityURL('file_view') }}" target="_blank" data-no-ajax class="link-external">{% trans %}attachment.view{% endtrans %}</a>
|
<a href="{{ attach | entityURL('file_view') }}" target="_blank" data-no-ajax class="link-external">{% trans %}attachment.view{% endtrans %}</a>
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
|
|
||||||
{% if attach.picture %}
|
{% if attach.picture %}
|
||||||
<a href="{{ attach | entityURL('file_view') }}" target="_blank" data-no-ajax>
|
<a href="{{ attach | entityURL('file_view') }}" target="_blank" data-no-ajax>
|
||||||
<img class="img-fluid img-thumbnail thumbnail-sm" src="{{ attach | entityURL('file_view') }}" alt="{% trans %}attachment.preview.alt{% endtrans %}" />
|
<img class="img-fluid img-thumbnail thumbnail-sm" src="{{ attachment_thumbnail(attach, 'thumbnail_md') }}" alt="{% trans %}attachment.preview.alt{% endtrans %}" />
|
||||||
</a>
|
</a>
|
||||||
{% else %}
|
{% else %}
|
||||||
<a href="{{ attach | entityURL('file_view') }}" target="_blank" data-no-ajax class="link-external">{% trans %}attachment.view{% endtrans %}</a>
|
<a href="{{ attach | entityURL('file_view') }}" target="_blank" data-no-ajax class="link-external">{% trans %}attachment.view{% endtrans %}</a>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue