diff --git a/app/models/user_story.rb b/app/models/user_story.rb index cc8c9c7b..b3146169 100644 --- a/app/models/user_story.rb +++ b/app/models/user_story.rb @@ -5,6 +5,7 @@ class UserStory < ActiveRecord::Base include ElasticSearchable include Formatters include SprintPlannable + include State mapping do indexes :id, index: :not_analyzed @@ -59,62 +60,6 @@ def stakeholder super.blank? ? person.try(:name) : super end - def status - cached_status = REDIS.get("user_story:#{self.id}:status") - unless cached_status - if self.inprogress? - cached_status = "inprogress" - elsif self.complete? - cached_status = "complete" - else - cached_status = "incomplete" - end - REDIS.set("user_story:#{self.id}:status", cached_status) - REDIS.expire("user_story:#{self.id}:status", REDIS_EXPIRY) - end - cached_status - end - - def inprogress? - if !tasks.blank? - tasks.each do |task| - return true if task.inprogress? - end - return false - else - return false - end - end - - def complete? - if !tasks.blank? - tasks.each do |task| - return false unless task.done? - end - return true - else - return false - end - end - - def state - cached_state = REDIS.get("user_story:#{self.id}:state") - unless cached_state - if self.cannot_be_estimated? - cached_state = 'clarify' - elsif self.acceptance_criteria.blank? - cached_state = 'criteria' - elsif self.story_points.blank? - cached_state = 'estimate' - else - cached_state = 'plan' - end - REDIS.set("user_story:#{self.id}:state", cached_state) - REDIS.expire("user_story:#{self.id}:state", REDIS_EXPIRY) - end - cached_state - end - def copy! us = clone_story! self.acceptance_criteria.each do |ac| @@ -138,18 +83,6 @@ def clone_story! new_us end - def expire_status - REDIS.del("user_story:#{self.id}:status") - end - - def expire_state - REDIS.del("user_story:#{self.id}:state") - end - - def expire_story_points - REDIS.del("project:#{self.project.id}:story_points") - end - def expire_sprint_story_points sprint.try(:expire_total_story_points) sprints.map(&:expire_total_story_points) diff --git a/app/models/user_story/state.rb b/app/models/user_story/state.rb new file mode 100644 index 00000000..f0dc9df3 --- /dev/null +++ b/app/models/user_story/state.rb @@ -0,0 +1,76 @@ +module UserStory::State + + # State on task board + # TODO: Redo for clarity + def status + cached_status = REDIS.get("user_story:#{self.id}:status") + unless cached_status + if self.inprogress? + cached_status = "inprogress" + elsif self.complete? + cached_status = "complete" + else + cached_status = "incomplete" + end + REDIS.set("user_story:#{self.id}:status", cached_status) + REDIS.expire("user_story:#{self.id}:status", REDIS_EXPIRY) + end + cached_status + end + + def inprogress? + if !tasks.blank? + tasks.each do |task| + return true if task.inprogress? + end + return false + else + return false + end + end + + def complete? + if !tasks.blank? + tasks.each do |task| + return false unless task.done? + end + return true + else + return false + end + end + + # State on backlog + # TODO: Redo for clarity + def state + cached_state = REDIS.get("user_story:#{self.id}:state") + unless cached_state + if self.cannot_be_estimated? + cached_state = 'clarify' + elsif self.acceptance_criteria.blank? + cached_state = 'criteria' + elsif self.story_points.blank? + cached_state = 'estimate' + else + cached_state = 'plan' + end + REDIS.set("user_story:#{self.id}:state", cached_state) + REDIS.expire("user_story:#{self.id}:state", REDIS_EXPIRY) + end + cached_state + end + + private + + def expire_status + REDIS.del("user_story:#{self.id}:status") + end + + def expire_state + REDIS.del("user_story:#{self.id}:state") + end + + def expire_story_points + REDIS.del("project:#{self.project.id}:story_points") + end +end