commit dfe432185233d62f8a8062491ae8481c2aea546a
Author: vastja <vastja@gmail.com>
Date:   Mon May 11 10:57:41 2020 +0200

    + validace

diff --git a/website/public/js/zcu-heatmap.js b/website/public/js/zcu-heatmap.js
index 686349c..ccae886 100644
--- a/website/public/js/zcu-heatmap.js
+++ b/website/public/js/zcu-heatmap.js
@@ -223,6 +223,13 @@ function updateAvailableDataSets(available) {
     options += '<option value="' + value + '">' + key + '</option>\n'; 
   });
 
+  if (options === '') {
+    $('#submit-btn').prop('disabled', true);
+  }
+  else {
+    $('#submit-btn').prop('disabled', false);
+  }
+
   $('#type').empty().append(options);
   
 }
diff --git a/website/src/Controller/HeatmapController.php b/website/src/Controller/HeatmapController.php
index 867202b..52ac429 100644
--- a/website/src/Controller/HeatmapController.php
+++ b/website/src/Controller/HeatmapController.php
@@ -13,16 +13,18 @@ class HeatmapController extends AbstractController {
     /**
      * @Route("/heatmap", name="heatmap")
      */
-    public function index(Request $request) {
+    public function index(Request $request, IOpenDataManager $manager) {
         $dataSet = new DataSet();
 
         $form = $this->createForm(DataSetType::class, $dataSet);
         $form->handleRequest($request);
 
-        // Todo validation
-        // $form->isValid()
         if ($form->isSubmitted()) {
             $dataSet = $form->getData();
+            $name = $manager->getXthAvailableCollectionByDay($dataSet->getType(), $dataSet->getDate());
+            if (false == $manager->isCollectionAvailable($name, $dataSet->getDate())) {
+                $form = $this->createForm(DataSetType::class, new DataSet());
+            }
         }
 
         return $this->render(
diff --git a/website/src/Entity/DataSet.php b/website/src/Entity/DataSet.php
index 4fb7e0c..d6c294f 100644
--- a/website/src/Entity/DataSet.php
+++ b/website/src/Entity/DataSet.php
@@ -17,7 +17,7 @@ class DataSet {
     }
 
     public function setDate($date) {
-        $this->date = $date;
+        $this->date = date('dmY', strtotime($date));
     }
 
     public function getDate() {
diff --git a/website/src/IOpenDataManager.php b/website/src/IOpenDataManager.php
index feb89c3..7ffce16 100644
--- a/website/src/IOpenDataManager.php
+++ b/website/src/IOpenDataManager.php
@@ -8,4 +8,10 @@ interface IOpenDataManager {
     public function getAvailableCollections();
 
     public function getAvailableCollectionsByDay($date);
+    
+    public function getXthAvailableCollectionByDay($index, $date);
+
+    public function isCollectionAvailable($name, $date);
+
+    public function getMaxCollectionNumberAtDay($name, $date);
 }
diff --git a/website/src/OpenDataManager.php b/website/src/OpenDataManager.php
index 80a142e..f1d7a1c 100644
--- a/website/src/OpenDataManager.php
+++ b/website/src/OpenDataManager.php
@@ -45,10 +45,7 @@ class OpenDataManager implements IOpenDataManager {
         $available = $this->getAvailableCollections();
         $index = 0;
         foreach ($available as $key => $value) {
-            $command = new Command(['listCollections' => 1, 'filter' => ['name' => $value['name'].$date]]);
-            $result = $this->manager->executeCommand('open-data-db', $command)->toArray();
-
-            if (false == empty($result) && false == array_key_exists($value['name'], $availableInDate)) {
+            if ($this->isCollectionAvailable($value['name'], $date) && false == array_key_exists($value['name'], $availableInDate)) {
                 $availableInDate[$value['name']] = $index++;
             }
         }
@@ -56,6 +53,33 @@ class OpenDataManager implements IOpenDataManager {
         return $availableInDate;
     }
 
+    public function getXthAvailableCollectionByDay($index, $date) {
+        $availableInDate = [];
+        $available = $this->getAvailableCollections();
+        $currentIndex = 0;
+
+        foreach ($available as $key => $value) {
+            if ($this->isCollectionAvailable($value['name'], $date) && false == array_key_exists($value['name'], $availableInDate)) {
+                if ($currentIndex == $index) {
+                    return $value['name'];
+                }
+                else {
+                    $currentIndex++;
+                }
+            }
+        }
+
+        return "";
+    }
+
+    public function isCollectionAvailable($name, $date) {
+
+        $command = new Command(['listCollections' => 1, 'filter' => ['name' => $name.$date]]);
+        $result = $this->manager->executeCommand('open-data-db', $command)->toArray();
+
+        return !empty($result);
+    }
+
     public function getMaxCollectionNumberAtDay($name, $date) {
         $max = $this->manager->executeQuery('open-data-db.'.$name.$date, new Query([], ['sort' => ['number' => -1], 'limit' => 1]));
 
diff --git a/website/templates/heatmap.html.twig b/website/templates/heatmap.html.twig
index 86c47e6..3d0365b 100644
--- a/website/templates/heatmap.html.twig
+++ b/website/templates/heatmap.html.twig
@@ -33,7 +33,7 @@
                   'type' : 'date',
                   'id' : 'date',
                   'attr' : {
-                    'max' : 'now'|date('d-m-Y'),
+                    'max' : 'now'|date('Y-m-d'),
                     'class' : 'form-control',                 
                     'onChange' : 'checkDataSetsAvailability("' ~ path('available') ~ '")'
                   }
@@ -71,6 +71,7 @@
                 {
                   'label' : 'Potvrdit výběr',
                   'type' : 'submit',
+                  'id' : 'submit-btn',
                   'attr' : {
                     'class': 'btn btn-secondary'
                   }
