From dd55b1faee05cc76cf259b36dbf3a7805ed5148a Mon Sep 17 00:00:00 2001 From: Maximilian Grundke Date: Tue, 24 Apr 2018 16:58:31 +0200 Subject: [PATCH] Use sane default values --- app/assets/javascripts/rfc_activity_history.js | 7 +++---- app/controllers/statistics_controller.rb | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/rfc_activity_history.js b/app/assets/javascripts/rfc_activity_history.js index e3b6e7b5..d672c567 100644 --- a/app/assets/javascripts/rfc_activity_history.js +++ b/app/assets/javascripts/rfc_activity_history.js @@ -8,8 +8,6 @@ $(document).ready(function () { var graph; var groups; - var params = new URLSearchParams(window.location.search.slice(1)); - var buildChartGroups = function() { return _.map(chartData, function(element) { return { @@ -39,12 +37,13 @@ $(document).ready(function () { style: 'circle' }, legend: true, - start: params.get('from'), - end: params.get('to') + start: $('#from-date')[0].value, + end: $('#to-date')[0].value }); }; var refreshData = function(callback) { + var params = new URLSearchParams(window.location.search.slice(1)); var jqxhr = $.ajax('rfc-activity-history.json', { dataType: 'json', data: {from: params.get('from'), to: params.get('to'), interval: params.get('interval')}, diff --git a/app/controllers/statistics_controller.rb b/app/controllers/statistics_controller.rb index 8640a9cd..db014338 100644 --- a/app/controllers/statistics_controller.rb +++ b/app/controllers/statistics_controller.rb @@ -37,9 +37,9 @@ class StatisticsController < ApplicationController respond_to do |format| format.html { render 'rfc_activity_history' } format.json do - interval = params[:interval] || 'year' - from = DateTime.strptime(params[:from], '%Y-%M-%D') rescue DateTime.new(0) - to = DateTime.strptime(params[:to], '%Y-%M-%D') rescue DateTime.now + interval = params[:interval].to_s.nil? ? 'year' : params[:interval] + from = DateTime.strptime(params[:from], '%Y-%m-%d') rescue DateTime.new(0) + to = DateTime.strptime(params[:to], '%Y-%m-%d') rescue DateTime.now render(json: ranged_rfc_data(interval, from, to)) end end