Commit 26172c7f authored by Mat's avatar Mat

ImageAPI read, et GET ajax dans une grille

parent 1ef2bbbb
......@@ -12,6 +12,20 @@ class ImageAPIController extends MasterAPIController
/**
* @return \Symfony\Component\HttpFoundation\JsonResponse
*/
public function readAction()
{
$em = $this->getDoctrine()->getManager();
$images = $em->getRepository('TechnoBundle:Image')->findAllForAPIRead();
return $this->api($images);
}
/**
* @param Request
* @param $id
* @return \Symfony\Component\HttpFoundation\JsonResponse
*/
public function updateAction(Request $request, $id)
{
$em = $this->getDoctrine()->getManager();
......
......@@ -25,6 +25,7 @@ class OwnerAPIController extends MasterAPIController
/**
* @param $id
* @return \Symfony\Component\HttpFoundation\JsonResponse
*/
public function readOneAction($id)
......@@ -41,6 +42,7 @@ class OwnerAPIController extends MasterAPIController
}
/**
* @param $id
* @return \Symfony\Component\HttpFoundation\JsonResponse
*/
public function deleteOneAction($id)
......@@ -59,6 +61,7 @@ class OwnerAPIController extends MasterAPIController
/**
* @param Request
* @return \Symfony\Component\HttpFoundation\JsonResponse
*/
public function createAction(Request $request)
......@@ -83,6 +86,8 @@ class OwnerAPIController extends MasterAPIController
/**
* @param Request
* @param $id
* @return \Symfony\Component\HttpFoundation\JsonResponse
*/
public function updateAction(Request $request, $id)
......
## OwnerAPI
api_owner_read:
path: /owners
defaults:
......@@ -36,6 +38,15 @@ api_owner_delete_one:
id: \d+
methods: [ DELETE ]
## ImageAPI
api_image_read:
path: /images
defaults:
_controller: APIBundle:ImageAPI:read
methods: [ GET ]
options:
expose: true # façon crade d'esposer la route
api_image_update:
path: /image/{id}
......
......@@ -86,6 +86,18 @@ class ImageRepository extends \Doctrine\ORM\EntityRepository
return $qb->getQuery()->getOneOrNullResult();
}
/**
* @return Image[]
*/
public function findAllForAPIRead()
{
$qb = $this->createQueryBuilder('i')
->join('i.owner', 'o')
->addSelect('o');
return $qb->getQuery()->getResult();
}
/**
* @param $id
* @return Image
......
......@@ -57,15 +57,51 @@
<i>Formulaire et table en AJAX, requêtes vers APIBundle</i>
</p>
<table id="table-images">
<div id="grid-images">
</table>
</div>
{% endblock %}
{% block customJS %}
<script type="text/javascript">
let grid = document.querySelector('div#grid-images');
let imagesURL = Routing.generate('api_image_read');
AJAX('GET', imagesURL, function(request)
{
let json = JSON.parse(request.responseText);
for (let i = 0; i < json.length; i++)
{
let div = document.createElement('div');
div.classList.add('image');
let img = document.createElement('img');
img.setAttribute('src', json[i].path);
img.setAttribute('title', json[i].name);
img.setAttribute('alt', json[i].name);
div.appendChild(img);
console.log(
json[i].id
+ ' | ' +
json[i].name
+ ' | ' +
json[i].path
+ ' | ' +
json[i].legend
+ ' | ' +
json[i].owner.firstname
+ ' ' +
json[i].owner.lastname
);
grid.appendChild(div);
}
});
</script>
{% endblock %}
......@@ -225,6 +225,7 @@ ul.vignettes li img {
width: 60px;
height: 60px;
}
#grid-images div.image,
#gallery_read div.image {
width: 200px;
height: 200px;
......@@ -232,10 +233,12 @@ ul.vignettes li img {
position: relative;
float: left;
}
#grid-images div.image img,
#gallery_read div.image img {
width: 100%;
height: 100%;
}
#grid-images div.image div.modify,
#gallery_read div.image div.modify {
position: absolute;
z-index: 10;
......
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