add validation of existing file

This commit is contained in:
Julien Fastré 2018-06-07 16:54:13 +02:00
parent 299491cb5b
commit fcc74c993d
11 changed files with 75 additions and 8 deletions

View File

@ -13,6 +13,7 @@ use Chill\PersonBundle\Entity\Person;
use Symfony\Component\Security\Core\Role\Role;
use Chill\PersonBundle\Security\Authorization\PersonVoter;
use Chill\DocStoreBundle\Security\Authorization\PersonDocumentVoter;
use Symfony\Component\Translation\TranslatorInterface;
/**
* @Route("/{_locale}/person/{person}/document")
@ -21,6 +22,18 @@ use Chill\DocStoreBundle\Security\Authorization\PersonDocumentVoter;
*/
class DocumentPersonController extends Controller
{
/**
*
* @var TranslatorInterface
*/
protected $translator;
public function __construct(TranslatorInterface $translator)
{
$this->translator = $translator;
}
/**
* @Route("/", name="person_document_index", methods="GET")
*/
@ -85,7 +98,11 @@ class DocumentPersonController extends Controller
$em->persist($document);
$em->flush();
$this->addFlash('success', $this->translator->trans("The document is successfully registered"));
return $this->redirectToRoute('person_document_index', ['person' => $person->getId()]);
} elseif ($form->isSubmitted() and !$form->isValid()) {
$this->addFlash('error', $this->translator->trans("This form contains errors"));
}
return $this->render('ChillDocStoreBundle:PersonDocument:new.html.twig', [
@ -129,9 +146,13 @@ class DocumentPersonController extends Controller
if ($form->isSubmitted() && $form->isValid()) {
$this->getDoctrine()->getManager()->flush();
$this->addFlash('success', $this->translator->trans("The document is successfully updated"));
return $this->redirectToRoute(
'person_document_edit',
['id' => $document->getId(), 'person' => $person->getId()]);
} elseif ($form->isSubmitted() and !$form->isValid()) {
$this->addFlash('error', $this->translator->trans("This form contains errors"));
}
return $this->render(

View File

@ -27,6 +27,7 @@ class ChillDocStoreExtension extends Extension implements PrependExtensionInterf
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
$loader->load('services/media.yml');
$loader->load('services/controller.yml');
}

View File

@ -6,7 +6,8 @@ use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Chill\MainBundle\Entity\HasScopeInterface;
use Chill\MainBundle\Entity\User;
use ChampsLibres\AsyncUploaderBundle\Validator\Constraints\AsyncFileExists;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\MappedSuperclass()
@ -22,6 +23,9 @@ class Document implements HasScopeInterface
/**
* @ORM\Column(type="text")
* @Assert\Length(
* min=2, max=250
* )
*/
private $title;
@ -44,6 +48,7 @@ class Document implements HasScopeInterface
* targetEntity="Chill\DocStoreBundle\Entity\StoredObject",
* cascade={"persist"}
* )
* @Assert\Valid()
*/
private $object;

View File

@ -6,6 +6,7 @@ namespace Chill\DocStoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use ChampsLibres\AsyncUploaderBundle\Model\AsyncFileInterface;
use ChampsLibres\AsyncUploaderBundle\Validator\Constraints\AsyncFileExists;
/**
* Represent a document stored in an object store
@ -14,6 +15,9 @@ use ChampsLibres\AsyncUploaderBundle\Model\AsyncFileInterface;
*
* @ORM\Entity()
* @ORM\Table("chill_doc.stored_object")
* @AsyncFileExists(
* message="The file is not stored properly"
* )
*/
class StoredObject implements AsyncFileInterface
{

View File

@ -65,7 +65,9 @@ class PersonDocumentType extends AbstractType
->add('description', TextareaType::class, [
'required' => false
])
->add('object', StoredObjectType::class)
->add('object', StoredObjectType::class, [
'error_bubbling' => true
])
->add('scope', ScopePickerType::class, [
'center' => $options['center'],
'role' => $options['role']

View File

@ -0,0 +1,8 @@
services:
Chill\DocStoreBundle\Controller\:
resource: '../../../Controller'
tags: ['controller.service_arguments']
Chill\DocStoreBundle\Controller\DocumentPersonController:
autowire: true

View File

@ -0,0 +1,2 @@
## YAML Template.
---

View File

@ -0,0 +1 @@
The file is not stored properly: Le fichier n'est pas téléchargé correctement

View File

@ -1 +0,0 @@
{{ form_widget(form) }}

View File

@ -17,14 +17,32 @@
{% extends "ChillPersonBundle::layout.html.twig" %}
{% import "@ChillDocStore/Macro/macro.html.twig" as m %}
{% set activeRouteKey = '' %}
{% block title %}{{ 'Editing document for %name%'|trans({ '%name%': person.firstName|capitalize ~ ' ' ~ person.lastName } )|capitalize }}{% endblock %}
{% block personcontent %}
<h1>{{ 'Edit Document' | trans }}</h1>
{{ form_errors(form) }}
{{ form_start(form) }}
{{ include('ChillDocStoreBundle:PersonDocument:_form.html.twig', {'button_label': 'Update'}) }}
{{ form_row(form.title) }}
{{ form_row(form.date) }}
{{ form_row(form.category) }}
{{ form_row(form.scope) }}
{{ form_row(form.description) }}
<div class="container">
<div class="grid-4 clear">
<label>{{ 'Existing document'|trans }}</label>
</div>
<div class="grid-8">
{{ m.download_button(document.object, document.title) }}
</div>
</div>
{{ form_row(form.object, { 'label': 'Document', 'existing': document.object }) }}
<ul class="record_actions">
<li class="cancel">
@ -35,14 +53,18 @@
<li class="edit">
<button class="sc-button bt-edit">{{ 'Edit'|trans }}</button>
</li>
{% if is_granted('CHILL_PERSON_DOCUMENT_DELETE', document) %}
{# {% if is_granted('CHILL_PERSON_DOCUMENT_DELETE', document) %}
<li class="delete">
{{ include('ChillDocStoreBundle:PersonDocument:_delete_form.html.twig') }}
</li>
{% endif %}
{% endif %} #}
</ul>
{{ form_end(form) }}
{% endblock %}
{% block js %}
<script src="{{ asset('build/async_upload.js') }}" type="text/javascript"></script>
{% endblock %}

View File

@ -23,8 +23,10 @@
{% block personcontent %}
<h1>{{ 'Create new Document' | trans }}</h1>
{{ form_errors(form) }}
{{ form_start(form) }}
{{ include('ChillDocStoreBundle:PersonDocument:_form.html.twig') }}
{{ form_widget(form) }}
<ul class="record_actions">
<li class="cancel">