Projekt

Obecné

Profil

« Předchozí | Další » 

Revize dfe43218

Přidáno uživatelem Jakub Vašta před asi 4 roky(ů)

+ validace

Zobrazit rozdíly:

website/public/js/zcu-heatmap.js
223 223
    options += '<option value="' + value + '">' + key + '</option>\n'; 
224 224
  });
225 225

  
226
  if (options === '') {
227
    $('#submit-btn').prop('disabled', true);
228
  }
229
  else {
230
    $('#submit-btn').prop('disabled', false);
231
  }
232

  
226 233
  $('#type').empty().append(options);
227 234
  
228 235
}
website/src/Controller/HeatmapController.php
13 13
    /**
14 14
     * @Route("/heatmap", name="heatmap")
15 15
     */
16
    public function index(Request $request) {
16
    public function index(Request $request, IOpenDataManager $manager) {
17 17
        $dataSet = new DataSet();
18 18

  
19 19
        $form = $this->createForm(DataSetType::class, $dataSet);
20 20
        $form->handleRequest($request);
21 21

  
22
        // Todo validation
23
        // $form->isValid()
24 22
        if ($form->isSubmitted()) {
25 23
            $dataSet = $form->getData();
24
            $name = $manager->getXthAvailableCollectionByDay($dataSet->getType(), $dataSet->getDate());
25
            if (false == $manager->isCollectionAvailable($name, $dataSet->getDate())) {
26
                $form = $this->createForm(DataSetType::class, new DataSet());
27
            }
26 28
        }
27 29

  
28 30
        return $this->render(
website/src/Entity/DataSet.php
17 17
    }
18 18

  
19 19
    public function setDate($date) {
20
        $this->date = $date;
20
        $this->date = date('dmY', strtotime($date));
21 21
    }
22 22

  
23 23
    public function getDate() {
website/src/IOpenDataManager.php
8 8
    public function getAvailableCollections();
9 9

  
10 10
    public function getAvailableCollectionsByDay($date);
11
    
12
    public function getXthAvailableCollectionByDay($index, $date);
13

  
14
    public function isCollectionAvailable($name, $date);
15

  
16
    public function getMaxCollectionNumberAtDay($name, $date);
11 17
}
website/src/OpenDataManager.php
45 45
        $available = $this->getAvailableCollections();
46 46
        $index = 0;
47 47
        foreach ($available as $key => $value) {
48
            $command = new Command(['listCollections' => 1, 'filter' => ['name' => $value['name'].$date]]);
49
            $result = $this->manager->executeCommand('open-data-db', $command)->toArray();
50

  
51
            if (false == empty($result) && false == array_key_exists($value['name'], $availableInDate)) {
48
            if ($this->isCollectionAvailable($value['name'], $date) && false == array_key_exists($value['name'], $availableInDate)) {
52 49
                $availableInDate[$value['name']] = $index++;
53 50
            }
54 51
        }
......
56 53
        return $availableInDate;
57 54
    }
58 55

  
56
    public function getXthAvailableCollectionByDay($index, $date) {
57
        $availableInDate = [];
58
        $available = $this->getAvailableCollections();
59
        $currentIndex = 0;
60

  
61
        foreach ($available as $key => $value) {
62
            if ($this->isCollectionAvailable($value['name'], $date) && false == array_key_exists($value['name'], $availableInDate)) {
63
                if ($currentIndex == $index) {
64
                    return $value['name'];
65
                }
66
                else {
67
                    $currentIndex++;
68
                }
69
            }
70
        }
71

  
72
        return "";
73
    }
74

  
75
    public function isCollectionAvailable($name, $date) {
76

  
77
        $command = new Command(['listCollections' => 1, 'filter' => ['name' => $name.$date]]);
78
        $result = $this->manager->executeCommand('open-data-db', $command)->toArray();
79

  
80
        return !empty($result);
81
    }
82

  
59 83
    public function getMaxCollectionNumberAtDay($name, $date) {
60 84
        $max = $this->manager->executeQuery('open-data-db.'.$name.$date, new Query([], ['sort' => ['number' => -1], 'limit' => 1]));
61 85

  
website/templates/heatmap.html.twig
33 33
                  'type' : 'date',
34 34
                  'id' : 'date',
35 35
                  'attr' : {
36
                    'max' : 'now'|date('d-m-Y'),
36
                    'max' : 'now'|date('Y-m-d'),
37 37
                    'class' : 'form-control',                 
38 38
                    'onChange' : 'checkDataSetsAvailability("' ~ path('available') ~ '")'
39 39
                  }
......
71 71
                {
72 72
                  'label' : 'Potvrdit výběr',
73 73
                  'type' : 'submit',
74
                  'id' : 'submit-btn',
74 75
                  'attr' : {
75 76
                    'class': 'btn btn-secondary'
76 77
                  }

Také k dispozici: Unified diff