diff --git a/app/controllers/contexts_controller.rb b/app/controllers/contexts_controller.rb index 1bf89264..54b78035 100644 --- a/app/controllers/contexts_controller.rb +++ b/app/controllers/contexts_controller.rb @@ -69,6 +69,7 @@ class ContextsController < ApplicationController return end @context = current_user.contexts.build(params['context']) + @context.hide! if params['context_state']['hide'] == '1' @saved = @context.save @context_not_done_counts = { @context.id => 0 } respond_to do |format| @@ -97,13 +98,22 @@ class ContextsController < ApplicationController @original_context_hidden = @context.hidden? @context.attributes = params["context"] + if params['context_state'] + if params['context_state']['hide'] == '1' + @context.hide! if !@context.hidden? + else + @context.activate! if @context.hidden? + end + else + @context.activate! if @context.hidden? + end @saved = @context.save if @saved if boolean_param('wants_render') @state_changed = (@original_context_hidden != @context.hidden?) - @new_state = (@context.hidden? ? "hidden" : "active") if @state_changed + @new_state = @context.state if @state_changed respond_to do |format| format.js end diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index d5d70478..cc0fe6cf 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -212,7 +212,7 @@ class StatsController < ApplicationController all_actions_per_context = current_user.contexts.find_by_sql( "SELECT c.name AS name, c.id as id, count(*) AS total "+ "FROM contexts c, todos t "+ - "WHERE t.context_id=c.id AND t.completed_at IS NULL AND NOT c.hide "+ + "WHERE t.context_id=c.id AND t.completed_at IS NULL AND NOT c.state='hidden' "+ "AND c.user_id = #{current_user.id} " + "GROUP BY c.name, c.id "+ "ORDER BY total DESC" @@ -491,7 +491,7 @@ class StatsController < ApplicationController @running_actions_per_context = current_user.contexts.find_by_sql( "SELECT c.id AS id, c.name AS name, count(*) AS total "+ "FROM contexts c, todos t "+ - "WHERE t.context_id=c.id AND t.completed_at IS NULL AND NOT c.hide "+ + "WHERE t.context_id=c.id AND t.completed_at IS NULL AND NOT c.state='hidden' "+ "AND t.user_id=#{current_user.id} " + "GROUP BY c.id, c.name ORDER BY total DESC " + "LIMIT 5" diff --git a/app/controllers/todos_controller.rb b/app/controllers/todos_controller.rb index cdd97c9b..acce9f47 100644 --- a/app/controllers/todos_controller.rb +++ b/app/controllers/todos_controller.rb @@ -692,7 +692,7 @@ class TodosController < ApplicationController @projects = current_user.projects @contexts = current_user.contexts - @contexts_to_show = @contexts.reject {|x| x.hide? } + @contexts_to_show = @contexts.reject {|c| c.hidden? } # Set defaults for new_action @initial_tags = @tag_name @@ -999,7 +999,7 @@ class TodosController < ApplicationController context_id = @original_item_context_id || @todo.context_id todos = current_user.contexts.find(context_id).todos.not_completed - if @todo.context.hide? + if @todo.context.hidden? # include hidden todos @down_count = todos.count else @@ -1063,12 +1063,12 @@ class TodosController < ApplicationController @remaining_deferred_or_pending_count = context.todos.deferred_or_blocked.count remaining_actions_in_context = context.todos(true).active - remaining_actions_in_context = remaining_actions_in_context.not_hidden if !context.hide? + remaining_actions_in_context = remaining_actions_in_context.not_hidden if !context.hidden? @remaining_in_context = remaining_actions_in_context.count if @todo_was_deferred_or_blocked actions_in_target = current_user.contexts.find(@todo.context_id).todos(true).active - actions_in_target = actions_in_target.not_hidden if !context.hide? + actions_in_target = actions_in_target.not_hidden if !context.hidden? else actions_in_target = @todo.context.todos.deferred_or_blocked end diff --git a/app/models/context.rb b/app/models/context.rb index dd78f9bc..dc3eee69 100644 --- a/app/models/context.rb +++ b/app/models/context.rb @@ -6,7 +6,7 @@ class Context < ActiveRecord::Base belongs_to :user scope :active, :conditions => { :state => :active } - scope :hidden, :conditions => { :state => :hide } + scope :hidden, :conditions => { :state => :hidden } acts_as_list :scope => :user, :top_of_list => 0 diff --git a/app/models/todo.rb b/app/models/todo.rb index 1628c15b..9f569b37 100644 --- a/app/models/todo.rb +++ b/app/models/todo.rb @@ -34,12 +34,12 @@ class Todo < ActiveRecord::Base scope :not_deferred_or_blocked, :conditions => ["(NOT todos.state=?) AND (NOT todos.state = ?)", "deferred", "pending"] scope :hidden, :joins => "INNER JOIN contexts c_hidden ON c_hidden.id = todos.context_id", - :conditions => ["todos.state = ? OR (c_hidden.hide = ? AND (todos.state = ? OR todos.state = ? OR todos.state = ?))", - 'project_hidden', true, 'active', 'deferred', 'pending'] + :conditions => ["todos.state = ? OR (c_hidden.state = ? AND (todos.state = ? OR todos.state = ? OR todos.state = ?))", + 'project_hidden', 'hidden', 'active', 'deferred', 'pending'] scope :not_hidden, :joins => "INNER JOIN contexts c_hidden ON c_hidden.id = todos.context_id", - :conditions => ['NOT(todos.state = ? OR (c_hidden.hide = ? AND (todos.state = ? OR todos.state = ? OR todos.state = ?)))', - 'project_hidden', true, 'active', 'deferred', 'pending'] + :conditions => ['NOT(todos.state = ? OR (c_hidden.state = ? AND (todos.state = ? OR todos.state = ? OR todos.state = ?)))', + 'project_hidden', 'hidden', 'active', 'deferred', 'pending'] # other scopes scope :are_due, :conditions => ['NOT (todos.due IS NULL)'] diff --git a/app/views/contexts/_context_form.html.erb b/app/views/contexts/_context_form.html.erb index 228be0c8..18f1a10c 100644 --- a/app/views/contexts/_context_form.html.erb +++ b/app/views/contexts/_context_form.html.erb @@ -13,7 +13,7 @@ <%= text_field('context', 'name', :class => 'context-name', :tabindex => next_tab_index) %>
- <%= check_box('context', 'hide', {:class => 'context-hide', :tabindex => next_tab_index}) %> + <%= check_box_tag('context_state[hide]', 1, context.hidden?, {:class => 'context-hide', :tabindex => next_tab_index}) %>
diff --git a/app/views/contexts/_new_context_form.html.erb b/app/views/contexts/_new_context_form.html.erb index 92fd8c20..d32a6336 100644 --- a/app/views/contexts/_new_context_form.html.erb +++ b/app/views/contexts/_new_context_form.html.erb @@ -22,7 +22,7 @@ <%= text_field( "context", "name", :tabindex => next_tab_index ) %>
- <%= check_box( "context", "hide", {:tabindex => next_tab_index} ) %>
+ <%= check_box( "context_state", "hide", {:tabindex => next_tab_index} ) %>
diff --git a/features/step_definitions/context_steps.rb b/features/step_definitions/context_steps.rb index 9f0e6bdd..d9f5ae82 100644 --- a/features/step_definitions/context_steps.rb +++ b/features/step_definitions/context_steps.rb @@ -6,7 +6,7 @@ end Given /^there exists an active context called "([^"]*)" for user "([^"]*)"$/ do |context_name, login| user = User.where(:login => login).first user.should_not be_nil - @context = user.contexts.where(:name => context_name, :hide => false).first_or_create + @context = user.contexts.where(:name => context_name, :state => 'active').first_or_create end Given /^there exists a context called "([^"]*)" for user "([^"]*)"$/ do |context_name, login| @@ -16,7 +16,7 @@ end Given /^there exists a hidden context called "([^"]*)" for user "([^"]*)"$/ do |context_name, login| user = User.where(:login => login).first user.should_not be_nil - @context = user.contexts.create!(:name => context_name, :hide => true) + @context = user.contexts.create!(:name => context_name, :state => 'hidden') end Given /^I have a context called "([^\"]*)"$/ do |context_name| @@ -34,7 +34,7 @@ end Given /^I have the following contexts:$/ do |table| table.hashes.each do |context| step 'I have a context called "'+context[:context]+'"' - @context.hide = context[:hide] == "true" unless context[:hide].blank? + @context.state = (context[:hide] == "true") ? 'hidden' : 'active' unless context[:hide].blank? # acts_as_list puts the last added context at the top, but we want it # at the bottom to be consistent with the table in the scenario @context.move_to_bottom