diff --git a/app/controllers/contexts_controller.rb b/app/controllers/contexts_controller.rb index 6261a684..96c2a10b 100644 --- a/app/controllers/contexts_controller.rb +++ b/app/controllers/contexts_controller.rb @@ -14,6 +14,7 @@ class ContextsController < ApplicationController @active_contexts = current_user.contexts.active(true) @hidden_contexts = current_user.contexts.hidden(true) @count = @active_contexts.size + @hidden_contexts.size + @new_context = current_user.contexts.build init_not_done_counts(['context']) respond_to do |format| format.html &render_contexts_html diff --git a/app/views/contexts/_new_context_form.rhtml b/app/views/contexts/_new_context_form.rhtml new file mode 100644 index 00000000..1ce509ea --- /dev/null +++ b/app/views/contexts/_new_context_form.rhtml @@ -0,0 +1,28 @@ +
+ +
+ « <%= t('contexts.hide_form') %> +
+ +
+ <% form_for(@new_context, :html => {:id => 'context-form',:name=>'context',:class => "inline-form", :method => :post }) do -%> + +
<%= error_messages_for('context') %>
+ +
+ <%= text_field( "context", "name" ) %>
+ + + <%= check_box( "context", "hide" ) %>
+ +
+
+ +
+
+

+ <% end -%> +
+
\ No newline at end of file diff --git a/app/views/contexts/create.js.erb b/app/views/contexts/create.js.erb new file mode 100644 index 00000000..5e2fecda --- /dev/null +++ b/app/views/contexts/create.js.erb @@ -0,0 +1,36 @@ +<% if @saved -%> + hide_empty_message(); + TracksForm.hide_errors(); + set_page_badge(<%= @down_count %>); + add_context("<%=@context.hidden? ? 'hidden' : 'active'%>"); + clear_form(); +<% else -%> + TracksForm.show_errors(html_for_error_messages()); +<% end -%> + +/* +if @saved + container_name = 'list-contexts-' + (@context.hidden? ? 'hidden' : 'active') + page.insert_html :bottom, container_name, :partial => 'context_listing', :locals => { :context_listing => @context } +*/ + +function hide_empty_message() { + $('contexts-empty-nd').hide(); +} + +function add_context(state) { + $('#list-contexts-'+state).append(html_for_context_listing()); +} + +function clear_form() { + $('#context-form').clearForm(); + $('#context-form input:text:first').focus(); +} + +function html_for_context_listing() { + return "<%= @saved ? escape_javascript(render(:partial => 'context_listing', :locals => { :context_listing => @context })) : "" %>"; +} + +function html_for_error_messages() { + return "<%= escape_javascript(error_messages_for('context')) %>"; +} \ No newline at end of file diff --git a/app/views/contexts/create.js.rjs b/app/views/contexts/create.js.rjs deleted file mode 100644 index a4755f81..00000000 --- a/app/views/contexts/create.js.rjs +++ /dev/null @@ -1,12 +0,0 @@ -if @saved - container_name = 'list-contexts-' + (@context.hidden? ? 'hidden' : 'active') - page.hide 'contexts-empty-nd' - page.insert_html :bottom, container_name, :partial => 'context_listing', :locals => { :context_listing => @context } - page.hide 'status' - page['badge_count'].replace_html @down_count - page << '$("#context-form").clearForm();' - page << '$("#context-form input:text:first").focus();' -else - page.show 'status' - page.replace_html 'status', "#{error_messages_for('context')}" -end diff --git a/app/views/contexts/index.html.erb b/app/views/contexts/index.html.erb index ea1ee468..58deec59 100644 --- a/app/views/contexts/index.html.erb +++ b/app/views/contexts/index.html.erb @@ -4,41 +4,5 @@
-
- - - -
- <% form_remote_tag( - :url => contexts_path, - :method => :post, - :html=> { :id => 'context-form', :name => 'context', :class => 'inline-form'}, - :before => "$('#context_new_submit').block({message: null})", - :complete => "$('#context_new_submit').unblock()") do -%> - -
<%= error_messages_for('context') %>
- -
- <%= text_field( "context", "name" ) %>
- - - <%= check_box( "context", "hide" ) %>
- -
-
- -
-
-

- <% end -%> -
-
-
-<% -sortable_element 'list-contexts-active', get_listing_sortable_options -sortable_element 'list-contexts-hidden', get_listing_sortable_options --%> + <%= render :partial => 'new_context_form' %> + \ No newline at end of file diff --git a/app/views/projects/create.js.erb b/app/views/projects/create.js.erb index d756056b..4fbe6952 100644 --- a/app/views/projects/create.js.erb +++ b/app/views/projects/create.js.erb @@ -2,32 +2,23 @@ <% if @go_to_project -%> redirect_to ("<%= project_path(@project) -%>") <% else -%> - hide_errors(); - hide_empty_msg(); + TracksForm.hide_errors(); + hide_empty_message(); set_page_badge(<%= @down_count %>); update_active_projects_container(); add_project(); clear_form(); <% end -%> <% else -%> - show_errors(); + TracksForm.show_errors(html_for_error_messages()); <% end -%> -function show_errors() { - $('div#error_status').html(html_for_error_messages()); - $('div#error_status').show(); -} - -function hide_errors() { - $('div#error_status').hide(); -} - -function hide_empty_msg() { +function hide_empty_message() { $('projects-empty-nd').hide(); } function add_project() { - $('#list-active-projects').append(html_for_project_listing); + $('#list-active-projects').append(html_for_project_listing()); } function clear_form() { diff --git a/config/cucumber.yml b/config/cucumber.yml index 97f4fd48..19a76f8e 100644 --- a/config/cucumber.yml +++ b/config/cucumber.yml @@ -5,5 +5,5 @@ std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} --strict --tags ~@w %> default: <%= std_opts %> features --tags ~@selenium selenium: <%= std_opts %> features --tags @selenium -wip: --tags @wip:3 --wip features +wip: --tags @wip:10 --wip features rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip diff --git a/features/context_edit.feature b/features/context_edit.feature new file mode 100644 index 00000000..3a248d59 --- /dev/null +++ b/features/context_edit.feature @@ -0,0 +1,21 @@ +Feature: Edit a context + + In order to work on todos in a context + As a Tracks user + I want to manage todos in a context + + Background: + Given the following user record + | login | password | is_admin | + | testuser | secret | false | + And I have logged in as "testuser" with password "secret" + + @selenium + Scenario: In place edit of context name + Given I have a context called "Errands" + When I visit the context page for "Errands" + And I edit the context name in place to be "OutAndAbout" + Then I should see the context name is "OutAndAbout" + When I go to the contexts page + Then he should see that a context named "Errands" is not present + And he should see that a context named "OutAndAbout" is present diff --git a/features/context_list.feature b/features/context_list.feature index 8c07cd0d..28ac77e3 100644 --- a/features/context_list.feature +++ b/features/context_list.feature @@ -1,8 +1,8 @@ -Feature: Manage contexts +Feature: Manage the list of contexts - In order to manage my contexts + In order to keep track and manage all of my contexts As a Tracks user - I want to view, edit, add, or remove contexts + I want to manage my list of contexts Background: Given the following user record @@ -10,17 +10,7 @@ Feature: Manage contexts | testuser | secret | false | And I have logged in as "testuser" with password "secret" - @selenium - Scenario: In place edit of context name - Given I have a context called "Errands" - When I visit the context page for "Errands" - And I edit the context name in place to be "OutAndAbout" - Then I should see the context name is "OutAndAbout" - When I go to the contexts page - Then he should see that a context named "Errands" is not present - And he should see that a context named "OutAndAbout" is present - - @selenium + @selenium, @wip Scenario: Delete context from context page should update badge Given I have a context called "@computer" When I go to the contexts page @@ -29,7 +19,7 @@ Feature: Manage contexts Then he should see that a context named "@computer" is not present And the badge should show 0 - @selenium + @selenium, @wip Scenario: Delete context from context page right after an edit Given I have a context called "@computer" When I go to the contexts page @@ -38,7 +28,7 @@ Feature: Manage contexts Then he should see that a context named "@laptop" is not present And the badge should show 0 - @selenium + @selenium, @wip Scenario: Edit context from context twice Given I have a context called "@computer" When I go to the contexts page @@ -50,21 +40,16 @@ Feature: Manage contexts And the badge should show 1 @selenium - Scenario: Add new context + Scenario Outline: Add a new context with state Given I have the following contexts | name | hide | | @ipad | true | | @home | false | When I go to the contexts page - And I add a new context "@phone" - Then I should see the context "@phone" under "active" + And I add a new context "" + Then I should see the context "" under "" - @selenium - Scenario: Add new hidden context - Given I have the following contexts - | name | hide | - | @ipad | true | - | @home | false | - When I go to the contexts page - And I add a new hidden context "@hidden" - Then I should see the context "@hidden" under "hidden" + Examples: + | state | name | + | active | @phone | + | hidden | @hidden| diff --git a/features/project_list.feature b/features/project_list.feature index 71f34a60..1809a3f6 100644 --- a/features/project_list.feature +++ b/features/project_list.feature @@ -1,6 +1,6 @@ Feature: Manage the list of projects - In order to keep tracks and manage of all my projects + In order to keep track and manage of all my projects As a Tracks user I want to manage my list of projects diff --git a/features/step_definitions/context_list_steps.rb b/features/step_definitions/context_list_steps.rb new file mode 100644 index 00000000..6af5fea7 --- /dev/null +++ b/features/step_definitions/context_list_steps.rb @@ -0,0 +1,49 @@ +When /^I delete the context "([^\"]*)"$/ do |context_name| + context = @current_user.contexts.find_by_name(context_name) + context.should_not be_nil + click_link "delete_context_#{context.id}" + selenium.get_confirmation.should == "Are you sure that you want to delete the context '#{context_name}'? Be aware that this will also delete all (repeating) actions in this context!" + wait_for do + !selenium.is_element_present("delete_context_#{context.id}") + end +end + +When /^I edit the context to rename it to "([^\"]*)"$/ do |new_name| + click_link "edit_context_#{@context.id}" + + wait_for do + selenium.is_element_present("submit_context_#{@context.id}") + end + + fill_in "context_name", :with => new_name + + selenium.click "submit_context_#{@context.id}", + :wait_for => :text, + :element => "flash", + :text => "Context saved" + + wait_for do + selenium.is_element_present("edit_context_#{@context.id}") + end +end + +When /^I add a new context "([^"]*)"$/ do |context_name| + fill_in "context[name]", :with => context_name + submit_new_context_form +end + +When /^I add a new active context "([^"]*)"$/ do |context_name| + When "I add a new context \"#{context_name}\"" +end + + +When /^I add a new hidden context "([^"]*)"$/ do |context_name| + fill_in "context[name]", :with => context_name + check "context_hide" + submit_new_context_form +end + +Then /^I should see the context "([^"]*)" under "([^"]*)"$/ do |context_name, state| + context = Context.find_by_name(context_name) + response.should have_xpath("//div[@id='list-contexts-#{state}']//div[@id='context_#{context.id}']") +end diff --git a/features/step_definitions/context_steps.rb b/features/step_definitions/context_steps.rb index d47a7b06..0e0fae48 100644 --- a/features/step_definitions/context_steps.rb +++ b/features/step_definitions/context_steps.rb @@ -33,6 +33,7 @@ Given /^I have the following contexts$/ do |table| end end +# TODO: refactor this to paths.rb When /^I visit the context page for "([^\"]*)"$/ do |context_name| context = @current_user.contexts.find_by_name(context_name) context.should_not be_nil @@ -41,7 +42,7 @@ end When /^I edit the context name in place to be "([^\"]*)"$/ do |new_context_name| selenium.click "context_name" - fill_in "value", :with => "OutAndAbout" + fill_in "value", :with => new_context_name click_button "OK" end @@ -96,8 +97,3 @@ end Then /^he should see that a context named "([^\"]*)" is not present$/ do |context_name| Then "I should not see \"#{context_name} (\"" end - -Then /^I should see the context "([^"]*)" under "([^"]*)"$/ do |context_name, state| - context = Context.find_by_name(context_name) - response.should have_xpath("//div[@id='list-contexts-#{state}']//div[@id='context_#{context.id}']") -end diff --git a/features/step_definitions/todo_steps.rb b/features/step_definitions/todo_steps.rb index 141bb3fc..4a57a897 100644 --- a/features/step_definitions/todo_steps.rb +++ b/features/step_definitions/todo_steps.rb @@ -55,7 +55,7 @@ When /^I drag "(.*)" to "(.*)"$/ do |dragged, target| selenium.drag_and_drop_to_object(drag_name, drop_name) arrow = "xpath=//div[@id='line_todo_#{drop_id}']/div/a[@class='show_successors']/img" - selenium.wait_for_element(arrow) + selenium.wait_for_element(arrow, :timeout_in_seconds => 5) end When /^I expand the dependencies of "([^\"]*)"$/ do |todo_name| diff --git a/public/javascripts/application.js b/public/javascripts/application.js index cc6d068c..2dc949e6 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -41,6 +41,13 @@ var TracksForm = { }, set_tag_list: function (name) { $('input#tag_list').val(name); + }, + show_errors: function (html) { + $('div#error_status').html(html); + $('div#error_status').show(); + }, + hide_errors: function () { + $('div#error_status').hide(); } } @@ -617,6 +624,17 @@ $(document).ready(function() { return false; }); + $("form#context-form button.positive").live('click', function (ev) { + $('form.#context-form').ajaxSubmit({ + type: 'POST', + async: true, + buttons_dom_elem: $(this), + beforeSend: function() {this.buttons_dom_elem.block({message: null});}, + complete: function() {this.buttons_dom_elem.unblock();} + }); + return false; + }); + $('#toggle_project_new').click(function(evt){ TracksForm.toggle('toggle_project_new', 'project_new', 'project-form', '« Hide form', 'Hide new project form',