mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-01-13 05:39:33 +00:00
Assembly um IPN-Eingabemöglichkeit und Automatismus zur Name-Angabe erweitern
This commit is contained in:
parent
bba619797e
commit
4f9c20a409
29 changed files with 287 additions and 3 deletions
|
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||
namespace App\Controller\AdminPages;
|
||||
|
||||
use App\DataTables\LogDataTable;
|
||||
use App\Entity\AssemblySystem\Assembly;
|
||||
use App\Entity\Attachments\Attachment;
|
||||
use App\Entity\Attachments\AttachmentContainingDBElement;
|
||||
use App\Entity\Attachments\AttachmentUpload;
|
||||
|
|
@ -193,6 +194,15 @@ abstract class BaseAdminController extends AbstractController
|
|||
$entity->setMasterPictureAttachment(null);
|
||||
}
|
||||
|
||||
if ($entity instanceof Assembly) {
|
||||
/* Replace ipn placeholder with the IPN information if applicable.
|
||||
* The '%%ipn%%' placeholder is automatically inserted into the Name property,
|
||||
* depending on CREATE_ASSEMBLY_USE_IPN_PLACEHOLDER_IN_NAME, when creating a new one,
|
||||
* to avoid having to insert it manually */
|
||||
|
||||
$entity->setName(str_ireplace('%%ipn%%', $entity->getIpn(), $entity->getName()));
|
||||
}
|
||||
|
||||
$this->commentHelper->setMessage($form['log_comment']->getData());
|
||||
|
||||
$em->persist($entity);
|
||||
|
|
@ -287,6 +297,15 @@ abstract class BaseAdminController extends AbstractController
|
|||
$new_entity->setMasterPictureAttachment(null);
|
||||
}
|
||||
|
||||
if ($new_entity instanceof Assembly) {
|
||||
/* Replace ipn placeholder with the IPN information if applicable.
|
||||
* The '%%ipn%%' placeholder is automatically inserted into the Name property,
|
||||
* depending on CREATE_ASSEMBLY_USE_IPN_PLACEHOLDER_IN_NAME, when creating a new one,
|
||||
* to avoid having to insert it manually */
|
||||
|
||||
$new_entity->setName(str_ireplace('%%ipn%%', $new_entity->getIpn(), $new_entity->getName()));
|
||||
}
|
||||
|
||||
$this->commentHelper->setMessage($form['log_comment']->getData());
|
||||
$em->persist($new_entity);
|
||||
$em->flush();
|
||||
|
|
|
|||
|
|
@ -47,8 +47,10 @@ use Doctrine\Common\Collections\ArrayCollection;
|
|||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use InvalidArgumentException;
|
||||
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
||||
use Symfony\Component\Serializer\Annotation\Groups;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
use Symfony\Component\Validator\Constraints\Length;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
|
||||
/**
|
||||
|
|
@ -58,6 +60,8 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
|||
*/
|
||||
#[ORM\Entity]
|
||||
#[ORM\Table(name: 'assemblies')]
|
||||
#[UniqueEntity(fields: ['ipn'], message: 'assembly.ipn.must_be_unique')]
|
||||
#[ORM\Index(columns: ['ipn'], name: 'assembly_idx_ipn')]
|
||||
#[ApiResource(
|
||||
operations: [
|
||||
new Get(security: 'is_granted("read", object)'),
|
||||
|
|
@ -83,7 +87,7 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
|||
normalizationContext: ['groups' => ['assembly:read', 'api:basic:read'], 'openapi_definition_name' => 'Read']
|
||||
)]
|
||||
#[ApiFilter(PropertyFilter::class)]
|
||||
#[ApiFilter(LikeFilter::class, properties: ["name", "comment"])]
|
||||
#[ApiFilter(LikeFilter::class, properties: ["name", "comment", "ipn"])]
|
||||
#[ApiFilter(OrderFilter::class, properties: ['name', 'id', 'addedDate', 'lastModified'])]
|
||||
class Assembly extends AbstractStructuralDBElement
|
||||
{
|
||||
|
|
@ -122,6 +126,14 @@ class Assembly extends AbstractStructuralDBElement
|
|||
#[ORM\Column(type: Types::STRING, length: 64, nullable: true)]
|
||||
protected ?string $status = null;
|
||||
|
||||
/**
|
||||
* @var string|null The internal ipn number of the assembly
|
||||
*/
|
||||
#[Assert\Length(max: 100)]
|
||||
#[Groups(['extended', 'full', 'project:read', 'project:write', 'import'])]
|
||||
#[ORM\Column(type: Types::STRING, length: 100, unique: true, nullable: true)]
|
||||
#[Length(max: 100)]
|
||||
protected ?string $ipn = null;
|
||||
|
||||
/**
|
||||
* @var Part|null The (optional) part that represents the builds of this assembly in the stock
|
||||
|
|
@ -301,6 +313,25 @@ class Assembly extends AbstractStructuralDBElement
|
|||
$this->status = $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the internal part number of the assembly.
|
||||
* @return string
|
||||
*/
|
||||
public function getIpn(): ?string
|
||||
{
|
||||
return $this->ipn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the internal part number of the assembly.
|
||||
* @param string $ipn The new IPN of the assembly
|
||||
*/
|
||||
public function setIpn(?string $ipn): Assembly
|
||||
{
|
||||
$this->ipn = $ipn;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this assembly has an associated part representing the builds of this assembly in the stock.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -25,11 +25,22 @@ namespace App\Form\AdminPages;
|
|||
use App\Entity\Base\AbstractNamedDBElement;
|
||||
use App\Form\AssemblySystem\AssemblyBOMEntryCollectionType;
|
||||
use App\Form\Type\RichTextEditorType;
|
||||
use App\Services\LogSystem\EventCommentNeededHelper;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
class AssemblyAdminForm extends BaseEntityAdminForm
|
||||
{
|
||||
public function __construct(
|
||||
protected Security $security,
|
||||
protected EventCommentNeededHelper $eventCommentNeededHelper,
|
||||
protected bool $useAssemblyIpnPlaceholder = false
|
||||
) {
|
||||
parent::__construct($security, $eventCommentNeededHelper, $useAssemblyIpnPlaceholder);
|
||||
}
|
||||
|
||||
protected function additionalFormElements(FormBuilderInterface $builder, array $options, AbstractNamedDBElement $entity): void
|
||||
{
|
||||
$builder->add('description', RichTextEditorType::class, [
|
||||
|
|
@ -60,5 +71,11 @@ class AssemblyAdminForm extends BaseEntityAdminForm
|
|||
'assembly.status.archived' => 'archived',
|
||||
],
|
||||
]);
|
||||
|
||||
$builder->add('ipn', TextType::class, [
|
||||
'required' => false,
|
||||
'empty_data' => null,
|
||||
'label' => 'assembly.edit.ipn',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,8 +48,11 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
|||
|
||||
class BaseEntityAdminForm extends AbstractType
|
||||
{
|
||||
public function __construct(protected Security $security, protected EventCommentNeededHelper $eventCommentNeededHelper)
|
||||
{
|
||||
public function __construct(
|
||||
protected Security $security,
|
||||
protected EventCommentNeededHelper $eventCommentNeededHelper,
|
||||
protected bool $useAssemblyIpnPlaceholder = false
|
||||
) {
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
|
|
@ -70,6 +73,7 @@ class BaseEntityAdminForm extends AbstractType
|
|||
->add('name', TextType::class, [
|
||||
'empty_data' => '',
|
||||
'label' => 'name.label',
|
||||
'data' => $is_new && $entity instanceof Assembly && $this->useAssemblyIpnPlaceholder ? '%%ipn%%' : $entity->getName(),
|
||||
'attr' => [
|
||||
'placeholder' => 'part.name.placeholder',
|
||||
],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue