Permalink
Browse files

pause/resume expression (breakpoint too)

  • Loading branch information...
jmettraux committed Jun 19, 2011
1 parent 7303af6 commit f87358b0ada1db7e9fd62378a7c8e0986743a255
Showing with 367 additions and 177 deletions.
  1. +1 −0 CHANGELOG.txt
  2. +34 −26 lib/ruote-kit/resources/expressions.rb
  3. +33 −9 lib/ruote-kit/views/expression.html.haml
  4. +299 −142 spec/resources/expressions_spec.rb
View
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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}
@@ -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;
}
Oops, something went wrong.

0 comments on commit f87358b

Please sign in to comment.