Merge branch 'master' into dist/envole/6/master

This commit is contained in:
Arnaud Fornerot 2020-10-13 17:40:03 +02:00
commit c02d5f0869
3 changed files with 120 additions and 6 deletions

View File

@ -259,6 +259,56 @@ class FileController extends Controller
return $response; return $response;
} }
public function moveAction(Request $request,$access="config")
{
// S'assurer que c'est un appel ajax
if (!$request->isXmlHttpRequest()) {
return new JsonResponse(array('message' => 'Interdit'), 400);
}
$output=array();
$directory=$request->request->get('directory');+
// Récupération du répertoire source et le nom du fichier
$racine=$this->get('kernel')->getRootDir()."/../uploads/file";
$dirsource =$request->request->get('dirsource');
$namesource =$request->request->get('namesource');
$dirdestination =$request->request->get('dirdestination');
$namedestination =$request->request->get('namedestination');
$destid=$request->request->get('destid');
$this->getPermission($access,$directory);
$fs = new Filesystem();
// Déplacer le fichier
$urlsource=$racine."/".$dirsource."/".$namesource;
$urldestination=$racine."/".$dirdestination."/".$namedestination;
if($fs->exists($urlsource)) {
$fs->rename($urlsource,$urldestination);
}
// Déplacer le thumb
$fs->mkdir($racine."/".$dirdestination."/thumb");
$urlsource=$racine."/".$dirsource."/thumb/".$namesource;
$urldestination=$racine."/".$dirdestination."/thumb/".$namedestination;
if($fs->exists($urlsource)) {
$fs->rename($urlsource,$urldestination);
}
// Déplacer le thumbmini
$fs->mkdir($racine."/".$dirdestination."/thumbmini");
$urlsource=$racine."/".$dirsource."/thumbmini/".$namesource;
$urldestination=$racine."/".$dirdestination."/thumbmini/".$namedestination;
if($fs->exists($urlsource)) {
$fs->rename($urlsource,$urldestination);
}
$response = new Response(json_encode($output));
$response->headers->set('Content-Type', 'application/json');
return $response;
}
public function viewAction($directory,$filename,Request $request,$access="config") public function viewAction($directory,$filename,Request $request,$access="config")
{ {
$this->getPermission($access,$directory); $this->getPermission($access,$directory);

View File

@ -73,6 +73,10 @@ cadoles_core_config_file_delete:
path: /config/file/delete/ path: /config/file/delete/
defaults: { _controller: CadolesCoreBundle:File:delete, access: config } defaults: { _controller: CadolesCoreBundle:File:delete, access: config }
cadoles_core_config_file_move:
path: /config/file/move/
defaults: { _controller: CadolesCoreBundle:File:move, access: config }
cadoles_core_config_file_view: cadoles_core_config_file_view:
path: /config/file/view/{directory}/{filename} path: /config/file/view/{directory}/{filename}
defaults: { _controller: CadolesCoreBundle:File:view, access: config } defaults: { _controller: CadolesCoreBundle:File:view, access: config }
@ -102,6 +106,10 @@ cadoles_core_user_file_delete:
path: /user/file/delete path: /user/file/delete
defaults: { _controller: CadolesCoreBundle:File:delete, access: user } defaults: { _controller: CadolesCoreBundle:File:delete, access: user }
cadoles_core_user_file_move:
path: /user/file/move/
defaults: { _controller: CadolesCoreBundle:File:move, access: user }
cadoles_core_user_file_view: cadoles_core_user_file_view:
path: /user/file/view/{directory}/{filename} path: /user/file/view/{directory}/{filename}
defaults: { _controller: CadolesCoreBundle:File:view, access: user } defaults: { _controller: CadolesCoreBundle:File:view, access: user }

View File

@ -93,20 +93,22 @@
<div aria-label="breadcrumb"> <div aria-label="breadcrumb">
<ol class="breadcrumb"> <ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{{ path('cadoles_core_'~access~'_file_list',{'directory':directory, 'clear':true }) }}">Home</a></li> <li class="breadcrumb-item directory" data-dir="{{directory}}" data-name=""><a href="{{ path('cadoles_core_'~access~'_file_list',{'directory':directory, 'clear':true }) }}">Home</a></li>
{% set sub = "" %} {% set sub = "" %}
{% set datadir = directory %}
{% for parent in parents %} {% for parent in parents %}
{% if loop.index==1 %} {% if loop.index==1 %}
{% set sub = parent %} {% set sub = parent %}
{% else %} {% else %}
{% set datadir = datadir~'/'~sub %}
{% set sub = sub~"/"~parent %} {% set sub = sub~"/"~parent %}
{% endif %} {% endif %}
<li class="breadcrumb-item"><a href="{{ path('cadoles_core_'~access~'_file_list',{'directory':directory,'subdirectory':sub }) }}">{{parent}}</a></li> <li class="brea.dcrumb-item directory" data-dir="{{datadir}}" data-name="{{ parent }}"><a href="{{ path('cadoles_core_'~access~'_file_list',{'directory':directory,'subdirectory':sub }) }}">{{parent|raw}}</a></li>
{% endfor %} {% endfor %}
{% if not subdirectory is empty %} {% if not subdirectory is empty %}
<li class="breadcrumb-item"><a href="{{ path('cadoles_core_'~access~'_file_list',{'directory':directory,'subdirectory':subdirectory }) }}">{{dirname}}</a></li> <li class="breadcrumb-item directory" data-dir="{{directory}}/{{sub}}" data-name="{{dirname}}"><a href="{{ path('cadoles_core_'~access~'_file_list',{'directory':directory,'subdirectory':subdirectory }) }}">{{dirname|raw}}</a></li>
{% endif %} {% endif %}
</ol> </ol>
@ -119,7 +121,7 @@
{% for dir in dirs %} {% for dir in dirs %}
<div class="grid-item grid-{{view}}"> <div id="{{dir.name|e('js')|raw }}" class="grid-item grid-{{view}} directory" data-dir="{{directory}}/{{subdirectory}}" data-name="{{dir.name}}">
<div class="grid-item-content"> <div class="grid-item-content">
{% if canadd %} {% if canadd %}
<a style="cursor:pointer;" onClick="delFile('{{ directory }}','{{subdirectory}}','{{dir.name|e('js')|raw }}')" class="item-delete"> <a style="cursor:pointer;" onClick="delFile('{{ directory }}','{{subdirectory}}','{{dir.name|e('js')|raw }}')" class="item-delete">
@ -148,7 +150,7 @@
{% endfor %} {% endfor %}
{% for file in files %} {% for file in files %}
<div class="grid-item grid-{{view}}"> <div class="grid-item grid-{{view}} file" data-dir="{{directory}}/{{subdirectory}}" data-name="{{file.name}}">
<div class="grid-item-content"> <div class="grid-item-content">
{% if canadd %} {% if canadd %}
<a style="cursor:pointer;" onClick="delFile('{{ directory }}','{{subdirectory}}','{{file.name|e('js')|raw }}')" class="item-delete"> <a style="cursor:pointer;" onClick="delFile('{{ directory }}','{{subdirectory}}','{{file.name|e('js')|raw }}')" class="item-delete">
@ -186,7 +188,9 @@
{% block localjavascript %} {% block localjavascript %}
var optiongrid={columnWidth: '.grid-sizer',itemSelector: '.grid-item', gutter: '.grid-gutter-sizer'}; var optiongrid={columnWidth: '.grid-sizer',itemSelector: '.grid-item', gutter: '.grid-gutter-sizer'};
var formodalglobal; var formodalglobal;
var dirsource;
var namesource;
var domsource;
// Création des grilles d'items // Création des grilles d'items
$('body').imagesLoaded(function() { $('body').imagesLoaded(function() {
@ -214,6 +218,58 @@
}); });
$('.file').on('dragstart', function (s) {
dirsource=$(this).data("dir");
namesource=$(this).data("name");
domsource=$(this);
});
$('.directory').on('dragstart', function (s) {
dirsource=$(this).data("dir");
namesource=$(this).data("name");
domsource=$(this);
});
$('.directory')
// crucial for the 'drop' event to fire
.on('dragover', false)
.on('drop', function (e) {
// Récupérer la destination
dirdestination=$(this).data("dir")+"/"+$(this).data("name");
namedestination=namesource;
// Si la source est la meme que la destination on ne fait rien
if(dirdestination+"/"+namedestination==dirsource+"/"+namesource) return false;
console.log(dirsource+"/"+namesource);
console.log(dirdestination+"/"+namedestination);
// On déplace l'element
$.ajax({
method: "POST",
url: "{{ path('cadoles_core_'~access~'_file_move') }}",
data: {
directory:'{{directory}}',
dirsource:dirsource,
namesource:namesource,
dirdestination:dirdestination,
namedestination:namedestination
},
success: function() {
domsource.remove();
var grid = $('.grid').masonry(optiongrid);
ajust();
}
});
return false;
});
}); });
$(window).resize(function() { $(window).resize(function() {