You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whimsical.apache.org by Sam Ruby <ru...@apache.org> on 2016/03/16 16:21:33 UTC

[whimsy.git] [2/2] Commit e4f7f1b: add mail.deliver!

Commit e4f7f1b08e62b5021a1c618e346c5b7d0fec5bf2:
    add mail.deliver!


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

------------------------------------------------------------
www/board/agenda/routes.rb                                   | ++++++ 
www/board/agenda/views/actions/feedback.json.rb              | +++++++++ ---
www/board/agenda/views/feedback.html.rb                      | +++++++++ 
------------------------------------------------------------
54 changes: 51 additions, 3 deletions.
------------------------------------------------------------


diff --git a/www/board/agenda/routes.rb b/www/board/agenda/routes.rb
index e32ad99..b24deac 100755
--- a/www/board/agenda/routes.rb
+++ b/www/board/agenda/routes.rb
@@ -8,6 +8,12 @@
 end
 get %r{^/(\d\d\d\d-\d\d-\d\d)/feedback.json$} do |date|
   @agenda = "board_agenda_#{date.gsub('-', '_')}.txt".untaint
+  @dryrun = true
+  _json :'actions/feedback'
+end
+post %r{^/(\d\d\d\d-\d\d-\d\d)/feedback.json$} do |date|
+  @agenda = "board_agenda_#{date.gsub('-', '_')}.txt".untaint
+  @dryrun = false
   _json :'actions/feedback'
 end
 
diff --git a/www/board/agenda/views/actions/feedback.json.rb b/www/board/agenda/views/actions/feedback.json.rb
index 1a710f6..d8c45b3 100644
--- a/www/board/agenda/views/actions/feedback.json.rb
+++ b/www/board/agenda/views/actions/feedback.json.rb
@@ -17,9 +17,11 @@
 end
 
 # extract values for common fields
-unless @from
+if @from
+  from = @from
+else
   sender = ASF::Person.find(env.user || ENV['USER'])
-  @from = "#{sender.public_name} <#{...@apache.org>".untaint
+  from = "#{sender.public_name} <#{...@apache.org>".untaint
 end
 
 output = []
@@ -30,6 +32,7 @@
   next unless item[:attach] =~ /^(4[A-Z]|\d|[A-Z]+)$/
   next unless item['chair_email']
 
+  # collect comments and minutes
   text = ''
 
   if item['comments'] and not item['comments'].empty?
@@ -44,7 +47,7 @@
 
   # construct email
   mail = Mail.new do
-    from @from
+    from from
     to "#{item['owner']} <#{item['chair_email']}>".untaint
     subject "Board feedback on #{date} #{item['title']} report"
 
@@ -59,6 +62,9 @@
     body text.strip.untaint
   end
 
+  mail.deliver! unless @dryrun
+
+  # add to output
   output << {
     attach: item[:attach],
     title: item['title'],
diff --git a/www/board/agenda/views/feedback.html.rb b/www/board/agenda/views/feedback.html.rb
index 6aa590c..a5af238 100644
--- a/www/board/agenda/views/feedback.html.rb
+++ b/www/board/agenda/views/feedback.html.rb
@@ -1,8 +1,23 @@
 _html do
+  _head do
+    _style %{
+      div:empty {display: none}
+    }
+  end
+
   _body do
+    _div.alert
+
+    _form method: 'post' do
+      _button.btn.btn_primary 'Send email', type: 'submit', disabled: true
+    end
+
     _p 'loading'
 
     _script %{
+      var button = document.querySelector('button');
+      var alert = document.querySelector('.alert');
+
       jQuery.getJSON('feedback.json', function(data) {
         data.forEach(function(message) {
           var h1 = document.createElement('h1');
@@ -13,7 +28,28 @@
           document.body.appendChild(h1);
           document.body.appendChild(pre);
         });
+
         document.querySelector('p').remove();
+
+        button.disabled = false;
+      });
+
+      button.addEventListener('click', function(event) {
+        event.preventDefault();
+        button.disabled = true;
+        jQuery.ajax('feedback.json', {
+          method: 'POST',
+
+          success: function(event) {
+            alert.classList.add('alert-success');
+            alert.textContent = 'emails sent';
+          },
+
+          error: function(event) {
+            alert.classList.add('alert-danger');
+            alert.textContent = event.statusText;
+          }
+        });
       });
     }
   end