Commit db3936ba authored by Mat's avatar Mat

LettreInfos, adapte le controllerAPI qui doit vérifier l'ordre d'affichage...

LettreInfos, adapte le controllerAPI qui doit vérifier l'ordre d'affichage avant d'envoyer les Infos
parent 29dfc08b
......@@ -146,6 +146,31 @@ class LettreAPIController extends MasterAPIController
}
/**
* @param $id
* @return \Symfony\Component\HttpFoundation\JsonResponse
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function readInfosAction($id)
{
$em = $this->getDoctrine()->getManager();
// Récupère l'ordre de tri
$sorted = $em->getRepository('PotageBundle:Lettre')->findOneForSorted($id)->getSorted();
if (!empty($sorted))
{
$infos = $em->getRepository('PotageBundle:Info')->findAllForLettreReadInfosSorted($id, $sorted);
}
else {
$infos = $em->getRepository('PotageBundle:Info')->findAllForLettreReadInfos($id);
}
return $this->api($infos);
}
/**
* Form update (post) pour modifier la colonne 'sorted'
*
......@@ -157,7 +182,7 @@ class LettreAPIController extends MasterAPIController
public function updateSortedAction(Request $request, $id)
{
$em = $this->getDoctrine()->getManager();
$lettre = $em->getRepository('PotageBundle:Lettre')->findOneForSorted($id);
$lettre = $em->getRepository('PotageBundle:Lettre')->findOneForSortedWhereStatus($id);
if ($lettre === null)
{
......
......@@ -188,6 +188,15 @@ api_lettre_read_one:
_controller: APIBundle:LettreAPI:readOne
methods: [ GET ]
api_lettre_infos_read:
path: /lettre/{id}/infos
requirements:
id: \d+
defaults:
_controller: APIBundle:LettreAPI:readInfos
methods: [ GET ]
api_lettre_update:
path: /lettre/{id}
requirements:
......
<?php
namespace PotageBundle\Repository;
use PotageBundle\Entity\Info;
/**
* InfoRepository
......@@ -80,4 +81,44 @@ class InfoRepository extends \Doctrine\ORM\EntityRepository
return $qb->getQuery()->getOneOrNullResult();
}
/**
* @param $id
* @param $sorted
* @return Info[]
*/
public function findAllForLettreReadInfosSorted($id, $sorted)
{
$qb = $this->createQueryBuilder('i')
->select('i.id', 'i.title', 'i.subtitle', 'i.text', 'i.color', 'i.status')
->join('i.lettres', 'l')
->addSelect('l.id id_lettre')
->where('l.id = :id')
->orderBy('FIELD(i.id, :sorted)')
->setParameters(array(
':id' => $id,
':sorted' => explode(',', $sorted )
))
;
return $qb->getQuery()->getResult();
}
/**
* @param $id
* @return Info[]
*/
public function findAllForLettreReadInfos($id)
{
$qb = $this->createQueryBuilder('i')
->join('i.lettres', 'l')
->where('i.lettres = :id')
->setParameters(array(
':id' => $id,
))
;
return $qb->getQuery()->getResult();
}
}
......@@ -54,7 +54,7 @@ class LettreRepository extends \Doctrine\ORM\EntityRepository
->setParameter(':id', $id);
return $qb->getQuery()->getOneOrNullResult();
}
/**
* @param $id
......@@ -116,6 +116,21 @@ class LettreRepository extends \Doctrine\ORM\EntityRepository
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function findOneForSorted($id)
{
$qb = $this->createQueryBuilder('l')
->where('l.id = :id')
->setParameters(array(
':id'=> $id
));
return $qb->getQuery()->getOneOrNullResult();
}
/**
* @param $id
* @return mixed
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function findOneForSortedWhereStatus($id)
{
$qb = $this->createQueryBuilder('l')
->where('l.id = :id')
......@@ -127,5 +142,4 @@ class LettreRepository extends \Doctrine\ORM\EntityRepository
));
return $qb->getQuery()->getOneOrNullResult();
}
}
......@@ -8,15 +8,14 @@ function reloadGridInfos()
let sortable = grid.querySelector('div#sortable');
sortable.innerHTML = null;
let URL = Routing.generate('api_lettre_read_one', {'id': id_lettre });
let URL = Routing.generate('api_lettre_infos_read', {'id': id_lettre });
AJAX('GET', URL, function(request)
{
let json = JSON.parse(request.responseText);
for(let i = 0; i < json.infos.length; i++ )
for(let i = 0; i < json.length; i++ )
{
let div = buildItemLettreInfos(json.infos[i]);
let div = buildItemLettreInfos(json[i]);
sortable.appendChild(div);
}
});
......@@ -29,7 +28,7 @@ function reloadGridInfos()
*/
function buildItemLettreInfos(jsonRow)
{
console.log(jsonRow);
//console.log(jsonRow);
let div = document.createElement('div');
div.classList.add('ui-state-default', 'info');
......@@ -66,7 +65,6 @@ sortForm.addEventListener('submit', function(e)
list[i] = items[i].dataset.infoId;
}
console.log(list);
input.value = list;
let form = this;
......
......@@ -254,7 +254,7 @@ table span.details { /*
width: 100%;
height: unset;
min-height: 50px;
background-color: #a7afb9;
background-color: #e8e8e8;
}
#sortable div.ui-state-default {
margin: 1em 1em 0 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment