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/08/12 03:13:27 UTC

svn commit: r685014 - in /ode/sandbox/singleshot: app/controllers/ app/models/ app/views/activity/ app/views/layouts/ config/ config/initializers/ spec/models/

Author: assaf
Date: Mon Aug 11 18:13:26 2008
New Revision: 685014

URL: http://svn.apache.org/viewvc?rev=685014&view=rev
Log:
Added: next/previous meta-links in page layout.
Added: next/previous pagination links in activity list (Atom).
Added: /activity/recent to show recent activity on all tasks.
Changed: Group activities by day (no clever grouping by week/month).
Added: MIME type OSD for OpenSearch descriptor.

Modified:
    ode/sandbox/singleshot/app/controllers/activity_controller.rb
    ode/sandbox/singleshot/app/controllers/tasks_controller.rb
    ode/sandbox/singleshot/app/models/activity.rb
    ode/sandbox/singleshot/app/views/activity/index.atom.builder
    ode/sandbox/singleshot/app/views/activity/index.html.erb
    ode/sandbox/singleshot/app/views/layouts/application.html.erb
    ode/sandbox/singleshot/app/views/layouts/head.html.erb
    ode/sandbox/singleshot/config/initializers/mime_types.rb
    ode/sandbox/singleshot/config/routes.rb
    ode/sandbox/singleshot/spec/models/activity_spec.rb

Modified: ode/sandbox/singleshot/app/controllers/activity_controller.rb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/controllers/activity_controller.rb?rev=685014&r1=685013&r2=685014&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/controllers/activity_controller.rb (original)
+++ ode/sandbox/singleshot/app/controllers/activity_controller.rb Mon Aug 11 18:13:26 2008
@@ -25,6 +25,8 @@
                    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).with_dependents.paginate(:page=>params['page'], :per_page=>50)
+    @next = activity_url(:page=>@activities.next_page) if @activities.next_page
+    @previous = activity_url(:page=>@activities.previous_page) if @activities.previous_page
     respond_to do |want|
       want.html do
         @graph = Activity.for_stakeholder(authenticated).for_dates(Date.current - 1.month)
@@ -34,19 +36,13 @@
     end
   end
 
-  def for_task
-    @task = Task.for_stakeholder(authenticated).find(params[:task_id], :include=>:activities)
-    @activities = @task.activities
-    @title = "Activities - #{@task.title}"
-    @subtitle = "Track all activities in the task #{@task.title}"
-    @alternate = { Mime::HTML=>task_activity_url(@task),
-                   Mime::ATOM=>formatted_task_activity_url(@task, :format=>:atom, :access_key=>authenticated.access_key),
-                   Mime::ICS=>formatted_task_activity_url(@task, :format=>:ics, :access_key=>authenticated.access_key) }
-    respond_to do |want|
-      want.html { @graph = @activities ; render :action=>'index' }
-      want.atom { render :action=>'index' }
-      want.ics  { render :action=>'index' }
-    end
+  # TODO: Need admin verification filter.  
+  def recent
+    @title = 'Recently added activities'
+    @subtitle = 'Recently added activities on all tasks.'
+    @activities = Activity.recently_added.with_dependents.paginate(:page=>params['page'], :per_page=>50)
+    @next = recent_activity_url(:page=>@activities.next_page) if @activities.next_page
+    @previous = recent_activity_url(:page=>@activities.previous_page) if @activities.previous_page
   end
-
+  
 end

Modified: ode/sandbox/singleshot/app/controllers/tasks_controller.rb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/controllers/tasks_controller.rb?rev=685014&r1=685013&r2=685014&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/controllers/tasks_controller.rb (original)
+++ ode/sandbox/singleshot/app/controllers/tasks_controller.rb Mon Aug 11 18:13:26 2008
@@ -133,6 +133,20 @@
       @task.cancel!
     head :ok
   end
+  
+  def activities
+    @activities = @task.activities
+    @title = "Activities - #{@task.title}"
+    @subtitle = "Track all activities in the task #{@task.title}"
+    @alternate = { Mime::HTML=>task_activity_url(@task),
+                   Mime::ATOM=>formatted_task_activity_url(@task, :format=>:atom, :access_key=>authenticated.access_key),
+                   Mime::ICS=>formatted_task_activity_url(@task, :format=>:ics, :access_key=>authenticated.access_key) }
+    respond_to do |want|
+      want.html { @graph = @activities ; render :action=>'index' }
+      want.atom { render :action=>'index' }
+      want.ics  { render :action=>'index' }
+    end
+  end
 
 private
 

Modified: ode/sandbox/singleshot/app/models/activity.rb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/models/activity.rb?rev=685014&r1=685013&r2=685014&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/models/activity.rb (original)
+++ ode/sandbox/singleshot/app/models/activity.rb Mon Aug 11 18:13:26 2008
@@ -54,4 +54,7 @@
     end
     { :conditions=>{ :created_at=>range } } }
 
+  # Returns activities by recently added order.
+  named_scope :recently_added, :order=>'created_at desc'
+
 end

Modified: ode/sandbox/singleshot/app/views/activity/index.atom.builder
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/views/activity/index.atom.builder?rev=685014&r1=685013&r2=685014&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/views/activity/index.atom.builder (original)
+++ ode/sandbox/singleshot/app/views/activity/index.atom.builder Mon Aug 11 18:13:26 2008
@@ -2,6 +2,8 @@
   feed.title "Singleshot: #{@title}"
   feed.subtitle @subtitle
   feed.updated @activities.first.created_at unless @activities.empty?
+  feed.link :href=>@next, :rel=>'next', :type=>Mime::ATOM if @next
+  feed.link :href=>@previous, :rel=>'previous', :type=>Mime::ATOM if @previous
   feed.link :href=>@alternate[Mime::ICS], :rel=>'alternate', :type=>Mime::ICS if @alternate[Mime::ICS]
   feed.generator 'Singleshot', :version=>Singleshot::VERSION
 

Modified: ode/sandbox/singleshot/app/views/activity/index.html.erb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/views/activity/index.html.erb?rev=685014&r1=685013&r2=685014&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/views/activity/index.html.erb (original)
+++ ode/sandbox/singleshot/app/views/activity/index.html.erb Mon Aug 11 18:13:26 2008
@@ -1,11 +1,13 @@
-<% graph = @graph.group_by { |activity| activity.created_at.to_date }
-   range = graph.last.first..Date.current %>
-<div class='right'><%= sparkline_tag range.map { |date| graph[date] ? graph[date].size : 0 },
-                                     :title=>'Level of activity for each day' unless graph.empty?  %></div>
+<%  if @graph
+      graph = @graph.group_by { |activity| activity.created_at.to_date }
+      range = graph.last.first..Date.current %>
+      <div class='right'><%= sparkline_tag range.map { |date| graph[date] ? graph[date].size : 0 },
+                                           :title=>'Level of activity for each day' unless graph.empty?  %></div>
+<%  end %>
 <ol class='dates hfeed'>
-  <% for date, activities in group_by_dates(@activities, :created_at) %>
+  <% for date, activities in @activities.group_by{ |a| a.created_at.to_date } %>
     <li class='date'>
-      <h2><%= date.humanize %></h2>
+      <h2><%= relative_date(date).humanize %></h2>
       <%= render :partial=>'activities', :locals=>{ :activities=>activities, :today=>nil } %>
     </li>
   <% end %>

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=685014&r1=685013&r2=685014&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/views/layouts/application.html.erb (original)
+++ ode/sandbox/singleshot/app/views/layouts/application.html.erb Mon Aug 11 18:13:26 2008
@@ -4,8 +4,10 @@
     <%= javascript_include_tag :all, :cache=>true %>
     <%= stylesheet_link_tag 'default', :cache=>true %>
     <%= stylesheet_link_tag 'print', :media=>'print', :cache=>true %>
-    <% @alternate.each do |mime, url| %><%= auto_discovery_link_tag mime.to_sym, url %><% end if @alternate %>
-      <link rel='search' type='application/opensearchdescription+xml' href='<%= open_search_url %>' title='Search your tasks list' />
+    <%= @alternate.map { |mime, url| auto_discovery_link_tag mime.to_sym, url } if @alternate %>
+    <%= tag :link, :rel=>'search', :type=>Mime::OSD, :href=>open_search_url, :title=>'Search your tasks list' %>
+    <%= tag :link, :rel=>'next', :type=>Mime::HTML, :href=>@next if @next %>
+    <%= tag :previous, :rel=>'previous', :type=>Mime::HTML, :href=>@previous if @previous %>
   </head>
   <body>
     <div id='header'>

Modified: ode/sandbox/singleshot/app/views/layouts/head.html.erb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/views/layouts/head.html.erb?rev=685014&r1=685013&r2=685014&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/views/layouts/head.html.erb (original)
+++ ode/sandbox/singleshot/app/views/layouts/head.html.erb Mon Aug 11 18:13:26 2008
@@ -4,9 +4,7 @@
     <%= javascript_include_tag :all, :cache=>true %>
     <%= stylesheet_link_tag 'default', :cache=>true %>
     <%= stylesheet_link_tag 'print', :media=>'print', :cache=>true %>
-    <% @alternate.each do |mime, url| %>
-      <%= auto_discovery_link_tag mime.to_sym, url %>
-    <% end if @alternate %>
+    <%= @alternate.map { |mime, url| auto_discovery_link_tag mime.to_sym, url } if @alternate %>
   </head>
   <body>
 <%= yield %>

Modified: ode/sandbox/singleshot/config/initializers/mime_types.rb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/config/initializers/mime_types.rb?rev=685014&r1=685013&r2=685014&view=diff
==============================================================================
--- ode/sandbox/singleshot/config/initializers/mime_types.rb (original)
+++ ode/sandbox/singleshot/config/initializers/mime_types.rb Mon Aug 11 18:13:26 2008
@@ -3,3 +3,4 @@
 # Add new mime types for use in respond_to blocks:
 # Mime::Type.register "text/richtext", :rtf
 # Mime::Type.register_alias "text/html", :iphone
+Mime::Type.register 'application/opensearchdescription+xml', :osd

Modified: ode/sandbox/singleshot/config/routes.rb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/config/routes.rb?rev=685014&r1=685013&r2=685014&view=diff
==============================================================================
--- ode/sandbox/singleshot/config/routes.rb (original)
+++ ode/sandbox/singleshot/config/routes.rb Mon Aug 11 18:13:26 2008
@@ -1,23 +1,21 @@
 ActionController::Routing::Routes.draw do |map|
 
   map.resource 'session'
-  map.resources 'tasks', :collection=>{ 'completed'=>:get, 'following'=>:get, 'complete_redirect'=>:get } do |tasks|
+  map.resources 'tasks', :collection=>{ 'completed'=>:get, 'following'=>:get, 'complete_redirect'=>:get },
+    :member=>['activities'] do |tasks|
     map.connect '/tasks/:id', :controller=>'tasks', :action=>'complete', :conditions=>{ :method=>:post }
     tasks.with_options :controller=>'task_for' do |opts|
       opts.connect 'for/:person_id', :action=>'update', :conditions=>{ :method=>:put }
       opts.for_person 'for/:person_id', :action=>'show'
     end
-    tasks.with_options :controller=>'activity', :action=>'for_task' do |opts|
-      opts.activity 'activity'
-      opts.activity 'activity.:format', :name_prefix=>'formatted_task_'
-    end
   end
   map.search '/search', :controller=>'tasks', :action=>'search'
   map.open_search '/search/osd', :controller=>'tasks', :action=>'opensearch'
-  map.with_options :controller=>'activity', :action=>'index' do |opts|
-    opts.activity '/activity'
-    opts.formatted_activity '/activity.:format'
-  end
+ 
+  map.activity '/activity', :controller=>'activity', :action=>'index'
+  map.formatted_activity '/activity.:format', :controller=>'activity', :action=>'index'
+  map.recent_activity '/activity/recent', :controller=>'activity', :action=>'recent'
+  
   map.sparklines '/sparklines', :controller=>'sparklines'
   map.root :controller=>'application'
 

Modified: ode/sandbox/singleshot/spec/models/activity_spec.rb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/spec/models/activity_spec.rb?rev=685014&r1=685013&r2=685014&view=diff
==============================================================================
--- ode/sandbox/singleshot/spec/models/activity_spec.rb (original)
+++ ode/sandbox/singleshot/spec/models/activity_spec.rb Mon Aug 11 18:13:26 2008
@@ -136,4 +136,13 @@
     end
   end
 
+
+  describe 'recently_added' do
+    it 'should return recently added activities' do
+      Activity.recently_added.proxy_options[:order].downcase.split.should == ['created_at', 'desc']
+    end
+    
+  end
+
+
 end