Permalink
Browse files

pagination

  • Loading branch information...
1 parent 0343081 commit 1bc2826806d0cf809f949d57c69991caf476193c @mszczytowski mszczytowski committed Jan 18, 2009
@@ -6,13 +6,13 @@ class ChartsBurndownController < ChartsController
def get_data(conditions, grouping, range)
- first_date = Date.current
- f = Issue.minimum(:start_date, :conditions => { :project_id => conditions[:project_id]})
- first_date = f if f and f < first_date
- f = Issue.minimum(:created_on, :conditions => { :project_id => conditions[:project_id]})
- first_date = f if f and f < first_date
-
- range = RedmineCharts::RangeUtils.count_range({:in => :days, :offset => 1}, first_date.to_time)
+# first_date = Date.current
+# f = Issue.minimum(:start_date, :conditions => { :project_id => conditions[:project_id]})
+# first_date = f if f and f < first_date
+# f = Issue.minimum(:created_on, :conditions => { :project_id => conditions[:project_id]})
+# first_date = f if f and f < first_date
+#
+# range = RedmineCharts::RangeUtils.count_range({:in => :days, :offset => 1}, first_date.to_time)
from, to, x_labels, x_count, range, dates = RedmineCharts::RangeUtils.prepare_range(range, "start_date")
@@ -96,7 +96,7 @@ def show_y_axis
end
def show_date_condition
- false
+ true
end
def get_grouping_options
@@ -10,21 +10,29 @@ class ChartsController < ApplicationController
# Show main page with conditions form and chart
def index
- if show_date_condition or not get_grouping_options.empty? or not get_conditions_options.empty?
- @grouping_options = get_grouping_options.collect { |i| [l("charts_group_by_#{i}".to_sym), i] }
- @conditions_options = get_conditions_options.collect do |i|
- case i
- when :user_id then [:user_id, Project.find(params[:project_id]).assignable_users.collect { |u| [u.login, u.id] }.unshift([l(:charts_condition_all), 0])]
- when :issue_id then [:issue_id, nil]
- when :activity_id then [:activity_id, Enumeration.get_values("ACTI").collect { |a| [a.name.downcase, a.id] }.unshift([l(:charts_condition_all), 0])]
- when "issues.category_id".to_sym then ["issues.category_id".to_sym, IssueCategory.find_all_by_project_id(Project.find(params[:project_id]).id).collect { |c| [c.name.downcase, c.id] }.unshift([l(:charts_condition_all), 0])]
- end
- end
- @date_condition = show_date_condition
+ @show_conditions = false
+
+ if show_date_condition
+ @date_condition = true
+ @show_conditions = true
+ else
+ @date_condition = false
+ end
+
+ unless get_grouping_options.empty?
+ @grouping_options = RedmineCharts::GroupingUtils.to_options(get_grouping_options)
+ @show_conditions = true
+ else
+ @grouping_options = []
+ end
+
+ unless get_conditions_options.empty?
+ @conditions_options = RedmineCharts::ConditionsUtils.to_options(get_conditions_options, params[:project_id])
@show_conditions = true
else
- @show_conditions = false
+ @conditions_options = []
end
+
@help = get_help
@title = get_title
@@ -39,38 +47,38 @@ def data
grouping = RedmineCharts::GroupingUtils.from_params(params)
conditions = RedmineCharts::ConditionsUtils.from_params(params, get_conditions_options)
- x_labels, x_count, y_max, sets = get_data(conditions, grouping, range)
+ labels, count, max, sets = get_data(conditions, grouping, range)
index = 0
converter = get_converter
sets.each do |name,values|
- chart.add_element(converter.convert(index,name,values,x_labels))
+ chart.add_element(converter.convert(index,name,values,labels))
index += 1
end
if show_y_axis
y = YAxis.new
- y.set_range(0,y_max*1.2,y_max/5) if y_max
+ y.set_range(0,max*1.2,max/5) if max
chart.y_axis = y
end
if show_x_axis
x = XAxis.new
- x.set_range(0,x_count,1) if x_count
- if x_labels
- labels = []
- step = (x_labels.size/5).to_i
+ x.set_range(0,count,1) if count
+ if labels
+ labels2 = []
+ step = (labels.size/5).to_i
step = 1 if step == 0
- x_labels.each_with_index do |l,i|
+ labels.each_with_index do |l,i|
if i % step == 0
- labels << l
+ labels2 << l
else
- labels << ""
+ labels2 << ""
end
end
- x.set_labels(labels)
+ x.set_labels(labels2)
end
chart.x_axis = x
else
@@ -80,23 +88,24 @@ def data
end
unless get_x_legend.nil?
- x_legend = XLegend.new(get_x_legend)
- x_legend.set_style('{font-size: 12px}')
- chart.set_x_legend(x_legend)
+ legend = XLegend.new(get_x_legend)
+ legend.set_style('{font-size: 12px}')
+ chart.set_x_legend(legend)
end
unless get_x_legend.nil?
- y_legend = YLegend.new(get_y_legend)
- y_legend.set_style('{font-size: 12px}')
- chart.set_y_legend(y_legend)
+ legend = YLegend.new(get_y_legend)
+ legend.set_style('{font-size: 12px}')
+ chart.set_y_legend(legend)
end
chart.set_bg_colour('#ffffff');
render :text => chart.to_s
end
- def get_sets(rows, grouping, x_count, flat = false)
+ # TODO Move it outside this class
+ def get_sets(rows, grouping, count, flat = false)
if rows.empty?
[nil, {}]
end
@@ -111,7 +120,7 @@ def get_sets(rows, grouping, x_count, flat = false)
else
group_name = RedmineCharts::GroupingUtils.to_string(r.group_id, grouping)
end
- sets[group_name] ||= Array.new(x_count, [0, get_hints])
+ sets[group_name] ||= Array.new(count, [0, get_hints])
if r.value_x
i = r.value_x.to_i
@@ -190,17 +199,19 @@ def get_conditions_options
private
+ # Returns converter for given chart type
def get_converter
eval("RedmineCharts::#{get_type.to_s.camelize}DataConverter")
end
- # Find current project or raise 404
+ # Finds current project or raises 404
def find_project
@project = Project.find(params[:project_id])
rescue ActiveRecord::RecordNotFound
render_404
end
+ # Checks and sets default params values
def check_params
RedmineCharts::RangeUtils.set_params(params)
end
@@ -19,11 +19,23 @@ def show_graph
controller.open_flash_chart_object("100%", "400", url_for(controller.params).gsub("&amp;", "&"))
end
- def show_date_condition(range_steps, range_in)
+ def show_date_condition(range_steps, range_in, range_offset)
res = l(:charts_show_last) << " "
res << text_field_tag(:range_steps, range_steps, :size => 4)
+ res << hidden_field_tag(:range_offset, range_offset)
res << " "
res << select_tag(:range_in, options_for_select(RedmineCharts::RangeUtils.in_options, range_in))
+
+ res << "<br/><br/>"
+
+ res << link_to_function(l(:charts_earlier), :onclick => 'charts_earlier();')
+ res << " - "
+ if range_offset.to_i == 1
+ res << l(:charts_later)
+ else
+ res << link_to_function(l(:charts_later), :onclick => 'charts_later();')
+ end
+
res
end
@@ -2,6 +2,7 @@
<% content_for :header_tags do %>
<%= javascript_include_tag '/plugin_assets/open_flash_chart/javascripts/swfobject.js' %>
+ <%= javascript_include_tag '/plugin_assets/redmine_charts/javascripts/charts.js' %>
<% end %>
<h2><%=l(:charts_menu_label)%>
@@ -15,11 +16,13 @@
<% if @show_conditions %>
<div class="splitcontentleft" style="width:30%">
<% form_tag '#', :method => :get do %>
- <div class="box">
+ <div class="box" style="text-align:center">
<% if @date_condition %>
- <p><%= show_date_condition(params[:range_steps], params[:range_in]) %></p>
+ <p><%= show_date_condition(params[:range_steps], params[:range_in], params[:range_offset]) %></p>
<% end %>
- <% unless @grouping_options.empty? %>
+ </div>
+ <div class="box">
+ <% unless @grouping_options.empty? %>
<p><%= l(:charts_group_by) %> <%= select_tag :grouping, options_for_select(@grouping_options, params[:grouping] ? params[:grouping].to_sym : nil) %></p>
<% end %>
<% @conditions_options.each do |condition| %>
@@ -0,0 +1,12 @@
+function charts_earlier() {
+ $('range_offset').value = parseInt($('range_offset').value) + 1;
+ $('range_offset').form.submit();
+}
+
+function charts_later() {
+ $('range_offset').value = parseInt($('range_offset').value) - 1;
+ if($('range_offset').value < 1) {
+ $('range_offset').value = 1;
+ }
+ $('range_offset').form.submit();
+}
View
@@ -3,7 +3,7 @@ charts_link_groups: Logged hours ratio
charts_link_hours: Logged hours timeline
charts_link_burndown: Burndown
charts_link_deviation: Logged hours deviations
-charts_show_last: Show last
+charts_show_last: Show
charts_show_last_days: days
charts_show_last_weeks: weeks
charts_show_last_months: months
@@ -55,4 +55,7 @@ charts_deviation_hint_issue: <br>%d hours estimated, %d%% work done
charts_deviation_hint_label: "issue #%d, %s"
charts_deviation_group_logged: logged hours
charts_deviation_group_remaining: remaining hours
-charts_deviation_help: "Chart shows, for every issue, logged and remaining hours in the ratio of estimated hours. This ratio should be lower or equal to 100%%."
+charts_deviation_help: "Chart shows, for every issue, logged and remaining hours in the ratio of estimated hours. This ratio should be lower or equal to 100%%."
+
+charts_earlier: "&laquo; Earlier"
+charts_later: "Later &raquo;"
View
@@ -55,4 +55,7 @@ charts_deviation_hint_issue: <br>oszacowano na %d godzin, wykonano %d%% prac
charts_deviation_hint_label: "zagadnienie #%d, %s"
charts_deviation_group_logged: zaraportowane godziny
charts_deviation_group_remaining: pozostałe godziny
-charts_deviation_help: "Wykres przedstawia, dla każdego zagadnienia, stosunek godzin zaraportowanych oraz pozostałych do oszacowanych. Suma godzin zaraportowanych i pozostałych nie powinna przekraczać 100%%."
+charts_deviation_help: "Wykres przedstawia, dla każdego zagadnienia, stosunek godzin zaraportowanych oraz pozostałych do oszacowanych. Suma godzin zaraportowanych i pozostałych nie powinna przekraczać 100%%."
+
+charts_earlier: "&laquo; Wcześniej"
+charts_later: "Później &raquo;"
@@ -1,6 +1,8 @@
module RedmineCharts
module ConditionsUtils
+ include GLoc
+
@@default_types = [ :user_id, :issue_id, :activity_id, "issues.category_id".to_sym ]
def self.default_types
@@ -16,5 +18,16 @@ def self.from_params(params, options)
conditions
end
+ def self.to_options(options, project_id)
+ options.collect do |i|
+ case i
+ when :user_id then [:user_id, Project.find(project_id).assignable_users.collect { |u| [u.login, u.id] }.unshift([l(:charts_condition_all), 0])]
+ when :issue_id then [:issue_id, nil]
+ when :activity_id then [:activity_id, Enumeration.get_values("ACTI").collect { |a| [a.name.downcase, a.id] }.unshift([l(:charts_condition_all), 0])]
+ when "issues.category_id".to_sym then ["issues.category_id".to_sym, IssueCategory.find_all_by_project_id(Project.find(project_id).id).collect { |c| [c.name.downcase, c.id] }.unshift([l(:charts_condition_all), 0])]
+ end
+ end
+ end
+
end
end
@@ -1,6 +1,8 @@
module RedmineCharts
module GroupingUtils
+ include GLoc
+
@@types = [ :users, :issues, :activities, :categories ]
def self.default_types
@@ -14,6 +16,10 @@ def self.from_params(params)
params[:grouping].to_sym
end
end
+
+ def self.to_options(options)
+ options.collect { |i| [l("charts_group_by_#{i}".to_sym), i] }
+ end
def self.to_string(id, grouping)
if grouping == :categories and category = IssueCategory.find_by_id(id.to_i)

0 comments on commit 1bc2826

Please sign in to comment.