mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 09:35:49 +02:00
Allow to define manufacturing status for a part.
This commit is contained in:
parent
b14edfc3bd
commit
d22f9da1f0
5 changed files with 84 additions and 4 deletions
|
@ -246,8 +246,9 @@ class Part extends AttachmentContainingDBElement
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
* @ORM\Column(type="string", length=255, nullable=true)
|
* @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)
|
* @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;
|
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.
|
* Get the category of this part.
|
||||||
*
|
*
|
||||||
|
|
|
@ -48,6 +48,7 @@ use FOS\CKEditorBundle\Form\Type\CKEditorType;
|
||||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||||
use Symfony\Component\Form\AbstractType;
|
use Symfony\Component\Form\AbstractType;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
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\CollectionType;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\NumberType;
|
use Symfony\Component\Form\Extension\Core\Type\NumberType;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\UrlType;
|
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\Form\Extension\Core\Type\TextType;
|
||||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
use Symfony\Component\Security\Core\Security;
|
use Symfony\Component\Security\Core\Security;
|
||||||
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||||
|
|
||||||
class PartBaseType extends AbstractType
|
class PartBaseType extends AbstractType
|
||||||
{
|
{
|
||||||
protected $security;
|
protected $security;
|
||||||
|
protected $trans;
|
||||||
|
|
||||||
public function __construct(Security $security)
|
public function __construct(Security $security, TranslatorInterface $trans)
|
||||||
{
|
{
|
||||||
$this->security = $security;
|
$this->security = $security;
|
||||||
|
$this->trans = $trans;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||||
|
@ -73,6 +77,15 @@ class PartBaseType extends AbstractType
|
||||||
/** @var Part $part */
|
/** @var Part $part */
|
||||||
$part = $builder->getData();
|
$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
|
//Common section
|
||||||
$builder
|
$builder
|
||||||
->add('name', TextType::class, ['empty_data' => '', 'label' => 'name.label',
|
->add('name', TextType::class, ['empty_data' => '', 'label' => 'name.label',
|
||||||
|
@ -105,7 +118,13 @@ class PartBaseType extends AbstractType
|
||||||
'disabled' => !$this->security->isGranted('manufacturer.edit', $part), ])
|
'disabled' => !$this->security->isGranted('manufacturer.edit', $part), ])
|
||||||
->add('manufacturer_product_number', TextType::class, ['required' => false,
|
->add('manufacturer_product_number', TextType::class, ['required' => false,
|
||||||
'empty_data' => '', 'label' => 'part.mpn',
|
'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
|
//Advanced section
|
||||||
$builder->add('needsReview', CheckboxType::class, ['label_attr'=> ['class' => 'checkbox-custom'],
|
$builder->add('needsReview', CheckboxType::class, ['label_attr'=> ['class' => 'checkbox-custom'],
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
{{ form_row(form.manufacturer) }}
|
{{ form_row(form.manufacturer) }}
|
||||||
{{ form_row(form.manufacturer_product_number) }}
|
{{ form_row(form.manufacturer_product_number) }}
|
||||||
{{ form_row(form.manufacturer_product_url)}}
|
{{ form_row(form.manufacturer_product_url)}}
|
||||||
|
{{ form_row(form.manufacturing_status) }}
|
|
@ -45,6 +45,13 @@
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{# Manufacturing status tag #}
|
||||||
|
<div class="mt-1">
|
||||||
|
<h6>
|
||||||
|
{{ helper.m_status_to_badge(part.manufacturingStatus) }}
|
||||||
|
</h6>
|
||||||
|
</div>
|
||||||
|
|
||||||
{# Show tags #}
|
{# Show tags #}
|
||||||
{% if part.tags is not empty %}
|
{% if part.tags is not empty %}
|
||||||
<div class="mt-1">
|
<div class="mt-1">
|
||||||
|
|
|
@ -53,3 +53,24 @@
|
||||||
<a href="#" class="{{ class }}" >{{ tag | trim }}</a>
|
<a href="#" class="{{ class }}" >{{ tag | trim }}</a>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endmacro %}
|
{% 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 %}
|
||||||
|
|
||||||
|
<span class="{{ class ~ color}}" title="{{ ("m_status." ~ status ~ ".help") | trans }}">
|
||||||
|
<i class="fa-fw fas fa-info-circle"></i>
|
||||||
|
{{ ("m_status." ~ status) | trans }}
|
||||||
|
</span>
|
||||||
|
{% endif %}
|
||||||
|
{% endmacro %}
|
Loading…
Add table
Add a link
Reference in a new issue