From 470e7ab95a6bd167f054f8cc90f64da1d0b4890c Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 30 May 2019 05:14:22 +0000 Subject: [PATCH 1/7] Add geofence menu to the acl and menu yaml files. #220 --- config/acl.yaml | 5 +++++ config/menu.yaml | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/config/acl.yaml b/config/acl.yaml index 6655e53f..3b0103bf 100644 --- a/config/acl.yaml +++ b/config/acl.yaml @@ -163,6 +163,11 @@ access_keys: label: Update - id: hub.delete label: Delete + - id: geofence + label: Geofence + acls: + - id: geofence.menu + label: Menu - id: rider label: Rider Access diff --git a/config/menu.yaml b/config/menu.yaml index fd870fea..202d81cd 100644 --- a/config/menu.yaml +++ b/config/menu.yaml @@ -75,6 +75,10 @@ main_menu: acl: hub.menu label: Hub parent: location + - id: geofence + acl: geofence.menu + label: Geofence + parent: location - id: joborder From e574ae966ae38d83a975e0f05c08a1f7f4e26d68 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 30 May 2019 09:21:23 +0000 Subject: [PATCH 2/7] Add geofence to menu under Location. Add list of saved coverage areas. #220 --- config/acl.yaml | 8 + config/menu.yaml | 2 +- config/routes/geofence.yaml | 35 ++++ src/Controller/GeofenceController.php | 179 ++++++++++++++++++++ templates/geofence/form.html.twig | 233 ++++++++++++++++++++++++++ templates/geofence/list.html.twig | 144 ++++++++++++++++ 6 files changed, 600 insertions(+), 1 deletion(-) create mode 100644 config/routes/geofence.yaml create mode 100644 src/Controller/GeofenceController.php create mode 100644 templates/geofence/form.html.twig create mode 100644 templates/geofence/list.html.twig diff --git a/config/acl.yaml b/config/acl.yaml index 3b0103bf..594a23f5 100644 --- a/config/acl.yaml +++ b/config/acl.yaml @@ -168,6 +168,14 @@ access_keys: acls: - id: geofence.menu label: Menu + - id: geofence.list + label: List + - id: geofence.add + label: Add + - id: geofence.update + label: Update + - id: geofence.delete + label: Delete - id: rider label: Rider Access diff --git a/config/menu.yaml b/config/menu.yaml index 202d81cd..ba9f0f2d 100644 --- a/config/menu.yaml +++ b/config/menu.yaml @@ -75,7 +75,7 @@ main_menu: acl: hub.menu label: Hub parent: location - - id: geofence + - id: geofence_list acl: geofence.menu label: Geofence parent: location diff --git a/config/routes/geofence.yaml b/config/routes/geofence.yaml new file mode 100644 index 00000000..b210e0db --- /dev/null +++ b/config/routes/geofence.yaml @@ -0,0 +1,35 @@ +#geofence + +geofence_list: + path: /geofence + controller: App\Controller\GeofenceController::index + +geofence_rows: + path: /geofence/rows + controller: App\Controller\GeofenceController::rows + methods: [POST] + +geofence_create: + path: /geofence/create + controller: App\Controller\GeofenceController::addForm + methods: [GET] + +geofence_create_submit: + path: /geofence/create + controller: App\Controller\GeofenceController::addSubmit + methods: [POST] + +geofence_update: + path: /geofence/{id} + controller: App\Controller\GeofenceController::updateForm + methods: [GET] + +geofence_update_submit: + path: /geofence/{id} + controller: App\Controller\GeofenceController::updateSubmit + methods: [POST] + +geofence_delete: + path: /geofence/{id} + controller: App\Controller\GeofenceController::destroy + methods: [DELETE] diff --git a/src/Controller/GeofenceController.php b/src/Controller/GeofenceController.php new file mode 100644 index 00000000..91585d91 --- /dev/null +++ b/src/Controller/GeofenceController.php @@ -0,0 +1,179 @@ +denyAccessUnlessGranted('geofence.list', null, 'No access.'); + + $params = $this->initParameters('geofence_list'); + + return $this->render('geofence/list.html.twig', $params); + } + + public function rows(Request $req) + { + $this->denyAccessUnlessGranted('geofence.list', null, 'No access.'); + + // get query builder + $qb = $this->getDoctrine() + ->getRepository(SupportedArea::class) + ->createQueryBuilder('q'); + + // get datatable params + $datatable = $req->get('datatable'); + + // count total records + $tquery = $qb->select('COUNT(q)'); + $this->setQueryFilters($datatable, $tquery); + $total = $tquery->getQuery() + ->getSingleScalarResult(); + + // get current page number + $page = $datatable['pagination']['page'] ?? 1; + + $perpage = $datatable['pagination']['perpage']; + $offset = ($page - 1) * $perpage; + + // add metadata + $meta = [ + 'page' => $page, + 'perpage' => $perpage, + 'pages' => ceil($total / $perpage), + 'total' => $total, + 'sort' => 'asc', + 'field' => 'id' + ]; + + // build query + $query = $qb->select('q'); + $this->setQueryFilters($datatable, $query); + + // check if sorting is present, otherwise use default + if (isset($datatable['sort']['field']) && !empty($datatable['sort']['field'])) { + $order = $datatable['sort']['sort'] ?? 'asc'; + $query->orderBy('q.' . $datatable['sort']['field'], $order); + } else { + $query->orderBy('q.id', 'asc'); + } + + // get rows for this page + $obj_rows = $query->setFirstResult($offset) + ->setMaxResults($perpage) + ->getQuery() + ->getResult(); + + // process rows + $rows = []; + foreach ($obj_rows as $orow) { + // add row data + $row['id'] = $orow->getID(); + $row['name'] = $orow->getName(); + + // add row metadata + $row['meta'] = [ + 'update_url' => '', + 'delete_url' => '' + ]; + + // add crud urls + if ($this->isGranted('geofence.update')) + $row['meta']['update_url'] = $this->generateUrl('geofence_update', ['id' => $row['id']]); + if ($this->isGranted('geofence.delete')) + $row['meta']['delete_url'] = $this->generateUrl('geofence_delete', ['id' => $row['id']]); + + $rows[] = $row; + } + + // response + return $this->json([ + 'meta' => $meta, + 'data' => $rows + ]); + } + + public function addForm() + { + $this->denyAccessUnlessGranted('geofence.add', null, 'No access.'); + + $params = $this->initParameters('geofence_list'); + $params['obj'] = new SupportedArea(); + $params['mode'] = 'create'; + + $this->fillFormTags($params); + + // response + return $this->render('geofence/form.html.twig', $params); + } + + public function updateForm($id) + { + $this->denyAccessUnlessGranted('geofence.update', null, 'No access.'); + + $params = $this->initParameters('geofence_list'); + + // get row data + $em = $this->getDoctrine()->getManager(); + $obj = $em->getRepository(SupportedArea::class)->find($id); + + // make sure this row exists + if (empty($obj)) + throw $this->createNotFoundException('The item does not exist'); + + $params['obj'] = $obj; + $params['mode'] = 'update'; + + $this->fillFormTags($params); + + // response + return $this->render('geofence/form.html.twig', $params); + } + + protected function initFormTags(&$params) + { + // default to editing, as we have more forms editing than creating + $params['ftags'] = [ + 'set_map_coordinate' => true, + ]; + } + + protected function fillFormTags(&$params) + { + $this->initFormTags($params); + + switch ($params['mode']) + { + case 'create': + $params['ftags']['set_map_coordinate'] = false; + break; + case 'update': + $params['ftags']['set_map_coordinate'] = true; + break; + } + } + + + protected function setQueryFilters($datatable, QueryBuilder $query) + { + if (isset($datatable['query']['data-rows-search']) && !empty($datatable['query']['data-rows-search'])) { + $query->where('q.name LIKE :filter') + ->setParameter('filter', '%' . $datatable['query']['data-rows-search'] . '%'); + } + } + +} diff --git a/templates/geofence/form.html.twig b/templates/geofence/form.html.twig new file mode 100644 index 00000000..c1f4a976 --- /dev/null +++ b/templates/geofence/form.html.twig @@ -0,0 +1,233 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +
+
+
+

Geofence

+
+
+
+ +
+ +
+
+
+
+
+
+ + + +

+ {% if mode == 'update' %} + Edit Geofence + {{ obj.getName }} + {% else %} + New Geofence + {% endif %} +

+
+
+
+
+
+
+
+ + + +
+
+
+
+ + + +
+ + + + +
+
+ +
+
+
+
+
+
+
+ + Back +
+
+
+
+
+
+
+
+
+{% endblock %} + +{% block scripts %} + + + + +{% endblock %} + + diff --git a/templates/geofence/list.html.twig b/templates/geofence/list.html.twig new file mode 100644 index 00000000..db6ad2cf --- /dev/null +++ b/templates/geofence/list.html.twig @@ -0,0 +1,144 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +
+
+
+

+ Geofence +

+
+
+
+ +
+ +
+
+
+
+
+
+
+
+
+
+ + + + +
+
+
+
+ +
+
+ +
+ +
+
+
+
+
+{% endblock %} + +{% block scripts %} + +{% endblock %} + + + From 9e9c59cd0b1a18cd43e0eee4b86655d24a60e088 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 31 May 2019 06:55:02 +0000 Subject: [PATCH 3/7] Display supported areas in google map. #220 --- config/acl.yaml | 4 - config/routes/geofence.yaml | 20 --- src/Controller/GeofenceController.php | 136 +-------------- templates/geofence/form.html.twig | 233 -------------------------- templates/geofence/list.html.twig | 164 ++++++------------ 5 files changed, 58 insertions(+), 499 deletions(-) delete mode 100644 templates/geofence/form.html.twig diff --git a/config/acl.yaml b/config/acl.yaml index 594a23f5..f6677bdf 100644 --- a/config/acl.yaml +++ b/config/acl.yaml @@ -172,10 +172,6 @@ access_keys: label: List - id: geofence.add label: Add - - id: geofence.update - label: Update - - id: geofence.delete - label: Delete - id: rider label: Rider Access diff --git a/config/routes/geofence.yaml b/config/routes/geofence.yaml index b210e0db..5d6a2ea9 100644 --- a/config/routes/geofence.yaml +++ b/config/routes/geofence.yaml @@ -4,11 +4,6 @@ geofence_list: path: /geofence controller: App\Controller\GeofenceController::index -geofence_rows: - path: /geofence/rows - controller: App\Controller\GeofenceController::rows - methods: [POST] - geofence_create: path: /geofence/create controller: App\Controller\GeofenceController::addForm @@ -18,18 +13,3 @@ geofence_create_submit: path: /geofence/create controller: App\Controller\GeofenceController::addSubmit methods: [POST] - -geofence_update: - path: /geofence/{id} - controller: App\Controller\GeofenceController::updateForm - methods: [GET] - -geofence_update_submit: - path: /geofence/{id} - controller: App\Controller\GeofenceController::updateSubmit - methods: [POST] - -geofence_delete: - path: /geofence/{id} - controller: App\Controller\GeofenceController::destroy - methods: [DELETE] diff --git a/src/Controller/GeofenceController.php b/src/Controller/GeofenceController.php index 91585d91..f96efda2 100644 --- a/src/Controller/GeofenceController.php +++ b/src/Controller/GeofenceController.php @@ -23,88 +23,13 @@ class GeofenceController extends BaseController $params = $this->initParameters('geofence_list'); - return $this->render('geofence/list.html.twig', $params); - } - - public function rows(Request $req) - { - $this->denyAccessUnlessGranted('geofence.list', null, 'No access.'); - // get query builder - $qb = $this->getDoctrine() + $params['areas'] = $this->getDoctrine() ->getRepository(SupportedArea::class) - ->createQueryBuilder('q'); - - // get datatable params - $datatable = $req->get('datatable'); - - // count total records - $tquery = $qb->select('COUNT(q)'); - $this->setQueryFilters($datatable, $tquery); - $total = $tquery->getQuery() - ->getSingleScalarResult(); - - // get current page number - $page = $datatable['pagination']['page'] ?? 1; - - $perpage = $datatable['pagination']['perpage']; - $offset = ($page - 1) * $perpage; - - // add metadata - $meta = [ - 'page' => $page, - 'perpage' => $perpage, - 'pages' => ceil($total / $perpage), - 'total' => $total, - 'sort' => 'asc', - 'field' => 'id' - ]; - - // build query - $query = $qb->select('q'); - $this->setQueryFilters($datatable, $query); - - // check if sorting is present, otherwise use default - if (isset($datatable['sort']['field']) && !empty($datatable['sort']['field'])) { - $order = $datatable['sort']['sort'] ?? 'asc'; - $query->orderBy('q.' . $datatable['sort']['field'], $order); - } else { - $query->orderBy('q.id', 'asc'); - } - - // get rows for this page - $obj_rows = $query->setFirstResult($offset) - ->setMaxResults($perpage) - ->getQuery() - ->getResult(); - - // process rows - $rows = []; - foreach ($obj_rows as $orow) { - // add row data - $row['id'] = $orow->getID(); - $row['name'] = $orow->getName(); - - // add row metadata - $row['meta'] = [ - 'update_url' => '', - 'delete_url' => '' - ]; - - // add crud urls - if ($this->isGranted('geofence.update')) - $row['meta']['update_url'] = $this->generateUrl('geofence_update', ['id' => $row['id']]); - if ($this->isGranted('geofence.delete')) - $row['meta']['delete_url'] = $this->generateUrl('geofence_delete', ['id' => $row['id']]); - - $rows[] = $row; - } + ->findAll(); // response - return $this->json([ - 'meta' => $meta, - 'data' => $rows - ]); + return $this->render('geofence/list.html.twig', $params); } public function addForm() @@ -121,59 +46,4 @@ class GeofenceController extends BaseController return $this->render('geofence/form.html.twig', $params); } - public function updateForm($id) - { - $this->denyAccessUnlessGranted('geofence.update', null, 'No access.'); - - $params = $this->initParameters('geofence_list'); - - // get row data - $em = $this->getDoctrine()->getManager(); - $obj = $em->getRepository(SupportedArea::class)->find($id); - - // make sure this row exists - if (empty($obj)) - throw $this->createNotFoundException('The item does not exist'); - - $params['obj'] = $obj; - $params['mode'] = 'update'; - - $this->fillFormTags($params); - - // response - return $this->render('geofence/form.html.twig', $params); - } - - protected function initFormTags(&$params) - { - // default to editing, as we have more forms editing than creating - $params['ftags'] = [ - 'set_map_coordinate' => true, - ]; - } - - protected function fillFormTags(&$params) - { - $this->initFormTags($params); - - switch ($params['mode']) - { - case 'create': - $params['ftags']['set_map_coordinate'] = false; - break; - case 'update': - $params['ftags']['set_map_coordinate'] = true; - break; - } - } - - - protected function setQueryFilters($datatable, QueryBuilder $query) - { - if (isset($datatable['query']['data-rows-search']) && !empty($datatable['query']['data-rows-search'])) { - $query->where('q.name LIKE :filter') - ->setParameter('filter', '%' . $datatable['query']['data-rows-search'] . '%'); - } - } - } diff --git a/templates/geofence/form.html.twig b/templates/geofence/form.html.twig deleted file mode 100644 index c1f4a976..00000000 --- a/templates/geofence/form.html.twig +++ /dev/null @@ -1,233 +0,0 @@ -{% extends 'base.html.twig' %} - -{% block body %} - -
-
-
-

Geofence

-
-
-
- -
- -
-
-
-
-
-
- - - -

- {% if mode == 'update' %} - Edit Geofence - {{ obj.getName }} - {% else %} - New Geofence - {% endif %} -

-
-
-
-
-
-
-
- - - -
-
-
-
- - - -
- - - - -
-
- -
-
-
-
-
-
-
- - Back -
-
-
-
-
-
-
-
-
-{% endblock %} - -{% block scripts %} - - - - -{% endblock %} - - diff --git a/templates/geofence/list.html.twig b/templates/geofence/list.html.twig index db6ad2cf..31dda159 100644 --- a/templates/geofence/list.html.twig +++ b/templates/geofence/list.html.twig @@ -5,9 +5,7 @@
-

- Geofence -

+

Geofence

@@ -17,36 +15,30 @@
-
-
-
-
-
-
-
- - - - -
-
-
-
-
- - - - Add Covered Area - - -
+
+
+
+ + + +

+ Covered Areas +

+
+
+
+
+
+
+
+ +
- -
- -
+
@@ -54,91 +46,45 @@ {% endblock %} {% block scripts %} - + - return actions; - }, - } - ], - search: { - onEnter: false, - input: $('#data-rows-search'), - delay: 400 - } - }; + + coveredarea.setMap(map); + {% endfor %} +} + +// END google maps stuff + + {% endblock %} - From f2a180420a5fa65eb79fa420108b46744234a413 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 3 Jun 2019 08:05:10 +0000 Subject: [PATCH 4/7] Add upload KML feature for geofence. #220 --- config/routes/geofence.yaml | 10 +-- src/Controller/GeofenceController.php | 24 ++++++- templates/geofence/form.html.twig | 96 +++++++++++++++++++++++++++ templates/geofence/list.html.twig | 18 +++-- 4 files changed, 134 insertions(+), 14 deletions(-) create mode 100644 templates/geofence/form.html.twig diff --git a/config/routes/geofence.yaml b/config/routes/geofence.yaml index 5d6a2ea9..a902802f 100644 --- a/config/routes/geofence.yaml +++ b/config/routes/geofence.yaml @@ -4,12 +4,12 @@ geofence_list: path: /geofence controller: App\Controller\GeofenceController::index +geofence_upload_kml: + path: /geofence/upload + controller: App\Controller\GeofenceController::uploadKML + methods: [POST] + geofence_create: path: /geofence/create controller: App\Controller\GeofenceController::addForm methods: [GET] - -geofence_create_submit: - path: /geofence/create - controller: App\Controller\GeofenceController::addSubmit - methods: [POST] diff --git a/src/Controller/GeofenceController.php b/src/Controller/GeofenceController.php index f96efda2..0411fd39 100644 --- a/src/Controller/GeofenceController.php +++ b/src/Controller/GeofenceController.php @@ -5,6 +5,9 @@ namespace App\Controller; use App\Ramcar\BaseController; use App\Entity\SupportedArea; +use App\Service\KMLFileImporter; +use App\Service\FileUploader; + use Doctrine\ORM\Query; use Doctrine\ORM\QueryBuilder; use Symfony\Component\HttpFoundation\Request; @@ -38,12 +41,27 @@ class GeofenceController extends BaseController $params = $this->initParameters('geofence_list'); $params['obj'] = new SupportedArea(); - $params['mode'] = 'create'; - - $this->fillFormTags($params); // response return $this->render('geofence/form.html.twig', $params); } + public function uploadKML(Request $req, FileUploader $uploader, KMLFileImporter $importer) + { + // retrieve temporary info for file + $file = $req->files->get('kml_file'); + + // upload the file + $filename = $uploader->upload($file); + + // process the kml file + $kml_file = $uploader->getTargetDir() . '/' . $filename; + $importer->getMapdata($kml_file); + + // return response + return $this->json([ + 'success' => true, + 'filename' => $filename + ]); + } } diff --git a/templates/geofence/form.html.twig b/templates/geofence/form.html.twig new file mode 100644 index 00000000..be2d4a5d --- /dev/null +++ b/templates/geofence/form.html.twig @@ -0,0 +1,96 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +
+
+
+

Geofence

+
+
+
+ +
+ +
+
+
+
+
+
+ + + +

+ New Coverage Area +

+
+
+
+
+
+
+
+ +
+
+

+ Drop files here or click to upload. +

+ + Upload only valid KML files + +
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+{% endblock %} + +{% block scripts %} + +{% endblock %} + diff --git a/templates/geofence/list.html.twig b/templates/geofence/list.html.twig index 31dda159..d26bf7ec 100644 --- a/templates/geofence/list.html.twig +++ b/templates/geofence/list.html.twig @@ -17,23 +17,29 @@
-
+
-

+

Covered Areas

+

+ + + + New Coverage Area + + +

+
-
+
-
From 0f6229405e70cbea0452ee4cf206567f11a76656 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 4 Jun 2019 00:42:58 +0000 Subject: [PATCH 5/7] Use getClientOriginalExtension() for the file extensions for file upload. #220 --- src/Service/FileUploader.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Service/FileUploader.php b/src/Service/FileUploader.php index d202ee68..10d4ec71 100644 --- a/src/Service/FileUploader.php +++ b/src/Service/FileUploader.php @@ -17,7 +17,8 @@ class FileUploader { do { - $filename = md5(uniqid()) . '.' . $file->guessExtension(); + //$filename = md5(uniqid()) . '.' . $file->guessExtension(); + $filename = md5(uniqid()) . '.' . $file->getClientOriginalExtension(); } while(file_exists($this->getTargetDir() . '/' . $filename)); From eaf77fc634cabde1f2adb24a980b3dee04746661 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 4 Jun 2019 07:15:56 +0000 Subject: [PATCH 6/7] Add rows table to geofence page with Delete action. #220 --- config/acl.yaml | 2 + config/routes/geofence.yaml | 10 +++ src/Controller/GeofenceController.php | 67 +++++++++++++- templates/geofence/list.html.twig | 123 +++++++++++++++++++++----- 4 files changed, 178 insertions(+), 24 deletions(-) diff --git a/config/acl.yaml b/config/acl.yaml index f6677bdf..85577e38 100644 --- a/config/acl.yaml +++ b/config/acl.yaml @@ -172,6 +172,8 @@ access_keys: label: List - id: geofence.add label: Add + - id: geofence.delete + label: Delete - id: rider label: Rider Access diff --git a/config/routes/geofence.yaml b/config/routes/geofence.yaml index a902802f..a050cc85 100644 --- a/config/routes/geofence.yaml +++ b/config/routes/geofence.yaml @@ -4,6 +4,11 @@ geofence_list: path: /geofence controller: App\Controller\GeofenceController::index +geofence_rows: + path: /geofence/rows + controller: App\Controller\GeofenceController::rows + methods: [POST] + geofence_upload_kml: path: /geofence/upload controller: App\Controller\GeofenceController::uploadKML @@ -13,3 +18,8 @@ geofence_create: path: /geofence/create controller: App\Controller\GeofenceController::addForm methods: [GET] + +geofence_delete: + path: /geofence/{id} + controller: App\Controller\GeofenceController::destroy + methods: [DELETE] diff --git a/src/Controller/GeofenceController.php b/src/Controller/GeofenceController.php index 0411fd39..7ccc4277 100644 --- a/src/Controller/GeofenceController.php +++ b/src/Controller/GeofenceController.php @@ -26,13 +26,53 @@ class GeofenceController extends BaseController $params = $this->initParameters('geofence_list'); - // get query builder $params['areas'] = $this->getDoctrine() + ->getRepository(SupportedArea::class) + ->findAll();; + + return $this->render('geofence/list.html.twig', $params); + } + + public function rows(Request $req) + { + $this->denyAccessUnlessGranted('geofence.list', null, 'No access.'); + + $params = $this->initParameters('geofence_list'); + + // get query builder + $obj_rows = $this->getDoctrine() ->getRepository(SupportedArea::class) ->findAll(); + // add metadata + $meta = [ + 'sort' => 'asc', + 'field' => 'id' + ]; + + // process rows + $rows = []; + foreach($obj_rows as $orow) { + // add row data + $row['id'] = $orow->getID(); + $row['name'] = $orow->getName(); + + // add row metadata + $row['meta'] = [ + 'delete_url' => '' + ]; + + if ($this->isGranted('geofence.delete')) + $row['meta']['delete_url'] = $this->generateUrl('geofence_delete', ['id' => $row['id']]); + + $rows[] = $row; + } + // response - return $this->render('geofence/list.html.twig', $params); + return $this->json([ + 'meta' => $meta, + 'data' => $rows + ]); } public function addForm() @@ -64,4 +104,27 @@ class GeofenceController extends BaseController 'filename' => $filename ]); } + + public function destroy($id) + { + $this->denyAccessUnlessGranted('geofence.delete', null, 'No access.'); + + $params = $this->initParameters('geofence_list'); + + // get object data + $em = $this->getDoctrine()->getManager(); + $obj = $em->getRepository(SupportedArea::class)->find($id); + + if (empty($obj)) + throw $this->createNotFoundException('The item does not exist'); + + // delete this object + $em->remove($obj); + $em->flush(); + + // response + $response = new Response(); + $response->setStatusCode(Response::HTTP_OK); + $response->send(); + } } diff --git a/templates/geofence/list.html.twig b/templates/geofence/list.html.twig index d26bf7ec..c3c417e9 100644 --- a/templates/geofence/list.html.twig +++ b/templates/geofence/list.html.twig @@ -32,17 +32,19 @@ -
-
-
-
-
+
+
+
+
+ +
+
@@ -56,9 +58,10 @@ {% endblock %} From b2e394d1b297d7fe616b005ccb3319ad44ce45e2 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 5 Jun 2019 06:18:51 +0000 Subject: [PATCH 7/7] Add highlighting of area in map and row when selecting an area. #220 --- config/routes/geofence.yaml | 5 - src/Controller/GeofenceController.php | 42 ------- templates/geofence/list.html.twig | 153 +++++++++++++------------- 3 files changed, 79 insertions(+), 121 deletions(-) diff --git a/config/routes/geofence.yaml b/config/routes/geofence.yaml index a050cc85..58a5dc3f 100644 --- a/config/routes/geofence.yaml +++ b/config/routes/geofence.yaml @@ -4,11 +4,6 @@ geofence_list: path: /geofence controller: App\Controller\GeofenceController::index -geofence_rows: - path: /geofence/rows - controller: App\Controller\GeofenceController::rows - methods: [POST] - geofence_upload_kml: path: /geofence/upload controller: App\Controller\GeofenceController::uploadKML diff --git a/src/Controller/GeofenceController.php b/src/Controller/GeofenceController.php index 7ccc4277..8c25983c 100644 --- a/src/Controller/GeofenceController.php +++ b/src/Controller/GeofenceController.php @@ -33,48 +33,6 @@ class GeofenceController extends BaseController return $this->render('geofence/list.html.twig', $params); } - public function rows(Request $req) - { - $this->denyAccessUnlessGranted('geofence.list', null, 'No access.'); - - $params = $this->initParameters('geofence_list'); - - // get query builder - $obj_rows = $this->getDoctrine() - ->getRepository(SupportedArea::class) - ->findAll(); - - // add metadata - $meta = [ - 'sort' => 'asc', - 'field' => 'id' - ]; - - // process rows - $rows = []; - foreach($obj_rows as $orow) { - // add row data - $row['id'] = $orow->getID(); - $row['name'] = $orow->getName(); - - // add row metadata - $row['meta'] = [ - 'delete_url' => '' - ]; - - if ($this->isGranted('geofence.delete')) - $row['meta']['delete_url'] = $this->generateUrl('geofence_delete', ['id' => $row['id']]); - - $rows[] = $row; - } - - // response - return $this->json([ - 'meta' => $meta, - 'data' => $rows - ]); - } - public function addForm() { $this->denyAccessUnlessGranted('geofence.add', null, 'No access.'); diff --git a/templates/geofence/list.html.twig b/templates/geofence/list.html.twig index c3c417e9..1b9598bc 100644 --- a/templates/geofence/list.html.twig +++ b/templates/geofence/list.html.twig @@ -35,16 +35,45 @@
-
+
- -
- +
+ {% if areas is empty %} + + {% else %} + + + + + + + + + + {% for result in areas %} + + + + + + {% endfor %} + +
IDName
{{ result.getID|default("") }}{{ result.getName|default("") }}
+ {% endif %} +
@@ -60,6 +89,8 @@ {% endblock %} - -