diff --git a/app/controllers/roles_controller.rb b/app/controllers/roles_controller.rb index 72555e5b0..ab70ebf41 100644 --- a/app/controllers/roles_controller.rb +++ b/app/controllers/roles_controller.rb @@ -79,27 +79,6 @@ class RolesController < ApplicationController redirect_to :action => 'list' end - def workflow - @role = Role.find_by_id(params[:role_id]) - @tracker = Tracker.find_by_id(params[:tracker_id]) - - if request.post? - Workflow.destroy_all( ["role_id=? and tracker_id=?", @role.id, @tracker.id]) - (params[:issue_status] || []).each { |old, news| - news.each { |new| - @role.workflows.build(:tracker_id => @tracker.id, :old_status_id => old, :new_status_id => new) - } - } - if @role.save - flash[:notice] = l(:notice_successful_update) - redirect_to :action => 'workflow', :role_id => @role, :tracker_id => @tracker - end - end - @roles = Role.find(:all, :order => 'builtin, position') - @trackers = Tracker.find(:all, :order => 'position') - @statuses = IssueStatus.find(:all, :order => 'position') - end - def report @roles = Role.find(:all, :order => 'builtin, position') @permissions = Redmine::AccessControl.permissions.select { |p| !p.public? } diff --git a/app/controllers/workflows_controller.rb b/app/controllers/workflows_controller.rb new file mode 100644 index 000000000..380d4e752 --- /dev/null +++ b/app/controllers/workflows_controller.rb @@ -0,0 +1,45 @@ +# Redmine - project management software +# Copyright (C) 2006-2008 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +class WorkflowsController < ApplicationController + before_filter :require_admin + + def index + @workflow_counts = Workflow.count_by_tracker_and_role + end + + def edit + @role = Role.find_by_id(params[:role_id]) + @tracker = Tracker.find_by_id(params[:tracker_id]) + + if request.post? + Workflow.destroy_all( ["role_id=? and tracker_id=?", @role.id, @tracker.id]) + (params[:issue_status] || []).each { |old, news| + news.each { |new| + @role.workflows.build(:tracker_id => @tracker.id, :old_status_id => old, :new_status_id => new) + } + } + if @role.save + flash[:notice] = l(:notice_successful_update) + redirect_to :action => 'edit', :role_id => @role, :tracker_id => @tracker + end + end + @roles = Role.find(:all, :order => 'builtin, position') + @trackers = Tracker.find(:all, :order => 'position') + @statuses = IssueStatus.find(:all, :order => 'position') + end +end diff --git a/app/helpers/workflows_helper.rb b/app/helpers/workflows_helper.rb new file mode 100644 index 000000000..48ded305f --- /dev/null +++ b/app/helpers/workflows_helper.rb @@ -0,0 +1,19 @@ +# Redmine - project management software +# Copyright (C) 2006-2008 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +module WorkflowsHelper +end diff --git a/app/models/workflow.rb b/app/models/workflow.rb index 89322aa58..e254ac48c 100644 --- a/app/models/workflow.rb +++ b/app/models/workflow.rb @@ -21,4 +21,23 @@ class Workflow < ActiveRecord::Base belongs_to :new_status, :class_name => 'IssueStatus', :foreign_key => 'new_status_id' validates_presence_of :role, :old_status, :new_status + + # Returns workflow transitions count by tracker and role + def self.count_by_tracker_and_role + counts = connection.select_all("SELECT role_id, tracker_id, count(id) AS c FROM #{Workflow.table_name} GROUP BY role_id, tracker_id") + roles = Role.find(:all, :order => 'builtin, position') + trackers = Tracker.find(:all, :order => 'position') + + result = [] + trackers.each do |tracker| + t = [] + roles.each do |role| + row = counts.detect {|c| c['role_id'] == role.id.to_s && c['tracker_id'] = tracker.id.to_s} + t << [role, (row.nil? ? 0 : row['c'].to_i)] + end + result << [tracker, t] + end + + result + end end diff --git a/app/views/admin/index.rhtml b/app/views/admin/index.rhtml index 18bee34cb..438f72a30 100644 --- a/app/views/admin/index.rhtml +++ b/app/views/admin/index.rhtml @@ -19,7 +19,7 @@
<%= link_to l(:label_tracker_plural), :controller => 'trackers' %> | <%= link_to l(:label_issue_status_plural), :controller => 'issue_statuses' %> | -<%= link_to l(:label_workflow), :controller => 'roles', :action => 'workflow' %> +<%= link_to l(:label_workflow), :controller => 'workflows', :action => 'edit' %>
diff --git a/app/views/roles/workflow.rhtml b/app/views/workflows/edit.rhtml similarity index 83% rename from app/views/roles/workflow.rhtml rename to app/views/workflows/edit.rhtml index 0f08b0d22..00d6115d9 100644 --- a/app/views/roles/workflow.rhtml +++ b/app/views/workflows/edit.rhtml @@ -1,8 +1,12 @@ +
<%=l(:text_workflow_edit)%>:
-<% form_tag({:action => 'workflow'}, :method => 'get') do %> +<% form_tag({}, :method => 'get') do %><% end %> <% unless @tracker.nil? or @role.nil? %> -<% form_tag({:action => 'workflow', :role_id => @role, :tracker_id => @tracker }, :id => 'workflow_form' ) do %> +<% form_tag({}, :id => 'workflow_form' ) do %> +<%= hidden_field_tag 'tracker_id', @tracker.id %> +<%= hidden_field_tag 'role_id', @role.id %>
| + <% @workflow_counts.first.last.each do |role, count| %> + | + <%= content_tag(role.builtin? ? 'em' : 'span', h(role.name)) %> + | + + <% end %> +
|---|---|
| <%= h tracker %> | + <% roles.each do |role, count| -%> ++ <%= link_to((count > 1 ? count : image_tag('false.png')), {:action => 'edit', :role_id => role, :tracker_id => tracker}, :title => l(:button_edit)) %> + | + <% end -%> +