add ui for changing state of context to closed. This fixes #645

This commit is contained in:
Reinier Balt 2013-03-01 16:20:15 +01:00
parent acab98d4c7
commit 4df340bd7b
12 changed files with 114 additions and 86 deletions

View file

@ -783,16 +783,24 @@ var ContextListPage = {
update_state_count: function(state, count) {
$('#'+state+'-contexts-count').html(count);
},
update_all_states_count: function (active_count, hidden_count, completed_count) {
$(["active", "hidden"]).each(function() {
update_all_states_count: function (active_count, hidden_count, closed_count) {
$(["active", "hidden", "closed"]).each(function() {
ContextListPage.update_state_count(this, eval(this+'_count'));
});
},
show_or_hide_all_state_containers: function (show_active, show_hidden, show_completed) {
$(["active", "hidden"]).each(function() {
show_or_hide_all_state_containers: function (show_active, show_hidden, show_closed) {
$(["active", "hidden", "closed"]).each(function() {
ContextListPage.set_state_container_visibility(this, eval('show_'+this));
ContextListPage.hide_empty_message(this, !eval('show_'+this));
});
},
hide_empty_message: function(state, set_visible) {
if(set_visible) {
$('div#'+state+'-contexts-empty-nd').slideDown("fast");
} else {
$('div#'+state+'-contexts-empty-nd').slideUp("fast");
}
},
set_state_container_visibility: function (state, set_visible) {
if (set_visible) {
$('#list-'+state+'-contexts-container').slideDown("fast");

View file

@ -11,6 +11,7 @@ class ContextsController < ApplicationController
@all_contexts = current_user.contexts
@active_contexts = current_user.contexts.active
@hidden_contexts = current_user.contexts.hidden
@closed_contexts = current_user.contexts.closed
init_not_done_counts(['context']) unless request.format == :autocomplete
respond_to do |format|
@ -96,24 +97,17 @@ class ContextsController < ApplicationController
params['context']['name'] = params['value']
end
@original_context_hidden = @context.hidden?
@original_context_state = @context.state
@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?)
@state_changed = (@original_context_state != @context.state)
@new_state = @context.state if @state_changed
@active_contexts = current_user.contexts.active
@hidden_contexts = current_user.contexts.hidden
@closed_contexts = current_user.contexts.closed
respond_to do |format|
format.js
end
@ -202,8 +196,10 @@ class ContextsController < ApplicationController
def update_state_counts
@active_contexts_count = current_user.contexts.active.count
@hidden_contexts_count = current_user.contexts.hidden.count
@closed_contexts_count = current_user.contexts.closed.count
@show_active_contexts = @active_contexts_count > 0
@show_hidden_contexts = @hidden_contexts_count > 0
@show_closed_contexts = @closed_contexts_count > 0
end
def render_contexts_html
@ -211,9 +207,11 @@ class ContextsController < ApplicationController
@page_title = "TRACKS::List Contexts"
@no_active_contexts = @active_contexts.empty?
@no_hidden_contexts = @hidden_contexts.empty?
@no_closed_contexts = @closed_contexts.empty?
@active_count = @active_contexts.size
@hidden_count = @hidden_contexts.size
@count = @active_count + @hidden_count
@closed_count = @closed_contexts.size
@count = @active_count + @hidden_count + @closed_count
@new_context = current_user.contexts.build
render

View file

@ -7,6 +7,7 @@ class Context < ActiveRecord::Base
scope :active, :conditions => { :state => :active }
scope :hidden, :conditions => { :state => :hidden }
scope :closed, :conditions => { :state => :closed }
acts_as_list :scope => :user, :top_of_list => 0

View file

@ -12,8 +12,11 @@
<label for="context_name"><%= t 'contexts.context_name' %></label><br/>
<%= text_field('context', 'name', :class => 'context-name', :tabindex => next_tab_index) %><br/>
<label for="context_hide"><%= t 'contexts.context_hide' %> </label>
<%= check_box_tag('context_state[hide]', 1, context.hidden?, {:class => 'context-hide', :tabindex => next_tab_index}) %>
<label for="context_hide"><%= t 'contexts.context_state' %> </label><br/>
<% ['active', 'hidden', 'closed'].each do | state | %>
<%= radio_button(:context, 'state', state, {:tabindex => next_tab_index}) %> <%= state.titlecase %>
<% end %>
<input type="hidden" name="wants_render" value="true" />
<div class="submit_box">

View file

@ -2,18 +2,14 @@
hide_empty_message();
TracksPages.hide_errors();
TracksPages.set_page_badge(<%= @down_count %>);
add_context("<%=@context.hidden? ? 'hidden' : 'active'%>");
add_context("<%=@context.state%>");
clear_form();
<% else -%>
TracksPages.show_errors(html_for_error_messages());
<% end -%>
function hide_empty_message() {
<% if @context.hidden? -%>
$('div#hidden-contexts-empty-nd').hide();
<% else -%>
$('div#active-contexts-empty-nd').hide();
<% end -%>
$('div#<%=@context.state%>-contexts-empty-nd').hide();
}
function add_context(state) {

View file

@ -1,7 +1,7 @@
remove_deleted_context();
ContextListPage.update_all_states_count(<%=@active_contexts_count%>, <%=@hidden_contexts_count%>)
ContextListPage.show_or_hide_all_state_containers(<%= @show_active_contexts %>, <%= @show_hidden_contexts %>);
ContextListPage.update_all_states_count(<%=@active_contexts_count%>, <%=@hidden_contexts_count%>, <%=@closed_contexts_count%>)
ContextListPage.show_or_hide_all_state_containers(<%= @show_active_contexts %>, <%= @show_hidden_contexts %>, <%= @show_closed_contexts %>);
TracksPages.set_page_badge(<%=@down_count%>);
TracksPages.page_notify('notice', "<%= t('contexts.context_deleted', :name=>@context.name)%>", 5);

View file

@ -1,6 +1,7 @@
<div id="display_box">
<%= render :partial => 'context_state_group', :object => @active_contexts, :locals => { :state => 'active', :no_contexts => @no_active_contexts} %>
<%= render :partial => 'context_state_group', :object => @hidden_contexts, :locals => { :state => 'hidden', :no_contexts => @no_hidden_contexts} %>
<%= render :partial => 'context_state_group', :object => @closed_contexts, :locals => { :state => 'closed', :no_contexts => @no_closed_contexts} %>
</div>
<div id="input_box">

View file

@ -1,42 +1,48 @@
<% if @saved -%>
<% unless @saved -%>
TracksPages.show_edit_errors(html_for_error_messages());
function html_for_error_messages() {
return "<%= escape_javascript(get_list_of_error_messages_for(@context)) %>";
}
<% else -%>
TracksPages.page_notify('notice', '<%= t('contexts.save_status_message') %>', 5);
<% if @state_changed -%>
remove_and_re_add_context();
update_container_states();
<% else -%>
replace_context_form_with_updated_context();
<% end -%>
<% else -%>
TracksPages.show_edit_errors(html_for_error_messages());
<% end -%>
function remove_and_re_add_context() {
function remove_and_re_add_context() {
$('#<%=dom_id(@context, 'container')%>').slideUp(500, function() {
$('#<%=dom_id(@context, 'container')%>').remove();
$('#list-contexts-<%=@new_state%>').append(html_for_context_listing());
});
}
}
function replace_context_form_with_updated_context() {
function replace_context_form_with_updated_context() {
$('#<%=dom_id(@context, 'container')%>').fadeOut(250, function() {
<%
<%
# first add the updated context after the old one, then remove old one
# using html() does not work, because it will replace the _content_ of
# the container instead of the container itself, i.e. you will get
# a container within a container which will break drag-and-drop sorting
-%>
-%>
$('#<%=dom_id(@context, 'container')%>').after(html_for_context_listing());
$('#<%=dom_id(@context, 'container')%>').remove();
$('#<%=dom_id(@context, 'container')%>').fadeIn(500);
});
}
}
function html_for_error_messages() {
return "<%= escape_javascript(get_list_of_error_messages_for(@context)) %>";
}
function update_container_states() {
ContextListPage.update_all_states_count(<%=@active_contexts.count%>, <%=@hidden_contexts.count%>, <%=@closed_contexts.count%>);
ContextListPage.show_or_hide_all_state_containers(<%= !@active_contexts.empty? %>, <%= !@hidden_contexts.empty? %>, <%= !@closed_contexts.empty? %>);
}
function html_for_context_listing() {
function html_for_context_listing() {
return "<%= escape_javascript(render(:partial => 'context_listing', :object => @context))%>";
}
}
<% end -%>

View file

@ -892,6 +892,7 @@ en:
edit_context: Edit context
hide_form_title: Hide new context form
context_hide: Hide from front page?
context_state: Context state
hidden_contexts: Hidden contexts
no_contexts_active: Currently there are no active contexts
show_form: Create a new context

View file

@ -49,18 +49,23 @@ Feature: Manage the list of contexts
And the context list badge for active contexts should show 1
@javascript
Scenario: Delete last context from context page should remove the contexts container for hidden or active contexts
Scenario: Delete last context from context page should remove the contexts container
Given I have a context called "@computer"
And I have a hidden context called "@ipad"
And I have a closed context called "@ibm-pc"
When I go to the contexts page
And I should see that the context container for active contexts is present
And I should see that the context container for hidden contexts is present
And I should see that the context container for closed contexts is present
When I delete the context "@computer"
Then I should see that a context named "@computer" is not present
And I should see that the context container for active contexts is not present
When I delete the context "@ipad"
Then I should see that a context named "@ipad" is not present
And I should see that the context container for hidden contexts is not present
When I delete the context "@ibm-pc"
Then I should see that a context named "@ibm-pc" is not present
And I should see that the context container for closed contexts is not present
@javascript
Scenario: Delete context from context page right after an edit
@ -102,12 +107,16 @@ Feature: Manage the list of contexts
When I go to the contexts page
Then I should see empty message for active contexts
And I should see empty message for hidden contexts
And I should see empty message for closed contexts
When I add a new active context "@active"
Then I should see the context "@active" under "active"
And I should not see empty message for active contexts
When I add a new hidden context "@hidden"
Then I should see the context "@hidden" under "hidden"
And I should not see empty message for hidden contexts
When I edit the state of context "@hidden" to closed
Then I should not see empty message for closed contexts
And I should see the context "@hidden" under "closed"
@javascript
Scenario: I can drag and drop to order the contexts

View file

@ -39,7 +39,7 @@ end
When /^I add a new hidden context "([^"]*)"$/ do |context_name|
fill_in "context[name]", :with => context_name
check "context_hide"
check "context_state_hide"
submit_new_context_form
end
@ -53,6 +53,28 @@ When /^I drag context "([^"]*)" above context "([^"]*)"$/ do |context_drag, cont
page.execute_script "$('#{sortable_css}').simulateDragSortable({move: #{drop_index-drag_index}, handle: '.grip'});"
end
When /^I edit the state of context "(.*?)" to closed$/ do |context_name|
context = @current_user.contexts.where(:name => context_name).first
context.should_not be_nil
# open edit form
page.find("a#link_edit_context_#{context.id}").click
# wait for the form to appear (which included a submit button)
page.should have_css("button#submit_context_#{context.id}", :visible=>true)
# change state
within "form#edit_form_context_#{context.id}" do
find("input#context_state_closed").click
click_button "submit_context_#{context.id}"
end
# wait for the form to go away
page.should_not have_css("button#submit_context_#{context.id}", :visible => true)
# wait for the changed context to appear
page.should have_css("a#link_edit_context_#{context.id}", :visible=> true)
end
Then /^context "([^"]*)" should be above context "([^"]*)"$/ do |context_high, context_low|
context_list_find_index(context_high).should < context_list_find_index(context_low)
end
@ -64,12 +86,8 @@ Then /^I should see that a context named "([^"]*)" (is|is not) present$/ do |con
end
end
Then /^I should see that the context container for (.*) contexts is not present$/ do |state|
page.should_not have_css("div#list-#{state}-contexts-container", :visible => true)
end
Then /^I should see that the context container for (.*) contexts is present$/ do |state|
page.should have_css("div#list-#{state}-contexts-container", :visible => true)
Then /^I should see that the context container for (.*) contexts (is|is not) present$/ do |state, visible|
page.send(visible=="is" ? :should : :should_not, have_css("div#list-#{state}-contexts-container", :visible => true))
end
Then /^I should see the context "([^"]*)" under "([^"]*)"$/ do |context_name, state|
@ -79,20 +97,16 @@ Then /^I should see the context "([^"]*)" under "([^"]*)"$/ do |context_name, st
page.has_css?("div#list-contexts-#{state} div#context_#{context.id}").should be_true
end
Then /^the new context form should be visible$/ do
page.has_css?("div#context_new", :visible => true).should be_true
end
Then /^the new context form should not be visible$/ do
page.has_css?("div#context_new", :visible => true).should be_false
Then /^the new context form should (be|not be) visible$/ do |visible|
page.has_css?("div#context_new", :visible => true).should (visible=="be" ? be_true : be_false)
end
Then /^the context list badge for ([^"]*) contexts should show (\d+)$/ do |state_name, count|
find("span##{state_name}-contexts-count").text.should == count
end
Then /^I should (see|not see) empty message for (active|hidden) contexts$/ do |visible, state|
box = (state=='active') ? "div#active-contexts-empty-nd" : "div#hidden-contexts-empty-nd"
Then /^I should (see|not see) empty message for (active|hidden|closed) contexts$/ do |visible, state|
box = "div##{state}-contexts-empty-nd"
elem = page.find(box)
elem.should_not be_nil

View file

@ -3,32 +3,23 @@ Given /^I have no contexts$/ do
Context.delete_all
end
Given /^there exists an active context called "([^"]*)" for user "([^"]*)"$/ do |context_name, login|
Given /^there exists (an active|a hidden|a closed) context called "([^"]*)" for user "([^"]*)"$/ do |state, context_name, login|
user = User.where(:login => login).first
user.should_not be_nil
@context = user.contexts.where(:name => context_name, :state => 'active').first_or_create
context_state = {"an active" => "active", "a hidden" => "hidden", "a closed" => "closed"}[state]
@context = user.contexts.where(:name => context_name, :state => context_state).first_or_create
end
Given /^there exists a context called "([^"]*)" for user "([^"]*)"$/ do |context_name, login|
step "there exists an active context called \"#{context_name}\" for user \"#{login}\""
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, :state => 'hidden')
end
Given /^I have a context called "([^\"]*)"$/ do |context_name|
step "there exists an active context called \"#{context_name}\" for user \"#{@current_user.login}\""
end
Given /^I have an active context called "([^\"]*)"$/ do |context_name|
step "there exists an active context called \"#{context_name}\" for user \"#{@current_user.login}\""
end
Given /^I have a hidden context called "([^\"]*)"$/ do |context_name|
step "there exists a hidden context called \"#{context_name}\" for user \"#{@current_user.login}\""
Given /^I have (an active|a hidden|a closed) context called "([^\"]*)"$/ do |state, context_name|
step "there exists #{state} context called \"#{context_name}\" for user \"#{@current_user.login}\""
end
Given /^I have the following contexts:$/ do |table|