trie sur widget fichier

This commit is contained in:
afornerot 2020-09-21 16:47:57 +02:00
parent 9947b7db23
commit ea2af3b861
2 changed files with 49 additions and 8 deletions

View File

@ -25,6 +25,7 @@ class FileController extends Controller
$subdirectory=$request->get("subdirectory");
$clear=$request->get("clear");
$view=$request->get("view");
$sort=$request->get("sort");
$defaultview=$request->get("defaultview");
// Récupérer en session le dernier subdirectory visité
@ -53,6 +54,14 @@ class FileController extends Controller
$sessionviewdirectory[$directory] = $view;
$this->get('session')->set('sessionviewdirectory',$sessionviewdirectory);
// Récupérer en session le trie
$sessionviewsort = $this->get('session')->get('sessionviewsort');
if(!is_array($sessionviewsort)) $sessionviewsort=[$sort=>"name"];
if(!array_key_exists($directory,$sessionviewsort)) $sessionviewsort[$directory]="name";
if($sort)
$sessionviewsort[$directory] = $sort;
$this->get('session')->set('sessionviewsort',$sessionviewsort);
// Construire le chemin réel
$iddirectory=explode("-",$directory)[1];
@ -79,6 +88,7 @@ class FileController extends Controller
if(is_dir($file)) {
$tmp=[];
$tmp["name"]=$file->getRelativePathname();
$tmp["date"]=date ("d/m/Y H:i", filemtime($file));
array_push($dirs,$tmp);
}
else {
@ -88,6 +98,7 @@ class FileController extends Controller
$fileinfo = new file($file->getPathname());
$tmp["minetype"]=$fileinfo->getMimeType();
$tmp["minefamily"]=explode("/",$tmp["minetype"])[0];
$tmp["date"] = date ("d/m/Y H:i", filemtime($file));
$tmp["thumb"]="";
if($tmp["extension"]=="pdf") {
@ -110,6 +121,13 @@ class FileController extends Controller
}
}
// Trie du tableu
$sort = array_column($files, $sessionviewsort[$directory]);
array_multisort($sort, SORT_ASC, $files);
$sort = array_column($dirs, $sessionviewsort[$directory]);
array_multisort($sort, SORT_ASC, $dirs);
return $this->render('CadolesCoreBundle:File:list.html.twig',[
'useheader' => false,
'usemenu' => false,
@ -125,6 +143,7 @@ class FileController extends Controller
'canupdate' => $canupdate,
'canadd' => $canupdate,
'view' => $sessionviewdirectory[$directory],
'sort' => $sessionviewsort[$directory],
]);
}

View File

@ -11,14 +11,21 @@
.grid .grid-list .grid-item-title h2 {
font-size: 14px;
line-height: 22px;
height: 22px;
line-height: 18px;
height: 18px
}
.grid .grid-list .grid-item-title {
padding:0px 0px 0px 5px;
line-height: 10px;
}
.grid-item-title h2 {
text-transform: initial !important;
}
{% endblock %}
{% block pagewrapper %}
@ -43,19 +50,34 @@
{% else %}
{%set action="small" %}
{% endif %}
{% if not subdirectory is empty %}
<a href="{{ path('cadoles_core_'~access~'_file_list',{'directory':directory,'subdirectory':subdirectory,'view':action }) }}" type="button" class="btn btn-primary">
{% else %}
<a href="{{ path('cadoles_core_'~access~'_file_list',{'directory':directory,'clear':true,'view':action }) }}" type="button" class="btn btn-primary">
{% endif %}
{% if view=="small" %}
<i class="fas fa-list"></i>
{% else %}
<i class="fas fa-th"></i>
{% endif %}
</a>
{% if sort=="name" %}
{%set action="date" %}
{% else %}
{%set action="name" %}
{% endif %}
{% if not subdirectory is empty %}
<a href="{{ path('cadoles_core_'~access~'_file_list',{'directory':directory,'subdirectory':subdirectory,'sort':action }) }}" type="button" class="btn btn-primary">
{% else %}
<a href="{{ path('cadoles_core_'~access~'_file_list',{'directory':directory,'clear':true,'sort':action }) }}" type="button" class="btn btn-primary">
{% endif %}
{% if sort=="name" %}
<i class="fas fa-sort-alpha-down"></i>
{% else %}
<i class="fas fa-sort-numeric-down"></i>
{% endif %}
</a>
</div>
</div>
@ -87,7 +109,7 @@
{% for dir in dirs|sort %}
{% for dir in dirs %}
<div class="grid-item grid-{{view}}">
<div class="grid-item-content">
{% if canadd %}
@ -108,7 +130,7 @@
</div>
<div class="grid-item-title">
<h2>{{ dir.name }}</h2>
<h2>{{ dir.name }}</h2>{% if view=="list" %}<small>le {{ dir.date }}</small>{%endif%}
</div>
</div>
</a>
@ -116,7 +138,7 @@
</div>
{% endfor %}
{% for file in files|sort %}
{% for file in files %}
<div class="grid-item grid-{{view}}">
<div class="grid-item-content">
{% if canadd %}
@ -140,7 +162,7 @@
</div>
<div class="grid-item-title">
<h2>{{ file.name }}</h2>
<h2>{{ file.name }}</h2>{% if view=="list" %}<small>le {{ file.date }}</small>{%endif%}
</div>
</div>
</a>