diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index e4f39cd4..3c27571a 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -26,24 +26,18 @@ class NotesController < ApplicationController end def create - note = current_user.notes.build - note.attributes = params["note"] + @note = current_user.notes.build + @note.attributes = params["note"] - saved = note.save + @saved = @note.save respond_to do |format| - format.js do - if note.save - render :partial => 'notes_summary', :object => note - else - render :text => '' - end - end + format.js format.xml do - if saved - head :created, :location => note_url(note), :text => "new note with id #{note.id}" + if @saved + head :created, :location => note_url(@note), :text => "new note with id #{@note.id}" else - render_failure note.errors.full_messages.join(', ') + render_failure @note.errors.full_messages.join(', ') end end format.html do diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index f21329d2..a698fb44 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -56,6 +56,8 @@ class ProjectsController < ApplicationController @next_project = current_user.projects.next_from(@project) @previous_project = current_user.projects.previous_from(@project) @default_tags = @project.default_tags + @new_note = current_user.notes.build + @new_note.project_id = @project.id respond_to do |format| format.html format.m &render_project_mobile diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 724de012..2969a8b2 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -246,4 +246,21 @@ module ApplicationHelper note = Sanitize.clean(note, Sanitize::Config::RELAXED) return note end + + def sidebar_html_for_titled_list (list, title) + return content_tag(:h3, title+" (#{list.length})") + + content_tag(:ul, sidebar_html_for_list(list)) + end + + def sidebar_html_for_list(list) + if list.empty? + return content_tag(:li, t('sidebar.list_empty')) + else + return list.inject("") do |html, item| + link = (item.class == "Project") ? link_to_project( item ) : link_to_context(item) + html << content_tag(:li, link + " (" + count_undone_todos_phrase(item,"actions")+")") + end + end + end + end diff --git a/app/views/notes/_note_edit_form.rhtml b/app/views/notes/_note_edit_form.rhtml index 5ad8d16d..fa9dbfc2 100644 --- a/app/views/notes/_note_edit_form.rhtml +++ b/app/views/notes/_note_edit_form.rhtml @@ -1,7 +1,8 @@ +<% submit_text ||= t('common.update') -%> <% form_for(note_edit_form, :html => { :id => dom_id(note_edit_form, 'edit_form'), :class => "inline-form edit-note-form", - :method => :put }) do |f| + :method => :post }) do |f| -%>
<%= error_messages_for("note") %>
@@ -13,7 +14,7 @@
<%=image_tag("cancel.png", :alt => "") %> diff --git a/app/views/notes/_notes_summary.rhtml b/app/views/notes/_notes_summary.rhtml index bb9633a1..de09228a 100644 --- a/app/views/notes/_notes_summary.rhtml +++ b/app/views/notes/_notes_summary.rhtml @@ -1,6 +1,11 @@ <% note = notes_summary -%>
-<%= link_to( image_tag("blank.png", :border => 0), note_path(note), :title => t('notes.show_note_title'), :class => "link_to_notes icon") %>  +<%= link_to( + image_tag("blank.png", :border => 0), + note_path(note), + :title => t('notes.show_note_title'), + :class => "link_to_notes icon", + :id => dom_id(note, "link")) %>  <%= rendered_note(note) %>
<% note = nil -%> diff --git a/app/views/notes/create.js.erb b/app/views/notes/create.js.erb new file mode 100644 index 00000000..1bba282c --- /dev/null +++ b/app/views/notes/create.js.erb @@ -0,0 +1,25 @@ +<% if @saved -%> + TracksForm.hide_errors(); + add_note(); + clear_form(); +<% else -%> + TracksForm.show_errors(html_for_error_messages()); +<% end -%> + +function add_note() { + $('div#notes').append(html_for_note_summary()); + $('#empty-n').hide(); +} + +function clear_form() { + $('#new-note').hide(); + $('#edit-note-form').clearForm(); +} + +function html_for_error_messages() { + return "<%= escape_javascript(error_messages_for('project')) %>"; +} + +function html_for_note_summary() { + return "<%= @saved ? escape_javascript(render(:partial => 'notes_summary', :object => @note)) : "" %>"; +} \ No newline at end of file diff --git a/app/views/notes/update.js.erb b/app/views/notes/update.js.erb index 58735b31..d44fe2c1 100644 --- a/app/views/notes/update.js.erb +++ b/app/views/notes/update.js.erb @@ -4,14 +4,9 @@ replace_note_form_with_updated_note(); <% else -%> - show_errors(); + TracksForm.show_errors(html_for_error_messages()); <% end %> -function show_errors() { - $('div#edit_error_status').html(html_for_error_messages()); - $('div#edit_error_status').show(); -} - function replace_note_form_with_updated_note() { $('#<%= dom_id(@note, 'edit')%>').fadeOut(250, function() { $('#<%= dom_id(@note, 'edit')%>').html(html_for_updated_note_form()); diff --git a/app/views/projects/show.html.erb b/app/views/projects/show.html.erb index db4d4bce..c338155b 100644 --- a/app/views/projects/show.html.erb +++ b/app/views/projects/show.html.erb @@ -11,7 +11,7 @@
- +

Notes

<%= render :partial => "shared/empty", @@ -22,18 +22,9 @@
+
diff --git a/app/views/sidebar/_context.rhtml b/app/views/sidebar/_context.rhtml deleted file mode 100644 index 70d8d493..00000000 --- a/app/views/sidebar/_context.rhtml +++ /dev/null @@ -1 +0,0 @@ -
  • <%= link_to_context( context ) + " (" + count_undone_todos_phrase(context,"actions") + ")"%>
  • \ No newline at end of file diff --git a/app/views/sidebar/_context_list.rhtml b/app/views/sidebar/_context_list.rhtml deleted file mode 100644 index d2010c7b..00000000 --- a/app/views/sidebar/_context_list.rhtml +++ /dev/null @@ -1,8 +0,0 @@ -

    <%= list_name %> (<%= contexts.length %>)

    -
      - <% if contexts.empty? -%> -
    • <%= t('sidebar.list_empty') %>
    • - <% else -%> - <%= render :partial => "sidebar/context", :collection => contexts -%> - <% end -%> -
    \ No newline at end of file diff --git a/app/views/sidebar/_project.rhtml b/app/views/sidebar/_project.rhtml deleted file mode 100644 index d7fade18..00000000 --- a/app/views/sidebar/_project.rhtml +++ /dev/null @@ -1 +0,0 @@ -
  • <%= link_to_project( project ) + " (" + count_undone_todos_phrase(project,"actions") + ")" %>
  • \ No newline at end of file diff --git a/app/views/sidebar/_project_list.rhtml b/app/views/sidebar/_project_list.rhtml deleted file mode 100644 index f30a697a..00000000 --- a/app/views/sidebar/_project_list.rhtml +++ /dev/null @@ -1,8 +0,0 @@ -

    <%= list_name %> (<%= projects.length %>)

    -
      - <% if projects.empty? %> -
    • <%= t('sidebar.list_empty') %>
    • - <% else %> - <%= render :partial => "sidebar/project", :collection => projects %> - <% end %> -
    \ No newline at end of file diff --git a/app/views/sidebar/sidebar.html.erb b/app/views/sidebar/sidebar.html.erb index f331d22d..f539587f 100644 --- a/app/views/sidebar/sidebar.html.erb +++ b/app/views/sidebar/sidebar.html.erb @@ -1,30 +1,13 @@ \ No newline at end of file diff --git a/features/project_edit.feature b/features/project_edit.feature index 8872843f..a8c2f682 100644 --- a/features/project_edit.feature +++ b/features/project_edit.feature @@ -63,26 +63,31 @@ Feature: Edit a project When I try to edit the project name of "manage me" to "test" Then I should see "Name already exists" - @selenium @wip + @selenium Scenario: I can go to the note of a project - Given I have a project "test" with 2 note + Given I have a project "test" with 2 notes When I visit the "test" project - Then I should see 2 notes When I click on the first note icon Then I should go to that note page - @selenium @wip + @selenium Scenario: I can add a note to the project - Given I have a project "test" + Given I have a project called "test" When I visit the "test" project - And I add a note "hello I'm testing" - Then I should see one note + And I add a note "hello I'm testing" to the project + Then I should see one note in the project - @selenium @wip + @selenium @focus + Scenario: Cancelling adding a note to the project will remove form + Given I have a project called "test" + When I visit the "test" project + And I cancel adding a note to the project + Then the form for adding a note should not be visible + + @selenium Scenario: Long notes in a project are shown cut off - Given I have a project "test" + Given I have a project called "test" When I visit the "test" project - And I add a note "test 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234 TOO LONG" + And I add a note "test 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234 TOO LONG" to the project Then I should not see "test 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234 TOO LONG" - And I should see "test 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234" - + And I should see "test 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234" \ No newline at end of file diff --git a/features/step_definitions/project_steps.rb b/features/step_definitions/project_steps.rb index 96335e07..5df89c2e 100644 --- a/features/step_definitions/project_steps.rb +++ b/features/step_definitions/project_steps.rb @@ -86,7 +86,6 @@ When /^I try to edit the project name of "([^"]*)" to "([^"]*)"$/ do |project_cu When "I try to edit the project name to \"#{project_new_name}\"" end - When /^I edit the project name in place to be "([^"]*)"$/ do |new_project_name| selenium.click "project_name" fill_in "value", :with => new_project_name @@ -115,6 +114,42 @@ When /^I edit the project state of "([^"]*)" to "([^"]*)"$/ do |project_name, st end end +When /^I add a note "([^"]*)" to the project$/ do |note_body| + click_link "Add a note" + fill_in "note[body]", :with => note_body + click_button "Add note" +end + +When /^I click on the first note icon$/ do + @project.should_not be_nil + @note = @project.notes.first # assume first note is also first on screen + @note.should_not be_nil + + click_link "link_note_#{@note.id}" +end + +When /^I cancel adding a note to the project$/ do + click_link "Add a note" + fill_in "note[body]", :with => "will not save this" + click_link "neg_edit_form_note" +end + +Then /^the form for adding a note should not be visible$/ do + wait_for do # wait for the form to go away + !selenium.is_visible("edit_form_note") + end +end + +Then /^I should go to that note page$/ do + current_path = URI.parse(current_url).path + note_path = note_path(@note) + current_path.should == note_path +end + +Then /^I should see one note in the project$/ do + selenium.wait_for_element("xpath=//div[@class='note_wrapper']") +end + Then /^I should see the bold text "([^\"]*)" in the project description$/ do |bold| xpath="//div[@class='project_description']/p/strong" diff --git a/features/step_definitions/todo_steps.rb b/features/step_definitions/todo_steps.rb index b8a5c91d..1ab0fe91 100644 --- a/features/step_definitions/todo_steps.rb +++ b/features/step_definitions/todo_steps.rb @@ -118,7 +118,6 @@ When /^I edit the dependency of "([^"]*)" to '([^'']*)'$/ do |todo_name, deps| fill_in "predecessor_list_todo_#{todo.id}", :with => deps # submit form selenium.click("//div[@id='edit_todo_#{todo.id}']//button[@id='submit_todo_#{todo.id}']", :wait_for => :ajax, :javascript_framework => :jquery) - end Then /^there should not be an error$/ do @@ -126,7 +125,6 @@ Then /^there should not be an error$/ do selenium.is_visible("edit_todo_#{@dep_todo.id}").should == false end - Then /^the dependencies of "(.*)" should include "(.*)"$/ do |child_name, parent_name| parent = @current_user.todos.find_by_description(parent_name) parent.should_not be_nil diff --git a/features/support/paths.rb b/features/support/paths.rb index 96e04562..fcdf6b93 100644 --- a/features/support/paths.rb +++ b/features/support/paths.rb @@ -47,7 +47,8 @@ module NavigationHelpers when /the "([^\"]*)" project for user "([^\"]*)"/i project_path(User.find_by_login($2).projects.find_by_name($1)) when /the "([^\"]*)" project/i - project_path(@current_user.projects.find_by_name($1)) + @project = @current_user.projects.find_by_name($1) + project_path(@project) # Add more mappings here. # Here is an example that pulls values out of the Regexp: diff --git a/public/javascripts/application.js b/public/javascripts/application.js index fbd50251..887ef0fb 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -106,6 +106,13 @@ var IntegrationsPage = { var NotesPage = { setup_behavior: function() { + /* Add note */ + $(".add_note_link a").live('click', function(){ + $('#new-note').show(); + $('textarea#note_body').val(''); + $('textarea#note_body').focus(); + }); + /* delete button for note */ $('a.delete_note_button').live('click', function(evt){ evt.preventDefault(); @@ -126,7 +133,13 @@ var NotesPage = { /* cancel button when editing a note */ $('.edit-note-form a.negative').live('click', function(){ dom_id = this.id.substr(14); - $('#'+dom_id).toggle(); $('#edit_'+dom_id).hide(); + /* dom_id == 'note_XX' on notes page and just 'note' on project page */ + if (dom_id == 'note') { + $('#new-note').hide(); + } else { + $('#'+dom_id).toggle(); + $('#edit_'+dom_id).hide(); + } return false; }); @@ -753,12 +766,6 @@ $(document).ready(function() { 'Create a new project ยป', 'Add a project'); }); - $(".add_note_link a").live('click', function(){ - $('#new-note').show(); - $('#new-note form').clearForm(); - $('#new-note form input:text:first').focus(); - }); - $("#list-active-projects").sortable({handle: '.handle', update: update_order}); $("#list-hidden-projects").sortable({handle: '.handle', update: update_order}); $("#list-completed-projects").sortable({handle: '.handle', update: update_order});