-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issues with Conditional question serialization (offered by @briri
from DMPTool).nBased on DMPtool commit CDLUC3#667. Changes proposed in this PR (text from cited PR): - There is a migration file with code for MySQL and Postgres to update the Conditions table to convert JSON Arrays in string format records in the conditions table so that they are JSON Arrays. - Updated the form partials in app/views/org_admin/conditions/_form.erb.rb to properly send condition data to the controller. - Removed all JSON.parse calls in the app/helpers/conditions.rb helper - The user canno longer edit a condition. They need to remove it and create a new condition. This applies to the email for 'add notifications' too. Made the following changes to simplify this patch and to make it a little more user friendly: - The "Add Conditions" button will now say "Edit Conditions" if there are any conditions for a given question. - Updated the column heading over the "thing that happens when the condition is met" from "Remove" to "Target" since the content of the column can either be questions being removed or an email notification being sent. - Conditions of action type 'remove' can be added or removed (not updated anymore). - Hovering over the email of an existing condition displays a tooltip that shows the email message, subject, etc. - We allow only one question option to be selected when adding a Condition unlike inthe DMPTool version because experience with multiple options chosen has been problematic and buggy when used by users in DMPOnline.
- Loading branch information
John Pinto
committed
Jan 29, 2025
1 parent
994bb60
commit f105553
Showing
12 changed files
with
235 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
<div class="row"> | ||
<div class="col-md-12 mt-2"> | ||
<%= link_to _('Add condition'), new_org_admin_question_condition_path(question_id: question.id, condition_no: condition_no), remote: true, class: "add-condition" %> | ||
<p>To add a condition you must have selected an Option and Action together with | ||
<ul> | ||
<li>if Action is 'remove', you need to select one or more choices in Target.</li> | ||
<li>if Action is 'add notification', you need to fill in all the fields in the 'Send email' popup.</li> | ||
</ul> | ||
Otherwise, the condition will not be saved. | ||
</p> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,88 @@ | ||
<% condition = condition ||= nil %> | ||
|
||
<div class="row condition-partial mb-3"> | ||
<% | ||
action_type_arr = [["removes", :remove], ["adds notification", :add_webhook]] | ||
name_start = "conditions[]condition_" + condition_no.to_s | ||
action_type_arr = [["removes", :remove], ["adds notification", :add_webhook]] | ||
# name_start = "conditions[]condition_" + condition_no.to_s | ||
name_start = "conditions[#{condition_no.to_s}]" | ||
remove_question_collection = later_question_list(question) | ||
condition_exists = local_assigns.has_key? :condition | ||
type_default = condition_exists ? (condition[:action_type] == "remove" ? :remove : :add_webhook) : :remove | ||
remove_question_group = condition_exists ? | ||
grouped_options_for_select(remove_question_collection, condition[:remove_question_id]) : | ||
grouped_options_for_select(remove_question_collection) | ||
multiple = (question.question_format.multiselectbox? || question.question_format.checkbox?) | ||
view_email_content_info = _("Hover over the email address to view email content.") | ||
%> | ||
<div class="col-md-3 pe-2"> | ||
<%= select_tag(:question_option, options_from_collection_for_select(question.question_options.sort_by(&:number), "id", "text", | ||
condition_exists ? condition[:question_option_id] : question.question_options.sort_by(&:number)[0]), {class: 'form-select regular', 'data-bs-style': 'dropdown-toggle bg-white px-4 py-3', name: name_start + "[question_option][]"}) %> | ||
</div> | ||
<div class="col-md-3 pe-2"> | ||
<%= select_tag(:action_type, options_for_select(action_type_arr, type_default), {name: name_start + "[action_type]", class: 'action-type form-select narrow', 'data-bs-style': 'dropdown-toggle bg-white px-4 py-3'}) %> | ||
</div> | ||
<div class="col-md-3 pe-2"> | ||
<div class="remove-dropdown"> | ||
<%= select_tag(:remove_question_id, remove_question_group, {name: name_start + "[remove_question_id][]", class: 'form-select regular', multiple: true, 'data-bs-style': 'dropdown-toggle bg-white px-4 py-3'}) %> | ||
|
||
<%# If this is a new condition then display the interactive controls. otherwise just display the logic %> | ||
<% if condition.nil? %> | ||
<div class="form-label bold">Add condition</div> | ||
<div class="row mb-3"> | ||
<div class="col-md-9 pe-2"> | ||
<div class="form-label bold"><%= _('Option') %></div> | ||
<%= select_tag(:question_option, options_from_collection_for_select(question.question_options.sort_by(&:number), "id", "text", | ||
condition_exists ? condition[:question_option_id] : question.question_options.sort_by(&:number)[0]), {class: 'form-select regular', 'data-bs-style': 'dropdown-toggle bg-white px-4 py-3', name: name_start + "[question_option][]"}) %> | ||
</div> | ||
<div class="webhook-replacement display-off my-auto text-center"> | ||
<%= link_to _('Edit email'), '#' %> | ||
<div class="col-md-3 pe-2"> | ||
<div class="form-label bold"><%= _('Action') %></div> | ||
<%= select_tag(:action_type, options_for_select(action_type_arr, type_default), {name: name_start + "[action_type]", class: 'action-type form-select narrow', 'data-bs-style': 'dropdown-toggle bg-white px-4 py-3'}) %> | ||
</div> | ||
</div> | ||
<%= hidden_field_tag(name_start + "[number]", condition_no) %> | ||
|
||
<div class="col-md-3"> | ||
<a href="#anotherurl" class="delete-condition"><%= _('Remove') %></a> | ||
<div class="row d-flex mb-3"> | ||
<div class="col-md-10 pe-2"> | ||
<div class="form-label bold"><%= _('Target') %></div> | ||
<div class="remove-dropdown"> | ||
<%= select_tag(:remove_question_id, remove_question_group, {name: name_start + "[remove_question_id][]", class: 'form-select regular', multiple: true, 'data-bs-style': 'dropdown-toggle bg-white px-4 py-3'}) %> | ||
</div> | ||
<%= hidden_field_tag(name_start + "[number]", condition_no) %> | ||
</div> | ||
<div class="col-md-2 align-self-center"> | ||
<a href="#anotherurl" class="delete-condition btn btn-primary"><%= _('Remove') %></a> | ||
</div> | ||
<%= render partial: 'org_admin/conditions/webhook_form', locals: {name_start: name_start, condition_no: condition_no} %> | ||
</div> | ||
<% else %> | ||
<% | ||
qopt = condition[:question_option_id].any? ? QuestionOption.find_by(id: condition[:question_option_id].first): nil | ||
rquesArray = condition[:remove_question_id].any? ? Question.where(id: condition[:remove_question_id]) : nil | ||
%> | ||
<div class="col-md-3 pe-2"> | ||
<%= qopt[:text]&.slice(0, 25) %> | ||
<%= hidden_field_tag(name_start + "[question_option][]", condition[:question_option_id]) %> | ||
</div> | ||
<div class="col-md-3 pe-2"> | ||
<%= condition[:action_type] == 'remove' ? 'Remove' : 'Email' %> | ||
<%= hidden_field_tag(name_start + "[action_type]", condition[:action_type]) %> | ||
</div> | ||
<div class="col-md-3 pe-2"> | ||
<% if !rquesArray.nil? %> | ||
<% rquesArray.each do |rques| %> | ||
Question <%= rques[:number] %>: <%= rques.text.gsub(%r{</?p>}, '').slice(0, 50) %> | ||
<%= '...' if rques.text.gsub(%r{</?p>}, '').length > 50 %> | ||
<br> | ||
<% end %> | ||
<%= hidden_field_tag(name_start + "[remove_question_id][]", condition[:remove_question_id]) %> | ||
<% else %> | ||
<% | ||
hook_tip = "Name: #{condition[:webhook_data]['name']}\nEmail: #{condition[:webhook_data]['email']}\n" | ||
hook_tip += "Subject: #{condition[:webhook_data]['subject']}\nMessage: #{condition[:webhook_data]['message']}" | ||
%> | ||
<span title="<%= hook_tip %>"><%= condition[:webhook_data]['email'] %></span> | ||
<br><span class="webhook-replacement display-off my-auto text-center" style="display: block;"> | ||
<%= link_to _('Edit email'), '#' %> | ||
</span> | ||
<br>(<%= view_email_content_info %>) | ||
|
||
<%= render partial: 'org_admin/conditions/webhook_form', locals: {name_start: name_start, condition_no: condition_no} %> | ||
<%= hidden_field_tag(name_start + "[webhook-email]", condition[:webhook_data]['email']) %> | ||
<%= hidden_field_tag(name_start + "[webhook-name]", condition[:webhook_data]['name']) %> | ||
<%= hidden_field_tag(name_start + "[webhook-subject]", condition[:webhook_data]['subject']) %> | ||
<%= hidden_field_tag(name_start + "[webhook-message]", condition[:webhook_data]['message']) %> | ||
<% end %> | ||
<%= hidden_field_tag(name_start + "[number]", condition_no) %> | ||
</div> | ||
<div class="col-md-3"> | ||
<a href="#anotherurl" class="delete-condition"><%= _('Remove') %></a> | ||
</div> | ||
<% end %> | ||
</div> |
Oops, something went wrong.