mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-25 19:28:51 +02:00
Allow to specify a preview attachment in the AdminPages.
This commit is contained in:
parent
280b2d4427
commit
d9fe77d0e8
5 changed files with 120 additions and 26 deletions
|
@ -337,6 +337,8 @@ abstract class Attachment extends NamedDBElement
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->path = $url;
|
$this->path = $url;
|
||||||
|
//Reset internal filename
|
||||||
|
$this->original_filename = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
|
@ -38,7 +38,9 @@ use App\Entity\Attachments\PartAttachment;
|
||||||
use App\Entity\Base\NamedDBElement;
|
use App\Entity\Base\NamedDBElement;
|
||||||
use App\Entity\Base\StructuralDBElement;
|
use App\Entity\Base\StructuralDBElement;
|
||||||
use App\Form\AttachmentFormType;
|
use App\Form\AttachmentFormType;
|
||||||
|
use App\Form\Type\MasterPictureAttachmentType;
|
||||||
use App\Form\Type\StructuralEntityType;
|
use App\Form\Type\StructuralEntityType;
|
||||||
|
use Doctrine\ORM\EntityRepository;
|
||||||
use FOS\CKEditorBundle\Form\Type\CKEditorType;
|
use FOS\CKEditorBundle\Form\Type\CKEditorType;
|
||||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||||
use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface;
|
use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface;
|
||||||
|
@ -87,7 +89,7 @@ class BaseEntityAdminForm extends AbstractType
|
||||||
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ])
|
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ])
|
||||||
|
|
||||||
->add('parent', StructuralEntityType::class, ['class' => get_class($entity),
|
->add('parent', StructuralEntityType::class, ['class' => get_class($entity),
|
||||||
'required' => false, 'label' => $this->trans->trans('parent.label'),
|
'required' => false, 'label' => $this->trans->trans('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, ['required' => false,
|
->add('not_selectable', CheckboxType::class, ['required' => false,
|
||||||
|
@ -101,7 +103,7 @@ class BaseEntityAdminForm extends AbstractType
|
||||||
'attr' => ['rows' => 4], 'help' => $this->trans->trans('bbcode.hint'),
|
'attr' => ['rows' => 4], 'help' => $this->trans->trans('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);
|
||||||
|
|
||||||
//Attachment section
|
//Attachment section
|
||||||
$builder->add('attachments', CollectionType::class, [
|
$builder->add('attachments', CollectionType::class, [
|
||||||
|
@ -116,11 +118,18 @@ class BaseEntityAdminForm extends AbstractType
|
||||||
'by_reference' => false
|
'by_reference' => false
|
||||||
]);
|
]);
|
||||||
|
|
||||||
//Buttons
|
$builder->add('master_picture_attachment', MasterPictureAttachmentType::class, [
|
||||||
$builder->add('save', SubmitType::class, [
|
'required' => false,
|
||||||
'label' => $is_new ? $this->trans->trans('entity.create') : $this->trans->trans('entity.edit.save'),
|
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
|
||||||
'attr' => ['class' => $is_new ? 'btn-success' : ''],
|
'label' => $this->trans->trans('part.edit.master_attachment'),
|
||||||
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)])
|
'entity' => $entity
|
||||||
|
]);
|
||||||
|
|
||||||
|
//Buttons
|
||||||
|
$builder->add('save', SubmitType::class, [
|
||||||
|
'label' => $is_new ? $this->trans->trans('entity.create') : $this->trans->trans('entity.edit.save'),
|
||||||
|
'attr' => ['class' => $is_new ? 'btn-success' : ''],
|
||||||
|
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)])
|
||||||
->add('reset', ResetType::class, ['label' => 'entity.edit.reset',
|
->add('reset', ResetType::class, ['label' => 'entity.edit.reset',
|
||||||
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)]);
|
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,7 @@ use App\Entity\Parts\Part;
|
||||||
use App\Entity\Parts\Storelocation;
|
use App\Entity\Parts\Storelocation;
|
||||||
use App\Entity\PriceInformations\Orderdetail;
|
use App\Entity\PriceInformations\Orderdetail;
|
||||||
use App\Form\AttachmentFormType;
|
use App\Form\AttachmentFormType;
|
||||||
|
use App\Form\Type\MasterPictureAttachmentType;
|
||||||
use App\Form\Type\SIUnitType;
|
use App\Form\Type\SIUnitType;
|
||||||
use App\Form\Type\StructuralEntityType;
|
use App\Form\Type\StructuralEntityType;
|
||||||
use Doctrine\DBAL\Types\FloatType;
|
use Doctrine\DBAL\Types\FloatType;
|
||||||
|
@ -219,28 +220,11 @@ class PartBaseType extends AbstractType
|
||||||
'by_reference' => false
|
'by_reference' => false
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$builder->add('master_picture_attachment', EntityType::class, [
|
$builder->add('master_picture_attachment', MasterPictureAttachmentType::class, [
|
||||||
'required' => false,
|
'required' => false,
|
||||||
'disabled' => !$this->security->isGranted('attachments.edit', $part),
|
'disabled' => !$this->security->isGranted('attachments.edit', $part),
|
||||||
'label' => $this->trans->trans('part.edit.master_attachment'),
|
'label' => $this->trans->trans('part.edit.master_attachment'),
|
||||||
'class' => PartAttachment::class,
|
'entity' => $part
|
||||||
'attr' => ['class' => 'selectpicker'],
|
|
||||||
'choice_attr' => function ($choice, $key, $value) {
|
|
||||||
/** @var Attachment $choice */
|
|
||||||
return ['data-subtext' => $choice->getFilename() ?? "URL"];
|
|
||||||
},
|
|
||||||
'choice_label' => 'name',
|
|
||||||
'query_builder' => function (EntityRepository $er) use ($part) {
|
|
||||||
if ($part->getID() == null) {
|
|
||||||
//This query is always false, so we get empty results
|
|
||||||
return $er->createQueryBuilder('u')->where('0 = 2');
|
|
||||||
}
|
|
||||||
return $er->createQueryBuilder('u')
|
|
||||||
->where('u.element = ?1')
|
|
||||||
->andWhere("u.path <> ''")
|
|
||||||
->orderBy('u.name', 'ASC')
|
|
||||||
->setParameter(1, $part);
|
|
||||||
}
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
//Orderdetails section
|
//Orderdetails section
|
||||||
|
|
95
src/Form/Type/MasterPictureAttachmentType.php
Normal file
95
src/Form/Type/MasterPictureAttachmentType.php
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* part-db version 0.1
|
||||||
|
* Copyright (C) 2005 Christoph Lechner
|
||||||
|
* http://www.cl-projects.de/
|
||||||
|
*
|
||||||
|
* part-db version 0.2+
|
||||||
|
* Copyright (C) 2009 K. Jacobs and others (see authors.php)
|
||||||
|
* http://code.google.com/p/part-db/
|
||||||
|
*
|
||||||
|
* Part-DB Version 0.4+
|
||||||
|
* Copyright (C) 2016 - 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\Form\Type;
|
||||||
|
|
||||||
|
|
||||||
|
use App\Entity\Attachments\Attachment;
|
||||||
|
use App\Entity\Attachments\AttachmentContainingDBElement;
|
||||||
|
use Doctrine\ORM\EntityRepository;
|
||||||
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||||
|
use Symfony\Component\Form\AbstractType;
|
||||||
|
use Symfony\Component\OptionsResolver\Options;
|
||||||
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
|
||||||
|
class MasterPictureAttachmentType extends AbstractType
|
||||||
|
{
|
||||||
|
|
||||||
|
public function configureOptions(OptionsResolver $resolver)
|
||||||
|
{
|
||||||
|
$resolver->setRequired('entity');
|
||||||
|
$resolver->setAllowedTypes('entity', AttachmentContainingDBElement::class);
|
||||||
|
|
||||||
|
$resolver->setDefaults([
|
||||||
|
'filter' => 'picture',
|
||||||
|
'attr' => ['class' => 'selectpicker'],
|
||||||
|
'choice_attr' => function (Options $options) {
|
||||||
|
return function ($choice, $key, $value) use ($options) {
|
||||||
|
/** @var Attachment $choice */
|
||||||
|
$tmp = ['data-subtext' => $choice->getFilename() ?? 'URL'];
|
||||||
|
|
||||||
|
if ($options['filter'] === 'picture' && !$choice->isPicture()) {
|
||||||
|
$tmp += ['disabled' => 'disabled'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $tmp;
|
||||||
|
};
|
||||||
|
},
|
||||||
|
'choice_label' => 'name',
|
||||||
|
'class' => function (Options $options) {
|
||||||
|
$short_class_name = (new \ReflectionClass($options['entity']))->getShortName();
|
||||||
|
//Category becomes CategoryAttachment
|
||||||
|
return 'App\\Entity\\Attachments\\' . $short_class_name . 'Attachment';
|
||||||
|
},
|
||||||
|
'query_builder' => function (Options $options) {
|
||||||
|
return function (EntityRepository $er) use ($options) {
|
||||||
|
$entity = $options['entity'];
|
||||||
|
if ($entity->getID() === null) {
|
||||||
|
//This query is always false, so we get empty results
|
||||||
|
return $er->createQueryBuilder('u')->where('0 = 2');
|
||||||
|
}
|
||||||
|
return $er->createQueryBuilder('u')
|
||||||
|
->where('u.element = ?1')
|
||||||
|
->andWhere("u.path <> ''")
|
||||||
|
->orderBy('u.name', 'ASC')
|
||||||
|
->setParameter(1, $entity);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
|
$resolver->setAllowedValues('filter', ['', 'picture', '3d_models']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getParent()
|
||||||
|
{
|
||||||
|
return EntityType::class;
|
||||||
|
}
|
||||||
|
}
|
|
@ -67,6 +67,10 @@
|
||||||
{% trans %}attachment.create{% endtrans %}
|
{% trans %}attachment.create{% endtrans %}
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
{% block master_picture_block %}
|
||||||
|
{{ form_row(form.master_picture_attachment) }}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
function delete_attachment_entry(btn) {
|
function delete_attachment_entry(btn) {
|
||||||
window.bootbox.confirm('{% trans %}part_lot.edit.delete.confirm{% endtrans %}', function (result) {
|
window.bootbox.confirm('{% trans %}part_lot.edit.delete.confirm{% endtrans %}', function (result) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue