-
Notifications
You must be signed in to change notification settings - Fork 117
Fix issues with Conditional question serialization (offered by @briri from DMPTool) in PR https://github.com/CDLUC3/dmptool/pull/667 #3497
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
aaronskiba
merged 26 commits into
development
from
johnpinto1-updated-port-of-dmptool-conditional-questions-fix-for-rails7
Apr 9, 2025
Merged
Changes from 3 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
c5fd8af
Fix issues with Conditional question serialization (offered by @briri
7ffc815
`bin/rails db:migrate`
aaronskiba da93d72
Fix for Conditional model bug for the webhook_data which was typed as a
dba3999
Updated the comment for param_conditions parameter for method
a58017c
Updated the check (!conditions.nil? && conditions.any?) in tag
06b0db5
Updated the tag in app/views/org_admin/conditions/_form.html.erb
739aad0
Refactor mapping of `remove_data` & `option_list`
aaronskiba f6a232b
Refactor webhook_data validation and construction
aaronskiba 82984e2
Refactor handling of `c.option_list.empty?`
aaronskiba 49b9f7d
Refactor option_list and remove_data handling
aaronskiba 115ea70
Put back `# rubocop:disable Metrics/MethodLength`
aaronskiba 0fde253
Update CHANGELOG.md
aaronskiba 0c2e2d2
Document callers of conditions/form partial
aaronskiba c879520
Merge pull request #3501 from DMPRoadmap/aaron/refactor-question-save…
aaronskiba 97677d4
Remove commented-out code
aaronskiba c7abc11
Remove unused variable from conditions/form
aaronskiba b2eaac4
Replace `condition_exists` w/ `condition.present?`
aaronskiba e651186
Remove redundant `type_default` variable
aaronskiba dc04625
Remove redundant conditional check
aaronskiba 5d0ec1e
Remove redundant conditional check
aaronskiba 3a11067
Refactor: Split conditions/_form into two
aaronskiba 4724bc7
Cleanup after `condtions/_form` refactor
aaronskiba 8f952be
Update CHANGELOG.md
aaronskiba ae5786e
Merge branch 'johnpinto1-updated-port-of-dmptool-conditional-question…
aaronskiba 478fdad
Merge pull request #3502 from DMPRoadmap/aaron/refactor-conditions-form
aaronskiba c0f6981
Enable translations with gettext method
aaronskiba File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
|
aaronskiba marked this conversation as resolved.
|
This file contains hidden or 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 hidden or 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 hidden or 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 %> | ||
|
aaronskiba marked this conversation as resolved.
Outdated
|
||
|
|
||
| <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. To change email details you need to remove and add the condition again.") | ||
| %> | ||
| <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][]"}) %> | ||
|
aaronskiba marked this conversation as resolved.
Outdated
|
||
| </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 display-if-action-remove"><%= _('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> | ||
| <div class="webhook-replacement display-off my-auto text-center"> | ||
| <%= link_to _('Edit email'), '#' %> | ||
| </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>(<%= 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.