From b2c84f3b9f287b5543549d47d1756c3b52445003 Mon Sep 17 00:00:00 2001 From: Brad Beattie Date: Fri, 24 Apr 2009 15:36:37 -0700 Subject: [PATCH] Adding a widget that shows issue assignment flow --- app/controllers/graphs_controller.rb | 20 +++++++ .../recent_assigned_to_changes_graph.html.erb | 56 +++++++++++++++++++ ..._recent_assigned_to_changes_graph.html.erb | 5 ++ 3 files changed, 81 insertions(+) create mode 100644 app/views/graphs/recent_assigned_to_changes_graph.html.erb create mode 100644 app/views/my/blocks/_recent_assigned_to_changes_graph.html.erb diff --git a/app/controllers/graphs_controller.rb b/app/controllers/graphs_controller.rb index e826a4a..d512ed3 100644 --- a/app/controllers/graphs_controller.rb +++ b/app/controllers/graphs_controller.rb @@ -9,6 +9,26 @@ class GraphsController < ApplicationController before_filter :find_optional_project, :only => [:issue_growth, :issue_growth_graph] helper IssuesHelper + + def recent_assigned_to_changes_graph + # Get the top visible projects by issue count + sql = " select u1.id as old_user, u2.id as new_user, count(*) as changes_count" + sql << " from journals as j" + sql << " left join journal_details as jd on j.id = jd.journal_id" + sql << " left join users as u1 on jd.old_value = u1.id" + sql << " left join users as u2 on jd.value = u2.id" + sql << " where journalized_type = 'issue' and prop_key = 'assigned_to_id' and DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 1 DAY) <= j.created_on" + sql << " and (u1.id = #{User.current.id} or u2.id = #{User.current.id})" + sql << " and u1.id <> 0 and u2.id <> 0" + sql << " group by old_value, value" + @assigned_to_changes = ActiveRecord::Base.connection.select_all(sql) + user_ids = @assigned_to_changes.collect { |change| [change["old_user"].to_i, change["new_user"].to_i] }.flatten.uniq + user_ids.delete(User.current.id) + @users = User.find(:all, :conditions => "id IN ("+user_ids.join(',')+")").index_by { |user| user.id } unless user_ids.empty? + + headers["Content-Type"] = "image/svg+xml" + render :layout => false + end def recent_status_changes_graph # Get the top visible projects by issue count diff --git a/app/views/graphs/recent_assigned_to_changes_graph.html.erb b/app/views/graphs/recent_assigned_to_changes_graph.html.erb new file mode 100644 index 0000000..4622179 --- /dev/null +++ b/app/views/graphs/recent_assigned_to_changes_graph.html.erb @@ -0,0 +1,56 @@ + + + +<% + points = Hash.new + points[User.current.id] = { "x" => 140, "y" => 140 } + i = -1 + @users.each do |user_id, user| + points[user_id] = { + "x" => Math.sin(2*Math::PI*i/@users.size)*100 + 140, + "y" => Math.cos(2*Math::PI*i/@users.size)*100 + 140 + } + i -= 1 + end unless @users.nil? +%> + + + + <% @assigned_to_changes.each do |assigned_to_change| %> + <% + changes_count = [assigned_to_change["changes_count"].to_i*3,35].min + old_user = assigned_to_change["old_user"].to_i + new_user = assigned_to_change["new_user"].to_i + + x1 = points[old_user]["x"] + y1 = points[old_user]["y"] + + x2 = points[new_user]["x"] + y2 = points[new_user]["y"] + + atan2 = -Math.atan2(y1-y2,x1-x2) + xdiff = Math.sin(atan2)*changes_count + ydiff = Math.cos(atan2)*changes_count + %> + " + stroke="<%= assigned_to_change["old_user"].to_i == User.current.id ? "green" : "red" %>" + /> + <% end %> + + + <% points.each do |user_id, point| %> + " cy="<%= point["y"] %>" r="35" /> + <% end %> + + + <% points.each do |user_id, point| %> + " y="<%= point["y"] + 3 %>"><%= user_id == User.current.id ? User.current : @users[user_id] %> + <% end %> + + diff --git a/app/views/my/blocks/_recent_assigned_to_changes_graph.html.erb b/app/views/my/blocks/_recent_assigned_to_changes_graph.html.erb new file mode 100644 index 0000000..a88f6cf --- /dev/null +++ b/app/views/my/blocks/_recent_assigned_to_changes_graph.html.erb @@ -0,0 +1,5 @@ +

<%= l(:label_graphs_issue_status_flow) %>

+ +
+<%= tag("embed", :width => "280", :height => 280, :type => "image/svg+xml", :src => url_for(:controller => 'graphs', :action => 'recent_assigned_to_changes_graph')) %> +