Author: assaf
Date: Thu May 22 19:55:36 2008
New Revision: 659383

URL: http://svn.apache.org/viewvc?rev=659383&view=rev
Log:
Added owner modification (no access control yet).

Added:
    ode/sandbox/singleshot/app/controllers/owners_controller.rb
Modified:
    ode/sandbox/singleshot/Rakefile
    ode/sandbox/singleshot/app/controllers/tasks_controller.rb
    ode/sandbox/singleshot/app/helpers/application_helper.rb
    ode/sandbox/singleshot/app/helpers/task_helper.rb
    ode/sandbox/singleshot/app/models/task.rb
    ode/sandbox/singleshot/config/routes.rb
    ode/sandbox/singleshot/lib/tasks/populate.rake

Modified: ode/sandbox/singleshot/Rakefile
URL: 
http://svn.apache.org/viewvc/ode/sandbox/singleshot/Rakefile?rev=659383&r1=659382&r2=659383&view=diff
==============================================================================
--- ode/sandbox/singleshot/Rakefile (original)
+++ ode/sandbox/singleshot/Rakefile Thu May 22 19:55:36 2008
@@ -1,3 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with this
+# work for additional information regarding copyright ownership.  The ASF
+# licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+
 # Add your own tasks in files placed in lib/tasks ending in .rake,
 # for example lib/tasks/capistrano.rake, and they will automatically be 
available to Rake.
 

Added: ode/sandbox/singleshot/app/controllers/owners_controller.rb
URL: 
http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/controllers/owners_controller.rb?rev=659383&view=auto
==============================================================================
--- ode/sandbox/singleshot/app/controllers/owners_controller.rb (added)
+++ ode/sandbox/singleshot/app/controllers/owners_controller.rb Thu May 22 
19:55:36 2008
@@ -0,0 +1,35 @@
+class OwnersController < ApplicationController
+
+  before_filter :set_task
+
+  def show
+    owner = @task.owner
+    respond_to do |wants|
+      wants.any  { render :text=>owner && owner.identity }
+    end
+  end
+
+  def update
+    # TODO: add access control check
+    @task.update_attributes :owner=>params['owner']
+    respond_to do |wants|
+      wants.html { redirect_to :back }
+    end
+  end
+
+  def destroy
+    # TODO: add access control check
+    @task.update_attributes :owner=>nil
+    respond_to do |wants|
+      wants.html { redirect_to :back }
+    end
+  end
+
+private
+
+  def set_task
+    @task = Task.find(params['task_id'])
+    @task.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=659383&r1=659382&r2=659383&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/controllers/tasks_controller.rb (original)
+++ ode/sandbox/singleshot/app/controllers/tasks_controller.rb Thu May 22 
19:55:36 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.with_stakeholders.for_stakeholder(authenticated).pending.prioritized
+    @tasks = 
Task.for_stakeholder(authenticated).pending.with_stakeholders.prioritized
   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=659383&r1=659382&r2=659383&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/helpers/application_helper.rb (original)
+++ ode/sandbox/singleshot/app/helpers/application_helper.rb Thu May 22 
19:55:36 2008
@@ -33,6 +33,19 @@
     end
   end
 
+  def relative_time(time)
+    diff = Time.now - time
+    if diff < 1.minute
+      'this minute'
+    elsif diff < 1.hour
+      "#{(diff / 1.minute).round} minutes ago"
+    elsif diff < 1.day
+      "#{(diff / 1.hour).round} hours ago"
+    elsif diff < 1.month
+      "#{(diff / 1.day).round} days ago"
+    end
+  end
+
   def relative_date_abbr(date, options = {})
     content_tag 'abbr', relative_date(date), 
options.merge(:title=>date.to_date.to_s)
   end

Modified: ode/sandbox/singleshot/app/helpers/task_helper.rb
URL: 
http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/helpers/task_helper.rb?rev=659383&r1=659382&r2=659383&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/helpers/task_helper.rb (original)
+++ ode/sandbox/singleshot/app/helpers/task_helper.rb Thu May 22 19:55:36 2008
@@ -7,7 +7,7 @@
     actions = [
       manage && button_to('Manage', edit_task_url(task), :method=>:get, 
:title=>'Managed this task', :disabled=>!manage),
       cancel && button_to('Cancel', task_url(task), :method=>:delete, 
:title=>'Cancel this task', :disabled=>!cancel),
-      claim && button_to('Claim', task_url(task, 
'task[owner]'=>authenticated.identity), :method=>:put, :title=>'Claim task', 
:disabled=>!claim)
+      claim && button_to('Claim', task_owner_url(task, 
'owner'=>authenticated.identity), :method=>:put, :title=>'Claim task', 
:disabled=>!claim),
     ].select { |action| action }.join(' ')
   end
 

Modified: ode/sandbox/singleshot/app/models/task.rb
URL: 
http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/models/task.rb?rev=659383&r1=659382&r2=659383&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/models/task.rb (original)
+++ ode/sandbox/singleshot/app/models/task.rb Thu May 22 19:55:36 2008
@@ -147,7 +147,8 @@
   named_scope :with_stakeholders, :include=>{ :stakeholders=>:person }
 
   named_scope :for_stakeholder, lambda { |person|
-    { :joins=>'JOIN stakeholders AS involved ON involved.task_id=tasks.id', 
:conditions=>['involved.person_id=?', person.id], :include=>:stakeholders }
+    { :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] }

Modified: ode/sandbox/singleshot/config/routes.rb
URL: 
http://svn.apache.org/viewvc/ode/sandbox/singleshot/config/routes.rb?rev=659383&r1=659382&r2=659383&view=diff
==============================================================================
--- ode/sandbox/singleshot/config/routes.rb (original)
+++ ode/sandbox/singleshot/config/routes.rb Thu May 22 19:55:36 2008
@@ -1,7 +1,8 @@
 ActionController::Routing::Routes.draw do |map|
 
   map.resource 'session'
-  map.resources 'tasks', :collection=>{ 'following'=>:get, 'completed'=>:get 
}, :member=>{ 'activity'=>:get }
+  map.resources 'tasks', :collection=>{ 'following'=>:get, 'completed'=>:get 
}, :member=>{ 'activity'=>:get },
+    :has_one=>[ 'owner' ]
   map.resources 'activities'
   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'

Modified: ode/sandbox/singleshot/lib/tasks/populate.rake
URL: 
http://svn.apache.org/viewvc/ode/sandbox/singleshot/lib/tasks/populate.rake?rev=659383&r1=659382&r2=659383&view=diff
==============================================================================
--- ode/sandbox/singleshot/lib/tasks/populate.rake (original)
+++ ode/sandbox/singleshot/lib/tasks/populate.rake Thu May 22 19:55:36 2008
@@ -31,16 +31,17 @@
 
     def create(attributes)
       retract Task, Stakeholder, Activity
-      attributes = { :title=>Faker::Lorem.sentence, 
:description=>Faker::Lorem.paragraph,
-                     :frame_url=>'http://localhost:3001/sandwich', 
:modified_by=>Person.find_by_identity(ENV['USER']) }.
-                     merge(attributes || {})
-      Task.create!(attributes)
+      you = Person.find_by_identity(ENV['USER']) 
+      defaults = { :title=>Faker::Lorem.sentence, 
:description=>Faker::Lorem.paragraph,
+                   :frame_url=>'http://localhost:3001/sandwich', 
:modified_by=>you,
+                   :potential_owners=>you }
+      Task.create! defaults.merge(attributes || {})
     end
 
 
     # Tasks you should not see.
-    create :title=>'You will not see this task since this task is reserved.', 
:status=>'reserved', :creator=>you
-    create :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.', 
:status=>'reserved', :creator=>you, :potential_owners=>[]
+    create :title=>'You will not see this task since you are not a 
stakeholder.', :potential_owners=>[]
     # Tasks in which we are:
     # - creator
     # - owner


Reply via email to