Skip to content
This repository has been archived by the owner on Oct 1, 2020. It is now read-only.

Filter workflow by roles used in project #14

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/views/workflow_enhancements/_workflow_graph.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
roles = Array(roles)
minimal = false if local_assigns[:minimal].nil?
issue ||= nil
project_roles = @project.users_by_role.map{ |x| x[0][:id] } unless @project.nil?
%>
<% if trackers.length == 1 %>
<%= javascript_include_tag "d3.v3.min.js", :plugin => :redmine_workflow_enhancements %>
Expand Down Expand Up @@ -31,7 +32,7 @@

<script type="text/javascript">
$(function() {
var json = <%= WorkflowEnhancements::Graph.load_data(roles, trackers, issue).to_json.html_safe %>;
var json = <%= WorkflowEnhancements::Graph.load_data(roles, trackers, issue, project_roles).to_json.html_safe %>;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't calculate project_roles in the view, just pass the @project object and do things in the Graph.


var renderer = new dagreD3.Renderer();
var oldDrawNodes = renderer.drawNodes();
Expand Down
7 changes: 5 additions & 2 deletions lib/workflow_enhancements/graph.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module WorkflowEnhancements::Graph

def self.load_data(roles, trackers, issue=nil)
def self.load_data(roles, trackers, issue=nil, project_roles=nil)
tracker = nil
if trackers.is_a?(Array)
tracker = trackers.length == 1 ? trackers.first : nil
Expand All @@ -24,6 +24,7 @@ def self.load_data(roles, trackers, issue=nil)
new_issue_status_map = {}
edges_map = {}
WorkflowTransition.where(:tracker_id => tracker).each do |t|
next unless project_roles.nil? || project_roles.include?(t.role_id)
if t.old_status_id != 0
key = t.old_status_id.to_s + '-' + t.new_status_id.to_s
own = role_map.include?(t.role_id)
Expand All @@ -45,6 +46,7 @@ def self.load_data(roles, trackers, issue=nil)
end
end
edges_array = []
statuses_list = []
edges_map.each_value do |e|
cls = role_map.empty? ? '' : 'transOther'
if e[:own]
Expand All @@ -55,9 +57,10 @@ def self.load_data(roles, trackers, issue=nil)
end
end
edges_array << { :u => e[:u], :v => e[:v], :value => { :edgeclass => cls } }
statuses_list |= [e[:u], e[:v]]
end

statuses_array = tracker.issue_statuses.map do |s|
statuses_array = tracker.issue_statuses.select{ |s| statuses_list.include?(s.id) }.map do |s|
cls = ''
if is_default_status(tracker, s)
cls = 'state-new'
Expand Down