Browse Source

filtra per data di creazione

boyska 3 years ago
parent
commit
509d3bd47a
3 changed files with 49 additions and 8 deletions
  1. 32 7
      rxmap/rxmapp/static/js/viewmap.js
  2. 10 0
      rxmap/rxmapp/templates/index.html
  3. 7 1
      rxmap/rxmapp/views.py

+ 32 - 7
rxmap/rxmapp/static/js/viewmap.js

@@ -41,16 +41,41 @@ function viewMap () {
     })
   }
 
-  $('body').on('click', '.btn-elimina', function onCancella (evt) {
-    var rid = $('#dialog').data('rid')
-    console.log('cancelliamo?', rid)
-    $.post('/api/rapporti/delete', { rid: rid }, function () {
-      map.removeLayer($('#dialog').data('marker'))
-      $('#dialog').dialog('close')
+    $('body').on('click', '.btn-elimina', function onCancella (evt) {
+        var rid = $('#dialog').data('rid')
+        console.log('cancelliamo?', rid)
+        $.post('/api/rapporti/delete', { rid: rid }, function () {
+            map.removeLayer($('#dialog').data('marker'))
+            $('#dialog').dialog('close')
+        })
     })
-  })
 }
 jQuery(function ($) {
+    var dateFormat = "yy-mm-dd";
+    function getDate( element ) {
+        var date;
+        try {
+            date = $.datepicker.parseDate( dateFormat, element.value )
+        } catch( error ) {
+            date = null
+        }
+
+        return date
+    }
   $('#mapid').css('height', $(window).height() - 200)
+    var from=$('input[name=created__gt]').datepicker({defaultDate: "-1month",
+        changeMonth: true, numberOfMonths: 1,
+        dateFormat: dateFormat
+    }
+    ).on("change", function() {
+        to.datepicker("option", "minDate", getDate(this));
+    })
+    var to = $('input[name=created__lt]').datepicker({
+        defaultDate: "+1d", changeMonth: true, numberOfMonths: 1,
+        dateFormat: dateFormat
+    }
+    ).on("change", function() {
+        from.datepicker("option", "maxDate", getDate(this))
+    })
   viewMap()
 })

+ 10 - 0
rxmap/rxmapp/templates/index.html

@@ -10,8 +10,12 @@
 {% endblock extra_scripts %}
 
 {% block content %}
+    <style>
+.ui-datepicker { z-index: 10 !important ;}
+    </style>
 <div id="dialog"></div>
 <div id="filters">
+    <!-- TODO: rendi collassabile -->
     <header><h3>Filtra</h3></header>
     <form method="GET">
 
@@ -23,6 +27,12 @@
                 <option value="{{tr.id}}"><strong>{{tr.nome}}</strong> - {{tr.descrizione|default:'' }}</option>
             {% endfor %}
         </select>
+        <div>
+            <label for="created__gt">Da</label>
+            <input type="text" name="created__gt" value="{{params.created__gt}}">
+            <label for="created__lt">A</label>
+            <input type="text" name="created__lt" value="{{params.created__lt}}">
+        </div>
         </div>
 
 

+ 7 - 1
rxmap/rxmapp/views.py

@@ -16,6 +16,12 @@ class ViewMap(TemplateView):
     def get_context_data(self, **kwargs):
         ctx = super().get_context_data(**kwargs)
         ctx["tipiradio"] = TipoRadio.objects.all()
+        f = RapportiFilter()
+        params = {}
+        for field in f.get_filters():
+            if field in self.request.GET:
+                params[field] = self.request.GET[field]
+        ctx["params"] = params
         return ctx
 
 
@@ -31,7 +37,7 @@ def add_page(request):
 class RapportiFilter(django_filters.FilterSet):
     class Meta:
         model = RapportoRicezione
-        fields = ["tipo_radio__id"]
+        fields = {"tipo_radio__id": ["exact"], "created": ["gt", "lt"]}
 
 
 def rapporti_get(request):