Skip to content

Commit

Permalink
Fix on document upload (#124)
Browse files Browse the repository at this point in the history
* Fix error on view to upload a document for an Etude

* Improve UI for Etude and Member selection on Upload Doctype view

* Fix reference selection for Doctypes

* Improve code style and quality
  • Loading branch information
Stoakes authored Jul 9, 2017
1 parent d2be95c commit 41283ab
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 59 deletions.
Empty file added .styleci.yml
Empty file.
49 changes: 26 additions & 23 deletions src/Mgate/PubliBundle/Controller/DocumentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
use Mgate\PubliBundle\Entity\Document;
use Mgate\PubliBundle\Entity\RelatedDocument;
use Mgate\PubliBundle\Form\Type\DocumentType;
use Mgate\SuiviBundle\Entity\Etude;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
Expand Down Expand Up @@ -46,13 +48,15 @@ public function indexAction()

/**
* @Security("has_role('ROLE_CA')")
*
* @param Document $documentType (ParamConverter) The document to be downloaded.
* @return BinaryFileResponse
*
* @throws \Exception
*/
public function voirAction(Document $documentType)
{
$documentStoragePath = $this->get('kernel')->getRootDir(). '' . Document::DOCUMENT_STORAGE_ROOT;
$documentStoragePath = $this->get('kernel')->getRootDir() . '' . Document::DOCUMENT_STORAGE_ROOT;
if (file_exists($documentStoragePath . '/' . $documentType->getPath())) {
$response = new BinaryFileResponse($documentStoragePath . '/' . $documentType->getPath());
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT);
Expand All @@ -65,28 +69,23 @@ public function voirAction(Document $documentType)

/**
* @Security("has_role('ROLE_SUIVEUR')")
*
* @param Request $request
* @param Etude $etude
*
* @return Response
*/
public function uploadEtudeAction(Request $request, $etude_id)
public function uploadEtudeAction(Request $request, Etude $etude)
{
$em = $this->getDoctrine()->getManager();
$etude = $em->getRepository('MgateSuiviBundle:Etude')->getByNom($etude_id);

if (!$etude) {
throw $this->createNotFoundException('Le document ne peut être lié à une étude qui n\'existe pas!');
}

if ($this->get('Mgate.etude_manager')->confidentielRefus($etude, $this->getUser(), $this->get('security.authorization_checker'))) {
throw new AccessDeniedException('Cette étude est confidentielle !');
}

$options['etude'] = $etude;

if (!$response = $this->upload($request, false, $options)) {
// Si tout est ok
if (!$response = $this->upload($request, false, ['etude' => $etude])) {
$this->addFlash('success', 'Document mis en ligne');
return $this->redirect($this->generateUrl('MgateSuivi_etude_voir', array('nom' => $etude->getNom())));
} else {
return $response;
}
return $response;
}

/**
Expand All @@ -104,7 +103,7 @@ public function uploadEtudiantAction(Request $request, $membre_id)
$options['etudiant'] = $membre;

if (!$response = $this->upload($request, false, $options)) {
$this->addFlash('success','Document mis en ligne');
$this->addFlash('success', 'Document mis en ligne');
return $this->redirect($this->generateUrl('MgatePersonne_membre_voir', array('id' => $membre_id)));
} else {
return $response;
Expand All @@ -120,6 +119,10 @@ public function uploadFormationAction($id)

/**
* @Security("has_role('ROLE_ADMIN')")
*
* @param Request $request
*
* @return Response
*/
public function uploadDoctypeAction(Request $request)
{
Expand All @@ -133,23 +136,23 @@ public function uploadDoctypeAction(Request $request)

/**
* @Security("has_role('ROLE_CA')")
*
* @param Document $doc
*
* @return Response
*/
public function deleteAction($id, Request $request)
public function deleteAction(Document $doc)
{
$em = $this->getDoctrine()->getManager();

if (!$doc = $em->getRepository('MgatePubliBundle:Document')->find($id)) {
throw $this->createNotFoundException('Le Document n\'existe pas !');
}
$doc->setRootDir($this->get('kernel')->getRootDir());

if ($doc->getRelation()) { // Cascade sucks
$relation = $doc->getRelation()->setDocument();
$doc->setRelation();
$doc->setRelation(null);
$em->remove($relation);
$em->flush();
}
$request->getSession()->getFlashBag()->add('success', 'Document supprimé');
$this->addFlash('success', 'Document supprimé');
$em->remove($doc);
$em->flush();

Expand Down
2 changes: 1 addition & 1 deletion src/Mgate/PubliBundle/Form/Type/DocTypeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
->add('etude', Select2EntityType::class, array(
'label' => 'Etude pour vérifier le template',
'class' => 'Mgate\\SuiviBundle\\Entity\\Etude',
'choice_label' => 'reference',
'choice_label' => 'nom',
'required' => false, ))
->add('verification', CheckboxType::class, array('label' => 'Activer la vérification', 'required' => false));
}
Expand Down
52 changes: 28 additions & 24 deletions src/Mgate/PubliBundle/Form/Type/RelatedDocumentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,39 +22,43 @@ public function buildForm(FormBuilderInterface $builder, array $options)
{
if ($options['etude']) {
$builder->add('etude', Select2EntityType::class, array(
'class' => 'Mgate\SuiviBundle\Entity\Etude',
'choice_label' => 'reference',
'required' => false,
'label' => 'Document lié à l\'étude',
'configs' => array('placeholder' => 'Sélectionnez une étude', 'allowClear' => true),
));
'class' => 'Mgate\SuiviBundle\Entity\Etude',
'choice_label' => 'nom',
'required' => false,
'label' => 'Document lié à l\'étude',
'data' => $options['etude'],
'attr' => array('style' => 'min-width: 300px'),
'configs' => array('placeholder' => 'Sélectionnez une étude', 'allowClear' => true),
));
}
if ($options['prospect']) {
$builder->add('prospect', Select2EntityType::class, array(
'class' => 'Mgate\PersonneBundle\Entity\Prospect',
'choice_label' => 'nom',
'required' => false,
'label' => 'Document lié au prospect',
'configs' => array('placeholder' => 'Sélectionnez un prospect', 'allowClear' => true),
));
'class' => 'Mgate\PersonneBundle\Entity\Prospect',
'choice_label' => 'nom',
'required' => false,
'label' => 'Document lié au prospect',
'attr' => array('style' => 'min-width: 300px'),
'configs' => array('placeholder' => 'Sélectionnez un prospect', 'allowClear' => true),
));
}
if ($options['formation']) {
$builder->add('formation', Select2EntityType::class, array(
'class' => 'Mgate\FormationBundle\Entity\Formation',
'choice_label' => 'titre',
'required' => false,
'label' => 'Document lié à la formation',
'configs' => array('placeholder' => 'Sélectionnez une formation', 'allowClear' => true),
));
'class' => 'Mgate\FormationBundle\Entity\Formation',
'choice_label' => 'titre',
'required' => false,
'label' => 'Document lié à la formation',
'attr' => array('style' => 'min-width: 300px'),
'configs' => array('placeholder' => 'Sélectionnez une formation', 'allowClear' => true),
));
}
if ($options['etudiant'] || $options['etude']) {
$builder->add('membre', Select2EntityType::class, array(
'label' => 'Document lié à l\'étudiant',
'class' => 'Mgate\\PersonneBundle\\Entity\\Membre',
'choice_label' => 'personne.prenomNom',
'required' => false,
'configs' => array('placeholder' => 'Sélectionnez un étudiant', 'allowClear' => true), ))
;
'label' => 'Document lié à l\'étudiant (optionnel)',
'class' => 'Mgate\\PersonneBundle\\Entity\\Membre',
'choice_label' => 'personne.prenomNom',
'required' => false,
'attr' => array('style' => 'min-width: 300px'),
'configs' => array('placeholder' => 'Sélectionnez un étudiant', 'allowClear' => true),));
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/Mgate/PubliBundle/Resources/config/routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ Mgate_publi_document_voir:
methods: [GET, HEAD]

Mgate_publi_document_uploadEtude:
path: /Documents/Upload/Etude/{etude_id}
path: /Documents/Upload/Etude/{nom}
defaults: {_controller: MgatePubliBundle:Document:uploadEtude}
requirements:
etude_id: \d+
methods: [GET, HEAD, POST]

Mgate_publi_document_uploadEtudiant:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
</tr>
<tr>
<td>{{ form_label(form.etude) }}</td>
<td>{{ form_widget(form.etude) }}</td>
<td>{{ form_widget(form.etude, {'attr': {'style': 'min-width: 300px'}}) }}</td>
</tr>
<tr>
<td>{{ form_label(form.etudiant) }}</td>
<td>{{ form_widget(form.etudiant) }}</td>
<td>{{ form_widget(form.etudiant, {'attr': {'style': 'min-width: 300px'}}) }}</td>
</tr>
<tr>
<td>{{ form_label(form.verification) }}</td>
Expand Down
19 changes: 15 additions & 4 deletions src/Mgate/PubliBundle/Resources/views/Document/upload.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,25 @@
{% endblock %}

{% block content_title %}
Uploader un document
Uploader un document
{% endblock %}

{% block content_bundle %}
{{ form_start(form) }}
{{ form_widget(form) }}

<input type="submit" value="Uploader" class="btn btn-warning"/>
{{ form_start(form, {'attr': {'class': 'form-horizontal'}}) }}
{% for field in form.children if field.vars.name != "_token" %}
<div class="form-group">
<div class="col-lg-3 col-xs-4">
{{ form_label(field) }}
{{ form_errors(field) }}
</div>
<div class="col-lg-8">
{{ form_widget(field, {'attr': {'class': (field is not iterable ? 'form-control': '')}}) }}
</div>
</div>
{% endfor %}

<button type="submit" class="btn btn-warning">Mettre en ligne</button>
{{ form_end(form) }}
{% endblock %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</div>
<div class="collapse navbar-collapse navbar-suivi">
<ul class="nav navbar-nav">
<li><a href="{{ path('Mgate_publi_document_uploadEtude', {'etude_id': etude.nom}) }}"><span class="fa fa-pencil"></span> {{ 'suivi.document_ajouter'|trans({}, 'suivi') }}</a></li>
<li><a href="{{ path('Mgate_publi_document_uploadEtude', {'nom': etude.nom}) }}"><span class="fa fa-pencil"></span> {{ 'suivi.document_ajouter'|trans({}, 'suivi') }}</a></li>
</ul>
</div>
</nav>
Expand Down
2 changes: 1 addition & 1 deletion src/Mgate/TresoBundle/Form/Type/BVType.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
->add('mission', Select2EntityType::class, array(
'label' => 'Mission',
'class' => 'Mgate\\SuiviBundle\\Entity\\Mission',
'choice_label' => 'reference',
'choice_label' => 'nom',
'required' => true, ))
->add('numeroVirement', TextType::class, array('label' => 'Numéro de Virement', 'required' => true));
}
Expand Down

0 comments on commit 41283ab

Please sign in to comment.