mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 17:39:06 +02:00
Allow to delete parts.
This commit is contained in:
parent
0ff9e3813a
commit
94ed78f66d
4 changed files with 55 additions and 8 deletions
|
@ -30,12 +30,15 @@
|
|||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Base\NamedDBElement;
|
||||
use App\Entity\Base\StructuralDBElement;
|
||||
use App\Entity\Parts\Category;
|
||||
use App\Entity\Parts\Part;
|
||||
use App\Form\AttachmentFormType;
|
||||
use App\Form\Part\PartBaseType;
|
||||
use App\Services\AttachmentHelper;
|
||||
use App\Services\PricedetailHelper;
|
||||
use App\Services\StructuralElementRecursionHelper;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
|
@ -43,11 +46,15 @@ use Symfony\Component\HttpFoundation\Request;
|
|||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
/**
|
||||
* @Route("/part")
|
||||
* @package App\Controller
|
||||
*/
|
||||
class PartController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @Route("/part/{id}/info", name="part_info")
|
||||
* @Route("/part/{id}", requirements={"id"="\d+"})
|
||||
* @Route("/{id}/info", name="part_info")
|
||||
* @Route("/{id}", requirements={"id"="\d+"})
|
||||
* @param Part $part
|
||||
* @param AttachmentHelper $attachmentHelper
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
|
@ -66,7 +73,7 @@ class PartController extends AbstractController
|
|||
}
|
||||
|
||||
/**
|
||||
* @Route("/part/{id}/edit", name="part_edit")
|
||||
* @Route("/{id}/edit", name="part_edit")
|
||||
*
|
||||
* @param Part $part
|
||||
*
|
||||
|
@ -109,7 +116,32 @@ class PartController extends AbstractController
|
|||
}
|
||||
|
||||
/**
|
||||
* @Route("/part/new", name="part_new")
|
||||
* @Route("/{id}/delete", name="part_delete", methods={"DELETE"})
|
||||
* @param Request $request
|
||||
* @param Part $part
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse
|
||||
*/
|
||||
public function delete(Request $request, Part $part)
|
||||
{
|
||||
$this->denyAccessUnlessGranted('delete', $part);
|
||||
|
||||
if ($this->isCsrfTokenValid('delete' . $part->getId(), $request->request->get('_token'))) {
|
||||
$entityManager = $this->getDoctrine()->getManager();
|
||||
|
||||
//Remove part
|
||||
$entityManager->remove($part);
|
||||
|
||||
//Flush changes
|
||||
$entityManager->flush();
|
||||
|
||||
$this->addFlash('success', 'part.deleted');
|
||||
}
|
||||
|
||||
return $this->redirectToRoute('homepage');
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/new", name="part_new")
|
||||
*
|
||||
* @param Request $request
|
||||
* @param EntityManagerInterface $em
|
||||
|
@ -158,7 +190,7 @@ class PartController extends AbstractController
|
|||
}
|
||||
|
||||
/**
|
||||
* @Route("/part/{id}/clone", name="part_clone")
|
||||
* @Route("/{id}/clone", name="part_clone")
|
||||
* @param Part $part
|
||||
* @param Request $request
|
||||
* @param EntityManagerInterface $em
|
||||
|
|
|
@ -84,7 +84,7 @@ class OrderdetailType extends AbstractType
|
|||
$orderdetail = $event->getData();
|
||||
|
||||
$dummy_pricedetail = new Pricedetail();
|
||||
if ($orderdetail->getSupplier() !== null) {
|
||||
if ($orderdetail !== null && $orderdetail->getSupplier() !== null) {
|
||||
$dummy_pricedetail->setCurrency($orderdetail->getSupplier()->getDefaultCurrency());
|
||||
}
|
||||
|
||||
|
|
|
@ -285,6 +285,10 @@ class EntityURLGenerator
|
|||
|
||||
public function deleteURL($entity) : string
|
||||
{
|
||||
if ($entity instanceof Part) {
|
||||
return $this->urlGenerator->generate('part_delete', ['id' => $entity->getID()]);
|
||||
}
|
||||
|
||||
if ($entity instanceof AttachmentType) {
|
||||
return $this->urlGenerator->generate('attachment_type_delete', ['id' => $entity->getID()]);
|
||||
}
|
||||
|
|
|
@ -23,6 +23,17 @@
|
|||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
{% endif %}
|
||||
|
||||
<form method="post" class="mt-2" action="{{ part|entityURL('delete') }}"
|
||||
data-delete-form data-title="{% trans with {'%name%': part.name }%}part.delete.confirm_title{% endtrans %}"
|
||||
data-message="{% trans %}part.delete.message{% endtrans %}">
|
||||
<input type="hidden" name="_method" value="DELETE">
|
||||
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ part.id) }}">
|
||||
<div class="form-group">
|
||||
<button class="btn btn-danger" {% if not is_granted("delete", part) %}disabled{% endif %}">
|
||||
<i class="fa fa-trash fa-fw"></i>
|
||||
{% trans %}part.delete{% endtrans %}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
Loading…
Add table
Add a link
Reference in a new issue