mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-25 19:28:51 +02:00
Allow to specify which label profiles are shown in dropdown.
This commit is contained in:
parent
3804e2534d
commit
8b372a3443
8 changed files with 64 additions and 80 deletions
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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');
|
||||
}
|
|
@ -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']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -14,6 +14,10 @@
|
|||
</div>
|
||||
{% 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 %}
|
||||
<div class="card mt-2 mb-2 p-1 border-secondary" style="resize: vertical; overflow: scroll; height: 250px;">
|
||||
|
|
|
@ -4,10 +4,13 @@
|
|||
<i class="fas fa-fw fa-qrcode"></i> {% if include_text %}{% trans %}label_generator.label_btn{% endtrans %}{% endif %}
|
||||
</button>
|
||||
<div class="dropdown-menu">
|
||||
{% for profile in label_profile_dropdown_helper.dropdownProfiles(type) %}
|
||||
{% set profiles = label_profile_dropdown_helper.dropdownProfiles(type) %}
|
||||
{% for profile in profiles %}
|
||||
<a class="dropdown-item" href="{{ path('label_dialog_profile', {'profile': profile.id, 'target_type': type, 'target_id': id, 'generate': true}) }}">{{ profile.name }}</a>
|
||||
{% endfor %}
|
||||
{% if profiles is not empty %}
|
||||
<div class="dropdown-divider"></div>
|
||||
{% endif %}
|
||||
<a class="dropdown-item" href="{{ path('label_dialog', {'target_type': type, 'target_id': id}) }}">{% trans %}label_generator.label_empty{% endtrans %}</a>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue