pj sur projecttask (ref #19)

This commit is contained in:
afornerot 2020-04-16 10:10:11 +02:00
parent a74fb27773
commit 6ffa8a20bf
3 changed files with 132 additions and 9 deletions

View File

@ -180,6 +180,18 @@ class FileController extends Controller
$em->getRepository("CadolesPortalBundle:Page")->getPermission($this->getUser(),$page,$cansee,$canupdate);
if(!$cansee) throw $this->createNotFoundException('Permission denied');
break;
case "taskproject":
// Récupération de la tache
$projecttask=$em->getRepository("CadolesPortalBundle:Projecttask")->find($id);
if (!$projecttask) throw $this->createNotFoundException('Unable to find entity.');
// On s'assure que l'utilisateur à la permission de voir
$project=$projecttask->getProject();
$user=$this->getUser();
$em->getRepository("CadolesPortalBundle:Project")->getPermission($user,$project,$cansee,$canupdate,$canadd);
if(!$cansee) throw $this->createNotFoundException('Permission denied');
break;
}
}
}

View File

@ -7,6 +7,8 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpFoundation\File\File;
use Cadoles\PortalBundle\Entity\Projecttask;
use Cadoles\PortalBundle\Form\ProjecttaskType;
@ -206,6 +208,54 @@ class ProjecttaskController extends Controller
$em->getRepository("CadolesPortalBundle:Projecttask")->getProjectsTasks($projects,0,10,$count,$projecttasks);
// Récupérer les fichiers de la tache
$directory=$this->get('kernel')->getRootDir()."/../uploads/file/taskproject-".$id;
$files=[];
$fs = new Filesystem();
if($fs->exists($directory)) {
$finder = new Finder();
$finder->sortByName()->in($directory)->exclude('thumb')->exclude('thumbmini');
foreach ($finder as $file) {
$tmp=[];
$tmp["name"]=$file->getRelativePathname();
$tmp["extension"]=$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";
if($fs->exists($directory."/thumbmini/".$tmp["name"])) {
$data = file_get_contents($directory."/thumbmini/".$tmp["name"]);
$tmp["thumb"]="data:image/jpg;base64," . base64_encode($data);
}
elseif($fs->exists($directory."/thumb/".$tmp["name"])) {
$data = file_get_contents($directory."/thumb/".$tmp["name"]);
$tmp["thumb"]="data:image/jpg;base64," . base64_encode($data);
}
}
elseif($fs->exists($directory."/thumbmini/".$tmp["name"])) {
$data = file_get_contents($directory."/thumbmini/".$tmp["name"]);
$tmp["thumb"]="data:image/" . $tmp["extension"] . ";base64," . base64_encode($data);
}
elseif($fs->exists($directory."/thumb/".$tmp["name"])) {
$data = file_get_contents($directory."/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($this->labelentity.':view.html.twig', [
'useheader' => ($access=="config"),
'usemenu' => false,
@ -216,7 +266,8 @@ class ProjecttaskController extends Controller
'canupdate' => $canupdate,
'canadd' => $canadd,
'projects' => $projects,
'projecttasks' => $projecttasks
'projecttasks' => $projecttasks,
'files' => $files
]);
}
@ -311,7 +362,7 @@ class ProjecttaskController extends Controller
$idproject=$entity->getProject()->getId();
$oldpercentage=$entity->getPercentage();
// On s'assure que l'utilisateur à la permission de supprimer
// On s'assure que l'utilisateur à la permission de modifier
if($access=="user") {
$user=$this->getUser();
$em->getRepository("CadolesPortalBundle:Project")->getPermission($user,$entity->getProject(),$cansee,$canupdate,$canadd);

View File

@ -105,10 +105,49 @@
<div id="slider"></div>
{% endif %}
<div data-toggle="modal" data-target="#mymodal" onclick="ModalLoad('mymodal','Fichiers','/ninegate/user/config/file/upload/projecttask-{{entity.id}}');" title="Ajouter des fichiers" class="grid-item-content" style="cursor:pointer;margin-top:20px;">
{% if files|length >= 1 %}
<br>
<div class="grid clearfix">
<div class="grid-sizer grid-small"></div>
<div class="grid-gutter-sizer"></div>
{% for file in files|sort %}
<div class="grid-item grid-small">
<div class="grid-item-content" style="background-color: #{{ color["main"]}}">
{% if canadd %}
<a style="cursor:pointer;color: #{{color['fontcolorhover']}}" onClick="delFile('taskproject-{{ entity.id}}','{{file.name|e('js')|raw }}')" class="item-delete">
<i class="fa fa-trash" title="Supprimer le fichier"></i>
</a>
{% endif %}
<a style="cursor:pointer" href="{{ path('cadoles_core_'~access~'_file_download',{'directory':'taskproject-'~entity.id,'filename':file.name }) }}">
<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>{{ file.name }}</h2>
</div>
</div>
</a>
</div>
</div>
{% endfor %}
</div>
{% endif %}
{% if canadd %}
<div data-toggle="modal" data-target="#mymodal" onClick="ModalLoad('mymodal','Fichiers','{{ path('cadoles_core_'~access~'_file_upload',{'id': 'taskproject-'~entity.id,'type':'all'}) }}');" title="Ajouter des fichiers" class="grid-item-content" style="cursor:pointer;margin-top:20px;">
<img class="grid-item-img imageshadow" height="60" src="/ninegate/uploads/icon/icon_add.png">
<br>Ajouter un fichier
</div>
{% endif %}
</div>
</div>
</div>
@ -138,6 +177,11 @@
showProject(0, {{ canupdate }});
{% endif %}
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);
});
});
{% if canadd %}
@ -163,6 +207,22 @@
$("#menuproject-"+id).addClass("active");
}
// 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();
}
});
}
}
{% endblock %}