##// END OF EJS Templates
Adds a workflow overview screen....
Jean-Philippe Lang -
r1912:a37af7a2260d
parent child
Show More
@@ -0,0 +1,45
1 # Redmine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 class WorkflowsController < ApplicationController
19 before_filter :require_admin
20
21 def index
22 @workflow_counts = Workflow.count_by_tracker_and_role
23 end
24
25 def edit
26 @role = Role.find_by_id(params[:role_id])
27 @tracker = Tracker.find_by_id(params[:tracker_id])
28
29 if request.post?
30 Workflow.destroy_all( ["role_id=? and tracker_id=?", @role.id, @tracker.id])
31 (params[:issue_status] || []).each { |old, news|
32 news.each { |new|
33 @role.workflows.build(:tracker_id => @tracker.id, :old_status_id => old, :new_status_id => new)
34 }
35 }
36 if @role.save
37 flash[:notice] = l(:notice_successful_update)
38 redirect_to :action => 'edit', :role_id => @role, :tracker_id => @tracker
39 end
40 end
41 @roles = Role.find(:all, :order => 'builtin, position')
42 @trackers = Tracker.find(:all, :order => 'position')
43 @statuses = IssueStatus.find(:all, :order => 'position')
44 end
45 end
@@ -0,0 +1,19
1 # Redmine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 module WorkflowsHelper
19 end
@@ -0,0 +1,31
1 <h2><%=l(:label_workflow)%></h2>
2
3 <% if @workflow_counts.empty? %>
4 <p class="nodata"><%= l(:label_no_data) %></p>
5 <% else %>
6 <table class="list">
7 <thead>
8 <tr>
9 <th></th>
10 <% @workflow_counts.first.last.each do |role, count| %>
11 <th>
12 <%= content_tag(role.builtin? ? 'em' : 'span', h(role.name)) %>
13 </th>
14
15 <% end %>
16 </tr>
17 </thead>
18 <tbody>
19 <% @workflow_counts.each do |tracker, roles| -%>
20 <tr class="<%= cycle('odd', 'even') %>">
21 <td><%= h tracker %></td>
22 <% roles.each do |role, count| -%>
23 <td align="center">
24 <%= link_to((count > 1 ? count : image_tag('false.png')), {:action => 'edit', :role_id => role, :tracker_id => tracker}, :title => l(:button_edit)) %>
25 </td>
26 <% end -%>
27 </tr>
28 <% end -%>
29 </tbody>
30 </table>
31 <% end %>
@@ -0,0 +1,84
1 # Redmine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 require File.dirname(__FILE__) + '/../test_helper'
19 require 'workflows_controller'
20
21 # Re-raise errors caught by the controller.
22 class WorkflowsController; def rescue_action(e) raise e end; end
23
24 class WorkflowsControllerTest < Test::Unit::TestCase
25 fixtures :roles, :trackers, :workflows
26
27 def setup
28 @controller = WorkflowsController.new
29 @request = ActionController::TestRequest.new
30 @response = ActionController::TestResponse.new
31 User.current = nil
32 @request.session[:user_id] = 1 # admin
33 end
34
35 def test_index
36 get :index
37 assert_response :success
38 assert_template 'index'
39
40 count = Workflow.count(:all, :conditions => 'role_id = 1 AND tracker_id = 2')
41 assert_tag :tag => 'a', :content => count.to_s,
42 :attributes => { :href => '/workflows/edit?role_id=1&amp;tracker_id=2' }
43 end
44
45 def test_get_edit
46 get :edit
47 assert_response :success
48 assert_template 'edit'
49 assert_not_nil assigns(:roles)
50 assert_not_nil assigns(:trackers)
51 end
52
53 def test_get_edit_with_role_and_tracker
54 get :edit, :role_id => 2, :tracker_id => 1
55 assert_response :success
56 assert_template 'edit'
57 # allowed transitions
58 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
59 :name => 'issue_status[2][]',
60 :value => '1',
61 :checked => 'checked' }
62 # not allowed
63 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
64 :name => 'issue_status[2][]',
65 :value => '3',
66 :checked => nil }
67 end
68
69 def test_post_edit
70 post :edit, :role_id => 2, :tracker_id => 1, :issue_status => {'4' => ['5'], '3' => ['1', '2']}
71 assert_redirected_to 'workflows/edit'
72
73 assert_equal 3, Workflow.count(:conditions => {:tracker_id => 1, :role_id => 2})
74 assert_not_nil Workflow.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 2})
75 assert_nil Workflow.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4})
76 end
77
78 def test_clear_workflow
79 assert Workflow.count(:conditions => {:tracker_id => 1, :role_id => 2}) > 0
80
81 post :edit, :role_id => 2, :tracker_id => 1
82 assert_equal 0, Workflow.count(:conditions => {:tracker_id => 1, :role_id => 2})
83 end
84 end
@@ -79,27 +79,6 class RolesController < ApplicationController
79 79 redirect_to :action => 'list'
80 80 end
81 81
82 def workflow
83 @role = Role.find_by_id(params[:role_id])
84 @tracker = Tracker.find_by_id(params[:tracker_id])
85
86 if request.post?
87 Workflow.destroy_all( ["role_id=? and tracker_id=?", @role.id, @tracker.id])
88 (params[:issue_status] || []).each { |old, news|
89 news.each { |new|
90 @role.workflows.build(:tracker_id => @tracker.id, :old_status_id => old, :new_status_id => new)
91 }
92 }
93 if @role.save
94 flash[:notice] = l(:notice_successful_update)
95 redirect_to :action => 'workflow', :role_id => @role, :tracker_id => @tracker
96 end
97 end
98 @roles = Role.find(:all, :order => 'builtin, position')
99 @trackers = Tracker.find(:all, :order => 'position')
100 @statuses = IssueStatus.find(:all, :order => 'position')
101 end
102
103 82 def report
104 83 @roles = Role.find(:all, :order => 'builtin, position')
105 84 @permissions = Redmine::AccessControl.permissions.select { |p| !p.public? }
@@ -21,4 +21,23 class Workflow < ActiveRecord::Base
21 21 belongs_to :new_status, :class_name => 'IssueStatus', :foreign_key => 'new_status_id'
22 22
23 23 validates_presence_of :role, :old_status, :new_status
24
25 # Returns workflow transitions count by tracker and role
26 def self.count_by_tracker_and_role
27 counts = connection.select_all("SELECT role_id, tracker_id, count(id) AS c FROM #{Workflow.table_name} GROUP BY role_id, tracker_id")
28 roles = Role.find(:all, :order => 'builtin, position')
29 trackers = Tracker.find(:all, :order => 'position')
30
31 result = []
32 trackers.each do |tracker|
33 t = []
34 roles.each do |role|
35 row = counts.detect {|c| c['role_id'] == role.id.to_s && c['tracker_id'] = tracker.id.to_s}
36 t << [role, (row.nil? ? 0 : row['c'].to_i)]
37 end
38 result << [tracker, t]
39 end
40
41 result
42 end
24 43 end
@@ -19,7 +19,7
19 19 <p class="icon22 icon22-tracker">
20 20 <%= link_to l(:label_tracker_plural), :controller => 'trackers' %> |
21 21 <%= link_to l(:label_issue_status_plural), :controller => 'issue_statuses' %> |
22 <%= link_to l(:label_workflow), :controller => 'roles', :action => 'workflow' %>
22 <%= link_to l(:label_workflow), :controller => 'workflows', :action => 'edit' %>
23 23 </p>
24 24
25 25 <p class="icon22 icon22-workflow">
@@ -1,8 +1,12
1 <div class="contextual">
2 <%= link_to l(:field_summary), :action => 'index' %>
3 </div>
4
1 5 <h2><%=l(:label_workflow)%></h2>
2 6
3 7 <p><%=l(:text_workflow_edit)%>:</p>
4 8
5 <% form_tag({:action => 'workflow'}, :method => 'get') do %>
9 <% form_tag({}, :method => 'get') do %>
6 10 <p><label for="role_id"><%=l(:label_role)%>:</label>
7 11 <select id="role_id" name="role_id">
8 12 <%= options_from_collection_for_select @roles, "id", "name", (@role.id unless @role.nil?) %>
@@ -12,14 +16,16
12 16 <select id="tracker_id" name="tracker_id">
13 17 <%= options_from_collection_for_select @trackers, "id", "name", (@tracker.id unless @tracker.nil?) %>
14 18 </select>
15 <%= submit_tag l(:button_edit) %>
19 <%= submit_tag l(:button_edit), :name => nil %>
16 20 </p>
17 21 <% end %>
18 22
19 23
20 24
21 25 <% unless @tracker.nil? or @role.nil? %>
22 <% form_tag({:action => 'workflow', :role_id => @role, :tracker_id => @tracker }, :id => 'workflow_form' ) do %>
26 <% form_tag({}, :id => 'workflow_form' ) do %>
27 <%= hidden_field_tag 'tracker_id', @tracker.id %>
28 <%= hidden_field_tag 'role_id', @role.id %>
23 29 <div class="box">
24 30 <table>
25 31 <tr>
@@ -118,46 +118,6 class RolesControllerTest < Test::Unit::TestCase
118 118 assert_not_nil Role.find_by_id(1)
119 119 end
120 120
121 def test_get_workflow
122 get :workflow
123 assert_response :success
124 assert_template 'workflow'
125 assert_not_nil assigns(:roles)
126 assert_not_nil assigns(:trackers)
127 end
128
129 def test_get_workflow_with_role_and_tracker
130 get :workflow, :role_id => 2, :tracker_id => 1
131 assert_response :success
132 assert_template 'workflow'
133 # allowed transitions
134 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
135 :name => 'issue_status[2][]',
136 :value => '1',
137 :checked => 'checked' }
138 # not allowed
139 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
140 :name => 'issue_status[2][]',
141 :value => '3',
142 :checked => nil }
143 end
144
145 def test_post_workflow
146 post :workflow, :role_id => 2, :tracker_id => 1, :issue_status => {'4' => ['5'], '3' => ['1', '2']}
147 assert_redirected_to 'roles/workflow'
148
149 assert_equal 3, Workflow.count(:conditions => {:tracker_id => 1, :role_id => 2})
150 assert_not_nil Workflow.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 2})
151 assert_nil Workflow.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4})
152 end
153
154 def test_clear_workflow
155 assert Workflow.count(:conditions => {:tracker_id => 1, :role_id => 2}) > 0
156
157 post :workflow, :role_id => 2, :tracker_id => 1
158 assert_equal 0, Workflow.count(:conditions => {:tracker_id => 1, :role_id => 2})
159 end
160
161 121 def test_get_report
162 122 get :report
163 123 assert_response :success
General Comments 0
You need to be logged in to leave comments. Login now