The projects controller gets more RESTy. It now supports XML, RSS, ATOM, HTML and plain text views of the projects list.

Changes include:

 * Add assert_xml_select method for testing RSS and ATOM results (Thanks, Jamis! http://weblog.jamisbuck.org/2007/1/4/assert_xml_select)
 * Add resource_feeder plugin for generating RSS and ATOM feeds
 * Update the URL on the Feeds page to use /projects.rss or /projects.txt instead of FeedController link
 * Add created_at and updated_at timestamps to project table to support ATOM feeds
 * Added new filter to login_system "login_or_feed_token_required" to allow RSS, ATOM or text requests with token-based authentication 
 
Notes:
 * This will break previous project listing feed subscriptions.
 * RSS, ATOM & text feeds are available via session or HTTP_BASIC authentication, or by passing the user's token on the url; HTML and XML results are only available via session or HTTP_BASIC authentication
 


git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@415 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
lukemelia 2007-02-01 05:32:05 +00:00
parent fda7788237
commit d9d5ff4d06
35 changed files with 735 additions and 94 deletions

View file

@ -62,6 +62,26 @@ class ApplicationController < ActionController::Base
end
end
# Returns a count of next actions in the given context or project
# The result is count and a string descriptor, correctly pluralised if there are no
# actions or multiple actions
#
def count_undone_todos(todos_parent, string="actions")
if (todos_parent.is_a?(Project) && todos_parent.hidden?)
count = eval "@project_project_hidden_todo_counts[#{todos_parent.id}]"
else
count = eval "@#{todos_parent.class.to_s.downcase}_not_done_counts[#{todos_parent.id}]"
end
count = 0 if count == nil
#count = todos_parent.todos.select{|t| !t.done }.size
if count == 1
word = string.singularize
else
word = string.pluralize
end
return count.to_s + " " + word
end
protected
def admin_login_required
@ -101,7 +121,7 @@ class ApplicationController < ActionController::Base
parents.each do |parent|
eval("@#{parent}_project_hidden_todo_counts = Todo.count(:conditions => ['user_id = ? and state = ?', @user.id, 'project_hidden'], :group => :#{parent}_id)")
end
end
end
# Set the contents of the flash message from a controller
# Usage: notify :warning, "This is the message"

View file

@ -45,14 +45,6 @@ class FeedController < ApplicationController
end
headers["Content-Type"] = "text/calendar"
end
def list_projects_only
init_not_done_counts('project')
init_project_hidden_todo_counts
@projects = @user.projects
@description = "Lists all the projects for #{@user.login}."
render :action => 'projects_' + params['feedtype']
end
def list_contexts_only
init_not_done_counts('context')

View file

@ -1,14 +1,31 @@
class ProjectsController < ApplicationController
helper :todos, :notes
helper :application, :todos, :notes
before_filter :init, :except => [:create, :destroy, :order]
skip_before_filter :login_required, :only => [:index]
prepend_before_filter :login_or_feed_token_required, :only => [:index]
session :off, :only => :index, :if => Proc.new { |req| ['rss','atom','txt'].include?(req.parameters[:format]) }
def index
init_project_hidden_todo_counts
@page_title = "TRACKS::List Projects"
respond_to do |wants|
wants.html
wants.xml { render :xml => @projects.to_xml( :except => :user_id ) }
respond_to do |format|
format.html do
init_project_hidden_todo_counts
@page_title = "TRACKS::List Projects"
render
end
format.xml { render :xml => @projects.to_xml( :except => :user_id ) }
format.rss do
render_rss_feed_for @projects, :feed => Project.feed_options(@user),
:item => { :description => lambda { |p| p.summary(count_undone_todos(p)) } }
end
format.atom do
render_atom_feed_for @projects, :feed => Project.feed_options(@user),
:item => { :description => lambda { |p| p.summary(count_undone_todos(p)) },
:author => lambda { |p| nil } }
end
format.text do
render :action => 'index_text', :layout => false, :content_type => Mime::TEXT
end
end
end

View file

@ -12,6 +12,7 @@ class UsersController < ApplicationController
# GET /users
# GET /users.xml
def index
@users = User.find(:all, :order => 'login')
respond_to do |format|
format.html do
@page_title = "TRACKS::Manage Users"
@ -21,10 +22,7 @@ class UsersController < ApplicationController
# we store the URL so that we get returned here when signup is successful
store_location
end
format.xml do
@users = User.find(:all)
render :xml => @users.to_xml(:except => [ :password ])
end
format.xml { render :xml => @users.to_xml(:except => [ :password ]) }
end
end