diff --git a/src/Entity/LabelSystem/LabelOptions.php b/src/Entity/LabelSystem/LabelOptions.php index 381186d7..10b3ab2b 100644 --- a/src/Entity/LabelSystem/LabelOptions.php +++ b/src/Entity/LabelSystem/LabelOptions.php @@ -31,8 +31,8 @@ class LabelOptions public const BARCODE_TYPES = ['none', /*'ean8',*/ 'qr', 'code39', 'datamatrix', 'code93']; public const SUPPORTED_ELEMENTS = ['part', 'part_lot']; public const PICTURE_TYPES = ['none', 'element_picture', 'main_attachment']; - public const POSITIONS = ['left', 'right', 'top', 'bottom']; - public const FONTS = ['default']; + + public const LINES_MODES = ['html', 'twig']; /** * @var float The page size of the label in mm @@ -55,13 +55,6 @@ class LabelOptions */ 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) @@ -69,13 +62,6 @@ class LabelOptions */ 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) @@ -84,10 +70,16 @@ class LabelOptions protected $supported_element = 'part'; /** - * @var string The font that should be used in the Barcode + * @var string Any additional CSS for the label. + * @ORM\Column(type="text") + */ + protected $additional_css = ''; + + /** @var string The mode that will be used to interpret the lines. + * @Assert\Choice(choices=LabelOptions::LINES_MODES) * @ORM\Column(type="string") */ - protected $font = 'default'; + protected $lines_mode = 'html'; /** * @var string @@ -149,24 +141,6 @@ class LabelOptions 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 */ @@ -185,24 +159,6 @@ class LabelOptions 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 */ @@ -221,24 +177,6 @@ class LabelOptions 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 */ diff --git a/src/Entity/LabelSystem/LabelProfile.php b/src/Entity/LabelSystem/LabelProfile.php index 41c0703f..f2a0884d 100644 --- a/src/Entity/LabelSystem/LabelProfile.php +++ b/src/Entity/LabelSystem/LabelProfile.php @@ -56,6 +56,12 @@ class LabelProfile extends AttachmentContainingDBElement */ protected $comment = ''; + /** + * @var bool Determines, if this label profile should be shown in the dropdown quick menu. + * @ORM\Column(type="boolean") + */ + protected $show_in_dropdown = true; + public function __construct() { parent::__construct(); @@ -82,6 +88,28 @@ class LabelProfile extends AttachmentContainingDBElement return $this; } + /** + * Returns true, if this label profile should be shown in label generator quick menu. + * @return bool + */ + public function isShowInDropdown(): bool + { + return $this->show_in_dropdown; + } + + /** + * Sets the show in dropdown menu. + * @param bool $show_in_dropdown + * @return LabelProfile + */ + public function setShowInDropdown(bool $show_in_dropdown): LabelProfile + { + $this->show_in_dropdown = $show_in_dropdown; + return $this; + } + + + /** * @inheritDoc */ diff --git a/src/Form/AdminPages/LabelProfileAdminForm.php b/src/Form/AdminPages/LabelProfileAdminForm.php index 6e56d088..fad8dc39 100644 --- a/src/Form/AdminPages/LabelProfileAdminForm.php +++ b/src/Form/AdminPages/LabelProfileAdminForm.php @@ -24,6 +24,7 @@ namespace App\Form\AdminPages; use App\Entity\Base\AbstractNamedDBElement; use App\Entity\LabelSystem\LabelProfile; use App\Form\LabelOptionsType; +use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -31,6 +32,14 @@ class LabelProfileAdminForm extends BaseEntityAdminForm { protected function additionalFormElements(FormBuilderInterface $builder, array $options, AbstractNamedDBElement $entity): void { + + $builder->add('show_in_dropdown', CheckboxType::class, [ + 'required' => false, + 'label' => 'label_profile.showInDropdown', + 'label_attr' => [ + 'class' => 'checkbox-custom', + ], + ]); $builder->add('options', LabelOptionsType::class); } diff --git a/src/Migrations/Version20200411145120.php b/src/Migrations/Version20200502161750.php similarity index 64% rename from src/Migrations/Version20200411145120.php rename to src/Migrations/Version20200502161750.php index 2c0a122a..74be880a 100644 --- a/src/Migrations/Version20200411145120.php +++ b/src/Migrations/Version20200502161750.php @@ -10,7 +10,7 @@ use Doctrine\Migrations\AbstractMigration; /** * Auto-generated Migration: Please modify to your needs! */ -final class Version20200411145120 extends AbstractMigration +final class Version20200502161750 extends AbstractMigration { public function getDescription() : string { @@ -22,7 +22,7 @@ final class Version20200411145120 extends AbstractMigration // 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('CREATE TABLE label_profiles (id INT AUTO_INCREMENT NOT NULL, id_preview_attachement INT DEFAULT NULL, comment LONGTEXT NOT NULL, show_in_dropdown TINYINT(1) 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_picture_type VARCHAR(255) NOT NULL, options_supported_element VARCHAR(255) NOT NULL, options_additional_css LONGTEXT NOT NULL, options_lines_mode 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'); } diff --git a/src/Repository/LabelProfileRepository.php b/src/Repository/LabelProfileRepository.php index cb558a6d..fad62359 100644 --- a/src/Repository/LabelProfileRepository.php +++ b/src/Repository/LabelProfileRepository.php @@ -36,8 +36,10 @@ class LabelProfileRepository extends NamedDBElementRepository */ public function getDropdownProfiles(string $type): array { - //TODO: Improve this, when we have a 'showInDropdown' flag for profiles. - return $this->findForSupportedElement($type); + if (!in_array($type, LabelOptions::SUPPORTED_ELEMENTS)) { + throw new \InvalidArgumentException('Invalid supported_element type given.'); + } + return $this->findBy(['options.supported_element' => $type, 'show_in_dropdown' => true], ['name' => 'ASC']); } /** diff --git a/src/Services/LabelSystem/LabelProfileDropdownHelper.php b/src/Services/LabelSystem/LabelProfileDropdownHelper.php index 800772e9..c90fcb55 100644 --- a/src/Services/LabelSystem/LabelProfileDropdownHelper.php +++ b/src/Services/LabelSystem/LabelProfileDropdownHelper.php @@ -33,9 +33,9 @@ class LabelProfileDropdownHelper private $entityManager; private $keyGenerator; - public function __construct(TagAwareCacheInterface $cache, EntityManagerInterface $entityManager, UserCacheKeyGenerator $keyGenerator) + public function __construct(TagAwareCacheInterface $treeCache, EntityManagerInterface $entityManager, UserCacheKeyGenerator $keyGenerator) { - $this->cache = $cache; + $this->cache = $treeCache; $this->entityManager = $entityManager; $this->keyGenerator = $keyGenerator; } diff --git a/templates/AdminPages/LabelProfileAdmin.html.twig b/templates/AdminPages/LabelProfileAdmin.html.twig index 0c2244dd..15177ee5 100644 --- a/templates/AdminPages/LabelProfileAdmin.html.twig +++ b/templates/AdminPages/LabelProfileAdmin.html.twig @@ -14,6 +14,10 @@ {% endblock %} +{% block additional_controls %} + {{ form_row(form.show_in_dropdown) }} +{% endblock %} + {% block additional_content %} {% if pdf_data is defined and pdf_data is not empty %}