Added basic admin page for Label profiles.

This commit is contained in:
Jan Böhmer 2020-04-11 17:34:01 +02:00
parent b23dec0262
commit a8a92b9c5d
20 changed files with 1688 additions and 857 deletions

View file

@ -17,7 +17,9 @@ fos_ck_editor:
extraPlugins: "markdown" extraPlugins: "markdown"
height: 60 height: 60
toolbar: description_toolbar toolbar: description_toolbar
label_config:
height: 100
toolbar: config_toolbar
plugins: plugins:
bbcode: bbcode:
@ -33,6 +35,13 @@ fos_ck_editor:
toolbars: toolbars:
configs: configs:
config_toolbar:
- [ 'Bold', 'Italic', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat' ]
- ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock']
- ["SpecialChar"]
- ["Source"]
- "/"
- ['Format', 'FontSize' ]
description_toolbar: description_toolbar:
- [ 'Bold', 'Italic', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat' ] - [ 'Bold', 'Italic', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat' ]
- ["SpecialChar"] - ["SpecialChar"]

View file

@ -0,0 +1,126 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2020 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 Affero General Public License as published
* by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 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\Controller\AdminPages;
use App\Entity\Attachments\AttachmentType;
use App\Entity\Attachments\AttachmentTypeAttachment;
use App\Entity\Attachments\LabelAttachment;
use App\Entity\LabelSystem\LabelProfile;
use App\Entity\Parameters\AttachmentTypeParameter;
use App\Form\AdminPages\AttachmentTypeAdminForm;
use App\Form\AdminPages\BaseEntityAdminForm;
use App\Form\AdminPages\LabelProfileAdminForm;
use App\Services\EntityExporter;
use App\Services\EntityImporter;
use App\Services\StructuralElementRecursionHelper;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/label_profile")
*/
class LabelProfileController extends BaseAdminController
{
protected $entity_class = LabelProfile::class;
protected $twig_template = 'AdminPages/LabelProfileAdmin.html.twig';
protected $form_class = LabelProfileAdminForm::class;
protected $route_base = 'label_profile';
protected $attachment_class = LabelAttachment::class;
protected $parameter_class = 'not_used';
/**
* @Route("/{id}", name="label_profile_delete", methods={"DELETE"})
*
* @return RedirectResponse
*/
public function delete(Request $request, LabelProfile $entity, StructuralElementRecursionHelper $recursionHelper): RedirectResponse
{
return $this->_delete($request, $entity, $recursionHelper);
}
/**
* @Route("/{id}/edit/{timestamp}", requirements={"id"="\d+"}, name="label_profile_edit")
* @Route("/{id}", requirements={"id"="\d+"})
*
* @return Response
*/
public function edit(LabelProfile $entity, Request $request, EntityManagerInterface $em, ?string $timestamp = null): Response
{
return $this->_edit($entity, $request, $em, $timestamp);
}
/**
* @Route("/new", name="label_profile_new")
* @Route("/{id}/clone", name="label_profile_clone")
* @Route("/")
*
* @return Response
*/
public function new(Request $request, EntityManagerInterface $em, EntityImporter $importer, ?AttachmentType $entity = null): Response
{
return $this->_new($request, $em, $importer, $entity);
}
/**
* @Route("/export", name="label_profile_export_all")
*
* @return Response
*/
public function exportAll(EntityManagerInterface $em, EntityExporter $exporter, Request $request): Response
{
return $this->_exportAll($em, $exporter, $request);
}
/**
* @Route("/{id}/export", name="label_profile_export")
*
* @return Response
*/
public function exportEntity(LabelProfile $entity, EntityExporter $exporter, Request $request): Response
{
return $this->_exportEntity($entity, $exporter, $request);
}
}

View file

@ -43,7 +43,7 @@ use LogicException;
* "Footprint" = "FootprintAttachment", "Manufacturer" = "ManufacturerAttachment", * "Footprint" = "FootprintAttachment", "Manufacturer" = "ManufacturerAttachment",
* "Currency" = "CurrencyAttachment", "Group" = "GroupAttachment", * "Currency" = "CurrencyAttachment", "Group" = "GroupAttachment",
* "MeasurementUnit" = "MeasurementUnitAttachment", "Storelocation" = "StorelocationAttachment", * "MeasurementUnit" = "MeasurementUnitAttachment", "Storelocation" = "StorelocationAttachment",
* "Supplier" = "SupplierAttachment", "User" = "UserAttachment" * "Supplier" = "SupplierAttachment", "User" = "UserAttachment", "LabelProfile" = "LabelAttachment",
* }) * })
* @ORM\EntityListeners({"App\EntityListeners\AttachmentDeleteListener"}) * @ORM\EntityListeners({"App\EntityListeners\AttachmentDeleteListener"})
*/ */

View file

@ -0,0 +1,44 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2020 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 Affero General Public License as published
* by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace App\Entity\Attachments;
use App\Entity\LabelSystem\LabelProfile;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* A attachment attached to a user element.
*
* @ORM\Entity()
* @UniqueEntity({"name", "attachment_type", "element"})
*/
class LabelAttachment extends Attachment
{
public const ALLOWED_ELEMENT_CLASS = LabelProfile::class;
/**
* @var LabelProfile the element this attachment is associated with
* @ORM\ManyToOne(targetEntity="App\Entity\LabelSystem\LabelProfile", inversedBy="attachments")
* @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE").
*/
protected $element;
}

View file

@ -0,0 +1,262 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2020 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 Affero General Public License as published
* by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace App\Entity\LabelSystem;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Embeddable()
*/
class LabelOptions
{
public const BARCODE_TYPES = ['none', /*'ean8',*/ 'qr', 'code39'];
public const SUPPORTED_ELEMENTS = ['part'];
public const PICTURE_TYPES = ['none', 'element_picture', 'main_attachment'];
public const POSITIONS = ['left', 'right', 'top', 'bottom'];
public const FONTS = ['default'];
/**
* @var float The page size of the label in mm
* @Assert\Positive()
* @ORM\Column(type="float")
*/
protected $width = 50.0;
/**
* @var float The page size of the label in mm
* @Assert\Positive()
* @ORM\Column(type="float")
*/
protected $height = 30.0;
/**
* @var string The type of the barcode that should be used in the label (e.g. 'qr')
* @Assert\Choice(choices=LabelOptions::BARCODE_TYPES)
* @ORM\Column(type="string")
*/
protected $barcode_type = 'none';
/**
* @var string The position where the barcode should be put
* @Assert\Choice(choices=LabelOptions::POSITIONS)
* @ORM\Column(type="string")
*/
protected $barcode_position = 'left';
/**
* @var string What image should be shown along the
* @Assert\Choice(choices=LabelOptions::PICTURE_TYPES)
* @ORM\Column(type="string")
*/
protected $picture_type = 'none';
/**
* @var string
* @Assert\Choice(choices=LabelOptions::POSITIONS)
* @ORM\Column(type="string")
*/
protected $picture_position = 'left';
/**
* @var string
* @Assert\Choice(choices=LabelOptions::SUPPORTED_ELEMENTS)
* @ORM\Column(type="string")
*/
protected $supported_element = 'part';
/**
* @var string The font that should be used in the Barcode
* @ORM\Column(type="string")
*/
protected $font = 'default';
/**
* @var string
* @ORM\Column(type="text")
*/
protected $lines = '';
/**
* @return float
*/
public function getWidth(): float
{
return $this->width;
}
/**
* @param float $width
* @return LabelOptions
*/
public function setWidth(float $width): LabelOptions
{
$this->width = $width;
return $this;
}
/**
* @return float
*/
public function getHeight(): float
{
return $this->height;
}
/**
* @param float $height
* @return LabelOptions
*/
public function setHeight(float $height): LabelOptions
{
$this->height = $height;
return $this;
}
/**
* @return string
*/
public function getBarcodeType(): string
{
return $this->barcode_type;
}
/**
* @param string $barcode_type
* @return LabelOptions
*/
public function setBarcodeType(string $barcode_type): LabelOptions
{
$this->barcode_type = $barcode_type;
return $this;
}
/**
* @return string
*/
public function getBarcodePosition(): string
{
return $this->barcode_position;
}
/**
* @param string $barcode_position
* @return LabelOptions
*/
public function setBarcodePosition(string $barcode_position): LabelOptions
{
$this->barcode_position = $barcode_position;
return $this;
}
/**
* @return string
*/
public function getPictureType(): string
{
return $this->picture_type;
}
/**
* @param string $picture_type
* @return LabelOptions
*/
public function setPictureType(string $picture_type): LabelOptions
{
$this->picture_type = $picture_type;
return $this;
}
/**
* @return string
*/
public function getPicturePosition(): string
{
return $this->picture_position;
}
/**
* @param string $picture_position
* @return LabelOptions
*/
public function setPicturePosition(string $picture_position): LabelOptions
{
$this->picture_position = $picture_position;
return $this;
}
/**
* @return string
*/
public function getSupportedElement(): string
{
return $this->supported_element;
}
/**
* @param string $supported_element
* @return LabelOptions
*/
public function setSupportedElement(string $supported_element): LabelOptions
{
$this->supported_element = $supported_element;
return $this;
}
/**
* @return string
*/
public function getFont(): string
{
return $this->font;
}
/**
* @param string $font
* @return LabelOptions
*/
public function setFont(string $font): LabelOptions
{
$this->font = $font;
return $this;
}
/**
* @return string
*/
public function getLines(): string
{
return $this->lines;
}
/**
* @param string $lines
* @return LabelOptions
*/
public function setLines(string $lines): LabelOptions
{
$this->lines = $lines;
return $this;
}
}

View file

@ -0,0 +1,92 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2020 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 Affero General Public License as published
* by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace App\Entity\LabelSystem;
use App\Entity\Attachments\AttachmentContainingDBElement;
use App\Entity\Attachments\LabelAttachment;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass="App\Repository\NamedDBElementRepository")
* @ORM\Table(name="label_profiles")
* @ORM\EntityListeners({"App\EntityListeners\TreeCacheInvalidationListener"})
* @UniqueEntity({"name", "options.supported_element"})
* @package App\Entity\LabelSystem
*/
class LabelProfile extends AttachmentContainingDBElement
{
/**
* @var Collection<int, LabelAttachment>
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\LabelAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
* @ORM\OrderBy({"name" = "ASC"})
*/
protected $attachments;
/**
* @var LabelOptions
* @ORM\Embedded(class="LabelOptions")
* @Assert\Valid()
*/
protected $options;
/**
* @var string The comment info for this element
* @ORM\Column(type="text")
*/
protected $comment = '';
public function __construct()
{
parent::__construct();
$this->options = new LabelOptions();
}
public function getOptions(): LabelOptions
{
return $this->options;
}
/**
* Get the comment of the element.
* @return string the comment
*/
public function getComment(): ?string
{
return $this->comment;
}
public function setComment(string $new_comment): string
{
$this->comment = $new_comment;
return $this;
}
/**
* @inheritDoc
*/
public function getIDString(): string
{
return 'LP'.sprintf('%09d', $this->getID());
}
}

View file

@ -47,6 +47,7 @@ use App\Entity\Attachments\AttachmentType;
use App\Entity\Base\AbstractDBElement; use App\Entity\Base\AbstractDBElement;
use App\Entity\Devices\Device; use App\Entity\Devices\Device;
use App\Entity\Devices\DevicePart; use App\Entity\Devices\DevicePart;
use App\Entity\LabelSystem\LabelProfile;
use App\Entity\Parameters\AbstractParameter; use App\Entity\Parameters\AbstractParameter;
use App\Entity\Parts\Category; use App\Entity\Parts\Category;
use App\Entity\Parts\Footprint; use App\Entity\Parts\Footprint;
@ -117,6 +118,7 @@ abstract class AbstractLogEntry extends AbstractDBElement
protected const TARGET_TYPE_PRICEDETAIL = 16; protected const TARGET_TYPE_PRICEDETAIL = 16;
protected const TARGET_TYPE_MEASUREMENTUNIT = 17; protected const TARGET_TYPE_MEASUREMENTUNIT = 17;
protected const TARGET_TYPE_PARAMETER = 18; protected const TARGET_TYPE_PARAMETER = 18;
protected const TARGET_TYPE_LABEL_PROFILE = 19;
/** @var array This const is used to convert the numeric level to a PSR-3 compatible log level */ /** @var array This const is used to convert the numeric level to a PSR-3 compatible log level */
protected const LEVEL_ID_TO_STRING = [ protected const LEVEL_ID_TO_STRING = [
@ -149,6 +151,7 @@ abstract class AbstractLogEntry extends AbstractDBElement
self::TARGET_TYPE_PRICEDETAIL => Pricedetail::class, self::TARGET_TYPE_PRICEDETAIL => Pricedetail::class,
self::TARGET_TYPE_MEASUREMENTUNIT => MeasurementUnit::class, self::TARGET_TYPE_MEASUREMENTUNIT => MeasurementUnit::class,
self::TARGET_TYPE_PARAMETER => AbstractParameter::class, self::TARGET_TYPE_PARAMETER => AbstractParameter::class,
self::TARGET_TYPE_LABEL_PROFILE => LabelProfile::class,
]; ];
/** @var User The user which has caused this log entry /** @var User The user which has caused this log entry
@ -163,7 +166,7 @@ abstract class AbstractLogEntry extends AbstractDBElement
protected $timestamp; protected $timestamp;
/** @var int The priority level of the associated level. 0 is highest, 7 lowest /** @var int The priority level of the associated level. 0 is highest, 7 lowest
* @ORM\Column(type="integer", name="level", columnDefinition="TINYINT") * @ORM\Column(type="integer", name="level", columnDefinition="TINYINT(4) NOT NULL")
*/ */
protected $level; protected $level;

View file

@ -85,11 +85,11 @@ class Storelocation extends AbstractPartsContainingDBElement
protected $storage_type; protected $storage_type;
/** /**
* @ORM\ManyToMany(targetEntity="Part", fetch="EXTRA_LAZY") * //@ORM\ManyToMany(targetEntity="Part", fetch="EXTRA_LAZY")
* @ORM\JoinTable(name="part_lots", * //@ORM\JoinTable(name="part_lots",
* joinColumns={@ORM\JoinColumn(name="id_store_location", referencedColumnName="id")}, * // joinColumns={@ORM\JoinColumn(name="id_store_location", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="id_part", referencedColumnName="id")} * // inverseJoinColumns={@ORM\JoinColumn(name="id_part", referencedColumnName="id")}
* ) * //)
*/ */
protected $parts; protected $parts;

View file

@ -101,11 +101,11 @@ class Supplier extends AbstractCompany
protected $shipping_costs; protected $shipping_costs;
/** /**
* @ORM\ManyToMany(targetEntity="Part", fetch="EXTRA_LAZY") * //@ORM\ManyToMany(targetEntity="Part", fetch="EXTRA_LAZY")
* @ORM\JoinTable(name="orderdetails", * //@ORM\JoinTable(name="orderdetails",
* joinColumns={@ORM\JoinColumn(name="id_supplier", referencedColumnName="id")}, * // joinColumns={@ORM\JoinColumn(name="id_supplier", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="part_id", referencedColumnName="id")} * // inverseJoinColumns={@ORM\JoinColumn(name="part_id", referencedColumnName="id")}
* ) * //)
*/ */
protected $parts; protected $parts;

View file

@ -44,6 +44,7 @@ namespace App\EntityListeners;
use App\Entity\Base\AbstractDBElement; use App\Entity\Base\AbstractDBElement;
use App\Entity\Base\AbstractStructuralDBElement; use App\Entity\Base\AbstractStructuralDBElement;
use App\Entity\LabelSystem\LabelProfile;
use App\Entity\UserSystem\Group; use App\Entity\UserSystem\Group;
use App\Entity\UserSystem\User; use App\Entity\UserSystem\User;
use App\Services\UserCacheKeyGenerator; use App\Services\UserCacheKeyGenerator;
@ -71,7 +72,7 @@ class TreeCacheInvalidationListener
public function invalidate(AbstractDBElement $element, LifecycleEventArgs $event): void public function invalidate(AbstractDBElement $element, LifecycleEventArgs $event): void
{ {
//If an element was changed, then invalidate all cached trees with this element class //If an element was changed, then invalidate all cached trees with this element class
if ($element instanceof AbstractStructuralDBElement) { if ($element instanceof AbstractStructuralDBElement || $element instanceof LabelProfile) {
$secure_class_name = str_replace('\\', '_', get_class($element)); $secure_class_name = str_replace('\\', '_', get_class($element));
$this->cache->invalidateTags([$secure_class_name]); $this->cache->invalidateTags([$secure_class_name]);
} }

View file

@ -45,6 +45,8 @@ namespace App\Form\AdminPages;
use App\Entity\Attachments\Attachment; use App\Entity\Attachments\Attachment;
use App\Entity\Base\AbstractNamedDBElement; use App\Entity\Base\AbstractNamedDBElement;
use App\Entity\Base\AbstractStructuralDBElement; use App\Entity\Base\AbstractStructuralDBElement;
use App\Entity\LabelSystem\LabelOptions;
use App\Entity\LabelSystem\LabelProfile;
use App\Form\AttachmentFormType; use App\Form\AttachmentFormType;
use App\Form\ParameterType; use App\Form\ParameterType;
use App\Form\Type\MasterPictureAttachmentType; use App\Form\Type\MasterPictureAttachmentType;
@ -94,26 +96,38 @@ class BaseEntityAdminForm extends AbstractType
'placeholder' => 'part.name.placeholder', 'placeholder' => 'part.name.placeholder',
], ],
'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity), 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity),
]) ]);
->add('parent', StructuralEntityType::class, [ if ($entity instanceof AbstractStructuralDBElement) {
$builder->add(
'parent',
StructuralEntityType::class,
[
'class' => get_class($entity), 'class' => get_class($entity),
'required' => false, 'required' => false,
'label' => 'parent.label', 'label' => 'parent.label',
'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'move', $entity), 'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity),
]) ]
)
->add('not_selectable', CheckboxType::class, [ ->add(
'not_selectable',
CheckboxType::class,
[
'required' => false, 'required' => false,
'label' => 'entity.edit.not_selectable', 'label' => 'entity.edit.not_selectable',
'help' => 'entity.edit.not_selectable.help', 'help' => 'entity.edit.not_selectable.help',
'label_attr' => [ 'label_attr' => [
'class' => 'checkbox-custom', 'class' => 'checkbox-custom',
], ],
'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity), 'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
]) ]
);
->add('comment', CKEditorType::class, [ }
if ($entity instanceof AbstractStructuralDBElement || $entity instanceof LabelProfile) {
$builder->add(
'comment',
CKEditorType::class,
[
'required' => false, 'required' => false,
'empty_data' => '', 'empty_data' => '',
'label' => 'comment.label', 'label' => 'comment.label',
@ -121,8 +135,10 @@ class BaseEntityAdminForm extends AbstractType
'rows' => 4, 'rows' => 4,
], ],
'help' => 'bbcode.hint', 'help' => 'bbcode.hint',
'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity), 'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
]); ]
);
}
$this->additionalFormElements($builder, $options, $entity); $this->additionalFormElements($builder, $options, $entity);
@ -154,11 +170,15 @@ class BaseEntityAdminForm extends AbstractType
'empty_data' => null, 'empty_data' => null,
]); ]);
$builder->add('parameters', CollectionType::class, [ if ($entity instanceof StructuralEntityType) {
$builder->add(
'parameters',
CollectionType::class,
[
'entry_type' => ParameterType::class, 'entry_type' => ParameterType::class,
'allow_add' => $this->security->isGranted($is_new ? 'create' : 'edit', $entity), 'allow_add' => $this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'allow_delete' => $this->security->isGranted($is_new ? 'create' : 'edit', $entity), 'allow_delete' => $this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity), 'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'reindex_enable' => true, 'reindex_enable' => true,
'label' => false, 'label' => false,
'by_reference' => false, 'by_reference' => false,
@ -166,7 +186,9 @@ class BaseEntityAdminForm extends AbstractType
'entry_options' => [ 'entry_options' => [
'data_class' => $options['parameter_class'], 'data_class' => $options['parameter_class'],
], ],
]); ]
);
}
//Buttons //Buttons
$builder->add('save', SubmitType::class, [ $builder->add('save', SubmitType::class, [

View file

@ -0,0 +1,42 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2020 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 Affero General Public License as published
* by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace App\Form\AdminPages;
use App\Entity\Base\AbstractNamedDBElement;
use App\Entity\LabelSystem\LabelProfile;
use App\Form\LabelOptionsType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class LabelProfileAdminForm extends BaseEntityAdminForm
{
protected function additionalFormElements(FormBuilderInterface $builder, array $options, AbstractNamedDBElement $entity): void
{
$builder->add('options', LabelOptionsType::class);
}
public function configureOptions(OptionsResolver $resolver): void
{
parent::configureOptions($resolver);
$resolver->setDefault('data_class', LabelProfile::class);
}
}

View file

@ -0,0 +1,78 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2020 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 Affero General Public License as published
* by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace App\Form;
use App\Entity\LabelSystem\LabelOptions;
use FOS\CKEditorBundle\Form\Type\CKEditorType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class LabelOptionsType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('width', NumberType::class, [
'label' => 'label_options.page_size.label',
'html5' => true,
'attr' => [
'placeholder' => 'label_options.width.placeholder',
'min' => 0,
'step' => 'any',
]
]);
$builder->add('height', NumberType::class, [
'label' => false,
'html5' => true,
'attr' => [
'placeholder' => 'label_options.height.placeholder',
'min' => 0,
'step' => 'any',
]
]);
$builder->add('barcode_type', ChoiceType::class, [
'label' => 'label_options.barcode_type.label',
'empty_data' => 'none',
'choices' => [
'label_options.barcode_type.none' => 'none',
'label_options.barcode_type.qr' => 'qr',
'label_options.barcode_type.code39' => 'code39',
]
]);
$builder->add('lines', CKEditorType::class, [
'label' => 'label_profile.lines.label',
'attr' => [
'rows' => 4,
],
'config_name' => 'label_config',
]);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefault('data_class', LabelOptions::class);
}
}

View file

@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20200411145120 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}
public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('CREATE TABLE label_profiles (id INT AUTO_INCREMENT NOT NULL, id_preview_attachement INT DEFAULT NULL, comment LONGTEXT NOT NULL, name VARCHAR(255) NOT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, options_width DOUBLE PRECISION NOT NULL, options_height DOUBLE PRECISION NOT NULL, options_barcode_type VARCHAR(255) NOT NULL, options_barcode_position VARCHAR(255) NOT NULL, options_picture_type VARCHAR(255) NOT NULL, options_picture_position VARCHAR(255) NOT NULL, options_supported_element VARCHAR(255) NOT NULL, options_font VARCHAR(255) NOT NULL, options_lines LONGTEXT NOT NULL, INDEX IDX_C93E9CF56DEDCEC2 (id_preview_attachement), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE label_profiles ADD CONSTRAINT FK_C93E9CF56DEDCEC2 FOREIGN KEY (id_preview_attachement) REFERENCES `attachments` (id)');
$this->addSql('ALTER TABLE log CHANGE level level TINYINT(4) NOT NULL');
}
public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('DROP TABLE label_profiles');
$this->addSql('ALTER TABLE log CHANGE level level TINYINT(1) DEFAULT NULL');
}
}

View file

@ -0,0 +1,49 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2020 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 Affero General Public License as published
* by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace App\Security\Voter;
use App\Entity\LabelSystem\LabelProfile;
use App\Entity\UserSystem\User;
class LabelProfileVoter extends ExtendedVoter
{
/**
* @inheritDoc
*/
protected function voteOnUser($attribute, $subject, User $user): bool
{
return true;
}
/**
* @inheritDoc
*/
protected function supports($attribute, $subject)
{
if ($subject instanceof LabelProfile) {
return true;
}
return false;
}
}

View file

@ -46,6 +46,7 @@ use App\Entity\Attachments\Attachment;
use App\Entity\Attachments\AttachmentType; use App\Entity\Attachments\AttachmentType;
use App\Entity\Contracts\NamedElementInterface; use App\Entity\Contracts\NamedElementInterface;
use App\Entity\Devices\Device; use App\Entity\Devices\Device;
use App\Entity\LabelSystem\LabelProfile;
use App\Entity\Parameters\AbstractParameter; use App\Entity\Parameters\AbstractParameter;
use App\Entity\Parts\Category; use App\Entity\Parts\Category;
use App\Entity\Parts\Footprint; use App\Entity\Parts\Footprint;
@ -92,6 +93,7 @@ class ElementTypeNameGenerator
Group::class => $this->translator->trans('group.label'), Group::class => $this->translator->trans('group.label'),
User::class => $this->translator->trans('user.label'), User::class => $this->translator->trans('user.label'),
AbstractParameter::class => $this->translator->trans('parameter.label'), AbstractParameter::class => $this->translator->trans('parameter.label'),
LabelProfile::class => $this->translator->trans('label_profile.label'),
]; ];
} }

View file

@ -47,6 +47,7 @@ use App\Entity\Attachments\AttachmentType;
use App\Entity\Attachments\PartAttachment; use App\Entity\Attachments\PartAttachment;
use App\Entity\Base\AbstractDBElement; use App\Entity\Base\AbstractDBElement;
use App\Entity\Devices\Device; use App\Entity\Devices\Device;
use App\Entity\LabelSystem\LabelProfile;
use App\Entity\Parts\Category; use App\Entity\Parts\Category;
use App\Entity\Parts\Footprint; use App\Entity\Parts\Footprint;
use App\Entity\Parts\Manufacturer; use App\Entity\Parts\Manufacturer;
@ -133,7 +134,6 @@ class EntityURLGenerator
{ {
$map = [ $map = [
Part::class => 'part_info', Part::class => 'part_info',
//As long we does not have own things for it use edit page //As long we does not have own things for it use edit page
AttachmentType::class => 'attachment_type_edit', AttachmentType::class => 'attachment_type_edit',
Category::class => 'category_edit', Category::class => 'category_edit',
@ -146,6 +146,7 @@ class EntityURLGenerator
Currency::class => 'currency_edit', Currency::class => 'currency_edit',
MeasurementUnit::class => 'measurement_unit_edit', MeasurementUnit::class => 'measurement_unit_edit',
Group::class => 'group_edit', Group::class => 'group_edit',
LabelProfile::class => 'label_profile_edit',
]; ];
try { try {
@ -241,6 +242,7 @@ class EntityURLGenerator
Currency::class => 'currency_edit', Currency::class => 'currency_edit',
MeasurementUnit::class => 'measurement_unit_edit', MeasurementUnit::class => 'measurement_unit_edit',
Group::class => 'group_edit', Group::class => 'group_edit',
LabelProfile::class => 'label_profile_edit'
]; ];
return $this->urlGenerator->generate($this->mapToController($map, $entity), ['id' => $entity->getID()]); return $this->urlGenerator->generate($this->mapToController($map, $entity), ['id' => $entity->getID()]);
@ -270,6 +272,7 @@ class EntityURLGenerator
Currency::class => 'currency_edit', Currency::class => 'currency_edit',
MeasurementUnit::class => 'measurement_unit_edit', MeasurementUnit::class => 'measurement_unit_edit',
Group::class => 'group_edit', Group::class => 'group_edit',
LabelProfile::class => 'label_profile_edit'
]; ];
return $this->urlGenerator->generate($this->mapToController($map, $entity), ['id' => $entity->getID()]); return $this->urlGenerator->generate($this->mapToController($map, $entity), ['id' => $entity->getID()]);
@ -299,6 +302,7 @@ class EntityURLGenerator
Currency::class => 'currency_new', Currency::class => 'currency_new',
MeasurementUnit::class => 'measurement_unit_new', MeasurementUnit::class => 'measurement_unit_new',
Group::class => 'group_new', Group::class => 'group_new',
LabelProfile::class => 'label_profile_new'
]; ];
return $this->urlGenerator->generate($this->mapToController($map, $entity)); return $this->urlGenerator->generate($this->mapToController($map, $entity));
@ -329,6 +333,7 @@ class EntityURLGenerator
Currency::class => 'currency_clone', Currency::class => 'currency_clone',
MeasurementUnit::class => 'measurement_unit_clone', MeasurementUnit::class => 'measurement_unit_clone',
Group::class => 'group_clone', Group::class => 'group_clone',
LabelProfile::class => 'label_profile_clone'
]; ];
return $this->urlGenerator->generate($this->mapToController($map, $entity), ['id' => $entity->getID()]); return $this->urlGenerator->generate($this->mapToController($map, $entity), ['id' => $entity->getID()]);
@ -371,6 +376,7 @@ class EntityURLGenerator
Currency::class => 'currency_delete', Currency::class => 'currency_delete',
MeasurementUnit::class => 'measurement_unit_delete', MeasurementUnit::class => 'measurement_unit_delete',
Group::class => 'group_delete', Group::class => 'group_delete',
LabelProfile::class => 'label_profile_delete'
]; ];
return $this->urlGenerator->generate($this->mapToController($map, $entity), ['id' => $entity->getID()]); return $this->urlGenerator->generate($this->mapToController($map, $entity), ['id' => $entity->getID()]);

View file

@ -0,0 +1,15 @@
{% extends "AdminPages/EntityAdminBase.html.twig" %}
{% block card_title %}
<i class="fas fa-qr fa-fw"></i> {% trans %}label_profile.caption{% endtrans %}
{% endblock %}
{% block additional_pills %}
<li class="nav-item"><a data-toggle="tab" class="nav-link link-anchor" href="#tab_options">{% trans %}admin.options{% endtrans %}</a></li>
{% endblock %}
{% block additional_panes %}
<div class="tab-pane" id="tab_options">
{{ form_widget(form.options) }}
</div>
{% endblock %}

View file

@ -46,6 +46,24 @@
{{ form_errors(form.value) }} {{ form_errors(form.value) }}
{% endblock %} {% endblock %}
{% block label_options_widget %}
<div class="form-group row">
{{ form_label(form.width) }}
<div class="input-group col-9">
{{ form_widget(form.width) }}
<div class="input-group-append input-group-prepend">
<span class="input-group-text">x</span>
</div>
{{ form_widget(form.height) }}
<div class="input-group-append">
<span class="input-group-text">mm</span>
</div>
</div>
</div>
{{ form_row(form.barcode_type) }}
{{ form_row(form.lines) }}
{% endblock %}
{####################################################################################### {#######################################################################################
# #
# Definitions for Tristate Checkbox Type (mostly based on bootstrap checkbox type) # Definitions for Tristate Checkbox Type (mostly based on bootstrap checkbox type)

File diff suppressed because it is too large Load diff