Skip to content

Commit

Permalink
Merge pull request #20 from EarthPortal/feature/slice-form-improvement
Browse files Browse the repository at this point in the history
slice form modifications and restoring original feedback slice
  • Loading branch information
hakimalem authored Mar 4, 2025
2 parents 608922e + 556f12b commit 7ea66ab
Show file tree
Hide file tree
Showing 9 changed files with 2,129 additions and 81 deletions.
104 changes: 79 additions & 25 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,72 @@ def all_resources
end

def feedback
# Show the header/footer or not
feedback_layout = params[:pop].eql?('true') ? 'popup' : 'ontology'


# We're using a hidden form field to trigger for error checking
# If sim_submit is nil, we know the form hasn't been submitted and we should
# bypass form processing.
if params[:sim_submit].nil?
render 'home/feedback/feedback', layout: feedback_layout
return
end

@tags = []
unless params[:bug].nil? || params[:bug].empty?
@tags << t('home.bug')
end
unless params[:proposition].nil? || params[:proposition].empty?
@tags << t('home.proposition')
end
unless params[:question].nil? || params[:question].empty?
@tags << t('home.question')
end
unless params[:ontology_submissions_request].nil? || params[:ontology_submissions_request].empty?
@tags << t('home.ontology_submissions_request')
end

@errors = []

if params[:name].nil? || params[:name].empty?
@errors << t('home.include_name')
end
if params[:email].nil? || params[:email].length < 1 || !params[:email].match(/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i)
@errors << t('home.include_email')
end
if params[:comment].nil? || params[:comment].empty?
@errors << t('home.include_comment')
end
if using_captcha? && !session[:user]
unless verify_recaptcha
@errors << t('home.fill_text')
end
end

unless @errors.empty?
render 'home/feedback/feedback', layout: feedback_layout
return
end

Notifier.feedback(params[:name], params[:email], params[:comment], params[:location], @tags).deliver_later

if params[:pop].eql?('true')
render 'home/feedback/feedback_complete', layout: 'popup'
else
flash[:notice] = t('home.notice_feedback')
redirect_to_home
end
end


def slice
unless session[:user]
redirect_to "/login?redirect=/slice", alert: t('home.slice.login_required')
return
end

# Skip processing if form not submitted
return render('home/feedback/feedback', layout: feedback_layout) if params[:sim_submit].nil?
return render('home/slice/slice') if params[:sim_submit].nil?

@errors = []

Expand All @@ -103,36 +165,28 @@ def feedback
@errors << t('home.include_ontologies') if params[:ontologies].blank?
@errors << t('home.include_comment') if params[:comment].blank?

# Captcha validation for non-logged in users
if using_captcha? && !session[:user]
@errors << t('home.fill_captcha') unless verify_recaptcha
end

# Re-render form if errors exist
if @errors.any?
return render('home/feedback/feedback', layout: feedback_layout)
return render('home/slice/slice')
end

# Process feedback
Notifier.feedback(
params[:name],
params[:email],
params[:comment],
params[:slice_name],
params[:ontologies]
).deliver_later

# Response based on popup status
if params[:pop].eql?('true')
render 'home/feedback/feedback_complete', layout: 'popup'
else
flash[:notice] = t('home.notice_feedback')
begin
ontologies_str = params[:ontologies].join(", ")

# Process slice
Notifier.slice(
params[:name],
params[:email],
params[:comment],
params[:slice_name],
ontologies_str
).deliver_later
flash[:notice] = t('home.notice_slice')
redirect_to_home
end
end

private



def invalid_email?(email)
email.blank? || !email.match?(/\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i)
end
Expand Down
12 changes: 12 additions & 0 deletions app/mailers/notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,16 @@ def feedback(name, email, comment, location, tags)
:subject => "[#{$SITE}] Feedback from #{name}")
end

def slice(name, email, comment, slice_name, ontologies)
@name = name
@email = email
@comment = comment
@slice_name = slice_name
@ontologies = ontologies

mail(:to => "#{$SUPPORT_EMAIL}, #{email}",
:from => "#{$SUPPORT_EMAIL}",
:subject => "[#{$SITE}] new slice suggestion from #{name}")
end

end
95 changes: 45 additions & 50 deletions app/views/home/feedback/feedback.html.haml
Original file line number Diff line number Diff line change
@@ -1,66 +1,61 @@
- if params[:pop].eql?("true")
- pop = true
- unless @errors.nil?
%div{style: "color:red;margin-bottom:1em;"}
%div{:style => "color:red;margin-bottom:1em;"}
= t("home.feedback.error_on_form")
%ul
- @errors.each do |error|
- for error in @errors
%li= error
= form_tag('/feedback') do
-# Simulate form_for by providing a hidden field to check for submission
= hidden_field_tag 'sim_submit', 'true'
= hidden_field_tag("pop", pop)
.d-flex.justify-content-center.m-3
.feedback-form.p-4{style: "max-width: 600px; width: 100%;"}
.feedback-title-container.text-center.mb-4
.feedback-form
.feedback-title-container
%h2.feedback-title
= t("home.feedback.suggest_a_slice")
%hr#feedback-title-line.mb-4/
.form-group.mb-3{style: "max-width: 500px; margin: 0 auto;"}
= t("home.feedback.leave_your_feedback")
%hr#feedback-title-line/
- unless session[:user].nil?
%p.feedback-text
= t("home.feedback.feedback_hi_text")
%font
= session[:user].username
,
%p.feedback-email
= t("home.feedback.feedback_info_text")
%a{:href => "mailto: #{$SUPPORT_EMAIL}"}= $SUPPORT_EMAIL
= t("home.feedback.feedback_info_text_rest")
%a{:href => $GITHUB_ISSUES}
Github issues
- if session[:user].nil?
%p.feedback-input-title
= t("home.feedback.email")
%font{color: "red"} *
- if session[:user]
= hidden_field_tag "email", session[:user].email
%input.feedback-input.w-100{name: "email", type: "email", value: session[:user].email, disabled: true}/
- else
%input.feedback-input.w-100{name: "email", type: "email"}/
.form-group.mb-3{style: "max-width: 500px; margin: 0 auto;"}
%font{:color => "red"} *
%input.feedback-input{:name => "email", :type => "email"}/
%p.feedback-input-title
= t("home.feedback.name")
%font{color: "red"} *
- if session[:user]
= hidden_field_tag "name", session[:user].username
%input.feedback-input.w-100{name: "name", type: "text", value: session[:user].username, disabled: true}/
- else
%input.feedback-input.w-100{name: "name", type: "text"}/
.form-group.mb-3{style: "max-width: 500px; margin: 0 auto;"}
%p.feedback-input-title
= t("home.feedback.slice_name")
%font{color: "red"} *
%input.feedback-input.w-100{name: "slice_name", type: "text"}/
.form-group.mb-3{style: "max-width: 500px; margin: 0 auto;"}
%p.feedback-input-title
= t("search.advanced_options.ontologies")
%font{color: "red"} *
.field.w-100{style: "border: none;"}
= ontologies_selector(id:'feedback_ontologies',
name: 'ontologies[]',
selected: params[:ontologies]&.split(','),
ontologies: onts_for_select(include_views: true))
.form-group.mb-4{style: "max-width: 500px; margin: 0 auto;"}
%p.feedback-input-title
= t("home.feedback.reason_usage")
%font{color: "red"} *
%textarea.feedback-input.w-100{name: "comment", rows: "3"}
%font.register-optional= t("home.feedback.optional")
%input.feedback-input{:name => "name", :type => "text"}/
- else
= hidden_field_tag "name", session[:user].username
= hidden_field_tag "email", session[:user].email
%p.feedback-input-title
= t("home.feedback.proposition_url_page")
%font.register-optional= t("home.feedback.optional")
%input.feedback-input{:name => "location", :type => "text", :value => unescape(params[:location] || '')}
%p.feedback-input-title
= t("home.feedback.feedback")
%font{:color => "red"} *
%textarea.feedback-input{:name => "comment", :rows => "6"}
%p.feedback-input-title
= t("home.feedback.tags")
%font.register-optional= t("home.feedback.optional")
.feedback-checks
= render(ChipsComponent.new(name:"bug", value: t("home.feedback.bug")))
= render(ChipsComponent.new(name:"proposition", value: t("home.feedback.proposition")))
= render(ChipsComponent.new(name:"question", value: t("home.feedback.question")))
= render(ChipsComponent.new(name:"ontology_submissions_request", value: t("home.feedback.ontology_submissions_request")))
- if using_captcha?
.mb-3
= recaptcha_tags
.text-center
%input.feedback-button{type: "submit", value: t("home.feedback.send")}/
= recaptcha_tags
%input.feedback-button{:type => "submit", :value => t("home.feedback.send")}/
46 changes: 46 additions & 0 deletions app/views/home/slice/slice.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
- if session[:user]
- unless @errors.nil?
%div{style: "color:red;margin-bottom:1em;"}
= t("home.slice.error_on_form")
%ul
- @errors.each do |error|
%li= error
= form_tag('/slice') do
= hidden_field_tag 'sim_submit', 'true'
.d-flex.justify-content-center.m-3
.feedback-form.p-4{style: "max-width: 600px; width: 100%;"}
.feedback-title-container.text-center.mb-4
%h2.feedback-title
= t("home.slice.suggest_a_slice")
%hr#feedback-title-line.mb-4/
.form-group.mb-3
= hidden_field_tag "email", session[:user].email
= render Input::TextInputComponent.new(label: label_required(t("home.slice.email")), name: "email", value: session[:user].email, disabled: true)
.form-group.mb-3
= hidden_field_tag "name", session[:user].username
= render Input::TextInputComponent.new(label: t("home.slice.name"), name: "name", value: session[:user].username, disabled: true)
.form-group.mb-3
= render Input::TextInputComponent.new(label: label_required(t("home.slice.slice_name")), name: "slice_name")
.form-group.mb-3{style: "margin: 0 auto;"}
%p.feedback-input-title
= t("search.advanced_options.ontologies")
%font{color: "red"} *
.field.w-100{style: "border: none;"}
= ontologies_selector(id:'slice_ontologies',
name: 'ontologies[]',
selected: params[:ontologies]&.split(','),
ontologies: onts_for_select(include_views: true))
.form-group.mb-4
= render Input::TextAreaComponent.new(label: label_required(t("home.slice.reason_usage")), name: "comment", value: "", placeholder: "", helper_text: "", rows: 3)
.form-group.text-center{style: "max-width: 500px; margin: 0 auto;"}
%input.feedback-button.w-100{type: "submit", value: t("home.slice.send")}
- else
.d-flex.justify-content-center.align-items-center{style: "height: 300px;"}
.text-center
%h3= t("home.slice.login_required")
= link_to t("home.slice.login"), login_path(redirect: slice_path), class: "btn btn-primary mt-3"
65 changes: 65 additions & 0 deletions app/views/notifier/slice.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
!!!
%html
%head
%meta{content: "text/html; charset=UTF-8", "http-equiv" => "Content-Type"}/
%meta{content: "no-cache", name: "turbo-cache-control"}/
:css
body {
font-family: Arial, sans-serif;
line-height: 1.6;
color: #333;
max-width: 600px;
margin: 20px auto;
padding: 20px;
}
.header {
border-bottom: 2px solid #eee;
padding-bottom: 15px;
margin-bottom: 20px;
}
.content {
background: #fff;
padding: 20px;
border-radius: 5px;
}
.ontology-list {
background: #f9f9f9;
padding: 15px 30px;
border-radius: 5px;
}
.comment-section {
margin-top: 20px;
padding-top: 20px;
border-top: 1px solid #eee;
}
.label {
color: #666;
font-weight: bold;
}
%body
.content
.header
%h2{style: "color: #2c3e50;"} Slice Request Details

%p
%span.label= t("slice_mail.name") + ": "
= @name

%p
%span.label= t("slice_mail.email") + ": "
= @email

%p
%span.label= t("slice_mail.slice_name") + ": "
= @slice_name

.ontology-list
%h3{style: "color: #2c3e50; margin-top: 0;"}= t("slice_mail.ontologies")
%ul
- @ontologies.split(/\s*,\s*/).each do |ontology|
%li= ontology
.comment-section
%h3{style: "color: #2c3e50; margin-top: 0;"}= t("slice_mail.comment")
.comment-content
= simple_format(@comment)
Loading

0 comments on commit 7ea66ab

Please sign in to comment.