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/11/19 00:32:29 UTC
svn commit: r718770 - in /ode/sandbox/singleshot/app:
controllers/activity_controller.rb controllers/tasks_controller.rb
presenters/ presenters/activity_presenter.rb
views/activity/index.atom.builder views/activity/index.html.erb
Author: assaf
Date: Tue Nov 18 15:32:28 2008
New Revision: 718770
URL: http://svn.apache.org/viewvc?rev=718770&view=rev
Log:
Activity controller now using presenters
Added:
ode/sandbox/singleshot/app/presenters/
ode/sandbox/singleshot/app/presenters/activity_presenter.rb
Modified:
ode/sandbox/singleshot/app/controllers/activity_controller.rb
ode/sandbox/singleshot/app/controllers/tasks_controller.rb
ode/sandbox/singleshot/app/views/activity/index.atom.builder
ode/sandbox/singleshot/app/views/activity/index.html.erb
Modified: ode/sandbox/singleshot/app/controllers/activity_controller.rb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/controllers/activity_controller.rb?rev=718770&r1=718769&r2=718770&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/controllers/activity_controller.rb (original)
+++ ode/sandbox/singleshot/app/controllers/activity_controller.rb Tue Nov 18 15:32:28 2008
@@ -17,29 +17,21 @@
class ActivityController < ApplicationController
def index
- @title = I18n.t('activities.index.title')
- @subtitle = I18n.t('activities.index.subtitle')
- @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
+ @title = I18n.t('activity.index.title')
+ @subtitle = I18n.t('activity.index.subtitle')
+ for_stakeholder = Activity.for_stakeholder(authenticated)
+ @activities = for_stakeholder.with_dependents.paginate(:page=>params['page'], :per_page=>50)
respond_to do |want|
want.html do
@atom_feed_url = formatted_activity_url(:format=>:atom, :access_key=>authenticated.access_key)
- @graph = Activity.for_stakeholder(authenticated).for_dates(Date.current - 1.month)
+ @next = activity_url(:page=>@activities.next_page) if @activities.next_page
+ @previous = activity_url(:page=>@activities.previous_page) if @activities.previous_page
+ @graph = for_stakeholder.for_dates(Date.current - 1.month)
end
want.atom { @root_url = activity_url }
- want.json
- want.xml
+ want.json { render :json=>presenting(@activities) }
+ want.xml { render :xml=>presenting(@activities) }
end
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=718770&r1=718769&r2=718770&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/controllers/tasks_controller.rb (original)
+++ ode/sandbox/singleshot/app/controllers/tasks_controller.rb Tue Nov 18 15:32:28 2008
@@ -79,9 +79,10 @@
def show
@title = @task.title
- @alternate = { Mime::HTML=>task_url(@task),
- Mime::ICS=>formatted_task_url(@task, :format=>:ics, :access_key=>authenticated.access_key),
- Mime::ATOM=>formatted_task_activity_url(@task, :format=>:atom, :access_key=>authenticated.access_key) }
+# @alternate = { Mime::HTML=>task_url(@task),
+# Mime::ICS=>formatted_task_url(@task, :format=>:ics, :access_key=>authenticated.access_key),
+# Mime::ATOM=>formatted_task_activity_url(@task, :format=>:atom, :access_key=>authenticated.access_key) }
+ @alternate = {}
respond_to do |wants|
wants.html { render :layout=>'head' }
# TODO: wants.xml
Added: ode/sandbox/singleshot/app/presenters/activity_presenter.rb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/presenters/activity_presenter.rb?rev=718770&view=auto
==============================================================================
--- ode/sandbox/singleshot/app/presenters/activity_presenter.rb (added)
+++ ode/sandbox/singleshot/app/presenters/activity_presenter.rb Tue Nov 18 15:32:28 2008
@@ -0,0 +1,34 @@
+class ActivityPresenter < Presenter::Base
+
+ def to_html
+ grouped = activities.group_by { |activity| [activity.task, activity.person, activity.created_at] }
+ list = grouped.map { |(task, person, published), related|
+ %{<li id="#{id_for(related.first)}" class="activity hentry">
+ <abbr class="published" title="#{published.iso8601}">#{I18n.l(published, :format=>'%I:%M%p')}</abbr>
+ <span class="entry-title">#{presenting(related).single_entry(:html)}</span>
+ </li>}
+ }.join
+ %{<ol class="activities">#{list}</ol>}
+ end
+
+ def single_entry(format = :text)
+ first = activities.first
+ names = activities.map { |activity| I18n.t("activity.name.#{activity.name}") }
+ if format == :text
+ person, task = first.person.fullname, first.task.title
+ else
+ person = %{<a href="#{first.person.url}" rel="author">#{h(first.person.fullname)}</a>}
+ task = %{<a href="#{task_url(first.task)}" rel="task">#{h(first.task.title)}</a>}
+ end
+ I18n.t("activity.entry.#{format}", :person=>person, :task=>task, :names=>names)
+ end
+
+ def hash_for(activity)
+ task, person = activity.task, activity.person
+ { :id=>id_for(activity), :name=>activity.name, :published=>activity.created_at,
+ :task=>{ :id=>id_for(task), :url=>task_url(task), :title=>task.title },
+ :person=>{ :id=>person.identity, :url=>person.url, :name=>person.fullname }
+ }
+ end
+
+end
\ No newline at end of file
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=718770&r1=718769&r2=718770&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/views/activity/index.atom.builder (original)
+++ ode/sandbox/singleshot/app/views/activity/index.atom.builder Tue Nov 18 15:32:28 2008
@@ -6,12 +6,12 @@
feed.link :href=>@previous, :rel=>'previous', :type=>Mime::ATOM if @previous
feed.generator 'Singleshot', :version=>Singleshot::VERSION
- for (task, person, published), related in @activities.group_by { |activity| [activity.task, activity.person, activity.created_at] }
+ grouped = @activities.group_by { |activity| [activity.task, activity.person, activity.created_at] }
+ grouped.each do |(task, person, published), related|
feed.entry related.first, :url=>task_url(task) do |entry|
- entry.title activity_as_text(person, related, task)
- entry.content :type=>'html' do |content|
- content.text! activity_as_html(person, related, task)
- end
+ related = presenting(related)
+ entry.title related.single_entry(:text)
+ entry.content related.single_entry(:html), :type=>'html'
entry.author do |author|
author.name person ? person.fullname : 'Unknown'
author.url person.url if person && person.url
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=718770&r1=718769&r2=718770&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/views/activity/index.html.erb (original)
+++ ode/sandbox/singleshot/app/views/activity/index.html.erb Tue Nov 18 15:32:28 2008
@@ -8,7 +8,7 @@
<% for date, activities in @activities.group_by{ |a| a.created_at.to_date } %>
<li class='date'>
<h2><%= relative_date(date).humanize %></h2>
- <%= render :partial=>'activities', :locals=>{ :activities=>activities, :today=>nil } %>
+ <%= presenting(activities).to_html %>
</li>
<% end %>
</ol>