Author: assaf
Date: Fri Jun 6 20:26:38 2008
New Revision: 664259
URL: http://svn.apache.org/viewvc?rev=664259&view=rev
Log:
Form now gets and updates task status in task manager.
Modified:
ode/sandbox/singleshot/app/controllers/sandwiches_controller.rb
ode/sandbox/singleshot/app/controllers/task_for_controller.rb
ode/sandbox/singleshot/app/models/sandwich.rb
ode/sandbox/singleshot/app/models/task.rb
Modified: ode/sandbox/singleshot/app/controllers/sandwiches_controller.rb
URL:
http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/controllers/sandwiches_controller.rb?rev=664259&r1=664258&r2=664259&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/controllers/sandwiches_controller.rb (original)
+++ ode/sandbox/singleshot/app/controllers/sandwiches_controller.rb Fri Jun 6
20:26:38 2008
@@ -7,12 +7,11 @@
before_filter :instance
def show
- [EMAIL PROTECTED] = true unless params['perform'] == 'true'
end
def update
@sandwich.update_attributes params['sandwich']
- if @sandwich.save
+ if @sandwich.save(@task['update_url'])
flash[:success] = 'Changes have been saved.'
redirect_to :back
else
@@ -22,9 +21,9 @@
def create
@sandwich.update_attributes params['sandwich']
- if @sandwich.save
+ if @sandwich.save(@task['update_url'], true)
flash[:success] = 'Changes have been saved.'
- redirect_to params['complete_url']
+ redirect_to @task['redirect_url']
else
render :action=>'show'
end
@@ -33,11 +32,14 @@
private
def instance
- [EMAIL PROTECTED] = params['task_url'] or raise
ActiveRecord::RecordNotFound
- #uri = URI(@task_url)
- #xml = REXML::Document.new(open(uri.to_s,
:http_basic_authentication=>[uri.user, uri.password]))
- session[:sandwich] = @sandwich = Sandwich.new(session[:sandwich])
- [EMAIL PROTECTED] = true if @sandwich.status == 'completed'
+ uri = URI(params['task_url'])
+ xml = uri.read(:http_basic_authentication=>[uri.user, uri.password],
'Content-Type'=>Mime::XML.to_s)
+ @task = Hash.from_xml(xml)['task']
+ logger.info @task['update_url']
+ @sandwich = Sandwich.new(@task['data'])
+ rescue =>error
+ logger.error error
+ raise ActiveRecord::RecordNotFound
end
end
Modified: ode/sandbox/singleshot/app/controllers/task_for_controller.rb
URL:
http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/controllers/task_for_controller.rb?rev=664259&r1=664258&r2=664259&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/controllers/task_for_controller.rb (original)
+++ ode/sandbox/singleshot/app/controllers/task_for_controller.rb Fri Jun 6
20:26:38 2008
@@ -2,24 +2,29 @@
before_filter :authenticate
verify :params=>'task', :only=>:update
+ include TaskHelper
def show
respond_to do |wants|
- wants.xml { render :xml=>@task }
- wants.json { render :json=>@task }
+ wants.xml { render :xml=>state.to_xml(:root=>'task') }
+ wants.json { render :json=>state.to_json }
end
end
def update
@task.modify_by(@person).update_attributes! params[:task]
- respond_to do |wants|
- wants.xml { render :xml=>@task }
- wants.json { render :json=>@task }
- end
+ show
end
private
+ def state
+ attributes = { 'id'=>@task.id, 'url'=>task_url(@task),
'title'=>@task.title, 'description'=>@task.description,
+ 'status'=>@task.status, 'owner'=>@task.owner.to_param,
'data'=>@task.data }
+ attributes.update 'update_url'=>task_for_person_url(@task, @person),
'redirect_url'=>complete_redirect_tasks_url if @task.owner?(@person)
+ attributes
+ end
+
def authenticate
@task = Task.with_stakeholders.find(params[:task_id])
@person = Person.identify(params[:person_id])
Modified: ode/sandbox/singleshot/app/models/sandwich.rb
URL:
http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/models/sandwich.rb?rev=664259&r1=664258&r2=664259&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/models/sandwich.rb (original)
+++ ode/sandbox/singleshot/app/models/sandwich.rb Fri Jun 6 20:26:38 2008
@@ -4,10 +4,12 @@
name.titleize
end
- def initialize(other = nil)
- ['bread', 'spread', 'toppings'].each do |name|
- send "#{name}=", other.send(name)
- end if other
+ def initialize(attributes = {})
+ if attributes
+ ['bread', 'spread', 'toppings'].each do |name|
+ send "#{name}=", attributes[name]
+ end
+ end
end
attr_accessor :bread, :spread, :toppings
@@ -26,9 +28,18 @@
end
end
- def save
+ def save(url, completed = false)
validate
errors.empty?
+ data = ['bread', 'spread', 'toppings'].inject({}) { |hash, name|
hash.update(name=>send(name)) }
+ task = { 'data'=>data }
+ task.update 'status'=>'completed' if completed
+ uri = URI(url)
+ http = Net::HTTP.new(uri.host, uri.port)
+ post = Net::HTTP::Put.new(uri.path)
+ post.basic_auth uri.user, uri.password
+ post.content_type = Mime::XML.to_s
+ http.request(post, task.to_xml(:root=>'task'))
end
private
Modified: ode/sandbox/singleshot/app/models/task.rb
URL:
http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/models/task.rb?rev=664259&r1=664258&r2=664259&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/models/task.rb (original)
+++ ode/sandbox/singleshot/app/models/task.rb Fri Jun 6 20:26:38 2008
@@ -438,7 +438,7 @@
enumerable :cancellation, [:admin, :owner], :default=>:admin
def can_cancel?(person)
- admin?(person) && !completed && !cancelled?
+ admin?(person) && !completed? && !cancelled?
end
def can_complete?(person)