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 ...@@ -12,6 +12,20 @@ class ImageAPIController extends MasterAPIController
/** /**
* @return \Symfony\Component\HttpFoundation\JsonResponse * @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) public function updateAction(Request $request, $id)
{ {
$em = $this->getDoctrine()->getManager(); $em = $this->getDoctrine()->getManager();
......
...@@ -25,6 +25,7 @@ class OwnerAPIController extends MasterAPIController ...@@ -25,6 +25,7 @@ class OwnerAPIController extends MasterAPIController
/** /**
* @param $id
* @return \Symfony\Component\HttpFoundation\JsonResponse * @return \Symfony\Component\HttpFoundation\JsonResponse
*/ */
public function readOneAction($id) public function readOneAction($id)
...@@ -41,6 +42,7 @@ class OwnerAPIController extends MasterAPIController ...@@ -41,6 +42,7 @@ class OwnerAPIController extends MasterAPIController
} }
/** /**
* @param $id
* @return \Symfony\Component\HttpFoundation\JsonResponse * @return \Symfony\Component\HttpFoundation\JsonResponse
*/ */
public function deleteOneAction($id) public function deleteOneAction($id)
...@@ -59,6 +61,7 @@ class OwnerAPIController extends MasterAPIController ...@@ -59,6 +61,7 @@ class OwnerAPIController extends MasterAPIController
/** /**
* @param Request
* @return \Symfony\Component\HttpFoundation\JsonResponse * @return \Symfony\Component\HttpFoundation\JsonResponse
*/ */
public function createAction(Request $request) public function createAction(Request $request)
...@@ -83,6 +86,8 @@ class OwnerAPIController extends MasterAPIController ...@@ -83,6 +86,8 @@ class OwnerAPIController extends MasterAPIController
/** /**
* @param Request
* @param $id
* @return \Symfony\Component\HttpFoundation\JsonResponse * @return \Symfony\Component\HttpFoundation\JsonResponse
*/ */
public function updateAction(Request $request, $id) public function updateAction(Request $request, $id)
......
## OwnerAPI
api_owner_read: api_owner_read:
path: /owners path: /owners
defaults: defaults:
...@@ -36,6 +38,15 @@ api_owner_delete_one: ...@@ -36,6 +38,15 @@ api_owner_delete_one:
id: \d+ id: \d+
methods: [ DELETE ] 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: api_image_update:
path: /image/{id} path: /image/{id}
......
...@@ -86,6 +86,18 @@ class ImageRepository extends \Doctrine\ORM\EntityRepository ...@@ -86,6 +86,18 @@ class ImageRepository extends \Doctrine\ORM\EntityRepository
return $qb->getQuery()->getOneOrNullResult(); 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 * @param $id
* @return Image * @return Image
......
...@@ -57,15 +57,51 @@ ...@@ -57,15 +57,51 @@
<i>Formulaire et table en AJAX, requêtes vers APIBundle</i> <i>Formulaire et table en AJAX, requêtes vers APIBundle</i>
</p> </p>
<table id="table-images"> <div id="grid-images">
</table> </div>
{% endblock %} {% endblock %}
{% block customJS %} {% block customJS %}
<script type="text/javascript"> <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> </script>
{% endblock %} {% endblock %}
...@@ -225,6 +225,7 @@ ul.vignettes li img { ...@@ -225,6 +225,7 @@ ul.vignettes li img {
width: 60px; width: 60px;
height: 60px; height: 60px;
} }
#grid-images div.image,
#gallery_read div.image { #gallery_read div.image {
width: 200px; width: 200px;
height: 200px; height: 200px;
...@@ -232,10 +233,12 @@ ul.vignettes li img { ...@@ -232,10 +233,12 @@ ul.vignettes li img {
position: relative; position: relative;
float: left; float: left;
} }
#grid-images div.image img,
#gallery_read div.image img { #gallery_read div.image img {
width: 100%; width: 100%;
height: 100%; height: 100%;
} }
#grid-images div.image div.modify,
#gallery_read div.image div.modify { #gallery_read div.image div.modify {
position: absolute; position: absolute;
z-index: 10; 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