diff --git a/migrations/Version20221204004815.php b/migrations/Version20221204004815.php new file mode 100644 index 00000000..2fbdeb2b --- /dev/null +++ b/migrations/Version20221204004815.php @@ -0,0 +1,44 @@ +addSql('ALTER TABLE parts ADD ipn VARCHAR(100) DEFAULT NULL'); + $this->addSql('CREATE UNIQUE INDEX UNIQ_6940A7FE3D721C14 ON parts (ipn)'); + $this->addSql('CREATE INDEX parts_idx_ipn ON parts (ipn)'); + } + + public function mySQLDown(Schema $schema): void + { + $this->addSql('DROP INDEX UNIQ_6940A7FE3D721C14 ON `parts`'); + $this->addSql('DROP INDEX parts_idx_ipn ON `parts`'); + $this->addSql('ALTER TABLE `parts` DROP ipn'); + } + + public function sqLiteUp(Schema $schema): void + { + // TODO: Implement sqLiteUp() method. + } + + public function sqLiteDown(Schema $schema): void + { + // TODO: Implement sqLiteDown() method. + } +} diff --git a/src/DataTables/PartsDataTable.php b/src/DataTables/PartsDataTable.php index 824b44a6..7a3c3faa 100644 --- a/src/DataTables/PartsDataTable.php +++ b/src/DataTables/PartsDataTable.php @@ -153,6 +153,10 @@ final class PartsDataTable implements DataTableTypeInterface 'label' => $this->translator->trans('part.table.id'), 'visible' => false, ]) + ->add('ipn', TextColumn::class, [ + 'label' => $this->translator->trans('part.table.ipn'), + 'visible' => false, + ]) ->add('description', MarkdownColumn::class, [ 'label' => $this->translator->trans('part.table.description'), ]); diff --git a/src/Entity/Parts/Part.php b/src/Entity/Parts/Part.php index bd358d76..27aeabaa 100644 --- a/src/Entity/Parts/Part.php +++ b/src/Entity/Parts/Part.php @@ -37,6 +37,7 @@ use DateTime; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; +use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Component\Validator\Constraints as Assert; /** @@ -49,7 +50,9 @@ use Symfony\Component\Validator\Constraints as Assert; * @ORM\Table("`parts`", indexes={ * @ORM\Index(name="parts_idx_datet_name_last_id_needs", columns={"datetime_added", "name", "last_modified", "id", "needs_review"}), * @ORM\Index(name="parts_idx_name", columns={"name"}), + * @ORM\Index(name="parts_idx_ipn", columns={"ipn"}), * }) + * @UniqueEntity(fields={"ipn"}, message="part.ipn.must_be_unique") */ class Part extends AttachmentContainingDBElement { diff --git a/src/Entity/Parts/PartTraits/AdvancedPropertyTrait.php b/src/Entity/Parts/PartTraits/AdvancedPropertyTrait.php index c36ba7c9..a798c305 100644 --- a/src/Entity/Parts/PartTraits/AdvancedPropertyTrait.php +++ b/src/Entity/Parts/PartTraits/AdvancedPropertyTrait.php @@ -50,6 +50,14 @@ trait AdvancedPropertyTrait */ protected ?float $mass = null; + /** + * @var string The internal part number of the part + * @ORM\Column(type="string", length=100, nullable=true, unique=true) + * @Assert\Length(max="100") + * + */ + protected ?string $ipn = null; + /** * Checks if this part is marked, for that it needs further review. */ @@ -117,4 +125,26 @@ trait AdvancedPropertyTrait return $this; } + + /** + * Returns the internal part number of the part. + * @return string + */ + public function getIpn(): ?string + { + return $this->ipn; + } + + /** + * Sets the internal part number of the part + * @param string $ipn The new IPN of the part + * @return Part + */ + public function setIpn(?string $ipn): Part + { + $this->ipn = $ipn; + return $this; + } + + } diff --git a/src/Form/Part/PartBaseType.php b/src/Form/Part/PartBaseType.php index 2b34bd00..3f7a4d82 100644 --- a/src/Form/Part/PartBaseType.php +++ b/src/Form/Part/PartBaseType.php @@ -50,6 +50,8 @@ use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Security\Core\Security; +use function Sodium\add; + class PartBaseType extends AbstractType { protected Security $security; @@ -169,6 +171,11 @@ class PartBaseType extends AbstractType 'required' => false, 'disable_not_selectable' => true, 'label' => 'part.edit.partUnit', + ]) + ->add('ipn', TextType::class, [ + 'required' => false, + 'empty_data' => null, + 'label' => 'part.edit.ipn', ]); //Comment section diff --git a/src/Migration/AbstractMultiPlatformMigration.php b/src/Migration/AbstractMultiPlatformMigration.php index fbb811bf..12d4cf87 100644 --- a/src/Migration/AbstractMultiPlatformMigration.php +++ b/src/Migration/AbstractMultiPlatformMigration.php @@ -130,7 +130,9 @@ abstract class AbstractMultiPlatformMigration extends AbstractMigration public function postUp(Schema $schema): void { parent::postUp($schema); - $this->logger->warning('[!!!] Permissions were updated! Please check if they fit your expectations!'); + if($this->permissions_updated) { + $this->logger->warning('[!!!] Permissions were updated! Please check if they fit your expectations!'); + } if (!empty($this->admin_pw)) { $this->logger->warning(''); diff --git a/templates/Parts/edit/_advanced.html.twig b/templates/Parts/edit/_advanced.html.twig index 0e79688a..12b546ab 100644 --- a/templates/Parts/edit/_advanced.html.twig +++ b/templates/Parts/edit/_advanced.html.twig @@ -1,4 +1,5 @@ {{ form_row(form.needsReview) }} {{ form_row(form.favorite) }} {{ form_row(form.mass) }} +{{ form_row(form.ipn) }} {{ form_row(form.partUnit) }} \ No newline at end of file diff --git a/templates/Parts/edit/edit_part_info.html.twig b/templates/Parts/edit/edit_part_info.html.twig index 981cc874..5ed0c105 100644 --- a/templates/Parts/edit/edit_part_info.html.twig +++ b/templates/Parts/edit/edit_part_info.html.twig @@ -9,7 +9,7 @@ {% trans with {'%name%': part.name} %}part.edit.card_title{% endtrans %} {{ part.name }}
- {% trans %}id.label{% endtrans %}: {{ part.id }} + {% trans %}id.label{% endtrans %}: {{ part.id }} {% if part.ipn is not empty %}({{ part.ipn }}){% endif %}
{% endblock %} diff --git a/templates/Parts/info/_extended_infos.html.twig b/templates/Parts/info/_extended_infos.html.twig index 97a375d7..fec3d5c9 100644 --- a/templates/Parts/info/_extended_infos.html.twig +++ b/templates/Parts/info/_extended_infos.html.twig @@ -37,6 +37,11 @@ {{ part.iD }} + {# ID #} + {% trans %}part.edit.ipn{% endtrans %} + {{ part.ipn ?? 'part.ipn.not_defined'|trans }} + + {# Favorite status #} {% trans %}part.isFavorite{% endtrans %} {{ helper.boolean(part.favorite) }} diff --git a/templates/Parts/info/show_part_info.html.twig b/templates/Parts/info/show_part_info.html.twig index 649e690b..021b6666 100644 --- a/templates/Parts/info/show_part_info.html.twig +++ b/templates/Parts/info/show_part_info.html.twig @@ -21,7 +21,7 @@ ({{ timeTravel | format_datetime('short') }}) {% endif %}
- {% trans %}id.label{% endtrans %}: {{ part.id }} + {% trans %}id.label{% endtrans %}: {{ part.id }} {% if part.ipn is not empty %}({{ part.ipn }}){% endif %}
{% endblock %} diff --git a/translations/messages.en.xlf b/translations/messages.en.xlf index 6ed05329..d10f8379 100644 --- a/translations/messages.en.xlf +++ b/translations/messages.en.xlf @@ -9905,5 +9905,23 @@ Element 3 Unset Needs Review Status + + + part.edit.ipn + Internal Part Number (IPN) + + + + + part.ipn.not_defined + Not defined + + + + + part.table.ipn + IPN + + diff --git a/translations/validators.en.xlf b/translations/validators.en.xlf index cccb2bb7..f425756a 100644 --- a/translations/validators.en.xlf +++ b/translations/validators.en.xlf @@ -233,5 +233,11 @@ To enable SI prefixes, you have to set a unit symbol! + + + part.ipn.must_be_unique + The internal part number must be unique. {{ value }} is already in use! + +