You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whimsical.apache.org by ru...@apache.org on 2017/07/15 15:02:41 UTC

[whimsy] branch master updated: initial cut at a new mod dialog

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 da9bd79  initial cut at a new mod dialog
da9bd79 is described below

commit da9bd7931a0925f461c53ad2187ee376fb502676
Author: Sam Ruby <ru...@intertwingly.net>
AuthorDate: Sat Jul 15 11:02:30 2017 -0400

    initial cut at a new mod dialog
---
 www/roster/views/app.js.rb        |   1 +
 www/roster/views/pmc/main.js.rb   |  25 +++++++-
 www/roster/views/pmc/mod.js.rb    | 129 ++++++++++++++++++++++++++++++++++++++
 www/roster/views/pmc/roster.js.rb |   2 +-
 4 files changed, 154 insertions(+), 3 deletions(-)

diff --git a/www/roster/views/app.js.rb b/www/roster/views/app.js.rb
index 72f26f0..99636a9 100644
--- a/www/roster/views/app.js.rb
+++ b/www/roster/views/app.js.rb
@@ -5,6 +5,7 @@ require_relative 'pmc/pmc'
 require_relative 'pmc/committers'
 require_relative 'pmc/roster'
 require_relative 'pmc/add'
+require_relative 'pmc/mod'
 
 require_relative 'person'
 require_relative 'person/fullname'
diff --git a/www/roster/views/pmc/main.js.rb b/www/roster/views/pmc/main.js.rb
index 1904091..31995f1 100644
--- a/www/roster/views/pmc/main.js.rb
+++ b/www/roster/views/pmc/main.js.rb
@@ -69,8 +69,18 @@ class PMC < React
       _div.col_sm_6 do
         if auth
           _button.btn.btn_default 'Add',
-              data_target: '#pmcadd', data_toggle: 'modal'
-          _button.btn.btn_default 'Modify', disabled: true
+            data_target: '#pmcadd', data_toggle: 'modal'
+
+          mod_disabled = true
+          for id in @committee.roster
+            if @committee.roster[id].selected
+              mod_disabled = false
+              break
+            end
+          end
+
+          _button.btn.btn_default 'Modify', disabled: mod_disabled,
+            data_target: '#pmcmod', data_toggle: 'modal'
         end
       end
       _div.col_sm_6 do
@@ -183,6 +193,7 @@ class PMC < React
     if auth
       _Confirm action: :committee, project: @committee.id, update: self.update
       _PMCAdd committee: @@committee, update: self.update
+      _PMCMod committee: @@committee, update: self.update
     end
   end
 
@@ -196,6 +207,16 @@ class PMC < React
     self.update(@@committee)
   end
 
+  # refresh the current page
+  def refresh()
+    self.forceUpdate()
+  end
+
+  def componentDidMount()
+    # export refesh method
+    PMC.refresh = self.refresh
+  end
+
   # update committee from conformation form
   def update(committee)
     @committee = committee
diff --git a/www/roster/views/pmc/mod.js.rb b/www/roster/views/pmc/mod.js.rb
new file mode 100644
index 0000000..e427a1f
--- /dev/null
+++ b/www/roster/views/pmc/mod.js.rb
@@ -0,0 +1,129 @@
+#
+# Add People to a project
+#
+
+class PMCMod < React
+  def initialize
+    @people = []
+  end
+
+  def render
+    _div.modal.fade.pmcmod! 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 "Modify People's Roles in the " + 
+              @@committee.display_name + ' Project'
+          end
+
+          _div.modal_body do
+            _div.container_fluid do
+	      _table.table do
+		_thead do
+		  _tr do
+		    _th 'id'
+		    _th 'name'
+		  end
+		end
+		_tbody do
+		  @people.each do |person|
+		    _tr do
+		      _td person.id
+		      _td person.name
+		    end
+		  end
+		end
+	      end
+            end
+          end
+
+          _div.modal_footer do
+            _span.status 'Processing request...' if @disabled
+
+            _button.btn.btn_default 'Cancel', data_dismiss: 'modal',
+              disabled: @disabled
+
+            # show add to PMC button only if every person is not on the PMC
+            if @people.all? {|person| !@@committee.members.include? person.id}
+              _button.btn.btn_primary "Add to PMC", 
+	        data_action: 'add pmc info',
+	        onClick: self.post, disabled: (@people.empty?)
+            end
+
+            # remove from all relevant locations
+            remove_from = ['commit']
+            if @people.any? {|person| @@committee.members.include? person.id}
+              remove_from << 'info'
+            end
+            if @people.any? {|person| @@committee.ldap.include? person.id}
+              remove_from << 'pmc'
+            end
+
+            _button.btn.btn_primary 'Remove from project', onClick: self.post,
+	      data_action: "remove #{remove_from.join(' ')}"
+          end
+        end
+      end
+    end
+  end
+
+  def componentDidMount()
+    jQuery('#pmcmod').on('show.bs.modal') do |event|
+      button = event.relatedTarget
+      setTimeout(500) { jQuery('#pmcmod input').focus() }
+
+      selected = []
+      roster = @@committee.roster
+      for id in roster
+        if roster[id].selected
+          roster[id].id = id
+          selected << roster[id]
+        end
+      end
+
+      @people = selected
+    end
+  end
+
+  def post(event)
+    button = event.currentTarget
+
+    # parse action extracted from the button
+    targets = button.dataset.action.split(' ')
+    action = targets.shift()
+
+    # construct arguments to fetch
+    args = {
+      method: 'post',
+      credentials: 'include',
+      headers: {'Content-Type' => 'application/json'},
+      body: {
+        project: @@committee.id, 
+        ids: @people.map {|person| person.id}, 
+        action: action, 
+        targets: targets
+      }.inspect
+    }
+
+    @disabled = true
+    Polyfill.require(%w(Promise fetch)) do
+      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|
+            @@update.call(json)
+          end
+        else
+          alert "#{response.status} #{response.statusText}"
+        end
+        jQuery('#pmcmod').modal(:hide)
+        @disabled = false
+      }.catch {|error|
+        alert error
+        jQuery('#pmcmod').modal(:hide)
+        @disabled = false
+      }
+    end
+  end
+end
diff --git a/www/roster/views/pmc/roster.js.rb b/www/roster/views/pmc/roster.js.rb
index 7291e09..60487ef 100644
--- a/www/roster/views/pmc/roster.js.rb
+++ b/www/roster/views/pmc/roster.js.rb
@@ -63,6 +63,6 @@ class PMCRoster < React
 
   def toggleSelect(person)
     person.selected = !person.selected
-    self.forceUpdate()
+    PMC.refresh()
   end
 end

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