mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-17 06:35:28 +01:00
migrate creating a new context and refactor some project js to share with context js
This commit is contained in:
parent
8f5efff8da
commit
15fdb1e572
14 changed files with 178 additions and 101 deletions
|
|
@ -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
|
||||
|
|
|
|||
28
app/views/contexts/_new_context_form.rhtml
Normal file
28
app/views/contexts/_new_context_form.rhtml
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<div id="context_new_container">
|
||||
|
||||
<div id="toggle_context_new" class="hide_form">
|
||||
<a title="<%= t('contexts.hide_form_link_title') %>" accesskey="n">« <%= t('contexts.hide_form') %></a>
|
||||
</div>
|
||||
|
||||
<div id="context_new" class="context_new" style="display:block">
|
||||
<% form_for(@new_context, :html => {:id => 'context-form',:name=>'context',:class => "inline-form", :method => :post }) do -%>
|
||||
|
||||
<div id="error_status"><%= error_messages_for('context') %></div>
|
||||
|
||||
<label for="context_name"><%= t 'contexts.context_name' %></label><br />
|
||||
<%= text_field( "context", "name" ) %><br />
|
||||
|
||||
<label for="context_hide"><%= t 'contexts.context_hide' %></label>
|
||||
<%= check_box( "context", "hide" ) %><br />
|
||||
|
||||
<div class="submit_box">
|
||||
<div class="widgets">
|
||||
<button type="submit" class="positive" id="context_new_submit">
|
||||
<%= image_tag("accept.png", :alt => "") + 'Add Context' %>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<br/><br/>
|
||||
<% end -%>
|
||||
</div>
|
||||
</div>
|
||||
36
app/views/contexts/create.js.erb
Normal file
36
app/views/contexts/create.js.erb
Normal file
|
|
@ -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')) %>";
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
@ -4,41 +4,5 @@
|
|||
</div>
|
||||
|
||||
<div id="input_box">
|
||||
<div id="context_new_container">
|
||||
|
||||
<div id="toggle_context_new" class="hide_form">
|
||||
<a title="<%= t('contexts.hide_form_link_title') %>" accesskey="n">« <%= t('contexts.hide_form') %></a>
|
||||
</div>
|
||||
|
||||
<div id="context_new" class="context_new" style="display:block">
|
||||
<% 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 -%>
|
||||
|
||||
<div id="status"><%= error_messages_for('context') %></div>
|
||||
|
||||
<label for="context_name"><%= t 'contexts.context_name' %></label><br />
|
||||
<%= text_field( "context", "name" ) %><br />
|
||||
|
||||
<label for="context_hide"><%= t 'contexts.context_hide' %></label>
|
||||
<%= check_box( "context", "hide" ) %><br />
|
||||
|
||||
<div class="submit_box">
|
||||
<div class="widgets">
|
||||
<button type="submit" class="positive" id="context_new_submit">
|
||||
<%= image_tag("accept.png", :alt => "") + t('contexts.add_context') %>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<br/><br/>
|
||||
<% end -%>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<%
|
||||
sortable_element 'list-contexts-active', get_listing_sortable_options
|
||||
sortable_element 'list-contexts-hidden', get_listing_sortable_options
|
||||
-%>
|
||||
<%= render :partial => 'new_context_form' %>
|
||||
</div>
|
||||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
21
features/context_edit.feature
Normal file
21
features/context_edit.feature
Normal file
|
|
@ -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
|
||||
|
|
@ -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 <state> context "<name>"
|
||||
Then I should see the context "<name>" under "<state>"
|
||||
|
||||
@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|
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
49
features/step_definitions/context_list_steps.rb
Normal file
49
features/step_definitions/context_list_steps.rb
Normal file
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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|
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue