{% extends 'base.html.twig' %}
{% block title %}Rate My Parking{% endblock %}
{% block body %}
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDWaJ2b1TAr9bscOiUQABTV3aqudLPlG9Q&callback=initMap&v=weekly" defer></script>
<script type="text/javascript">
var postFilter = "new";
var initialBounds = null;
var map = null;
// Post Markers
var markerPosts = [];
jQuery.loadScript = function (url, callback) {
jQuery.ajax({
url: url,
dataType: 'script',
success: callback,
async: true
});
}
function btnFilter(btn) {
switch (btn) {
case 1:
postFilter = "new";
$('#btnNewFilter').removeClass("btn-secondary");
$('#btnNewFilter').addClass("btn-primary");
$('#btnAllFilter').removeClass("btn-primary");
$('#btnAllFilter').addClass("btn-secondary");
break;
case 2:
postFilter = "all";
$('#btnNewFilter').removeClass("btn-primary");
$('#btnNewFilter').addClass("btn-secondary");
$('#btnAllFilter').removeClass("btn-secondary");
$('#btnAllFilter').addClass("btn-primary");
break;
default:
postFilter = "new";
$('#btnNewFilter').removeClass("btn-secondary");
$('#btnNewFilter').addClass("btn-primary");
$('#btnAllFilter').removeClass("btn-primary");
$('#btnAllFilter').addClass("btn-secondary");
break;
}
updateMapPosts();
}
function updateMapPosts() {
initialBounds = map.getBounds();
latlo = initialBounds.getSouthWest(0).lat(0);
lathi = initialBounds.getNorthEast(0).lat(0);
lonlo = initialBounds.getSouthWest(0).lng(0);
lonhi = initialBounds.getNorthEast(0).lng(0);
//alert(latlo + " " + lathi + " " + lonlo + " " + lonhi);
$.ajax({
type: 'POST',
url: '/data/getposts',
crossDomain: true,
dataType: "json",
data: { latlo: latlo, lathi: lathi, lonlo: lonlo, lonhi: lonhi, filter: postFilter },
success: function(responseData, textStatus, jqXHR) {
markerPosts.forEach(function(marker) {
marker.setMap(null);
});
markerPosts = [];
if (responseData != null) {
for (let i = 0; i < responseData.length; i++) {
var image = responseData[i].Image;
markerPosts[i] = new HTMLMapMarker({
latlng: new google.maps.LatLng(parseFloat(responseData[i].Latitude), parseFloat(responseData[i].Longitude)),
map: map,
html: '<div class="asset-map-image-marker"><div class="image" style="background-image: url(' + image + ')"></div></div>',
});
markerPosts[i].addListener("click", () => {
var url = '/data/getpost/' + responseData[i].Id;
$.ajax({
type: 'POST',
url: url,
crossDomain: true,
dataType: "json",
success: function(imageData, imageStatus, imageXHR) {
var htmlBtn = "";
var htmlDiv = "";
for (let j = 0; j < imageData.images.length; j++) {
// Fill Btn Indicators Carousel HTML content
htmlBtn += '<button type="button" data-bs-target="#carouselIndicators" data-bs-slide-to="'+j+'" ';
if (j == 0) htmlBtn += 'class="active" aria-current="true" ';
htmlBtn += 'aria-label="Slide '+j+'"></button>';
// Fill div Inner Carousel HTML content
htmlDiv += '<div class="carousel-item';
if (j == 0) htmlDiv += ' active';
htmlDiv += '">';
htmlDiv += '<img src="'+imageData.images[j].url+'" alt="Slide '+j+'">';
htmlDiv += '</div>';
}
if (imageData.rated == 1) {
$('#divRate').addClass("invisible");
} else {
$('#divRate').removeClass("invisible");
}
$('#postModalLabel').html(imageData.infraction + " - Rating: " + imageData.rating);
$('#btn-Carousel-Indicators').html(htmlBtn);
$('#div-Carousel-Inner').html(htmlDiv);
for (let k = 1; k <= 10; k++) {
$("#btnRate" + k).attr("onclick", "submitRating(" + imageData.id + ", " + k + ");");
}
$('#postModal').modal('show');
},
error: function(imageData, imageStatus, imageThrown) {
alert("alert1: " +imageThrown);
}
});
});
}
}
},
error: function(responseData, textStatus, errorThrown) {
}
});
}
// Initialize and add the map
function initMap() {
// The location of Uluru
const uluru = { lat: {{ records.latitude }}, lng: {{ records.longitude }} };
// The map, centered at Uluru
map = new google.maps.Map(document.getElementById("map"), {
zoom: 15,
center: uluru,
mapTypeId: 'satellite',
mapTypeControl: false,
rotateControl: false,
fullscreenControl: false,
});
$.loadScript('/js/htmlmapmarker.js', function(){
// Event Map Bounds Changed
google.maps.event.addListener(map, 'bounds_changed', function() {
try {
updateMapPosts();
} catch( err ) {
alert( "alert2: "+err );
}
});
});
}
function submitRating(post, rate) {
$.ajax({
type: 'POST',
url: "/data/setrate/" + post,
crossDomain: true,
dataType: "json",
data: "rate=" + rate,
success: function(imageData, imageStatus, imageXHR) {
var modalTitle = $('#postModalLabel').html();
modalTitle = modalTitle.split(':')[0]
$('#postModalLabel').html(modalTitle + ": " + imageData.avgrating);
$('#divRate').addClass("invisible");
},
error: function(imageData, imageStatus, imageThrown) {
alert("alert3: "+imageThrown);
}
});
}
window.initMap = initMap;
</script>
<div class="container-fluid h-100 position-relative">
<div class="h-100" id="map"></div>
<button id="btnNewFilter" type="button" class="btn btn-primary position-absolute" style="top: 10px; left: 25px;" onclick="btnFilter(1);">New Posts</button>
<button id="btnAllFilter" type="button" class="btn btn-secondary position-absolute" style="top: 10px; left: 135px;" onclick="btnFilter(2);">All Posts</button>
</div>
<!-- Modal -->
<style>
.modal-dialog {
height: 95% !important;
}
.modal-content {
height: 95%;
background-color: #495057;
}
.modal-body {
height: calc(95% - 120px);
}
.carousel, slide {
height: 100%;
}
.carousel-inner {
height: 100%;
}
.carousel-item {
height: 100%;
}
.carousel-item img {
height: 100%;
justify-content: center;
display: flex;
margin-right: auto;
margin-left: auto;
object-fit: contain;
}
</style>
<div class="modal fade" id="postModal" tabindex="-1" aria-labelledby="postModalLabel" aria-hidden="true">
<div class="modal-dialog modal-xl">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="postModalLabel">Post</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div id="carouselIndicators" class="carousel slide" data-bs-ride="true">
<div id="btn-Carousel-Indicators" class="carousel-indicators">
<!-- Fill by JS modal action -->
</div>
<div id="div-Carousel-Inner" class="carousel-inner">
<!-- Fill by JS modal action -->
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#carouselIndicators" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#carouselIndicators" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
</div>
<div class="modal-footer">
<div id="divRate" class="me-auto">
<h1 class="fs-5 d-inline">Rate:</h5>
{% for i in 1..10 %}
<button id="btnRate{{ i }}" type="button" class="btn btn-primary d-inline" onclick="submitRating(1, {{ i }});">{{ i }}</button>
{% endfor %}
</div>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
{% endblock %}