diff --git a/config/acl.yaml b/config/acl.yaml index 1b378e66..0cd66ef5 100644 --- a/config/acl.yaml +++ b/config/acl.yaml @@ -189,6 +189,17 @@ access_keys: label: Update - id: hub.delete label: Delete + - id: geofence + label: Geofence + acls: + - id: geofence.menu + label: Menu + - id: geofence.list + label: List + - id: geofence.add + label: Add + - id: geofence.delete + label: Delete - id: rider label: Rider Access diff --git a/config/menu.yaml b/config/menu.yaml index d5efba1b..3cfb83e5 100644 --- a/config/menu.yaml +++ b/config/menu.yaml @@ -88,6 +88,10 @@ main_menu: acl: hub.menu label: Hub parent: location + - id: geofence_list + acl: geofence.menu + label: Geofence + parent: location - id: joborder diff --git a/config/routes/geofence.yaml b/config/routes/geofence.yaml new file mode 100644 index 00000000..58a5dc3f --- /dev/null +++ b/config/routes/geofence.yaml @@ -0,0 +1,20 @@ +#geofence + +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_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..8c25983c --- /dev/null +++ b/src/Controller/GeofenceController.php @@ -0,0 +1,88 @@ +denyAccessUnlessGranted('geofence.list', null, 'No access.'); + + $params = $this->initParameters('geofence_list'); + + $params['areas'] = $this->getDoctrine() + ->getRepository(SupportedArea::class) + ->findAll();; + + return $this->render('geofence/list.html.twig', $params); + } + + public function addForm() + { + $this->denyAccessUnlessGranted('geofence.add', null, 'No access.'); + + $params = $this->initParameters('geofence_list'); + $params['obj'] = new SupportedArea(); + + // 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 + ]); + } + + 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/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)); 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 new file mode 100644 index 00000000..1b9598bc --- /dev/null +++ b/templates/geofence/list.html.twig @@ -0,0 +1,180 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +
+
+
+

Geofence

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

+ Covered Areas +

+

+ + + + New Coverage Area + + +

+
+
+
+
+
+
+
+
+
+
+
+ {% if areas is empty %} + + {% else %} + + + + + + + + + + {% for result in areas %} + + + + + + {% endfor %} + +
IDName
{{ result.getID|default("") }}{{ result.getName|default("") }}
+ {% endif %} +
+
+
+
+
+
+
+{% endblock %} + +{% block scripts %} + + + + +{% endblock %}