migrate deleting of contexts

This commit is contained in:
Reinier Balt 2010-10-23 17:52:50 +02:00
parent 15fdb1e572
commit e52a8609c7
10 changed files with 124 additions and 31 deletions

View file

@ -127,7 +127,10 @@ class ContextsController < ApplicationController
@context.destroy @context.destroy
respond_to do |format| respond_to do |format|
format.js { @down_count = current_user.contexts.size } format.js do
@down_count = current_user.contexts.size
update_state_counts
end
format.xml { render :text => "Deleted context #{@context.name}" } format.xml { render :text => "Deleted context #{@context.name}" }
end end
end end
@ -145,6 +148,13 @@ class ContextsController < ApplicationController
protected protected
def update_state_counts
@active_contexts_count = current_user.contexts.active.count
@hidden_contexts_count = current_user.contexts.hidden.count
@show_active_contexts = @active_contexts_count > 0
@show_hidden_contexts = @hidden_contexts_count > 0
end
def render_contexts_html def render_contexts_html
lambda do lambda do
@page_title = "TRACKS::List Contexts" @page_title = "TRACKS::List Contexts"

View file

@ -124,7 +124,15 @@ module ApplicationHelper
{:id => "delete_project_#{project.id}", :class => "delete_project_button", :title => "#{t('projects.delete_project_title')} '#{project.name}'"} {:id => "delete_project_#{project.id}", :class => "delete_project_button", :title => "#{t('projects.delete_project_title')} '#{project.name}'"}
) )
end end
def link_to_delete_context(context, descriptor = sanitize(context.name))
link_to(
descriptor,
context_path(context, :format => 'js'),
{:id => "delete_context_#{context.id}", :class => "delete_context_button", :title => t('contexts.delete_context_confirmation', :name => context.name)}
)
end
def link_to_project_mobile(project, accesskey, descriptor = sanitize(project.name)) def link_to_project_mobile(project, accesskey, descriptor = sanitize(project.name))
link_to( descriptor, project_path(project, :format => 'm'), {:title => "View project: #{project.name}", :accesskey => accesskey} ) link_to( descriptor, project_path(project, :format => 'm'), {:title => "View project: #{project.name}", :accesskey => accesskey} )
end end

View file

@ -1,6 +1,6 @@
<% context = context_listing <% context = context_listing
suppress_drag_handle ||= false suppress_drag_handle ||= false
suppress_edit_button ||= false suppress_edit_button ||= false
%> %>
<div id="<%= dom_id(context, "container") %>" class="list"> <div id="<%= dom_id(context, "container") %>" class="list">
<div id="<%= dom_id(context) %>" class="context sortable_row" style="display:'';"> <div id="<%= dom_id(context) %>" class="context sortable_row" style="display:'';">
@ -12,23 +12,16 @@
<div class="data"> <div class="data">
<%= link_to_context( context ) %> <%= " (" + count_undone_todos_phrase(context,"actions") + ")" %> <%= link_to_context( context ) %> <%= " (" + count_undone_todos_phrase(context,"actions") + ")" %>
</div> </div>
<div class="buttons"> <div class="buttons">
<% if context.hide? %> <% if context.hide? %>
<span class="grey"><%= t('states.hidden') %></span> <span class="grey"><%= t('states.hidden') %></span>
<% else %> <% else %>
<span class="grey"><%= t('states.visible') %></span> <span class="grey"><%= t('states.visible') %></span>
<% end %> <% end %>
<%= link_to_remote(
image_tag( "blank.png", :title => t('contexts.delete_context'), :class=>"delete_item"), <%= link_to_delete_context(context, image_tag( "blank.png", :title => t('contexts.delete_context'), :class=>"delete_item")) %>
:url => {:controller => 'contexts', :action => 'destroy', :id => context.id},
:method => 'delete',
:with => "'_source_view=#{@source_view}'",
:before => "$('#{dom_id(context)}').block({message:null});",
:complete => "$('#{dom_id(context)}').unblock();",
:confirm => t('contexts.delete_context_confirmation', :name => context.name),
:html => { :id => dom_id(context, 'delete') }
) %>
<%= link_to_remote( <%= link_to_remote(
image_tag( "blank.png", :title => t('contexts.edit_context'), :class=>"edit_item"), image_tag( "blank.png", :title => t('contexts.edit_context'), :class=>"edit_item"),
:url => {:controller => 'contexts', :action => 'edit', :id => context.id}, :url => {:controller => 'contexts', :action => 'edit', :id => context.id},
@ -37,7 +30,7 @@
:before => "$('#{dom_id(context)}').block({message:null});", :before => "$('#{dom_id(context)}').block({message:null});",
:complete => "$('#{dom_id(context)}').unblock();", :complete => "$('#{dom_id(context)}').unblock();",
:html => {:id => "edit_context_#{context.id}_link"} :html => {:id => "edit_context_#{context.id}_link"}
) %> ) %>
</div> </div>
</div> </div>
<div id="<%= dom_id(context, 'edit') %>" class="edit-form" style="display:none;"> <div id="<%= dom_id(context, 'edit') %>" class="edit-form" style="display:none;">

View file

@ -1,5 +1,5 @@
<div class="list-stategroup-contexts-container"> <div class="list-stategroup-contexts-container" id="list-<%= state %>-contexts-container">
<h2><span id="<%= state %>-contexts-count" class="badge"><%= context_state_group.length %></span><%= t('states.'+ state +'_plural')%> <%= t('common.contexts') %></h2> <h2><span id="<%= state %>-contexts-count" class="badge"><%= context_state_group.length %></span><%= t("states."+ state +"_plural")%> <%= t('common.contexts') %></h2>
<div id="<%= state%>-contexts-empty-nd" style="<%= no_contexts ? 'display:block' : 'display:none'%>"> <div id="<%= state%>-contexts-empty-nd" style="<%= no_contexts ? 'display:block' : 'display:none'%>">
<div class="message"><p><%= t('contexts.no_contexts_' + state) %></p></div> <div class="message"><p><%= t('contexts.no_contexts_' + state) %></p></div>
</div> </div>

View file

@ -0,0 +1,15 @@
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 %>);
set_page_badge(<%=@down_count%>);
page_notify('notice', "<%= t('contexts.context_deleted', :name=>@context.name)%>", 5);
function remove_deleted_context() {
$('div#<%=dom_id(@context, "container")%>').slideUp(1000,
function() {
$('div#<%=dom_id(@context, "container")%>').remove();
});
}

View file

@ -1,6 +0,0 @@
page.visual_effect :fade, dom_id(@context, "container"), :duration => 0.5
page.delay(0.5) do
page[dom_id(@context, "container")].remove
end
page['badge_count'].replace_html @down_count
page.notify :notice, t('contexts.context_deleted', :name=>@context.name), 5.0

View file

@ -10,14 +10,29 @@ Feature: Manage the list of contexts
| testuser | secret | false | | testuser | secret | false |
And I have logged in as "testuser" with password "secret" And I have logged in as "testuser" with password "secret"
@selenium, @wip @selenium
Scenario: Delete context from context page should update badge Scenario: Delete context from context page should update badge
Given I have a context called "@computer" Given I have a context called "@computer"
And I have a context called "@ipad"
When I go to the contexts page When I go to the contexts page
Then the badge should show 1 Then the badge should show 2
And the context list badge for active contexts should show 2
When I delete the context "@computer" When I delete the context "@computer"
Then he should see that a context named "@computer" is not present Then he should see that a context named "@computer" is not present
And the badge should show 0 And the badge should show 1
And the context list badge for active contexts should show 1
@selenium, @wip
Scenario: Delete last context from context page should remove the contexts container for hidden or active contexts
Given I have a context called "@computer"
And I have a hidden context called "@ipad"
When I go to the contexts page
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
@selenium, @wip @selenium, @wip
Scenario: Delete context from context page right after an edit Scenario: Delete context from context page right after an edit

View file

@ -36,14 +36,27 @@ When /^I add a new active context "([^"]*)"$/ do |context_name|
When "I add a new context \"#{context_name}\"" When "I add a new context \"#{context_name}\""
end end
When /^I add a new hidden context "([^"]*)"$/ do |context_name| When /^I add a new hidden context "([^"]*)"$/ do |context_name|
fill_in "context[name]", :with => context_name fill_in "context[name]", :with => context_name
check "context_hide" check "context_hide"
submit_new_context_form submit_new_context_form
end end
Then /^I should see that a context named "([^"]*)" is not present$/ do |context_name|
Then "I should not see \"#{context_name}\""
end
Then /^I should see that the context container for (.*) contexts is not present$/ do |state|
present = selenium.is_element_present("list-contexts-#{state}'")
present.should_not be_true
end
Then /^I should see the context "([^"]*)" under "([^"]*)"$/ do |context_name, state| Then /^I should see the context "([^"]*)" under "([^"]*)"$/ do |context_name, state|
context = Context.find_by_name(context_name) context = Context.find_by_name(context_name)
context.should_not be_nil
response.should have_xpath("//div[@id='list-contexts-#{state}']//div[@id='context_#{context.id}']") response.should have_xpath("//div[@id='list-contexts-#{state}']//div[@id='context_#{context.id}']")
end end
Then /^the context list badge for ([^"]*) contexts should show (\d+)$/ do |state_name, count|
selenium.get_text("xpath=//span[@id='#{state_name}-contexts-count']").should == count
end

View file

@ -3,14 +3,28 @@ Given /^I have no contexts$/ do
Context.delete_all Context.delete_all
end end
Given /^there exists a context called "([^"]*)" for user "([^"]*)"$/ do |context_name, login| Given /^there exists an active context called "([^"]*)" for user "([^"]*)"$/ do |context_name, login|
user = User.find_by_login(login) user = User.find_by_login(login)
user.should_not be_nil user.should_not be_nil
@context = user.contexts.create!(:name => context_name) @context = user.contexts.create!(:name => context_name, :hide => false)
end
Given /^there exists a hidden context called "([^"]*)" for user "([^"]*)"$/ do |context_name, login|
user = User.find_by_login(login)
user.should_not be_nil
@context = user.contexts.create!(:name => context_name, :hide => true)
end end
Given /^I have a context called "([^\"]*)"$/ do |context_name| Given /^I have a context called "([^\"]*)"$/ do |context_name|
Given "there exists a context called \"#{context_name}\" for user \"#{@current_user.login}\"" Given "there exists an active context called \"#{context_name}\" for user \"#{@current_user.login}\""
end
Given /^I have an active context called "([^\"]*)"$/ do |context_name|
Given "there exists an active context called \"#{context_name}\" for user \"#{@current_user.login}\""
end
Given /^I have a hidden context called "([^\"]*)"$/ do |context_name|
Given "there exists a hidden context called \"#{context_name}\" for user \"#{@current_user.login}\""
end end
Given /^I have the following contexts:$/ do |table| Given /^I have the following contexts:$/ do |table|

View file

@ -51,6 +51,7 @@ var TracksForm = {
} }
} }
/* TODO, refactor the following two objects into three without obvious duplication */
var ProjectListPage = { var ProjectListPage = {
update_state_count: function(state, count) { update_state_count: function(state, count) {
$('#'+state+'-projects-count').html(count); $('#'+state+'-projects-count').html(count);
@ -70,6 +71,26 @@ var ProjectListPage = {
} }
} }
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() { 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() { ContextListPage.set_state_container_visibility(this, eval('show_'+this)); });
},
set_state_container_visibility: function (state, set_visible) {
if (set_visible) {
$('#list-'+state+'-contexts-container').slideDown("fast");
} else {
$('#list-'+state+'-contexts-container').slideUp("fast");
}
}
}
$.fn.clearForm = function() { $.fn.clearForm = function() {
return this.each(function() { return this.each(function() {
var type = this.type, tag = this.tagName.toLowerCase(); var type = this.type, tag = this.tagName.toLowerCase();
@ -624,6 +645,16 @@ $(document).ready(function() {
return false; return false;
}); });
$('a.delete_context_button').live('click', function(evt){
evt.preventDefault();
if(confirm("Are you sure that you want to "+this.title+"? Be aware that this will also delete all (repeating) actions in this context!")){
$(this).parents('.project').block({message: null});
params = {_method: 'delete'};
$.post(this.href, params, null, 'script');
}
});
$("form#context-form button.positive").live('click', function (ev) { $("form#context-form button.positive").live('click', function (ev) {
$('form.#context-form').ajaxSubmit({ $('form.#context-form').ajaxSubmit({
type: 'POST', type: 'POST',