OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openproject/app/models/story.rb

128 lines
3.7 KiB

15 years ago
class Story < Issue
unloadable
14 years ago
acts_as_list :scope => :project
def self.product_backlog(project, limit=nil)
return Story.find(:all,
14 years ago
# this forces NULLS-LAST ordering
:order => 'case when position is null then 1 else 0 end ASC, position ASC',
15 years ago
:conditions => [
"parent_id is NULL and project_id = ? and tracker_id in (?) and fixed_version_id is NULL", #and status_id in (?)",
project.id, Story.trackers #, IssueStatus.find(:all, :conditions => ["is_closed = ?", false]).collect {|s| "#{s.id}" }
],
:limit => limit)
end
15 years ago
named_scope :sprint_backlog, lambda { |sprint|
{
14 years ago
# this forces NULLS-LAST ordering
:order => 'case when position is null then 1 else 0 end ASC, position ASC',
15 years ago
:conditions => [
"parent_id is NULL and tracker_id in (?) and fixed_version_id = ?",
Story.trackers, sprint.id
15 years ago
]
}
}
14 years ago
def self.create_and_position(params)
attribs = params.select{|k,v| k != 'prev_id' and k != 'id' and Story.column_names.include? k }
attribs = Hash[*attribs.flatten]
s = Story.new(attribs)
14 years ago
s.move_after(params['prev_id']) if s.save!
return s
end
def self.find_all_updated_since(since, project_id)
find(:all,
:conditions => ["project_id=(?) AND updated_on > ? AND tracker_id in (?)", project_id, since, trackers],
:order => "updated_on ASC")
end
def self.trackers
trackers = Setting.plugin_redmine_backlogs[:story_trackers]
return [] if trackers == '' or trackers.nil?
return trackers.map { |tracker| Integer(tracker) }
15 years ago
end
def move_after(prev_id)
14 years ago
# remove so the potential 'prev' has a correct position
remove_from_list
begin
prev = self.class.find(prev_id)
rescue ActiveRecord::RecordNotFound
prev = nil
end
# if it's the first story, move it to the 1st position
if prev.nil?
14 years ago
insert_at
move_to_top
# if its predecessor has no position (shouldn't happen), make it
# the last story
elsif !prev.in_list?
14 years ago
insert_at
move_to_bottom
# there's a valid predecessor
else
14 years ago
insert_at(prev.position + 1)
end
end
def set_points(p)
self.init_journal(User.current)
if p.nil? || p == '' || p == '-'
self.update_attribute(:story_points, nil)
return
end
if p.downcase == 's'
self.update_attribute(:story_points, 0)
return
end
p = Integer(p)
if p >= 0
self.update_attribute(:story_points, p)
return
end
end
def points_display(notsized='-')
# For reasons I have yet to uncover, activerecord will
# sometimes return numbers as Fixnums that lack the nil?
# method. Comparing to nil should be safe.
return notsized if story_points == nil
return 'S' if story_points == 0
return story_points.to_s
end
def task_status
closed = 0
open = 0
self.descendants.each {|task|
if task.closed?
closed += 1
else
open += 1
end
}
return {:open => open, :closed => closed}
end
def update_and_position!(params)
attribs = params.select{|k,v| k != 'id' and Story.column_names.include? k }
attribs = Hash[*attribs.flatten]
result = journalized_update_attributes! attribs
if result and params[:prev]
move_after(params[:prev])
end
result
end
15 years ago
end