You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by as...@apache.org on 2008/05/16 02:02:38 UTC

svn commit: r656897 - in /ode/sandbox/singleshot: app/controllers/ app/models/ app/views/activities/ config/

Author: assaf
Date: Thu May 15 17:02:37 2008
New Revision: 656897

URL: http://svn.apache.org/viewvc?rev=656897&view=rev
Log:
Activity stream now has Atom feed and iCal.

Added:
    ode/sandbox/singleshot/app/views/activities/show.atom.builder
    ode/sandbox/singleshot/app/views/activities/show.ics.erb
Modified:
    ode/sandbox/singleshot/app/controllers/activities_controller.rb
    ode/sandbox/singleshot/app/controllers/application.rb
    ode/sandbox/singleshot/app/models/activity.rb
    ode/sandbox/singleshot/app/views/activities/show.html.erb
    ode/sandbox/singleshot/config/routes.rb

Modified: ode/sandbox/singleshot/app/controllers/activities_controller.rb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/controllers/activities_controller.rb?rev=656897&r1=656896&r2=656897&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/controllers/activities_controller.rb (original)
+++ ode/sandbox/singleshot/app/controllers/activities_controller.rb Thu May 15 17:02:37 2008
@@ -1,7 +1,19 @@
 class ActivitiesController < ApplicationController
 
+  prepend_before_filter :authenticate_with_access_key, :unless=>lambda { |controller| controller.request.format.html? }
+
   def show
-    @days = Activity.for_stakeholder(authenticated).by_day
+    @alternate = { Mime::ATOM=>formatted_activity_url(:format=>:atom, :access_key=>authenticated.access_key),
+                   Mime::ICS=>formatted_activity_url(:format=>:ics, :access_key=>authenticated.access_key) }
+    @activities = Activity.for_stakeholder(authenticated)
+    day = Date.new(params[:year].to_i, params[:month].to_i, params[:day].to_i) rescue nil if params[:year]
+    dates = day ? day..day + 1.day : Date.today - 3.day..Date.today + 1.day
+    @activities = @activities.for_dates(dates)
+    respond_to do |want|
+      want.html { @days = @activities.by_day }
+      want.atom
+      want.ics
+    end
   end
 
 end

Modified: ode/sandbox/singleshot/app/controllers/application.rb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/controllers/application.rb?rev=656897&r1=656896&r2=656897&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/controllers/application.rb (original)
+++ ode/sandbox/singleshot/app/controllers/application.rb Thu May 15 17:02:37 2008
@@ -17,6 +17,7 @@
   # Authentication filter, added by default on all actions in all controllers.
   # Uses HTTP Basic Authentication or, when processing HTML/AJAX requests, sessions.
   def authenticate
+    return if @authenticated
     if ActionController::HttpAuthentication::Basic.authorization(request) || !session_enabled?
       authenticate_or_request_with_http_basic request.domain do |login, password|
         @authenticated = Person.authenticate(login, password)

Modified: ode/sandbox/singleshot/app/models/activity.rb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/models/activity.rb?rev=656897&r1=656896&r2=656897&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/models/activity.rb (original)
+++ ode/sandbox/singleshot/app/models/activity.rb Thu May 15 17:02:37 2008
@@ -35,7 +35,7 @@
   named_scope :for_stakeholder, lambda { |person|
     { :joins=>'JOIN stakeholders AS involved ON involved.task_id=tasks.id',
       :conditions=>["involved.person_id=? AND involved.role != 'excluded'", person.id],
-      :include=>[:task, :person], :order=>'activities.created_at' }
+      :include=>[:task, :person], :order=>'activities.created_at DESC' }
   } do
     def by_day
       self.inject([]) { |days, activity|
@@ -47,6 +47,7 @@
       }
     end
   end
+  named_scope :for_dates, lambda { |dates| { :conditions=>{ :created_at=>dates } } }
 
 end
 

Added: ode/sandbox/singleshot/app/views/activities/show.atom.builder
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/views/activities/show.atom.builder?rev=656897&view=auto
==============================================================================
--- ode/sandbox/singleshot/app/views/activities/show.atom.builder (added)
+++ ode/sandbox/singleshot/app/views/activities/show.atom.builder Thu May 15 17:02:37 2008
@@ -0,0 +1,14 @@
+atom_feed :root_url=>activity_url do |feed|
+  feed.title 'Singleshot: Activities'
+  feed.updated @activities.first.created_at
+
+  for activity in @activities
+    feed.entry activity, :url=>task_url(activity.task) do |entry|
+      entry.title "#{activity.person.fullname} #{activity.action} #{activity.task.title}"
+      entry.content :type=>'html' do |content|
+        content.text! "<p>#{link_to h(activity.person.fullname), activity.person.identity} #{activity.action} #{link_to h(activity.task.title), task_url(activity.task)}</p>"
+        content.text! "<p>#{h(activity.task.description)}</p>"
+      end
+    end
+  end
+end

Modified: ode/sandbox/singleshot/app/views/activities/show.html.erb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/views/activities/show.html.erb?rev=656897&r1=656896&r2=656897&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/views/activities/show.html.erb (original)
+++ ode/sandbox/singleshot/app/views/activities/show.html.erb Thu May 15 17:02:37 2008
@@ -1,8 +1,8 @@
 <ol class='activities'>
-  <% @days.each do |day| %>
+  <% for day in @days %>
     <li class='day'>
       <h3><%= day.first.to_formatted_s(:long) %></h3>
-      <% day.last.each do |activity|  %>
+      <% for activity in day.last %>
         <% content_tag_for 'li', activity do %>
           <%= link_to activity.person.fullname, activity.person.identity %>
           <%= activity.action %>

Added: ode/sandbox/singleshot/app/views/activities/show.ics.erb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/views/activities/show.ics.erb?rev=656897&view=auto
==============================================================================
--- ode/sandbox/singleshot/app/views/activities/show.ics.erb (added)
+++ ode/sandbox/singleshot/app/views/activities/show.ics.erb Thu May 15 17:02:37 2008
@@ -0,0 +1,11 @@
+BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Apache Software Foundation//NONSGML Singleshot//EN
+<% for activity in @activities %>
+BEGIN:VEVENT
+DTSTART:<%= activity.created_at.strftime('%Y%m%dT%H%M%S') %>
+SUMMARY:<%= "#{activity.person.fullname} #{activity.action} #{activity.task.title}" %>
+URL:<%= task_url(activity.task) %>
+END:VEVENT
+<% end %>
+END:VCALENDAR

Modified: ode/sandbox/singleshot/config/routes.rb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/config/routes.rb?rev=656897&r1=656896&r2=656897&view=diff
==============================================================================
--- ode/sandbox/singleshot/config/routes.rb (original)
+++ ode/sandbox/singleshot/config/routes.rb Thu May 15 17:02:37 2008
@@ -3,6 +3,7 @@
   map.resource 'session'
   map.resources 'tasks', :collection=>{ 'following'=>:get, 'completed'=>:get }
   map.resource 'activity'
+  map.day_activity 'activity/:year/:month/:day', :controller=>'activities', :action=>'show', :year =>/\d{4}/, :month=>/\d{1,2}/, :day=>/\d{1,2}/
   map.root :controller=>'tasks'
   map.resource 'sandwich'
   #map.connect ':controller/:action/:id'