Added an option for mass creation of structured data.

This commit is contained in:
Jan Böhmer 2019-08-12 22:41:58 +02:00
parent 51be176418
commit 87e6f641c3
18 changed files with 177 additions and 24 deletions

View file

@ -0,0 +1,95 @@
<?php
/**
*
* part-db version 0.1
* Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/
*
* part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php)
* http://code.google.com/p/part-db/
*
* Part-DB Version 0.4+
* Copyright (C) 2016 - 2019 Jan Böhmer
* https://github.com/jbtronics
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Form\AdminPages;
use App\Entity\Base\NamedDBElement;
use App\Entity\Base\StructuralDBElement;
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\ResetType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Security\Core\Security;
class BaseEntityAdminForm extends AbstractType
{
protected $security;
public function __construct(Security $security)
{
$this->security = $security;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
/** @var StructuralDBElement $entity */
$entity = $options['data'];
$is_new = $entity->getID() === null;
$builder
->add('name', TextType::class, ['empty_data' => '', 'label' => 'name.label',
'attr' => ['placeholder' => 'part.name.placeholder'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ])
->add('parent', EntityType::class, ['class' => get_class($entity), 'choice_label' => 'full_path',
'attr' => ['class' => 'selectpicker', 'data-live-search' => true], 'required' => false, 'label' => 'parent.label',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity), ])
->add('not_selectable', CheckboxType::class, ['required' => false,
'label' => 'not_selectable.label', 'help' => 'not_selectable.help', 'label_attr'=> ['class' => 'checkbox-custom'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity) ])
->add('comment', CKEditorType::class, ['required' => false,
'label' => 'comment.label', 'attr' => ['rows' => 4], 'help' => 'bbcode.hint',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)]);
$this->additionalFormElements($builder, $options, $entity);
//Buttons
$builder->add('save', SubmitType::class, ['label' => $is_new ? 'entity.create' : 'entity.edit.save',
'attr' => ['class' => $is_new ? 'btn-success' : ''],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)])
->add('reset', ResetType::class, ['label' => 'entity.edit.reset',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)]);
}
protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity)
{
//Empty for Base
}
}

View file

@ -0,0 +1,79 @@
<?php
/**
*
* part-db version 0.1
* Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/
*
* part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php)
* http://code.google.com/p/part-db/
*
* Part-DB Version 0.4+
* Copyright (C) 2016 - 2019 Jan Böhmer
* https://github.com/jbtronics
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Form\AdminPages;
use App\Entity\Base\NamedDBElement;
use App\Form\AdminPages\BaseEntityAdminForm;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
class CategoryAdminForm extends BaseEntityAdminForm
{
protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity)
{
$is_new = $entity->getID() === null;
$builder->add('disable_footprints', CheckboxType::class, ['required' => false,
'label' => 'disable_footprints.label', 'help' => 'disable_footprints.help', 'label_attr'=> ['class' => 'checkbox-custom'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)]);
$builder->add('disable_manufacturers', CheckboxType::class, ['required' => false,
'label' => 'disable_manufacturers.label', 'help' => 'disable_manufacturers.help', 'label_attr'=> ['class' => 'checkbox-custom'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)]);
$builder->add('disable_autodatasheets', CheckboxType::class, ['required' => false,
'label' => 'disable_autodatasheets.label', 'help' => 'disable_autodatasheets.help', 'label_attr'=> ['class' => 'checkbox-custom'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)]);
$builder->add('disable_properties', CheckboxType::class, ['required' => false,
'label' => 'disable_properties.label', 'help' => 'disable_properties.help', 'label_attr'=> ['class' => 'checkbox-custom'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)]);
$builder->add('partname_hint', TextType::class, ['required' => false, 'empty_data' => '',
'label' => 'disable_manufacturers.label', 'attr' => ['placeholder' => 'disable_manufacturers.placeholder'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)]);
$builder->add('partname_regex', TextType::class, ['required' => false, 'empty_data' => '',
'label' => 'partname_regex.label', 'attr' => ['placeholder' => 'partname_regex.placeholder'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)]);
$builder->add('default_description', TextType::class, ['required' => false, 'empty_data' => '',
'label' => 'default_description.label', 'attr' => ['placeholder' => 'default_description.placeholder'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)]);
$builder->add('default_comment', TextType::class, ['required' => false, 'empty_data' => '',
'label' => 'default_description.label', 'attr' => ['placeholder' => 'default_comment.placeholder'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)]);
}
}

View file

@ -0,0 +1,87 @@
<?php
/**
*
* part-db version 0.1
* Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/
*
* part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php)
* http://code.google.com/p/part-db/
*
* Part-DB Version 0.4+
* Copyright (C) 2016 - 2019 Jan Böhmer
* https://github.com/jbtronics
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Form\AdminPages;
use App\Entity\Base\NamedDBElement;
use App\Form\AdminPages\BaseEntityAdminForm;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TelType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\UrlType;
use Symfony\Component\Form\FormBuilderInterface;
class CompanyForm extends BaseEntityAdminForm
{
protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity)
{
$is_new = $entity->getID() === null;
$builder->add('address', TextareaType::class, ['label' => 'company.address.label',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'attr' => ['placeholder' => 'company.address.placeholder'], 'required' => false,
'empty_data' => ''
]);
$builder->add('phone_number', TelType::class, ['label' => 'company.phone_number.label',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'attr' => ['placeholder' => 'company.phone_number.placeholder'], 'required' => false,
'empty_data' => ''
]);
$builder->add('fax_number', TelType::class, ['label' => 'company.fax_number.label',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'attr' => ['placeholder' => 'company.fax_number.placeholder'], 'required' => false,
'empty_data' => ''
]);
$builder->add('email_address', EmailType::class, ['label' => 'company.email.label',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'attr' => ['placeholder' => 'company.email.placeholder'], 'required' => false,
'empty_data' => ''
]);
$builder->add('website', UrlType::class, ['label' => 'company.website.label',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'attr' => ['placeholder' => 'company.website.placeholder'], 'required' => false,
'empty_data' => ''
]);
$builder->add('auto_product_url', UrlType::class, ['label' => 'company.auto_product_url.label',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'attr' => ['placeholder' => 'company.auto_product_url.placeholder'], 'required' => false,
'empty_data' => ''
]);
}
}

View file

@ -0,0 +1,92 @@
<?php
/**
*
* part-db version 0.1
* Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/
*
* part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php)
* http://code.google.com/p/part-db/
*
* Part-DB Version 0.4+
* Copyright (C) 2016 - 2019 Jan Böhmer
* https://github.com/jbtronics
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Form\AdminPages;
use App\Entity\Base\StructuralDBElement;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Bundle\MakerBundle\Str;
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\FileType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Security\Core\Security;
class ImportType extends AbstractType
{
protected $security;
public function __construct(Security $security)
{
$this->security = $security;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$data = $options['data'];
//Disable import if user is not allowed to create elements.
$entity = new $data['entity_class'];
$perm_name = "create";
$disabled = ! $this->security->isGranted($perm_name, $entity);
$builder
->add('format', ChoiceType::class, ['choices' =>
['JSON' => 'json', 'XML' => 'xml','CSV'=>'csv' ,'YAML' => 'yaml'], 'label' => 'export.format',
'disabled' => $disabled])
->add('csv_separator', TextType::class, ['data' => ';', 'label' => 'import.csv_separator',
'disabled' => $disabled]);
if($entity instanceof StructuralDBElement) {
$builder->
add('parent', EntityType::class, ['class' => $data['entity_class'], 'choice_label' => 'full_path',
'attr' => ['class' => 'selectpicker', 'data-live-search' => true], 'required' => false,
'label' => 'parent.label', 'disabled' => $disabled]);
}
$builder->add('file', FileType::class, ['label' => 'import.file',
'attr' => ['class' => 'file', 'data-show-preview' => 'false', 'data-show-upload' => 'false'], 'disabled' => $disabled])
->add('preserve_children', CheckboxType::class, ['data' => true, 'required' => false,
'label' => 'import.preserve_children', 'label_attr'=> ['class' => 'checkbox-custom'], 'disabled' => $disabled])
->add('abort_on_validation_error', CheckboxType::class, ['data' => true, 'required' => false,
'label' => 'import.abort_on_validation', 'help'=> 'import.abort_on_validation.help',
'label_attr'=> ['class' => 'checkbox-custom'], 'disabled' => $disabled])
//Buttons
->add('import', SubmitType::class, ['label' => 'import.btn', 'disabled' => $disabled]);
}
}

View file

@ -0,0 +1,81 @@
<?php
/**
*
* part-db version 0.1
* Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/
*
* part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php)
* http://code.google.com/p/part-db/
*
* Part-DB Version 0.4+
* Copyright (C) 2016 - 2019 Jan Böhmer
* https://github.com/jbtronics
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Form\AdminPages;
use App\Entity\Base\StructuralDBElement;
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\FileType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Security\Core\Security;
class MassCreationForm extends AbstractType
{
protected $security;
public function __construct(Security $security)
{
$this->security = $security;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$data = $options['data'];
//Disable import if user is not allowed to create elements.
$entity = new $data['entity_class']();
$perm_name = "create";
$disabled = ! $this->security->isGranted($perm_name, $entity);
$builder
->add('lines', TextareaType::class, ['data' => '', 'label' => 'mass_creation.lines',
'disabled' => $disabled, 'required' => true,
'attr' => ['placeholder' => 'mass_creation.lines.placeholder', 'rows' => 10]]);
if ($entity instanceof StructuralDBElement) {
$builder->
add('parent', EntityType::class, ['class' => $data['entity_class'], 'choice_label' => 'full_path',
'attr' => ['class' => 'selectpicker', 'data-live-search' => true], 'required' => false,
'label' => 'parent.label', 'disabled' => $disabled]);
}
$builder
//Buttons
->add('create', SubmitType::class, ['label' => 'mass_creation.btn', 'disabled' => $disabled]);
}
}

View file

@ -0,0 +1,51 @@
<?php
/**
*
* part-db version 0.1
* Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/
*
* part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php)
* http://code.google.com/p/part-db/
*
* Part-DB Version 0.4+
* Copyright (C) 2016 - 2019 Jan Böhmer
* https://github.com/jbtronics
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Form\AdminPages;
use App\Entity\Base\NamedDBElement;
use App\Form\AdminPages\BaseEntityAdminForm;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
class StorelocationAdminForm extends BaseEntityAdminForm
{
protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity)
{
$is_new = $entity->getID() === null;
$builder->add('is_full', CheckboxType::class, ['required' => false,
'label' => 'is_full.label', 'help' => 'is_full.help', 'label_attr'=> ['class' => 'checkbox-custom'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity)]);
}
}