mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 01:25:55 +02:00
Added links between edit page and show page.
This commit is contained in:
parent
63c7beb05b
commit
061ca799e3
6 changed files with 105 additions and 9 deletions
|
@ -37,6 +37,7 @@ use App\Entity\Category;
|
|||
use App\Entity\Part;
|
||||
use App\Form\PartType;
|
||||
use App\Services\AttachmentFilenameService;
|
||||
use App\Services\EntityURLGenerator;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
|
@ -70,7 +71,7 @@ class PartController extends AbstractController
|
|||
* @param Part $part
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function edit(Part $part, Request $request, EntityManagerInterface $em, TranslatorInterface $translator)
|
||||
public function edit(Part $part, Request $request, EntityManagerInterface $em)
|
||||
{
|
||||
$form = $this->createForm(PartType::class, $part);
|
||||
|
||||
|
@ -85,7 +86,7 @@ class PartController extends AbstractController
|
|||
return $this->render('edit_part_info.html.twig',
|
||||
[
|
||||
"part" => $part,
|
||||
"form" => $form->createView()
|
||||
"form" => $form->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,6 @@ namespace App\Form;
|
|||
|
||||
|
||||
use App\Entity\Part;
|
||||
use phpDocumentor\Reflection\Types\Integer;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\UrlType;
|
||||
|
@ -49,14 +48,18 @@ class PartType extends AbstractType
|
|||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('name', TextType::class, ['empty_data'=>'', 'label'=> 'name.label'])
|
||||
->add('description', TextType::class, ['required'=>false, 'empty_data'=>'', 'label'=> 'description.label'])
|
||||
->add('instock', IntegerType::class, ['attr' => ['min'=>0], 'label'=> 'instock.label'])
|
||||
->add('mininstock', IntegerType::class, ['attr' => ['min'=>0], 'label'=> 'mininstock.label'])
|
||||
->add('name', TextType::class, ['empty_data'=>'', 'label'=> 'name.label',
|
||||
'attr' => ['placeholder' => 'part.name.placeholder']])
|
||||
->add('description', TextType::class, ['required'=>false, 'empty_data'=>'',
|
||||
'label'=> 'description.label', 'help' => 'bbcode.hint', 'attr' => ['placeholder' => 'part.description.placeholder']])
|
||||
->add('instock', IntegerType::class,
|
||||
['attr' => ['min'=>0, 'placeholder' => 'part.instock.placeholder'], 'label'=> 'instock.label'])
|
||||
->add('mininstock', IntegerType::class,
|
||||
['attr' => ['min'=>0, 'placeholder' => 'part.mininstock.placeholder'], 'label'=> 'mininstock.label'])
|
||||
->add('manufacturer_product_url', UrlType::class, ['required'=>false, 'empty_data' => '',
|
||||
'label'=> 'manufacturer_url.label'])
|
||||
->add('comment', TextareaType::class, ['required'=>false,
|
||||
'label'=> 'comment.label', 'attr' => ['rows'=> 4]])
|
||||
'label'=> 'comment.label', 'attr' => ['rows'=> 4], 'help' => 'bbcode.hint'])
|
||||
|
||||
//Buttons
|
||||
->add('save', SubmitType::class, ['label' => 'part.edit.save'])
|
||||
|
|
|
@ -69,6 +69,27 @@ class EntityURLGenerator
|
|||
throw new EntityNotSupported('The given entity is not supported yet!');
|
||||
}
|
||||
|
||||
public function editURL($entity) : string
|
||||
{
|
||||
if($entity instanceof Part)
|
||||
{
|
||||
return $this->urlGenerator->generate('part_edit', ['id' => $entity->getID()]);
|
||||
}
|
||||
|
||||
//Otherwise throw an error
|
||||
throw new EntityNotSupported('The given entity is not supported yet!');
|
||||
}
|
||||
|
||||
public function createURL($entity) : string
|
||||
{
|
||||
if($entity instanceof Part)
|
||||
{
|
||||
return $this->urlGenerator->generate('part_new');
|
||||
}
|
||||
|
||||
throw new EntityNotSupported('The given entity is not supported yet!');
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an HTML link to the info page about the given entity.
|
||||
* @param $entity mixed The entity for which the info link should be generated.
|
||||
|
|
70
src/Twig/AppExtension.php
Normal file
70
src/Twig/AppExtension.php
Normal file
|
@ -0,0 +1,70 @@
|
|||
<?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\Twig;
|
||||
|
||||
|
||||
use App\Entity\DBElement;
|
||||
use App\Services\EntityURLGenerator;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFilter;
|
||||
|
||||
class AppExtension extends AbstractExtension
|
||||
{
|
||||
protected $entityURLGenerator;
|
||||
|
||||
public function __construct(EntityURLGenerator $entityURLGenerator)
|
||||
{
|
||||
$this->entityURLGenerator = $entityURLGenerator;
|
||||
}
|
||||
|
||||
public function getFilters()
|
||||
{
|
||||
return [
|
||||
new TwigFilter('entityURL', [$this, 'generateEntityURL'])
|
||||
];
|
||||
}
|
||||
|
||||
public function generateEntityURL(DBElement $entity, string $method = 'info') : string
|
||||
{
|
||||
switch($method) {
|
||||
case 'info':
|
||||
return $this->entityURLGenerator->infoURL($entity);
|
||||
case 'edit':
|
||||
return $this->entityURLGenerator->editURL($entity);
|
||||
case 'create':
|
||||
return $this->entityURLGenerator->createURL($entity);
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException('method is not supported!');
|
||||
}
|
||||
|
||||
}
|
|
@ -7,6 +7,7 @@
|
|||
{% block card_title %}
|
||||
<i class="fas fa-edit fa-fw" aria-hidden="true"></i>
|
||||
{% trans with {'%name%': part.name} %}part.edit.card_title{% endtrans %}
|
||||
<b><a href="{{ part|entityURL('info') }}" class="text-white">{{ part.name }}</a></b>
|
||||
<div class="float-right">
|
||||
{% trans %}id.label{% endtrans %}: {{ part.id }}
|
||||
</div>
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
</div>
|
||||
<div class="col-md-9">
|
||||
<h5 class="text-muted pt-2" title="{% trans %}manufacturer.label{% endtrans %}">{{ part.manufacturer.name ?? ""}}</h5>
|
||||
<h3>{{ part.name }}</h3>
|
||||
<h3>{{ part.name }} <a href="{{ part|entityURL('edit') }}"><i class="fas fa-fw fa-sm fa-edit"></i></a></h3>
|
||||
<h6 class="text-muted"><span title="{% trans %}description.label{% endtrans %}">{{ part.description }}</span></h6>
|
||||
<h6 class="" title="{% trans %}storelocation.label{% endtrans %}">
|
||||
<i class="fas fa-cube fa-fw"></i>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue