Add list, create, delete for blacklisted areas. #685
This commit is contained in:
parent
54f065d30f
commit
738cd74522
8 changed files with 501 additions and 3 deletions
|
|
@ -202,6 +202,17 @@ access_keys:
|
|||
label: Add
|
||||
- id: geofence.delete
|
||||
label: Delete
|
||||
- id: geofence_blacklist
|
||||
label: Geofence Blacklist
|
||||
acls:
|
||||
- id: geofence_blacklist.menu
|
||||
label: Menu
|
||||
- id: geofence_blacklist.list
|
||||
label: List
|
||||
- id: geofence_blacklist.add
|
||||
label: Add
|
||||
- id: geofence_blacklist.delete
|
||||
label: Delete
|
||||
|
||||
- id: rider
|
||||
label: Rider Access
|
||||
|
|
|
|||
|
|
@ -116,7 +116,11 @@ main_menu:
|
|||
parent: location
|
||||
- id: geofence_list
|
||||
acl: geofence.menu
|
||||
label: Geofence
|
||||
label: Geofence Whitelist
|
||||
parent: location
|
||||
- id: geofence_blacklist_list
|
||||
acl: geofence_blacklist.menu
|
||||
label: Geofence Blacklist
|
||||
parent: location
|
||||
|
||||
|
||||
|
|
|
|||
20
config/routes/geofence_blacklist.yaml
Normal file
20
config/routes/geofence_blacklist.yaml
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#geofence blacklist
|
||||
|
||||
geofence_blacklist_list:
|
||||
path: /geofence-blacklist
|
||||
controller: App\Controller\GeofenceBlacklistController::index
|
||||
|
||||
geofence_blacklist_upload_kml:
|
||||
path: /geofence-blacklist/upload
|
||||
controller: App\Controller\GeofenceBlacklistController::uploadKML
|
||||
methods: [POST]
|
||||
|
||||
geofence_blacklist_create:
|
||||
path: /geofence-blacklist/create
|
||||
controller: App\Controller\GeofenceBlacklistController::addForm
|
||||
methods: [GET]
|
||||
|
||||
geofence_blacklist_delete:
|
||||
path: /geofence-blacklist/{id}
|
||||
controller: App\Controller\GeofenceBlacklistController::destroy
|
||||
methods: [DELETE]
|
||||
91
src/Controller/GeofenceBlacklistController.php
Normal file
91
src/Controller/GeofenceBlacklistController.php
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\BlacklistArea;
|
||||
|
||||
use App\Service\KMLFileImporter;
|
||||
use App\Service\FileUploader;
|
||||
|
||||
use Doctrine\ORM\Query;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
|
||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
|
||||
|
||||
use Catalyst\MenuBundle\Annotation\Menu;
|
||||
|
||||
use CrEOF\Spatial\PHP\Types\Geometry\Point;
|
||||
use DateTime;
|
||||
|
||||
class GeofenceBlacklistController extends Controller
|
||||
{
|
||||
/**
|
||||
* @Menu(selected="geofence_blacklist_list")
|
||||
* @IsGranted("geofence_blacklist.list")
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$params['areas'] = $this->getDoctrine()
|
||||
->getRepository(BlacklistArea::class)
|
||||
->findAll();;
|
||||
|
||||
return $this->render('geofence-blacklist/list.html.twig', $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Menu(selected="geofence_blacklist_list")
|
||||
* @IsGranted("geofence_blacklist.add")
|
||||
*/
|
||||
public function addForm()
|
||||
{
|
||||
$params['obj'] = new BlacklistArea();
|
||||
|
||||
// response
|
||||
return $this->render('geofence-blacklist/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, 'blacklist');
|
||||
|
||||
// return response
|
||||
return $this->json([
|
||||
'success' => true,
|
||||
'filename' => $filename
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ParamConverter("blacklist_area", class="App\Entity\BlacklistArea")
|
||||
* @IsGranted("geofence_blacklist.delete")
|
||||
*/
|
||||
public function destroy(BlacklistArea $obj, EntityManagerInterface $em)
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
86
src/Entity/BlacklistArea.php
Normal file
86
src/Entity/BlacklistArea.php
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
use CrEOF\Spatial\PHP\Types\Geometry\Polygon;
|
||||
use DateTime;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="blacklist_area")
|
||||
*/
|
||||
class BlacklistArea
|
||||
{
|
||||
// unique id
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
// date blacklist area was created
|
||||
/**
|
||||
* @ORM\Column(type="datetime")
|
||||
*/
|
||||
protected $date_create;
|
||||
|
||||
// name of the blacklist area
|
||||
/**
|
||||
* @ORM\Column(type="string", length=80)
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
// coordinates of the blacklist area
|
||||
/**
|
||||
* @ORM\Column(type="polygon")
|
||||
*/
|
||||
protected $coverage_area;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->date_create = new DateTime();
|
||||
}
|
||||
|
||||
public function getID()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function setDateCreate(DateTime $date_create)
|
||||
{
|
||||
$this->date_create = $date_create;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDateCreate()
|
||||
{
|
||||
return $this->date_Create;
|
||||
}
|
||||
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setCoverageArea(Polygon $polygon)
|
||||
{
|
||||
$this->coverage_area = $polygon;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCoverageArea()
|
||||
{
|
||||
return $this->coverage_area;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -5,6 +5,7 @@ namespace App\Service;
|
|||
use XMLReader;
|
||||
|
||||
use App\Entity\SupportedArea;
|
||||
use App\Entity\BlacklistArea;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
|
|
@ -21,7 +22,7 @@ class KMLFileImporter
|
|||
$this->em = $em;
|
||||
}
|
||||
|
||||
public function getMapData($fh)
|
||||
public function getMapData($fh, $type=null)
|
||||
{
|
||||
$placemark_name = '';
|
||||
|
||||
|
|
@ -42,7 +43,13 @@ class KMLFileImporter
|
|||
if ($reader->nodeType == XMLReader::ELEMENT && $reader->name == "coordinates")
|
||||
{
|
||||
// each polygon is a new area
|
||||
// check if blacklist area or whitelist area.
|
||||
// type = null if whitelist
|
||||
if ($type == null)
|
||||
$supported_area = new SupportedArea();
|
||||
else
|
||||
$supported_area = new BlacklistArea();
|
||||
|
||||
$supported_area->setName($placemark_name);
|
||||
|
||||
$point_array = [];
|
||||
|
|
|
|||
96
templates/geofence-blacklist/form.html.twig
Normal file
96
templates/geofence-blacklist/form.html.twig
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block body %}
|
||||
<!-- BEGIN: Subheader -->
|
||||
<div class="m-subheader">
|
||||
<div class="d-flex align-items-center">
|
||||
<div class="mr-auto">
|
||||
<h3 class="m-subheader__title">Geofence Blacklist</h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- END: Subheader -->
|
||||
<div class="m-content">
|
||||
<!--Begin::Section-->
|
||||
<div class="row">
|
||||
<div class="col-xl-12">
|
||||
<div class="m-portlet m-portlet--mobile">
|
||||
<div class="m-portlet__head">
|
||||
<div class="m-portlet__head-caption">
|
||||
<div class="m-portlet__head-title">
|
||||
<span class="m-portlet__head-icon">
|
||||
<i class="fa fa-building"></i>
|
||||
</span>
|
||||
<h3 class="m-portlet__head-text">
|
||||
New Blacklist Area
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<form id="row-form" class="m-form m-form--label-align-right">
|
||||
<div class="m-portlet__body">
|
||||
<div class="form-group m-form__group row no-border">
|
||||
<div class="col-lg-6">
|
||||
<label data-field="kml_file">
|
||||
KML File
|
||||
</label>
|
||||
<div class="m-dropzone dropzone m-dropzone--primary" action="{{ url('geofence_blacklist_upload_kml') }}" id="kml-file">
|
||||
<div class="m-dropzone__msg dz-message needsclick">
|
||||
<h3 class="m-dropzone__msg-title">
|
||||
Drop files here or click to upload.
|
||||
</h3>
|
||||
<span class="m-dropzone__msg-desc">
|
||||
Upload only valid KML files
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-control-feedback hide" data-field="kml_file"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="m-portlet__foot m-portlet__foot--fit">
|
||||
<div class="m-form__actions m-form__actions--solid m-form__actions--right">
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<a href="{{ url('geofence_blacklist_list') }}" class="btn btn-success">Submit</button>
|
||||
<a href="{{ url('geofence_blacklist_list') }}" class="btn btn-secondary">Back</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script>
|
||||
// image upload
|
||||
Dropzone.options.kmlFile = {
|
||||
paramName: "kml_file", // The name that will be used to transfer the file
|
||||
maxFiles: 1,
|
||||
uploadMultiple: false,
|
||||
maxFilesize: 5, // MB
|
||||
addRemoveLinks: true,
|
||||
acceptedFiles: "text/xml, .kml",
|
||||
accept: function(file, done) {
|
||||
done();
|
||||
},
|
||||
init: function() {
|
||||
this.on("maxfilesexceeded", function(file) {
|
||||
// limit to one file, overwrite old one
|
||||
this.removeAllFiles();
|
||||
this.addFile(file);
|
||||
});
|
||||
},
|
||||
success: function(file, response) {
|
||||
if (response.success) {
|
||||
$("input[name='kml_file']").val(response.filename);
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
183
templates/geofence-blacklist/list.html.twig
Normal file
183
templates/geofence-blacklist/list.html.twig
Normal file
|
|
@ -0,0 +1,183 @@
|
|||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block body %}
|
||||
<!-- BEGIN: Subheader -->
|
||||
<div class="m-subheader">
|
||||
<div class="d-flex align-items-center">
|
||||
<div class="mr-auto">
|
||||
<h3 class="m-subheader__title">Geofence Blacklist</h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- END: Subheader -->
|
||||
<div class="m-content">
|
||||
<!--Begin::Section-->
|
||||
<div class="row">
|
||||
<div class="col-xl-12">
|
||||
<div class="m-portlet m-portlet--mobile">
|
||||
<div class="m-portlet__head">
|
||||
<div class="m-portlet__head-caption">
|
||||
<div class="m-portlet__head-title col-xl-12">
|
||||
<span class="m-portlet__head-icon">
|
||||
<i class="fa fa-building"></i>
|
||||
</span>
|
||||
<h3 class="m-portlet__head-text col-xl-4">
|
||||
Blacklist Areas
|
||||
</h3>
|
||||
<h3 class="m-portlet__head-text col-xl-8" align="right">
|
||||
<a href="{{ url('geofence_blacklist_create') }}" class="btn btn-focus m-btn m-btn--custom m-btn--icon m-btn--air m-btn--pill">
|
||||
<span>
|
||||
<i class="fa fa-building"></i>
|
||||
<span>New Blacklist Area</span>
|
||||
</span>
|
||||
</a>
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<form id="row-form" class="m-form m-form--fit m-form--label-align-right m-form--group-seperator-dashed" method="POST" }}">
|
||||
<div class="m-portlet__body">
|
||||
<div class="form-group m-form__group row">
|
||||
<div class="col-lg-12">
|
||||
<div id="m_gmap" style="height:600px;"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div id = "area-rows" class="form-group m-form__group row">
|
||||
{% if areas is empty %}
|
||||
<div class="m-alert m-alert--icon m-alert--icon-solid m-alert--outline alert alert-brand" role="alert">
|
||||
<div class="m-alert__icon">
|
||||
<i class="flaticon-exclamation-2"></i>
|
||||
<span></span>
|
||||
</div>
|
||||
<div class="m-alert__text">
|
||||
No records for blacklist area.
|
||||
</div>
|
||||
</div>
|
||||
{% else %}
|
||||
<table id="area-table" class="table table-striped m-table">
|
||||
<thead>
|
||||
<tr class="m-table__row--brand">
|
||||
<th>ID</th>
|
||||
<th>Name</th>
|
||||
<th> </th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for result in areas %}
|
||||
<tr>
|
||||
<td>{{ result.getID|default("") }}</td>
|
||||
<td>{{ result.getName|default("") }}</td>
|
||||
<td> <a href="{{ url('geofence_blacklist_delete', {'id': result.getID }) }}" class="m-portlet__nav-link btn m-btn m-btn--hover-danger m-btn--icon m-btn--icon-only m-btn--pill btn-delete"> <i class="la la-trash"> </a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script src="//maps.google.com/maps/api/js?key={{ gmaps_api_key }}" type="text/javascript"></script>
|
||||
<script src="/assets/vendors/custom/gmaps/gmaps.js" type="text/javascript"></script>
|
||||
|
||||
<script>
|
||||
// BEGIN google maps stuff
|
||||
|
||||
var polygons = new Array();
|
||||
|
||||
initMap();
|
||||
|
||||
function initMap() {
|
||||
var map = new google.maps.Map(document.getElementById('m_gmap'),
|
||||
{
|
||||
center: {
|
||||
lat: {% trans %}default_lat{% endtrans %},
|
||||
lng: {% trans %}default_long{% endtrans %},
|
||||
},
|
||||
mapTypeId: 'roadmap',
|
||||
zoom: 13
|
||||
});
|
||||
|
||||
{% if areas %}
|
||||
{% for obj in areas %}
|
||||
var pointsArray = new Array();
|
||||
|
||||
{% for point in obj.getCoverageArea.getRing(0).getPoints() %}
|
||||
var polylatlng = new google.maps.LatLng(
|
||||
{{ point.getLatitude }},
|
||||
{{ point.getLongitude }});
|
||||
|
||||
pointsArray.push(polylatlng);
|
||||
{% endfor %}
|
||||
|
||||
var coveredarea = new google.maps.Polygon({
|
||||
paths: pointsArray,
|
||||
fillColor: "#FF0000",
|
||||
fillOpacity: .5,
|
||||
mapTypeId: 'roadmap'
|
||||
});
|
||||
coveredarea.setMap(map);
|
||||
|
||||
polygons[{{ obj.getID}}] = coveredarea;
|
||||
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
}
|
||||
|
||||
// END google maps stuff
|
||||
|
||||
$('tr td').click(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var currentRow = $(this).closest('tr');
|
||||
var id = currentRow.find('td:eq(0)').text();
|
||||
|
||||
if (id in polygons)
|
||||
{
|
||||
for (var p in polygons)
|
||||
{
|
||||
var pg = polygons[p];
|
||||
pg.setOptions({fillColor: "#FF0000"});
|
||||
};
|
||||
|
||||
var polygon = polygons[id];
|
||||
polygon.setOptions({fillColor: '#32CD32'});
|
||||
}
|
||||
|
||||
currentRow.addClass('bg-warning').siblings().removeClass('bg-warning');
|
||||
|
||||
});
|
||||
|
||||
$(document).on('click', '.btn-delete', function(e) {
|
||||
var url = $(this).prop('href');
|
||||
var currentRow = $(this).closest('tr');
|
||||
var id = currentRow.find('td:eq(1)').text();
|
||||
var btn = $(this);
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
swal({
|
||||
title: 'Confirmation',
|
||||
html: 'Are you sure you want to delete <strong>' + id + '</strong>?',
|
||||
type: 'warning',
|
||||
showCancelButton: true
|
||||
}).then((result) => {
|
||||
if (result.value) {
|
||||
$.ajax({
|
||||
method: "DELETE",
|
||||
url: url
|
||||
}).done(function(response) {
|
||||
window.location.reload();
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
{% endblock %}
|
||||
Loading…
Reference in a new issue