Skip to content

Commit

Permalink
afup#1461 General Meeting reports
Browse files Browse the repository at this point in the history
  • Loading branch information
stakovicz committed Mar 19, 2024
1 parent d144045 commit 74666d5
Show file tree
Hide file tree
Showing 7 changed files with 230 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
Préparer une assemblée générale
</div>
</a>
<a href="{{ path('admin_members_general_meeting_reports') }}" class="item">
<div data-tooltip="Lister/ajouter/modifier des CR d'AGs" data-position="bottom left">
<i class="icon file pdf"></i>
Liste des comptes rendus
</div>
</a>
</div>

{% if latestDate %}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{% extends 'admin/base_with_header.html.twig' %}

{% block content %}
<h2>Assemblée générale - Comptes rendus</h2>
<div class="ui segment">
<h3 class="ui header">Ajouter un compte rendu</h3>
<div class="ui grid">
<div class="six wide column">
{{ form_start(form) }}
<div class="ui form">
<div class="field">
{{ form_row(form.file) }}
</div>
<div class="field">
{{ form_row(form.submit, {attr: {class: "ui primary button"}}) }}
</div>
</div>
{{ form_end(form) }}
</div>
<div class="ten wide column">
<ul>
<li>Fichiers PDF uniquement</li>
<li>Format de nommage : <code>YYYY-MM-JJ_CR AG AFUP YYYY-YYYY.pdf</code><br />
Exemple : <code>2014-02-15_CR AG AFUP 2013-2014.pdf</code></li>
</ul>
</div>
</div>
</div>


<h3 class="ui header">Liste des comptes rendus</h3>
<table class="ui table striped compact celled">
<thead>
<tr>
<th>Nom</th>
<th>Type</th>
<th>Poids</th>
<th>Date</th>
<th></th>
</tr>
</thead>
<tbody>
{% for report in reports %}
<tr>
<td>{{ report.filename }}</td>
<td>
{{ report.extension }}
</td>
<td>
{{ report.size }}
</td>
<td>
{{ report.mtime|date('d/m/y H:i') }}
</td>
<td>
<a href="{{ path('admin_members_general_meeting_reports', {file: report.basename}) }}"
data-position="left center"
data-tooltip="Supprimer le CR {{ report.filename }}"
class="compact ui red icon button confirmable"
data-confirmable-label="Êtes-vous sûr de vouloir supprimer le CR {{ report.basename }} ?"
>
<i class="trash icon"></i>
</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
1 change: 1 addition & 0 deletions app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ parameters:
- admin_members_general_meeting
- admin_members_general_meeting_prepare
- admin_members_general_meeting_edit
- admin_members_general_meeting_reports
assemblee_generale_votes:
nom: 'Assemblée générale - votes'
niveau: 'ROLE_ADMIN'
Expand Down
4 changes: 4 additions & 0 deletions app/config/routing/admin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ admin_members_general_vote_close:
path: /members/general_meeting_vote/close
defaults: {_controller: AppBundle\Controller\Admin\Members\GeneralMeetingVote\CloseAction}

admin_members_general_meeting_reports:
path: /members/general_meeting/reports
defaults: {_controller: AppBundle\Controller\Admin\Members\GeneralMeeting\ReportsAction}

admin_techletter:
resource: "techletter_admin.yml"
prefix: /techletter
Expand Down
9 changes: 9 additions & 0 deletions db/seeds/GeneralMeetings.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ class GeneralMeetings extends AbstractSeed
{
public function run()
{
$dir = 'htdocs/uploads/general_meetings_reports/';
if (!is_dir($dir)) {
if (!mkdir($dir) && !is_dir($dir)) {
throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir));
}
}
copy('tests/behat/files/test_file1.pdf', $dir.'2014-02-15_CR AG AFUP 2013-2014.pdf');
copy('tests/behat/files/test_file2.pdf', $dir.'2013-01-30_CR AG AFUP 2012-2013.pdf');

$timestamp = strtotime(date("Y-m-d") . "+2 months");

// Assemblées générales
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<?php

namespace AppBundle\Controller\Admin\Members\GeneralMeeting;

use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Validator\Constraints\File;
use Symfony\Component\Validator\Constraints\NotBlank;
use Twig\Environment;

class ReportsAction
{
/** @var Environment */
private $twig;
/** @var FlashBagInterface */
private $flashBag;
/** @var UrlGeneratorInterface */
private $urlGenerator;
/** @var FormFactoryInterface */
private $formFactory;

public function __construct(Environment $twig,
FlashBagInterface $flashBag,
UrlGeneratorInterface $urlGenerator,
FormFactoryInterface $formFactory)
{
$this->twig = $twig;
$this->flashBag = $flashBag;
$this->urlGenerator = $urlGenerator;
$this->formFactory = $formFactory;
}

public function __invoke(Request $request): Response
{
$basePath = 'uploads/general_meetings_reports/';

// delete
if ($fileToDelete = $request->query->get('file')) {
$fileToDelete = $basePath . basename($fileToDelete);
if (is_file($fileToDelete) && unlink($fileToDelete)) {
$this->flashBag->add('notice', 'Le compte rendu a correctement été supprimé.');
} else {
$this->flashBag->add('error', 'Le compte rendu n\'a pas été supprimé.');
}
return new RedirectResponse($this->urlGenerator->generate($request->attributes->get('_route')));
}

// add
$form = $this->buildForm();
if ($form->handleRequest($request) && $form->isValid()) {
/** @var UploadedFile $uploadedFile */
$reportFile = $form->get('file')->getData();
if ($reportFile->move($basePath, $reportFile->getClientOriginalName())) {
$this->flashBag->add('notice', 'Le compte rendu a correctement été ajouté.');
} else {
$this->flashBag->add('error', 'Le compte rendu n\'a pas été ajouté.');
}
return new RedirectResponse($this->urlGenerator->generate($request->attributes->get('_route')));
}

$files = glob($basePath . '*.pdf');
rsort($files);

$reports = [];
foreach ($files as $file) {
$report = pathinfo($file);

$report['size'] = self::humanFilesize(filesize($file));
$report['mtime'] = filemtime($file);
$reports[] = $report;
}

return new Response($this->twig->render('admin/members/general_meeting/reports.html.twig', [
'form' => $form->createView(),
'reports' => $reports
]));
}

private static function humanFilesize($bytes): string
{
$sz = 'BKMGTP';
$factor = floor((strlen($bytes) - 1) / 3);

return sprintf("%.2f", $bytes / (1024 ** $factor)) . $sz[(int) $factor];
}

private function buildForm(): FormInterface
{
return $this->formFactory->createNamed('report')
->add('file', FileType::class, [
'label' => 'Fichier',
'required' => true,
'constraints' => [
new NotBlank(),
new File([
'maxSize' => '2M',
'mimeTypes' => [
'application/pdf',
'application/x-pdf',
],
'mimeTypesMessage' => 'Uniquement des fichiers PDF.',
])
]
])
->add('submit', SubmitType::class, [
'label' => 'Envoyer',
]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Feature: Administration - Partie Assemblée Générale CR

@reloadDbWithTestData
Scenario: Accède à la liste des CR
Given I am logged in as admin and on the Administration
And I follow "Assemblée générale"
Then the ".content h2" element should contain "Assemblée générale"
When I follow "Liste des comptes rendus"

# Liste
Then the ".content h2" element should contain "Assemblée générale - Comptes rendus"
And I should see "2014-02-15_CR AG AFUP 2013-2014"

# Ajout
And I attach the file "test_file1.pdf" to "report_file"
And I press "report[submit]"
Then the ".content .message" element should contain "Le compte rendu a correctement été ajouté."
And I should see "test_file1"

# Suppression
And I follow the button of tooltip "Supprimer le CR test_file1"
Then the ".content .message" element should contain "Le compte rendu a correctement été supprimé."


0 comments on commit 74666d5

Please sign in to comment.