mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 09:35:49 +02:00
Added a 'clone part' function.
This commit is contained in:
parent
33631f16cf
commit
10f39b7f45
7 changed files with 87 additions and 16 deletions
|
@ -121,7 +121,38 @@ class PartController extends AbstractController
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return $this->render('new_part.html.twig',
|
return $this->render('Parts/new_part.html.twig',
|
||||||
|
[
|
||||||
|
"part" => $new_part,
|
||||||
|
"form" => $form->createView()
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Route("/part/{id}/clone", name="part_clone")
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function clone(Part $part, Request $request, EntityManagerInterface $em, TranslatorInterface $translator)
|
||||||
|
{
|
||||||
|
|
||||||
|
/** @var Part $new_part */
|
||||||
|
$new_part = clone($part);
|
||||||
|
|
||||||
|
$this->denyAccessUnlessGranted('create', $new_part);
|
||||||
|
|
||||||
|
$form = $this->createForm(PartType::class, $new_part);
|
||||||
|
|
||||||
|
$form->handleRequest($request);
|
||||||
|
|
||||||
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
|
$em->persist($new_part);
|
||||||
|
$em->flush();
|
||||||
|
$this->addFlash('success', $translator->trans('part.created_flash'));
|
||||||
|
return $this->redirectToRoute('part_edit',['id' => $new_part->getID()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return $this->render('Parts/new_part.html.twig',
|
||||||
[
|
[
|
||||||
"part" => $new_part,
|
"part" => $new_part,
|
||||||
"form" => $form->createView()
|
"form" => $form->createView()
|
||||||
|
|
|
@ -56,6 +56,7 @@ abstract class DBElement
|
||||||
return (int) $this->id;
|
return (int) $this->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the ID as an string, defined by the element class.
|
* Returns the ID as an string, defined by the element class.
|
||||||
* This should have a form like P000014, for a part with ID 14.
|
* This should have a form like P000014, for a part with ID 14.
|
||||||
|
@ -63,4 +64,10 @@ abstract class DBElement
|
||||||
*/
|
*/
|
||||||
abstract public function getIDString() : string;
|
abstract public function getIDString() : string;
|
||||||
|
|
||||||
|
public function __clone()
|
||||||
|
{
|
||||||
|
//Set ID to null, so that an new entry is created
|
||||||
|
$this->id = null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -90,6 +90,16 @@ class EntityURLGenerator
|
||||||
throw new EntityNotSupported('The given entity is not supported yet!');
|
throw new EntityNotSupported('The given entity is not supported yet!');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function cloneURL($entity) : string
|
||||||
|
{
|
||||||
|
if($entity instanceof Part)
|
||||||
|
{
|
||||||
|
return $this->urlGenerator->generate('part_clone', ['id' => $entity->getID()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new EntityNotSupported('The given entity is not supported yet!');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates an HTML link to the info page about the given entity.
|
* 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.
|
* @param $entity mixed The entity for which the info link should be generated.
|
||||||
|
|
|
@ -68,6 +68,8 @@ class AppExtension extends AbstractExtension
|
||||||
return $this->entityURLGenerator->editURL($entity);
|
return $this->entityURLGenerator->editURL($entity);
|
||||||
case 'create':
|
case 'create':
|
||||||
return $this->entityURLGenerator->createURL($entity);
|
return $this->entityURLGenerator->createURL($entity);
|
||||||
|
case 'clone':
|
||||||
|
return $this->entityURLGenerator->cloneURL($entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new \InvalidArgumentException('method is not supported!');
|
throw new \InvalidArgumentException('method is not supported!');
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
{% extends "edit_part_info.html.twig" %}
|
{% extends "Parts/edit_part_info.html.twig" %}
|
||||||
|
|
||||||
{% block card_border %}border-success{% endblock %}
|
{% block card_border %}border-success{% endblock %}
|
||||||
{% block card_type %}bg-success text-white{% endblock %}
|
{% block card_type %}bg-success text-white{% endblock %}
|
|
@ -68,8 +68,8 @@
|
||||||
<ul class="nav nav-tabs" id="partTab" role="tablist">
|
<ul class="nav nav-tabs" id="partTab" role="tablist">
|
||||||
{% if part.comment is not empty %}
|
{% if part.comment is not empty %}
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link active" id="attachment-tab" data-toggle="tab"
|
<a class="nav-link active" id="comment-tab" data-toggle="tab"
|
||||||
href="#comment" role="tab" aria-controls="home" aria-selected="true">
|
href="#comment" role="tab">
|
||||||
<i class="fas fa-comment-alt fa-fw"></i>
|
<i class="fas fa-comment-alt fa-fw"></i>
|
||||||
{% trans %}comment.label{% endtrans %}
|
{% trans %}comment.label{% endtrans %}
|
||||||
</a>
|
</a>
|
||||||
|
@ -77,25 +77,25 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link {% if part.comment is empty%} active{% endif %}" id="attachment-tab" data-toggle="tab"
|
<a class="nav-link {% if part.comment is empty%} active{% endif %}" id="attachment-tab" data-toggle="tab"
|
||||||
href="#attachments" role="tab" aria-controls="home" aria-selected="true">
|
href="#attachments" role="tab">
|
||||||
<i class="fas fa-paperclip fa-fw"></i>
|
<i class="fas fa-paperclip fa-fw"></i>
|
||||||
{% trans %}attachment.labelp{% endtrans %}
|
{% trans %}attachment.labelp{% endtrans %}
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" id="supplier-tab" data-toggle="tab" href="#suppliers" role="tab" aria-controls="profile" aria-selected="false">
|
<a class="nav-link" id="supplier-tab" data-toggle="tab" href="#suppliers" role="tab">
|
||||||
<i class="fas fa-shopping-cart fa-fw"></i>
|
<i class="fas fa-shopping-cart fa-fw"></i>
|
||||||
{% trans %}vendor.partinfo.shopping_infos{% endtrans %}
|
{% trans %}vendor.partinfo.shopping_infos{% endtrans %}
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" id="history-tab" data-toggle="tab" href="#history" role="tab" aria-controls="contact" aria-selected="false">
|
<a class="nav-link" id="history-tab" data-toggle="tab" href="#history" role="tab">
|
||||||
<i class="fas fa-history"></i>
|
<i class="fas fa-history"></i>
|
||||||
{% trans %}vendor.partinfo.history{% endtrans %}
|
{% trans %}vendor.partinfo.history{% endtrans %}
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" id="tools-tab" data-toggle="tab" href="#tools" role="tab" aria-controls="contact" aria-selected="false">
|
<a class="nav-link" id="tools-tab" data-toggle="tab" href="#tools" role="tab">
|
||||||
<i class="fas fa-tools"></i>
|
<i class="fas fa-tools"></i>
|
||||||
{% trans %}tools.label{% endtrans %}
|
{% trans %}tools.label{% endtrans %}
|
||||||
</a>
|
</a>
|
||||||
|
@ -119,12 +119,33 @@
|
||||||
TODO
|
TODO
|
||||||
</div>
|
</div>
|
||||||
<div class="tab-pane fade" id="tools" role="tabpanel" aria-labelledby="contact-tab">
|
<div class="tab-pane fade" id="tools" role="tabpanel" aria-labelledby="contact-tab">
|
||||||
<form class="mt-3">
|
{% if is_granted('edit', part) %}
|
||||||
<div class="form-group">
|
<a href="{{ part|entityURL('edit') }}" class="btn btn-primary mt-3">
|
||||||
<label>{% trans %}part.delete.caption{% endtrans %}:</label>
|
<i class="fas fa-fw fa-edit"></i>
|
||||||
<button class="btn btn-danger">{% trans %}part.delete.btn{% endtrans %}</button>
|
{% trans %}part.edit.btn{% endtrans %}
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
|
{% if is_granted('create', part) %}
|
||||||
|
<br>
|
||||||
|
<div class="btn-group mt-2">
|
||||||
|
<a class="btn btn-primary" href="{{ part|entityURL('clone') }}">
|
||||||
|
<i class="fas fa-clone"></i>
|
||||||
|
{% trans %}part.clone.btn{% endtrans %}
|
||||||
|
</a>
|
||||||
|
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
|
||||||
|
<span class="caret"></span>
|
||||||
|
</button>
|
||||||
|
<div class="dropdown-menu" role="menu">
|
||||||
|
<a class="dropdown-item" href="{{ part|entityURL('create') }}">
|
||||||
|
<i class="fas fa-plus-square"></i>
|
||||||
|
{% trans %}part.create.btn{% endtrans %}
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -141,7 +141,7 @@
|
||||||
<div class="collapse d-md-block bg-light" id="sidebar-container">
|
<div class="collapse d-md-block bg-light" id="sidebar-container">
|
||||||
<nav class="fixed-sidebar col-md-3 col-lg-2 " id="fixed-sidebar">
|
<nav class="fixed-sidebar col-md-3 col-lg-2 " id="fixed-sidebar">
|
||||||
<ul class="nav flex-column">
|
<ul class="nav flex-column">
|
||||||
<li id="categories">
|
<li id="treeBox-categories">
|
||||||
<div class="dropdown">
|
<div class="dropdown">
|
||||||
<button class="btn-text dropdown-toggle mb-2" type="button" id="dropdownCat" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
|
<button class="btn-text dropdown-toggle mb-2" type="button" id="dropdownCat" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
|
||||||
<span class="sidebar-title" id="tree-categories-title">{% trans %}category.labelp{% endtrans %}</span>
|
<span class="sidebar-title" id="tree-categories-title">{% trans %}category.labelp{% endtrans %}</span>
|
||||||
|
@ -163,7 +163,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div id="tree-categories"></div>
|
<div id="tree-categories"></div>
|
||||||
</li>
|
</li>
|
||||||
<li id="devices">
|
<li id="treeBox-devices">
|
||||||
<div class="dropdown">
|
<div class="dropdown">
|
||||||
<button class="btn-text dropdown-toggle mb-2 mt-2" type="button" id="dropdownDev" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
|
<button class="btn-text dropdown-toggle mb-2 mt-2" type="button" id="dropdownDev" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
|
||||||
<span class="sidebar-title" id="tree-devices-title">{% trans %}device.labelp{% endtrans %}</span>
|
<span class="sidebar-title" id="tree-devices-title">{% trans %}device.labelp{% endtrans %}</span>
|
||||||
|
@ -186,7 +186,7 @@
|
||||||
<div id="tree-devices"></div>
|
<div id="tree-devices"></div>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li id="tools">
|
<li id="treeBox-tools">
|
||||||
<div class="dropdown">
|
<div class="dropdown">
|
||||||
<button class="btn-text dropdown-toggle mb-2 mt-2" type="button" id="dropdownTools" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
|
<button class="btn-text dropdown-toggle mb-2 mt-2" type="button" id="dropdownTools" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
|
||||||
<span class="sidebar-title" id="tree-tools-title">{% trans %}tools.label{% endtrans %}</span>
|
<span class="sidebar-title" id="tree-tools-title">{% trans %}tools.label{% endtrans %}</span>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue