@@ -1,128 +1,128 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | class WorkflowsController < ApplicationController |
|
19 | 19 | layout 'admin' |
|
20 | 20 | |
|
21 | 21 | before_filter :require_admin, :find_roles, :find_trackers |
|
22 | 22 | |
|
23 | 23 | def index |
|
24 | 24 | @workflow_counts = WorkflowTransition.count_by_tracker_and_role |
|
25 | 25 | end |
|
26 | 26 | |
|
27 | 27 | def edit |
|
28 | 28 | @role = Role.find_by_id(params[:role_id]) if params[:role_id] |
|
29 | 29 | @tracker = Tracker.find_by_id(params[:tracker_id]) if params[:tracker_id] |
|
30 | 30 | |
|
31 | 31 | if request.post? |
|
32 | 32 | WorkflowTransition.destroy_all( ["role_id=? and tracker_id=?", @role.id, @tracker.id]) |
|
33 | 33 | (params[:issue_status] || []).each { |status_id, transitions| |
|
34 | 34 | transitions.each { |new_status_id, options| |
|
35 | 35 | author = options.is_a?(Array) && options.include?('author') && !options.include?('always') |
|
36 | 36 | assignee = options.is_a?(Array) && options.include?('assignee') && !options.include?('always') |
|
37 | 37 | WorkflowTransition.create(:role_id => @role.id, :tracker_id => @tracker.id, :old_status_id => status_id, :new_status_id => new_status_id, :author => author, :assignee => assignee) |
|
38 | 38 | } |
|
39 | 39 | } |
|
40 | 40 | if @role.save |
|
41 | redirect_to :action => 'edit', :role_id => @role, :tracker_id => @tracker | |
|
41 | redirect_to :action => 'edit', :role_id => @role, :tracker_id => @tracker, :used_statuses_only => params[:used_statuses_only] | |
|
42 | 42 | return |
|
43 | 43 | end |
|
44 | 44 | end |
|
45 | 45 | |
|
46 | 46 | @used_statuses_only = (params[:used_statuses_only] == '0' ? false : true) |
|
47 | 47 | if @tracker && @used_statuses_only && @tracker.issue_statuses.any? |
|
48 | 48 | @statuses = @tracker.issue_statuses |
|
49 | 49 | end |
|
50 | 50 | @statuses ||= IssueStatus.sorted.all |
|
51 | 51 | |
|
52 | 52 | if @tracker && @role && @statuses.any? |
|
53 | 53 | workflows = WorkflowTransition.where(:role_id => @role.id, :tracker_id => @tracker.id).all |
|
54 | 54 | @workflows = {} |
|
55 | 55 | @workflows['always'] = workflows.select {|w| !w.author && !w.assignee} |
|
56 | 56 | @workflows['author'] = workflows.select {|w| w.author} |
|
57 | 57 | @workflows['assignee'] = workflows.select {|w| w.assignee} |
|
58 | 58 | end |
|
59 | 59 | end |
|
60 | 60 | |
|
61 | 61 | def permissions |
|
62 | 62 | @role = Role.find_by_id(params[:role_id]) if params[:role_id] |
|
63 | 63 | @tracker = Tracker.find_by_id(params[:tracker_id]) if params[:tracker_id] |
|
64 | 64 | |
|
65 | 65 | if request.post? && @role && @tracker |
|
66 | 66 | WorkflowPermission.replace_permissions(@tracker, @role, params[:permissions] || {}) |
|
67 | redirect_to :action => 'permissions', :role_id => @role, :tracker_id => @tracker | |
|
67 | redirect_to :action => 'permissions', :role_id => @role, :tracker_id => @tracker, :used_statuses_only => params[:used_statuses_only] | |
|
68 | 68 | return |
|
69 | 69 | end |
|
70 | 70 | |
|
71 | 71 | @used_statuses_only = (params[:used_statuses_only] == '0' ? false : true) |
|
72 | 72 | if @tracker && @used_statuses_only && @tracker.issue_statuses.any? |
|
73 | 73 | @statuses = @tracker.issue_statuses |
|
74 | 74 | end |
|
75 | 75 | @statuses ||= IssueStatus.sorted.all |
|
76 | 76 | |
|
77 | 77 | if @role && @tracker |
|
78 | 78 | @fields = (Tracker::CORE_FIELDS_ALL - @tracker.disabled_core_fields).map {|field| [field, l("field_"+field.sub(/_id$/, ''))]} |
|
79 | 79 | @custom_fields = @tracker.custom_fields |
|
80 | 80 | |
|
81 | 81 | @permissions = WorkflowPermission.where(:tracker_id => @tracker.id, :role_id => @role.id).all.inject({}) do |h, w| |
|
82 | 82 | h[w.old_status_id] ||= {} |
|
83 | 83 | h[w.old_status_id][w.field_name] = w.rule |
|
84 | 84 | h |
|
85 | 85 | end |
|
86 | 86 | @statuses.each {|status| @permissions[status.id] ||= {}} |
|
87 | 87 | end |
|
88 | 88 | end |
|
89 | 89 | |
|
90 | 90 | def copy |
|
91 | 91 | |
|
92 | 92 | if params[:source_tracker_id].blank? || params[:source_tracker_id] == 'any' |
|
93 | 93 | @source_tracker = nil |
|
94 | 94 | else |
|
95 | 95 | @source_tracker = Tracker.find_by_id(params[:source_tracker_id].to_i) |
|
96 | 96 | end |
|
97 | 97 | if params[:source_role_id].blank? || params[:source_role_id] == 'any' |
|
98 | 98 | @source_role = nil |
|
99 | 99 | else |
|
100 | 100 | @source_role = Role.find_by_id(params[:source_role_id].to_i) |
|
101 | 101 | end |
|
102 | 102 | |
|
103 | 103 | @target_trackers = params[:target_tracker_ids].blank? ? nil : Tracker.find_all_by_id(params[:target_tracker_ids]) |
|
104 | 104 | @target_roles = params[:target_role_ids].blank? ? nil : Role.find_all_by_id(params[:target_role_ids]) |
|
105 | 105 | |
|
106 | 106 | if request.post? |
|
107 | 107 | if params[:source_tracker_id].blank? || params[:source_role_id].blank? || (@source_tracker.nil? && @source_role.nil?) |
|
108 | 108 | flash.now[:error] = l(:error_workflow_copy_source) |
|
109 | 109 | elsif @target_trackers.nil? || @target_roles.nil? |
|
110 | 110 | flash.now[:error] = l(:error_workflow_copy_target) |
|
111 | 111 | else |
|
112 | 112 | WorkflowRule.copy(@source_tracker, @source_role, @target_trackers, @target_roles) |
|
113 | 113 | flash[:notice] = l(:notice_successful_update) |
|
114 | 114 | redirect_to :action => 'copy', :source_tracker_id => @source_tracker, :source_role_id => @source_role |
|
115 | 115 | end |
|
116 | 116 | end |
|
117 | 117 | end |
|
118 | 118 | |
|
119 | 119 | private |
|
120 | 120 | |
|
121 | 121 | def find_roles |
|
122 | 122 | @roles = Role.sorted.all |
|
123 | 123 | end |
|
124 | 124 | |
|
125 | 125 | def find_trackers |
|
126 | 126 | @trackers = Tracker.sorted.all |
|
127 | 127 | end |
|
128 | 128 | end |
@@ -1,57 +1,58 | |||
|
1 | 1 | <%= render :partial => 'action_menu' %> |
|
2 | 2 | |
|
3 | 3 | <h2><%=l(:label_workflow)%></h2> |
|
4 | 4 | |
|
5 | 5 | <div class="tabs"> |
|
6 | 6 | <ul> |
|
7 | 7 | <li><%= link_to l(:label_status_transitions), {:action => 'edit', :role_id => @role, :tracker_id => @tracker}, :class => 'selected' %></li> |
|
8 | 8 | <li><%= link_to l(:label_fields_permissions), {:action => 'permissions', :role_id => @role, :tracker_id => @tracker} %></li> |
|
9 | 9 | </ul> |
|
10 | 10 | </div> |
|
11 | 11 | |
|
12 | 12 | <p><%=l(:text_workflow_edit)%>:</p> |
|
13 | 13 | |
|
14 | 14 | <%= form_tag({}, :method => 'get') do %> |
|
15 | 15 | <p> |
|
16 | 16 | <label><%=l(:label_role)%>: |
|
17 | 17 | <%= select_tag 'role_id', options_from_collection_for_select(@roles, "id", "name", @role && @role.id) %></label> |
|
18 | 18 | |
|
19 | 19 | <label><%=l(:label_tracker)%>: |
|
20 | 20 | <%= select_tag 'tracker_id', options_from_collection_for_select(@trackers, "id", "name", @tracker && @tracker.id) %></label> |
|
21 | 21 | |
|
22 | 22 | <%= submit_tag l(:button_edit), :name => nil %> |
|
23 | 23 | |
|
24 | 24 | <%= hidden_field_tag 'used_statuses_only', '0' %> |
|
25 | 25 | <label><%= check_box_tag 'used_statuses_only', '1', @used_statuses_only %> <%= l(:label_display_used_statuses_only) %></label> |
|
26 | 26 | |
|
27 | 27 | </p> |
|
28 | 28 | <% end %> |
|
29 | 29 | |
|
30 | 30 | <% if @tracker && @role && @statuses.any? %> |
|
31 | 31 | <%= form_tag({}, :id => 'workflow_form' ) do %> |
|
32 | 32 | <%= hidden_field_tag 'tracker_id', @tracker.id %> |
|
33 | 33 | <%= hidden_field_tag 'role_id', @role.id %> |
|
34 | <%= hidden_field_tag 'used_statuses_only', params[:used_statuses_only] %> | |
|
34 | 35 | <div class="autoscroll"> |
|
35 | 36 | <%= render :partial => 'form', :locals => {:name => 'always', :workflows => @workflows['always']} %> |
|
36 | 37 | |
|
37 | 38 | <fieldset class="collapsible" style="padding: 0; margin-top: 0.5em;"> |
|
38 | 39 | <legend onclick="toggleFieldset(this);"><%= l(:label_additional_workflow_transitions_for_author) %></legend> |
|
39 | 40 | <div id="author_workflows" style="margin: 0.5em 0 0.5em 0;"> |
|
40 | 41 | <%= render :partial => 'form', :locals => {:name => 'author', :workflows => @workflows['author']} %> |
|
41 | 42 | </div> |
|
42 | 43 | </fieldset> |
|
43 | 44 | <%= javascript_tag "hideFieldset($('author_workflows'))" unless @workflows['author'].present? %> |
|
44 | 45 | |
|
45 | 46 | <fieldset class="collapsible" style="padding: 0;"> |
|
46 | 47 | <legend onclick="toggleFieldset(this);"><%= l(:label_additional_workflow_transitions_for_assignee) %></legend> |
|
47 | 48 | <div id="assignee_workflows" style="margin: 0.5em 0 0.5em 0;"> |
|
48 | 49 | <%= render :partial => 'form', :locals => {:name => 'assignee', :workflows => @workflows['assignee']} %> |
|
49 | 50 | </div> |
|
50 | 51 | </fieldset> |
|
51 | 52 | <%= javascript_tag "hideFieldset($('assignee_workflows'))" unless @workflows['assignee'].present? %> |
|
52 | 53 | </div> |
|
53 | 54 | <%= submit_tag l(:button_save) %> |
|
54 | 55 | <% end %> |
|
55 | 56 | <% end %> |
|
56 | 57 | |
|
57 | 58 | <% html_title(l(:label_workflow)) -%> |
@@ -1,94 +1,95 | |||
|
1 | 1 | <%= render :partial => 'action_menu' %> |
|
2 | 2 | |
|
3 | 3 | <h2><%=l(:label_workflow)%></h2> |
|
4 | 4 | |
|
5 | 5 | <div class="tabs"> |
|
6 | 6 | <ul> |
|
7 | 7 | <li><%= link_to l(:label_status_transitions), {:action => 'edit', :role_id => @role, :tracker_id => @tracker} %></li> |
|
8 | 8 | <li><%= link_to l(:label_fields_permissions), {:action => 'permissions', :role_id => @role, :tracker_id => @tracker}, :class => 'selected' %></li> |
|
9 | 9 | </ul> |
|
10 | 10 | </div> |
|
11 | 11 | |
|
12 | 12 | <p><%=l(:text_workflow_edit)%>:</p> |
|
13 | 13 | |
|
14 | 14 | <%= form_tag({}, :method => 'get') do %> |
|
15 | 15 | <p> |
|
16 | 16 | <label><%=l(:label_role)%>: |
|
17 | 17 | <%= select_tag 'role_id', options_from_collection_for_select(@roles, "id", "name", @role && @role.id) %></label> |
|
18 | 18 | |
|
19 | 19 | <label><%=l(:label_tracker)%>: |
|
20 | 20 | <%= select_tag 'tracker_id', options_from_collection_for_select(@trackers, "id", "name", @tracker && @tracker.id) %></label> |
|
21 | 21 | |
|
22 | 22 | <%= submit_tag l(:button_edit), :name => nil %> |
|
23 | 23 | |
|
24 | 24 | <%= hidden_field_tag 'used_statuses_only', '0' %> |
|
25 | 25 | <label><%= check_box_tag 'used_statuses_only', '1', @used_statuses_only %> <%= l(:label_display_used_statuses_only) %></label> |
|
26 | 26 | </p> |
|
27 | 27 | <% end %> |
|
28 | 28 | |
|
29 | 29 | <% if @tracker && @role && @statuses.any? %> |
|
30 | 30 | <%= form_tag({}, :id => 'workflow_form' ) do %> |
|
31 | 31 | <%= hidden_field_tag 'tracker_id', @tracker.id %> |
|
32 | 32 | <%= hidden_field_tag 'role_id', @role.id %> |
|
33 | <%= hidden_field_tag 'used_statuses_only', params[:used_statuses_only] %> | |
|
33 | 34 | <div class="autoscroll"> |
|
34 | 35 | <table class="list fields_permissions"> |
|
35 | 36 | <thead> |
|
36 | 37 | <tr> |
|
37 | 38 | <th align="left"> |
|
38 | 39 | </th> |
|
39 | 40 | <th align="center" colspan="<%= @statuses.length %>"><%=l(:label_issue_status)%></th> |
|
40 | 41 | </tr> |
|
41 | 42 | <tr> |
|
42 | 43 | <td></td> |
|
43 | 44 | <% for status in @statuses %> |
|
44 | 45 | <td width="<%= 75 / @statuses.size %>%" align="center"> |
|
45 | 46 | <%=h status.name %> |
|
46 | 47 | </td> |
|
47 | 48 | <% end %> |
|
48 | 49 | </tr> |
|
49 | 50 | </thead> |
|
50 | 51 | <tbody> |
|
51 | 52 | <tr class="group open"> |
|
52 | 53 | <td colspan="<%= @statuses.size + 1 %>"> |
|
53 | 54 | <span class="expander" onclick="toggleRowGroup(this);"> </span> |
|
54 | 55 | <%= l(:field_core_fields) %> |
|
55 | 56 | </td> |
|
56 | 57 | </tr> |
|
57 | 58 | <% @fields.each do |field, name| %> |
|
58 | 59 | <tr class="<%= cycle("odd", "even") %>"> |
|
59 | 60 | <td> |
|
60 | 61 | <%=h name %> |
|
61 | 62 | </td> |
|
62 | 63 | <% for status in @statuses -%> |
|
63 | 64 | <td align="center" class="<%= @permissions[status.id][field] %>"> |
|
64 | 65 | <%= field_permission_tag(@permissions, status, field) %> |
|
65 | 66 | </td> |
|
66 | 67 | <% end -%> |
|
67 | 68 | </tr> |
|
68 | 69 | <% end %> |
|
69 | 70 | <% if @custom_fields.any? %> |
|
70 | 71 | <tr class="group open"> |
|
71 | 72 | <td colspan="<%= @statuses.size + 1 %>"> |
|
72 | 73 | <span class="expander" onclick="toggleRowGroup(this);"> </span> |
|
73 | 74 | <%= l(:label_custom_field_plural) %> |
|
74 | 75 | </td> |
|
75 | 76 | </tr> |
|
76 | 77 | <% @custom_fields.each do |field| %> |
|
77 | 78 | <tr class="<%= cycle("odd", "even") %>"> |
|
78 | 79 | <td> |
|
79 | 80 | <%=h field.name %> |
|
80 | 81 | </td> |
|
81 | 82 | <% for status in @statuses -%> |
|
82 | 83 | <td align="center" class="<%= @permissions[status.id][field.id.to_s] %>"> |
|
83 | 84 | <%= field_permission_tag(@permissions, status, field) %> |
|
84 | 85 | </td> |
|
85 | 86 | <% end -%> |
|
86 | 87 | </tr> |
|
87 | 88 | <% end %> |
|
88 | 89 | <% end %> |
|
89 | 90 | </tbody> |
|
90 | 91 | </table> |
|
91 | 92 | </div> |
|
92 | 93 | <%= submit_tag l(:button_save) %> |
|
93 | 94 | <% end %> |
|
94 | 95 | <% end %> |
General Comments 0
You need to be logged in to leave comments.
Login now