diff --git a/Controller/UploadedFileController.php b/Controller/UploadedFileController.php new file mode 100644 index 0000000000000000000000000000000000000000..048dc3f454df8f4c76d25ea0dd00a44227782986 --- /dev/null +++ b/Controller/UploadedFileController.php @@ -0,0 +1,71 @@ +<?php + +namespace Irstea\FileUploadBundle\Controller; + +use Symfony\Component\HttpFoundation\Request; +use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; +use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; +use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; +use Irstea\FileUploadBundle\Entity\UploadedFile; + +use Pagerfanta\Adapter\DoctrineORMAdapter; +use Pagerfanta\Pagerfanta; + +/** + * UploadedFile controller. + * + * @Route("/files") + */ +class UploadedFileController extends Controller +{ + /** + * Lists all UploadedFile entities. + * + * @Route("/", name="files") + * @Method("GET") + * @Template() + */ + public function indexAction(Request $request) + { + $em = $this->getDoctrine()->getManager(); + + $queryBuilder = $em->getRepository('IrsteaFileUploadBundle:UploadedFile') + ->createQueryBuilder("u") + ->orderBy("u.createdAt", "DESC"); + + $pager = new Pagerfanta(new DoctrineORMAdapter($queryBuilder)); + $pager->setCurrentPage($request->query->get("page", 1)); + + $uploadedFiles = $pager->getCurrentPageResults(); + + return [ + 'uploadedFiles' => $uploadedFiles, + 'pager' => $pager, + ]; + } + + /** + * Finds and displays a UploadedFile entity. + * + * @Route("/{id}", name="files_show") + * @Method("GET") + * @Template() + */ + public function showAction(UploadedFile $uploadedFile) + { + + return [ + 'uploadedFile' => $uploadedFile, + ]; + } + + /** + * @param string $message + * @param array $parameters + */ + public function notice($message, array $parameters = []) + { + $this->get('monolog.logger.irstea_logger')->notice($message, $parameters); + } +} diff --git a/Resources/translations/messages.fr.yml b/Resources/translations/messages.fr.yml index bdbe1a71211153dce22ae1037e90b7618debb097..a3cd90195829a8ad6ac0c2bd41ad24a24aa3c828 100644 --- a/Resources/translations/messages.fr.yml +++ b/Resources/translations/messages.fr.yml @@ -1,2 +1,26 @@ +button.upload: 'Ajouter un fichier' -button.upload: Ajouter un fichier +UploadedFile: + index: + title: Liste des fichiers + breadcrumb: Fichiers + id.label: Identifiant + displayName.label: Nom + etat: + label: Etat + en-cours: En cours + orphelin: Orphelin + normal: Normal + corrompu: Corrompu + manquant: Manquant + rejete: Refusé + mimeType.label: Type MIME + size.label: Taille + checksum.label: Somme de contrôle + createdAt.label: Date de création + show.title(%uploadedFile%): Fichier %uploadedFile% + path.label: Chemin + createdBy.label: Créateur + createdFrom.label: Adresse IP + metadata.label: Métadonnées + description.label: Description diff --git a/Resources/views/UploadedFile/index.html.twig b/Resources/views/UploadedFile/index.html.twig new file mode 100644 index 0000000000000000000000000000000000000000..73092aa4018e5b98986214f119754f5d16d98b22 --- /dev/null +++ b/Resources/views/UploadedFile/index.html.twig @@ -0,0 +1,44 @@ +{% extends '::base.html.twig' %} + +{% block titrePage %}{% trans %}UploadedFile.index.title{% endtrans %}{% endblock titrePage %} + +{% block breadcrumb_content %} + <li>{% trans %}UploadedFile.index.breadcrumb{% endtrans %}</li> +{% endblock breadcrumb_content %} + + +{% block content -%} + <table class="table table-striped records_list"> + <thead> + <tr> + <th>{% trans %}UploadedFile.id.label{% endtrans %}</th> + <th>{% trans %}UploadedFile.displayName.label{% endtrans %}</th> + <th>{% trans %}UploadedFile.etat.label{% endtrans %}</th> + <th>{% trans %}UploadedFile.mimeType.label{% endtrans %}</th> + <th>{% trans %}UploadedFile.size.label{% endtrans %}</th> + <th>{% trans %}UploadedFile.createdAt.label{% endtrans %}</th> + <th> </th> + </tr> + </thead> + <tbody> + {% for uploadedFile in uploadedFiles %} + <tr> + <td><a href="{{ path('files_show', { 'id': uploadedFile.id }) }}">{{ uploadedFile.id }}</a></td> + <td>{{ uploadedFile.displayName }}</td> + <td><span class="label label-{{ uploadedFile.etat == 'orphelin' ? 'warning' : (uploadedFile.etat == 'normal' ? 'success' : (uploadedFile.etat == 'en-cours' ? 'default' : 'danger')) }}">{{ uploadedFile.etat }}</span></td> + <td>{% if uploadedFile.mimeType is not empty %}{{ irstea_file_icon(uploadedFile.mimeType) }} {{ uploadedFile.mimeType }}{% else %}-{% endif %}</td> + <td>{{ uploadedFile.size|irstea_file_size|default('-') }}</td> + <td>{% if uploadedFile.createdAt %}{{ uploadedFile.createdAt|localizeddate('medium', 'medium') }}{% endif %}</td> + <td> + <a class="btn btn-xs btn-default" title="{% trans %}button.show{% endtrans %}" href="{{ path('files_show', { 'id': uploadedFile.id }) }}">{{ irstea_icon("search") }}</a> + </td> + </tr> + {% endfor %} + </tbody> + <tfoot> + <tr> + <td colspan="13"><div class="pagerfanta pull-right">{{ pagerfanta(pager) }}</div></td> + </tr> + </tfoot> + </table> +{% endblock %} diff --git a/Resources/views/UploadedFile/show.html.twig b/Resources/views/UploadedFile/show.html.twig new file mode 100644 index 0000000000000000000000000000000000000000..608aa7823ecd5094221d2371c48344670c374ebd --- /dev/null +++ b/Resources/views/UploadedFile/show.html.twig @@ -0,0 +1,86 @@ +{% extends '::base.html.twig' %} + +{% block titrePage %}{% trans %}UploadedFile.show.title(%uploadedFile%){% endtrans %}{% endblock titrePage %} + +{% block breadcrumb_content %} + <li><a href="{{ path('files') }}">{% trans %}UploadedFile.index.breadcrumb{% endtrans %}</a></li> + <li>{{ uploadedFile }}</li> +{% endblock breadcrumb_content %} + +{% block content_right_header %} +{% endblock content_right_header %} + +{% macro prettyPrint(data) %} + {%- if data is iterable and data is not empty %} + <div style="margin: 0.2em 0 1em 2em"> + {%- for key, value in data %} + <div><strong>{{ key }} :</strong> {{ _self.prettyPrint(value) }}</div> + {%- endfor %} + </div> + {%- else %} + {{- data|json_encode }} + {%- endif %} +{% endmacro %} + +{% block content -%} + <div class="row"> + <div class="col-md-6"> + <div class="panel panel-default"> + <div class="panel-heading"><strong>Identification</strong></div> + <div class="panel-body row"> + <p> + <strong class="col-md-3">{% trans %}UploadedFile.id.label{% endtrans %} :</strong> {{ uploadedFile.id }} + </p> + <p> + <strong class="col-md-3">{% trans %}UploadedFile.displayName.label{% endtrans %} :</strong> {{ uploadedFile.displayName }} + </p> + <p> + <strong class="col-md-3">{% trans %}UploadedFile.path.label{% endtrans %} :</strong> {{ uploadedFile.path }} + </p> + <p> + <strong class="col-md-3">{% trans %}UploadedFile.description.label{% endtrans %} :</strong> {{ uploadedFile.description|default('-') }} + </p> + <p> + <strong class="col-md-3">{% trans %}UploadedFile.etat.label{% endtrans %} :</strong> <span class="label label-{{ uploadedFile.etat == 'orphelin' ? 'warning' : (uploadedFile.etat == 'normal' ? 'success' : (uploadedFile.etat == 'en-cours' ? 'default' : 'danger')) }}">{{ uploadedFile.etat }}</span> + </p> + </div> + </div> + <div class="panel panel-default"> + <div class="panel-heading"><strong>Contenu</strong></div> + <div class="panel-body row"> + <p> + <strong class="col-md-3">{% trans %}UploadedFile.mimeType.label{% endtrans %} :</strong> {{ uploadedFile.mimeType|default('-') }} + </p> + <p> + <strong class="col-md-3">{% trans %}UploadedFile.size.label{% endtrans %} :</strong> {{ uploadedFile.size|irstea_file_size|default('-') }} + </p> + <p> + <strong class="col-md-3">{% trans %}UploadedFile.checksum.label{% endtrans %} :</strong> {{ uploadedFile.checksum|default('-') }} + </p> + </div> + </div> + <div class="panel panel-default"> + <div class="panel-heading"><strong>Création</strong></div> + <div class="panel-body row"> + <p> + <strong class="col-md-3">{% trans %}UploadedFile.createdAt.label{% endtrans %} :</strong> {{ uploadedFile.createdAt|localizeddate('medium', 'medium') }} + </p> + <p> + <strong class="col-md-3">{% trans %}UploadedFile.createdBy.label{% endtrans %} :</strong> {{ uploadedFile.createdBy|default('-') }} + </p> + <p> + <strong class="col-md-3">{% trans %}UploadedFile.createdFrom.label{% endtrans %} :</strong> {{ uploadedFile.createdFrom|default('-') }} + </p> + </div> + </div> + </div> + <div class="col-md-6"> + <div class="panel panel-default"> + <div class="panel-heading"><strong>Méta-données</strong></div> + <div class="panel-body row"> + {{ _self.prettyPrint(uploadedFile.metadata) }} + </div> + </div> + </div> + </div> +{% endblock %}