This is an automated email from the ASF dual-hosted git repository.
clr 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 fd861f1 Add error handling for discuss and vote pages
fd861f1 is described below
commit fd861f13ee85746ea7dcb67a4b7a338a7b63f238
Author: Craig L Russell <[email protected]>
AuthorDate: Wed Jan 24 17:59:24 2018 -0800
Add error handling for discuss and vote pages
---
www/project/icla/main.rb | 89 ++++++++-------
www/project/icla/views/app.html.rb | 5 +-
www/project/icla/views/pages/discuss.js.rb | 120 ++++++++++++---------
www/project/icla/views/pages/vote.js.rb | 167 ++++++++++++++++-------------
4 files changed, 206 insertions(+), 175 deletions(-)
diff --git a/www/project/icla/main.rb b/www/project/icla/main.rb
index 8236625..c51f400 100755
--- a/www/project/icla/main.rb
+++ b/www/project/icla/main.rb
@@ -9,6 +9,7 @@ require 'wunderbar/vue'
require 'wunderbar/bootstrap/theme'
require 'ruby2js/filter/functions'
require 'ruby2js/filter/require'
+require 'json'
disable :logging # suppress log of requests to stderr/error.log
@@ -34,15 +35,45 @@ helpers do
'pmcmail' => mailList
}
end
+ def loadProgress(token)
+ if @token
+ # read the file corresponging to the token
+ # the file name is '/srv/<token>.json
+ @filename = '/srv/icla/' + token + '.json'
+ begin
+ @progress = JSON.parse(File.read(@filename))
+ rescue SystemCallError => e
+ @progress = {
+ phase: 'error', errorMessage: e.message, errorCode: e.errno
+ }
+ rescue JSON::ParserError => e
+ @progress = {
+ phase: 'error', errorMessage: e.message, errorCode: 999
+ }
+ end
+ end
+ end
end
+@phase = ''
+@progress = ''
+
#
# Sinatra routes
#
get '/' do
- redirect to('/invite')
+ @token = params['token']
+ @progress = loadProgress(@token) if @token
+ @phase = @progress[:phase] if @progress
+ if @phase == 'discuss'
+ redirect to("/discuss?token=" + @token)
+ elsif @phase == 'vote'
+ redirect to("/vote?token=" + @token)
+ else
+ redirect to("/invite")
+ end
end
get '/invite' do
@@ -65,74 +96,40 @@ end
get '/discuss' do
@view = 'discuss'
- @user = env.user
-
- # get a complete list of PMC and PPMC names and mail lists
- projects = projectsForUser(env.user)
# server data sent to client
- @token = params['token']
@debug = params['debug']
+ @user = env.user
+ @token = params['token']
+ @progress = loadProgress(@token) if @token
# not needed for this form but required for other forms
@pmcs = []
@ppmcs = []
@pmc_mail = {}
- # mocked for testing
- @proposer = 'shane'
- @contributor = {
- project: 'whimsy',
- name: 'Joe Blow',
- email: '[email protected]'
- }
- @subject = '[DISCUSS] Invite Joe Blow to become committer '\
- 'and PMC member for whimsy'
- comment1 = {member: 'sebb', timestamp: '11/30/2017 15:30:00',
- comment: "Seems like a good enough guy"}
- comment2 = {member: 'rubys', timestamp: '12/04/2017 17:20:00',
- comment: "I agree"}
- comment3 = {member: 'clr', timestamp: '12/06/2017 10:14:00',
- comment: "We could do better\nMuch better"}
- @comments = [comment1, comment2, comment3]
+ @cssmtime = File.mtime('public/css/icla.css').to_i
+ @appmtime =
Wunderbar::Asset.convert("#{settings.views}/app.js.rb").mtime.to_i
_html :app
end
get '/vote' do
@view = 'vote'
- @user = env.user
- # server data sent to client
- @token = params['token']
+# server data sent to client
@debug = params['debug']
+ @user = env.user
+ @token = params['token']
+ @progress = loadProgress(@token) if @token
# not needed for this form but required for other forms
@pmcs = []
@ppmcs = []
@pmc_mail = {}
- # mocked for testing
- @proposer = 'shane'
- @contributor = {
- project: 'whimsy',
- name: 'Joe Blow',
- email: '[email protected]'
- }
- @subject = '[VOTE] Invite Joe Blow to become committer '\
- 'and PMC member for whimsy'
- comment1 = {member: 'sebb', timestamp: '11/30/2017 15:30:00',
- comment: "Seems like a good enough guy"}
- comment2 = {member: 'rubys', timestamp: '12/04/2017 17:20:00',
- comment: "I agree"}
- comment3 = {member: 'clr', timestamp: '12/06/2017 10:14:00',
- comment: "We could do better\nMuch better"}
- @comments = [comment1, comment2, comment3]
-
- vote1 = {vote: '+1', member: 'sebb', timestamp: '12/19/2017 15:30:00'}
- vote2 = {vote: '+1', member: 'clr', timestamp: '12/20/2017 14:20:00'}
- vote3 = {vote: '+1', member: 'rubys', timestamp: '12/22/2017 10:33:00'}
- @votes = [vote1, vote2, vote3]
+ @cssmtime = File.mtime('public/css/icla.css').to_i
+ @appmtime =
Wunderbar::Asset.convert("#{settings.views}/app.js.rb").mtime.to_i
_html :app
end
diff --git a/www/project/icla/views/app.html.rb
b/www/project/icla/views/app.html.rb
index b1aaace..01bb6ce 100755
--- a/www/project/icla/views/app.html.rb
+++ b/www/project/icla/views/app.html.rb
@@ -374,9 +374,8 @@ _html lang: 'en', _width: '80' do
_.render '#main' do
_Main data: {pmcs: @pmcs, ppmcs: @ppmcs, pmc_mail: @pmc_mail,
- token: @token, contributor: @contributor, comments: @comments,
- user: @user, subject: @subject, phase: @phase, votes: @votes,
- proposer: @proposer, debug: @debug},
+ token: @token, progress: @progress, user: @user,
+ debug: @debug},
view: @view
end
end
diff --git a/www/project/icla/views/pages/discuss.js.rb
b/www/project/icla/views/pages/discuss.js.rb
index 4c5ca10..85a7625 100644
--- a/www/project/icla/views/pages/discuss.js.rb
+++ b/www/project/icla/views/pages/discuss.js.rb
@@ -5,15 +5,29 @@ class Discuss < Vue
# initialize form fields
@user = Server.data.user
- @proposer = Server.data.proposer
- @pmc = Server.data.contributor[:project]
- @iclaname = Server.data.contributor[:name]
- @iclaemail = Server.data.contributor[:email]
+ console.log('discuss')
+ console.log('token: ' + Server.data.token)
+ console.log('user: ' + @user)
+ @progress = Server.data.progress
+ console.log('progress: ' + @progress.inspect)
+ @phase = @progress[:phase]
+ console.log('phase: ' + @phase)
+ if @phase == 'error'
+ @alert = @progress[:errorMessage]
+ elsif @phase != 'discuss'
+ @alert = "Wrong phase: " + @phase + "; should be discuss"
+ else
+ @pmc = @progress[:project]
+ @proposer = @progress[:proposer]
+ @contributor = @progress[:contributor]
+ @iclaname = @contributor[:name]
+ @iclaemail = @contributor[:email]
@token = Server.data.token
- @comments = Server.data.comments
+ @comments = @progress[:comments]
@discussBody = ''
- @subject = Server.data.subject
- @debug = false;
+ @subject = @progress[:subject]
+ @debug = Server.data.debug
+ end
end
@@ -22,57 +36,59 @@ class Discuss < Vue
This form allows PMC and PPMC members to
discuss contributors to achieve consensus.
}
- _b "Project: " + @pmc
- _p
- _b "Contributor: " + @iclaname + " (" + @iclaemail + ")"
- _p
- _b "Proposed by: " + @proposer
- _p
- _p "Subject: " + @subject
- _p
- #
- # Form fields
- #
- _div.form_group do
- _label "Comment from " + @user, for: 'discussBody'
- _textarea.form_control rows: 4,
- required: true, placeholder: 'new comment',
- id: 'discussBody', value: @discussBody,
- onChange: self.setDiscussBody
- end
- @comments.each {|c|
- _b 'From: ' + c.member + ' Date: ' + c.timestamp
- _p c.comment
- }
-if @debug
- _p 'token: ' + @token
- _p 'comment: ' + @discussBody
-end
- # error messages
- if @alert
- _div.alert.alert_danger do
- _b 'Error: '
- _span @alert
+ if @phase == 'discuss'
+ _b "Project: " + @pmc
+ _p
+ _b "Contributor: " + @iclaname + " (" + @iclaemail + ")"
+ _p
+ _b "Proposed by: " + @proposer
+ _p
+ _p "Subject: " + @subject
+ _p
+ #
+ # Form fields
+ #
+ _div.form_group do
+ _label "Comment from " + @user, for: 'discussBody'
+ _textarea.form_control rows: 4,
+ required: true, placeholder: 'new comment',
+ id: 'discussBody', value: @discussBody,
+ onChange: self.setDiscussBody
end
- end
-
-
- #
- # Submission buttons
- #
-
- _p do
- _button.btn.btn_primary 'Submit comment and continue to discuss',
+ @comments.each {|c|
+ _b 'From: ' + c.member + ' Date: ' + c.timestamp
+ _p c.comment
+ }
+ #
+ # Submission buttons
+ #
+
+ _p do
+ _button.btn.btn_primary 'Submit comment and continue to discuss',
disabled: @disabled,
onClick: self.submitComment
- _b ' or '
- _button.btn.btn_primary 'Submit comment and start voting',
+ _b ' or '
+ _button.btn.btn_primary 'Submit comment and start voting',
disabled: @disabled,
onClick: self.startVoting
- _b ' or '
- _button.btn.btn_primary 'Submit comment and invite contributor to submit
ICLA',
+ _b ' or '
+ _button.btn.btn_primary 'Submit comment and invite contributor to
submit ICLA',
disabled: @disabled,
onClick: self.invite
+ end
+ end
+ if @debug
+ _p 'token: ' + @token.to_s
+ _p 'comment: ' + @discussBody.inspect
+ _p 'progress: ' + @progress.inspect
+ end
+
+ # error messages
+ if @alert
+ _div.alert.alert_danger do
+ _b 'Error: '
+ _span @alert
+ end
end
#
@@ -121,7 +137,7 @@ end
# when the form is initially loaded, set the focus on the discussBody field
def mounted()
- document.getElementById('discussBody').focus()
+ document.getElementById('discussBody').focus() if not @alert
end
#
diff --git a/www/project/icla/views/pages/vote.js.rb
b/www/project/icla/views/pages/vote.js.rb
index 51ae47b..3964127 100644
--- a/www/project/icla/views/pages/vote.js.rb
+++ b/www/project/icla/views/pages/vote.js.rb
@@ -5,19 +5,34 @@ class Vote < Vue
# initialize form fields
@user = Server.data.user
- @proposer = Server.data.proposer
- @pmc = Server.data.contributor[:project]
- @iclaname = Server.data.contributor[:name]
- @iclaemail = Server.data.contributor[:email]
+ console.log('vote')
+ # console.log('time now: ' + Time.now.to_s)
+ console.log('token: ' + Server.data.token)
+ console.log('user: ' + @user)
+ @progress = Server.data.progress
+ console.log('progress: ' + @progress.inspect)
+ @phase = @progress[:phase]
+ console.log('phase: ' + @phase)
+ if @phase == 'error'
+ @alert = @progress[:errorMessage]
+ elsif @phase != 'vote'
+ @alert = "Wrong phase: " + @phase + "; should be vote"
+ else
+ @pmc = @progress[:project]
+ @proposer = @progress[:proposer]
+ @contributor = @progress[:contributor]
+ @iclaname = @contributor[:name]
+ @iclaemail = @contributor[:email]
@token = Server.data.token
- @comments = Server.data.comments
- @votes = Server.data.votes
+ @comments = @progress[:comments]
+ @votes = @progress[:votes]
@vote = ''
@timestamp = ''
@commentBody = ''
- @subject = Server.data.subject
+ @subject = @progress[:subject]
@showComment = false;
@debug = Server.data.debug
+ end
end
def render
@@ -25,90 +40,94 @@ class Vote < Vue
This form allows PMC and PPMC members to
vote to invite a contributor to become a committer or a PMC/PPMC member.
}
- _b "Project: " + @pmc
- _p
- _b "Contributor: " + @iclaname + " (" + @iclaemail + ")"
- _p
- _b "Proposed by: " + @proposer
- _p
- _p "Subject: " + @subject
- _p
- _div.form_group.vote do
- _label do
- _input type: 'radio', name: 'vote', value: '+1',
- onClick: -> {@vote = '+1'; @showComment = false; checkValidity()}
- _span " +1 approve "
- end
+ if @phase == 'vote'
+ _b "Project: " + @pmc
_p
- _label do
- _input type: 'radio', name: 'vote', value: '+0',
- onClick: -> {@vote = '+0'; @showComment = false; checkValidity()}
- _span " +0 don't care "
- end
+ _b "Contributor: " + @iclaname + " (" + @iclaemail + ")"
_p
- _label do
- _input type: 'radio', name: 'vote', value: '-0',
- onClick: -> {@vote = '-0'; @showComment = false; checkValidity()}
- _span " -0 don't care "
- end
+ _b "Proposed by: " + @proposer
_p
- _label do
- _input type: 'radio', name: 'vote', value: '-1',
- onClick: -> {@vote = '-1'; @showComment = true; checkValidity()}
- _span " -1 disapprove, because... "
- end
+ _p "Subject: " + @subject
_p
- end
+ _div.form_group.vote do
+ _label do
+ _input type: 'radio', name: 'vote', value: '+1',
+ onClick: -> {@vote = '+1'; @showComment = false; checkValidity()}
+ _span " +1 approve "
+ end
+ _p
+ _label do
+ _input type: 'radio', name: 'vote', value: '+0',
+ onClick: -> {@vote = '+0'; @showComment = false; checkValidity()}
+ _span " +0 don't care "
+ end
+ _p
+ _label do
+ _input type: 'radio', name: 'vote', value: '-0',
+ onClick: -> {@vote = '-0'; @showComment = false; checkValidity()}
+ _span " -0 don't care "
+ end
+ _p
+ _label do
+ _input type: 'radio', name: 'vote', value: '-1',
+ onClick: -> {@vote = '-1'; @showComment = true; checkValidity()}
+ _span " -1 disapprove, because... "
+ end
+ _p
+ end
- # error messages
- if @alert
- _div.alert.alert_danger do
- _b 'Error: '
- _span @alert
+ #
+ # Form fields
+ #
+ if @showComment
+ _div.form_group do
+ _textarea.form_control rows: 4,
+ placeholder: 'reason to disapprove',
+ id: 'commentBody', value: @commentBody,
+ onChange: self.setCommentBody
+ end
end
- end
- #
- # Form fields
- #
- if @showComment
- _div.form_group do
- _textarea.form_control rows: 4,
- placeholder: 'reason to disapprove',
- id: 'commentBody', value: @commentBody,
- onChange: self.setCommentBody
+ # previous votes
+ @votes.each {|v|
+ _p v.vote + ' From: ' + v.member + ' Date: ' + v.timestamp
+ }
+
+ # previous comments
+ @comments.each {|c|
+ _b 'From: ' + c.member + ' Date: ' + c.timestamp
+ _p c.comment
+ }
+
+ #
+ # Submission buttons
+ #
+ _p do
+ _button.btn.btn_primary 'Submit my vote', disabled: @disabled,
+ onClick: self.submitVote
+ _b ' or '
+ _button.btn.btn_primary 'Cancel the vote', disabled: false,
+ onClick: self.cancelVote
+ _b ' or '
+ _button.btn.btn_primary 'Tally the vote', disabled: false,
+ onClick: self.tallyVote
end
end
- @votes.each {|v|
- _p v.vote + ' From: ' + v.member + ' Date: ' + v.timestamp
- }
-
- @comments.each {|c|
- _b 'From: ' + c.member + ' Date: ' + c.timestamp
- _p c.comment
- }
-
if @debug
_p 'token: ' + @token
_p 'comment: ' + @commentBody
_p 'vote: ' + @vote
end
-
- #
- # Submission buttons
- #
- _p do
- _button.btn.btn_primary 'Submit my vote', disabled: @disabled,
- onClick: self.submitVote
- _b ' or '
- _button.btn.btn_primary 'Cancel the vote', disabled: false,
- onClick: self.cancelVote
- _b ' or '
- _button.btn.btn_primary 'Tally the vote', disabled: false,
- onClick: self.tallyVote
+ # error messages
+ if @alert
+ _div.alert.alert_danger do
+ _b 'Error: '
+ _span @alert
+ end
end
+
#
# Hidden form: preview invite email
#
--
To stop receiving notification emails like this one, please contact
[email protected].