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/09/08 02:04:29 UTC
[whimsy] 01/02: refactor using mixins
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
commit bc3479f328f3d86de41caded89076660663e1351
Author: Sam Ruby <ru...@intertwingly.net>
AuthorDate: Thu Sep 7 20:57:06 2017 -0400
refactor using mixins
---
www/roster/views/app.js.rb | 3 +
www/roster/views/mixins/add.js.rb | 60 ++++++++++++++++++
www/roster/views/mixins/mod.js.rb | 65 ++++++++++++++++++++
www/roster/views/pmc/add.js.rb | 102 ++++++++----------------------
www/roster/views/pmc/main.js.rb | 4 +-
www/roster/views/pmc/mod.js.rb | 111 ++++++++-------------------------
www/roster/views/ppmc/add.js.rb | 103 ++++++++-----------------------
www/roster/views/ppmc/main.js.rb | 4 +-
www/roster/views/ppmc/mod.js.rb | 126 +++++++++++---------------------------
9 files changed, 245 insertions(+), 333 deletions(-)
diff --git a/www/roster/views/app.js.rb b/www/roster/views/app.js.rb
index 0ec24a8..dd9a79f 100644
--- a/www/roster/views/app.js.rb
+++ b/www/roster/views/app.js.rb
@@ -1,6 +1,9 @@
require_relative 'vue-config'
require_relative 'polyfill'
+require_relative 'mixins/add'
+require_relative 'mixins/mod'
+
require_relative 'pmc/main'
require_relative 'pmc/pmc'
require_relative 'pmc/committers'
diff --git a/www/roster/views/mixins/add.js.rb b/www/roster/views/mixins/add.js.rb
new file mode 100644
index 0000000..50c4ae0
--- /dev/null
+++ b/www/roster/views/mixins/add.js.rb
@@ -0,0 +1,60 @@
+#
+# Add People to a PMC or podling
+#
+
+class ProjectAdd < Vue::Mixin
+ def mounted()
+ jQuery("##{$options.add_tag}").on('show.bs.modal') do |event|
+ button = event.relatedTarget
+ setTimeout(500) { jQuery("##{$options.add_tag} input").focus() }
+ end
+ end
+
+ def add(person)
+ @people << person
+ Vue.forceUpdate()
+ jQuery("##{$options.add_tag} input").focus()
+ 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: @@project.id,
+ ids: @people.map {|person| person.id}.join(','),
+ action: action,
+ targets: targets
+ }.inspect
+ }
+
+ @disabled = true
+ Polyfill.require(%w(Promise fetch)) do
+ fetch($options.add_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|
+ Vue.emit :update, json
+ end
+ else
+ alert "#{response.status} #{response.statusText}"
+ end
+
+ jQuery("##{$options.add_tag}").modal(:hide)
+ @disabled = false
+ }.catch {|error|
+ alert error
+ jQuery("##{$options.add_tag}").modal(:hide)
+ @disabled = false
+ }
+ end
+ end
+end
diff --git a/www/roster/views/mixins/mod.js.rb b/www/roster/views/mixins/mod.js.rb
new file mode 100644
index 0000000..9a2992f
--- /dev/null
+++ b/www/roster/views/mixins/mod.js.rb
@@ -0,0 +1,65 @@
+#
+# Modify People's role in a project
+#
+
+class ProjectMod < Vue::Mixin
+ def mounted()
+ jQuery("##{$options.mod_tag}").on('show.bs.modal') do |event|
+ button = event.relatedTarget
+ setTimeout(500) { jQuery("##{$options.mod_tag} input").focus() }
+
+ selected = []
+ roster = @@project.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: @@project.id,
+ ids: @people.map {|person| person.id}.join(','),
+ action: action,
+ targets: targets
+ }.inspect
+ }
+
+ @disabled = true
+ Polyfill.require(%w(Promise fetch)) do
+ fetch($options.add_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|
+ Vue.emit :update, json
+ end
+ else
+ alert "#{response.status} #{response.statusText}"
+ end
+
+ jQuery("##{$options.mod_tag}").modal(:hide)
+ @disabled = false
+ }.catch {|error|
+ alert error
+ jQuery("##{$options.mod_tag}").modal(:hide)
+ @disabled = false
+ }
+ end
+ end
+end
diff --git a/www/roster/views/pmc/add.js.rb b/www/roster/views/pmc/add.js.rb
index 0b77efa..c0f4cef 100644
--- a/www/roster/views/pmc/add.js.rb
+++ b/www/roster/views/pmc/add.js.rb
@@ -1,49 +1,52 @@
#
-# Add People to a project
+# Add People to a PMC
#
class PMCAdd < Vue
+ mixin ProjectAdd
+ options add_tag: "pmcadd", add_action: 'actions/committee'
+
def initialize
@people = []
end
def render
- _div.modal.fade.pmcadd! tabindex: -1 do
+ _div.modal.fade id: $options.add_tag, 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 'Add People to the ' + @@committee.display_name +
- ' Project'
+ _h4.modal_title 'Add People to the ' + @@project.display_name +
+ ' Project'
end
_div.modal_body do
_div.container_fluid do
- unless @people.empty?
+ unless @people.empty?
_table.table do
_thead do
_tr do
- _th 'id'
- _th 'name'
- _th 'email'
- end
+ _th 'id'
+ _th 'name'
+ _th 'email'
+ end
end
_tbody do
@people.each do |person|
- _tr do
- _td person.id
- _td person.name
- _td person.mail[0]
- end
- end
+ _tr do
+ _td person.id
+ _td person.name
+ _td person.mail[0]
+ end
+ end
end
end
- end
+ end
_CommitterSearch add: self.add,
- exclude: @@committee.roster.keys().
- concat(@people.map {|person| person.id})
+ exclude: @@project.roster.keys().
+ concat(@people.map {|person| person.id})
end
end
@@ -53,72 +56,17 @@ class PMCAdd < Vue
_button.btn.btn_default 'Cancel', data_dismiss: 'modal',
disabled: @disabled
- plural = (@people.length > 1 ? 's' : '')
+ plural = (@people.length > 1 ? 's' : '')
_button.btn.btn_primary "Add as committer#{plural}",
- data_action: 'add commit',
- onClick: self.post, disabled: (@people.empty?)
+ data_action: 'add commit',
+ onClick: self.post, disabled: (@people.empty?)
_button.btn.btn_primary 'Add to PMC', onClick: self.post,
- data_action: 'add pmc info commit', disabled: (@people.empty?)
+ data_action: 'add pmc info commit', disabled: (@people.empty?)
end
end
end
end
end
-
- def mounted()
- jQuery('#pmcadd').on('show.bs.modal') do |event|
- button = event.relatedTarget
- setTimeout(500) { jQuery('#pmcadd input').focus() }
- end
- end
-
- def add(person)
- @people << person
- Vue.forceUpdate()
- jQuery('#pmcadd input').focus()
- 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}.join(','),
- 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|
- Vue.emit :update, json
- end
- else
- alert "#{response.status} #{response.statusText}"
- end
-
- jQuery('#pmcadd').modal(:hide)
- @disabled = false
- }.catch {|error|
- alert error
- jQuery('#pmcadd').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 4024136..ce8c271 100644
--- a/www/roster/views/pmc/main.js.rb
+++ b/www/roster/views/pmc/main.js.rb
@@ -189,8 +189,8 @@ class PMC < Vue
# hidden forms
if auth
_Confirm action: :committee, project: @committee.id, update: self.update
- _PMCAdd committee: @@committee, onUpdate: self.update
- _PMCMod committee: @@committee, onUpdate: self.update
+ _PMCAdd project: @@committee, onUpdate: self.update
+ _PMCMod project: @@committee, onUpdate: self.update
end
end
diff --git a/www/roster/views/pmc/mod.js.rb b/www/roster/views/pmc/mod.js.rb
index e6152df..f28b4ae 100644
--- a/www/roster/views/pmc/mod.js.rb
+++ b/www/roster/views/pmc/mod.js.rb
@@ -1,8 +1,11 @@
#
-# Add People to a project
+# Modify People's role in a project
#
class PMCMod < Vue
+ mixin ProjectMod
+ options mod_tag: "pmcmod", mod_action: 'actions/committee'
+
def initialize
@people = []
end
@@ -14,27 +17,27 @@ class PMCMod < Vue
_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'
+ @@project.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
+ _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
@@ -45,86 +48,26 @@ class PMCMod < Vue
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}
+ if @people.all? {|person| !@@project.members.include? person.id}
_button.btn.btn_primary "Add to PMC",
- data_action: 'add pmc info',
- onClick: self.post, disabled: (@people.empty?)
+ 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}
+ if @people.any? {|person| @@project.members.include? person.id}
remove_from << 'info'
end
- if @people.any? {|person| @@committee.ldap.include? person.id}
+ if @people.any? {|person| @@project.ldap.include? person.id}
remove_from << 'pmc'
end
_button.btn.btn_primary 'Remove from project', onClick: self.post,
- data_action: "remove #{remove_from.join(' ')}"
+ data_action: "remove #{remove_from.join(' ')}"
end
end
end
end
end
-
- def mounted()
- 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}.join(','),
- 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|
- Vue.emit :update, 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/ppmc/add.js.rb b/www/roster/views/ppmc/add.js.rb
index d65cd26..6f2eb9c 100644
--- a/www/roster/views/ppmc/add.js.rb
+++ b/www/roster/views/ppmc/add.js.rb
@@ -1,49 +1,52 @@
#
-# Add People to a project
+# Add People to a PPMC
#
class PPMCAdd < Vue
+ mixin ProjectAdd
+ options add_tag: "ppmcadd", add_action: 'actions/ppmc'
+
def initialize
@people = []
end
def render
- _div.modal.fade.ppmcadd! tabindex: -1 do
+ _div.modal.fade id: $options.add_tag, 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 'Add People to the ' + @@ppmc.display_name +
- ' Podling'
+ _h4.modal_title 'Add People to the ' + @@project.display_name +
+ ' Podling'
end
_div.modal_body do
_div.container_fluid do
- unless @people.empty?
+ unless @people.empty?
_table.table do
_thead do
_tr do
- _th 'id'
- _th 'name'
- _th 'email'
- end
+ _th 'id'
+ _th 'name'
+ _th 'email'
+ end
end
_tbody do
@people.each do |person|
- _tr do
- _td person.id
- _td person.name
- _td person.mail[0]
- end
- end
+ _tr do
+ _td person.id
+ _td person.name
+ _td person.mail[0]
+ end
+ end
end
end
- end
+ end
_CommitterSearch add: self.add,
- exclude: @@ppmc.roster.keys().
- concat(@people.map {|person| person.id})
+ exclude: @@project.roster.keys().
+ concat(@people.map {|person| person.id})
end
end
@@ -53,15 +56,15 @@ class PPMCAdd < Vue
_button.btn.btn_default 'Cancel', data_dismiss: 'modal',
disabled: @disabled
- plural = (@people.length > 1 ? 's' : '')
+ plural = (@people.length > 1 ? 's' : '')
if @@auth.ppmc
_button.btn.btn_primary "Add as committer#{plural}",
- data_action: 'add committer',
- onClick: self.post, disabled: (@people.empty?)
+ data_action: 'add committer',
+ onClick: self.post, disabled: (@people.empty?)
_button.btn.btn_primary 'Add to PPMC', onClick: self.post,
- data_action: 'add ppmc committer', disabled: (@people.empty?)
+ data_action: 'add ppmc committer', disabled: (@people.empty?)
end
if @@auth.ipmc
@@ -69,7 +72,7 @@ class PPMCAdd < Vue
action += ' ppmc committer' if @@auth.ppmc
_button.btn.btn_primary "Add as mentor#{plural}",
- data_action: action, onClick: self.post,
+ data_action: action, onClick: self.post,
disabled: (@people.empty?)
end
end
@@ -77,58 +80,4 @@ class PPMCAdd < Vue
end
end
end
-
- def mounted()
- jQuery('#ppmcadd').on('show.bs.modal') do |event|
- button = event.relatedTarget
- setTimeout(500) { jQuery('#ppmcadd input').focus() }
- end
- end
-
- def add(person)
- @people << person
- self.forceUpdate()
- jQuery('#ppmcadd input').focus()
- 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: @@ppmc.id,
- ids: @people.map {|person| person.id}.join(','),
- action: action,
- targets: targets
- }.inspect
- }
-
- @disabled = true
- Polyfill.require(%w(Promise fetch)) do
- fetch("actions/ppmc", 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('#ppmcadd').modal(:hide)
- @disabled = false
- }.catch {|error|
- alert error
- jQuery('#ppmcadd').modal(:hide)
- @disabled = false
- }
- end
- end
end
diff --git a/www/roster/views/ppmc/main.js.rb b/www/roster/views/ppmc/main.js.rb
index ce1a37e..4cdc4a9 100644
--- a/www/roster/views/ppmc/main.js.rb
+++ b/www/roster/views/ppmc/main.js.rb
@@ -201,8 +201,8 @@ class PPMC < Vue
# hidden forms
if @@auth.ppmc or @@auth.ipmc
_Confirm action: :ppmc, project: @ppmc.id, update: self.update
- _PPMCAdd ppmc: @ppmc, update: self.update, auth: @@auth
- _PPMCMod ppmc: @ppmc, update: self.update, auth: @@auth
+ _PPMCAdd project: @ppmc, onUpdate: self.update, auth: @@auth
+ _PPMCMod project: @ppmc, onUpdate: self.update, auth: @@auth
end
end
diff --git a/www/roster/views/ppmc/mod.js.rb b/www/roster/views/ppmc/mod.js.rb
index eb42ac3..219ff46 100644
--- a/www/roster/views/ppmc/mod.js.rb
+++ b/www/roster/views/ppmc/mod.js.rb
@@ -1,40 +1,43 @@
#
-# Add People to a project
+# Modify People's role in a podling
#
class PPMCMod < Vue
+ mixin ProjectMod
+ options mod_tag: "ppmcmod", mod_action: 'actions/ppmc'
+
def initialize
@people = []
end
def render
- _div.modal.fade.ppmcmod! tabindex: -1 do
+ _div.modal.fade id: $options.mod_tag, 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 " +
- @@ppmc.display_name + ' Podling'
+ @@project.display_name + ' Podling'
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
+ _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
@@ -45,103 +48,44 @@ class PPMCMod < Vue
disabled: @disabled
if @@auth.ppmc
- # show add to PPMC button only if every person is not on the PPMC
- if @people.all? {|person| !@@ppmc.owners.include? person.id}
- _button.btn.btn_primary "Add to PPMC",
- data_action: 'add ppmc',
- onClick: self.post, disabled: (@people.empty?)
- end
+ # show add to PPMC button only if every person is not on the PPMC
+ if @people.all? {|person| !@@project.owners.include? person.id}
+ _button.btn.btn_primary "Add to PPMC",
+ data_action: 'add ppmc',
+ onClick: self.post, disabled: (@people.empty?)
+ end
end
# show add as mentor button only if every person is not a mentor
if @@auth.ipmc
- if @people.all? {|person| !@@ppmc.mentors.include? person.id}
+ if @people.all? {|person| !@@project.mentors.include? person.id}
plural = (@people.length > 1 ? 's' : '')
action = 'add mentor'
- if @people.any? {|person| !@@ppmc.owners.include? person.id}
- action += ' ppmc'
+ if @people.any? {|person| !@@project.owners.include? person.id}
+ action += ' ppmc'
end
_button.btn.btn_primary "Add as Mentor#{plural}",
- data_action: action, onClick: self.post,
+ data_action: action, onClick: self.post,
disabled: (@people.empty?)
end
end
# remove from all relevant locations
remove_from = ['committer']
- if @people.any? {|person| @@ppmc.owners.include? person.id}
+ if @people.any? {|person| @@project.owners.include? person.id}
remove_from << 'ppmc'
end
- if @people.any? {|person| @@ppmc.mentors.include? person.id}
+ if @people.any? {|person| @@project.mentors.include? person.id}
remove_from << 'mentor'
end
_button.btn.btn_primary 'Remove from project', onClick: self.post,
- data_action: "remove #{remove_from.join(' ')}"
+ data_action: "remove #{remove_from.join(' ')}"
end
end
end
end
end
-
- def mounted()
- jQuery('#ppmcmod').on('show.bs.modal') do |event|
- button = event.relatedTarget
- setTimeout(500) { jQuery('#ppmcmod input').focus() }
-
- selected = []
- roster = @@ppmc.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: @@ppmc.id,
- ids: @people.map {|person| person.id}.join(','),
- action: action,
- targets: targets
- }.inspect
- }
-
- @disabled = true
- Polyfill.require(%w(Promise fetch)) do
- fetch("actions/ppmc", 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('#ppmcmod').modal(:hide)
- @disabled = false
- }.catch {|error|
- alert error
- jQuery('#ppmcmod').modal(:hide)
- @disabled = false
- }
- end
- end
end
--
To stop receiving notification emails like this one, please contact
"commits@whimsical.apache.org" <co...@whimsical.apache.org>.