From 68d7230d8e68594217fa14e3ae79100a7ce38ec9 Mon Sep 17 00:00:00 2001 From: Jens Ulferts Date: Fri, 25 Mar 2011 21:29:14 +0100 Subject: [PATCH] #3178: creating explicit impediment class, only copy and paste for now --- app/controllers/rb_impediments_controller.rb | 6 +-- app/models/impediment.rb | 41 ++++++++++++++++++++ app/models/task.rb | 26 ------------- 3 files changed, 44 insertions(+), 29 deletions(-) create mode 100644 app/models/impediment.rb diff --git a/app/controllers/rb_impediments_controller.rb b/app/controllers/rb_impediments_controller.rb index 5bf9866761..c9cf551fbe 100644 --- a/app/controllers/rb_impediments_controller.rb +++ b/app/controllers/rb_impediments_controller.rb @@ -2,7 +2,7 @@ class RbImpedimentsController < RbApplicationController unloadable def create - @impediment = Task.create_with_relationships(params, User.current.id, @project.id, true) + @impediment = Impediment.create_with_relationships(params, User.current.id, @project.id) result = @impediment.errors.length status = (result == 0 ? 200 : 400) @include_meta = true @@ -13,8 +13,8 @@ class RbImpedimentsController < RbApplicationController end def update - @impediment = Task.find_by_id(params[:id]) - result = @impediment.update_with_relationships(params, true) + @impediment = Impediment.find_by_id(params[:id]) + result = @impediment.update_with_relationships(params) status = (result ? 200 : 400) @include_meta = true diff --git a/app/models/impediment.rb b/app/models/impediment.rb new file mode 100644 index 0000000000..9a80e3e032 --- /dev/null +++ b/app/models/impediment.rb @@ -0,0 +1,41 @@ +class Impediment < Task + unloadable + + def self.create_with_relationships(params, user_id, project_id) + super(params, user_id, project_id, true) + end + + def self.find_all_updated_since(since, project_id) + super(since, project_id, true) + end + + def update_with_relationships(params) + super(params, true) + end + + def update_blocked_list(for_blocking) + # Existing relationships not in for_blocking should be removed from the 'blocks' list + relations_from.find(:all, :conditions => "relation_type='blocks'").each{ |ir| + ir.destroy unless for_blocking.include?( ir[:issue_to_id] ) + } + + already_blocking = relations_from.find(:all, :conditions => "relation_type='blocks'").map{|ir| ir.issue_to_id} + + # Non-existing relationships that are in for_blocking should be added to the 'blocks' list + for_blocking.select{ |id| !already_blocking.include?(id) }.each{ |id| + ir = relations_from.new(:relation_type=>'blocks') + ir[:issue_to_id] = id + ir.save! + } + reload + end + + def validate_blocks_list(list) + if list.split(/\D+/).length==0 + errors.add :blocks, :must_have_comma_delimited_list + false + else + true + end + end +end \ No newline at end of file diff --git a/app/models/task.rb b/app/models/task.rb index 0d7c5c57d0..3a55aa7dec 100644 --- a/app/models/task.rb +++ b/app/models/task.rb @@ -75,32 +75,6 @@ class Task < Issue end end - def update_blocked_list(for_blocking) - # Existing relationships not in for_blocking should be removed from the 'blocks' list - relations_from.find(:all, :conditions => "relation_type='blocks'").each{ |ir| - ir.destroy unless for_blocking.include?( ir[:issue_to_id] ) - } - - already_blocking = relations_from.find(:all, :conditions => "relation_type='blocks'").map{|ir| ir.issue_to_id} - - # Non-existing relationships that are in for_blocking should be added to the 'blocks' list - for_blocking.select{ |id| !already_blocking.include?(id) }.each{ |id| - ir = relations_from.new(:relation_type=>'blocks') - ir[:issue_to_id] = id - ir.save! - } - reload - end - - def validate_blocks_list(list) - if list.split(/\D+/).length==0 - errors.add :blocks, :must_have_comma_delimited_list - false - else - true - end - end - # assumes the task is already under the same story as 'id' def move_after(id) id = nil if id.respond_to?('blank?') && id.blank?