Commit ac2223b0 authored by Mat's avatar Mat
Browse files

Affiche les tables par statut (ajoute un where dans le repository)

parent 1b278a7d
......@@ -58,12 +58,14 @@ class OffreAPIController extends MasterAPIController
/**
* @param $status
* @return \Symfony\Component\HttpFoundation\JsonResponse
*/
public function readAction()
public function readByStatusAction($status)
{
$em = $this->getDoctrine()->getManager();
$offres = $em->getRepository('PotageBundle:Offre')->findAllForRead();
$offres = $em->getRepository('PotageBundle:Offre')
->findAllByStatusForRead($status);
return $this->api($offres);
......
......@@ -58,8 +58,11 @@ api_offre_create:
_controller: APIBundle:OffreAPI:create
methods: [ POST ]
api_offre_read:
path: /offres
api_offre_read_by_status:
path: /offres/{status}
requirements:
status: \w+
defaults:
_controller: APIBundle:OffreAPI:read
methods: [ GET ]
\ No newline at end of file
_controller: APIBundle:OffreAPI:readByStatus
methods: [ GET ]
......@@ -212,7 +212,7 @@ class Offre
*/
public function setEndedAt($endedAt)
{
$s_time = ' 12:00:00';
$s_time = ' 12:00:00'; // TODO une constante à fixer qqpart
$s_date = $endedAt->format('Y-m-d');
$string = $s_date . $s_time;
$endedAt = date_create_from_format('Y-m-d H:i:s', $string);
......
......@@ -2,6 +2,8 @@
namespace PotageBundle\Repository;
use PotageBundle\Entity\Offre;
/**
* OffreRepository
*
......@@ -25,11 +27,14 @@ class OffreRepository extends \Doctrine\ORM\EntityRepository
}
/**
* @return array
* @param $status
* @return Offre[]
*/
public function findAllForRead()
public function findAllByStatusForRead($status)
{
$qb = $this->createQueryBuilder('o')
->where('o.status = :status')
->setParameter(':status', $status)
->orderBy('o.status')
->addOrderBy('o.reference', 'DESC');
return $qb->getQuery()->getResult();
......
......@@ -66,8 +66,8 @@
{% include '@Potage/Offre/ajaxForm.html.twig' %}
<table id="maintab" class="table offres table-striped">
<h2>En préparation</h2>
<table id="maintab-draft" class="table offres table-striped">
<thead>
<tr>
<th scope="col">#</th>
......@@ -80,7 +80,16 @@
<tbody>
</tbody>
</table>
<h2>En cours</h2>
<table id="maintab-current" class="table offres table-striped">
<tbody>
</tbody>
</table>
<h2>Archives</h2>
<table id="maintab-closed" class="table offres table-striped">
<tbody>
</tbody>
</table>
</section>
</div>
......@@ -92,18 +101,20 @@
let submitURL = null;
let table = document.querySelector('table#maintab.offres');
let tbody = table.querySelector('tbody');
let form = document.querySelector('form[name=offre]');
let titleForm = document.querySelector('#form-offre');
/*
* Recharge la table
*/
function reloadTableOffre(){
function reloadTableOffre(status)
{
let table = document.querySelector('table#maintab-' + status + '.offres');
let tbody = table.querySelector('tbody');
tbody.innerHTML = null;
let offreURL = Routing.generate('api_offre_read');
let offreURL = Routing.generate('api_offre_read_by_status', {'status': status});
AJAX('GET', offreURL, function(request)
{
......@@ -147,7 +158,21 @@
}
});
}
reloadTableOffre();
/*
* Recharge les tables
*/
function reloadTables()
{
let tables = ['draft', 'current', 'closed'];
for (let table of tables) {
reloadTableOffre(table);
}
}
reloadTables();
......
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