mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 01:25:55 +02:00
Allow to show the footprint image in part info.
Also added an placehoder image for parts, who dont have an image.
This commit is contained in:
parent
2e3713cd5e
commit
40714c1914
4 changed files with 86 additions and 3 deletions
22
public/img/part_placeholder.svg
Normal file
22
public/img/part_placeholder.svg
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Generator: Adobe Illustrator 21.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||||
|
<svg version="1.1" id="Ebene_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||||
|
viewBox="0 0 283.5 283.5" style="enable-background:new 0 0 283.5 283.5;" xml:space="preserve">
|
||||||
|
<style type="text/css">
|
||||||
|
.st0{fill:none;}
|
||||||
|
.st1{fill:#444444;}
|
||||||
|
</style>
|
||||||
|
<rect class="st0" width="283.5" height="283.5"/>
|
||||||
|
<path class="st1" d="M204.4,60.3v162.8c0,10.4-8.4,18.8-18.8,18.8H97.9c-10.4,0-18.8-8.4-18.8-18.8V60.3c0-10.4,8.4-18.8,18.8-18.8
|
||||||
|
h87.7C195.9,41.5,204.4,49.9,204.4,60.3z M241.9,83v4.7c0,1.3-1.1,2.3-2.3,2.3h-7v2.3c0,1.3-1.1,2.3-2.3,2.3h-16.4V76h16.4
|
||||||
|
c1.3,0,2.3,1.1,2.3,2.3v2.3h7C240.9,80.7,241.9,81.7,241.9,83z M241.9,120.6v4.7c0,1.3-1.1,2.3-2.3,2.3h-7v2.3
|
||||||
|
c0,1.3-1.1,2.3-2.3,2.3h-16.4v-18.8h16.4c1.3,0,2.3,1.1,2.3,2.3v2.3h7C240.9,118.2,241.9,119.3,241.9,120.6z M241.9,158.2v4.7
|
||||||
|
c0,1.3-1.1,2.3-2.3,2.3h-7v2.3c0,1.3-1.1,2.3-2.3,2.3h-16.4v-18.8h16.4c1.3,0,2.3,1.1,2.3,2.3v2.3h7
|
||||||
|
C240.9,155.8,241.9,156.9,241.9,158.2z M241.9,195.7v4.7c0,1.3-1.1,2.3-2.3,2.3h-7v2.3c0,1.3-1.1,2.3-2.3,2.3h-16.4v-18.8h16.4
|
||||||
|
c1.3,0,2.3,1.1,2.3,2.3v2.3h7C240.9,193.4,241.9,194.4,241.9,195.7z M53.3,188.7h16.4v18.8H53.3c-1.3,0-2.3-1.1-2.3-2.3v-2.3h-7
|
||||||
|
c-1.3,0-2.3-1.1-2.3-2.3v-4.7c0-1.3,1.1-2.3,2.3-2.3h7V191C50.9,189.8,52,188.7,53.3,188.7z M53.3,151.1h16.4v18.8H53.3
|
||||||
|
c-1.3,0-2.3-1.1-2.3-2.3v-2.3h-7c-1.3,0-2.3-1.1-2.3-2.3v-4.7c0-1.3,1.1-2.3,2.3-2.3h7v-2.3C50.9,152.2,52,151.1,53.3,151.1z
|
||||||
|
M53.3,113.5h16.4v18.8H53.3c-1.3,0-2.3-1.1-2.3-2.3v-2.3h-7c-1.3,0-2.3-1.1-2.3-2.3v-4.7c0-1.3,1.1-2.3,2.3-2.3h7v-2.3
|
||||||
|
C50.9,114.6,52,113.5,53.3,113.5z M53.3,76h16.4v18.8H53.3c-1.3,0-2.3-1.1-2.3-2.3v-2.3h-7c-1.3,0-2.3-1.1-2.3-2.3V83
|
||||||
|
c0-1.3,1.1-2.3,2.3-2.3h7v-2.3C50.9,77,52,76,53.3,76z"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 1.8 KiB |
|
@ -34,6 +34,7 @@ namespace App\Controller;
|
||||||
|
|
||||||
|
|
||||||
use App\Entity\Part;
|
use App\Entity\Part;
|
||||||
|
use App\Services\AttachmentFilenameService;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\Routing\Annotation\Route;
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
|
|
||||||
|
@ -44,14 +45,15 @@ class PartController extends AbstractController
|
||||||
* @Route("/part/{id}/info", name="part_info")
|
* @Route("/part/{id}/info", name="part_info")
|
||||||
* @Route("/part/{id}")
|
* @Route("/part/{id}")
|
||||||
*/
|
*/
|
||||||
function show(Part $part)
|
function show(Part $part, AttachmentFilenameService $attachmentFilenameService)
|
||||||
{
|
{
|
||||||
$filename = $part->getMasterPictureFilename(true);
|
$filename = $part->getMasterPictureFilename(true);
|
||||||
dump($filename);
|
dump($filename);
|
||||||
|
|
||||||
return $this->render('show_part_info.html.twig',
|
return $this->render('show_part_info.html.twig',
|
||||||
[
|
[
|
||||||
"part" => $part
|
"part" => $part,
|
||||||
|
"main_image" => $attachmentFilenameService->attachmentPathToAbsolutePath($filename)
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
59
src/Services/AttachmentFilenameService.php
Normal file
59
src/Services/AttachmentFilenameService.php
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* part-db version 0.1
|
||||||
|
* Copyright (C) 2005 Christoph Lechner
|
||||||
|
* http://www.cl-projects.de/
|
||||||
|
*
|
||||||
|
* part-db version 0.2+
|
||||||
|
* Copyright (C) 2009 K. Jacobs and others (see authors.php)
|
||||||
|
* http://code.google.com/p/part-db/
|
||||||
|
*
|
||||||
|
* Part-DB Version 0.4+
|
||||||
|
* Copyright (C) 2016 - 2019 Jan Böhmer
|
||||||
|
* https://github.com/jbtronics
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Services;
|
||||||
|
|
||||||
|
|
||||||
|
use Symfony\Component\Asset\Packages;
|
||||||
|
|
||||||
|
class AttachmentFilenameService
|
||||||
|
{
|
||||||
|
protected $package;
|
||||||
|
|
||||||
|
public function __construct(Packages $package)
|
||||||
|
{
|
||||||
|
$this->package = $package;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function attachmentPathToAbsolutePath(?string $filename) : ?string
|
||||||
|
{
|
||||||
|
//Return placeholder if a part does not have an attachment
|
||||||
|
if ($filename == null) {
|
||||||
|
return $this->package->getUrl('/img/part_placeholder.svg');
|
||||||
|
}
|
||||||
|
if (stripos($filename, "%BASE%/img/") !== false) {
|
||||||
|
return $this->package->getUrl(str_replace('%BASE%', '', $filename));
|
||||||
|
}
|
||||||
|
|
||||||
|
//If no other method works, return placeholder
|
||||||
|
return $this->package->getUrl('/img/part_placeholder.svg');
|
||||||
|
}
|
||||||
|
}
|
|
@ -19,7 +19,7 @@
|
||||||
<div class="col-md-9">
|
<div class="col-md-9">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-3">
|
<div class="col-md-3">
|
||||||
<img src="https://via.placeholder.com/300" class="img-fluid img-thumbnail" height="300" width="300">
|
<img src="{{ main_image }}" class="img-fluid img-thumbnail bg-light" height="300" width="300">
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-9">
|
<div class="col-md-9">
|
||||||
<h5 class="text-muted pt-2" title="{% trans %}manufacturer.label{% endtrans %}">{{ part.manufacturer.name ?? ""}}</h5>
|
<h5 class="text-muted pt-2" title="{% trans %}manufacturer.label{% endtrans %}">{{ part.manufacturer.name ?? ""}}</h5>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue