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/23 04:56:02 UTC
svn commit: r659385 - in /ode/sandbox/singleshot: app/controllers/
app/helpers/ app/models/ lib/tasks/
Author: assaf
Date: Thu May 22 19:56:01 2008
New Revision: 659385
URL: http://svn.apache.org/viewvc?rev=659385&view=rev
Log:
Not much to write home about.
Modified:
ode/sandbox/singleshot/app/controllers/activities_controller.rb
ode/sandbox/singleshot/app/controllers/owners_controller.rb
ode/sandbox/singleshot/app/controllers/tasks_controller.rb
ode/sandbox/singleshot/app/helpers/application_helper.rb
ode/sandbox/singleshot/app/models/activity.rb
ode/sandbox/singleshot/app/models/task.rb
ode/sandbox/singleshot/lib/tasks/populate.rake
Modified: ode/sandbox/singleshot/app/controllers/activities_controller.rb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/controllers/activities_controller.rb?rev=659385&r1=659384&r2=659385&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/controllers/activities_controller.rb (original)
+++ ode/sandbox/singleshot/app/controllers/activities_controller.rb Thu May 22 19:56:01 2008
@@ -1,7 +1,6 @@
class ActivitiesController < ApplicationController
access_key_authentication :only=>[:index, :show]
- instance :task, :only=>[:show]
def index
@title = 'Activities'
@@ -20,6 +19,7 @@
end
def show
+ @task = Task.for_stakeholder(authenticated).find(params[:id])
@title = "Activities - #{@task.title}"
@subtitle = "Track all activities in the task #{@task.title}"
@alternate = { Mime::ATOM=>formatted_activity_url(@task, :atom, :access_key=>authenticated.access_key),
Modified: ode/sandbox/singleshot/app/controllers/owners_controller.rb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/controllers/owners_controller.rb?rev=659385&r1=659384&r2=659385&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/controllers/owners_controller.rb (original)
+++ ode/sandbox/singleshot/app/controllers/owners_controller.rb Thu May 22 19:56:01 2008
@@ -28,8 +28,7 @@
private
def set_task
- @task = Task.find(params['task_id'])
- @task.modified_by = authenticated
+ @task = Task.for_stakeholder(authenticated).find(params['task_id']).modified_by(authenticated)
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=659385&r1=659384&r2=659385&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/controllers/tasks_controller.rb (original)
+++ ode/sandbox/singleshot/app/controllers/tasks_controller.rb Thu May 22 19:56:01 2008
@@ -12,7 +12,7 @@
@subtitle = 'Tasks you are performing or can claim for your own.'
@alternate = { Mime::ATOM=>formatted_tasks_url(:format=>:atom, :access_key=>authenticated.access_key),
Mime::ICS=>formatted_tasks_url(:format=>:ics, :access_key=>authenticated.access_key) }
- @tasks = Task.for_stakeholder(authenticated).pending.with_stakeholders.rank_for(authenticated)
+ @tasks = Task.pending.for_stakeholder(authenticated).with_stakeholders.rank_for(authenticated)
end
def show
Modified: ode/sandbox/singleshot/app/helpers/application_helper.rb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/helpers/application_helper.rb?rev=659385&r1=659384&r2=659385&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/helpers/application_helper.rb (original)
+++ ode/sandbox/singleshot/app/helpers/application_helper.rb Thu May 22 19:56:01 2008
@@ -21,9 +21,9 @@
date = date.to_date
today = Date.today
if date == today
- 'Today'
+ 'today'
elsif date == today - 1.day
- 'Yesterday'
+ 'yesterday'
elsif date > today && date < today.next_week
date.strftime('%A')
elsif date.year == today.year
Modified: ode/sandbox/singleshot/app/models/activity.rb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/models/activity.rb?rev=659385&r1=659384&r2=659385&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/models/activity.rb (original)
+++ ode/sandbox/singleshot/app/models/activity.rb Thu May 22 19:56:01 2008
@@ -17,7 +17,7 @@
attr_readonly :person, :task, :action
- module Grouping
+ module GroupingMethods
def group_by_day
self.inject([]) do |days, activity|
created = activity.created_at.to_date
@@ -32,7 +32,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 DESC', :extend=>Grouping } }
+ :include=>[:task, :person], :order=>'activities.created_at DESC', :extend=>GroupingMethods } }
named_scope :for_dates,
lambda { |dates| { :conditions=>{ :created_at=>dates } } }
Modified: ode/sandbox/singleshot/app/models/task.rb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/models/task.rb?rev=659385&r1=659384&r2=659385&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/models/task.rb (original)
+++ ode/sandbox/singleshot/app/models/task.rb Thu May 22 19:56:01 2008
@@ -22,6 +22,7 @@
require 'openssl'
require 'md5'
+
class Task < ActiveRecord::Base
def initialize(attributes = {}) #:nodoc:
@@ -65,8 +66,7 @@
# transition to completed only from active, and transition to cancelled from
# any other state but completed. Completed and cancelled are terminal
# states.
- STATUSES = ['reserved', 'ready', 'active', 'suspended', 'completed',
- 'cancelled']
+ STATUSES = ['reserved', 'ready', 'active', 'suspended', 'completed', 'cancelled']
# Cannot change in mass update.
attr_protected :status
@@ -85,7 +85,7 @@
before_validation do |task|
case task.status
- when 'ready', 'reserved'
+ when 'ready'
task.owner = task.potential_owners.first unless task.owner || task.potential_owners.size > 1
task.status = 'active' if task.owner
when 'active'
@@ -144,29 +144,30 @@
include Stakeholder::Accessors
include Stakeholder::Validation
+ # Eager loading of stakeholders associated with each task.
named_scope :with_stakeholders, :include=>{ :stakeholders=>:person }
-
+ # Load only tasks that this person is a stakeholder of (owner, observer, etc).
named_scope :for_stakeholder, lambda { |person|
- { :joins=>'JOIN stakeholders AS involved ON involved.task_id=tasks.id', :conditions=>["involved.person_id=? AND tasks.status != 'reserved'", person.id],
- :include=>:stakeholders }
- }
- named_scope :for_owner, lambda { |person|
- { :joins=>:stakeholders, :conditions=>["stakeholders.person_id=? and stakeholders.role='owner'", person.id] }
- }
+ { :joins=>'JOIN stakeholders AS involved ON involved.task_id=tasks.id',
+ :conditions=>["(involved.person_id=? AND involved.role != 'excluded')", person.id] } }
# --- Priority and ordering ---
# Task priority: 1 is the highest, 3 the lowest, average is the default.
PRIORITIES = 1..3
- before_validation { |task| task.priority ||= (PRIORITIES.min + PRIORITIES.max) >> 1 }
validates_inclusion_of :priority, :in=>PRIORITIES
+ before_validation do |task|
+ task.priority ||= (PRIORITIES.min + PRIORITIES.max) >> 1
+ end
def over_due?
due_on && due_on < Date.today
end
- module Ranking
+ # Scopes can use this to add ranking methods on returned records.
+ module RankingMethods
+
# Tasks are ranked by the following rules:
# - Tasks you're performing (owner of) always rank higher than all other tasks.
# - Tasks available to you rank higher than tasks not available to you
@@ -185,12 +186,13 @@
-task.priority, today - task.created_at.to_date ] }
self.sort { |a,b| rank[b] <=> rank[a] }
end
+
end
# --- Activities ---
- has_many :activities, :include=>[:task, :person], :order=>'activities.created_at DESC', :extend=>Activity::Grouping
+ has_many :activities, :include=>[:task, :person], :order=>'activities.created_at DESC', :extend=>Activity::GroupingMethods
# Associate person with all modifications done on this task.
# This results in activities linked to the person and task when
@@ -201,7 +203,6 @@
end
before_save :log_activities, :unless=>lambda { |task| task.status == 'reserved' }
-
def log_activities
Activity.log self, @modified_by do |log|
if changes['status']
@@ -341,6 +342,22 @@
end
- named_scope :pending, :conditions=>["tasks.status IN ('ready', 'active') AND involved.role IN ('owner', 'potential')"],
- :order=>'involved.role, priority ASC, tasks.created_at', :extend=>Ranking
+
+
+
+
+
+
+
+
+
+ # --- Finders and named scopes ---
+
+ # Pending tasks are:
+ # - Active tasks owned by the person
+ # - Ready tasks that can be claimed by the person
+ named_scope :pending, :joins=>'JOIN stakeholders AS involved ON involved.task_id=tasks.id',
+ :conditions=>["(tasks.status = 'ready' AND involved.role = 'potential') OR (tasks.status = 'active' AND involved.role = 'owner')"],
+ :extend=>RankingMethods
+
end
Modified: ode/sandbox/singleshot/lib/tasks/populate.rake
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/lib/tasks/populate.rake?rev=659385&r1=659384&r2=659385&view=diff
==============================================================================
--- ode/sandbox/singleshot/lib/tasks/populate.rake (original)
+++ ode/sandbox/singleshot/lib/tasks/populate.rake Thu May 22 19:56:01 2008
@@ -11,18 +11,21 @@
end
puts "Populating database for #{you.identity}"
- other = Person.identify('anon') || Person.create(:email=>'anon@apache.org')
Activity.delete_all
Stakeholder.delete_all
Task.delete_all
+ def other
+ Person.identify('anon') || Person.create(:email=>'anon@apache.org')
+ end
def retract(*models)
+ models = Task, Stakeholder, Activity if models.empty?
models.each do |model|
model.all.each do |record|
- change = ['created_at = ?', record.created_at - 4.hours]
+ change = ['created_at = ?', record.created_at - 2.hour]
if record.respond_to?(:updated_at)
change.first << ', updated_at = ?'
- change << record.updated_at - 1.hours
+ change << record.updated_at - 2.hour
end
model.update_all change, :id=>record.id
end
@@ -30,10 +33,10 @@
end
def create(attributes)
- retract Task, Stakeholder, Activity
+ retract
you = Person.find_by_identity(ENV['USER'])
defaults = { :title=>Faker::Lorem.sentence, :description=>Faker::Lorem.paragraph,
- :frame_url=>'http://localhost:3001/sandwich', :potential_owners=>you }
+ :frame_url=>'http://localhost:3001/sandwich', :potential_owners=>[you, other] }
Task.new(defaults.merge(attributes || {})).modified_by(you).save!
end
@@ -47,13 +50,12 @@
# - observer
# - admin
create :creator=>you
- create :creator=>you, :owner=>you
+ create :creator=>you ; retract ; Task.last.modified_by(you).update_attributes :owner=>you
create :observers=>you
create :admins=>you
# Tasks in which we are only or one of many potential owners.
create :potential_owners=>you
- create :potential_owners=>[you, other]
- create :owner=>other, :potential_owners=>you
+ create :potential_owners=>[you, other] ; retract ; Task.last.update_attributes :owner=>other
# High priority should show first.
create :owner=>you, :priority=>Task::PRIORITIES.first
# Over-due before due today before anything else.