templates/main/index.html.twig line 1

Open in your IDE?
  1. {% extends 'base.html.twig' %}
  2. {% block title %}Rate My Parking{% endblock %}
  3. {% block body %}
  4. <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDWaJ2b1TAr9bscOiUQABTV3aqudLPlG9Q&callback=initMap&v=weekly" defer></script>
  5. <script type="text/javascript">
  6.     var postFilter = "new";
  7.     var initialBounds = null;
  8.     var map = null;
  9.     // Post Markers
  10.     var markerPosts = [];
  11.     jQuery.loadScript = function (url, callback) {
  12.         jQuery.ajax({
  13.             url: url,
  14.             dataType: 'script',
  15.             success: callback,
  16.             async: true
  17.         });
  18.     }
  19.     
  20.     function btnFilter(btn) {
  21.         switch (btn) {
  22.             case 1:
  23.                 postFilter = "new";
  24.                 $('#btnNewFilter').removeClass("btn-secondary");
  25.                 $('#btnNewFilter').addClass("btn-primary");
  26.                 $('#btnAllFilter').removeClass("btn-primary");
  27.                 $('#btnAllFilter').addClass("btn-secondary");
  28.                 break;
  29.             case 2:
  30.                 postFilter = "all";
  31.                 $('#btnNewFilter').removeClass("btn-primary");
  32.                 $('#btnNewFilter').addClass("btn-secondary");
  33.                 $('#btnAllFilter').removeClass("btn-secondary");
  34.                 $('#btnAllFilter').addClass("btn-primary");
  35.                 break;
  36.             default:
  37.                 postFilter = "new";
  38.                 $('#btnNewFilter').removeClass("btn-secondary");
  39.                 $('#btnNewFilter').addClass("btn-primary");
  40.                 $('#btnAllFilter').removeClass("btn-primary");
  41.                 $('#btnAllFilter').addClass("btn-secondary");
  42.                 break;
  43.         }
  44.         updateMapPosts();
  45.     }
  46.     
  47.     function updateMapPosts() {
  48.         initialBounds = map.getBounds();
  49.         
  50.         latlo = initialBounds.getSouthWest(0).lat(0);
  51.         lathi = initialBounds.getNorthEast(0).lat(0);
  52.         lonlo = initialBounds.getSouthWest(0).lng(0);
  53.         lonhi = initialBounds.getNorthEast(0).lng(0);
  54.         
  55.         //alert(latlo + " " + lathi + " " + lonlo + " " + lonhi);
  56.         
  57.         $.ajax({
  58.             type: 'POST',
  59.             url: '/data/getposts',
  60.             crossDomain: true,
  61.             dataType: "json",
  62.             data: { latlo: latlo, lathi: lathi, lonlo: lonlo, lonhi: lonhi, filter: postFilter },
  63.             success: function(responseData, textStatus, jqXHR) {
  64.                 markerPosts.forEach(function(marker) {
  65.                     marker.setMap(null);
  66.                 });
  67.                 markerPosts = [];
  68.                 if (responseData != null) {
  69.                     for (let i = 0; i < responseData.length; i++) {
  70.                         var image = responseData[i].Image;
  71.                     
  72.                         markerPosts[i] = new HTMLMapMarker({
  73.                             latlng: new google.maps.LatLng(parseFloat(responseData[i].Latitude), parseFloat(responseData[i].Longitude)),
  74.                             map: map,
  75.                             html: '<div class="asset-map-image-marker"><div class="image" style="background-image: url(' + image + ')"></div></div>',
  76.                         });
  77.                         
  78.                         markerPosts[i].addListener("click", () => {
  79.                             var url = '/data/getpost/' + responseData[i].Id;
  80.                             
  81.                             $.ajax({
  82.                                 type: 'POST',
  83.                                 url: url,
  84.                                 crossDomain: true,
  85.                                 dataType: "json",
  86.                                 success: function(imageData, imageStatus, imageXHR) {                        
  87.                                     var htmlBtn = "";
  88.                                     var htmlDiv = "";
  89.                                     for (let j = 0; j < imageData.images.length; j++) {
  90.                                         // Fill Btn Indicators Carousel HTML content
  91.                                         htmlBtn += '<button type="button" data-bs-target="#carouselIndicators" data-bs-slide-to="'+j+'" ';
  92.                                         if (j == 0) htmlBtn += 'class="active" aria-current="true" ';
  93.                                         htmlBtn += 'aria-label="Slide '+j+'"></button>';
  94.                                         
  95.                                         // Fill div Inner Carousel HTML content
  96.                                         htmlDiv += '<div class="carousel-item';
  97.                                         if (j == 0) htmlDiv += ' active';
  98.                                         htmlDiv += '">';
  99.                                         htmlDiv += '<img src="'+imageData.images[j].url+'" alt="Slide '+j+'">';
  100.                                         htmlDiv += '</div>';
  101.                                     }
  102.                                     
  103.                                     if (imageData.rated == 1) {
  104.                                         $('#divRate').addClass("invisible");
  105.                                     } else {
  106.                                         $('#divRate').removeClass("invisible");
  107.                                     }
  108.                                     $('#postModalLabel').html(imageData.infraction + " - Rating: " + imageData.rating);
  109.                                     $('#btn-Carousel-Indicators').html(htmlBtn);
  110.                                     $('#div-Carousel-Inner').html(htmlDiv);
  111.                                     
  112.                                     for (let k = 1; k <= 10; k++) {
  113.                                         $("#btnRate" + k).attr("onclick", "submitRating(" + imageData.id + ", " + k + ");");
  114.                                     }
  115.                                     
  116.                                     $('#postModal').modal('show');
  117.                                 },
  118.                                 error: function(imageData, imageStatus, imageThrown) {
  119.                                     alert("alert1: " +imageThrown);
  120.                                 }
  121.                             });
  122.                         });
  123.                     }
  124.                 }
  125.             },
  126.             error: function(responseData, textStatus, errorThrown) {
  127.             }
  128.         });
  129.     }
  130.     
  131.     // Initialize and add the map
  132.     function initMap() {
  133.         // The location of Uluru
  134.         const uluru = { lat: {{ records.latitude }}, lng: {{ records.longitude }} };
  135.         
  136.         // The map, centered at Uluru
  137.         map = new google.maps.Map(document.getElementById("map"), {
  138.             zoom: 15,
  139.             center: uluru,
  140.             mapTypeId: 'satellite',
  141.             mapTypeControl: false,
  142.             rotateControl: false,
  143.             fullscreenControl: false,
  144.         });
  145.                 
  146.         $.loadScript('/js/htmlmapmarker.js', function(){
  147.             // Event Map Bounds Changed
  148.             google.maps.event.addListener(map, 'bounds_changed', function() {
  149.                 try {
  150.                     updateMapPosts();
  151.                 } catch( err ) {
  152.                     alert( "alert2: "+err );
  153.                 }
  154.             });
  155.         });
  156.     }
  157.         
  158.     function submitRating(post, rate) {
  159.         $.ajax({
  160.             type: 'POST',
  161.             url: "/data/setrate/" + post,
  162.             crossDomain: true,
  163.             dataType: "json",
  164.             data: "rate=" + rate,
  165.             success: function(imageData, imageStatus, imageXHR) {            
  166.                 var modalTitle = $('#postModalLabel').html();
  167.                 modalTitle = modalTitle.split(':')[0]
  168.                 
  169.                 $('#postModalLabel').html(modalTitle + ": " + imageData.avgrating);
  170.                 $('#divRate').addClass("invisible");
  171.             },
  172.             error: function(imageData, imageStatus, imageThrown) {
  173.                 alert("alert3: "+imageThrown);
  174.             }
  175.         });
  176.     }
  177.     
  178.     window.initMap = initMap;
  179.  </script>
  180. <div class="container-fluid h-100 position-relative">
  181.     <div class="h-100" id="map"></div>
  182.     <button id="btnNewFilter" type="button" class="btn btn-primary position-absolute" style="top: 10px; left: 25px;" onclick="btnFilter(1);">New Posts</button>
  183.     <button id="btnAllFilter" type="button" class="btn btn-secondary position-absolute" style="top: 10px; left: 135px;" onclick="btnFilter(2);">All Posts</button>
  184. </div>
  185. <!-- Modal -->
  186. <style>
  187. .modal-dialog {
  188.     height: 95% !important;
  189. }
  190. .modal-content {
  191.     height: 95%;
  192.     background-color: #495057;
  193. }
  194. .modal-body {
  195.     height: calc(95% - 120px);
  196. }
  197. .carousel, slide {
  198.     height: 100%;
  199. }
  200. .carousel-inner {
  201.     height: 100%;
  202. }
  203. .carousel-item {
  204.     height: 100%;
  205. }
  206. .carousel-item img {
  207.     height: 100%;
  208.     justify-content: center;
  209.     display: flex;
  210.     margin-right: auto;
  211.     margin-left: auto;
  212.     object-fit: contain;
  213. }
  214. </style>
  215. <div class="modal fade" id="postModal" tabindex="-1" aria-labelledby="postModalLabel" aria-hidden="true">
  216.     <div class="modal-dialog modal-xl">
  217.         <div class="modal-content">
  218.             <div class="modal-header">
  219.                 <h1 class="modal-title fs-5" id="postModalLabel">Post</h1>
  220.                 <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
  221.             </div>
  222.             <div class="modal-body">
  223.                 <div id="carouselIndicators" class="carousel slide" data-bs-ride="true">
  224.                     <div id="btn-Carousel-Indicators" class="carousel-indicators">
  225.                         <!-- Fill by JS modal action -->
  226.                     </div>
  227.                     <div id="div-Carousel-Inner" class="carousel-inner">
  228.                         <!-- Fill by JS modal action -->
  229.                     </div>
  230.                     <button class="carousel-control-prev" type="button" data-bs-target="#carouselIndicators" data-bs-slide="prev">
  231.                         <span class="carousel-control-prev-icon" aria-hidden="true"></span>
  232.                         <span class="visually-hidden">Previous</span>
  233.                     </button>
  234.                     <button class="carousel-control-next" type="button" data-bs-target="#carouselIndicators" data-bs-slide="next">
  235.                         <span class="carousel-control-next-icon" aria-hidden="true"></span>
  236.                         <span class="visually-hidden">Next</span>
  237.                     </button>
  238.                 </div>
  239.             </div>
  240.             <div class="modal-footer">
  241.                 <div id="divRate" class="me-auto">
  242.                     <h1 class="fs-5 d-inline">Rate:</h5>
  243.                     {% for i in 1..10 %}
  244.                         <button id="btnRate{{ i }}" type="button" class="btn btn-primary d-inline" onclick="submitRating(1, {{ i }});">{{ i }}</button>
  245.                     {% endfor %}
  246.                 </div>
  247.                 <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
  248.             </div>
  249.         </div>
  250.     </div>
  251. </div>
  252. {% endblock %}