Fixing indentation and some code styles - no behavioral change intended

pull/6827/head
Gregor Schmidt 13 years ago
parent 80f4d630a2
commit 40798ce8a8
  1. 188
      app/models/sprint.rb

@ -1,22 +1,22 @@
require 'date' require 'date'
class Sprint < Version class Sprint < Version
unloadable unloadable
validate :start_and_end_dates validate :start_and_end_dates
named_scope :open_sprints, lambda { |project| named_scope :open_sprints, lambda { |project|
{ {
:order => 'start_date ASC, effective_date ASC', :order => 'start_date ASC, effective_date ASC',
:conditions => [ "versions.status = 'open' and versions.project_id = ?", project.id ] :conditions => [ "versions.status = 'open' and versions.project_id = ?", project.id ]
}
} }
}
named_scope :order_by_date, :order => 'start_date ASC, effective_date ASC' named_scope :order_by_date, :order => 'start_date ASC, effective_date ASC'
named_scope :order_by_name, :order => "#{Version.table_name}.name ASC" named_scope :order_by_name, :order => "#{Version.table_name}.name ASC"
named_scope :apply_to, lambda { |project| {:include => :project, named_scope :apply_to, lambda { |project| {:include => :project,
:conditions => ["#{Version.table_name}.project_id = #{project.id}" + :conditions => ["#{Version.table_name}.project_id = #{project.id}" +
" OR (#{Project.table_name}.status = #{Project::STATUS_ACTIVE} AND (" + " OR (#{Project.table_name}.status = #{Project::STATUS_ACTIVE} AND (" +
" #{Version.table_name}.sharing = 'system'" + " #{Version.table_name}.sharing = 'system'" +
" OR (#{Project.table_name}.lft >= #{project.root.lft} AND #{Project.table_name}.rgt <= #{project.root.rgt} AND #{Version.table_name}.sharing = 'tree')" + " OR (#{Project.table_name}.lft >= #{project.root.lft} AND #{Project.table_name}.rgt <= #{project.root.rgt} AND #{Version.table_name}.sharing = 'tree')" +
@ -24,116 +24,114 @@ class Sprint < Version
" OR (#{Project.table_name}.lft > #{project.lft} AND #{Project.table_name}.rgt < #{project.rgt} AND #{Version.table_name}.sharing = 'hierarchy')" + " OR (#{Project.table_name}.lft > #{project.lft} AND #{Project.table_name}.rgt < #{project.rgt} AND #{Version.table_name}.sharing = 'hierarchy')" +
"))"]}} "))"]}}
named_scope :displayed_left, lambda { |project| { :joins => sanitize_sql_array(["LEFT OUTER JOIN (SELECT * from #{VersionSetting.table_name}" + named_scope :displayed_left, lambda { |project| { :joins => sanitize_sql_array(["LEFT OUTER JOIN (SELECT * from #{VersionSetting.table_name}" +
" WHERE project_id = ? ) version_settings" + " WHERE project_id = ? ) version_settings" +
" ON version_settings.version_id = versions.id", " ON version_settings.version_id = versions.id",
project.id]), project.id]),
:conditions => ["(version_settings.project_id = ? AND version_settings.display = ?)" + :conditions => ["(version_settings.project_id = ? AND version_settings.display = ?)" +
" OR (version_settings.project_id is NULL)", " OR (version_settings.project_id is NULL)",
project.id, VersionSetting::DISPLAY_LEFT] } } project.id, VersionSetting::DISPLAY_LEFT] } }
named_scope :displayed_right, lambda { |project| { :include => :version_settings, named_scope :displayed_right, lambda { |project| {:include => :version_settings,
:conditions => ["version_settings.project_id = ? AND version_settings.display = ?", :conditions => ["version_settings.project_id = ? AND version_settings.display = ?",
project.id, VersionSetting::DISPLAY_RIGHT] } } project.id, VersionSetting::DISPLAY_RIGHT]} }
def stories(project, options = {} )
Story.sprint_backlog(project, self, options)
end
def points
stories.inject(0) { |sum, story| sum + story.story_points.to_i }
end
def stories(project, options = {} ) def has_wiki_page
Story.sprint_backlog(project, self, options) return false if wiki_page_title.blank?
end
def points page = project.wiki.find_page(self.wiki_page_title)
return stories.inject(0){|sum, story| sum + story.story_points.to_i} return false if !page
end
def has_wiki_page template = project.wiki.find_page(Setting.plugin_redmine_backlogs[:wiki_template])
return false if wiki_page_title.blank? return false if template && page.text == template.text
page = project.wiki.find_page(self.wiki_page_title) true
return false if !page end
template = project.wiki.find_page(Setting.plugin_redmine_backlogs[:wiki_template]) def wiki_page
return false if template && page.text == template.text return '' unless project.wiki
return true self.update_attribute(:wiki_page_title, Wiki.titleize(self.name)) if wiki_page_title.blank?
end
def wiki_page page = project.wiki.find_page(self.wiki_page_title)
if ! project.wiki template = project.wiki.find_page(Setting.plugin_redmine_backlogs[:wiki_template])
return ''
end
self.update_attribute(:wiki_page_title, Wiki.titleize(self.name)) if wiki_page_title.blank? if template and not page
page = project.wiki.pages.build(:title => self.wiki_page_title)
page.build_content(:text => "h1. #{self.name}\n\n#{template.text}")
page.save!
end
page = project.wiki.find_page(self.wiki_page_title) wiki_page_title
template = project.wiki.find_page(Setting.plugin_redmine_backlogs[:wiki_template]) end
if template and not page def days(cutoff = nil, alldays = false)
page = WikiPage.new(:wiki => project.wiki, :title => self.wiki_page_title) # assumes mon-fri are working days, sat-sun are not. this
page.content = WikiContent.new # assumption is not globally right, we need to make this configurable.
page.content.text = "h1. #{self.name}\n\n#{template.text}" cutoff = self.effective_date if cutoff.nil?
page.save!
end
return wiki_page_title (self.start_date .. cutoff).select {|d| alldays || (d.wday > 0 and d.wday < 6) }
end end
def days(cutoff = nil, alldays = false) def eta
# assumes mon-fri are working days, sat-sun are not. this return nil unless self.start_date
# assumption is not globally right, we need to make this configurable.
cutoff = self.effective_date if cutoff.nil?
return (self.start_date .. cutoff).select {|d| alldays || (d.wday > 0 and d.wday < 6) }
end
def eta dpp = self.project.scrum_statistics.info[:average_days_per_point]
return nil if ! self.start_date return nil unless dpp
dpp = self.project.scrum_statistics.info[:average_days_per_point] # assume 5 out of 7 are working days
return nil if !dpp self.start_date + Integer(self.points * dpp * 7.0/5)
end
# assume 5 out of 7 are working days def has_burndown?
return self.start_date + Integer(self.points * dpp * 7.0/5) !!(self.effective_date and self.start_date)
end end
def has_burndown? def activity
!!(self.effective_date and self.start_date) bd = self.burndown('up')
end return false if bd.blank?
def activity # assume a sprint is active if it's only 2 days old
bd = self.burndown('up') return true if bd.remaining_hours.size <= 2
return false if !bd
# assume a sprint is active if it's only 2 days old Issue.exists?(['fixed_version_id = ? and ((updated_on between ? and ?) or (created_on between ? and ?))',
return true if bd.remaining_hours.size <= 2 self.id, -2.days.from_now, Time.now, -2.days.from_now, Time.now])
end
return Issue.exists?(['fixed_version_id = ? and ((updated_on between ? and ?) or (created_on between ? and ?))', self.id, -2.days.from_now, Time.now, -2.days.from_now, Time.now]) def burndown(project, burn_direction = nil)
end return nil unless self.has_burndown?
def burndown(project, burn_direction = nil)
return nil if not self.has_burndown?
@cached_burndown ||= Burndown.new(self, project, burn_direction)
return @cached_burndown
end
def self.generate_burndown(only_current = true) @cached_burndown ||= Burndown.new(self, project, burn_direction)
if only_current end
conditions = ["? between start_date and effective_date", Date.today]
else
conditions = "1 = 1"
end
Version.find(:all, :conditions => conditions).each { |sprint| def self.generate_burndown(only_current = true)
sprint.burndown if only_current
} conditions = ["? BETWEEN start_date AND effective_date", Date.today]
else
conditions = "1 = 1"
end end
def impediments(project) Version.find(:all, :conditions => conditions).each { |sprint|
Impediment.find(:all, :conditions => {:fixed_version_id => self, :project_id => project}) sprint.burndown
end }
end
private def impediments(project)
def start_and_end_dates Impediment.find(:all, :conditions => {:fixed_version_id => self, :project_id => project})
errors.add_to_base(:cannot_end_before_it_starts) if self.effective_date && self.start_date && self.start_date >= self.effective_date end
end
private
def start_and_end_dates
if self.effective_date && self.start_date && self.start_date >= self.effective_date
errors.add_to_base(:cannot_end_before_it_starts)
end
end
end end

Loading…
Cancel
Save