Allow to put parameters in different groups.

This commit is contained in:
Jan Böhmer 2020-03-24 15:08:56 +01:00
parent 43857ce985
commit 2899db0206
31 changed files with 114 additions and 23 deletions

View file

@ -64,6 +64,7 @@ class AttachmentType extends AbstractStructuralDBElement
/** @var AttachmentTypeParameter[]
* @ORM\OneToMany(targetEntity="App\Entity\Parameters\AttachmentTypeParameter", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
* @ORM\OrderBy({"group" = "ASC" ,"name" = "ASC"})
* @Assert\Valid()
*/
protected $parameters;

View file

@ -100,6 +100,7 @@ class Device extends AbstractPartsContainingDBElement
/** @var DeviceParameter[]
* @ORM\OneToMany(targetEntity="App\Entity\Parameters\DeviceParameter", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
* @ORM\OrderBy({"group" = "ASC" ,"name" = "ASC"})
*/
protected $parameters;

View file

@ -28,6 +28,7 @@ use App\Entity\Base\AbstractNamedDBElement;
use Doctrine\ORM\Mapping as ORM;
use InvalidArgumentException;
use LogicException;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
/**
@ -211,6 +212,26 @@ abstract class AbstractParameter extends AbstractNamedDBElement
return $this;
}
/**
* Returns the name of the group this parameter is associated to (e.g. Technical Parameters)
* @return string
*/
public function getGroup(): string
{
return $this->group;
}
/**
* Sets the name of the group this parameter is associated to.
* @param string $group
* @return $this
*/
public function setGroup(string $group): self
{
$this->group = $group;
return $this;
}
/**
* Returns the mathematical symbol for this specification (e.g. "V_CB").
*

View file

@ -25,9 +25,11 @@ namespace App\Entity\Parameters;
use App\Entity\Attachments\AttachmentType;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @ORM\Entity()
* @UniqueEntity(fields={"name", "group", "element"})
*/
class AttachmentTypeParameter extends AbstractParameter
{

View file

@ -25,9 +25,11 @@ namespace App\Entity\Parameters;
use App\Entity\Parts\Category;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @ORM\Entity()
* @UniqueEntity(fields={"name", "group", "element"})
*/
class CategoryParameter extends AbstractParameter
{

View file

@ -25,11 +25,13 @@ namespace App\Entity\Parameters;
use App\Entity\PriceInformations\Currency;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* A attachment attached to a category element.
*
* @ORM\Entity()
* @UniqueEntity(fields={"name", "group", "element"})
*/
class CurrencyParameter extends AbstractParameter
{

View file

@ -25,9 +25,11 @@ namespace App\Entity\Parameters;
use App\Entity\Devices\Device;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @ORM\Entity()
* @UniqueEntity(fields={"name", "group", "element"})
*/
class DeviceParameter extends AbstractParameter
{

View file

@ -25,9 +25,11 @@ namespace App\Entity\Parameters;
use App\Entity\Parts\Footprint;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @ORM\Entity()
* @UniqueEntity(fields={"name", "group", "element"})
*/
class FootprintParameter extends AbstractParameter
{

View file

@ -25,9 +25,11 @@ namespace App\Entity\Parameters;
use App\Entity\UserSystem\Group;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @ORM\Entity()
* @UniqueEntity(fields={"name", "group", "element"})
*/
class GroupParameter extends AbstractParameter
{

View file

@ -25,9 +25,11 @@ namespace App\Entity\Parameters;
use App\Entity\Parts\Manufacturer;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @ORM\Entity()
* @UniqueEntity(fields={"name", "group", "element"})
*/
class ManufacturerParameter extends AbstractParameter
{

View file

@ -25,9 +25,11 @@ namespace App\Entity\Parameters;
use App\Entity\Parts\MeasurementUnit;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @ORM\Entity()
* @UniqueEntity(fields={"name", "group", "element"})
*/
class MeasurementUnitParameter extends AbstractParameter
{

View file

@ -65,4 +65,14 @@ trait ParametersTrait
return $this;
}
public function getGroupedParameters(): array
{
$tmp = [];
foreach ($this->parameters as $parameter) {
$tmp[$parameter->getGroup()][] = $parameter;
}
return $tmp;
}
}

View file

@ -25,9 +25,11 @@ namespace App\Entity\Parameters;
use App\Entity\Parts\Part;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @ORM\Entity()
* @UniqueEntity(fields={"name", "group", "element"})
*/
class PartParameter extends AbstractParameter
{

View file

@ -25,9 +25,11 @@ namespace App\Entity\Parameters;
use App\Entity\Parts\Storelocation;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @ORM\Entity()
* @UniqueEntity(fields={"name", "group", "element"})
*/
class StorelocationParameter extends AbstractParameter
{

View file

@ -25,9 +25,11 @@ namespace App\Entity\Parameters;
use App\Entity\Parts\Supplier;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @ORM\Entity()
* @UniqueEntity(fields={"name", "group", "element"})
*/
class SupplierParameter extends AbstractParameter
{

View file

@ -109,6 +109,7 @@ class Category extends AbstractPartsContainingDBElement
/** @var CategoryParameter[]
* @ORM\OneToMany(targetEntity="App\Entity\Parameters\CategoryParameter", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
* @ORM\OrderBy({"group" = "ASC" ,"name" = "ASC"})
* @Assert\Valid()
*/
protected $parameters;

View file

@ -96,6 +96,7 @@ class Footprint extends AbstractPartsContainingDBElement
/** @var FootprintParameter[]
* @ORM\OneToMany(targetEntity="App\Entity\Parameters\FootprintParameter", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
* @ORM\OrderBy({"group" = "ASC" ,"name" = "ASC"})@ORM\OrderBy({"group" = "ASC" ,"name" = "ASC"})
* @Assert\Valid()
*/
protected $parameters;

View file

@ -89,6 +89,7 @@ class Manufacturer extends AbstractCompany
/** @var ManufacturerParameter[]
* @ORM\OneToMany(targetEntity="App\Entity\Parameters\ManufacturerParameter", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
* @ORM\OrderBy({"group" = "ASC" ,"name" = "ASC"})
* @Assert\Valid()
*/
protected $parameters;

View file

@ -106,6 +106,7 @@ class MeasurementUnit extends AbstractPartsContainingDBElement
/** @var MeasurementUnitParameter[]
* @ORM\OneToMany(targetEntity="App\Entity\Parameters\MeasurementUnitParameter", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
* @ORM\OrderBy({"group" = "ASC" ,"name" = "ASC"})
* @Assert\Valid()
*/
protected $parameters;

View file

@ -93,6 +93,8 @@ class Part extends AttachmentContainingDBElement
/** @var PartParameter[]
* @Assert\Valid()
* @ORM\OneToMany(targetEntity="App\Entity\Parameters\PartParameter", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
* @ORM\OrderBy({"group" = "ASC" ,"name" = "ASC"})
* @ORM\OrderBy({"group" = "ASC" ,"name" = "ASC"})
*/
protected $parameters;

View file

@ -94,6 +94,7 @@ class Storelocation extends AbstractPartsContainingDBElement
/** @var StorelocationParameter[]
* @ORM\OneToMany(targetEntity="App\Entity\Parameters\StorelocationParameter", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
* @ORM\OrderBy({"group" = "ASC" ,"name" = "ASC"})
* @Assert\Valid()
*/
protected $parameters;

View file

@ -116,6 +116,7 @@ class Supplier extends AbstractCompany
/** @var SupplierParameter[]
* @ORM\OneToMany(targetEntity="App\Entity\Parameters\SupplierParameter", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
* @ORM\OrderBy({"group" = "ASC" ,"name" = "ASC"})
* @Assert\Valid()
*/
protected $parameters;

View file

@ -96,6 +96,7 @@ class Currency extends AbstractStructuralDBElement
/** @var CurrencyParameter[]
* @ORM\OneToMany(targetEntity="App\Entity\Parameters\CurrencyParameter", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
* @ORM\OrderBy({"group" = "ASC" ,"name" = "ASC"})
* @Assert\Valid()
*/
protected $parameters;

View file

@ -95,6 +95,7 @@ class Group extends AbstractStructuralDBElement implements HasPermissionsInterfa
/** @var GroupParameter[]
* @ORM\OneToMany(targetEntity="App\Entity\Parameters\GroupParameter", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
* @ORM\OrderBy({"group" = "ASC" ,"name" = "ASC"})
* @Assert\Valid()
*/
protected $parameters;

View file

@ -47,7 +47,7 @@ class ParameterType extends AbstractType
'attr' => [
'placeholder' => 'parameters.symbol.placeholder',
'class' => 'form-control-sm',
'style' => 'max-width: 15ch;',
'style' => 'max-width: 12ch;',
],
]);
$builder->add('value_text', TextType::class, [
@ -66,7 +66,7 @@ class ParameterType extends AbstractType
'step' => 'any',
'placeholder' => 'parameters.max.placeholder',
'class' => 'form-control-sm',
'style' => 'max-width: 15ch;',
'style' => 'max-width: 12ch;',
],
]);
$builder->add('value_min', NumberType::class, [
@ -76,7 +76,7 @@ class ParameterType extends AbstractType
'step' => 'any',
'placeholder' => 'parameters.min.placeholder',
'class' => 'form-control-sm',
'style' => 'max-width: 15ch;',
'style' => 'max-width: 12ch;',
],
]);
$builder->add('value_typical', NumberType::class, [
@ -86,7 +86,7 @@ class ParameterType extends AbstractType
'step' => 'any',
'placeholder' => 'parameters.typical.placeholder',
'class' => 'form-control-sm',
'style' => 'max-width: 15ch;',
'style' => 'max-width: 12ch;',
],
]);
$builder->add('unit', TextType::class, [
@ -98,12 +98,21 @@ class ParameterType extends AbstractType
'style' => 'max-width: 8ch;',
],
]);
$builder->add('group', TextType::class, [
'required' => false,
'empty_data' => '',
'attr' => [
'placeholder' => 'parameter.group.placeholder',
'class' => 'form-control-sm',
]
]);
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => AbstractParameter::class,
]);
'data_class' => AbstractParameter::class,
]);
}
}

View file

@ -52,6 +52,7 @@ use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\Part;
use App\Entity\PriceInformations\Orderdetail;
use App\Form\AttachmentFormType;
use App\Form\ParameterGroupType;
use App\Form\ParameterType;
use App\Form\Type\MasterPictureAttachmentType;
use App\Form\Type\SIUnitType;

View file

@ -10,6 +10,7 @@
<th>{% trans %}specifications.value_max{% endtrans %}</th>
<th>{% trans %}specifications.unit{% endtrans %}</th>
<th>{% trans %}specifications.text{% endtrans %}</th>
<th>{% trans %}specifications.group{% endtrans %}</th>
<th></th>
</tr>
</thead>

View file

@ -73,6 +73,7 @@
<td>{{ form_widget(form.value_max) }}{{ form_errors(form.value_max) }}</td>
<td>{{ form_widget(form.unit) }}{{ form_errors(form.unit) }}</td>
<td>{{ form_widget(form.value_text) }}{{ form_errors(form.value_text) }}</td>
<td>{{ form_widget(form.group) }}{{ form_errors(form.group) }}</td>
<td>
<button type="button" class="btn btn-danger btn-sm order_btn_delete" onclick="delete_specification_entry(this);" title="{% trans %}orderdetail.delete{% endtrans %}">
<i class="fas fa-trash-alt fa-fw"></i>

View file

@ -1,18 +1,7 @@
{# var \App\Entity\Parts\Part part #}
{% import "helper.twig" as helper %}
<table class="table table-hover table-striped table-sm">
<thead>
<tr>
<th>{% trans %}specifications.property{% endtrans %}</th>
<th>{% trans %}specifications.value{% endtrans %}</th>
</tr>
</thead>
<tbody>
{% for param in part.parameters %}
<tr>
<td>{{ param.name }} {% if param.symbol is not empty %}<span class="latex">${{ param.symbol }}$</span>{% endif %}</td>
<td>{{ param.formattedValue }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% for name, parameters in part.groupedParameters %}
{% if name is not empty %}<h5 class="mt-1">{{ name }}</h5>{% endif %}
{{ helper.parameters_table(parameters) }}
{% endfor %}

View file

@ -111,4 +111,23 @@
{% endif %}
{% endif %}
{% endif %}
{% endmacro %}
{% endmacro %}
{% macro parameters_table(parameters) %}
<table class="table table-hover table-striped table-sm">
<thead>
<tr>
<th>{% trans %}specifications.property{% endtrans %}</th>
<th>{% trans %}specifications.value{% endtrans %}</th>
</tr>
</thead>
<tbody>
{% for param in parameters %}
<tr>
<td>{{ param.name }} {% if param.symbol is not empty %}<span class="latex">${{ param.symbol }}$</span>{% endif %}</td>
<td>{{ param.formattedValue }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endmacro parameters_table %}

View file

@ -7994,5 +7994,11 @@ Element 3</target>
<target>Text</target>
</segment>
</unit>
<unit id="t9lgp3U" name="specifications.group">
<segment>
<source>specifications.group</source>
<target>Group</target>
</segment>
</unit>
</file>
</xliff>