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: rough in UI for additional ICLAs
Date Fri, 19 May 2017 14:58:42 GMT
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  c0acdb9   rough in UI for additional ICLAs
c0acdb9 is described below

commit c0acdb98afcb9651cb1da7e6474c81d85192d299
Author: Sam Ruby <rubys@intertwingly.net>
AuthorDate: Fri May 19 09:54:42 2017 -0400

    rough in UI for additional ICLAs
---
 www/secretary/workbench/public/secmail.css      |  15 ++
 www/secretary/workbench/server.rb               |  15 ++
 www/secretary/workbench/views/app.js.rb         |   1 +
 www/secretary/workbench/views/forms/icla2.js.rb | 181 ++++++++++++++++++++++++
 www/secretary/workbench/views/parts.js.rb       |   6 +
 5 files changed, 218 insertions(+)

diff --git a/www/secretary/workbench/public/secmail.css b/www/secretary/workbench/public/secmail.css
index a8ab8c2..93420a1 100644
--- a/www/secretary/workbench/public/secmail.css
+++ b/www/secretary/workbench/public/secmail.css
@@ -180,3 +180,18 @@ pre.bg-info {
 #parts table {
   margin-top: 14px; 
 }
+
+ul.icla-search {
+  padding: 0;
+  margin-left: 1em;
+}
+
+ul.icla-search li {
+  list-style: none;
+  padding: 0;
+  margin: 0;
+}
+
+ul.icla-search input[type=radio] {
+  margin-right: 10px;
+}
diff --git a/www/secretary/workbench/server.rb b/www/secretary/workbench/server.rb
index 2775a64..d62645a 100644
--- a/www/secretary/workbench/server.rb
+++ b/www/secretary/workbench/server.rb
@@ -179,6 +179,21 @@ get '/email.json' do
   end
 end
 
+# return a list of iclas
+get '/iclas.json' do
+  list = []
+  ASF::ICLA.each do |icla|
+    list << {
+      filename: icla.claRef,
+      id: icla.id,
+      name: icla.name,
+      fullname: icla.legal_name,
+      email: icla.email
+    }
+  end
+  list.to_json
+end
+
 # event stream for server sent events (a.k.a EventSource)
 get '/events', provides: 'text/event-stream' do
   events = Events.new
diff --git a/www/secretary/workbench/views/app.js.rb b/www/secretary/workbench/views/app.js.rb
index fb695d6..d4c789d 100644
--- a/www/secretary/workbench/views/app.js.rb
+++ b/www/secretary/workbench/views/app.js.rb
@@ -7,6 +7,7 @@ require_relative 'parts'
 require_relative 'check-signature'
 
 require_relative 'forms/icla'
+require_relative 'forms/icla2'
 require_relative 'forms/grant'
 require_relative 'forms/ccla'
 require_relative 'forms/nda'
diff --git a/www/secretary/workbench/views/forms/icla2.js.rb b/www/secretary/workbench/views/forms/icla2.js.rb
new file mode 100644
index 0000000..892d272
--- /dev/null
+++ b/www/secretary/workbench/views/forms/icla2.js.rb
@@ -0,0 +1,181 @@
+class ICLA2 < React
+  def initialize
+    @filed = false
+    @checked = nil
+    @submitted = false
+    @search = ''
+  end
+
+  def render
+    _h4 'Additional ICLA'
+
+    _form.form do
+      _h5 'Search'
+      _table.form do
+        _tr do
+          _input value: @search
+        end
+      end
+    end
+
+    if @search.length >= 3
+      search = @search.downcase().split(' ')
+      _ul.icla_search do
+        ICLA2.iclas.each do |icla|
+          if
+            search.all? {|part|
+              icla.id.include? part or
+              icla.name.downcase().include? part or
+              icla.fullname.downcase().include? part
+            }
+          then
+            _li do
+              _input type: 'radio', name: 'icla',
+                onClick: -> {@icla = icla} 
+              _a icla.name, href: "../../icla/#{icla.filename}",
+                target: 'content'
+           end
+          end
+        end
+      end
+    end
+
+    _form method: 'post', action: '../../tasklist/icla2', target: 'content' do
+      _input type: 'hidden', name: 'message'
+      _input type: 'hidden', name: 'selected'
+      _input type: 'hidden', name: 'signature', value: @@signature
+
+      _h5 'Current values'
+
+      _table.form do
+        _tr do
+          _th 'Full Name'
+          _td @icla && @icla.fullname
+        end
+
+        _tr do
+          _th 'Public Name'
+          _td @icla && @icla.name
+        end
+
+        _tr do
+          _th 'E-mail'
+          _td @icla && @icla.email
+        end
+
+        _tr do
+          _th 'File Name'
+          _td @icla && @icla.filename
+        end
+      end
+
+      _h5 'Updated values'
+      _table.form do
+        _tr do
+          _th 'Public Name'
+          _td do
+            _input name: 'pubname', value: @pubname, required: true,
+              disabled: @filed, onFocus: -> {@pubname ||= @realname}
+          end
+        end
+
+        _tr do
+          _th 'E-mail'
+          _td do
+            _input name: 'email', value: @email, required: true, type: 'email',
+              disabled: @filed
+          end
+        end
+      end
+
+      _input.btn.btn_primary value: 'File', type: 'submit', ref: 'file',
+        disabled: true
+    end
+  end
+
+  # on initial display, default various fields based on headers, and update
+  # state 
+  def componentDidMount()
+    if ICLA2.iclas
+      @disabled = false
+    else
+      @disabled = true
+      # construct arguments to fetch
+      args = {
+        method: 'get',
+        credentials: 'include',
+        headers: {'Content-Type' => 'application/json'}
+      }
+      fetch('../../iclas.json', args).then do |response|
+        response.json().then do |json|
+          ICLA2.iclas = json
+          @disabled = true
+        end
+      end
+    end
+
+    name = @@headers.name || ''
+
+    # reorder name if there is a single comma present
+    parts = name.split(',')
+    if parts.length == 2 and parts[1] !~ /^\s*(jr|ph\.d)\.?$/i
+      name = "#{parts[1].strip()} #{parts[0]}" 
+    end
+
+    @realname = name
+    @pubname = name
+    @search = name
+    @email = @@headers.from
+    self.componentDidUpdate()
+
+    # watch for status updates
+    window.addEventListener 'message', self.status_update
+  end
+
+  def componentWillUnmount()
+    window.removeEventListener 'message', self.status_update
+  end
+
+  # as fields change, enable/disable the associated buttons and adjust
+  # input requirements.
+  def componentDidUpdate()
+    # ICLA file form
+    valid = %w(pubname email).all? do |name|
+      document.querySelector("input[name=#{name}]").validity.valid
+    end
+
+    # $file.disabled = !valid or @filed or @submitted
+
+    # wire up form
+    jQuery('form')[0].addEventListener('submit', self.file)
+    jQuery('input[name=message]').val(window.parent.location.pathname)
+    jQuery('input[name=selected]').val(@@selected)
+
+    # Safari autocomplete workaround: trigger change on leaving field
+    # https://github.com/facebook/react/issues/2125
+    if navigator.userAgent.include? "Safari"
+      Array(document.getElementsByTagName('input')).each do |input|
+        input.addEventListener('blur', self.onblur)
+      end
+    end
+  end
+
+  # when leaving an input field, trigger change event (for Safari)
+  def onblur(event)
+    jQuery(event.target).trigger(:change)
+  end
+
+  # handle ICLA form submission
+  def file(event)
+    setTimeout 0 do
+      @submitted = true
+      @filed = true
+    end
+  end
+
+  # when tasks complete (or are aborted) reset form
+  def status_update(event)
+    @submitted = false
+    @filed = false
+  end
+end
diff --git a/www/secretary/workbench/views/parts.js.rb b/www/secretary/workbench/views/parts.js.rb
index 97038cb..ed219d0 100644
--- a/www/secretary/workbench/views/parts.js.rb
+++ b/www/secretary/workbench/views/parts.js.rb
@@ -102,6 +102,12 @@ class Parts < React
           end
 
           _label do
+            _input type: 'radio', name: 'doctype', value: 'icla2',
+              onClick: -> {@form = ICLA2}
+            _span 'additional icla'
+          end
+
+          _label do
             _input type: 'radio', name: 'doctype', value: 'ccla',
               onClick: -> {@form = CCLA}
             _span 'ccla'

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

Mime
View raw message