#3605: cleanup frontend code

* created burndown charts helper
pull/6827/head
Jens Ulferts 14 years ago
parent 784f2537b5
commit eff95d8a35
  1. 2
      app/controllers/rb_burndown_charts_controller.rb
  2. 26
      app/helpers/burndown_charts_helper.rb
  3. 25
      app/helpers/rb_common_helper.rb
  4. 8
      app/views/rb_burndown_charts/_burndown.html.erb

@ -1,6 +1,8 @@
class RbBurndownChartsController < RbApplicationController
unloadable
helper :burndown_charts
def show
@burndown = @sprint.burndown(@project)

@ -0,0 +1,26 @@
module BurndownChartsHelper
def yaxis_labels(burndown)
max = [burndown.max[:hours], burndown.max[:points]].max
labels = []
mvalue = (max / 25) + 1
(0..mvalue).each do |i|
labels << "[#{i*25}, #{i*25}]"
end
labels << "[#{(mvalue) * 25}, '<span class=\"axislabel\">#{l('backlogs.hours')}/<br>#{l('backlogs.points')}</span>']"
labels.join(', ')
end
def xaxis_labels(burndown)
burndown.days.enum_for(:each_with_index).collect{|d,i| "[#{i+1}, '#{escape_javascript(::I18n.t('date.abbr_day_names')[d.wday % 7])}']"}.join(',') +
", [#{burndown.days.length + 1}, '<span class=\"axislabel\">#{I18n.t('backlogs.date')}</span>']"
end
def dataseries(burndown)
burndown.series.collect{|s| "#{s.first.to_s}: {label: '#{l('backlogs.' + s.first.to_s)}', data: [#{s.last.enum_for(:each_with_index).collect{|s, i| "[#{i+1}, #{s}] "}.join(', ')}]} "}
end
end

@ -116,29 +116,4 @@ module RbCommonHelper
args.push(:plugin => 'redmine_backlogs')
javascript_include_tag *args
end
def burndown_yaxis_labels(burndown)
max = [burndown.max[:hours], burndown.max[:points]].max
labels = []
mvalue = (max / 25) + 1
(0..mvalue).each do |i|
labels << "[#{i*25}, #{i*25}]"
end
labels << "[#{(mvalue) * 25}, '<span class=\"axislabel\">#{l('backlogs.hours')}/<br>#{l('backlogs.points')}</span>']"
labels.join(', ')
end
def burndown_xaxis_labels(burndown)
burndown.days.enum_for(:each_with_index).collect{|d,i| "[#{i+1}, '#{escape_javascript(::I18n.t('date.abbr_day_names')[d.wday % 7])}']"}.join(',') +
", [#{burndown.days.length + 1}, '<span class=\"axislabel\">#{I18n.t('backlogs.date')}</span>']"
end
def burndown_dataseries(burndown)
burndown.series.collect{|s| "#{s.first.to_s}: {label: '#{l('backlogs.' + s.first.to_s)}', data: [#{s.last.enum_for(:each_with_index).collect{|s, i| "[#{i+1}, #{s}] "}.join(', ')}]} "}
end
end

@ -8,7 +8,7 @@
<script type="text/javascript" language="javascript">
jQuery(function ($) {
var Burndown = {
datasets: { <%= burndown_dataseries(burndown).join(', ') %> },
datasets: { <%= dataseries(burndown).join(', ') %> },
setDatasetColor: function () {
var i = 0;
@ -41,9 +41,9 @@
if (data.length > 0) {
$.plot($(".burndown_chart"), data, {
yaxis: { min: 0,
ticks: [ <%= burndown_yaxis_labels(burndown) %> ] },
ticks: [ <%= yaxis_labels(burndown) %> ] },
xaxis: {
ticks: [<%= burndown_xaxis_labels(burndown) %>],
ticks: [<%= xaxis_labels(burndown) %>],
tickDecimals: 0,
max: <%= burndown.days.length + 1 %>,
min: 1
@ -61,6 +61,6 @@
}
};
$(document).ready(Burndown.init);
Burndown.init();
});
</script>
Loading…
Cancel
Save