mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-03 07:48:50 +01:00
get tests running and fix editing context state
This commit is contained in:
parent
99eed9f638
commit
1e84adc91b
8 changed files with 27 additions and 17 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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)']
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
<%= text_field('context', 'name', :class => 'context-name', :tabindex => next_tab_index) %><br/>
|
||||
|
||||
<label for="context_hide"><%= t 'contexts.context_hide' %> </label>
|
||||
<%= 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}) %>
|
||||
<input type="hidden" name="wants_render" value="true" />
|
||||
|
||||
<div class="submit_box">
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@
|
|||
<%= text_field( "context", "name", :tabindex => next_tab_index ) %><br />
|
||||
|
||||
<label for="context_hide"><%= t 'contexts.context_hide' %></label>
|
||||
<%= check_box( "context", "hide", {:tabindex => next_tab_index} ) %><br />
|
||||
<%= check_box( "context_state", "hide", {:tabindex => next_tab_index} ) %><br />
|
||||
|
||||
<div class="submit_box">
|
||||
<div class="widgets">
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue