Added possibility to generate labels for storelocations.

This commit is contained in:
Jan Böhmer 2020-05-08 13:49:44 +02:00
parent 9a9cd8e887
commit bd6a0de0a2
12 changed files with 126 additions and 4 deletions

View file

@ -23,6 +23,7 @@ CKEDITOR.plugins.setLang( 'partdb_label', 'de', {
'section.global': 'Global',
'section.part': 'Bauteil',
'section.part_lot': 'Bauteilbestand',
'section.storelocation': 'Lagerort',
'part.id': 'Datenbank ID',
'part.name': 'Bauteilename',
'part.category': 'Kategorie',
@ -55,4 +56,14 @@ CKEDITOR.plugins.setLang( 'partdb_label', 'de', {
'lot.amount': 'Bestandsmenge',
'lot.location': 'Lagerort',
'lot.location_full': 'Lagerort (Ganzer Pfad)',
'storelocation.id': 'Lagerort ID',
'storelocation.name': 'Name',
'storelocation.full_path': 'Ganzer Pfad',
'storelocation.parent_name': 'Name des Übergeordneten Elements',
'storelocation.parent_full_path': 'Ganzer Pfad des Übergeordneten Elements',
'storelocation.comment': 'Kommentar',
'storelocation.comment_t': 'Kommentar (Text)',
'storelocation.last_modified': 'Änderungsdatum',
'storelocation.creation_date': 'Erstellungsdatum',
} );

View file

@ -23,6 +23,7 @@ CKEDITOR.plugins.setLang( 'partdb_label', 'en', {
'section.global': 'Globals',
'section.part': 'Part',
'section.part_lot': 'Part lot',
'section.storelocation': 'Storage location',
'part.id': 'Database ID',
'part.name': 'Part name',
'part.category': 'Category',
@ -55,4 +56,14 @@ CKEDITOR.plugins.setLang( 'partdb_label', 'en', {
'lot.amount': 'Lot amount',
'lot.location': 'Storage location',
'lot.location_full': 'Storage location (Full path)',
'storelocation.id': 'Location ID',
'storelocation.name': 'Name',
'storelocation.full_path': 'Full path',
'storelocation.parent_name': 'Parent name',
'storelocation.parent_full_path': 'Parent full path',
'storelocation.comment': 'Comment',
'storelocation.comment_t': 'Comment (Text)',
'storelocation.last_modified': 'Last modified datetime',
'storelocation.creation_date': 'Createion datetime',
} );

View file

@ -57,6 +57,20 @@ const PLACEHOLDERS = {
['[[LOCATION_FULL]]', 'lot.location_full'],
]
},
storelocation: {
label: 'section.storelocation',
entries: [
['[[ID]]', 'storelocation.id'],
['[[NAME]]', 'storelocation.name'],
['[[FULL_PATH]]', 'storelocation.full_path'],
['[[PARENT_NAME]]', 'storelocation.parent_name'],
['[[PARENT_FULL_PATH]]', 'storelocation.parent_full_path'],
['[[COMMENT]]', 'storelocation.comment'],
['[[COMMENT_T]]', 'storelocation.comment_t'],
['[[LAST_MODIFIED]]', 'storelocation.last_modified'],
['[[CREATION_DATE]]', 'storelocation.creation_date'],
]
},
global: {
label: 'section.global',
entries: [

View file

@ -29,7 +29,7 @@ use Symfony\Component\Validator\Constraints as Assert;
class LabelOptions
{
public const BARCODE_TYPES = ['none', /*'ean8',*/ 'qr', 'code39', 'datamatrix', 'code93', 'code128'];
public const SUPPORTED_ELEMENTS = ['part', 'part_lot'];
public const SUPPORTED_ELEMENTS = ['part', 'part_lot', 'storelocation'];
public const PICTURE_TYPES = ['none', 'element_picture', 'main_attachment'];
public const LINES_MODES = ['html', 'twig'];

View file

@ -65,7 +65,8 @@ class LabelOptionsType extends AbstractType
'label' => 'label_options.supported_elements.label',
'choices' => [
'part.label' => 'part',
'part_lot.label' => 'part_lot'
'part_lot.label' => 'part_lot',
'storelocation.label' => 'storelocation',
]
]);

View file

@ -37,11 +37,28 @@ class BarcodeExampleElementsGenerator
return $this->getExamplePart();
case 'part_lot':
return $this->getExamplePartLot();
case 'storelocation':
return $this->getStorelocation();
default:
throw new \InvalidArgumentException('Unknown $type.');
}
}
protected function getStorelocation(): Storelocation
{
$storelocation = new Storelocation();
$storelocation->setName('Location 1');
$storelocation->setComment('Example comment');
$storelocation->updatedTimestamps();
$parent = new Storelocation();
$parent->setName('Parent');
$storelocation->setParent($parent);
return $storelocation;
}
protected function getStructuralData(string $class): AbstractStructuralDBElement
{
if (!is_a($class, AbstractStructuralDBElement::class, true)) {

View file

@ -62,7 +62,7 @@ class BarcodeContentGenerator
return $this->urlGenerator->generate('scan_qr', [
'type' => $type,
'id' => $target->getID(),
'id' => $target->getID() ?? 0,
'_locale' => null,
], UrlGeneratorInterface::ABSOLUTE_URL);
}

View file

@ -25,6 +25,7 @@ use App\Entity\Contracts\NamedElementInterface;
use App\Entity\LabelSystem\LabelOptions;
use App\Entity\Parts\Part;
use App\Entity\Parts\PartLot;
use App\Entity\Parts\Storelocation;
use App\Services\ElementTypeNameGenerator;
use Dompdf\Dompdf;
use Twig\Environment;
@ -34,6 +35,7 @@ class LabelGenerator
public const CLASS_SUPPORT_MAPPING = [
'part' => Part::class,
'part_lot' => PartLot::class,
'storelocation' => Storelocation::class,
];
public const MM_TO_POINTS_FACTOR = 2.83465;

View file

@ -0,0 +1,52 @@
<?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\Services\LabelSystem\PlaceholderProviders;
use App\Entity\Base\AbstractDBElement;
use App\Entity\Base\AbstractStructuralDBElement;
class StructuralDBElementProvider implements PlaceholderProviderInterface
{
public function replace(string $placeholder, object $label_target, array $options = []): ?string
{
if ($label_target instanceof AbstractStructuralDBElement) {
if ($placeholder === '[[COMMENT]]') {
return $label_target->getComment();
}
if ($placeholder === '[[COMMENT_T]]') {
return strip_tags($label_target->getComment());
}
if ($placeholder === '[[FULL_PATH]]') {
return $label_target->getFullPath();
}
if ($placeholder === '[[PARENT]]') {
return $label_target->getParent() ? $label_target->getParent()->getName() : '';
}
if ($placeholder === '[[PARENT_FULL_PATH]]') {
return $label_target->getParent() ? $label_target->getParent()->getFullPath() : '';
}
}
return null;
}
}

View file

@ -1,10 +1,18 @@
{% extends "AdminPages/EntityAdminBase.html.twig" %}
{% import "LabelSystem/dropdown_macro.html.twig" as dropdown %}
{% block card_title %}
<i class="fas fa-cube fa-fw"></i> {% trans %}storelocation.labelp{% endtrans %}
{% endblock %}
{% block additional_controls %}
{% if entity.id %}
<div class="row form-group">
<div class="offset-sm-3 col-sm-9">
{{ dropdown.profile_dropdown('storelocation', entity.id) }}
</div>
</div>
{% endif %}
{% endblock %}
{% block additional_pills %}

View file

@ -1,5 +1,5 @@
{% macro profile_dropdown(type, id = null, include_text = true, btn_type = 'btn-secondary') %}
<div class="btn-group">
<div class="dropdown">
<button type="button" class="btn {{ btn_type }} dropdown-toggle" title="{% trans %}label_generator.label_btn{% endtrans %}"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" {% if not is_granted("@labels.create_labels") %}disabled{% endif %}>
<i class="fas fa-fw fa-qrcode"></i> {% if include_text %}{% trans %}label_generator.label_btn{% endtrans %}{% endif %}

View file

@ -1,4 +1,5 @@
{% import "helper.twig" as helper %}
{% import "LabelSystem/dropdown_macro.html.twig" as dropdown %}
{{ helper.breadcrumb_entity_link(entity) }}
@ -77,6 +78,11 @@
<i class="fas fa-calendar-plus fa-fw"></i> {{ entity.addedDate | format_datetime("short") }}
</span>
</div>
{% if entity is instanceof("App\\Entity\\Parts\\Storelocation") %}
{{ dropdown.profile_dropdown('storelocation', entity.id, true, 'btn-secondary btn-block mt-2') }}
{% endif %}
</div>
</div>
</div>