Allow to edit parameters for data structures.

This commit is contained in:
Jan Böhmer 2020-03-24 21:49:09 +01:00
parent 4c63c88021
commit ff05868051
16 changed files with 118 additions and 10 deletions

View file

@ -44,6 +44,7 @@ namespace App\Controller\AdminPages;
use App\Entity\Attachments\AttachmentType;
use App\Entity\Attachments\AttachmentTypeAttachment;
use App\Entity\Parameters\AttachmentTypeParameter;
use App\Form\AdminPages\AttachmentTypeAdminForm;
use App\Services\EntityExporter;
use App\Services\EntityImporter;
@ -64,6 +65,7 @@ class AttachmentTypeController extends BaseAdminController
protected $form_class = AttachmentTypeAdminForm::class;
protected $route_base = 'attachment_type';
protected $attachment_class = AttachmentTypeAttachment::class;
protected $parameter_class = AttachmentTypeParameter::class;
/**
* @Route("/{id}", name="attachment_type_delete", methods={"DELETE"})

View file

@ -77,6 +77,7 @@ abstract class BaseAdminController extends AbstractController
protected $twig_template = '';
protected $route_base = '';
protected $attachment_class = '';
protected $parameter_class = '';
protected $passwordEncoder;
protected $translator;
@ -101,6 +102,10 @@ abstract class BaseAdminController extends AbstractController
throw new InvalidArgumentException('You have to override the $attachment_class value in your subclass!');
}
if ('' === $this->parameter_class) {
throw new InvalidArgumentException('You have to override the $parameter_class value in your subclass!');
}
$this->translator = $translator;
$this->passwordEncoder = $passwordEncoder;
$this->attachmentHelper = $attachmentHelper;
@ -149,6 +154,7 @@ abstract class BaseAdminController extends AbstractController
$form = $this->createForm($this->form_class, $entity, [
'attachment_class' => $this->attachment_class,
'parameter_class' => $this->parameter_class,
'disabled' => null !== $timeTravel_timestamp ? true : null,
]);
@ -189,7 +195,10 @@ abstract class BaseAdminController extends AbstractController
//Rebuild form, so it is based on the updated data. Important for the parent field!
//We can not use dynamic form events here, because the parent entity list is build from database!
$form = $this->createForm($this->form_class, $entity, ['attachment_class' => $this->attachment_class]);
$form = $this->createForm($this->form_class, $entity, [
'attachment_class' => $this->attachment_class,
'parameter_class' => $this->parameter_class
]);
} elseif ($form->isSubmitted() && ! $form->isValid()) {
$this->addFlash('error', 'entity.edit_flash.invalid');
}
@ -212,7 +221,10 @@ abstract class BaseAdminController extends AbstractController
$this->denyAccessUnlessGranted('read', $new_entity);
//Basic edit form
$form = $this->createForm($this->form_class, $new_entity, ['attachment_class' => $this->attachment_class]);
$form = $this->createForm($this->form_class, $new_entity, [
'attachment_class' => $this->attachment_class,
'parameter_class' => $this->parameter_class,
]);
$form->handleRequest($request);

View file

@ -43,6 +43,7 @@ declare(strict_types=1);
namespace App\Controller\AdminPages;
use App\Entity\Attachments\CategoryAttachment;
use App\Entity\Parameters\CategoryParameter;
use App\Entity\Parts\Category;
use App\Form\AdminPages\CategoryAdminForm;
use App\Services\EntityExporter;
@ -64,6 +65,7 @@ class CategoryController extends BaseAdminController
protected $form_class = CategoryAdminForm::class;
protected $route_base = 'category';
protected $attachment_class = CategoryAttachment::class;
protected $parameter_class = CategoryParameter::class;
/**
* @Route("/{id}", name="category_delete", methods={"DELETE"})

View file

@ -43,6 +43,7 @@ declare(strict_types=1);
namespace App\Controller\AdminPages;
use App\Entity\Attachments\CurrencyAttachment;
use App\Entity\Parameters\CurrencyParameter;
use App\Entity\PriceInformations\Currency;
use App\Form\AdminPages\CurrencyAdminForm;
use App\Services\EntityExporter;
@ -66,6 +67,7 @@ class CurrencyController extends BaseAdminController
protected $form_class = CurrencyAdminForm::class;
protected $route_base = 'currency';
protected $attachment_class = CurrencyAttachment::class;
protected $parameter_class = CurrencyParameter::class;
/**
* @Route("/{id}", name="currency_delete", methods={"DELETE"})

View file

@ -44,6 +44,7 @@ namespace App\Controller\AdminPages;
use App\Entity\Attachments\DeviceAttachment;
use App\Entity\Devices\Device;
use App\Entity\Parameters\DeviceParameter;
use App\Form\AdminPages\BaseEntityAdminForm;
use App\Services\EntityExporter;
use App\Services\EntityImporter;
@ -64,6 +65,7 @@ class DeviceController extends BaseAdminController
protected $form_class = BaseEntityAdminForm::class;
protected $route_base = 'device';
protected $attachment_class = DeviceAttachment::class;
protected $parameter_class = DeviceParameter::class;
/**
* @Route("/{id}", name="device_delete", methods={"DELETE"})

View file

@ -44,6 +44,7 @@ namespace App\Controller\AdminPages;
use App\Entity\Attachments\AttachmentType;
use App\Entity\Attachments\FootprintAttachment;
use App\Entity\Parameters\FootprintParameter;
use App\Entity\Parts\Footprint;
use App\Form\AdminPages\FootprintAdminForm;
use App\Services\EntityExporter;
@ -64,6 +65,7 @@ class FootprintController extends BaseAdminController
protected $form_class = FootprintAdminForm::class;
protected $route_base = 'footprint';
protected $attachment_class = FootprintAttachment::class;
protected $parameter_class = FootprintParameter::class;
/**
* @Route("/{id}", name="footprint_delete", methods={"DELETE"})

View file

@ -43,6 +43,7 @@ declare(strict_types=1);
namespace App\Controller\AdminPages;
use App\Entity\Attachments\ManufacturerAttachment;
use App\Entity\Parameters\ManufacturerParameter;
use App\Entity\Parts\Manufacturer;
use App\Form\AdminPages\CompanyForm;
use App\Services\EntityExporter;
@ -63,6 +64,7 @@ class ManufacturerController extends BaseAdminController
protected $form_class = CompanyForm::class;
protected $route_base = 'manufacturer';
protected $attachment_class = ManufacturerAttachment::class;
protected $parameter_class = ManufacturerParameter::class;
/**
* @Route("/{id}", name="manufacturer_delete", methods={"DELETE"})

View file

@ -44,6 +44,7 @@ namespace App\Controller\AdminPages;
use App\Entity\Attachments\AttachmentType;
use App\Entity\Attachments\MeasurementUnitAttachment;
use App\Entity\Parameters\MeasurementUnitParameter;
use App\Entity\Parts\MeasurementUnit;
use App\Form\AdminPages\MeasurementUnitAdminForm;
use App\Services\EntityExporter;
@ -64,6 +65,7 @@ class MeasurementUnitController extends BaseAdminController
protected $form_class = MeasurementUnitAdminForm::class;
protected $route_base = 'measurement_unit';
protected $attachment_class = MeasurementUnitAttachment::class;
protected $parameter_class = MeasurementUnitParameter::class;
/**
* @Route("/{id}", name="measurement_unit_delete", methods={"DELETE"})

View file

@ -42,6 +42,7 @@ declare(strict_types=1);
namespace App\Controller\AdminPages;
use App\Entity\Parameters\StorelocationParameter;
use App\Entity\Parts\Storelocation;
use App\Form\AdminPages\StorelocationAdminForm;
use App\Services\EntityExporter;
@ -62,6 +63,7 @@ class StorelocationController extends BaseAdminController
protected $form_class = StorelocationAdminForm::class;
protected $route_base = 'store_location';
protected $attachment_class = StorelocationAdminForm::class;
protected $parameter_class = StorelocationParameter::class;
/**
* @Route("/{id}", name="store_location_delete", methods={"DELETE"})

View file

@ -43,6 +43,7 @@ declare(strict_types=1);
namespace App\Controller\AdminPages;
use App\Entity\Attachments\SupplierAttachment;
use App\Entity\Parameters\SupplierParameter;
use App\Entity\Parts\Supplier;
use App\Form\AdminPages\SupplierForm;
use App\Services\EntityExporter;
@ -63,6 +64,7 @@ class SupplierController extends BaseAdminController
protected $form_class = SupplierForm::class;
protected $route_base = 'supplier';
protected $attachment_class = SupplierAttachment::class;
protected $parameter_class = SupplierParameter::class;
/**
* @Route("/{id}", name="supplier_delete", methods={"DELETE"})

View file

@ -43,6 +43,7 @@ declare(strict_types=1);
namespace App\Controller;
use App\Entity\Attachments\UserAttachment;
use App\Entity\Parameters\PartParameter;
use App\Entity\UserSystem\User;
use App\Form\Permissions\PermissionsType;
use App\Form\UserAdminForm;
@ -67,6 +68,8 @@ class UserController extends AdminPages\BaseAdminController
protected $form_class = UserAdminForm::class;
protected $route_base = 'user';
protected $attachment_class = UserAttachment::class;
//Just define a value here to prevent error. It is not used.
protected $parameter_class = "not used";
/**
* @Route("/{id}/edit/{timestamp}", requirements={"id"="\d+"}, name="user_edit")

View file

@ -45,7 +45,9 @@ namespace App\Form\AdminPages;
use App\Entity\Attachments\Attachment;
use App\Entity\Base\AbstractNamedDBElement;
use App\Entity\Base\AbstractStructuralDBElement;
use App\Entity\Parameters\PartParameter;
use App\Form\AttachmentFormType;
use App\Form\ParameterType;
use App\Form\Type\MasterPictureAttachmentType;
use App\Form\Type\StructuralEntityType;
use FOS\CKEditorBundle\Form\Type\CKEditorType;
@ -74,8 +76,9 @@ class BaseEntityAdminForm extends AbstractType
public function configureOptions(OptionsResolver $resolver): void
{
parent::configureOptions($resolver); // TODO: Change the autogenerated stub
parent::configureOptions($resolver);
$resolver->setRequired('attachment_class');
$resolver->setRequired('parameter_class');
}
public function buildForm(FormBuilderInterface $builder, array $options): void
@ -151,6 +154,18 @@ class BaseEntityAdminForm extends AbstractType
'empty_data' => null,
]);
$builder->add('parameters', CollectionType::class, [
'entry_type' => ParameterType::class,
'allow_add' => true,
'allow_delete' => true,
'label' => false,
'by_reference' => false,
'prototype_data' => new $options['parameter_class'],
'entry_options' => [
'data_class' => $options['parameter_class'],
],
]);
//Buttons
$builder->add('save', SubmitType::class, [
'label' => $is_new ? 'entity.create' : 'entity.edit.save',

View file

@ -79,6 +79,7 @@ class UserAdminForm extends AbstractType
{
parent::configureOptions($resolver); // TODO: Change the autogenerated stub
$resolver->setRequired('attachment_class');
$resolver->setDefault('parameter_class', false);
}
public function buildForm(FormBuilderInterface $builder, array $options): void

View file

@ -85,6 +85,11 @@
<li class="nav-item">
<a data-toggle="tab" class="nav-link link-anchor" href="#attachments">{% trans %}admin.attachments{% endtrans %}</a>
</li>
{% if entity.parameters is defined %}
<li class="nav-item">
<a data-toggle="tab" class="nav-link link-anchor" href="#parameters">{% trans %}admin.parameters{% endtrans %}</a>
</li>
{% endif %}
</ul>
<!-- Tab panes -->
@ -113,6 +118,12 @@
{{ form_row(form.master_picture_attachment) }}
{% endblock %}
</div>
{% if entity.parameters is defined %}
<div id="parameters" class="tab-pane fade">
{% include "AdminPages/_parameters.html.twig" %}
</div>
{% endif %}
</div>
<div class="form-group row">
@ -176,13 +187,7 @@
{% endif %}
</div>
</fieldset>
</div>

View file

@ -0,0 +1,54 @@
{% form_theme form with ['Parts/edit/edit_form_styles.html.twig', "bootstrap_4_layout.html.twig"] %}
<table class="table table-striped table-sm table-bordered table-responsive-md" id="specifications_table" data-prototype="{% if form.parameters.vars.prototype is defined %}{{ form_widget(form.parameters.vars.prototype)|e('html_attr') }}{% endif %}">
<thead>
<tr>
<th>{% trans %}specifications.property{% endtrans %}</th>
<th>{% trans %}specifications.symbol{% endtrans %}</th>
<th>{% trans %}specifications.value_min{% endtrans %}</th>
<th>{% trans %}specifications.value_typ{% endtrans %}</th>
<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>
<tbody>
{% for param in form.parameters %}
{{ form_widget(param) }}
{% endfor %}
</tbody>
</table>
<button type="button" class="btn btn-success mb-2" onclick="create_specification_entry(this)" {% if not is_granted('edit', entity) %}disabled{% endif %}>
<i class="fas fa-plus-square fa-fw"></i>
{% trans %}specification.create{% endtrans %}
</button>
<script>
function delete_specification_entry(btn) {
window.bootbox.confirm('{% trans %}parameter.delete.confirm{% endtrans %}', function (result) {
if(result) {
$(btn).closest("tr").remove();
}
});
}
function create_specification_entry(btn) {
//Determine the table, so we can determine, how many entries there are already.
$holder = $(btn).siblings("table");
var index = $holder.find(":input").length;
var newForm = $holder.data("prototype");
//Increase the index
newForm = newForm.replace(/__name__/g, index);
$holder.children("tbody").append(newForm);
//Reinit the selectpickers
//$(".selectpicker").selectpicker();
}
</script>

View file

@ -28,7 +28,7 @@
<script>
function delete_specification_entry(btn) {
window.bootbox.confirm('{% trans %}pricedetails.edit.delete.confirm{% endtrans %}', function (result) {
window.bootbox.confirm('{% trans %}parameter.delete.confirm{% endtrans %}', function (result) {
if(result) {
$(btn).closest("tr").remove();
}