Author: assaf
Date: Tue May 20 17:31:51 2008
New Revision: 658512

URL: http://svn.apache.org/viewvc?rev=658512&view=rev
Log:
What was once status, then state, is now status again.

Added:
    ode/sandbox/singleshot/lib/tasks/populate.rake
      - copied, changed from r658511, 
ode/sandbox/singleshot/lib/tasks/database.rake
Modified:
    ode/sandbox/singleshot/app/models/task.rb
    ode/sandbox/singleshot/db/migrate/20080506015046_tasks.rb
    ode/sandbox/singleshot/db/schema.rb
    ode/sandbox/singleshot/lib/tasks/database.rake

Modified: ode/sandbox/singleshot/app/models/task.rb
URL: 
http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/models/task.rb?rev=658512&r1=658511&r2=658512&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/models/task.rb (original)
+++ ode/sandbox/singleshot/app/models/task.rb Tue May 20 17:31:51 2008
@@ -8,7 +8,7 @@
 #  description  :string(255)     not null
 #  priority     :integer(1)      not null
 #  due_on       :date
-#  state        :string(255)     not null
+#  status       :string(255)     not null
 #  frame_url    :string(255)
 #  outcome_url  :string(255)
 #  outcome_type :string(255)
@@ -27,7 +27,7 @@
   def initialize(attributes = {}) #:nodoc:
     super
     self.description ||= ''
-    self.state = attributes[:state] == 'ready' ? 'ready' : 'reserved'
+    self.status = attributes[:status] == 'reserved' ? 'reserved' : 'ready'
     self.data ||= {}
     self.access_key = MD5.hexdigest(OpenSSL::Random.random_bytes(128))
   end
@@ -46,71 +46,68 @@
   end
 
 
-  # --- Task state ---
+  # --- Task status ---
 
-  # A task can be in one of these states:
-  # - reserved  -- Task exists but is not yet ready or active.
-  # - ready     -- Task is ready and can be claimed by owner.
-  # - active    -- Task is performed by its owner.
-  # - suspended -- Task is suspended.
-  # - completed -- Task has completed.
-  # - cancelled -- Task was cancelled.
-  #
-  # A task can start in reserved state and remain there until populated with
-  # enough information to transition to the ready state.  From ready state, a
-  # stakeholder can claim the task, transitioning it to the active state.  The
-  # task transitions back to ready if stakeholder releases that claim.
+  # A task can report one of these statuses:
+  # * reserved  -- Task exists but is not yet ready or active.
+  # * ready     -- Task is ready and can be claimed by owner.
+  # * active    -- Task is performed by its owner.
+  # * suspended -- Task is suspended.
+  # * completed -- Task has completed.
+  # * cancelled -- Task was cancelled.
+  
+  # A task can start as reserved and remain there until populated with enough
+  # information to transition to ready.  From ready, a stakeholder can claim
+  # the task, transitioning it to active.  The task transitions back to ready
+  # if stakeholder releases that claim.
   #
   # Task can transition from ready/active to suspended and back.  Task can
-  # transition to completed state only from active state, and transition to
-  # cancelled state from any other state but completed.  Completed and
-  # cancelled are terminal states.
-  STATES = ['reserved', 'ready', 'active', 'suspended', 'completed', 
'cancelled']
+  # 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']
 
   # Cannot change in mass update.
-  attr_protected :state
-  validates_inclusion_of :state, :in=>STATES
+  attr_protected :status
+  validates_inclusion_of :status, :in=>STATUSES
 
-  STATES.each do |state|
-    define_method "#{state}?" do
-      self.state == state
+  # Check method for each status (active?, completed?, etc).
+  STATUSES.each do |status|
+    define_method "#{status}?" do
+      self.status == status
     end
   end
 
   before_validation_on_update do |task|
-    task.state = 'ready' if task.state == 'reserved'
+    task.status = 'ready' if task.status == 'reserved'
   end
 
   before_validation do |task|
-    case task.state
+    case task.status
     when 'ready', 'reserved'
       task.owner = task.potential_owners.first unless task.owner || 
task.potential_owners.size > 1
-      task.state = 'active' if task.owner
+      task.status = 'active' if task.owner
     when 'active'
-      task.state = 'ready' unless task.owner
+      task.status = 'ready' unless task.owner
     end
   end
 
   validate do |task|
-    changes = task.changes['state']
+    changes = task.changes['status']
     from, to = changes.first, changes.last if changes
     if from == 'completed' 
-      task.errors.add :state, 'Cannot change state of completed task.'
+      task.errors.add :status, 'Cannot change status of completed task.'
     elsif from == 'cancelled'
-      task.errors.add :state, 'Cannot change state of cancelled task.'
+      task.errors.add :status, 'Cannot change status of cancelled task.'
     elsif to == 'reserved'
-      task.errors.add :state, 'Cannot change state to reserved.' unless 
from.nil?
+      task.errors.add :status, 'Cannot change status to reserved.' unless 
from.nil?
     elsif to == 'completed'
-      task.errors.add :state, 'Only owner can complete task.' unless task.owner
-      task.errors.add :state, 'Cannot change to completed from any state but 
active.' unless from =='active'
+      task.errors.add :status, 'Only owner can complete task.' unless 
task.owner
+      task.errors.add :status, 'Cannot change to completed from any status but 
active.' unless from =='active'
     end
   end
 
-  def status
-    state
-  end
-
-
 
   # -- Common task attributes --
   #
@@ -156,11 +153,11 @@
     { :joins=>:stakeholders, :conditions=>["stakeholders.person_id=? and 
stakeholders.role='owner'", person.id] }
   }
 
-  named_scope :pending, :conditions=>["tasks.state IN ('ready', 'active') AND 
involved.role IN ('owner', 'potential')"],
+  named_scope :pending, :conditions=>["tasks.status IN ('ready', 'active') AND 
involved.role IN ('owner', 'potential')"],
     :order=>'involved.role, priority ASC, tasks.created_at' do
     def prioritized
       today = Date.today
-      prioritize = lambda { |task| [task.state == 'active' ? 0 : 1, 
task.due_on && task.due_on <= today ? task.due_on - today : 1, task.priority] }
+      prioritize = lambda { |task| [task.status == 'active' ? 0 : 1, 
task.due_on && task.due_on <= today ? task.due_on - today : 1, task.priority] }
       self.sort { |a, b| prioritize[a] <=> prioritize[b] }
     end
   end
@@ -186,10 +183,10 @@
   # but used to log activities associated with this task.
   attr_accessor :modified_by
 
-  before_save :unless=>lambda { |task| task.state == 'reserved' } do |task|
+  before_save :unless=>lambda { |task| task.status == 'reserved' } do |task|
     Activity.log task, task.modified_by do |log|
-      if task.changes['state']
-        from, to = *task.changes['state']
+      if task.changes['status']
+        from, to = *task.changes['status']
         log.add task.creator, 'created' if task.creator && (from.nil? || from 
== 'reserved')
         log.add 'resumed' if from == 'suspended'
         case to
@@ -259,7 +256,7 @@
 
   # Returns true if this person can cancel this task.
   def can_cancel?(person)
-    return false if state == 'completed' || state == 'cancelled'
+    return false if completed? || cancelled?
     #return true if person.admin? || admin?(person)
     #return owner?(person) if cancellation == :owner
     return true if admin?(person)

Modified: ode/sandbox/singleshot/db/migrate/20080506015046_tasks.rb
URL: 
http://svn.apache.org/viewvc/ode/sandbox/singleshot/db/migrate/20080506015046_tasks.rb?rev=658512&r1=658511&r2=658512&view=diff
==============================================================================
--- ode/sandbox/singleshot/db/migrate/20080506015046_tasks.rb (original)
+++ ode/sandbox/singleshot/db/migrate/20080506015046_tasks.rb Tue May 20 
17:31:51 2008
@@ -5,7 +5,7 @@
       t.string    :description,  :null=>false
       t.integer   :priority,     :null=>false, :limit=>1
       t.date      :due_on,       :null=>true
-      t.string    :state,        :null=>false
+      t.string    :status,       :null=>false
       t.string    :frame_url,    :null=>true
       t.string    :outcome_url,  :null=>true
       t.string    :outcome_type, :null=>true
@@ -14,7 +14,7 @@
       t.integer   :version,      :null=>false, :default=>0
       t.timestamps
     end
-    add_index :tasks, [:state, :updated_at]
+    add_index :tasks, [:status, :updated_at]
   end
 
   def self.down

Modified: ode/sandbox/singleshot/db/schema.rb
URL: 
http://svn.apache.org/viewvc/ode/sandbox/singleshot/db/schema.rb?rev=658512&r1=658511&r2=658512&view=diff
==============================================================================
--- ode/sandbox/singleshot/db/schema.rb (original)
+++ ode/sandbox/singleshot/db/schema.rb Tue May 20 17:31:51 2008
@@ -52,7 +52,7 @@
     t.string   "description",                               :null => false
     t.integer  "priority",     :limit => 1,                 :null => false
     t.date     "due_on"
-    t.string   "state",                                     :null => false
+    t.string   "status",                                    :null => false
     t.string   "frame_url"
     t.string   "outcome_url"
     t.string   "outcome_type"
@@ -63,6 +63,6 @@
     t.datetime "updated_at"
   end
 
-  add_index "tasks", ["state", "updated_at"], :name => 
"index_tasks_on_state_and_updated_at"
+  add_index "tasks", ["status", "updated_at"], :name => 
"index_tasks_on_status_and_updated_at"
 
 end

Modified: ode/sandbox/singleshot/lib/tasks/database.rake
URL: 
http://svn.apache.org/viewvc/ode/sandbox/singleshot/lib/tasks/database.rake?rev=658512&r1=658511&r2=658512&view=diff
==============================================================================
--- ode/sandbox/singleshot/lib/tasks/database.rake (original)
+++ ode/sandbox/singleshot/lib/tasks/database.rake Tue May 20 17:31:51 2008
@@ -1,57 +1,8 @@
 require 'annotate_models/tasks'
 
-namespace :db do
+namespace 'db' do
 
   desc 'Rebuild the database by running all migrations again'
   task 'rebuild'=>['environment', 'drop', 'create', 'migrate', 'test:clone', 
'annotate_models']
 
-  desc 'Populate the database with mock values'
-  task 'populate'=>['environment', 'create', 'migrate'] do
-    you = Person.find_by_identity(ENV['USER'])
-    unless you
-      you = Person.create(:email=>"#{ENV['USER'[EMAIL PROTECTED]", 
:password=>'secret')
-      puts 'Created an account for you:'
-      puts "  Username: #{ENV['USER']}"
-      puts '  Password: secret'
-    end
-
-    puts "Populating database for #{you.identity}"
-    url = 'http://localhost:3001/sandwich'
-    other = Person.identify('anon') || Person.create(:email=>'[EMAIL 
PROTECTED]')
-    Activity.delete_all
-    Stakeholder.delete_all
-    Task.delete_all
-    create = lambda do |attributes|
-      attributes = { :title=>Faker::Lorem.sentence, 
:description=>Faker::Lorem.paragraph,
-                     :frame_url=>url, :state=>'ready', :modified_by=>you 
}.merge(attributes || {})
-      Task.create!(attributes)
-    end
-    #create = lambda { |attributes| { :title=>Faker::Lorem.sentence, 
:description=>Faker::Lorem.paragraph,
-    #                                  :frame_url=>url, :state=>'ready' 
}.merge(attributes || {}) }
-
-    # Tasks you should not see.
-    create[:title=>'You will not see this task since this task is reserved.', 
:state=>'reserved', :creator=>you]
-    create[:title=>'You will not see this task since you are not a 
stakeholder.']
-    # Tasks in which we are:
-    # - creator
-    # - owner
-    # - observer
-    # - admin
-    create[:creator=>you]
-    create[:creator=>you, :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]
-    # High priority should show first.
-    create[:owner=>you, :priority=>Task::PRIORITIES.first]
-    # Over-due before due today before anything else.
-    create[:owner=>you, :due_on=>Time.today - 1.day]
-    create[:owner=>you, :due_on=>Time.today]
-    create[:owner=>you, :due_on=>Time.today + 1.day]
-  end
-
 end
-

Copied: ode/sandbox/singleshot/lib/tasks/populate.rake (from r658511, 
ode/sandbox/singleshot/lib/tasks/database.rake)
URL: 
http://svn.apache.org/viewvc/ode/sandbox/singleshot/lib/tasks/populate.rake?p2=ode/sandbox/singleshot/lib/tasks/populate.rake&p1=ode/sandbox/singleshot/lib/tasks/database.rake&r1=658511&r2=658512&rev=658512&view=diff
==============================================================================
--- ode/sandbox/singleshot/lib/tasks/database.rake (original)
+++ ode/sandbox/singleshot/lib/tasks/populate.rake Tue May 20 17:31:51 2008
@@ -1,9 +1,4 @@
-require 'annotate_models/tasks'
-
-namespace :db do
-
-  desc 'Rebuild the database by running all migrations again'
-  task 'rebuild'=>['environment', 'drop', 'create', 'migrate', 'test:clone', 
'annotate_models']
+namespace 'db' do
 
   desc 'Populate the database with mock values'
   task 'populate'=>['environment', 'create', 'migrate'] do
@@ -23,14 +18,12 @@
     Task.delete_all
     create = lambda do |attributes|
       attributes = { :title=>Faker::Lorem.sentence, 
:description=>Faker::Lorem.paragraph,
-                     :frame_url=>url, :state=>'ready', :modified_by=>you 
}.merge(attributes || {})
+                     :frame_url=>url, :modified_by=>you }.merge(attributes || 
{})
       Task.create!(attributes)
     end
-    #create = lambda { |attributes| { :title=>Faker::Lorem.sentence, 
:description=>Faker::Lorem.paragraph,
-    #                                  :frame_url=>url, :state=>'ready' 
}.merge(attributes || {}) }
 
     # Tasks you should not see.
-    create[:title=>'You will not see this task since this task is reserved.', 
:state=>'reserved', :creator=>you]
+    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.']
     # Tasks in which we are:
     # - creator
@@ -54,4 +47,3 @@
   end
 
 end
-


Reply via email to