Permalink
Browse files

add date support

  • Loading branch information...
1 parent b8bc452 commit abc289a705c24e96fb1c36ff9cd69a3b2cc3d90b @alx committed Jul 19, 2011
View
20 json_server/application.rb
@@ -24,12 +24,24 @@
get '/heatmap' do
content_type :json
+
$SEATS.each{|seat| seat[:count] = 0}
- month = 201104
- 3.times do
- parse_synthese "#{month}", params[:info]
- month += 1
+
+ start_date = Date.parse params[:start_date]
+ end_date = Date.parse params[:end_date]
+
+ start_date = Date.today if start_date > Date.today
+ end_date = Date.today if end_date > Date.today
+
+ start_date = Date.new(2007, 06) if start_date < Date.new(2007, 6)
+ end_date = Date.new(2007, 06) if end_date < Date.new(2007, 6)
+
+ current_date = start_date
+ while current_date <= end_date
+ parse_synthese current_date.strftime("%Y%m").to_i, params[:info]
+ current_date = current_date >> 1
end
+
max = 0
$SEATS.each do |seat|
if seat[:count] && seat[:count] > 0
View
4 json_server/public/css/monthpicker.css
@@ -1,5 +1,5 @@
/* basic style */
-.MonthPicker {margin:0; padding:0; font:bold 11px Arial; color:#ffe; background-image:url(../img/bg.png)}
+.MonthPicker {margin:0; padding:0; font:bold 12px Arial; color:#ffe; background-image:url(../img/bg.png)}
.MonthPicker {-moz-user-select:none; user-select:none}
.MonthPicker th{}
.MonthPicker td{padding:0px}
@@ -15,7 +15,7 @@
.MonthPicker li a{display:block}
.MonthPicker .li:hover ul{background:#ffe; visibility:visible}
.MonthPicker .li:hover li a:hover{background:#09f; color:#ffe}
-.MonthPicker span{display:inline-block; width:58px; padding:0px; line-height:20px; text-align:center; cursor:pointer}
+.MonthPicker span{display:inline-block; width:58px; padding:1px; line-height:22px; text-align:center; cursor:pointer}
.MonthPicker .month span{width:37px}
.MonthPicker .selected{background:#ffe}
/* print style */
View
45 json_server/public/js/script.js
@@ -56,26 +56,24 @@ function seatCanvas(data){
function refreshHeatmap(){
+ $("#heatmap_loading").remove();
+
var filters = {};
filters["info"] = $("input:checked").val();
- var start_year = $("#start_date td :first span.selected").html();
+ var start_year = $("#start_date td:last span.selected").html();
var start_month = $("#start_date td.month span.selected").parent().attr("title");
filters["start_date"] = Date.parse(start_year + "-" + start_month);
- var end_year = $("#end_date td :first span.selected").html();
+ var end_year = $("#end_date td:last span.selected").html();
var end_month = $("#end_date td.month span.selected").parent().attr("title");
filters["end_date"] = Date.parse(end_year + "-" + end_month);
if(filters["start_date"].compareTo(filters["end_date"]) == 1){
$("#heatmapArea").prepend("<span id='heatmap_loading'>erreur sur les dates sélectionnées: la fin est avant le début...</span>");
} else {
- if(filters["start_date"].equals(filters["end_date"])){
- filters["end_date"].addMonths(1);
- }
-
filters["start_date"] = filters["start_date"].toString('yyyy/MM');
filters["end_date"] = filters["end_date"].toString('yyyy/MM');
@@ -94,8 +92,39 @@ $(document).ready(function(){
$("#radio_info").buttonset();
- $("#start_date").monthpicker("2011-03", refreshHeatmap);
- $("#end_date").monthpicker("2011-06", refreshHeatmap);
+ $("#start_date").monthpicker({
+ elements: [
+ {tpl:"month",opt:{
+ caption: 'Début',
+ text: ['Jan', 'Fev', 'Mar', 'Avr', 'Mai', 'Jui', 'Jul', 'Aou', 'Sep', 'Oct', 'Nov', 'Dec'],
+ value: 3
+ }},
+ {tpl:"year",opt:{
+ caption: '',
+ range: "-4~0",
+ value: 2011
+ }}
+ ],
+ onChanged: refreshHeatmap
+ });
+
+
+ $("#end_date").monthpicker({
+ elements: [
+ {tpl:"month",opt:{
+ caption: 'Fin&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
+ text: ['Jan', 'Fev', 'Mar', 'Avr', 'Mai', 'Jui', 'Jul', 'Aou', 'Sep', 'Oct', 'Nov', 'Dec'],
+ value: 6
+ }},
+ {tpl:"year",opt:{
+ caption: '',
+ range: "-4~0",
+ value: 2011
+ }}
+ ],
+ onChanged: refreshHeatmap
+ });
+
$("input[type=radio]").click(refreshHeatmap);
refreshHeatmap();
View
6 json_server/views/layout.erb
@@ -40,7 +40,11 @@
<div class="span-17 prepend-1">
<h1>Politimap</h1>
</div>
- <div class="span-6 last">
+ <div class="span-3">
+ <a href="http://github.com/alx/politimap">code</a><br>
+ <a href="http://cpc.regardscitoyens.org/trac/wiki/API">api</a>
+ </div>
+ <div class="span-3 last">
<a href="http://www.patrick-wied.at/static/heatmapjs/">heatmap.js</a><br>
<a href="http://www.kineticjs.com">kinetic.js</a><br>
<a href="http://tetalab.org">tetalab</a>

0 comments on commit abc289a

Please sign in to comment.