résolution anomalies widget fichier (ref #239)

This commit is contained in:
afornerot 2021-03-15 15:03:29 +01:00
parent 49e2527337
commit 81f4614680
3 changed files with 72 additions and 15 deletions

View File

@ -26,6 +26,7 @@ class FileController extends Controller
$clear=$request->get("clear"); $clear=$request->get("clear");
$view=$request->get("view"); $view=$request->get("view");
$sort=$request->get("sort"); $sort=$request->get("sort");
$order=$request->get("order");
$defaultview=$request->get("defaultview"); $defaultview=$request->get("defaultview");
// Récupérer les préférences utilisateur // Récupérer les préférences utilisateur
@ -68,7 +69,7 @@ class FileController extends Controller
$preference["widgetviewdirectory"][$directory]=$view; $preference["widgetviewdirectory"][$directory]=$view;
} }
// Prérence trie // Prérence trie
if(!array_key_exists("widgetsortdirectory",$preference)) { if(!array_key_exists("widgetsortdirectory",$preference)) {
$toupdate=true; $toupdate=true;
$preference["widgetsortdirectory"]=[]; $preference["widgetsortdirectory"]=[];
@ -82,6 +83,21 @@ class FileController extends Controller
$preference["widgetsortdirectory"][$directory]=$sort; $preference["widgetsortdirectory"][$directory]=$sort;
} }
// Préférence order
if(!array_key_exists("widgetorderdirectory",$preference)) {
$toupdate=true;
$preference["widgetorderdirectory"]=[];
}
if((!array_key_exists($directory,$preference["widgetorderdirectory"]))) {
$toupdate=true;
$preference["widgetorderdirectory"][$directory]="SORT_ASC";
}
if($sort&&$preference["widgetorderdirectory"][$directory]!=$order) {
$toupdate=true;
$preference["widgetorderdirectory"][$directory]=$order;
}
// Mise à jour des préferences // Mise à jour des préferences
if($toupdate) { if($toupdate) {
$em = $this->getDoctrine()->getManager(); $em = $this->getDoctrine()->getManager();
@ -115,17 +131,21 @@ class FileController extends Controller
if(is_dir($file)) { if(is_dir($file)) {
$tmp=[]; $tmp=[];
$tmp["name"]=$file->getRelativePathname(); $tmp["name"]=$file->getRelativePathname();
$tmp["namesort"]=strtolower($tmp["name"]);
$tmp["date"]=date ("d/m/Y H:i", filemtime($file)); $tmp["date"]=date ("d/m/Y H:i", filemtime($file));
$tmp["datesort"] = date ("YmdHi", filemtime($file));
array_push($dirs,$tmp); array_push($dirs,$tmp);
} }
else { else {
$tmp=[]; $tmp=[];
$tmp["name"]=$file->getRelativePathname(); $tmp["name"]=$file->getRelativePathname();
$tmp["namesort"]=strtolower($tmp["name"]);
$tmp["extension"]=strtolower($file->getExtension()); $tmp["extension"]=strtolower($file->getExtension());
$fileinfo = new file($file->getPathname()); $fileinfo = new file($file->getPathname());
$tmp["minetype"]=$fileinfo->getMimeType(); $tmp["minetype"]=$fileinfo->getMimeType();
$tmp["minefamily"]=explode("/",$tmp["minetype"])[0]; $tmp["minefamily"]=explode("/",$tmp["minetype"])[0];
$tmp["date"] = date ("d/m/Y H:i", filemtime($file)); $tmp["date"] = date ("d/m/Y H:i", filemtime($file));
$tmp["datesort"] = date ("YmdHi", filemtime($file));
$tmp["thumb"]=""; $tmp["thumb"]="";
if($tmp["extension"]=="pdf") { if($tmp["extension"]=="pdf") {
@ -153,11 +173,17 @@ class FileController extends Controller
if(stripos($subdirectory,"_trash")==1) $fgtrash=true; if(stripos($subdirectory,"_trash")==1) $fgtrash=true;
// Trie du tableu // Trie du tableu
$sort = array_column($files, $preference["widgetsortdirectory"][$directory]); $sort = array_column($files, $preference["widgetsortdirectory"][$directory]."sort");
array_multisort($sort, SORT_ASC, $files); if($preference["widgetorderdirectory"][$directory]=="SORT_ASC")
array_multisort($sort, SORT_ASC, $files);
else
array_multisort($sort, SORT_DESC, $files);
$sort = array_column($dirs, $preference["widgetsortdirectory"][$directory]); $sort = array_column($dirs, $preference["widgetsortdirectory"][$directory]."sort");
array_multisort($sort, SORT_ASC, $dirs); if($preference["widgetorderdirectory"][$directory]=="SORT_ASC")
array_multisort($sort, SORT_ASC, $dirs);
else
array_multisort($sort, SORT_DESC, $dirs);
return $this->render('CadolesCoreBundle:File:list.html.twig',[ return $this->render('CadolesCoreBundle:File:list.html.twig',[
'useheader' => false, 'useheader' => false,
@ -175,6 +201,7 @@ class FileController extends Controller
'canadd' => $canupdate, 'canadd' => $canupdate,
'view' => $preference["widgetviewdirectory"][$directory], 'view' => $preference["widgetviewdirectory"][$directory],
'sort' => $preference["widgetsortdirectory"][$directory], 'sort' => $preference["widgetsortdirectory"][$directory],
'order' => $preference["widgetorderdirectory"][$directory],
'fgtrash' => $fgtrash, 'fgtrash' => $fgtrash,
]); ]);
} }
@ -184,9 +211,9 @@ class FileController extends Controller
$canupdate =$this->getPermission($access,$id); $canupdate =$this->getPermission($access,$id);
if(!$canupdate) throw $this->createNotFoundException('Permission denied'); if(!$canupdate) throw $this->createNotFoundException('Permission denied');
$subdirectory=$request->get("subdirectory"); $subdirectory=urldecode($request->get("subdirectory"));
$forcereload=(is_null($request->get("forcereload"))?true:$request->get("forcereload")); $forcereload=(is_null($request->get("forcereload"))?true:$request->get("forcereload"));
return $this->render('CadolesCoreBundle:File:upload.html.twig',[ return $this->render('CadolesCoreBundle:File:upload.html.twig',[
'useheader' => false, 'useheader' => false,
'usemenu' => false, 'usemenu' => false,
@ -286,14 +313,17 @@ class FileController extends Controller
} }
else { else {
$fs->rename($urlsource,$urldestination,true); $fs->rename($urlsource,$urldestination,true);
$fs->touch($urldestination);
$urlsource= $fulldirectory."/thumb/".$oldname; $urlsource= $fulldirectory."/thumb/".$oldname;
$urldestination = $fulldirectory."/thumb/".$data["subdirectory"]; $urldestination = $fulldirectory."/thumb/".$data["subdirectory"];
$fs->rename($urlsource,$urldestination,true); if($fs->exists($urlsource))
$fs->rename($urlsource,$urldestination,true);
$urlsource= $fulldirectory."/thumbmini/".$oldname; $urlsource= $fulldirectory."/thumbmini/".$oldname;
$urldestination = $fulldirectory."/thumbmini/".$data["subdirectory"]; $urldestination = $fulldirectory."/thumbmini/".$data["subdirectory"];
$fs->rename($urlsource,$urldestination,true); if($fs->exists($urlsource))
$fs->rename($urlsource,$urldestination,true);
} }
$toclose=true; $toclose=true;

View File

@ -74,20 +74,47 @@
{% endif %} {% endif %}
</a> </a>
{% set active="" %}
{% if sort=="name" %} {% if sort=="name" %}
{%set action="date" %} {% set active="active" %}
{%endif%}
{% if order=="SORT_ASC" %}
{%set action="SORT_DESC" %}
{% else %} {% else %}
{%set action="name" %} {%set action="SORT_ASC" %}
{% endif %} {% endif %}
{% if not subdirectory is empty %} {% 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"> <a href="{{ path('cadoles_core_'~access~'_file_list',{'directory':directory,'subdirectory':subdirectory,'sort':'name', 'order':action }) }}" type="button" class="btn btn-primary {{active}}">
{% else %} {% else %}
<a href="{{ path('cadoles_core_'~access~'_file_list',{'directory':directory,'clear':true,'sort':action }) }}" type="button" class="btn btn-primary"> <a href="{{ path('cadoles_core_'~access~'_file_list',{'directory':directory,'clear':true,'sort':'name', 'order':action }) }}" type="button" class="btn btn-primary {{active}}">
{% endif %} {% endif %}
{% if sort=="name" %} {% if order=="SORT_ASC" %}
<i class="fas fa-long-arrow-alt-down"></i> Nom <i class="fas fa-long-arrow-alt-down"></i> Nom
{% else %} {% else %}
<i class="fas fa-long-arrow-alt-up"></i> Nom
{% endif %}
</a>
{% set active="" %}
{% if sort=="date" %}
{% set active="active" %}
{%endif%}
{% if order=="SORT_ASC" %}
{%set action="SORT_DESC" %}
{% else %}
{%set action="SORT_ASC" %}
{% endif %}
{% if not subdirectory is empty %}
<a href="{{ path('cadoles_core_'~access~'_file_list',{'directory':directory,'subdirectory':subdirectory,'sort':'date', 'order':action }) }}" type="button" class="btn btn-primary {{active}}">
{% else %}
<a href="{{ path('cadoles_core_'~access~'_file_list',{'directory':directory,'clear':true,'sort':'date', 'order':action }) }}" type="button" class="btn btn-primary {{active}}">
{% endif %}
{% if order=="SORT_ASC" %}
<i class="fas fa-long-arrow-alt-down"></i> Date <i class="fas fa-long-arrow-alt-down"></i> Date
{% else %}
<i class="fas fa-long-arrow-alt-up"></i> Date
{% endif %} {% endif %}
</a> </a>
</div> </div>

View File

@ -23,7 +23,7 @@
init: function() { init: function() {
this.on("sending", function(file, xhr, formData) { this.on("sending", function(file, xhr, formData) {
formData.append("directory", "{{ id }}"); formData.append("directory", "{{ id }}");
formData.append("subdirectory", "{{ subdirectory }}"); formData.append("subdirectory", "{{ subdirectory|raw }}");
}); });
var totalFiles = 0; var totalFiles = 0;