mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-16 23:30:12 +01:00
Adds RSS and TEXT feeds for projects and contexts. fixes #282
git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@238 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
parent
378800218a
commit
ca8a386dd7
9 changed files with 107 additions and 1 deletions
|
|
@ -49,6 +49,18 @@ class FeedController < ApplicationController
|
|||
@headers["Content-Type"] = "text/plain; charset=utf-8"
|
||||
end
|
||||
|
||||
def list_projects_only
|
||||
@projects = @user.projects
|
||||
@description = "Lists all the projects for #{@user.login}."
|
||||
render :action => 'projects_' + @params['feedtype']
|
||||
end
|
||||
|
||||
def list_contexts_only
|
||||
@contexts = @user.contexts
|
||||
@description = "Lists all the contexts for #{@user.login}."
|
||||
render :action => 'contexts_' + @params['feedtype']
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# Check whether the token in the URL matches the word in the User's table
|
||||
|
|
|
|||
|
|
@ -27,4 +27,30 @@ module FeedHelper
|
|||
return result_string
|
||||
end
|
||||
|
||||
def build_projects_text_page(projects)
|
||||
result_string = ""
|
||||
projects.each do |p|
|
||||
result_string << "\n" + p.name.upcase + "\n"
|
||||
|
||||
result_string << p.description + "\n" if p.description_present?
|
||||
result_string << "#{p.count_undone_todos}. Project is #{p.done ? 'Done' : 'Active'}.\n"
|
||||
result_string << "#{p.linkurl}\n" if p.linkurl_present?
|
||||
result_string << "\n"
|
||||
end
|
||||
|
||||
return result_string
|
||||
end
|
||||
|
||||
def build_contexts_text_page(contexts)
|
||||
result_string = ""
|
||||
contexts.each do |c|
|
||||
result_string << "\n" + c.name.upcase + "\n"
|
||||
|
||||
result_string << "#{c.count_undone_todos}. Context is #{c.hidden? ? 'Hidden' : 'Active'}.\n"
|
||||
result_string << "\n"
|
||||
end
|
||||
|
||||
return result_string
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -17,6 +17,14 @@ class Project < ActiveRecord::Base
|
|||
find(:all, :conditions => [ "done = ?" , true ], :order => "position ASC")
|
||||
end
|
||||
|
||||
def description_present?
|
||||
attribute_present?("description")
|
||||
end
|
||||
|
||||
def linkurl_present?
|
||||
attribute_present?("linkurl")
|
||||
end
|
||||
|
||||
def find_not_done_todos
|
||||
todos = Todo.find :all, :conditions => ["project_id = #{id} AND done = ?", false],
|
||||
:order => "due IS NULL, due ASC, created_at ASC"
|
||||
|
|
@ -27,7 +35,7 @@ class Project < ActiveRecord::Base
|
|||
:order => "due IS NULL, due ASC, created_at ASC",
|
||||
:limit => @user.preferences["no_completed"].to_i
|
||||
end
|
||||
|
||||
|
||||
# Returns a count of next actions in the given project
|
||||
# The result is count and a string descriptor, correctly pluralised if there are no
|
||||
# actions or multiple actions
|
||||
|
|
|
|||
19
tracks/app/views/feed/contexts_rss.rxml
Normal file
19
tracks/app/views/feed/contexts_rss.rxml
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
@headers["Content-Type"] = "text/xml; charset=utf-8"
|
||||
xml.rss("version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/") do
|
||||
xml.channel do
|
||||
xml.title(@title)
|
||||
xml.link("http://#{@request.host}:#{@request.port}/contexts")
|
||||
xml.description(@description)
|
||||
@contexts.each { |c|
|
||||
xml.item do
|
||||
xml.title(c.name)
|
||||
xml.link(url_for(:only_path => false, :controller => 'context', :action => 'show', :name => urlize(c.name)))
|
||||
context_description = ''
|
||||
context_description += "<p>#{c.count_undone_todos}. "
|
||||
context_description += "Context is #{c.hidden? ? 'Hidden' : 'Active'}. "
|
||||
context_description += "</p>"
|
||||
xml.description(context_description)
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
2
tracks/app/views/feed/contexts_text.rhtml
Normal file
2
tracks/app/views/feed/contexts_text.rhtml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
<% @headers["Content-Type"] = "text/plain; charset=utf-8" -%>
|
||||
<%= build_contexts_text_page( @contexts ) -%>
|
||||
21
tracks/app/views/feed/projects_rss.rxml
Normal file
21
tracks/app/views/feed/projects_rss.rxml
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
@headers["Content-Type"] = "text/xml; charset=utf-8"
|
||||
xml.rss("version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/") do
|
||||
xml.channel do
|
||||
xml.title(@title)
|
||||
xml.link("http://#{@request.host}:#{@request.port}/projects")
|
||||
xml.description(@description)
|
||||
@projects.each { |p|
|
||||
xml.item do
|
||||
xml.title(p.name)
|
||||
xml.link(url_for(:only_path => false, :controller => 'project', :action => 'show', :name => urlize(p.name)))
|
||||
project_description = ''
|
||||
project_description += sanitize(markdown( p.description )) if p.description_present?
|
||||
project_description += "<p>#{p.count_undone_todos}. "
|
||||
project_description += "Project is #{p.done ? 'Done' : 'Active'}. "
|
||||
project_description += "<a href=\"#{p.linkurl}\">#{p.linkurl}</a>" if p.linkurl_present?
|
||||
project_description += "</p>"
|
||||
xml.description(project_description)
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
2
tracks/app/views/feed/projects_text.rhtml
Normal file
2
tracks/app/views/feed/projects_text.rhtml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
<% @headers["Content-Type"] = "text/plain; charset=utf-8" -%>
|
||||
<%= build_projects_text_page( @projects ) -%>
|
||||
|
|
@ -41,6 +41,16 @@
|
|||
<%= ical_feed_link({ :due => 6 }) %>
|
||||
Actions due in 7 days or earlier
|
||||
</li>
|
||||
<li>
|
||||
<%= rss_feed_link({ :action => 'list_contexts_only', :feedtype => 'rss' }) %>
|
||||
<%= text_feed_link({ :action => 'list_contexts_only', :feedtype => 'text' }) %>
|
||||
All Contexts
|
||||
</li>
|
||||
<li>
|
||||
<%= rss_feed_link({ :action => 'list_projects_only', :feedtype => 'rss' }) %>
|
||||
<%= text_feed_link({ :action => 'list_projects_only', :feedtype => 'text' }) %>
|
||||
All Projects
|
||||
</li>
|
||||
<li><h4>Feeds for uncompleted actions in a specific context:</h4>
|
||||
<ul>
|
||||
<% for context in @contexts %>
|
||||
|
|
|
|||
|
|
@ -31,17 +31,23 @@ ActionController::Routing::Routes.draw do |map|
|
|||
map.connect 'context/add_item', :controller => 'context', :action => 'add_item'
|
||||
map.connect 'context/order', :controller => 'context', :action => 'order'
|
||||
map.connect 'context/:id', :controller=> 'context', :action => 'show', :requirements => {:id => /\d+/}
|
||||
map.connect 'context/:context/feed/:action/:name/:token', :controller => 'feed'
|
||||
map.connect 'context/:name', :controller => 'context', :action => 'show'
|
||||
|
||||
map.connect 'contexts', :controller => 'context', :action => 'list'
|
||||
map.connect 'contexts/feed/:feedtype/:name/:token', :controller => 'feed', :action => 'list_contexts_only'
|
||||
|
||||
# Projects Routes
|
||||
map.connect 'project/new_project', :controller => 'project', :action => 'new_project'
|
||||
map.connect 'project/add_item/:id', :controller => 'project', :action => 'add_item'
|
||||
map.connect 'project/toggle_check/:id', :controller => 'project', :action => 'toggle_check'
|
||||
map.connect 'project/order', :controller => 'project', :action => 'order'
|
||||
map.connect 'project/:project/feed/:action/:name/:token', :controller => 'feed'
|
||||
map.connect 'project/:id', :controller => 'project', :action => 'show', :requirements => {:id => /\d+/}
|
||||
map.connect 'project/:name', :controller => 'project', :action => 'show'
|
||||
|
||||
map.connect 'projects', :controller => 'project', :action => 'list'
|
||||
map.connect 'projects/feed/:feedtype/:name/:token', :controller => 'feed', :action => 'list_projects_only'
|
||||
|
||||
# Notes Routes
|
||||
map.connect 'note/add', :controller => 'note', :action => 'add'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue