mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-16 23:30:12 +01:00
Remove 'project_hidden' state
Compute it using project/context state Notable change: todo.hidden? now also returns true if the todo is completed
This commit is contained in:
parent
543f49ed8a
commit
ed3bca22a4
12 changed files with 66 additions and 106 deletions
|
|
@ -75,7 +75,9 @@ class ApplicationController < ActionController::Base
|
||||||
if todos_parent.nil?
|
if todos_parent.nil?
|
||||||
count = 0
|
count = 0
|
||||||
elsif (todos_parent.is_a?(Project) && todos_parent.hidden?)
|
elsif (todos_parent.is_a?(Project) && todos_parent.hidden?)
|
||||||
count = @project_project_hidden_todo_counts[todos_parent.id]
|
count = @project_hidden_todo_counts[todos_parent.id]
|
||||||
|
elsif (todos_parent.is_a?(Context) && todos_parent.hidden?)
|
||||||
|
count = @context_hidden_todo_counts[todos_parent.id]
|
||||||
else
|
else
|
||||||
count = eval "@#{todos_parent.class.to_s.downcase}_not_done_counts[#{todos_parent.id}]"
|
count = eval "@#{todos_parent.class.to_s.downcase}_not_done_counts[#{todos_parent.id}]"
|
||||||
end
|
end
|
||||||
|
|
@ -200,7 +202,10 @@ class ApplicationController < ActionController::Base
|
||||||
|
|
||||||
init_not_done_counts
|
init_not_done_counts
|
||||||
if prefs.show_hidden_projects_in_sidebar
|
if prefs.show_hidden_projects_in_sidebar
|
||||||
init_project_hidden_todo_counts(['project'])
|
init_hidden_todo_counts(['project'])
|
||||||
|
end
|
||||||
|
if prefs.show_hidden_contexts_in_sidebar
|
||||||
|
init_hidden_todo_counts(['context'])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -211,9 +216,9 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def init_project_hidden_todo_counts(parents = ['project','context'])
|
def init_hidden_todo_counts(parents = ['project', 'context'])
|
||||||
parents.each do |parent|
|
parents.each do |parent|
|
||||||
eval("@#{parent}_project_hidden_todo_counts ||= current_user.todos.active_or_hidden.count_by_group('#{parent}_id')")
|
eval("@#{parent}_hidden_todo_counts ||= current_user.todos.active_or_hidden.count_by_group('#{parent}_id')")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,10 @@ class ContextsController < ApplicationController
|
||||||
@active_contexts = current_user.contexts.active
|
@active_contexts = current_user.contexts.active
|
||||||
@hidden_contexts = current_user.contexts.hidden
|
@hidden_contexts = current_user.contexts.hidden
|
||||||
@closed_contexts = current_user.contexts.closed
|
@closed_contexts = current_user.contexts.closed
|
||||||
init_not_done_counts(['context']) unless request.format == :autocomplete
|
unless request.format == :autocomplete
|
||||||
|
init_not_done_counts(['context'])
|
||||||
|
init_hidden_todo_counts(['context'])
|
||||||
|
end
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html &render_contexts_html
|
format.html &render_contexts_html
|
||||||
|
|
@ -37,7 +40,7 @@ class ContextsController < ApplicationController
|
||||||
unless @context.nil?
|
unless @context.nil?
|
||||||
@max_completed = current_user.prefs.show_number_completed
|
@max_completed = current_user.prefs.show_number_completed
|
||||||
@done = @context.todos.completed.limit(@max_completed).reorder("todos.completed_at DESC, todos.created_at DESC").includes(Todo::DEFAULT_INCLUDES)
|
@done = @context.todos.completed.limit(@max_completed).reorder("todos.completed_at DESC, todos.created_at DESC").includes(Todo::DEFAULT_INCLUDES)
|
||||||
@not_done_todos = @context.todos.active.reorder("todos.due IS NULL, todos.due ASC, todos.created_at ASC").includes(Todo::DEFAULT_INCLUDES)
|
@not_done_todos = @context.todos.active_or_hidden.not_project_hidden.reorder('todos.due IS NULL, todos.due ASC, todos.created_at ASC').includes(Todo::DEFAULT_INCLUDES)
|
||||||
@todos_without_project = @not_done_todos.select{|t| t.project.nil?}
|
@todos_without_project = @not_done_todos.select{|t| t.project.nil?}
|
||||||
|
|
||||||
@deferred_todos = @context.todos.deferred.includes(Todo::DEFAULT_INCLUDES)
|
@deferred_todos = @context.todos.deferred.includes(Todo::DEFAULT_INCLUDES)
|
||||||
|
|
@ -77,6 +80,7 @@ class ContextsController < ApplicationController
|
||||||
format.js do
|
format.js do
|
||||||
@down_count = current_user.contexts.size
|
@down_count = current_user.contexts.size
|
||||||
init_not_done_counts
|
init_not_done_counts
|
||||||
|
init_hidden_todo_counts(['context'])
|
||||||
end
|
end
|
||||||
format.xml do
|
format.xml do
|
||||||
if @context.new_record?
|
if @context.new_record?
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ class ProjectsController < ApplicationController
|
||||||
else
|
else
|
||||||
@contexts = current_user.contexts
|
@contexts = current_user.contexts
|
||||||
init_not_done_counts(['project'])
|
init_not_done_counts(['project'])
|
||||||
init_project_hidden_todo_counts(['project'])
|
init_hidden_todo_counts(['project'])
|
||||||
if params[:only_active_with_no_next_actions]
|
if params[:only_active_with_no_next_actions]
|
||||||
@projects = current_user.projects.active.select { |p| count_undone_todos(p) == 0 }
|
@projects = current_user.projects.active.select { |p| count_undone_todos(p) == 0 }
|
||||||
else
|
else
|
||||||
|
|
@ -64,7 +64,7 @@ class ProjectsController < ApplicationController
|
||||||
@current_projects = projects.uncompleted.select { |p| not (p.needs_review?(current_user)) }.sort_by { |p| p.last_reviewed || Time.zone.at(0) }
|
@current_projects = projects.uncompleted.select { |p| not (p.needs_review?(current_user)) }.sort_by { |p| p.last_reviewed || Time.zone.at(0) }
|
||||||
|
|
||||||
init_not_done_counts(['project'])
|
init_not_done_counts(['project'])
|
||||||
init_project_hidden_todo_counts(['project'])
|
init_hidden_todo_counts(['project'])
|
||||||
current_user.projects.cache_note_counts
|
current_user.projects.cache_note_counts
|
||||||
|
|
||||||
@page_title = t('projects.list_reviews')
|
@page_title = t('projects.list_reviews')
|
||||||
|
|
@ -220,7 +220,7 @@ class ProjectsController < ApplicationController
|
||||||
@contexts = current_user.contexts
|
@contexts = current_user.contexts
|
||||||
update_state_counts
|
update_state_counts
|
||||||
init_data_for_sidebar
|
init_data_for_sidebar
|
||||||
init_project_hidden_todo_counts(['project'])
|
init_hidden_todo_counts(['project'])
|
||||||
|
|
||||||
template = 'projects/update'
|
template = 'projects/update'
|
||||||
|
|
||||||
|
|
@ -292,7 +292,7 @@ class ProjectsController < ApplicationController
|
||||||
@projects = current_user.projects.alphabetize(:state => @state) if @state
|
@projects = current_user.projects.alphabetize(:state => @state) if @state
|
||||||
@contexts = current_user.contexts
|
@contexts = current_user.contexts
|
||||||
init_not_done_counts(['project'])
|
init_not_done_counts(['project'])
|
||||||
init_project_hidden_todo_counts(['project']) if @state == 'hidden'
|
init_hidden_todo_counts(['project']) if @state == 'hidden'
|
||||||
end
|
end
|
||||||
|
|
||||||
def actionize
|
def actionize
|
||||||
|
|
@ -300,7 +300,7 @@ class ProjectsController < ApplicationController
|
||||||
@projects = current_user.projects.actionize(:state => @state) if @state
|
@projects = current_user.projects.actionize(:state => @state) if @state
|
||||||
@contexts = current_user.contexts
|
@contexts = current_user.contexts
|
||||||
init_not_done_counts(['project'])
|
init_not_done_counts(['project'])
|
||||||
init_project_hidden_todo_counts(['project']) if @state == 'hidden'
|
init_hidden_todo_counts(['project']) if @state == 'hidden'
|
||||||
end
|
end
|
||||||
|
|
||||||
def done_todos
|
def done_todos
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ class SearchController < ApplicationController
|
||||||
@count = searcher.number_of_finds
|
@count = searcher.number_of_finds
|
||||||
|
|
||||||
init_not_done_counts
|
init_not_done_counts
|
||||||
init_project_hidden_todo_counts
|
init_hidden_todo_counts
|
||||||
end
|
end
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
|
|
||||||
|
|
@ -99,8 +99,7 @@ class TodosController < ApplicationController
|
||||||
@todo.add_predecessor_list(p.predecessor_list)
|
@todo.add_predecessor_list(p.predecessor_list)
|
||||||
@saved = @todo.save
|
@saved = @todo.save
|
||||||
@todo.tag_with(tag_list) if @saved && tag_list.present?
|
@todo.tag_with(tag_list) if @saved && tag_list.present?
|
||||||
@todo.update_state_from_project if @saved
|
@todo.block! if @todo.uncompleted_predecessors?
|
||||||
@todo.block! if @todo.should_be_blocked?
|
|
||||||
else
|
else
|
||||||
@saved = false
|
@saved = false
|
||||||
end
|
end
|
||||||
|
|
@ -448,7 +447,9 @@ class TodosController < ApplicationController
|
||||||
@todo.reload # refresh context and project object too (not only their id's)
|
@todo.reload # refresh context and project object too (not only their id's)
|
||||||
|
|
||||||
update_dependency_state
|
update_dependency_state
|
||||||
update_todo_state_if_project_changed
|
if @project_changed
|
||||||
|
@remaining_undone_in_project = current_user.projects.find(@original_item_project_id).todos.active.count if source_view_is :project
|
||||||
|
end
|
||||||
|
|
||||||
determine_changes_by_this_update
|
determine_changes_by_this_update
|
||||||
determine_remaining_in_container_count( (@context_changed || @project_changed) ? @original_item : @todo)
|
determine_remaining_in_container_count( (@context_changed || @project_changed) ? @original_item : @todo)
|
||||||
|
|
@ -588,7 +589,7 @@ class TodosController < ApplicationController
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html do
|
format.html do
|
||||||
init_not_done_counts
|
init_not_done_counts
|
||||||
init_project_hidden_todo_counts
|
init_hidden_todo_counts
|
||||||
init_data_for_sidebar unless mobile?
|
init_data_for_sidebar unless mobile?
|
||||||
end
|
end
|
||||||
format.m
|
format.m
|
||||||
|
|
@ -1189,12 +1190,6 @@ end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_todo_state_if_project_changed
|
|
||||||
if @project_changed
|
|
||||||
@todo.update_state_from_project
|
|
||||||
@remaining_undone_in_project = current_user.projects.find(@original_item_project_id).todos.active.count if source_view_is :project
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def update_context
|
def update_context
|
||||||
@context_changed = false
|
@context_changed = false
|
||||||
|
|
|
||||||
|
|
@ -442,21 +442,11 @@ module TodosHelper
|
||||||
# === handle CRUD actions for todos
|
# === handle CRUD actions for todos
|
||||||
|
|
||||||
def show_todo_on_current_context_page
|
def show_todo_on_current_context_page
|
||||||
return @todo.context_id==@default_context.id
|
@todo.context_id == @default_context.id && (!@todo.hidden? || @todo.context.hidden?)
|
||||||
end
|
|
||||||
|
|
||||||
def todo_should_not_be_hidden_on_context_page
|
|
||||||
return !@todo.hidden? || # todo is not hidden --> show
|
|
||||||
(@todo.hidden? && @todo.context.hidden?) # todo is hidden, but context is hidden too --> show
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def show_todo_on_current_project_page
|
def show_todo_on_current_project_page
|
||||||
return @todo.project.id == @default_project.id
|
@todo.project.id == @default_project.id && (!@todo.hidden? || @todo.project.hidden?)
|
||||||
end
|
|
||||||
|
|
||||||
def todo_should_not_be_hidden_on_project_page
|
|
||||||
return !@todo.hidden? ||
|
|
||||||
(@todo.project_hidden? && @todo.project.hidden?)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def should_show_new_item(todo = @todo)
|
def should_show_new_item(todo = @todo)
|
||||||
|
|
@ -464,9 +454,9 @@ module TodosHelper
|
||||||
source_view do |page|
|
source_view do |page|
|
||||||
page.todo { return !todo.hidden? && !todo.deferred? }
|
page.todo { return !todo.hidden? && !todo.deferred? }
|
||||||
page.deferred { return todo.deferred? || todo.pending? }
|
page.deferred { return todo.deferred? || todo.pending? }
|
||||||
page.context { return show_todo_on_current_context_page && todo_should_not_be_hidden_on_context_page }
|
|
||||||
page.tag { return todo.has_tag?(@tag_name) }
|
page.tag { return todo.has_tag?(@tag_name) }
|
||||||
page.project { return show_todo_on_current_project_page && todo_should_not_be_hidden_on_project_page }
|
page.context { return show_todo_on_current_context_page }
|
||||||
|
page.project { return show_todo_on_current_project_page }
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ class Project < ActiveRecord::Base
|
||||||
aasm :column => :state do
|
aasm :column => :state do
|
||||||
|
|
||||||
state :active, :initial => true
|
state :active, :initial => true
|
||||||
state :hidden, :enter => :hide_todos, :exit => :unhide_todos
|
state :hidden
|
||||||
state :completed, :enter => :set_completed_at_date, :exit => :clear_completed_at_date
|
state :completed, :enter => :set_completed_at_date, :exit => :clear_completed_at_date
|
||||||
|
|
||||||
event :activate do
|
event :activate do
|
||||||
|
|
@ -53,24 +53,6 @@ class Project < ActiveRecord::Base
|
||||||
self.last_reviewed = Time.now
|
self.last_reviewed = Time.now
|
||||||
end
|
end
|
||||||
|
|
||||||
def hide_todos
|
|
||||||
todos.each do |t|
|
|
||||||
unless t.completed? || t.deferred?
|
|
||||||
t.hide!
|
|
||||||
t.save
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def unhide_todos
|
|
||||||
todos.each do |t|
|
|
||||||
if t.project_hidden?
|
|
||||||
t.unhide!
|
|
||||||
t.save
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def set_completed_at_date
|
def set_completed_at_date
|
||||||
self.completed_at = Time.zone.now
|
self.completed_at = Time.zone.now
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -26,21 +26,25 @@ class Todo < ActiveRecord::Base
|
||||||
has_many :attachments, dependent: :destroy
|
has_many :attachments, dependent: :destroy
|
||||||
|
|
||||||
# scopes for states of this todo
|
# scopes for states of this todo
|
||||||
scope :active, -> { where state: 'active' }
|
scope :active, -> { active_or_hidden.not_hidden }
|
||||||
scope :active_or_hidden, -> { where "todos.state = ? OR todos.state = ?", 'active', 'project_hidden' }
|
scope :active_or_hidden, -> { where state: 'active' }
|
||||||
scope :not_completed, -> { where 'NOT (todos.state = ?)', 'completed' }
|
scope :context_hidden, -> { joins('INNER JOIN contexts c ON c.id = todos.context_id').where('c.state = ?', 'hidden') }
|
||||||
scope :completed, -> { where "todos.state = ?", 'completed' }
|
scope :project_hidden, -> { joins('LEFT OUTER JOIN projects p ON p.id = todos.project_id').where('p.state = ?', 'hidden') }
|
||||||
scope :deferred, -> { where "todos.state = ?", 'deferred' }
|
scope :completed, -> { where 'todos.state = ?', 'completed' }
|
||||||
|
scope :deferred, -> { where 'todos.state = ?', 'deferred' }
|
||||||
scope :blocked, -> {where 'todos.state = ?', 'pending' }
|
scope :blocked, -> {where 'todos.state = ?', 'pending' }
|
||||||
scope :pending, -> {where 'todos.state = ?', 'pending' }
|
scope :pending, -> {where 'todos.state = ?', 'pending' }
|
||||||
scope :deferred_or_blocked, -> { where "(todos.state = ?) OR (todos.state = ?)", "deferred", "pending" }
|
scope :deferred_or_blocked, -> { where '(todos.state = ?) OR (todos.state = ?)', 'deferred', 'pending' }
|
||||||
scope :not_deferred_or_blocked, -> { where "(NOT todos.state=?) AND (NOT todos.state = ?)", "deferred", "pending" }
|
|
||||||
scope :hidden, -> {
|
scope :hidden, -> {
|
||||||
joins("INNER JOIN contexts c_hidden ON c_hidden.id = todos.context_id").
|
joins('INNER JOIN contexts c_hidden ON c_hidden.id = todos.context_id').
|
||||||
where("todos.state = ? OR (c_hidden.state = ? AND (todos.state = ? OR todos.state = ? OR todos.state = ?))", 'project_hidden', 'hidden', 'active', 'deferred', 'pending') }
|
joins('LEFT OUTER JOIN projects p_hidden ON p_hidden.id = todos.project_id').
|
||||||
scope :not_hidden, -> {
|
where('(c_hidden.state = ? OR p_hidden.state = ?)', 'hidden', 'hidden').
|
||||||
joins("INNER JOIN contexts c_hidden ON c_hidden.id = todos.context_id").
|
where('NOT todos.state = ?', 'completed') }
|
||||||
where('NOT(todos.state = ? OR (c_hidden.state = ? AND (todos.state = ? OR todos.state = ? OR todos.state = ?)))','project_hidden', 'hidden', 'active', 'deferred', 'pending') }
|
scope :not_hidden, -> { not_context_hidden.not_project_hidden }
|
||||||
|
scope :not_deferred_or_blocked, -> { where '(NOT todos.state=?) AND (NOT todos.state = ?)', 'deferred', 'pending' }
|
||||||
|
scope :not_project_hidden, -> { joins('LEFT OUTER JOIN projects p ON p.id = todos.project_id').where('p.id IS NULL OR NOT(p.state = ?)', 'hidden') }
|
||||||
|
scope :not_context_hidden, -> { joins('INNER JOIN contexts c ON c.id = todos.context_id').where('NOT(c.state = ?)', 'hidden') }
|
||||||
|
scope :not_completed, -> { where 'NOT (todos.state = ?)', 'completed' }
|
||||||
|
|
||||||
# other scopes
|
# other scopes
|
||||||
scope :are_due, -> { where 'NOT (todos.due IS NULL)' }
|
scope :are_due, -> { where 'NOT (todos.due IS NULL)' }
|
||||||
|
|
@ -71,7 +75,6 @@ class Todo < ActiveRecord::Base
|
||||||
aasm :column => :state do
|
aasm :column => :state do
|
||||||
|
|
||||||
state :active
|
state :active
|
||||||
state :project_hidden
|
|
||||||
state :completed, :before_enter => Proc.new { |t| t.completed_at = Time.zone.now }, :before_exit => Proc.new { |t| t.completed_at = nil}
|
state :completed, :before_enter => Proc.new { |t| t.completed_at = Time.zone.now }, :before_exit => Proc.new { |t| t.completed_at = nil}
|
||||||
state :deferred, :before_exit => Proc.new { |t| t[:show_from] = nil }
|
state :deferred, :before_exit => Proc.new { |t| t[:show_from] = nil }
|
||||||
state :pending
|
state :pending
|
||||||
|
|
@ -81,29 +84,19 @@ class Todo < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
event :complete do
|
event :complete do
|
||||||
transitions :to => :completed, :from => [:active, :project_hidden, :deferred, :pending]
|
transitions :to => :completed, :from => [:active, :deferred, :pending]
|
||||||
end
|
end
|
||||||
|
|
||||||
event :activate do
|
event :activate do
|
||||||
transitions :to => :active, :from => [:project_hidden, :deferred]
|
transitions :to => :active, :from => [:deferred]
|
||||||
transitions :to => :active, :from => [:completed], :guard => :no_uncompleted_predecessors?
|
transitions :to => :active, :from => [:completed], :guard => :no_uncompleted_predecessors?
|
||||||
transitions :to => :active, :from => [:pending], :guard => :no_uncompleted_predecessors_or_deferral?
|
transitions :to => :active, :from => [:pending], :guard => :no_uncompleted_predecessors_or_deferral?
|
||||||
transitions :to => :pending, :from => [:completed], :guard => :uncompleted_predecessors?
|
transitions :to => :pending, :from => [:completed], :guard => :uncompleted_predecessors?
|
||||||
transitions :to => :deferred, :from => [:pending], :guard => :no_uncompleted_predecessors?
|
transitions :to => :deferred, :from => [:pending], :guard => :no_uncompleted_predecessors?
|
||||||
end
|
end
|
||||||
|
|
||||||
event :hide do
|
|
||||||
transitions :to => :project_hidden, :from => [:active, :deferred, :pending]
|
|
||||||
end
|
|
||||||
|
|
||||||
event :unhide do
|
|
||||||
transitions :to => :deferred, :from => [:project_hidden], :guard => Proc.new{|t| t.show_from.present? }
|
|
||||||
transitions :to => :pending, :from => [:project_hidden], :guard => :uncompleted_predecessors?
|
|
||||||
transitions :to => :active, :from => [:project_hidden]
|
|
||||||
end
|
|
||||||
|
|
||||||
event :block do
|
event :block do
|
||||||
transitions :to => :pending, :from => [:active, :deferred, :project_hidden]
|
transitions :to => :pending, :from => [:active, :deferred]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -143,10 +136,6 @@ class Todo < ActiveRecord::Base
|
||||||
return !uncompleted_predecessors.empty?
|
return !uncompleted_predecessors.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
def should_be_blocked?
|
|
||||||
return !( uncompleted_predecessors.empty? || state == 'project_hidden' )
|
|
||||||
end
|
|
||||||
|
|
||||||
def guard_for_transition_from_deferred_to_pending
|
def guard_for_transition_from_deferred_to_pending
|
||||||
no_uncompleted_predecessors? && not_part_of_hidden_container?
|
no_uncompleted_predecessors? && not_part_of_hidden_container?
|
||||||
end
|
end
|
||||||
|
|
@ -199,7 +188,7 @@ class Todo < ActiveRecord::Base
|
||||||
self.predecessors.delete(predecessor)
|
self.predecessors.delete(predecessor)
|
||||||
if self.predecessors.empty?
|
if self.predecessors.empty?
|
||||||
self.reload # reload predecessors
|
self.reload # reload predecessors
|
||||||
self.not_part_of_hidden_container? ? self.activate! : self.hide!
|
self.activate!
|
||||||
else
|
else
|
||||||
save!
|
save!
|
||||||
end
|
end
|
||||||
|
|
@ -226,20 +215,7 @@ class Todo < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def hidden?
|
def hidden?
|
||||||
return self.project_hidden? || ( self.context.hidden? && (self.active? || self.deferred?))
|
self.project.hidden? || self.context.hidden?
|
||||||
end
|
|
||||||
|
|
||||||
def update_state_from_project
|
|
||||||
if self.project_hidden? && (!self.project.hidden?)
|
|
||||||
if self.uncompleted_predecessors.empty?
|
|
||||||
self.activate!
|
|
||||||
else
|
|
||||||
self.block!
|
|
||||||
end
|
|
||||||
elsif self.active? && self.project.hidden?
|
|
||||||
self.hide!
|
|
||||||
end
|
|
||||||
self.save!
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def toggle_completion!
|
def toggle_completion!
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,16 @@ class ContextsControllerTest < ActionController::TestCase
|
||||||
assert_equal 'TRACKS::Context: agenda', assigns['page_title']
|
assert_equal 'TRACKS::Context: agenda', assigns['page_title']
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_shows_todos_when_hidden
|
||||||
|
c = contexts(:agenda)
|
||||||
|
todos = c.todos.active
|
||||||
|
assert_equal 6, todos.size
|
||||||
|
c.hide!
|
||||||
|
login_as :admin_user
|
||||||
|
get :show, { :id => '1'}
|
||||||
|
assert_equal 6, assigns['not_done_todos'].size
|
||||||
|
end
|
||||||
|
|
||||||
def test_show_renders_show_template
|
def test_show_renders_show_template
|
||||||
login_as :admin_user
|
login_as :admin_user
|
||||||
get :show, { :id => "1" }
|
get :show, { :id => "1" }
|
||||||
|
|
|
||||||
|
|
@ -52,13 +52,13 @@ class ProjectsControllerTest < ActionController::TestCase
|
||||||
assert_ajax_create_increments_count 'My New Project'
|
assert_ajax_create_increments_count 'My New Project'
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_todo_state_is_project_hidden_after_hiding_project
|
def test_todo_is_hidden_after_hiding_project
|
||||||
p = projects(:timemachine)
|
p = projects(:timemachine)
|
||||||
todos = p.todos.active
|
todos = p.todos.active
|
||||||
login_as(:admin_user)
|
login_as(:admin_user)
|
||||||
xhr :post, :update, :id => 1, "project"=>{"name"=>p.name, "description"=>p.description, "state"=>"hidden"}
|
xhr :post, :update, :id => 1, "project"=>{"name"=>p.name, "description"=>p.description, "state"=>"hidden"}
|
||||||
todos.each do |t|
|
todos.each do |t|
|
||||||
assert_equal :project_hidden, t.reload().aasm.current_state
|
assert t.reload().hidden?
|
||||||
end
|
end
|
||||||
assert p.reload().hidden?
|
assert p.reload().hidden?
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -381,7 +381,7 @@ class TodosControllerTest < ActionController::TestCase
|
||||||
assert p.reload().hidden?
|
assert p.reload().hidden?
|
||||||
todo = p.todos.first
|
todo = p.todos.first
|
||||||
|
|
||||||
assert todo.project_hidden?, "todo should be project_hidden"
|
assert todo.hidden?, 'todo should be hidden'
|
||||||
|
|
||||||
# clear project from todo: the todo should be unhidden
|
# clear project from todo: the todo should be unhidden
|
||||||
xhr :post, :update, :id => todo.id, :_source_view => 'todo', "project_name"=>"", "todo"=>{}
|
xhr :post, :update, :id => todo.id, :_source_view => 'todo', "project_name"=>"", "todo"=>{}
|
||||||
|
|
|
||||||
|
|
@ -216,8 +216,6 @@ class TodoTest < ActiveSupport::TestCase
|
||||||
new_todo = @not_completed1.user.todos.build(description: "test", context: @not_completed1.context, project: project)
|
new_todo = @not_completed1.user.todos.build(description: "test", context: @not_completed1.context, project: project)
|
||||||
new_todo.save!
|
new_todo.save!
|
||||||
assert new_todo.active?
|
assert new_todo.active?
|
||||||
# And I update the state of the todo from its project
|
|
||||||
new_todo.update_state_from_project
|
|
||||||
# Then the todo should be hidden
|
# Then the todo should be hidden
|
||||||
assert new_todo.hidden?
|
assert new_todo.hidden?
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue