diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index cca3fe623..081d8f895 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -194,6 +194,7 @@ class IssuesController < ApplicationController :change_status => User.current.allowed_to?(:change_issue_status, @project), :add => User.current.allowed_to?(:add_issues, @project), :move => User.current.allowed_to?(:move_issues, @project), + :copy => (@project.trackers.include?(@issue.tracker) && User.current.allowed_to?(:add_issues, @project)), :delete => User.current.allowed_to?(:delete_issues, @project)} render :layout => false end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 0f50cd780..37a788690 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -57,11 +57,13 @@ class ProjectsController < ApplicationController # Add a new project def add @custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") + @trackers = Tracker.all @root_projects = Project.find(:all, :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}") @project = Project.new(params[:project]) @project.enabled_module_names = Redmine::AccessControl.available_project_modules if request.get? @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project) } + @project.trackers = Tracker.all else @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids] @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => (params[:custom_fields] ? params["custom_fields"][x.id.to_s] : nil)) } @@ -80,7 +82,7 @@ class ProjectsController < ApplicationController @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role} @subprojects = @project.active_children @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC") - @trackers = Tracker.find(:all, :order => 'position') + @trackers = @project.trackers @open_issues_by_tracker = Issue.count(:group => :tracker, :joins => "INNER JOIN #{IssueStatus.table_name} ON #{IssueStatus.table_name}.id = #{Issue.table_name}.status_id", :conditions => ["project_id=? and #{IssueStatus.table_name}.is_closed=?", @project.id, false]) @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id]) @total_hours = @project.time_entries.sum(:hours) @@ -92,6 +94,7 @@ class ProjectsController < ApplicationController @custom_fields = IssueCustomField.find(:all) @issue_category ||= IssueCategory.new @member ||= @project.members.new + @trackers = Tracker.all @custom_values ||= ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) } @repository ||= @project.repository @wiki ||= @project.wiki @@ -207,7 +210,7 @@ class ProjectsController < ApplicationController @issue = params[:copy_from] ? Issue.new.copy_from(params[:copy_from]) : Issue.new(params[:issue]) @issue.project = @project @issue.author = User.current - @issue.tracker ||= Tracker.find(params[:tracker_id]) + @issue.tracker ||= @project.trackers.find(params[:tracker_id]) default_status = IssueStatus.default unless default_status @@ -293,6 +296,7 @@ class ProjectsController < ApplicationController def move_issues @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids] redirect_to :controller => 'issues', :action => 'index', :project_id => @project and return unless @issues + @projects = [] # find projects to which the user is allowed to move the issue if User.current.admin? @@ -301,14 +305,14 @@ class ProjectsController < ApplicationController else User.current.memberships.each {|m| @projects << m.project if m.role.allowed_to?(:move_issues)} end - # issue can be moved to any tracker - @trackers = Tracker.find(:all) - if request.post? && params[:new_project_id] && @projects.collect(&:id).include?(params[:new_project_id].to_i) && params[:new_tracker_id] - new_project = Project.find_by_id(params[:new_project_id]) - new_tracker = params[:new_tracker_id].blank? ? nil : Tracker.find_by_id(params[:new_tracker_id]) + @target_project = @projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id] + @target_project ||= @project + @trackers = @target_project.trackers + if request.post? + new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id]) unsaved_issue_ids = [] @issues.each do |issue| - unsaved_issue_ids << issue.id unless issue.move_to(new_project, new_tracker) + unsaved_issue_ids << issue.id unless issue.move_to(@target_project, new_tracker) end if unsaved_issue_ids.empty? flash[:notice] = l(:notice_successful_update) unless @issues.empty? @@ -316,7 +320,9 @@ class ProjectsController < ApplicationController flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, @issues.size, '#' + unsaved_issue_ids.join(', #')) end redirect_to :controller => 'issues', :action => 'index', :project_id => @project + return end + render :layout => false if request.xhr? end # Add a news to @project @@ -354,13 +360,13 @@ class ProjectsController < ApplicationController # Show changelog for @project def changelog - @trackers = Tracker.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position') + @trackers = @project.trackers.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position') retrieve_selected_tracker_ids(@trackers) @versions = @project.versions.sort end def roadmap - @trackers = Tracker.find(:all, :conditions => ["is_in_roadmap=?", true], :order => 'position') + @trackers = @project.trackers.find(:all, :conditions => ["is_in_roadmap=?", true]) retrieve_selected_tracker_ids(@trackers) @versions = @project.versions.sort @versions = @versions.select {|v| !v.completed? } unless params[:completed] diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index 6b95944a0..e18e117a6 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -25,7 +25,7 @@ class ReportsController < ApplicationController case params[:detail] when "tracker" @field = "tracker_id" - @rows = Tracker.find :all, :order => 'position' + @rows = @project.trackers @data = issues_by_tracker @report_title = l(:field_tracker) render :template => "reports/issue_report_details" @@ -60,7 +60,7 @@ class ReportsController < ApplicationController @report_title = l(:field_subproject) render :template => "reports/issue_report_details" else - @trackers = Tracker.find(:all, :order => 'position') + @trackers = @project.trackers @versions = @project.versions.sort @priorities = Enumeration::get_values('IPRI') @categories = @project.issue_categories diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 5b78db71c..4b1b1a954 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -190,7 +190,7 @@ module ProjectsHelper end if Object.const_defined?(:Magick) def new_issue_selector - trackers = Tracker.find(:all, :order => 'position') + trackers = @project.trackers # can't use form tag inside helper content_tag('form', select_tag('tracker_id', '' + options_from_collection_for_select(trackers, 'id', 'name'), :onchange => "if (this.value != '') {this.form.submit()}"), diff --git a/app/models/custom_value.rb b/app/models/custom_value.rb index afe4c1afb..c3d6b7bb9 100644 --- a/app/models/custom_value.rb +++ b/app/models/custom_value.rb @@ -31,9 +31,9 @@ protected when 'float' begin; !value.blank? && Kernel.Float(value); rescue; errors.add(:value, :activerecord_error_invalid) end when 'date' - errors.add(:value, :activerecord_error_not_a_date) unless value =~ /^\d{4}-\d{2}-\d{2}$/ or value.empty? + errors.add(:value, :activerecord_error_not_a_date) unless value =~ /^\d{4}-\d{2}-\d{2}$/ or value.blank? when 'list' - errors.add(:value, :activerecord_error_inclusion) unless custom_field.possible_values.include? value or value.empty? + errors.add(:value, :activerecord_error_inclusion) unless custom_field.possible_values.include?(value) or value.blank? end end end diff --git a/app/models/issue.rb b/app/models/issue.rb index 60cca4051..f7b01ea6a 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -40,7 +40,7 @@ class Issue < ActiveRecord::Base acts_as_event :title => Proc.new {|o| "#{o.tracker.name} ##{o.id}: #{o.subject}"}, :url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.id}} - validates_presence_of :subject, :description, :priority, :tracker, :author, :status + validates_presence_of :subject, :description, :priority, :project, :tracker, :author, :status validates_length_of :subject, :maximum => 255 validates_inclusion_of :done_ratio, :in => 0..100 validates_numericality_of :estimated_hours, :allow_nil => true @@ -106,6 +106,10 @@ class Issue < ActiveRecord::Base end end + def validate_on_create + errors.add :tracker_id, :activerecord_error_invalid unless project.trackers.include?(tracker) + end + def before_create # default assignment based on category if assigned_to.nil? && category && category.assigned_to diff --git a/app/models/project.rb b/app/models/project.rb index afaa049c6..be46d6189 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -24,6 +24,7 @@ class Project < ActiveRecord::Base has_many :users, :through => :members has_many :custom_values, :dependent => :delete_all, :as => :customized has_many :enabled_modules, :dependent => :delete_all + has_and_belongs_to_many :trackers, :order => "#{Tracker.table_name}.position" has_many :issues, :dependent => :destroy, :order => "#{Issue.table_name}.created_on DESC", :include => [:status, :tracker] has_many :issue_changes, :through => :issues, :source => :journals has_many :versions, :dependent => :destroy, :order => "#{Version.table_name}.effective_date DESC, #{Version.table_name}.name DESC" diff --git a/app/models/tracker.rb b/app/models/tracker.rb index 90ef31912..6de2a098c 100644 --- a/app/models/tracker.rb +++ b/app/models/tracker.rb @@ -29,6 +29,10 @@ class Tracker < ActiveRecord::Base def to_s; name end + def self.all + find(:all, :order => 'position') + end + private def check_integrity raise "Can't delete tracker" if Issue.find(:first, :conditions => ["tracker_id=?", self.id]) diff --git a/app/views/issues/_sidebar.rhtml b/app/views/issues/_sidebar.rhtml index 3b42ce465..6e61755e8 100644 --- a/app/views/issues/_sidebar.rhtml +++ b/app/views/issues/_sidebar.rhtml @@ -1,4 +1,4 @@ -<% if authorize_for('projects', 'add_issue') %> +<% if authorize_for('projects', 'add_issue') && @project.trackers.any? %>
<%= custom_field_tag_with_label @custom_value %>
<% end %> + + +<% unless @trackers.empty? %> + +<% end %> <% unless @custom_fields.empty? %> -+
<% end %> - + <% content_for :header_tags do %> <%= javascript_include_tag 'calendar/calendar' %> diff --git a/app/views/projects/add.rhtml b/app/views/projects/add.rhtml index 4818cae4a..e3ee0b591 100644 --- a/app/views/projects/add.rhtml +++ b/app/views/projects/add.rhtml @@ -3,13 +3,13 @@ <% labelled_tabular_form_for :project, @project, :url => { :action => "add" } do |f| %> <%= render :partial => 'form', :locals => { :f => f } %> -+
@@ -15,7 +15,12 @@
-<%= select_tag "new_project_id", options_from_collection_for_select(@projects, "id", "name", @project.id) %>
+<%= select_tag "new_project_id", + options_from_collection_for_select(@projects, 'id', 'name', @target_project.id), + :onchange => remote_function(:url => {:action => 'move_issues' , :id => @project}, + :method => :get, + :update => 'content', + :with => "Form.serialize('move_form')") %><%= select_tag "new_tracker_id", "" + options_from_collection_for_select(@trackers, "id", "name") %>
diff --git a/app/views/projects/show.rhtml b/app/views/projects/show.rhtml index 94df0bf3d..458e7975e 100644 --- a/app/views/projects/show.rhtml +++ b/app/views/projects/show.rhtml @@ -56,7 +56,7 @@