You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whimsical.apache.org by se...@apache.org on 2019/12/11 16:50:17 UTC

[whimsy] branch master updated: Add ICLAs search by name and email

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

sebb 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 fd1fec6  Add ICLAs search by name and email
fd1fec6 is described below

commit fd1fec6e98fc636d82ea8d991b028714ac2c9db2
Author: Sebb <se...@apache.org>
AuthorDate: Wed Dec 11 16:49:57 2019 +0000

    Add ICLAs search by name and email
---
 www/index.html                    |   1 +
 www/roster/main.rb                |  39 ++++++++++++++
 www/roster/views/app.js.rb        |   1 +
 www/roster/views/iclaSearch.js.rb | 105 ++++++++++++++++++++++++++++++++++++++
 www/roster/views/iclas.html.rb    |  21 ++++++++
 5 files changed, 167 insertions(+)

diff --git a/www/index.html b/www/index.html
index 4f1ff59..560cdc5 100644
--- a/www/index.html
+++ b/www/index.html
@@ -161,6 +161,7 @@
               <ul>
                 <li><a href="board/agenda/">Board Agenda</a></li>
                 <li><a href="officers/acreq">New Account Request</a></li>
+                <li><a href="roster/icla/">ICLAs</a></li>
                 <li><a href="officers/mlreq">Mailing List Request</a></li>
                 <li><a href="treasurer/bill-upload">Bill Upload</a></li>
                 <li><a href="board/subscriptions">PMC-chair vs board subscriptions</a></li>
diff --git a/www/roster/main.rb b/www/roster/main.rb
index 09ad883..bd38780 100755
--- a/www/roster/main.rb
+++ b/www/roster/main.rb
@@ -149,6 +149,45 @@ post '/committer/:userid/:file' do |name, file|
   _json :"actions/#{params[:file]}"
 end
 
+get '/icla/' do
+  @auth = Auth.info(env)
+  # Restrict who can see this
+  pass unless @auth[:member] or @auth[:chair]
+  _html :iclas
+end
+
+icla_index = nil
+icla_index_time = nil
+icla_index_etag = nil
+get '/icla/index.json' do
+  @auth = Auth.info(env)
+  # Restrict who can see this
+  pass unless @auth[:member] or @auth[:chair]
+  # recompute icla_index if the data is 5 minutes old or older
+  icla_index = nil if not icla_index_time or Time.now-icla_index_time >= 300
+
+  if not icla_index
+
+    # build a list of ICLA Public names, email addresses and icla files
+    tmp = []
+    ASF::ICLA.each {|icla|
+        tmp << { name: icla.name, mail: icla.email, claRef: icla.claRef} if icla.id == 'notinavail'
+    }
+    icla_index = tmp.to_json
+
+    # cache
+    icla_index_time = Time.now
+    icla_index_etag = etag = Digest::MD5.hexdigest(icla_index)
+  end
+
+  # send response
+  last_modified icla_index_time
+  etag icla_index_etag
+  content_type 'application/json', charset: 'UTF-8'
+  expires [icla_index_time+300, Time.now+60].max
+  icla_index
+end
+
 # Handle nonpmc: committees that aren't PMCs
 get '/nonpmc/' do
   @members = ASF::Member.list.keys
diff --git a/www/roster/views/app.js.rb b/www/roster/views/app.js.rb
index 796aa9b..2ce9220 100644
--- a/www/roster/views/app.js.rb
+++ b/www/roster/views/app.js.rb
@@ -40,6 +40,7 @@ require_relative 'ppmc/graduate'
 require_relative 'ppmc/new'
 
 require_relative 'committerSearch'
+require_relative 'iclaSearch'
 require_relative 'projectSearch'
 require_relative 'confirm'
 
diff --git a/www/roster/views/iclaSearch.js.rb b/www/roster/views/iclaSearch.js.rb
new file mode 100644
index 0000000..954749d
--- /dev/null
+++ b/www/roster/views/iclaSearch.js.rb
@@ -0,0 +1,105 @@
+class IclaSearch < Vue
+  def initialize
+    @list = []
+    @ready = false
+    @search = ''
+    @iclas = []
+  end
+
+  def mounted()
+    # start with (possibly stale) data from local storage when available
+    ls_iclas = localStorage.getItem('roster-iclas')
+    if ls_iclas
+      @iclas = JSON.parse(ls_iclas)
+      @ready = true
+      self.change(target: {value: @search}) unless @search.empty?
+    end
+
+    # load fresh data from the server
+    Polyfill.require(%w(Promise fetch)) do
+      fetch('icla/index.json', credentials: 'include').then {|response|
+        response.json().then do |iclas|
+          @iclas = iclas
+          @ready = true
+          self.change(target: {value: @search}) unless @search.empty?
+          localStorage.setItem('roster-iclas', @iclas.inspect)
+        end
+      }.catch {|error|
+        console.log error
+      }
+    end
+  end
+
+  def change(event)
+    @search = event.target.value
+
+    search = @search.downcase().split(' ')
+
+    list = []
+    @list = list
+    @iclas.each do |icla|
+      if 
+        search.all? {|part|
+          icla.name.downcase().include? part or
+          icla.mail.downcase().include? part
+        }
+      then
+        list << icla
+      end
+    end
+  end
+
+  def render
+    _div.form_group do
+      _label.control_label.col_sm_3 'Search for name or email', :for =>  'search-text'
+      _div.col_sm_9 do
+        _div.input_group do
+          _input.form_control autofocus: true, value: @search, 
+            onInput: self.change
+          _span.input_group_addon do
+            _span.glyphicon.glyphicon_user aria_label: "Committer ID or name"
+          end
+        end
+      end
+    end
+    
+    if @search.length
+      if not @ready
+        _p 'loading...'
+
+      else
+        search = @search.downcase().split(' ')
+        list = @list
+
+        if list.length == 0
+          _p 'none found'
+        elsif list.length > 99
+          _p "#{list.length} entries match"
+        else
+          _table.table.table_hover do
+            _thead do
+              _tr do
+                _th 'public name'
+                _th 'email'
+                _th 'ICLA'
+              end
+            end
+
+            _tbody do
+              list.each do |icla|
+                _tr do
+                  _td icla.name
+                  _td icla.mail
+                  _td { _a icla.claRef, href: "https://svn.apache.org/repos/private/documents/iclas/#{icla.claRef}" }
+                end
+              end
+
+            end
+          end
+
+        end
+      end
+    end
+  end
+
+end
diff --git a/www/roster/views/iclas.html.rb b/www/roster/views/iclas.html.rb
new file mode 100644
index 0000000..2ce1765
--- /dev/null
+++ b/www/roster/views/iclas.html.rb
@@ -0,0 +1,21 @@
+#
+# A single committer
+#
+
+_html do
+  _base href: '..'
+  _link rel: 'stylesheet', href: "stylesheets/app.css?#{cssmtime}"
+  _whimsy_body(
+    title: 'ASF ICLA Search',
+    breadcrumbs: {
+      roster: '.',
+      icla: 'icla/'
+    }
+  ) do
+    _div_.main!
+    _script src: "app.js?#{appmtime}"
+    _.render '#main' do
+      _IclaSearch
+    end
+  end
+end