mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-03 06:21:49 +01:00
Make the NotesController user RESTful routes.
git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@403 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
parent
bb4b726650
commit
828ad592e2
18 changed files with 88 additions and 75 deletions
|
|
@ -1,4 +1,4 @@
|
|||
class NoteController < ApplicationController
|
||||
class NotesController < ApplicationController
|
||||
|
||||
def index
|
||||
@all_notes = @user.notes
|
||||
|
|
@ -27,7 +27,7 @@ class NoteController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def delete
|
||||
def destroy
|
||||
note = check_user_return_note
|
||||
if note.destroy
|
||||
render :text => ''
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
class ProjectsController < ApplicationController
|
||||
|
||||
helper :todo
|
||||
helper :todo, :notes
|
||||
before_filter :init, :except => [:create, :destroy, :order]
|
||||
|
||||
def index
|
||||
|
|
|
|||
|
|
@ -1,2 +0,0 @@
|
|||
module NoteHelper
|
||||
end
|
||||
5
tracks/app/helpers/notes_helper.rb
Normal file
5
tracks/app/helpers/notes_helper.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
module NotesHelper
|
||||
def truncated_note(note, characters = 50)
|
||||
sanitize(textilize(truncate(note.body, characters, "...")))
|
||||
end
|
||||
end
|
||||
|
|
@ -45,7 +45,7 @@
|
|||
<li><%= navigation_link( "Projects", projects_path, {:accesskey=>"p", :title=>"Projects"} ) %></li>
|
||||
<li><%= navigation_link( "Tickler", {:controller => "todo", :action => "tickler"}, :title => "Tickler" ) %></li>
|
||||
<li><%= navigation_link( "Done", {:controller => "todo", :action => "completed"}, {:accesskey=>"d", :title=>"Completed"} ) %></li>
|
||||
<li><%= navigation_link( "Notes", {:controller => "note", :action => "index"}, {:accesskey => "o", :title => "Show all notes"} ) %></li>
|
||||
<li><%= navigation_link( "Notes", notes_path, {:accesskey => "o", :title => "Show all notes"} ) %></li>
|
||||
<li><%= navigation_link( "Preferences", {:controller => "preferences", :action => "index"}, {:accesskey => "u", :title => "Show my preferences"} ) %></li>
|
||||
<li><%= navigation_link( "Import/Export", {:controller => "data", :action => "index"}, {:accesskey => "i", :title => "Import and export data"} ) %></li>
|
||||
<% if @user.is_admin? -%>
|
||||
|
|
|
|||
|
|
@ -1,34 +0,0 @@
|
|||
<% note = notes -%>
|
||||
<div id="note-<%= note.id.to_s %>-container">
|
||||
<h2><%= link_to("Note #{note.id.to_s}", {:action => "show", :id => note.id}, :title => "Show note #{note.id.to_s}" ) %></h2>
|
||||
|
||||
<div id="note-<%= note.id.to_s %>">
|
||||
<%= sanitize(textilize(note.body)) %>
|
||||
|
||||
<div class="note_footer">
|
||||
<%= link_to_remote( image_tag("blank.png", :title =>"Delete this note", :class=>"delete_item"),
|
||||
:update => "note-#{note.id}",
|
||||
:loading => visual_effect(:fade, "note-#{note.id}-container"),
|
||||
:complete => "Element.remove('note-#{note.id}-wrapper');",
|
||||
:url => { :controller => "note", :action => "delete", :id => note.id },
|
||||
:confirm => "Are you sure that you want to delete the note \'#{note.id.to_s}\'?" ) + " "%><%= link_to_function(image_tag( "blank.png", :title => "Edit item", :class=>"edit_item"),
|
||||
"Element.toggle('note-#{note.id}'); Element.toggle('note-#{note.id}-edit-form'); Effect.Appear('note-#{note.id}-edit-form'); Form.focusFirstElement('form-note-#{note.id}');" ) + " | " %>
|
||||
<%= link_to("In: " + note.project.name, project_path(note.project), :class=>"footer_link" ) %> |
|
||||
Created: <%= format_date(note.created_at) %>
|
||||
<% if note.updated_at? -%>
|
||||
| Modified: <%= format_date(note.updated_at) %>
|
||||
<% end -%>
|
||||
</div>
|
||||
</div><!-- [end.note.id] -->
|
||||
|
||||
<div id="note-<%= note.id %>-edit-form" class="edit-form" style="display:none;">
|
||||
<% form_remote_tag :url => { :action => 'update', :id => note.id },
|
||||
:html => { :id => "form-note-#{note.id}", :class => "inline-form" },
|
||||
:update => "note-#{note.id}-container",
|
||||
:complete => visual_effect(:appear, "note-#{note.id}-container") do -%>
|
||||
<%= render :partial => "note_edit_form", :object => note %>
|
||||
<% end -%>
|
||||
</div><!-- [end:note-note.id-edit-form] -->
|
||||
|
||||
</div><!-- [end.note-note.id-container] -->
|
||||
<% note = nil -%>
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
<% note = notes_summary -%>
|
||||
<div class="note_wrapper">
|
||||
<%= link_to( image_tag("blank.png", :border => 0), { :controller => "note", :action => "show",
|
||||
:id => note.id}, :title => "Show note", :class => "show_notes icon") %>
|
||||
<%= sanitize(textilize(truncate(note.body, 50, "..."))) %>
|
||||
</div>
|
||||
<% note = nil -%>
|
||||
35
tracks/app/views/notes/_notes.rhtml
Normal file
35
tracks/app/views/notes/_notes.rhtml
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<% note = notes -%>
|
||||
<div id="<%= dom_id(note, 'container') %>">
|
||||
<h2><%= link_to("Note #{note.id}", note_path(note), :title => "Show note #{note.id}" ) %></h2>
|
||||
<div id="<%= dom_id(note) %>">
|
||||
<%= sanitize(textilize(note.body)) %>
|
||||
|
||||
<div class="note_footer">
|
||||
<%= link_to_remote( image_tag("blank.png", :title =>"Delete this note", :class=>"delete_item"),
|
||||
:update => dom_id(note),
|
||||
:loading => visual_effect(:fade, dom_id(note, 'container')),
|
||||
:complete => "Element.remove('#{dom_id(note, 'container')}');",
|
||||
:url => note_path(note),
|
||||
:method => :delete,
|
||||
:confirm => "Are you sure that you want to delete the note \'#{note.id.to_s}\'?" ) + " " -%>
|
||||
<%= link_to_function(image_tag( "blank.png", :title => "Edit item", :class=>"edit_item"),
|
||||
"Element.toggle('#{dom_id(note)}'); Element.toggle('#{dom_id(note, 'edit')}'); Effect.Appear('#{dom_id(note, 'edit')}'); Form.focusFirstElement('#{dom_id(note, 'edit_form')}');" ) + " | " %>
|
||||
<%= link_to("In: " + note.project.name, project_path(note.project), :class=>"footer_link" ) %> |
|
||||
Created: <%= format_date(note.created_at) %>
|
||||
<% if note.updated_at? -%>
|
||||
| Modified: <%= format_date(note.updated_at) %>
|
||||
<% end -%>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="<%= dom_id(note, 'edit') %>" class="edit-form" style="display:none;">
|
||||
<% form_remote_tag :url => note_path(note),
|
||||
:method => :put,
|
||||
:html => { :id => dom_id(note, 'edit_form'), :class => "inline-form" },
|
||||
:update => dom_id(note, 'container'),
|
||||
:complete => visual_effect(:appear, dom_id(note, 'container')) do -%>
|
||||
<%= render :partial => "note_edit_form", :object => note %>
|
||||
<% end -%>
|
||||
</div>
|
||||
</div>
|
||||
<% note = nil -%>
|
||||
6
tracks/app/views/notes/_notes_summary.rhtml
Normal file
6
tracks/app/views/notes/_notes_summary.rhtml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<% note = notes_summary -%>
|
||||
<div class="note_wrapper" id="<%= dom_id(note) %>">
|
||||
<%= link_to( image_tag("blank.png", :border => 0), note_path(note), :title => "Show note", :class => "show_notes icon") %>
|
||||
<%= truncated_note(note) %>
|
||||
</div>
|
||||
<% note = nil -%>
|
||||
|
|
@ -12,17 +12,18 @@
|
|||
<%= render :partial => "shared/empty",
|
||||
:locals => { :message => "Currently there are no notes attached to this project"} %>
|
||||
</div>
|
||||
<%= render :partial => "note/notes_summary", :collection => @project.notes %>
|
||||
<%= render :partial => "notes/notes_summary", :collection => @project.notes %>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
|
||||
<div id="new-note" style="display:none;">
|
||||
<% form_remote_tag :url => { :controller => "note", :action => "create" },
|
||||
:update => "notes",
|
||||
:position => "bottom",
|
||||
:complete => "new Effect.Highlight('notes');$('empty-n').hide();",
|
||||
:html => {:id=>'form-new-note', :class => 'inline-form'} do %>
|
||||
<% form_remote_tag :url => notes_path,
|
||||
:method => :post,
|
||||
:update => "notes",
|
||||
:position => "bottom",
|
||||
:complete => "new Effect.Highlight('notes');$('empty-n').hide();",
|
||||
:html => {:id=>'form-new-note', :class => 'inline-form'} do %>
|
||||
<%= hidden_field( "new_note", "project_id", "value" => "#{@project.id}" ) %>
|
||||
<%= text_area( "new_note", "body", "cols" => 50, "rows" => 3, "tabindex" => 1 ) %>
|
||||
<br /><br />
|
||||
|
|
|
|||
|
|
@ -45,10 +45,7 @@ ActionController::Routing::Routes.draw do |map|
|
|||
map.connect 'projects/feed/:feedtype/:login/:token', :controller => 'feed', :action => 'list_projects_only'
|
||||
|
||||
# Notes Routes
|
||||
map.connect 'note/create', :controller => 'note', :action => 'create'
|
||||
map.connect 'note/update/:id', :controller => 'note', :action => 'update', :id => 'id'
|
||||
map.connect 'note/:id', :controller => 'note', :action => 'show', :id => 'id'
|
||||
map.connect 'notes', :controller => 'note', :action => 'index'
|
||||
map.resources :notes
|
||||
|
||||
# Feed Routes
|
||||
map.connect 'feeds', :controller => 'feedlist', :action => 'index'
|
||||
|
|
|
|||
|
|
@ -2,16 +2,17 @@
|
|||
# migrations feature of ActiveRecord to incrementally modify your database, and
|
||||
# then regenerate this schema definition.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 24) do
|
||||
ActiveRecord::Schema.define(:version => 25) do
|
||||
|
||||
create_table "contexts", :force => true do |t|
|
||||
t.column "name", :string, :default => "", :null => false
|
||||
t.column "position", :integer, :default => 0, :null => false
|
||||
t.column "hide", :boolean, :default => false
|
||||
t.column "user_id", :integer, :default => 1
|
||||
t.column "name", :string, :default => "", :null => false
|
||||
t.column "hide", :integer, :limit => 4, :default => 0, :null => false
|
||||
t.column "position", :integer, :default => 0, :null => false
|
||||
t.column "user_id", :integer, :default => 0, :null => false
|
||||
end
|
||||
|
||||
add_index "contexts", ["user_id"], :name => "index_contexts_on_user_id"
|
||||
add_index "contexts", ["user_id", "name"], :name => "index_contexts_on_user_id_and_name"
|
||||
|
||||
create_table "notes", :force => true do |t|
|
||||
t.column "user_id", :integer, :default => 0, :null => false
|
||||
|
|
@ -61,12 +62,13 @@ ActiveRecord::Schema.define(:version => 24) do
|
|||
create_table "projects", :force => true do |t|
|
||||
t.column "name", :string, :default => "", :null => false
|
||||
t.column "position", :integer, :default => 0, :null => false
|
||||
t.column "user_id", :integer, :default => 1
|
||||
t.column "user_id", :integer, :default => 0, :null => false
|
||||
t.column "description", :text
|
||||
t.column "state", :string, :limit => 20, :default => "active", :null => false
|
||||
end
|
||||
|
||||
add_index "projects", ["user_id"], :name => "index_projects_on_user_id"
|
||||
add_index "projects", ["user_id", "name"], :name => "index_projects_on_user_id_and_name"
|
||||
|
||||
create_table "sessions", :force => true do |t|
|
||||
t.column "session_id", :string
|
||||
|
|
@ -94,16 +96,16 @@ ActiveRecord::Schema.define(:version => 24) do
|
|||
add_index "tags", ["name"], :name => "index_tags_on_name"
|
||||
|
||||
create_table "todos", :force => true do |t|
|
||||
t.column "context_id", :integer, :default => 0, :null => false
|
||||
t.column "project_id", :integer
|
||||
t.column "description", :string, :default => "", :null => false
|
||||
t.column "context_id", :integer, :default => 0, :null => false
|
||||
t.column "description", :string, :limit => 100, :default => "", :null => false
|
||||
t.column "notes", :text
|
||||
t.column "created_at", :datetime
|
||||
t.column "due", :date
|
||||
t.column "completed_at", :datetime
|
||||
t.column "user_id", :integer, :default => 1
|
||||
t.column "project_id", :integer
|
||||
t.column "user_id", :integer, :default => 0, :null => false
|
||||
t.column "show_from", :date
|
||||
t.column "state", :string, :limit => 20, :default => "immediate", :null => false
|
||||
t.column "state", :string, :limit => 20, :default => "immediate", :null => false
|
||||
end
|
||||
|
||||
add_index "todos", ["user_id", "state"], :name => "index_todos_on_user_id_and_state"
|
||||
|
|
@ -113,10 +115,10 @@ ActiveRecord::Schema.define(:version => 24) do
|
|||
add_index "todos", ["user_id", "context_id"], :name => "index_todos_on_user_id_and_context_id"
|
||||
|
||||
create_table "users", :force => true do |t|
|
||||
t.column "login", :string, :limit => 80, :default => "", :null => false
|
||||
t.column "password", :string, :limit => 40, :default => "", :null => false
|
||||
t.column "login", :string, :limit => 80
|
||||
t.column "password", :string, :limit => 40
|
||||
t.column "word", :string
|
||||
t.column "is_admin", :boolean, :default => false, :null => false
|
||||
t.column "is_admin", :integer, :limit => 4, :default => 0, :null => false
|
||||
t.column "first_name", :string
|
||||
t.column "last_name", :string
|
||||
t.column "auth_type", :string, :default => "database", :null => false
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'note_controller'
|
||||
require 'notes_controller'
|
||||
|
||||
# Re-raise errors caught by the controller.
|
||||
class NoteController; def rescue_action(e) raise e end; end
|
||||
class NotesController; def rescue_action(e) raise e end; end
|
||||
|
||||
class NoteControllerTest < Test::Unit::TestCase
|
||||
class NotesControllerTest < Test::Unit::TestCase
|
||||
def setup
|
||||
@controller = NoteController.new
|
||||
@controller = NotesController.new
|
||||
request = ActionController::TestRequest.new
|
||||
response = ActionController::TestResponse.new
|
||||
end
|
||||
5
tracks/test/selenium/notes/link_to_note.rsel
Normal file
5
tracks/test/selenium/notes/link_to_note.rsel
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
setup :fixtures => :all
|
||||
include_partial 'login/login', :username => 'admin', :password => 'abracadabra'
|
||||
open "/projects/Build_a_working_time_machine"
|
||||
click_and_wait "css=#note_1 .show_notes"
|
||||
assert_element_present "note_1"
|
||||
5
tracks/test/selenium/notes/see_all_notes.rsel
Normal file
5
tracks/test/selenium/notes/see_all_notes.rsel
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
setup :fixtures => :all
|
||||
include_partial 'login/login', :username => 'admin', :password => 'abracadabra'
|
||||
open "/notes/"
|
||||
assert_element_present "note_1"
|
||||
assert_element_present "note_2"
|
||||
Loading…
Add table
Add a link
Reference in a new issue