Skip to content

Commit

Permalink
pause/resume expression (breakpoint too)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmettraux committed Jun 19, 2011
1 parent 7303af6 commit f87358b
Show file tree
Hide file tree
Showing 4 changed files with 367 additions and 177 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Expand Up @@ -4,6 +4,7 @@

== ruote-kit - 2.2.1 not yet released

- Pause/resume expression (breakpoint too)
- Pause/resume process instance
- Upgraded to Haml 3.1.2
- Making sure run_worker really sets RuoteKit.engine
Expand Down
60 changes: 34 additions & 26 deletions lib/ruote-kit/resources/expressions.rb
Expand Up @@ -5,7 +5,7 @@ class RuoteKit::Application

get '/_ruote/expressions/:id' do

@process, @expression, fei = fetch_pe
@process, @expression, fei = fetch_pef

return http_error(404) unless @process

Expand All @@ -24,7 +24,7 @@ class RuoteKit::Application

delete '/_ruote/expressions/:id' do

process, expression, fei = fetch_pe
process, expression, fei = fetch_pef

return http_error(404) unless expression

Expand All @@ -44,38 +44,45 @@ class RuoteKit::Application

put '/_ruote/expressions/:id' do

process, expression, fei = fetch_pe
process, exp, fei = fetch_pef

return http_error(404) unless expression
return http_error(404) unless exp

check_if_match_etag(expression.to_h['_rev'])
check_if_match_etag(exp.to_h['_rev'])

info = begin
fetch_re_apply_info
fetch_expression_put_info
rescue Rufus::Json::ParserError => pe
return http_error(400, pe)
end

#puts '-' * 80
#p params
#p info
#puts '-' * 80
if state = info['state']

options = {}
options[:fields] = info.fields if info.fields
options[:tree] = info.tree if info.tree
if state == 'paused'
RuoteKit.engine.pause(exp.fei, :breakpoint => info['breakpoint'])
else
RuoteKit.engine.resume(exp.fei)
end

RuoteKit.engine.re_apply(expression.fei, options)
route = request.route
route = route + '.json' if request.media_type.match(/json/) # :-(

respond_to do |format|
format.html { redirect url("/_ruote/expressions/#{expression.fei.wfid}") }
format.json { json :status, :ok }
redirect(url(route))

else

RuoteKit.engine.re_apply(exp.fei, info)

respond_to do |format|
format.html { redirect url("/_ruote/expressions/#{exp.fei.wfid}") }
format.json { json :status, :ok }
end
end
end

protected

def fetch_pe
def fetch_pef

fei = params[:id].split('!')
wfid = fei.last
Expand All @@ -91,21 +98,22 @@ def fetch_pe
[ process, expression, fei ]
end

def fetch_re_apply_info
def fetch_expression_put_info

if request.content_type == 'application/json'

data = Rufus::Json.decode(request.body.read)

OpenStruct.new(
data['expression'] ? data['expression'] : data
)
data['expression'] ? data['expression'] : data

else

OpenStruct.new(
'fields' => params[:fields] ? Rufus::Json.decode(params[:fields]) : nil,
'tree' => params[:tree] ? Rufus::Json.decode(params[:tree]) : nil
)
{
'state' => params[:state],
'breakpoint' => !!params[:breakpoint],
:fields => params[:fields] ? Rufus::Json.decode(params[:fields]) : nil,
:tree => params[:tree] ? Rufus::Json.decode(params[:tree]) : nil
}
end
end
end
Expand Down
42 changes: 33 additions & 9 deletions lib/ruote-kit/views/expression.html.haml
Expand Up @@ -12,6 +12,7 @@
%form{ :method => 'POST', :enctype => 'multipart/form-data', :accept_charset => 'UTF-8' }

%input#_method{ :type => 'hidden', :name => '_method', :value => 'DELETE' }
%input#state{ :type => 'hidden', :name => 'state', :value => '' }
%input{ :type => 'hidden', :name => '_snowman', :value => '☃' }

%table.details
Expand Down Expand Up @@ -102,12 +103,27 @@

%tr
%td
%input{ :type => 'submit', :value => 'cancel', :onclick => 'return confirm("really ?");' }
- if @expression.state == 'paused'
%input{ :type => 'submit', :value => 'resume', :onclick => 'return confirmPut("really resume expression ?");' }
- else
%input{ :type => 'submit', :value => 'pause', :onclick => 'return confirmPut("really pause expression ?");' }
%input{ :type => 'checkbox', :name => 'breakpoint' }
breakpoint
%td
%span.description PUT /_ruote/expressions/#{@expression.fei.sid}

%tr
%td.no_border{ :colspan => 2 }
 

%tr
%td
%input{ :type => 'submit', :value => 'cancel', :onclick => 'return confirm("really cancel expression?");' }
%td
%span.description DELETE /_ruote/expressions/#{@expression.fei.sid}
%tr
%td
%input{ :type => 'submit', :value => 'kill', :onclick => 'return confirm("really ?");' }
%input{ :type => 'submit', :value => 'kill', :onclick => 'return confirm("really kill expression ?");' }
%td
%span.description DELETE /_ruote/expressions/#{@expression.fei.sid}?_kill=1

Expand Down Expand Up @@ -137,8 +153,7 @@
%tr.re_apply
%td
%td
-#%input{ :type => 'hidden', :name => '_method', :value => 'PUT' }
%input{ :type => 'submit', :value => 're-apply', :onclick => 'return confirmReApply();' }
%input{ :type => 'submit', :value => 're-apply', :onclick => 'return confirmPut("really re_apply ?");' }
%span.description PUT /_ruote/expressions/#{@expression.fei.sid}


Expand All @@ -152,15 +167,24 @@

$('.re_apply').hide();

function showReApply (elt) {
function showReApply(elt) {
$(elt).hide();
$('.re_apply').show();
}

function confirmReApply () {

var r = confirm('really ?');
if (r) $('#_method')[0].value = 'PUT';
function confirmPut(message) {

var r = confirm(message);
if (r) {
$('#_method')[0].value = 'PUT';
if (message.match(/pause/)) {
$('#state')[0].value = 'paused';
} else if (message.match(/resume/)) {
$('#state')[0].value = 'resuming';
} else {
$('#state').detach();
}
}

return r;
}
Expand Down

0 comments on commit f87358b

Please sign in to comment.