Commit 4f755cff authored by Guillaume Perréal's avatar Guillaume Perréal
Browse files

Ajout d'un CRUD pour les fichiers uploadés.

Showing with 226 additions and 1 deletion
+226 -1
<?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);
}
}
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
{% 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>&nbsp;</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) }}&nbsp;{{ 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 %}
{% 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 }}&nbsp;:</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 %}&nbsp;:</strong> {{ uploadedFile.id }}
</p>
<p>
<strong class="col-md-3">{% trans %}UploadedFile.displayName.label{% endtrans %}&nbsp;:</strong> {{ uploadedFile.displayName }}
</p>
<p>
<strong class="col-md-3">{% trans %}UploadedFile.path.label{% endtrans %}&nbsp;:</strong> {{ uploadedFile.path }}
</p>
<p>
<strong class="col-md-3">{% trans %}UploadedFile.description.label{% endtrans %}&nbsp;:</strong> {{ uploadedFile.description|default('-') }}
</p>
<p>
<strong class="col-md-3">{% trans %}UploadedFile.etat.label{% endtrans %}&nbsp;:</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 %}&nbsp;:</strong> {{ uploadedFile.mimeType|default('-') }}
</p>
<p>
<strong class="col-md-3">{% trans %}UploadedFile.size.label{% endtrans %}&nbsp;:</strong> {{ uploadedFile.size|irstea_file_size|default('-') }}
</p>
<p>
<strong class="col-md-3">{% trans %}UploadedFile.checksum.label{% endtrans %}&nbsp;:</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 %}&nbsp;:</strong> {{ uploadedFile.createdAt|localizeddate('medium', 'medium') }}
</p>
<p>
<strong class="col-md-3">{% trans %}UploadedFile.createdBy.label{% endtrans %}&nbsp;:</strong> {{ uploadedFile.createdBy|default('-') }}
</p>
<p>
<strong class="col-md-3">{% trans %}UploadedFile.createdFrom.label{% endtrans %}&nbsp;:</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 %}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment