commit 55098dbb88feff1302dfdabf4c1c162a2f8444f2
Author: Tomáš Ballák <balllak.tomas@gmail.com>
Date:   Mon Apr 20 21:46:48 2020 +0200

    Re #7857

diff --git a/.gitignore b/.gitignore
index ddeec69..3f33a9a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,4 @@ cache
 database/
 dev-dump/
 *.lock
+.env
diff --git a/website/.env b/website/.env
deleted file mode 100644
index dfeb211..0000000
--- a/website/.env
+++ /dev/null
@@ -1,21 +0,0 @@
-# In all environments, the following files are loaded if they exist,
-# the latter taking precedence over the former:
-#
-#  * .env                contains default values for the environment variables needed by the app
-#  * .env.local          uncommitted file with local overrides
-#  * .env.$APP_ENV       committed environment-specific defaults
-#  * .env.$APP_ENV.local uncommitted environment-specific overrides
-#
-# Real environment variables win over .env files.
-#
-# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES.
-#
-# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2).
-# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration
-
-###> symfony/framework-bundle ###
-APP_ENV=dev
-APP_SECRET=ca5751564bbb9a0d75d412e020790283
-#TRUSTED_PROXIES=127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16
-#TRUSTED_HOSTS='^(localhost|example\.com)$'
-###< symfony/framework-bundle ###
diff --git a/website/config/services.yaml b/website/config/services.yaml
index 5c4b417..d318be5 100644
--- a/website/config/services.yaml
+++ b/website/config/services.yaml
@@ -4,12 +4,15 @@
 # Put parameters here that don't need to change on each machine where the app is deployed
 # https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
 parameters:
+    databaseConnectionString: 'mongodb://root:root@database'
 
 services:
     # default configuration for services in *this* file
     _defaults:
         autowire: true      # Automatically injects dependencies in your services.
         autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
+        bind:
+            $connectionString: '%databaseConnectionString%'
 
     # makes classes in src/ available to be used as services
     # this creates a service per class whose id is the fully-qualified class name
@@ -25,3 +28,6 @@ services:
 
     # add more service definitions when explicit configuration is needed
     # please note that last definitions always *replace* previous ones
+
+    App\OpenData\OpenDataManager: ~      
+    App\OpenData\IOpenDataManager: '@App\OpenData\OpenDataManager'
diff --git a/website/public/js/zcu-heatmap.js b/website/public/js/zcu-heatmap.js
new file mode 100644
index 0000000..c209c05
--- /dev/null
+++ b/website/public/js/zcu-heatmap.js
@@ -0,0 +1,40 @@
+var mymap;
+
+
+function initMap(x = 49.724, y = 13.352, zoom = 17) {
+
+    mymap = L.map('heatmap').setView([x, y], zoom);
+
+    L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
+        attribution: '&copy; <a href="https://openstreetmap.org/copyright">OpenStreetMap contributors</a>',
+        maxZoom: 19
+    }).addTo(mymap);
+    
+    
+
+}
+
+function showHeatmap(route) {
+
+    $.ajax({
+        type: "POST",
+        url: route, 
+        success: function(result) {
+            drawHeatmap(result);
+        }
+    });
+
+}
+
+function drawHeatmap(points) {
+        
+    // Flipped x and y
+    points = points.map(function (p) { return [p['y'], p['x'], p['number']]; });
+
+    L.heatLayer(points).addTo(mymap), draw = true;
+
+}
+            
+            
+
+
diff --git a/website/src/Controller/HeatmapController.php b/website/src/Controller/HeatmapController.php
index 7952251..6c88dcb 100644
--- a/website/src/Controller/HeatmapController.php
+++ b/website/src/Controller/HeatmapController.php
@@ -2,9 +2,7 @@
 
 namespace App\Controller;
 
-use App\Entity\OpenData;
-use MongoDB\Driver\Query;
-use MongoDB\Driver\Manager;
+use App\OpenData\IOpenDataManager;
 use Symfony\Component\Routing\Annotation\Route;
 use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
 
@@ -13,37 +11,13 @@ class HeatmapController extends AbstractController {
      * @Route("/heatmap")
      */
     public function index() {
-        $manager = new Manager(
-            'mongodb://root:root@database'
-        );
-
-        $openData = $manager->executeQuery('open-data-db.KOLOBEZKY31102018', new Query([], []));
-        $openData->setTypeMap([
-            'array' => 'array',
-            'document' => 'array',
-            'root' => 'array',
-        ]);
-
-        return $this->render('heatmap.html.twig', [
-            'open_data' => $openData->toArray(),
-        ]);
+        return $this->render('heatmap.html.twig');
     }
 
     /**
-     * @Route("heatmap/opendata", name="opendata")
+     * @Route("heatmap/opendata/{collectionName}", name="opendata")
      */
-    public function opendata() {
-        $manager = new Manager(
-            'mongodb://root:root@database'
-        );
-
-        $openData = $manager->executeQuery('open-data-db.KOLOBEZKY31102018', new Query([], []));
-        $openData->setTypeMap([
-            'array' => 'array',
-            'document' => 'array',
-            'root' => 'array',
-        ]);
-
-        return $this->json($openData->toArray());
+    public function opendata(IOpenDataManager $manager, $collectionName) {
+        return $this->json($manager->getCollectionDataByName($collectionName));
     }
 }
diff --git a/website/src/IOpenDataManager.php b/website/src/IOpenDataManager.php
new file mode 100644
index 0000000..6b62fed
--- /dev/null
+++ b/website/src/IOpenDataManager.php
@@ -0,0 +1,7 @@
+<?php
+
+namespace App\OpenData;
+
+interface IOpenDataManager {
+    public function getCollectionDataByName($name);
+}
diff --git a/website/src/OpenDataManager.php b/website/src/OpenDataManager.php
new file mode 100644
index 0000000..4f31b2f
--- /dev/null
+++ b/website/src/OpenDataManager.php
@@ -0,0 +1,28 @@
+<?php
+
+namespace App\OpenData;
+
+use MongoDB\Driver\Query;
+use MongoDB\Driver\Manager;
+
+class OpenDataManager implements IOpenDataManager {
+    private $manager;
+
+    public function __construct() {
+        $this->manager = new Manager(
+            $_ENV['DATABASE_CONNECTION_STRING']
+        );
+    }
+
+    public function getCollectionDataByName($name) {
+        $openData = $this->manager->executeQuery($name, new Query([], []));
+
+        $openData->setTypeMap([
+            'array' => 'array',
+            'document' => 'array',
+            'root' => 'array',
+        ]);
+
+        return $openData->toArray();
+    }
+}
diff --git a/website/templates/heatmap.html.twig b/website/templates/heatmap.html.twig
index 8db75ea..6cf669e 100644
--- a/website/templates/heatmap.html.twig
+++ b/website/templates/heatmap.html.twig
@@ -24,37 +24,11 @@
     <script src="https://code.jquery.com/jquery-3.5.0.min.js" integrity="sha256-xNzN2a4ltkB44Mc/Jz3pT4iU1cmeR0FkXs4pru/JxaQ=" crossorigin="anonymous"></script>
     <script src="{{ asset('js/leaflet.js') }}"></script>
     <script src="{{ asset('js/leaflet-heat.js') }}"></script>
-
+    <script src="{{ asset('js/zcu-heatmap.js') }}"></script>
     <script>
 
-        $(document).ready(function() {
-            
-            var mymap = L.map('heatmap').setView([49.724, 13.352], 17);
-
-            L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
-                attribution: '&copy; <a href="https://openstreetmap.org/copyright">OpenStreetMap contributors</a>',
-                maxZoom: 19
-            }).addTo(mymap);
-            
-            $.ajax({
-                type: "POST",
-                url: "{{ path('opendata') }}",
-                success: function(result) {
-                    heatmap(result);
-                }
-            });
-        
-            function heatmap(points) {
-                
-                points = points.map(function (p) { return [p['y'], p['x'], p['number']]; });
-
-                var heat = L.heatLayer(points).addTo(mymap),
-                    draw = true;
-
-            }
-
-        });
-
+       initMap();
+       showHeatmap("{{ path('opendata', {'collectionName':'open-data-db.KOLOBEZKY31102018'}) }}");
 
     </script>
 
