whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sam Ruby <ru...@apache.org>
Subject [whimsy.git] [1/1] Commit a6f7875: implement dryrun for sascore
Date Sat, 02 Apr 2016 13:43:22 GMT
Commit a6f7875d06e335afead6991ab7bf782d5977f0ee:
    implement dryrun for sascore


Branch: refs/heads/master
Author: Sam Ruby <rubys@intertwingly.net>
Committer: Sam Ruby <rubys@intertwingly.net>
Pusher: rubys <rubys@apache.org>

------------------------------------------------------------
www/roster/public/stylesheets/app.css                        | +++++ -
www/roster/views/committer.js.rb                             | ++++++++++ --
------------------------------------------------------------
51 changes: 43 additions, 8 deletions.
------------------------------------------------------------


diff --git a/www/roster/public/stylesheets/app.css b/www/roster/public/stylesheets/app.css
index d7b5d44..4cc707b 100644
--- a/www/roster/public/stylesheets/app.css
+++ b/www/roster/public/stylesheets/app.css
@@ -53,7 +53,11 @@ pre.wide {padding: 0 8px; width: 60em; overflow-x: hidden; margin: 6px
0}
 pre.wide:hover {overflow-x: scroll}
 
 form.inline {display: inline}
-form.inline div label {min-width: 8em; text-align: right}
+form.inline div label {min-width: 7em; text-align: right}
 form.inline div input {min-width: 20em}
 form.inline button {margin-left: 10em}
 form.inline textarea {height: 20em; width: 60em}
+
+input:disabled[type=submit] {cursor: not-allowed}
+
+.modal textarea {width: 100%; height: 30em}
diff --git a/www/roster/views/committer.js.rb b/www/roster/views/committer.js.rb
index 2d1a040..8ffd3ee 100644
--- a/www/roster/views/committer.js.rb
+++ b/www/roster/views/committer.js.rb
@@ -1,6 +1,7 @@
 class Committer < React
   def initialize
     @committer = {}
+    @response = nil
   end
 
   def render
@@ -273,6 +274,24 @@ def render
         end
       end
     end
+
+    # modal dialog for dry run results
+    _div.modal.fade tabindex: -1 do
+      _div.modal_dialog do
+        _div.modal_content do
+          _div.modal_header do
+            _button.close 'x', data_dismiss: 'modal'
+            _h4 'Dry run results'
+          end
+          _div.modal_body do
+            _textarea value: JSON.stringify(@response, nil, 2), readonly: true
+          end
+          _div.modal_footer do
+            _button.btn.btn_default 'Close', data_dismiss: 'modal'
+          end
+        end
+      end
+    end
   end
 
   # capture committer on initial load
@@ -326,12 +345,21 @@ def submit(event)
     form = jQuery(event.currentTarget).closest('form')
     target = event.target
 
+    # serialize form
     formData = form.serializeArray();
-    if target and target.getAttribute('value')
+
+    # add button if it has a value
+    if target and target.getAttribute('name') and target.getAttribute('value')
       formData.push name: target.getAttribute('name'),
         value: target.getAttribute('value')
     end
 
+    # indicate dryrun is requested if option or control key is down
+    if event.altKey or event.ctrlKey
+      formData.unshift name: 'dryrun', value: true 
+    end
+
+    # issue request
     jQuery.ajax(
       method: (form[0].method || 'GET').upcase(),
       url: document.location.href + '/' + form[0].getAttribute('data-action'),
@@ -356,15 +384,18 @@ def submit(event)
       },
 
       complete: ->(response) do
-        # reenable form for later reuse
-        Array(form[0].querySelectorAll('input, button')).each do |input|
-          input.disabled = false
+        # show results of dryrun
+        if formData[0] and formData[0].name == 'dryrun'
+          @response = response.responseJSON
+          jQuery('div.modal').modal('show')
         end
+
+        # reenable form for later reuse
+        jQuery('input, button', form).prop('disabled', false)
       end
     )
 
-    Array(form[0].querySelectorAll('input, button')).each do |input|
-      input.disabled = true
-    end
+    # disable input
+    jQuery('input, button', form).prop('disabled', true)
   end
 end

Mime
View raw message