whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ru...@apache.org
Subject [whimsy] branch master updated: refactor to have a shared confirmation dialog
Date Mon, 23 Jan 2017 17:16:32 GMT
This is an automated email from the ASF dual-hosted git repository.

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

The following commit(s) were added to refs/heads/master by this push:
       new  c1f3295   refactor to have a shared confirmation dialog
c1f3295 is described below

commit c1f32958d7b9622eaf9d327f0786ae185f9a39a0
Author: Sam Ruby <rubys@intertwingly.net>
AuthorDate: Mon Jan 23 12:16:01 2017 -0500

    refactor to have a shared confirmation dialog
---
 www/roster/views/actions/committee.json.rb | 55 ++++++++++++--------
 www/roster/views/actions/ppmc.json.rb      |  6 +--
 www/roster/views/app.js.rb                 |  4 +-
 www/roster/views/{ppmc => }/confirm.js.rb  | 11 ++--
 www/roster/views/pmc/committers.js.rb      |  2 +-
 www/roster/views/pmc/confirm.js.rb         | 82 ------------------------------
 www/roster/views/pmc/main.js.rb            |  4 +-
 www/roster/views/pmc/pmc.js.rb             |  2 +-
 www/roster/views/ppmc/main.js.rb           |  2 +-
 9 files changed, 53 insertions(+), 115 deletions(-)

diff --git a/www/roster/views/actions/committee.json.rb b/www/roster/views/actions/committee.json.rb
index 2e61e1c..4af718f 100644
--- a/www/roster/views/actions/committee.json.rb
+++ b/www/roster/views/actions/committee.json.rb
@@ -1,16 +1,16 @@
 if env.password
-  person = ASF::Person.find(@id)
-  pmc = ASF::Committee.find(@pmc) if @targets.include? 'pmc'
-  group = ASF::Group.find(@pmc) if @targets.include? 'commit'
+  people = @ids.split(',').map {|id| ASF::Person.find(id)}
+  pmc = ASF::Committee.find(@project) if @targets.include? 'pmc'
+  group = ASF::Group.find(@project) if @targets.include? 'commit'
 
   # update LDAP
   ASF::LDAP.bind(env.user, env.password) do
     if @action == 'add'
-      pmc.add(person) if pmc
-      group.add(person) if group
+      pmc.add(people) if pmc
+      group.add(people) if group
     elsif @action == 'remove'
-      pmc.remove(person) if pmc
-      group.remove(person) if group
+      pmc.remove(people) if pmc
+      group.remove(people) if group
     end
   end
 
@@ -29,20 +29,23 @@ if env.password
 
       info.scan(/^\* (?:.|\n)*?\n\s*?\n/).each do |block|
         # find committee
-        next unless ASF::Committee.find(block[/\* (.*?)\s+\(/, 1]).id == @pmc
+        next unless ASF::Committee.find(block[/\* (.*?)\s+\(/, 1]).id==@project
 
         # split block into lines
         lines = block.strip.split("\n")
 
-        # add or remove person
-        if @action == 'add'
-          unless lines.any? {|line| line.include? "<#{@id}@apache.org>"}
-            name = "#{person.public_name.ljust(26)} <#{@id}@apache.org>"
-            time = Time.new.gmtime.strftime('%Y-%m-%d')
-            lines << "    #{name.ljust(59)} [#{time}]"
+        # add or remove people
+        people.each do |person|
+          id = person.id
+          if @action == 'add'
+            unless lines.any? {|line| line.include? "<#{id}@apache.org>"}
+              name = "#{person.public_name.ljust(26)} <#{id}@apache.org>"
+              time = Time.new.gmtime.strftime('%Y-%m-%d')
+              lines << "    #{name.ljust(59)} [#{time}]"
+            end
+          else
+            lines.reject! {|line| line.include? "<#{id}@apache.org>"}
           end
-        else
-          lines.reject! {|line| line.include? "<#{@id}@apache.org>"}
         end
 
         # replace committee block with new information
@@ -58,7 +61,7 @@ if env.password
         '--no-auth-cache', '--non-interactive',
         '--username', env.user.untaint, '--password', env.password.untaint,
         tmpdir.untaint, '--message',
-        "#{@pmc} #{@action == 'add' ? '+' : '-'}= #{@id}"
+        "#{@project} #{@action == 'add' ? '+' : '-'}= #{@id}"
 
       if rc
         # update cache
@@ -80,22 +83,32 @@ if env.password
     list = 'committers list'
   end
 
-  details = [person.dn]
+  details = people.map {|person| person.dn}
   details << group.dn if group
   details << pmc.dn if pmc
 
-  pmc ||= ASF::Committee.find(@pmc)
+  pmc ||= ASF::Committee.find(@project)
   from = ASF::Person.find(env.user)
 
+  # extract people's names (for short lists) or ids (for longer lists)
+  if people.length <= 2
+    who = people.map {|person| person.public_name}.join(' and ')
+  else
+    who = people[0..-2].map {|person| person.id}.join(', ') + 
+      ', and ' + person.last.id
+  end
+
+  # draft email
   mail = Mail.new do
     from "#{from.public_name} <#{from.id}@apache.org>".untaint
     to "private@#{pmc.mail_list}.apache.org".untaint
     bcc "root@apache.org"
-    subject "#{person.public_name} #{action} #{pmc.display_name} #{list}"
+    subject "#{who} #{action} #{pmc.display_name} #{list}"
     body "Current roster can be found at:\n\n" +
       "  https://whimsy.apache.org/roster/committee/#{pmc.id}\n\n" +
       "LDAP details:\n\n  #{details.join("\n  ")}"
   end
+
   # Header for root@'s lovely email filters
   mail.header['X-For-Root'] = 'yes'
 
@@ -104,4 +117,4 @@ if env.password
 end
 
 # return updated committee info to the client
-Committee.serialize(@pmc, env)
+Committee.serialize(@project, env)
diff --git a/www/roster/views/actions/ppmc.json.rb b/www/roster/views/actions/ppmc.json.rb
index 8cd5281..0b9196d 100644
--- a/www/roster/views/actions/ppmc.json.rb
+++ b/www/roster/views/actions/ppmc.json.rb
@@ -1,6 +1,6 @@
 if env.password
   people = @ids.split(',').map {|id| ASF::Person.find(id)}
-  project = ASF::Project.find(@ppmc)
+  project = ASF::Project.find(@project)
 
   # update LDAP
   ASF::LDAP.bind(env.user, env.password) do
@@ -15,7 +15,7 @@ if env.password
   action = (@action == 'add' ? 'added to' : 'removed from')
   details = people.map {|person| person.dn} + [project.dn]
   from = ASF::Person.find(env.user)
-  ppmc = ASF::Podling.find(@ppmc)
+  ppmc = ASF::Podling.find(@project)
 
   # extract people's names (for short lists) or ids (for longer lists)
   if people.length <= 2
@@ -45,4 +45,4 @@ if env.password
 end
 
 # return updated committee info to the client
-PPMC.serialize(@ppmc, env)
+PPMC.serialize(@project, env)
diff --git a/www/roster/views/app.js.rb b/www/roster/views/app.js.rb
index 16f9275..8161602 100644
--- a/www/roster/views/app.js.rb
+++ b/www/roster/views/app.js.rb
@@ -3,7 +3,6 @@ require_relative 'polyfill'
 require_relative 'pmc/main'
 require_relative 'pmc/pmc'
 require_relative 'pmc/committers'
-require_relative 'pmc/confirm'
 
 require_relative 'person'
 require_relative 'person/fullname'
@@ -19,8 +18,9 @@ require_relative 'person/sascore'
 
 require_relative 'ppmc/main'
 require_relative 'ppmc/members'
-require_relative 'ppmc/confirm'
 
 require_relative 'committerSearch'
+require_relative 'confirm'
 
 require_relative 'group'
+
diff --git a/www/roster/views/ppmc/confirm.js.rb b/www/roster/views/confirm.js.rb
similarity index 90%
rename from www/roster/views/ppmc/confirm.js.rb
rename to www/roster/views/confirm.js.rb
index 2ff8f5e..1c2f132 100644
--- a/www/roster/views/ppmc/confirm.js.rb
+++ b/www/roster/views/confirm.js.rb
@@ -2,7 +2,7 @@
 # Confirmation dialog
 #
 
-class PPMCConfirm < React
+class Confirm < React
   def initialize
     @text = 'text'
     @color = 'btn-default'
@@ -56,12 +56,17 @@ class PPMCConfirm < React
       method: 'post',
       credentials: 'include',
       headers: {'Content-Type' => 'application/json'},
-      body: {ppmc: @@ppmc, ids: @ids, action: action, targets: targets}.inspect
+      body: {
+        project: @@project, 
+        ids: @ids, 
+        action: action, 
+        targets: targets
+      }.inspect
     }
 
     @disabled = true
     Polyfill.require(%w(Promise fetch)) do
-      fetch('actions/ppmc', args).then {|response|
+      fetch("actions/#{@@action}", args).then {|response|
         content_type = response.headers.get('content-type') || ''
         if response.status == 200 and content_type.include? 'json'
           response.json().then do |json|
diff --git a/www/roster/views/pmc/committers.js.rb b/www/roster/views/pmc/committers.js.rb
index d04a6bb..0a14cbd 100644
--- a/www/roster/views/pmc/committers.js.rb
+++ b/www/roster/views/pmc/committers.js.rb
@@ -95,7 +95,7 @@ class PMCCommitter < React
       end
 
       if @state == :open
-        _td data_id: @@person.id do 
+        _td data_ids: @@person.id do 
           if @@person.date == 'pending'
             _button.btn.btn_primary 'Add as a committer only',
               data_action: 'add commit', 
diff --git a/www/roster/views/pmc/confirm.js.rb b/www/roster/views/pmc/confirm.js.rb
deleted file mode 100644
index c43c479..0000000
--- a/www/roster/views/pmc/confirm.js.rb
+++ /dev/null
@@ -1,82 +0,0 @@
-#
-# Confirmation dialog
-#
-
-class PMCConfirm < React
-  def initialize
-    @text = 'text'
-    @color = 'btn-default'
-    @button = 'OK'
-    @disabled = false
-  end
-
-  def render
-    _div.modal.fade.confirm! tabindex: -1 do
-      _div.modal_dialog do
-        _div.modal_content do
-          _div.modal_header.bg_info do
-            _button.close 'x', data_dismiss: 'modal'
-            _h4.modal_title 'Confirm Request'
-          end
-
-          _div.modal_body do
-            _p @text
-          end
-
-          _div.modal_footer do
-            _span.status 'Processing request...' if @disabled
-            _button.btn.btn_default 'Cancel', data_dismiss: 'modal',
-              disabled: @disabled
-            _button.btn @button, class: @color, onClick: self.post,
-              disabled: @disabled
-          end
-        end
-      end
-    end
-  end
-
-  def componentDidMount()
-    jQuery('#confirm').on('show.bs.modal') do |event|
-      button = event.relatedTarget
-      @id = button.parentNode.dataset.id
-      @action = button.dataset.action
-      @text = button.dataset.confirmation
-      @color = button.classList[1]
-      @button = button.textContent
-    end
-  end
-
-  def post()
-    # parse action extracted from the button
-    targets = @action.split(' ')
-    action = targets.shift()
-
-    # construct arguments to fetch
-    args = {
-      method: 'post',
-      credentials: 'include',
-      headers: {'Content-Type' => 'application/json'},
-      body: {pmc: @@pmc, id: @id, action: action, targets: targets}.inspect
-    }
-
-    @disabled = true
-    Polyfill.require(%w(Promise fetch)) do
-      fetch('actions/committee', args).then {|response|
-        content_type = response.headers.get('content-type') || ''
-        if response.status == 200 and content_type.include? 'json'
-          response.json().then do |json|
-            @@update.call(json)
-          end
-        else
-          alert "#{response.status} #{response.statusText}"
-        end
-        jQuery('#confirm').modal(:hide)
-        @disabled = false
-      }.catch {|error|
-        alert errror
-        jQuery('#confirm').modal(:hide)
-        @disabled = false
-      }
-    end
-  end
-end
diff --git a/www/roster/views/pmc/main.js.rb b/www/roster/views/pmc/main.js.rb
index 5ede89b..9114eff 100644
--- a/www/roster/views/pmc/main.js.rb
+++ b/www/roster/views/pmc/main.js.rb
@@ -78,7 +78,9 @@ class PMC < React
     end
 
     # hidden form
-    _PMCConfirm pmc: @committee.id, update: self.update if auth
+    if auth
+      _Confirm action: :committee, project: @committee.id, update: self.update
+    end
   end
 
   # capture committee on initial load
diff --git a/www/roster/views/pmc/pmc.js.rb b/www/roster/views/pmc/pmc.js.rb
index a6bca48..1213423 100644
--- a/www/roster/views/pmc/pmc.js.rb
+++ b/www/roster/views/pmc/pmc.js.rb
@@ -104,7 +104,7 @@ class PMCMember < React
       _td @@person.date
 
       if @state == :open
-        _td data_id: @@person.id do 
+        _td data_ids: @@person.id do 
           if @@person.date == 'pending'
             _button.btn.btn_primary 'Add as a committer and to the PMC',
               # not added yet
diff --git a/www/roster/views/ppmc/main.js.rb b/www/roster/views/ppmc/main.js.rb
index 28267ea..d4192d4 100644
--- a/www/roster/views/ppmc/main.js.rb
+++ b/www/roster/views/ppmc/main.js.rb
@@ -54,7 +54,7 @@ class PPMC < React
     end
 
     # hidden form
-    _PPMCConfirm ppmc: @ppmc.id, update: self.update if auth
+    _Confirm action: :ppmc, project: @ppmc.id, update: self.update if auth
   end
 
   # capture ppmc on initial load

-- 
To stop receiving notification emails like this one, please contact
['"commits@whimsical.apache.org" <commits@whimsical.apache.org>'].

Mime
View raw message