Author: assaf
Date: Thu May 15 12:42:45 2008
New Revision: 656808

URL: http://svn.apache.org/viewvc?rev=656808&view=rev
Log:
Added preliminary activity stream.

Added:
    ode/sandbox/singleshot/app/controllers/activities_controller.rb
    ode/sandbox/singleshot/app/models/activity.rb
    ode/sandbox/singleshot/app/views/activities/
    ode/sandbox/singleshot/app/views/activities/show.html.erb
    ode/sandbox/singleshot/db/migrate/20080506015153_activities.rb
      - copied, changed from r656512, 
ode/sandbox/singleshot/db/migrate/20080506015153_events.rb
Removed:
    ode/sandbox/singleshot/db/migrate/20080506015153_events.rb
Modified:
    ode/sandbox/singleshot/app/models/task.rb
    ode/sandbox/singleshot/app/views/layouts/application.html.erb
    ode/sandbox/singleshot/config/routes.rb
    ode/sandbox/singleshot/db/schema.rb
    ode/sandbox/singleshot/lib/tasks/database.rake
    ode/sandbox/singleshot/public/stylesheets/default.css

Added: ode/sandbox/singleshot/app/controllers/activities_controller.rb
URL: 
http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/controllers/activities_controller.rb?rev=656808&view=auto
==============================================================================
--- ode/sandbox/singleshot/app/controllers/activities_controller.rb (added)
+++ ode/sandbox/singleshot/app/controllers/activities_controller.rb Thu May 15 
12:42:45 2008
@@ -0,0 +1,7 @@
+class ActivitiesController < ApplicationController
+
+  def show
+    @days = Activity.for_stakeholder(authenticated).by_day
+  end
+
+end

Added: ode/sandbox/singleshot/app/models/activity.rb
URL: 
http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/models/activity.rb?rev=656808&view=auto
==============================================================================
--- ode/sandbox/singleshot/app/models/activity.rb (added)
+++ ode/sandbox/singleshot/app/models/activity.rb Thu May 15 12:42:45 2008
@@ -0,0 +1,52 @@
+class Activity < ActiveRecord::Base
+
+  class << self
+
+    def from_changes_to(task)
+      returning [] do |activities|
+        if task.changes['state']
+          from, to = *task.changes['state']
+          activities << new(:action=>'created', :person=>task.creator) if 
task.creator && from.nil? || from == 'reserved'
+          activities << new(:action=>'resumed') if from == 'suspended'
+          case to
+          when 'ready'
+          when 'active'
+            activities << new(:action=>'own', :person=>task.owner)
+          when 'suspended'
+            activities << new(:action=>'suspended')
+          when 'completed'
+            activities << new(:action=>'completed', :person=>task.owner)
+          when 'cancelled'
+            activities << new(:action=>'cancelled')
+          end
+        else
+          activities << new(:action=>'modified')
+        end
+      end
+    end
+
+  end
+
+  belongs_to :person
+  belongs_to :task
+
+  attr_readonly :person, :task, :action
+
+  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' }
+  } do
+    def by_day
+      self.inject([]) { |days, activity|
+        created = activity.created_at.to_date
+        day = days.last if days.last && days.last.first == created
+        days << (day = [created, []]) unless day
+        day.last << activity
+        days
+      }
+    end
+  end
+
+end
+

Modified: ode/sandbox/singleshot/app/models/task.rb
URL: 
http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/models/task.rb?rev=656808&r1=656807&r2=656808&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/models/task.rb (original)
+++ ode/sandbox/singleshot/app/models/task.rb Thu May 15 12:42:45 2008
@@ -161,6 +161,7 @@
     end
   end
 
+
   # --- Priority and ordering ---
   
   # Task priority: 1 is the lowest (and default) priority.
@@ -172,6 +173,24 @@
     due_on && due_on < Date.today
   end
 
+
+  # --- Activities ---
+
+  after_save do |task|
+    task.activities =  Activity.from_changes_to(task) unless task.state == 
'reserved'
+  end
+
+  attr_accessor :activities
+
+  def save(person = nil)
+    super
+    activities.each do |activity|
+      activity.task = self
+      activity.person ||= person
+      activity.save if activity.person
+    end if activities
+  end
+
  
   # --- Completion and cancellation ---
 

Added: 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=656808&view=auto
==============================================================================
--- ode/sandbox/singleshot/app/views/activities/show.html.erb (added)
+++ ode/sandbox/singleshot/app/views/activities/show.html.erb Thu May 15 
12:42:45 2008
@@ -0,0 +1,14 @@
+<ol class='activities'>
+  <% @days.each do |day| %>
+    <li class='day'>
+      <h3><%= day.first.to_formatted_s(:long) %></h3>
+      <% day.last.each do |activity|  %>
+        <% content_tag_for 'li', activity do %>
+          <%= link_to activity.person.fullname, activity.person.identity %>
+          <%= activity.action %>
+          <%= link_to activity.task.title, task_url(activity.task) %>
+        <% end %>
+      <% end %>
+    </li>
+  <% end %>
+</ol>

Modified: ode/sandbox/singleshot/app/views/layouts/application.html.erb
URL: 
http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/views/layouts/application.html.erb?rev=656808&r1=656807&r2=656808&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/views/layouts/application.html.erb (original)
+++ ode/sandbox/singleshot/app/views/layouts/application.html.erb Thu May 15 
12:42:45 2008
@@ -20,7 +20,7 @@
         <li><%= link_to '➠ Tasks', tasks_url %></li>
         <li><%= link_to 'Following', following_tasks_url %></a></li>
         <li><%= link_to 'Completed', completed_tasks_url %></a></li>
-        <li><a href='#'>Activity</a></li>
+        <li><%= link_to 'Activity', activity_url %></a></li>
         <li><a href='#'>Start &hellip;</a></li>
       </ul>
     </div>

Modified: ode/sandbox/singleshot/config/routes.rb
URL: 
http://svn.apache.org/viewvc/ode/sandbox/singleshot/config/routes.rb?rev=656808&r1=656807&r2=656808&view=diff
==============================================================================
--- ode/sandbox/singleshot/config/routes.rb (original)
+++ ode/sandbox/singleshot/config/routes.rb Thu May 15 12:42:45 2008
@@ -2,6 +2,7 @@
 
   map.resource 'session'
   map.resources 'tasks', :collection=>{ 'following'=>:get, 'completed'=>:get }
+  map.resource 'activity'
   map.root :controller=>'tasks'
   map.resource 'sandwich'
   #map.connect ':controller/:action/:id'

Copied: ode/sandbox/singleshot/db/migrate/20080506015153_activities.rb (from 
r656512, ode/sandbox/singleshot/db/migrate/20080506015153_events.rb)
URL: 
http://svn.apache.org/viewvc/ode/sandbox/singleshot/db/migrate/20080506015153_activities.rb?p2=ode/sandbox/singleshot/db/migrate/20080506015153_activities.rb&p1=ode/sandbox/singleshot/db/migrate/20080506015153_events.rb&r1=656512&r2=656808&rev=656808&view=diff
==============================================================================
--- ode/sandbox/singleshot/db/migrate/20080506015153_events.rb (original)
+++ ode/sandbox/singleshot/db/migrate/20080506015153_activities.rb Thu May 15 
12:42:45 2008
@@ -1,6 +1,6 @@
-class Events < ActiveRecord::Migration
+class Activities < ActiveRecord::Migration
   def self.up
-    create_table 'events' do |t|
+    create_table 'activities' do |t|
       t.integer 'person_id',   :null=>false
       t.integer 'task_id',     :null=>false
       t.string  'action',      :null=>false
@@ -9,6 +9,6 @@
   end
 
   def self.down
-    drop_table 'events'
+    drop_table 'activities'
   end
 end

Modified: ode/sandbox/singleshot/db/schema.rb
URL: 
http://svn.apache.org/viewvc/ode/sandbox/singleshot/db/schema.rb?rev=656808&r1=656807&r2=656808&view=diff
==============================================================================
--- ode/sandbox/singleshot/db/schema.rb (original)
+++ ode/sandbox/singleshot/db/schema.rb Thu May 15 12:42:45 2008
@@ -11,7 +11,7 @@
 
 ActiveRecord::Schema.define(:version => 20080506015153) do
 
-  create_table "events", :force => true do |t|
+  create_table "activities", :force => true do |t|
     t.integer  "person_id",  :null => false
     t.integer  "task_id",    :null => false
     t.string   "action",     :null => false

Modified: ode/sandbox/singleshot/lib/tasks/database.rake
URL: 
http://svn.apache.org/viewvc/ode/sandbox/singleshot/lib/tasks/database.rake?rev=656808&r1=656807&r2=656808&view=diff
==============================================================================
--- ode/sandbox/singleshot/lib/tasks/database.rake (original)
+++ ode/sandbox/singleshot/lib/tasks/database.rake Thu May 15 12:42:45 2008
@@ -18,31 +18,37 @@
     puts "Populating database for #{you.identity}"
     url = 'http://localhost:3001/sandwhich'
     other = Person.identify('anon') || Person.create(:email=>'[EMAIL 
PROTECTED]')
-    default = lambda { |attributes| { :title=>Faker::Lorem.sentence, 
:description=>Faker::Lorem.paragraph,
-                                      :frame_url=>url, :state=>'ready' 
}.merge(attributes || {}) }
+    create = lambda do |attributes|
+      attributes = { :title=>Faker::Lorem.sentence, 
:description=>Faker::Lorem.paragraph,
+                     :frame_url=>url, :state=>'ready' }.merge(attributes || {})
+      task = Task.new(attributes)
+      task.save(you)
+    end
+    #create = lambda { |attributes| { :title=>Faker::Lorem.sentence, 
:description=>Faker::Lorem.paragraph,
+    #                                  :frame_url=>url, :state=>'ready' 
}.merge(attributes || {}) }
 
     # Tasks you should not see.
-    Task.create! default[:title=>'You will not see this task since this task 
is reserved.', :state=>'reserved', :creator=>you]
-    Task.create! default[:title=>'You will not see this task since you are not 
a stakeholder.']
+    create[:title=>'You will not see this task since this task is reserved.', 
:state=>'reserved', :creator=>you]
+    create[:title=>'You will not see this task since you are not a 
stakeholder.']
     # Tasks in which we are:
     # - creator
     # - owner
     # - observer
     # - admin
-    Task.create! default[:creator=>you]
-    Task.create! default[:owner=>you]
-    Task.create! default[:observers=>you]
-    Task.create! default[:admins=>you]
+    create[:creator=>you]
+    create[:owner=>you]
+    create[:observers=>you]
+    create[:admins=>you]
     # Tasks in which we are only or one of many potential owners.
-    Task.create! default[:potential_owners=>you]
-    Task.create! default[:potential_owners=>[you, other]]
-    Task.create! default[:title=>'Invisible', :owner=>other, 
:potential_owners=>you]
+    create[:potential_owners=>you]
+    create[:potential_owners=>[you, other]]
+    create[:owner=>other, :potential_owners=>you]
     # High priority should show first.
-    Task.create! default[:owner=>you, :priority=>3]
+    create[:owner=>you, :priority=>3]
     # Over-due before due today before anything else.
-    Task.create! default[:owner=>you, :due_on=>Time.today - 1.day]
-    Task.create! default[:owner=>you, :due_on=>Time.today]
-    Task.create! default[:owner=>you, :due_on=>Time.today + 1.day]
+    create[:owner=>you, :due_on=>Time.today - 1.day]
+    create[:owner=>you, :due_on=>Time.today]
+    create[:owner=>you, :due_on=>Time.today + 1.day]
   end
 
 end

Modified: ode/sandbox/singleshot/public/stylesheets/default.css
URL: 
http://svn.apache.org/viewvc/ode/sandbox/singleshot/public/stylesheets/default.css?rev=656808&r1=656807&r2=656808&view=diff
==============================================================================
--- ode/sandbox/singleshot/public/stylesheets/default.css (original)
+++ ode/sandbox/singleshot/public/stylesheets/default.css Thu May 15 12:42:45 
2008
@@ -246,6 +246,19 @@
 }
 
 
+ol.activities {
+  list-style: none;
+  margin: 2em 3.5em 0 3.5em;
+  padding: 0;
+}
+ol.activities li.day h3 {
+  border-bottom: 1px solid #ccc;
+}
+ol.activities li.activity {
+  margin: 0 0 0.5em 0;
+}
+
+
 form.button-to, form.button-to div {
   display: inline;
 }


Reply via email to