debut explore de fichier

This commit is contained in:
afornerot 2020-09-11 17:02:46 +02:00
parent 16d24deab1
commit 4f9ce5fba7
5 changed files with 256 additions and 4 deletions

View File

@ -16,6 +16,83 @@ use Symfony\Component\HttpFoundation\File\File;
class FileController extends Controller
{
public function listAction($directory,Request $request,$access="config") {
$canupdate= $this->getPermission($access,$directory);
$subdirectory=$request->get("subdirectory");
$iddirectory=explode("-",$directory)[1];
$fulldirectory=$this->get('kernel')->getRootDir()."/../uploads/file/".$directory."/".$subdirectory;
$parents=null;
$dirname="Home";
if($subdirectory) {
$parents=explode("/",$subdirectory);
$dirname=end($parents);
array_pop($parents);
}
$files=[];
$dirs=[];
$fs = new Filesystem();
if($fs->exists($fulldirectory)) {
$finder = new Finder();
$finder->depth('== 0')->sortByName()->in($fulldirectory)->exclude('thumb')->exclude('thumbmini');
foreach ($finder as $file) {
if(is_dir($file)) {
$tmp=[];
$tmp["name"]=$file->getRelativePathname();
array_push($dirs,$tmp);
}
else {
$tmp=[];
$tmp["name"]=$file->getRelativePathname();
$tmp["extension"]=strtolower($file->getExtension());
$fileinfo = new file($file->getPathname());
$tmp["minetype"]=$fileinfo->getMimeType();
$tmp["minefamily"]=explode("/",$tmp["minetype"])[0];
$tmp["thumb"]="";
if($tmp["extension"]=="pdf") {
$tmp["thumb"]="/".$this->getParameter('alias')."/bundles/cadolescore/images/files/".$tmp["extension"].".png";
}
elseif($fs->exists($fulldirectory."/thumbmini/".$tmp["name"])) {
$data = file_get_contents($fulldirectory."/thumbmini/".$tmp["name"]);
$tmp["thumb"]="data:image/" . $tmp["extension"] . ";base64," . base64_encode($data);
}
elseif($fs->exists($fulldirectory."/thumb/".$tmp["name"])) {
$data = file_get_contents($fulldirectory."/thumb/".$tmp["name"]);
$tmp["thumb"]="data:image/" . $tmp["extension"] . ";base64," . base64_encode($data);
}
elseif($fs->exists($this->get('kernel')->getRootDir()."/../web/bundles/cadolescore/images/files/".$tmp["extension"].".png")) {
$tmp["thumb"]="/".$this->getParameter('alias')."/bundles/cadolescore/images/files/".$tmp["extension"].".png";
}
array_push($files,$tmp);
}
}
}
return $this->render('CadolesCoreBundle:File:list.html.twig',[
'useheader' => true,
'usemenu' => false,
'usesidebar' => false,
'access' => $access,
'iddirectory' => $iddirectory,
'directory' => $directory,
'parents' => $parents,
'subdirectory' => $subdirectory,
'dirname' => $dirname,
'dirs' => $dirs,
'files' => $files,
'canupdate' => $canupdate,
'canadd' => $canupdate,
'colorbodyfont' => "000000",
]);
}
public function uploadAction($id,$type,$access="config")
{
return $this->render('CadolesCoreBundle:File:upload.html.twig',[
@ -194,5 +271,8 @@ class FileController extends Controller
break;
}
}
else $canupdate=true;
return $canupdate;
}
}

View File

@ -57,6 +57,10 @@ cadoles_core_crop02:
#== File =================================================================================================================
#-- Access config
cadoles_core_config_file_list:
path: /config/file/list/{directory}
defaults: { _controller: CadolesCoreBundle:File:list, access: config }
cadoles_core_config_file_upload:
path: /config/file/upload/{id}/{type}
defaults: { _controller: CadolesCoreBundle:File:upload, access: config }
@ -78,6 +82,10 @@ cadoles_core_config_file_download:
defaults: { _controller: CadolesCoreBundle:File:download, access: config }
#-- Access user
cadoles_core_user_file_list:
path: /user/file/list/{directory}
defaults: { _controller: CadolesCoreBundle:File:list, access: user }
cadoles_core_user_file_upload:
path: /user/file/upload/{id}/{type}
defaults: { _controller: CadolesCoreBundle:File:upload, access: user }
@ -87,15 +95,15 @@ cadoles_core_user_file_delete:
defaults: { _controller: CadolesCoreBundle:File:delete, access: user }
cadoles_core_user_file_view:
path: file/view/{directory}/{filename}
path: /user/file/view/{directory}/{filename}
defaults: { _controller: CadolesCoreBundle:File:view, access: user }
cadoles_core_user_file_download:
path: file/download/{directory}/{filename}
path: /user/file/download/{directory}/{filename}
defaults: { _controller: CadolesCoreBundle:File:download, access: user }
cadoles_core_user_file_show:
path: file/show/{directory}/{filename}
path: /user/file/show/{directory}/{filename}
defaults: { _controller: CadolesCoreBundle:File:show, access: user }

View File

@ -291,7 +291,9 @@ span.item-drag {
position: relative;
display: block;
}
.grid-sizer {
display: none !important;
}
.grid-item .grid-item-content {
/*height: 100%;*/
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

View File

@ -0,0 +1,162 @@
{% extends '@CadolesCore/base.html.twig' %}
{% block pagewrapper %}
<div id="explorer">
<div class="btn-toolbar" role="toolbar" aria-label="Toolbar with button groups" style="margin-top:5px">
{% if canupdate %}
<div class="btn-group mr-2" role="group" aria-label="First group">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#mymodal" onClick="ModalLoad('mymodal','Fichiers','{{ path('cadoles_core_'~access~'_file_upload',{'id': directory,'type':'all'}) }}');" title="Ajouter des fichiers">
<i class="fa fa-upload"></i>
</button>
<button type="button" class="btn btn-primary">2</button>
<button type="button" class="btn btn-primary">3</button>
<button type="button" class="btn btn-primary">4</button>
</div>
{% endif %}
<div class="btn-group mr-2" role="group" aria-label="Second group">
<button type="button" class="btn btn-primary">5</button>
<button type="button" class="btn btn-primary">6</button>
<button type="button" class="btn btn-primary">7</button>
</div>
</div>
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{{ path('cadoles_core_'~access~'_file_list',{'directory':directory }) }}">Home</a></li>
{% set sub = "" %}
{% for parent in parents %}
{% if loop.index==1 %}
{% set sub = parent %}
{% else %}
{% set sub = sub~"/"~parent %}
{% endif %}
<li class="breadcrumb-item"><a href="{{ path('cadoles_core_'~access~'_file_list',{'directory':directory,'subdirectory':sub }) }}">{{parent}}</a></li>
{% endfor %}
{% if not subdirectory is empty %}
<li class="breadcrumb-item"><a href="{{ path('cadoles_core_'~access~'_file_list',{'directory':directory,'subdirectory':subdirectory }) }}">{{dirname}}</a></li>
{% endif %}
</ol>
</nav>
<div class="grid clearfix">
<div class="grid-sizer grid-small"></div>
<div class="grid-gutter-sizer"></div>
{% for dir in dirs|sort %}
<div class="grid-item grid-small">
<div class="grid-item-content">
{% if canadd %}
<a style="color:#{{colorbodyfont}}; cursor:pointer;" onClick="delFile('{{ directory }}','{{dir.name|e('js')|raw }}')" class="item-delete">
<i style="color:#{{colorbodyfont}}" class="fa fa-trash" title="Supprimer le dossier"></i>
</a>
{% endif %}
{% if subdirectory is empty %}
{% set link = dir.name %}
{% else %}
{% set link = subdirectory~"/"~dir.name %}
{% endif %}
<a style="cursor:pointer" href="{{ path('cadoles_core_'~access~'_file_list',{'directory':directory,'subdirectory':link }) }}">
<div class="item-link clearfix">
<div class="grid-item-logo">
<img class="grid-item-img" height="110" src="/{{ alias }}/bundles/cadolescore/images/files/dir.png">
</div>
<div class="grid-item-title">
<h2 style="color:#{{colorbodyfont}}">{{ dir.name }}</h2>
</div>
</div>
</a>
</div>
</div>
{% endfor %}
{% for file in files|sort %}
<div class="grid-item grid-small">
<div class="grid-item-content">
{% if canadd %}
<a style="color:#{{colorbodyfont}}; cursor:pointer;" onClick="delFile('{{ directory }}','{{file.name|e('js')|raw }}')" class="item-delete">
<i style="color:#{{colorbodyfont}}" class="fa fa-trash" title="Supprimer le fichier"></i>
</a>
{% endif %}
{% if file.minefamily=="text" or file.minefamily=="image" or file.minetype == "application/pdf" %}
<a style="cursor:pointer" onClick="showFrameitem('file-{{iddirectory}}-{{loop.index}}','{{ path('cadoles_core_'~access~'_file_view',{'directory':directory,'filename':file.name }) }}')">
{% else %}
<a style="cursor:pointer" href="{{ path('cadoles_core_'~access~'_file_download',{'directory':directory,'filename':file.name }) }}">
{% endif %}
<div class="item-link clearfix">
<div class="grid-item-logo">
{% if file.thumb is not empty %}
<img class="grid-item-img" height="110" src="{{ file.thumb }}">
{% else %}
<img class="grid-item-img" height="110" src="/{{ alias }}/bundles/cadolescore/images/files/_blank.png">
{% endif %}
</div>
<div class="grid-item-title">
<h2 style="color:#{{colorbodyfont}}">{{ file.name }}</h2>
</div>
</div>
</a>
</div>
</div>
{% endfor %}
</div>
</div>
{% endblock %}
{% block localjavascript %}
var optiongrid={columnWidth: '.grid-sizer',itemSelector: '.grid-item', gutter: '.grid-gutter-sizer'};
// Création des grilles d'items
$('body').imagesLoaded(function() {
var grid = $('.grid').masonry(optiongrid);
});
// Supprimer un fichier
function delFile(directory,filename) {
var r = confirm("Confirmez-vous la suppression de ce fichier ?");
if (r == true) {
$.ajax({
method: "POST",
url: "{{ path('cadoles_core_'~access~'_file_delete') }}",
data: {
directory:directory,
filename:filename
},
success: function() {
location.reload();
}
});
}
}
// Affichage des frames associés aux items de bureau
function showFrameitem(id,url,forcereload) {
$("#explorer").hide();
$("body").css("overflow-y","hidden");
if($("#frameitem-"+id).length) {
if(forcereload) {
$("#frameitem-"+id).attr("src",url);
}
$("#frameitem-"+id).show();
}
else {
$("#explorer").before("<iframe id='frameitem-"+id+"' class='frameitem' src='"+url+"'></iframe>");
}
}
{% endblock %}