diff --git a/src/Entity/Parts/Part.php b/src/Entity/Parts/Part.php index 53c877ff..1ebccd3b 100644 --- a/src/Entity/Parts/Part.php +++ b/src/Entity/Parts/Part.php @@ -246,8 +246,9 @@ class Part extends AttachmentContainingDBElement /** * @var string * @ORM\Column(type="string", length=255, nullable=true) + * @Assert\Choice({"announced", "active", "nrfnd", "eol", "discontinued", ""}) */ - protected $manufacturing_status; + protected $manufacturing_status = ""; /** * @var bool Determines if this part entry needs review (for example, because it is work in progress) @@ -442,6 +443,37 @@ class Part extends AttachmentContainingDBElement return $this->manufacturer_product_url; } + /** + * Returns the manufacturing/production status for this part. + * The status can be one of the following: + * (Similar to https://designspark.zendesk.com/hc/en-us/articles/213584805-What-are-the-Lifecycle-Status-definitions-) + * * "": Status unknown + * * "announced": Part has been announced, but is not in production yet + * * "active": Part is in production and will be for the forseeable future + * * "nrfnd": Not recommended for new designs. + * * "eol": Part will become discontinued soon + * * "discontinued": Part is obsolete/discontinued by the manufacturer + * @return string + */ + public function getManufacturingStatus(): ?string + { + return $this->manufacturing_status; + } + + /** + * Sets the manufacturing status for this part + * See getManufacturingStatus() for valid values. + * @param string $manufacturing_status + * @return Part + */ + public function setManufacturingStatus(string $manufacturing_status): Part + { + $this->manufacturing_status = $manufacturing_status; + return $this; + } + + + /** * Get the category of this part. * diff --git a/src/Form/Part/PartBaseType.php b/src/Form/Part/PartBaseType.php index dceb544e..331cccaa 100644 --- a/src/Form/Part/PartBaseType.php +++ b/src/Form/Part/PartBaseType.php @@ -48,6 +48,7 @@ use FOS\CKEditorBundle\Form\Type\CKEditorType; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; +use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\CollectionType; use Symfony\Component\Form\Extension\Core\Type\NumberType; use Symfony\Component\Form\Extension\Core\Type\UrlType; @@ -58,14 +59,17 @@ use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Security\Core\Security; +use Symfony\Contracts\Translation\TranslatorInterface; class PartBaseType extends AbstractType { protected $security; + protected $trans; - public function __construct(Security $security) + public function __construct(Security $security, TranslatorInterface $trans) { $this->security = $security; + $this->trans = $trans; } public function buildForm(FormBuilderInterface $builder, array $options) @@ -73,6 +77,15 @@ class PartBaseType extends AbstractType /** @var Part $part */ $part = $builder->getData(); + $status_choices = [ + $this->trans->trans("m_status.unknown") => '', + $this->trans->trans('m_stauts.announced') => 'announced', + $this->trans->trans('m_status.active') => 'active', + $this->trans->trans('m_status.nrfnd') => 'nrfnd', + $this->trans->trans('m_status.eol') => 'eol', + $this->trans->trans('m_status.discontinued') => 'discontinued' + ]; + //Common section $builder ->add('name', TextType::class, ['empty_data' => '', 'label' => 'name.label', @@ -105,7 +118,13 @@ class PartBaseType extends AbstractType 'disabled' => !$this->security->isGranted('manufacturer.edit', $part), ]) ->add('manufacturer_product_number', TextType::class, ['required' => false, 'empty_data' => '', 'label' => 'part.mpn', - 'disabled' => !$this->security->isGranted('manufacturer.edit', $part)]); + 'disabled' => !$this->security->isGranted('manufacturer.edit', $part)]) + ->add('manufacturing_status', ChoiceType::class, [ + 'label' => 'part.manufacturing_status', + 'choices' => $status_choices, + 'required' => false, + 'disabled' => !$this->security->isGranted('manufacturer.edit', $part) + ]); //Advanced section $builder->add('needsReview', CheckboxType::class, ['label_attr'=> ['class' => 'checkbox-custom'], diff --git a/templates/Parts/edit/_manufacturer.html.twig b/templates/Parts/edit/_manufacturer.html.twig index c25080d8..be95f330 100644 --- a/templates/Parts/edit/_manufacturer.html.twig +++ b/templates/Parts/edit/_manufacturer.html.twig @@ -1,3 +1,4 @@ {{ form_row(form.manufacturer) }} {{ form_row(form.manufacturer_product_number) }} -{{ form_row(form.manufacturer_product_url)}} \ No newline at end of file +{{ form_row(form.manufacturer_product_url)}} +{{ form_row(form.manufacturing_status) }} \ No newline at end of file diff --git a/templates/Parts/info/_sidebar.html.twig b/templates/Parts/info/_sidebar.html.twig index b299ff73..c9839719 100644 --- a/templates/Parts/info/_sidebar.html.twig +++ b/templates/Parts/info/_sidebar.html.twig @@ -45,6 +45,13 @@ {% endif %} +{# Manufacturing status tag #} +
+
+ {{ helper.m_status_to_badge(part.manufacturingStatus) }} +
+
+ {# Show tags #} {% if part.tags is not empty %}
diff --git a/templates/helper.twig b/templates/helper.twig index b47a2c76..05a48a08 100644 --- a/templates/helper.twig +++ b/templates/helper.twig @@ -52,4 +52,25 @@ {% for tag in string|split(',') %} {{ tag | trim }} {% endfor %} +{% endmacro %} + +{% macro m_status_to_badge(status, class="badge") %} + {% if status is not empty %} + {% set color = " badge-secondary" %} + + {% if status == "active" %} + {% set color = " badge-success" %} + {% elseif status == "nrfnd" %} + {% set color = " badge-warning" %} + {% elseif status == "eol" %} + {% set color = " badge-warning" %} + {% elseif status == "discontinued" %} + {% set color = " badge-danger" %} + {% endif %} + + + + {{ ("m_status." ~ status) | trans }} + + {% endif %} {% endmacro %} \ No newline at end of file