Skip to content

Commit

Permalink
First iteration of project grouping, related to bug #4
Browse files Browse the repository at this point in the history
  • Loading branch information
clueware committed Apr 22, 2012
1 parent cc233cf commit 4eafd42
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 112 deletions.
95 changes: 39 additions & 56 deletions app/controllers/my_roadmaps_controller.rb
Expand Up @@ -23,17 +23,12 @@ class MyRoadmapsController < ApplicationController

helper :queries
include QueriesHelper

def index

get_query

if @user_synthesis.nil?
@user_synthesis = Hash.new
else
@user_synthesis.clear
end


@user_synthesis = Hash.new

if @query.has_filter?('tracker_id')
tracker_list = Tracker.find(:all, :conditions => [@query.statement_for('tracker_id').sub('issues.tracker_id','trackers.id')], :order => 'position')
else
Expand All @@ -45,49 +40,46 @@ def index
version_condition += ' and ('+@query.statement_for('project_id').gsub('issues','versions')+' or exists (select 1 from issues where issues.fixed_version_id = versions.id and '+@query.statement_for('project_id')+'))' if @query.has_filter?('project_id')

Version.find(:all, :conditions => [version_condition] ) \
.select{|version| !version.completed? } \
.each{|version|
affected_project_ids = [version.project.id]
case
when version.sharing == 'none'
# do nothing: the version is not shared
when version.sharing == 'descendants'
version.project.descendants.visible.each{|p|
affected_project_ids.push(p.id)
}
when (version.sharing == 'hierarchy') || (version.sharing == 'tree')
version.project.hierarchy.visible.each{|p|
affected_project_ids.push(p.id)
}
when version.sharing == 'system'
Project.visible.each{|p|
affected_project_ids.push(p.id)
}
.select{|version| !version.completed? } \
.each{|version|
issue_condition = @query.statement_for('project_id')+' and '+ \
'tracker_id in (?) and '+ \
'( fixed_version_id = ? '+ \
'or exists (select 1 '+ \
'from issues as subissues '+ \
'where issues.root_id = subissues.root_id '+ \
'and subissues.fixed_version_id = ?) )'

if User.current.admin?
issue_condition = [issue_condition,
tracker_list, version.id, version.id]
else
issue_condition = [issue_condition + \
'and (assigned_to_id is null or assigned_to_id = ?)',
tracker_list, version.id, version.id, User.current.id ]
end

grouped_issues = Hash.new
Issue.visible.find(:all, :conditions => issue_condition, :include => [:status,:tracker], :order => 'project_id,tracker_id' ) \
.each {|issue|
if grouped_issues[issue.project].nil?
grouped_issues[issue.project]=[issue]
else
grouped_issues[issue.project].push(issue)
end
}

grouped_issues.each{|project, issues|
if @user_synthesis[project].nil?
@user_synthesis[project] = Hash.new
end
# list affected projects
issue_condition = @query.statement_for('project_id')+' and '+ \
'tracker_id in (?) and '+ \
'( fixed_version_id = ? '+ \
'or exists (select 1 '+ \
'from issues as subissues '+ \
'where issues.root_id = subissues.root_id '+ \
'and subissues.fixed_version_id = ?) )'
if User.current.admin?
issue_condition = [issue_condition,
tracker_list, version.id, version.id]
if @user_synthesis[project][version].nil?
@user_synthesis[project][version] = VersionSynthesis.new(project, version, issues)
else
issue_condition = [issue_condition + \
'and (assigned_to_id is null or assigned_to_id = ?)',
tracker_list, version.id, version.id, User.current.id ]
@user_synthesis[project][version].add_issues(issues)
end

issues = Issue.visible.find(:all, :conditions => issue_condition ) \
.select{|iss|
(( iss.fixed_version_id == version.id && iss.root_id == iss.id) || Issue.find(:all, :conditions => ['root_id = ? and fixed_version_id = ?', iss.root_id, version.id]).length>0)
}
@user_synthesis[version] = VersionSynthesis.new(version, issues) if issues.length > 0
}
}
@user_synthesis = @user_synthesis.sort{|a,b| [a[0].project.name.upcase, splitVersionName(a[0].name)]<=>[b[0].project.name.upcase, splitVersionName(b[0].name)]}
end

def initialize
Expand Down Expand Up @@ -125,13 +117,4 @@ def get_query
end
@query.filters={ 'project_id' => {:operator => "*", :values => [""]} } if @query.filters.length==0
end

# splits a version name into its constituents, returning an array.
# Numeric values are converted to a string on 10 positions to ease comparison
# with non-numeric strings
def splitVersionName(versionName)
return versionName.split(/[^a-zA-Z0-9]/).compact.map{ |elem|
(elem.to_i.to_s!=elem)?(elem.to_s):('%010d' % elem.to_i)
}
end
end
14 changes: 14 additions & 0 deletions app/helpers/my_roadmaps_helper.rb
Expand Up @@ -19,6 +19,19 @@

module MyRoadmapsHelper

module VersionPatch
def self.included(base)
base.send(:include, InstanceMethods)
end
module InstanceMethods
def splitted_version_name
return self.name.split(/[^a-zA-Z0-9]/).compact.map{ |elem|
(elem.to_i.to_s!=elem)?(elem.to_s):('%010d' % elem.to_i)
}
end
end
end

module QueryPatch
def self.included(base)
base.send(:include, InstanceMethods)
Expand Down Expand Up @@ -72,4 +85,5 @@ def statement_for(field_name)
end

Query.send(:include, QueryPatch)
Version.send(:include, VersionPatch)
end
105 changes: 54 additions & 51 deletions app/views/my_roadmaps/index.html.erb
Expand Up @@ -20,58 +20,61 @@
<h2><%= l(:my_roadmaps_name) %></h2>
<div id="roadmaps">
<%
prevProjectId=nil
@user_synthesis.each { |version,synthesis|
if prevProjectId.nil? || prevProjectId!=version.project.id
prevProjectId=version.project.id
@user_synthesis.keys.sort_by{|project| project.self_and_ancestors.join('/') }.each{ |project|
%>
<h2 class="project">
<%= link_to_if(version.project.visible?(User.current),version.project.name, {:controller => 'projects', :action => 'show', :id => version.project.id}) %>
</h2>
<%
end
%>
<h3 class="version">
<%= link_to_if(version.project.visible?(User.current),version.project.name, {:controller => 'projects', :action => 'show', :id => version.project.id}) %> -
<%= link_to_if(version.visible?(User.current),version.name, {:controller => 'versions', :action => 'show', :id => version.id}) %>
<span style="font-size:0.7em;">
<%= "("+l(:version_status_locked)+")" if version.status == 'locked' %>
<%= link_to l(:button_edit), {:controller => 'versions', :action => 'edit', :id => version.id} if version.visible?(User.current) %>
</span>
</h3>

<%= render :partial => 'trackers_progress', :locals => {:synthesis => synthesis} %>
<% if !synthesis.pct_done.nil? %>
<table class="list tracker" style="width: 70%; font-size: 90%;">
<caption>
<%= l(:label_related_issues) %>
<%= l(:label_x_closed_issue_not_shown, :count => synthesis.closed_nb) unless synthesis.closed_nb==0 %>
</caption>
<tr style="height: 5px; padding: 0px; margin:0px;">
<td style="width: 5px;"/>
<%
synthesis.pct_done.each_index{|i|
if i>0
%>
<td style="width: <%=synthesis.pct_done[i]-synthesis.pct_done[i-1]%>%;"/>
<%
end
}
<h2 class="project">
<%= link_to_if(project.visible?(User.current),project.name, {:controller => 'projects', :action => 'show', :id => project.id}) %>
</h2>
<%
@user_synthesis[project].keys.sort{|v1,v2| v1.splitted_version_name<=>v2.splitted_version_name}.each{ |version|
synthesis = @user_synthesis[project][version]
%>
<h3 class="version">
<%= link_to_if(project.visible?(User.current),project.name, {:controller => 'projects', :action => 'show', :id => project.id}) %> -
<%= link_to_if(version.visible?(User.current),version.name, {:controller => 'versions', :action => 'show', :id => version.id}) %>
<span style="font-size:0.7em;">
<%= "("+l(:version_status_locked)+")" if version.status == 'locked' %>
<%= link_to l(:button_edit), {:controller => 'versions', :action => 'edit', :id => version.id} if version.visible?(User.current) %>
</span>
</h3>

<%= render :partial => 'trackers_progress', :locals => {:synthesis => synthesis} %>
<% if !synthesis.pct_done.nil? %>
<table class="list tracker" style="width: 70%; font-size: 90%;">
<caption>
<%= l(:label_related_issues) %>
<%= l(:label_x_closed_issue_not_shown, :count => synthesis.closed_nb) unless synthesis.closed_nb==0 %>
</caption>
<tr style="height: 5px; padding: 0px; margin:0px;">
<td style="width: 5px;"/>
<%
synthesis.pct_done.each_index{|i|
if i>0
%>
<td style="width: <%=synthesis.pct_done[i]-synthesis.pct_done[i-1]%>%;"/>
<%
end
}
%>
<td style="width: 5px;"/>
</tr>
<%
synthesis.issues.sort_by{ |a| [a.wrapped_issue.root_id, \
((a.wrapped_issue.leaf?)?(a.wrapped_issue.parent_id):(a.wrapped_issue.id)),
a.depth,
a.wrapped_issue.tracker.position,
a.wrapped_issue.id]}.each { |issue_wrapper|
%>
<%= render :partial => 'related_issue', :locals => {:synthesis => synthesis, :issue_wrapper => issue_wrapper } %>
<%
}
%>
<td style="width: 5px;"/>
</tr>
<%
synthesis.issues.each { |issue_wrapper|
%>
<%= render :partial => 'related_issue', :locals => {:synthesis => synthesis, :issue_wrapper => issue_wrapper } %>
<%
}
%>
<tr style="height: 5px; padding: 0px; margin:0px;"><td colspan="12"/></tr>
</table>
<% end %>
<p>
<% } %>
<tr style="height: 5px; padding: 0px; margin:0px;"><td colspan="12"/></tr>
</table>
<% end %>
<p>
<% } # version %>
<% } # project %>
<h3><%= l(:my_roadmaps_no_version_match) if @user_synthesis.empty? %></h3>
</div>
12 changes: 7 additions & 5 deletions lib/version_synthesis.rb
Expand Up @@ -16,14 +16,18 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

class VersionSynthesis
def initialize(version, issues)
def initialize(project, version, issues)
@version = version
@project = version.project
@project = project
@issues = Array.new

@trackers = Array.new

@max_depth=0
self.add_issues(issues)
end

def add_issues(issues)
issues.each{ |issue|
if @trackers.select{|wrapper| wrapper.wrapped_tracker == issue.tracker }.length!=1
current_tracker = TrackerWrapper.new(version,issue.tracker)
Expand All @@ -39,7 +43,6 @@ def initialize(version, issues)
end
}

@issues = @issues.sort_by{ |a| [a.wrapped_issue.root_id, ((a.wrapped_issue.leaf?)?(a.wrapped_issue.parent_id):(a.wrapped_issue.id)), a.depth, a.wrapped_issue.tracker.position, a.wrapped_issue.id]}
@trackers.sort{|a,b| a.wrapped_tracker.position<=>b.wrapped_tracker.position}

@done_pct = 0
Expand All @@ -64,7 +67,6 @@ def initialize(version, issues)
@opened_pct = @opened_nb*100/@total_nb
end


# issues progress % set
if !@issues.nil? && @issues.length > 0
@pct_done = @issues.map{|issue_wrapper| (issue_wrapper.wrapped_issue.closed?)?100:issue_wrapper.wrapped_issue.done_ratio}
Expand All @@ -77,6 +79,6 @@ def initialize(version, issues)
@pct_done = nil
end
end

attr_reader :version, :project, :max_depth, :issues, :trackers, :pct_done, :done_nb, :done_pct, :closed_nb, :closed_pct, :opened_nb, :opened_pct
end

0 comments on commit 4eafd42

Please sign in to comment.