From 0d062632279fdfcdf4bbab85382e3c84a43a2359 Mon Sep 17 00:00:00 2001 From: afornerot Date: Wed, 23 Sep 2020 14:42:49 +0200 Subject: [PATCH] preference user widgetshowhide (#203) --- .../CoreBundle/Controller/UserController.php | 36 ++++ .../CoreBundle/Resources/config/routing.yml | 5 + .../Resources/views/File/list.html.twig | 16 +- .../Controller/PagewidgetController.php | 191 ++++++++++-------- .../Resources/views/Frame/only.html.twig | 14 +- .../Resources/views/Page/viewwidget.html.twig | 30 ++- .../views/Pagewidget/viewchat.html.twig | 2 +- .../views/Pagewidget/viewfile.html.twig | 8 +- .../views/Pagewidget/viewframe.html.twig | 2 +- 9 files changed, 201 insertions(+), 103 deletions(-) diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/UserController.php b/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/UserController.php index 6aecf02b..0ef7626b 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/UserController.php +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/UserController.php @@ -1206,6 +1206,42 @@ class UserController extends Controller return new Response(); } + public function preferenceAction(Request $request) { + // S'assurer que c'est un appel ajax + if (!$request->isXmlHttpRequest()) { + return new JsonResponse(array('message' => 'Interdit'), 400); + } + + $key=$request->request->get('key'); + $id=$request->request->get('id'); + $value=$request->request->get('value'); + + $preference=$this->getUser()->getPreference(); + $toupdate=false; + if(!array_key_exists($key,$preference)) { + $toupdate=true; + $preference[$key]=[]; + } + if((!array_key_exists($id,$preference[$key]))) { + $toupdate=true; + $preference[$key][$id]=$value; + } + if($value&&$preference[$key][$id]!=$value) { + $toupdate=true; + $preference[$key][$id]=$value; + } + + // Mise à jour des préferences + if($toupdate) { + $em = $this->getDoctrine()->getManager(); + $this->getUser()->setPreference($preference); + $em->persist($this->getUser()); + $em->flush(); + } + + return new Response(); + } + protected function getDatas() { $em = $this->getDoctrine()->getManager(); diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/config/routing.yml b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/config/routing.yml index 8687ad5e..af861a59 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/config/routing.yml +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/config/routing.yml @@ -318,6 +318,11 @@ cadoles_core_user_viewcalendar: path: /user/viewcalendar defaults: { _controller: CadolesCoreBundle:User:viewcalendar } +cadoles_core_user_preference: + path: /user/preference + defaults: { _controller: CadolesCoreBundle:User:preference } + + #== Niveau01 ============================================================================================================= cadoles_core_config_niveau01: path: /config/niveau01 diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/File/list.html.twig b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/File/list.html.twig index 37baffca..f2701097 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/File/list.html.twig +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/File/list.html.twig @@ -5,6 +5,15 @@ min-height:0px !important; } + .container-fluid { + padding:0px; + } + + #explorer { + margin-right: -15px; + margin-left: -15px; + } + .grid .grid-list .grid-item-logo { margin:0px; } @@ -213,10 +222,11 @@ function ajust(formodal) { - - if(inIframe()) { - if(!$("#frame-{{directory}}",window.parent.document).hasClass("notframeajust")) { + frame=$("#frame-{{directory}}",window.parent.document); + widgetbody=frame.parent(); + + if(!frame.hasClass("notframeajust")&&widgetbody.css("display")=="block") { if($('#mymodal').hasClass('in')) { $("#frame-{{directory}}",window.parent.document).height($("#mymodal").find(".modal-content").height()+80); } diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/PagewidgetController.php b/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/PagewidgetController.php index 5878dcbd..d9945446 100644 --- a/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/PagewidgetController.php +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/PagewidgetController.php @@ -386,6 +386,22 @@ class PagewidgetController extends Controller } } + protected function getPreference(&$entity) { + $user=$this->getUser(); + if($user) { + $preference=$user->getPreference(); + $id=$entity->getId(); + + // Preference widgetshowhide + if(is_array($preference)) { + if(array_key_exists("widgetshowhide",$preference)) { + if(array_key_exists($id,$preference["widgetshowhide"])) + $entity->setOpened(($preference["widgetshowhide"][$id]=="true")); + } + } + } + } + public function viewurlAction($id,$access="config") { $em = $this->getDoctrine()->getManager(); $entity = $em->getRepository($this->labelentity)->find($id); @@ -402,12 +418,17 @@ class PagewidgetController extends Controller if(!$cansee) throw $this->createNotFoundException('Permission denied'); } + // Récupération des paramétres du widget $url=""; foreach($entity->getParameter()["fields"] as $parameter) { if($parameter["id"]=="url") $url=$parameter["value"]; } + // Préference utilisateur + $this->getPreference($entity); + + // Gestion des url youtuve $url=str_replace("http://www.youtube.com","https://www.youtube.com",$url); $url=str_replace("https://www.youtube.com/watch?v=","https://www.youtube.com/embed/",$url); @@ -452,6 +473,7 @@ class PagewidgetController extends Controller if(!$cansee) throw $this->createNotFoundException('Permission denied'); } + // Récupération des paramétres du widget $url=""; $widgettype= $entity->getWidget(); $jsons=$widgettype->getParameter(); @@ -462,6 +484,9 @@ class PagewidgetController extends Controller $url=$field->value; } + // Préference utilisateur + $this->getPreference($entity); + // Gestion des url youtuve $url=str_replace("http://www.youtube.com","https://www.youtube.com",$url); $url=str_replace("https://www.youtube.com/watch?v=","https://www.youtube.com/embed/",$url); @@ -543,6 +568,8 @@ class PagewidgetController extends Controller } } + // Préference utilisateur + $this->getPreference($entity); // Profilage $user=$this->getUser(); @@ -705,7 +732,9 @@ class PagewidgetController extends Controller } } - + // Préference utilisateur + $this->getPreference($entity); + // Profilage $user=$this->getUser(); $roles=($user?$user->getRoles():["ROLE_ANONYME"]); @@ -829,7 +858,9 @@ class PagewidgetController extends Controller } } - + // Préference utilisateur + $this->getPreference($entity); + // Profilage $user=$this->getUser(); $roles=($user?$user->getRoles():["ROLE_ANONYME"]); @@ -950,6 +981,9 @@ class PagewidgetController extends Controller } } + // Préference utilisateur + $this->getPreference($entity); + // Profilage $user=$this->getUser(); $roles=($user?$user->getRoles():["ROLE_ANONYME"]); @@ -1207,6 +1241,9 @@ class PagewidgetController extends Controller break; } } + + // Préference utilisateur + $this->getPreference($entity); // On regarde si le flux a été lu il y a peu $toregen=true; @@ -1405,6 +1442,9 @@ class PagewidgetController extends Controller } } + // Préference utilisateur + $this->getPreference($entity); + // Profilage $user=$this->getUser(); @@ -1451,7 +1491,10 @@ class PagewidgetController extends Controller break; } } - + + // Préference utilisateur + $this->getPreference($entity); + // Render return $this->render($this->labelentity.':viewlink.html.twig', [ 'entity' => $entity, @@ -1489,7 +1532,10 @@ class PagewidgetController extends Controller } } - + + // Préference utilisateur + $this->getPreference($entity); + // Render return $this->render($this->labelentity.':vieweditor.html.twig', [ 'entity' => $entity, @@ -1516,7 +1562,7 @@ class PagewidgetController extends Controller if(!$cansee) throw $this->createNotFoundException('Permission denied'); } - // Parametres + // Récupération des paramétres du widget $interval="2"; foreach($entity->getParameter()["fields"] as $parameter) { switch($parameter["id"]) { @@ -1526,6 +1572,10 @@ class PagewidgetController extends Controller } } + // Préference utilisateur + $this->getPreference($entity); + + // Récupération des slides $slides=$em->getRepository("CadolesPortalBundle:Slide")->findBy(["pagewidget"=>$entity],['roworder'=>'ASC','title'=>'ASC']); // Render @@ -1555,58 +1605,7 @@ class PagewidgetController extends Controller if(!$cansee) throw $this->createNotFoundException('Permission denied'); } - /* - $directory=$this->get('kernel')->getRootDir()."/../uploads/file/widget-".$id; - - $files=[]; - $fs = new Filesystem(); - - if($fs->exists($directory)) { - $finder = new Finder(); - $finder->depth('== 0')->sortByName()->in($directory)->exclude('thumb')->exclude('thumbmini'); - - foreach ($finder as $file) { - if(!is_dir($file)) { - $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($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); - } - } - } - - // Render - return $this->render($this->labelentity.':viewfile.html.twig', [ - 'entity' => $entity, - 'canadd' => $canupdate, - 'canupdate' => $canupdate, - 'files' => $files, - 'access' => $access, - ]); - */ - - // Parametres + // Récupération des paramétres du widget $view="small"; foreach($entity->getParameter()["fields"] as $parameter) { switch($parameter["id"]) { @@ -1616,6 +1615,9 @@ class PagewidgetController extends Controller } } + // Préference utilisateur + $this->getPreference($entity); + return $this->render($this->labelentity.':viewfile.html.twig', [ 'entity' => $entity, 'canadd' => $canupdate, @@ -1644,7 +1646,10 @@ class PagewidgetController extends Controller $em->getRepository("CadolesPortalBundle:Page")->getPermission($this->getUser(),$page,$cansee,$canupdate); if(!$cansee) throw $this->createNotFoundException('Permission denied'); } - + + // Préference utilisateur + $this->getPreference($entity); + $directory=$this->get('kernel')->getRootDir()."/../uploads/file/widget-".$id; $files=[]; $fs = new Filesystem(); @@ -1703,7 +1708,7 @@ class PagewidgetController extends Controller if(!$cansee) throw $this->createNotFoundException('Permission denied'); } - // Parametres + // Récupération des paramétres du widget $nbday="0"; foreach($entity->getParameter()["fields"] as $parameter) { switch($parameter["id"]) { @@ -1713,6 +1718,9 @@ class PagewidgetController extends Controller } } + // Préference utilisateur + $this->getPreference($entity); + // On récupère soit les calendriers du group en cours soit l'ensemble des calendriers de l'utilisateur if($usage=="group") { $calendars=$em->getRepository("CadolesPortalBundle:Calendar")->getCalendarsGroup($this->getUser(),$group); @@ -1822,7 +1830,7 @@ class PagewidgetController extends Controller if(!$cansee) throw $this->createNotFoundException('Permission denied'); } - // Parametres + // Récupération des paramétres du widget $nbarticle=10; foreach($entity->getParameter()["fields"] as $parameter) { switch($parameter["id"]) { @@ -1832,6 +1840,9 @@ class PagewidgetController extends Controller } } + // Préference utilisateur + $this->getPreference($entity); + // On récupère soit les blogs du group en cours soit l'ensemble des blogs de l'utilisateur if($usage=="group") { $blogs=$em->getRepository("CadolesPortalBundle:Blog")->getBlogsGroup($this->getUser(),$group); @@ -1846,6 +1857,8 @@ class PagewidgetController extends Controller // On récupère les nbarticle de ses blogs $em->getRepository("CadolesPortalBundle:Blogarticle")->getBlogsArticles($blogs,0,$nbarticle,$count,$blogarticles); + + // Render return $this->render($this->labelentity.':viewblog.html.twig', [ 'entity' => $entity, @@ -1888,6 +1901,9 @@ class PagewidgetController extends Controller } } + // Préference utilisateur + $this->getPreference($entity); + // On récupère soit les projects du group en cours soit l'ensemble des projects de l'utilisateur $user=$this->getUser(); if($usage=="group") { @@ -1960,6 +1976,9 @@ class PagewidgetController extends Controller } } + // Préference utilisateur + $this->getPreference($entity); + // Render return $this->render($this->labelentity.':viewseparator.html.twig', [ 'entity' => $entity, @@ -1997,6 +2016,9 @@ class PagewidgetController extends Controller } } + // Préference utilisateur + $this->getPreference($entity); + // Render return $this->render($this->labelentity.':viewurl.html.twig', [ 'entity' => $entity, @@ -2024,6 +2046,8 @@ class PagewidgetController extends Controller if(!$cansee) throw $this->createNotFoundException('Permission denied'); } + // Préference utilisateur + $this->getPreference($entity); // Render return $this->render($this->labelentity.':viewframe.html.twig', [ @@ -2065,6 +2089,9 @@ class PagewidgetController extends Controller } } + // Préference utilisateur + $this->getPreference($entity); + $user=$this->getUser(); $items=[]; $itemcategorys=[]; @@ -2154,6 +2181,9 @@ class PagewidgetController extends Controller if(!$cansee) throw $this->createNotFoundException('Permission denied'); } + // Préference utilisateur + $this->getPreference($entity); + $icon=null; $title=null; $description=null; @@ -2218,6 +2248,9 @@ class PagewidgetController extends Controller if(!$cansee) throw $this->createNotFoundException('Permission denied'); } + // Préference utilisateur + $this->getPreference($entity); + if($usage!="group"||!$group) { $group=$em->getRepository("CadolesCoreBundle:Group")->findOneBy(["fgall"=>true])->getId(); } @@ -2256,6 +2289,9 @@ class PagewidgetController extends Controller if(!$cansee) throw $this->createNotFoundException('Permission denied'); } + // Préference utilisateur + $this->getPreference($entity); + $mygroups=[]; $this->getDoctrine()->getRepository("CadolesPortalBundle:Page")->getPagesUser($user,null,$default,$pagesuser,$pagesadmin,$groupsshared); if(is_array($groupsshared)) { @@ -2303,6 +2339,9 @@ class PagewidgetController extends Controller if(!$cansee) throw $this->createNotFoundException('Permission denied'); } + // Préference utilisateur + $this->getPreference($entity); + // Récupération des paramétres du widget $modelist=1; $nbarticle=5; @@ -2387,18 +2426,7 @@ class PagewidgetController extends Controller if(!$cansee) throw $this->createNotFoundException('Permission denied'); } - - /* - $onlyservice = $this->container->get('cadoles.portal.service.only'); - $firstfolder=null; - $files=$onlyservice->getDocument($group, $firstfolder, $tasks); - - $grp=null; - if($group) $grp=$em->getRepository("CadolesCoreBundle:Group")->find($group); - if($grp) $idonly= $grp->getIdOnlyoffice(); - else $idonly=0; - */ - + // Récupération des paramétres du widget $apponly=0; $view="small"; @@ -2412,23 +2440,10 @@ class PagewidgetController extends Controller break; } } - - /* - - // Render - return $this->render($this->labelentity.':viewonlydoc.html.twig', [ - 'entity' => $entity, - 'canadd' => $cansee, - 'canupdate' => $cansee, - 'firstfolder' => $firstfolder, - 'tasks' => $tasks, - 'urlonly' => $this->getParameter("widonlyoffice_url")."/products/projects/projects.aspx?prjID=".$idonly, - 'apponly' => $apponly, - 'files' => $files, - 'access' => $access, - ]); - */ + // Préference utilisateur + $this->getPreference($entity); + return $this->render($this->labelentity.':viewonlydoc.html.twig', [ 'entity' => $entity, 'canadd' => $canupdate, diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Frame/only.html.twig b/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Frame/only.html.twig index dbcd0349..05672ffa 100644 --- a/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Frame/only.html.twig +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Frame/only.html.twig @@ -5,6 +5,15 @@ min-height:0px !important; } + .container-fluid { + padding:0px; + } + + #explorer { + margin-right: -15px; + margin-left: -15px; + } + .grid .grid-list .grid-item-logo { margin:0px; } @@ -193,7 +202,10 @@ function ajust(formodal) { if(inIframe()) { - if(!$("#frame-{{directory}}",window.parent.document).hasClass("notframeajust")) { + frame=$("#frame-{{directory}}",window.parent.document); + widgetbody=frame.parent(); + + if(!frame.hasClass("notframeajust")&&widgetbody.css("display")=="block") { $("#frame-{{directory}}",window.parent.document).height($("#page-wrapper").height() + 10); } } diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Page/viewwidget.html.twig b/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Page/viewwidget.html.twig index f05736d3..2a037951 100644 --- a/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Page/viewwidget.html.twig +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Page/viewwidget.html.twig @@ -281,12 +281,34 @@ } function showhideWidget(elem) { - // on récupère le parent widget conteneur widget=$(elem).parent().parent(); - widget.children(".widgetbody" ).toggle(); + idwidget= widget.data("id"); + if(widget.children(".widgetbody").css("display")=='block') + value=false; + else + value=true; + + {% if app.user %} + $.ajax({ + method: "POST", + url: "{{ path('cadoles_core_user_preference') }}", + data: { + id:idwidget, + key:'widgetshowhide', + value:value + }, + success: function(idbookmark) { + // on récupère le parent widget conteneur + widget=$(elem).parent().parent(); + //console.log(widget.children(".widgetbody").css("display")); + widget.children(".widgetbody" ).toggle(); - // On recalcule les grilles - var grid = $('.grid').masonry(optiongrid); + // On recalcule les grilles + var grid = $('.grid').masonry(optiongrid); + } + }); + {% endif %} + } // Modification de la localisation d'un widget diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Pagewidget/viewchat.html.twig b/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Pagewidget/viewchat.html.twig index bc298d56..4fe9ef36 100644 --- a/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Pagewidget/viewchat.html.twig +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Pagewidget/viewchat.html.twig @@ -51,7 +51,7 @@ {{ entity.name }} -
+
{% if group is not null %} {{ render(url('cadoles_websocket_chat',{'id':group,'framed':true,'border':entity.border,'colorbodybacklight':colorbodyback, 'colorbodyback':colorbodyback,'colorbodyfont':colorbodyfont,'colorbody':colorbody,'colormain':colormain})) }} {% endif %} diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Pagewidget/viewfile.html.twig b/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Pagewidget/viewfile.html.twig index cd4df4fb..6cd7b093 100644 --- a/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Pagewidget/viewfile.html.twig +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Pagewidget/viewfile.html.twig @@ -49,11 +49,9 @@ {{ entity.name }}
-
- - - -
+
+ +
diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Pagewidget/viewframe.html.twig b/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Pagewidget/viewframe.html.twig index 7d2deb46..851cf1b5 100644 --- a/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Pagewidget/viewframe.html.twig +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Pagewidget/viewframe.html.twig @@ -45,7 +45,7 @@ {{ entity.name }} -
+
{% endif %}