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/29 01:02:34 UTC

svn commit: r661139 - in /ode/sandbox/singleshot: app/controllers/ app/helpers/ app/models/ app/views/activities/ app/views/layouts/ app/views/tasks/ lib/tasks/ public/stylesheets/

Author: assaf
Date: Wed May 28 16:02:34 2008
New Revision: 661139

URL: http://svn.apache.org/viewvc?rev=661139&view=rev
Log:
Owner can now claim task.

Modified:
    ode/sandbox/singleshot/app/controllers/sandwiches_controller.rb
    ode/sandbox/singleshot/app/controllers/tasks_controller.rb
    ode/sandbox/singleshot/app/helpers/task_helper.rb
    ode/sandbox/singleshot/app/models/task.rb
    ode/sandbox/singleshot/app/views/activities/index.html.erb
    ode/sandbox/singleshot/app/views/layouts/application.html.erb
    ode/sandbox/singleshot/app/views/tasks/following.html.erb
    ode/sandbox/singleshot/app/views/tasks/index.html.erb
    ode/sandbox/singleshot/lib/tasks/populate.rake
    ode/sandbox/singleshot/public/stylesheets/default.css

Modified: ode/sandbox/singleshot/app/controllers/sandwiches_controller.rb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/controllers/sandwiches_controller.rb?rev=661139&r1=661138&r2=661139&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/controllers/sandwiches_controller.rb (original)
+++ ode/sandbox/singleshot/app/controllers/sandwiches_controller.rb Wed May 28 16:02:34 2008
@@ -7,7 +7,7 @@
   before_filter :instance
 
   def show
-    #@read_only = true unless params['perform'] == 'true'
+    @read_only = true unless params['perform'] == 'true'
   end
 
   def update
@@ -23,11 +23,9 @@
   def create
     @sandwich.update_attributes params['sandwich']
     if @sandwich.save
-
       flash[:success] = 'Changes have been saved.'
-      #redirect_to :action=>'show', :task_url=>@task_url, :perform=>true
+      # TODO: FIX!
       render :text=>"<script>frames.top.location.href='http://localhost:3000/tasks'</script>"
-
     else
       render :action=>'show'
     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=661139&r1=661138&r2=661139&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/controllers/tasks_controller.rb (original)
+++ ode/sandbox/singleshot/app/controllers/tasks_controller.rb Wed May 28 16:02:34 2008
@@ -11,12 +11,12 @@
     @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.pending.for_stakeholder(authenticated).with_stakeholders.rank_for(authenticated)
-    respond_to do |format|
-      format.html
-      # TODO: format.xml
-      # TODO: format.json
-      format.atom
-      format.ics
+    respond_to do |wants|
+      wants.html
+      # TODO: wants.xml
+      # TODO: wants.json
+      wants.atom
+      wants.ics
     end
   end
 
@@ -25,14 +25,12 @@
     @alternate = { Mime::ATOM=>formatted_completed_tasks_url(:format=>:atom, :access_key=>authenticated.access_key), 
                    Mime::ICS=>formatted_completed_tasks_url(:format=>:ics, :access_key=>authenticated.access_key) }
     @tasks = Task.completed.for_stakeholder(authenticated).with_stakeholders
-    respond_to do |format|
-      format.html do 
-        @days = @tasks.group_by { |task| task.updated_at.to_date }
-      end
-      # TODO: format.xml
-      # TODO: format.json
-      format.atom { render :action=>'index' }
-      format.ics  { render :action=>'ics' }
+    respond_to do |wants|
+      wants.html { @days = @tasks.group_by { |task| task.updated_at.to_date } }
+      # TODO: wants.xml
+      # TODO: wants.json
+      wants.atom { render :action=>'index' }
+      wants.ics  { render :action=>'ics' }
     end
   end
 
@@ -41,24 +39,22 @@
     @alternate = { Mime::ATOM=>formatted_following_tasks_url(:format=>:atom, :access_key=>authenticated.access_key), 
                    Mime::ICS=>formatted_following_tasks_url(:format=>:ics, :access_key=>authenticated.access_key) }
     @tasks = Task.following.for_stakeholder(authenticated).with_stakeholders
-    respond_to do |format|
-      format.html do 
-        @days = @tasks.group_by { |task| task.updated_at.to_date }
-      end
-      # TODO: format.xml
-      # TODO: format.json
-      format.atom { render :action=>'index' }
-      format.ics  { render :action=>'ics' }
+    respond_to do |wants|
+      wants.html
+      # TODO: wants.xml
+      # TODO: wants.json
+      wants.atom { render :action=>'index' }
+      wants.ics  { render :action=>'ics' }
     end
   end
 
   def show
     @alternate = { Mime::ICS=>formatted_tasks_url(:format=>:ics, :access_key=>authenticated.access_key) }
-    respond_to do |format|
-      format.html { render :layout=>'head' }
-      # TODO: format.xml
-      # TODO: format.json
-      format.ics  do
+    respond_to do |wants|
+      wants.html { render :layout=>'head' }
+      # TODO: wants.xml
+      # TODO: wants.json
+      wants.ics  do
         @title = @task.title
         @tasks = [@task]
         render :action=>'index'
@@ -68,8 +64,12 @@
 
   def update
     # TODO: rescue ActiveRecord::ReadOnlyRecord
-    @task.modified_by(authenticated).update_attributes(params)
+    logger.info @task.inspect
+    logger.info @task.readonly?
+    logger.info params[:task].inspect
+    @task.modified_by(authenticated).update_attributes!(params[:task])
 
+=begin
     # TODO: conditional put
     raise ActiveRecord::StaleObjectError, 'This task already completed.' if @task.completed?
     input = params[:task]
@@ -78,12 +78,12 @@
     raise NotAuthorized, 'You are not allowed to change this task.' unless filter
     input = filter[input]
     raise NotAuthorized, 'You cannot make this change.' unless input
-
     @task.update_attributes! input
-    respond_to do |format|
-      format.html { redirect_to task_url }
-      format.xml  { render :xml=>@task }
-      format.json { render :json=>@task }
+=end
+    respond_to do |wants|
+      wants.html { flash['highlight'] = dom_id(@task) ; redirect_to :back }
+      # TODO: wants.xml
+      # TODO: wants.json
     end
   end
 
@@ -111,25 +111,6 @@
     end
   end
 
-
-  def update
-    # TODO: conditional put
-    raise ActiveRecord::StaleObjectError, 'This task already completed.' if @task.completed?
-    input = params[:task]
-    input[:outcome_type] ||= suggested_outcome_type unless @task.outcome_type
-    filter = @task.filter_update_for(authenticated)
-    raise NotAuthorized, 'You are not allowed to change this task.' unless filter
-    input = filter[input]
-    raise NotAuthorized, 'You cannot make this change.' unless input
-
-    @task.update_attributes! input
-    respond_to do |format|
-      format.html { redirect_to task_url }
-      format.xml  { render :xml=>@task }
-      format.json { render :json=>@task }
-    end
-  end
-
   def complete
     raise ActiveRecord::StaleObjectError, 'This task already completed.' if @task.completed?
     raise NotAuthorized, 'You are not allowed to complete this task.' unless @task.can_complete?(authenticated)

Modified: ode/sandbox/singleshot/app/helpers/task_helper.rb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/helpers/task_helper.rb?rev=661139&r1=661138&r2=661139&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/helpers/task_helper.rb (original)
+++ ode/sandbox/singleshot/app/helpers/task_helper.rb Wed May 28 16:02:34 2008
@@ -19,10 +19,13 @@
     if task.form_perform_url
       task_uri = URI(task_perform_url(task))
       task_uri.user, task_uri.password = '_token', task.token_for(authenticated)
-      # TODO: fix to handle perform/view URLs differently and decide when to pass perform query param.
-      uri = URI(task.owner?(authenticated) ? task.form_perform_url : (task.form_view_url || task.form_perform_url)) 
-      uri.query = CGI.parse(uri.query || '').update('perform'=>task.owner?(authenticated), 'task_url'=>task_uri).to_query
-      uri.to_s
+      if task.can_complete?(authenticated)
+        uri = URI(task.form_perform_url)
+        uri.query = CGI.parse(uri.query || '').update('perform'=>'true', 'task_url'=>task_uri).to_query
+      else
+        uri = URI(task.form_view_url || task.form_perform_url)
+        uri.query = CGI.parse(uri.query || '').update('task_url'=>task_uri).to_query
+      end
       content_tag 'iframe', '', :id=>'task_frame', :src=>uri.to_s
     end
   end

Modified: ode/sandbox/singleshot/app/models/task.rb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/models/task.rb?rev=661139&r1=661138&r2=661139&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/models/task.rb (original)
+++ ode/sandbox/singleshot/app/models/task.rb Wed May 28 16:02:34 2008
@@ -151,7 +151,7 @@
   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',
+    { :joins=>'JOIN stakeholders AS involved ON involved.task_id=tasks.id', :readonly=>false,
       :conditions=>["involved.person_id=? AND involved.role != 'excluded' AND tasks.status != 'reserved'", person.id] } }
 
 
@@ -212,8 +212,8 @@
   before_save :log_activities, :unless=>lambda { |task| task.status == 'reserved' }
   def log_activities
     Activity.log self, @modified_by do |log|
-      if changes['status']
-        from, to = *changes['status']
+      if status_changed?
+        from, to = status_change
         log.add creator, 'created' if creator && (from.nil? || from == 'reserved')
         log.add 'resumed' if from == 'suspended'
         case to

Modified: ode/sandbox/singleshot/app/views/activities/index.html.erb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/views/activities/index.html.erb?rev=661139&r1=661138&r2=661139&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/views/activities/index.html.erb (original)
+++ ode/sandbox/singleshot/app/views/activities/index.html.erb Wed May 28 16:02:34 2008
@@ -5,9 +5,10 @@
       <ol class='activities'>
         <% for activity in activities %>
           <% content_tag_for 'li', activity, :class=>'hentry entry-title' do %>
-            <%= link_to h(activity.person.fullname), activity.person.identity %>
-            <%= activity.action %>
-            the task <%= link_to h(truncate(activity.task.title, 100)), task_url(activity.task), :rel=>'bookmark, :title=>truncate(strip_tags(task.description), 250)' %>
+            <%= link_to h(activity.person.fullname), activity.person.url, :class=>'author fn url' %>
+            <%= activity.action %> the task
+            <%= link_to h(truncate(activity.task.title, 100)), task_url(activity.task),
+                  :rel=>'bookmark', :title=>truncate(strip_tags(activity.task.description), 250) %>
           <% end %>
         <% 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=661139&r1=661138&r2=661139&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/views/layouts/application.html.erb (original)
+++ ode/sandbox/singleshot/app/views/layouts/application.html.erb Wed May 28 16:02:34 2008
@@ -27,5 +27,6 @@
     <div id='footer'>
       <!-- Footer comes here -->
     </div>
+    <%= javascript_tag visual_effect(:highlight, flash['highlight'], :duration => 2) if flash['highlight'] %>
   </body>
 </html>

Modified: ode/sandbox/singleshot/app/views/tasks/following.html.erb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/views/tasks/following.html.erb?rev=661139&r1=661138&r2=661139&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/views/tasks/following.html.erb (original)
+++ ode/sandbox/singleshot/app/views/tasks/following.html.erb Wed May 28 16:02:34 2008
@@ -1,21 +1,24 @@
 <table class='tasks hfeed'>
   <thead>
-    <th style='width:4em'>Status</th>
+    <th style='width:6em'>Status</th>
     <th>Task</th>
-    <th>Assigned to</th>
-    <th style='width:5em'>Due on</th>
+    <th style='width:7em'>Due on</th>
     <th style='width:4em'>Priority</th>
     <th style='width:6em'>Age</th>
+    <th style='width:7em'>Assigned to</th>
   </thead>
   <tbody>
     <% for task in @tasks %>
-      <% content_tag_for 'tr', task, :class=>'hentry' + (task.over_due? ? ' overdue' : '') do %>
+      <% classes = ['hentry']
+         classes << 'overdue' if task.over_due?
+         classes << 'inactive' if task.cancelled? || task.suspended?
+         content_tag_for 'tr', task, :class=>classes.join(' ') do %>
         <td class='status'><%= task.status.titleize %></td>
         <td class='entry-title'><%= '⚠  ' if task.over_due? %><%= link_to h(task.title), task_url(task), :rel=>'bookmark', :title=>truncate(strip_tags(task.description), 250) %></td>
-        <td><%= link_to_person task.owner, :owner if task.owner %></td>
         <td><%= abbr_date task.due_on, relative_date(task.due_on).titleize, :class=>(task.over_due? ? 'overdue' : nil) if task.due_on %></td>
         <td><%= content_tag 'span', ['High', 'Normal', 'Low'][task.priority - 1], :class=>"priority_#{task.priority}" %></td>
         <td><%= abbr_time task.created_at, relative_time(task.created_at), :class=>'published' %></td>
+        <td><%= link_to_person task.owner, :owner if task.owner %></td>
       <% end %>
     <% end %>
   </tbody>

Modified: ode/sandbox/singleshot/app/views/tasks/index.html.erb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/views/tasks/index.html.erb?rev=661139&r1=661138&r2=661139&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/views/tasks/index.html.erb (original)
+++ ode/sandbox/singleshot/app/views/tasks/index.html.erb Wed May 28 16:02:34 2008
@@ -1,21 +1,19 @@
 <table class='tasks hfeed'>
   <thead>
-    <th style='width:4em'>Status</th>
     <th>Task</th>
-    <th style='width:5em'>Due on</th>
+    <th style='width:7em'>Due on</th>
     <th style='width:4em'>Priority</th>
     <th style='width:6em'>Age</th>
-    <th></th>
+    <th style='width:5em'></th>
   </thead>
   <tbody>
     <% for task in @tasks %>
       <% content_tag_for 'tr', task, :class=>'hentry' + (task.over_due? ? ' overdue' : '') do %>
-        <td class='status'><%= task.status.titleize %></td>
         <td class='entry-title'><%= link_to h(task.title), task_url(task), :rel=>'bookmark', :title=>truncate(strip_tags(task.description), 250) %></td>
         <td><%= image_tag('exclamation.png') if task.over_due? %> <%= abbr_date task.due_on, relative_date(task.due_on).titleize if task.due_on %></td>
         <td><%= content_tag 'span', ['High', 'Normal', 'Low'][task.priority - 1], :class=>"priority_#{task.priority}" %></td>
         <td><%= abbr_time task.created_at, relative_time(task.created_at), :class=>'published' %></td>
-        <td><%= button_to 'Claim', '' if task.can_claim?(authenticated) %></td>
+        <td><%= button_to 'Claim', task_url(task, 'task[owner]'=>authenticated), :method=>:put, :title=>'Claim this task' if task.can_claim?(authenticated) %></td>
       <% end %>
     <% end %>
   </tbody>

Modified: ode/sandbox/singleshot/lib/tasks/populate.rake
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/lib/tasks/populate.rake?rev=661139&r1=661138&r2=661139&view=diff
==============================================================================
--- ode/sandbox/singleshot/lib/tasks/populate.rake (original)
+++ ode/sandbox/singleshot/lib/tasks/populate.rake Wed May 28 16:02:34 2008
@@ -18,14 +18,13 @@
     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|
+    def Task.delay(duration = 2.hours)
+      for model in [Task, Stakeholder, Activity]
         model.all.each do |record|
-          change = ['created_at = ?', record.created_at - 2.hour]
+          change = ['created_at = ?', record.created_at - duration]
           if record.respond_to?(:updated_at)
             change.first << ', updated_at = ?'
-            change << record.updated_at - 2.hour
+            change << record.updated_at - duration
           end
           model.update_all change, :id=>record.id 
         end
@@ -33,12 +32,16 @@
     end
 
     def create(attributes)
-      retract 
+      Task.delay 
       you = Person.find_by_identity(ENV['USER']) 
       defaults = { :title=>Faker::Lorem.sentence, :description=>Faker::Lorem.paragraphs(3).join("\n\n"),
                    :form_perform_url=>'http://localhost:3001/sandwich', :form_completing=>true, :potential_owners=>[you, other] }
       returning Task.new(defaults.merge(attributes || {})) do |task|
         task.modified_by(you).save!
+        def task.delay(duration = 2.hours)
+          Task.delay(duration)
+          self
+        end
       end
     end
 
@@ -52,12 +55,12 @@
     # - observer
     # - admin
     create :creator=>you
-    create :creator=>you ; retract ; Task.last.modified_by(you).update_attributes :owner=>you
+    create(:creator=>you).delay(25.minutes).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] ; retract ; Task.last.update_attributes :owner=>other
+    create(:potential_owners=>[you, other]).delay(45.minutes).update_attributes :owner=>other
     # High priority should show first.
     create :owner=>you, :priority=>Task::PRIORITIES.first
     # Over-due before due today before anything else.
@@ -65,9 +68,9 @@
     create :owner=>you, :due_on=>Time.today
     create :owner=>you, :due_on=>Time.today + 1.day
     # Completed, cancelled, suspended
-    create(:potential_owners=>[you, other]).update_attributes(:status=>'suspended')
-    create(:owner=>you, :status=>'active').update_attributes(:status=>'completed')
-    create(:owner=>you, :status=>'active').update_attributes(:status=>'cancelled')
+    create(:potential_owners=>[you, other]).delay(30.minutes).modified_by(other).update_attributes(:status=>'suspended')
+    create(:owner=>you, :status=>'active').delay(2.hours).modified_by(you).update_attributes(:status=>'completed')
+    create(:owner=>you, :status=>'active').delay(96.minutes).modified_by(other).update_attributes(:status=>'cancelled')
   end
 
 end

Modified: ode/sandbox/singleshot/public/stylesheets/default.css
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/public/stylesheets/default.css?rev=661139&r1=661138&r2=661139&view=diff
==============================================================================
--- ode/sandbox/singleshot/public/stylesheets/default.css (original)
+++ ode/sandbox/singleshot/public/stylesheets/default.css Wed May 28 16:02:34 2008
@@ -212,7 +212,10 @@
 table.tasks tbody td img {
   vertical-align: middle;
 }
-table.tasks tbody .overdue td, table.tasks tbody .overdue td a {
+table.tasks tbody tr.inactive, table.tasks tbody tr.inactive td a {
+  color: #ccc;
+}
+table.tasks tbody tr.overdue td, table.tasks tbody .overdue td a {
   color: red;
 }
 table.tasks tbody td .priority_1 {