This is an automated email from the ASF dual-hosted git repository.

rubys pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git


The following commit(s) were added to refs/heads/master by this push:
     new 2278ce7  rough in action item reminder emails
2278ce7 is described below

commit 2278ce7202c4b3de18c795e52f73b63c893e3cf8
Author: Sam Ruby <[email protected]>
AuthorDate: Thu Jan 9 17:53:21 2020 -0500

    rough in action item reminder emails
---
 .../agenda/views/actions/remind-actions.json.rb    | 60 ++++++++++++++++++
 .../agenda/views/actions/send-reminders.json.rb    |  2 +-
 www/board/agenda/views/app.js.rb                   |  1 +
 www/board/agenda/views/buttons/post-actions.js.rb  |  2 +-
 .../agenda/views/buttons/remind-actions.js.rb      | 71 ++++++++++++++++++++++
 www/board/agenda/views/pages/action-items.js.rb    |  4 ++
 6 files changed, 138 insertions(+), 2 deletions(-)

diff --git a/www/board/agenda/views/actions/remind-actions.json.rb 
b/www/board/agenda/views/actions/remind-actions.json.rb
new file mode 100644
index 0000000..6690300
--- /dev/null
+++ b/www/board/agenda/views/actions/remind-actions.json.rb
@@ -0,0 +1,60 @@
+#
+# send reminders for action items
+#
+
+ASF::Mail.configure
+
+sent = {}
+unsent = []
+
+# extract a list of people from the agenda and committee-info.txt
+agenda = Agenda.parse(@agenda, :full)
+people = agenda[1]['people'].to_a +
+  (ASF::Committee.officers+ASF::Committee.nonpmcs).map(&:chairs).flatten.uniq.
+  map {|person| [person[:id], person.merge(role: :info)]}
+
+# build a mapping of first names to availids
+order = {director: 4, officer: 3, guest: 2, info: 1}
+name_map =  people.sort_by {|key,value| order[value[:role]]}.
+    map {|key, value| [value[:name].split(' ').first, key]}.to_h
+
+# extract values for common fields
+from = @from
+unless from
+  sender = ASF::Person.find(env.user)
+  from = "#{sender.public_name.inspect} <#{sender.id}@apache.org>".untaint
+end
+
+# iterate over the action items
[email protected]_by {|action| action['owner']}.each do |owner, actions|
+  person = ASF::Person[name_map[owner]]
+
+  # bail if owner can't be found
+  unless person
+    unsent << owner
+    next
+  end
+
+  body = "The following action items need your attention:\n"
+  body.sub!('items need', 'item needs') if actions.length == 1
+  body += actions.map do |action|
+    "\n* #{action['text']}\n  [ #{action['pmc']} #{action['date']} ]\n"
+  end.join
+
+  # construct email
+  mail = Mail.new do
+    from from
+    to "#{person.public_name} <#{person.id}@apache.org>".untaint
+    cc "[email protected]"
+    subject 'Action Item reminder'
+
+    body body
+  end
+
+  # deliver mail
+  mail.deliver! unless @dryrun
+  sent[person.id] = mail.to_s
+end
+
+# provide a response to the request
+{count: sent.length, unsent: unsent, sent: sent, dryrun: @dryrun}
diff --git a/www/board/agenda/views/actions/send-reminders.json.rb 
b/www/board/agenda/views/actions/send-reminders.json.rb
index e5c7461..13beab2 100644
--- a/www/board/agenda/views/actions/send-reminders.json.rb
+++ b/www/board/agenda/views/actions/send-reminders.json.rb
@@ -1,5 +1,5 @@
 #
-# send reminders
+# send reminders for missing board reports
 #
 
 ASF::Mail.configure
diff --git a/www/board/agenda/views/app.js.rb b/www/board/agenda/views/app.js.rb
index d45c075..7754e22 100644
--- a/www/board/agenda/views/app.js.rb
+++ b/www/board/agenda/views/app.js.rb
@@ -49,6 +49,7 @@ require_relative 'buttons/post'
 require_relative 'buttons/post-actions'
 require_relative 'buttons/publish-minutes'
 require_relative 'buttons/reminders'
+require_relative 'buttons/remind-actions'
 require_relative 'buttons/refresh'
 require_relative 'buttons/showseen'
 require_relative 'buttons/summary'
diff --git a/www/board/agenda/views/buttons/post-actions.js.rb 
b/www/board/agenda/views/buttons/post-actions.js.rb
index 12c67c7..7f00c31 100644
--- a/www/board/agenda/views/buttons/post-actions.js.rb
+++ b/www/board/agenda/views/buttons/post-actions.js.rb
@@ -1,5 +1,5 @@
 #
-# Indicate intention to attend / regrets for meeting
+# Post Action items
 #
 class PostActions < Vue
   def initialize
diff --git a/www/board/agenda/views/buttons/remind-actions.js.rb 
b/www/board/agenda/views/buttons/remind-actions.js.rb
new file mode 100644
index 0000000..cac814b
--- /dev/null
+++ b/www/board/agenda/views/buttons/remind-actions.js.rb
@@ -0,0 +1,71 @@
+#
+# Send reminders for action items
+#
+class ActionReminder < Vue
+  def initialize
+    @disabled = false
+    @list = @@item.actions.map do |action|
+      Object.assign({complete: action.status != ""}, action)
+    end
+  end
+
+  # default attributes for the button associated with this form
+  def self.button
+    {
+      text: 'send reminders',
+      class: 'btn_primary',
+      data_toggle: 'modal',
+      data_target: '#reminder-form'
+    }
+  end
+
+  # commit form: allow the user to select which reminders to send
+  def render
+    _ModalDialog.reminder_form!.wide_form color: 'blank' do
+      # header
+      _h4 'Send reminders'
+
+      _pre.report do
+        @list.each do |action|
+          _CandidateAction action: action
+        end
+      end
+
+      # buttons
+      _button.btn_default 'Close', data_dismiss: 'modal'
+      _button.btn_info 'Dry Run', onClick: self.click, disabled: @disabled
+      _button.btn_primary 'Submit', onClick: self.click, disabled: @disabled
+    end
+  end
+
+  def click(event)
+    dryrun = (event.target.textContent == 'Dry Run')
+
+    data = {
+      dryrun: dryrun,
+      agenda: Agenda.file,
+      actions: @list.select {|item| !item.complete}
+    }
+
+    @disabled = true
+    post 'remind-actions', data do |response|
+      if not response
+        alert("Server error - check console log")
+      elsif dryrun
+        console.log response
+        alert("Dry run - check console log")
+      elsif response.count == @list.length
+        alert("Reminders have been sent to: #{response.sent.keys.join(', ')}.")
+      elsif response.count and response.unsent
+        alert("Error: no emails were sent to #{response.unsent.join(', ')}")
+      else
+        alert("No reminders were sent")
+      end
+
+      @disabled = false
+      Agenda.load response.agenda, response.digest
+      jQuery('#reminder-form').modal(:hide)
+      document.body.classList.remove('modal-open')
+    end
+  end
+end
diff --git a/www/board/agenda/views/pages/action-items.js.rb 
b/www/board/agenda/views/pages/action-items.js.rb
index 19ebcc4..81ee671 100644
--- a/www/board/agenda/views/pages/action-items.js.rb
+++ b/www/board/agenda/views/pages/action-items.js.rb
@@ -8,6 +8,10 @@ class ActionItems < Vue
     @disabled = false
   end
 
+  def self.buttons()
+    return [{form: ActionReminder}]
+  end
+
   def render
     first = true
 

Reply via email to