mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-22 09:53:35 +02:00
Added dropdowns for quick generating labels for different profiles.
This commit is contained in:
parent
747962884a
commit
48ff81a6d1
8 changed files with 118 additions and 3 deletions
|
@ -15,3 +15,4 @@ twig:
|
||||||
allow_email_pw_reset: '%allow_email_pw_reset%'
|
allow_email_pw_reset: '%allow_email_pw_reset%'
|
||||||
locale_menu: '%locale_menu%'
|
locale_menu: '%locale_menu%'
|
||||||
attachment_manager: '@App\Services\Attachments\AttachmentManager'
|
attachment_manager: '@App\Services\Attachments\AttachmentManager'
|
||||||
|
label_profile_dropdown_helper: '@App\Services\LabelSystem\LabelProfileDropdownHelper'
|
||||||
|
|
|
@ -76,7 +76,7 @@ class LabelController extends AbstractController
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Route("/dialog", name="label_dialog")
|
* @Route("/dialog", name="label_dialog")
|
||||||
* @Route("/{profile}/dialog")
|
* @Route("/{profile}/dialog", name="label_dialog_profile")
|
||||||
*/
|
*/
|
||||||
public function generator(Request $request, ?LabelProfile $profile = null)
|
public function generator(Request $request, ?LabelProfile $profile = null)
|
||||||
{
|
{
|
||||||
|
@ -91,6 +91,8 @@ class LabelController extends AbstractController
|
||||||
//Try to parse given target_type and target_id
|
//Try to parse given target_type and target_id
|
||||||
$target_type = $request->query->get('target_type', null);
|
$target_type = $request->query->get('target_type', null);
|
||||||
$target_id = $request->query->get('target_id', null);
|
$target_id = $request->query->get('target_id', null);
|
||||||
|
$generate = $request->query->getBoolean('generate', false);
|
||||||
|
|
||||||
if ($profile === null && is_string($target_type)) {
|
if ($profile === null && is_string($target_type)) {
|
||||||
$label_options->setSupportedElement($target_type);
|
$label_options->setSupportedElement($target_type);
|
||||||
}
|
}
|
||||||
|
@ -108,7 +110,8 @@ class LabelController extends AbstractController
|
||||||
$pdf_data = null;
|
$pdf_data = null;
|
||||||
$filename = 'invalid.pdf';
|
$filename = 'invalid.pdf';
|
||||||
|
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
//Generate PDF either when the form is submitted and valid, or the form was not submit yet, and generate is set
|
||||||
|
if (($form->isSubmitted() && $form->isValid()) || ($generate && !$form->isSubmitted() && $profile !== null)) {
|
||||||
$target_id = (string) $form->get('target_id')->getData();
|
$target_id = (string) $form->get('target_id')->getData();
|
||||||
$targets = $this->findObjects($form_options->getSupportedElement(), $target_id);
|
$targets = $this->findObjects($form_options->getSupportedElement(), $target_id);
|
||||||
$pdf_data = $this->labelGenerator->generateLabel($form_options, $targets);
|
$pdf_data = $this->labelGenerator->generateLabel($form_options, $targets);
|
||||||
|
|
|
@ -27,6 +27,19 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
||||||
|
|
||||||
class LabelProfileRepository extends NamedDBElementRepository
|
class LabelProfileRepository extends NamedDBElementRepository
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find the profiles that are shown in the dropdown for the given type.
|
||||||
|
* You should maybe use the cached version of this in LabelProfileDropdownHelper
|
||||||
|
* @param string $type
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getDropdownProfiles(string $type): array
|
||||||
|
{
|
||||||
|
//TODO: Improve this, when we have a 'showInDropdown' flag for profiles.
|
||||||
|
return $this->findForSupportedElement($type);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a tree of TreeViewNode elements. The root elements has $parent as parent.
|
* Gets a tree of TreeViewNode elements. The root elements has $parent as parent.
|
||||||
* The treeview is generic, that means the href are null and ID values are set.
|
* The treeview is generic, that means the href are null and ID values are set.
|
||||||
|
|
57
src/Services/LabelSystem/LabelProfileDropdownHelper.php
Normal file
57
src/Services/LabelSystem/LabelProfileDropdownHelper.php
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
<?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;
|
||||||
|
|
||||||
|
|
||||||
|
use App\Entity\LabelSystem\LabelProfile;
|
||||||
|
use App\Services\UserCacheKeyGenerator;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Symfony\Contracts\Cache\ItemInterface;
|
||||||
|
use Symfony\Contracts\Cache\TagAwareCacheInterface;
|
||||||
|
|
||||||
|
class LabelProfileDropdownHelper
|
||||||
|
{
|
||||||
|
private $cache;
|
||||||
|
private $entityManager;
|
||||||
|
private $keyGenerator;
|
||||||
|
|
||||||
|
public function __construct(TagAwareCacheInterface $cache, EntityManagerInterface $entityManager, UserCacheKeyGenerator $keyGenerator)
|
||||||
|
{
|
||||||
|
$this->cache = $cache;
|
||||||
|
$this->entityManager = $entityManager;
|
||||||
|
$this->keyGenerator = $keyGenerator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDropdownProfiles(string $type): array
|
||||||
|
{
|
||||||
|
$secure_class_name = str_replace('\\', '_', LabelProfile::class);
|
||||||
|
$key = 'profile_dropdown_'.$this->keyGenerator->generateKey().'_'.$secure_class_name . '_' . $type;
|
||||||
|
|
||||||
|
$repo = $this->entityManager->getRepository(LabelProfile::class);
|
||||||
|
|
||||||
|
return $this->cache->get($key, function (ItemInterface $item) use ($repo, $type, $secure_class_name) {
|
||||||
|
// Invalidate when groups, a element with the class or the user changes
|
||||||
|
$item->tag(['groups', 'tree_treeview', $this->keyGenerator->generateKey(), $secure_class_name]);
|
||||||
|
|
||||||
|
return $repo->getDropdownProfiles($type);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
14
templates/LabelSystem/dropdown_macro.html.twig
Normal file
14
templates/LabelSystem/dropdown_macro.html.twig
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
{% macro profile_dropdown(type, id = null, include_text = true, btn_type = 'btn-secondary') %}
|
||||||
|
<div class="btn-group">
|
||||||
|
<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">
|
||||||
|
<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) %}
|
||||||
|
<a class="dropdown-item" href="{{ path('label_dialog_profile', {'profile': profile.id, 'target_type': type, 'target_id': id, 'generate': true}) }}">{{ profile.name }}</a>
|
||||||
|
{% endfor %}
|
||||||
|
<div class="dropdown-divider"></div>
|
||||||
|
<a class="dropdown-item" href="{{ path('label_dialog', {'target_type': type, 'target_id': id}) }}">{% trans %}label_generator.label_empty{% endtrans %}</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endmacro %}
|
|
@ -1,4 +1,5 @@
|
||||||
{% import "helper.twig" as helper %}
|
{% import "helper.twig" as helper %}
|
||||||
|
{% import "LabelSystem/dropdown_macro.html.twig" as dropdown %}
|
||||||
|
|
||||||
<table class="table table-striped table-hover table-responsive-sm">
|
<table class="table table-striped table-hover table-responsive-sm">
|
||||||
<thead>
|
<thead>
|
||||||
|
@ -7,6 +8,7 @@
|
||||||
<th>{% trans %}part_lots.storage_location{% endtrans %}</th>
|
<th>{% trans %}part_lots.storage_location{% endtrans %}</th>
|
||||||
<th>{% trans %}part_lots.amount{% endtrans %}</th>
|
<th>{% trans %}part_lots.amount{% endtrans %}</th>
|
||||||
<th></th> {# Tags row #}
|
<th></th> {# Tags row #}
|
||||||
|
<th></th> {# Button row #}
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
||||||
|
@ -55,6 +57,9 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</h6>
|
</h6>
|
||||||
</td>
|
</td>
|
||||||
|
<td>
|
||||||
|
{{ dropdown.profile_dropdown('part_lot', lot.id, false) }}
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
{% import "LabelSystem/dropdown_macro.html.twig" as dropdown %}
|
||||||
|
|
||||||
{% if is_granted('edit', part) %}
|
{% if is_granted('edit', part) %}
|
||||||
<a href="{{ part|entityURL('edit') }}" class="btn btn-primary mt-3">
|
<a href="{{ part|entityURL('edit') }}" class="btn btn-primary mt-3">
|
||||||
<i class="fas fa-fw fa-edit"></i>
|
<i class="fas fa-fw fa-edit"></i>
|
||||||
|
@ -46,4 +48,6 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
{{ dropdown.profile_dropdown('part', part.id) }}
|
|
@ -8370,5 +8370,23 @@ Element 3</target>
|
||||||
<target>Download</target>
|
<target>Download</target>
|
||||||
</segment>
|
</segment>
|
||||||
</unit>
|
</unit>
|
||||||
|
<unit id="iCTvpEA" name="navbar.scanner.link">
|
||||||
|
<segment>
|
||||||
|
<source>navbar.scanner.link</source>
|
||||||
|
<target>Scanner</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
|
<unit id="fkESKHW" name="label_generator.label_btn">
|
||||||
|
<segment>
|
||||||
|
<source>label_generator.label_btn</source>
|
||||||
|
<target>Generate label</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
|
<unit id="xXkObqX" name="label_generator.label_empty">
|
||||||
|
<segment>
|
||||||
|
<source>label_generator.label_empty</source>
|
||||||
|
<target>New empty label</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
</file>
|
</file>
|
||||||
</xliff>
|
</xliff>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue