#3178: creating explicit impediment class, only copy and paste for now

pull/6827/head
Jens Ulferts 14 years ago
parent 0541bad731
commit 68d7230d8e
  1. 6
      app/controllers/rb_impediments_controller.rb
  2. 41
      app/models/impediment.rb
  3. 26
      app/models/task.rb

@ -2,7 +2,7 @@ class RbImpedimentsController < RbApplicationController
unloadable unloadable
def create 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 result = @impediment.errors.length
status = (result == 0 ? 200 : 400) status = (result == 0 ? 200 : 400)
@include_meta = true @include_meta = true
@ -13,8 +13,8 @@ class RbImpedimentsController < RbApplicationController
end end
def update def update
@impediment = Task.find_by_id(params[:id]) @impediment = Impediment.find_by_id(params[:id])
result = @impediment.update_with_relationships(params, true) result = @impediment.update_with_relationships(params)
status = (result ? 200 : 400) status = (result ? 200 : 400)
@include_meta = true @include_meta = true

@ -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

@ -75,32 +75,6 @@ class Task < Issue
end end
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' # assumes the task is already under the same story as 'id'
def move_after(id) def move_after(id)
id = nil if id.respond_to?('blank?') && id.blank? id = nil if id.respond_to?('blank?') && id.blank?

Loading…
Cancel
Save