diff --git a/CHANGELOG.md b/CHANGELOG.md index df8056bee6..01808126a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ - Lower PostgreSQL GitHub Action Chrome Version to Address Breaking Changes Between Latest Chrome Version (134) and `/features` Tests [#3491](https://github.com/DMPRoadmap/roadmap/pull/3491) - Bumped dependencies via `bundle update && yarn upgrade` [#3483](https://github.com/DMPRoadmap/roadmap/pull/3483) - Fixed issues with Conditional Question serialization offered by @briri from PR https://github.com/CDLUC3/dmptool/pull/667 for DMPTool. 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. +- Refactor `org_admin/conditions/_form.html.erb` [#3502](https://github.com/DMPRoadmap/roadmap/pull/3502) - Refactor `Question.save_condition` [#3501](https://github.com/DMPRoadmap/roadmap/pull/3501) ## v4.2.0 diff --git a/app/views/org_admin/conditions/_existing_condition_display.erb b/app/views/org_admin/conditions/_existing_condition_display.erb new file mode 100644 index 0000000000..b2a76765f4 --- /dev/null +++ b/app/views/org_admin/conditions/_existing_condition_display.erb @@ -0,0 +1,39 @@ + <% + 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 + 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.") + %> +
+ <%= qopt[:text]&.slice(0, 25) %> + <%= hidden_field_tag(name_start + "[question_option][]", condition[:question_option_id]) %> +
+
+ <%= condition[:action_type] == 'remove' ? 'Remove' : 'Email' %> + <%= hidden_field_tag(name_start + "[action_type]", condition[:action_type]) %> +
+
+ <% if !rquesArray.nil? %> + <% rquesArray.each do |rques| %> + Question <%= rques[:number] %>: <%= rques.text.gsub(%r{}, '').slice(0, 50) %> + <%= '...' if rques.text.gsub(%r{}, '').length > 50 %> +
+ <% 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']}" + %> + <%= condition[:webhook_data]['email'] %> +
(<%= view_email_content_info %>) + + <%= 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) %> +
+
+ <%= _('Remove') %> +
diff --git a/app/views/org_admin/conditions/_form.html.erb b/app/views/org_admin/conditions/_form.html.erb index 3a7877f098..0fe405972b 100644 --- a/app/views/org_admin/conditions/_form.html.erb +++ b/app/views/org_admin/conditions/_form.html.erb @@ -1,88 +1,31 @@ -<% condition ||= nil %> +<%# This partial is called from the following files: + - app/controllers/org_admin/conditions_controller.rb + - app/views/org_admin/conditions/_container.html.erb + %>
<% - action_type_arr = [["removes", :remove], ["adds notification", :add_webhook]] - # name_start = "conditions[]condition_" + condition_no.to_s + condition ||= nil 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.") %> <%# If this is a new condition then display the interactive controls. otherwise just display the logic %> <% if condition.nil? %> -
Add condition
-
-
-
<%= _('Option') %>
- <%= 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][]"}) %> -
-
-
<%= _('Action') %>
- <%= 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'}) %> -
-
-
-
-
<%= _('Target') %>
-
- <%= 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'}) %> -
-
- <%= link_to _('Edit email'), '#' %> -
- <%= hidden_field_tag(name_start + "[number]", condition_no) %> -
- - <%= render partial: 'org_admin/conditions/webhook_form', locals: {name_start: name_start, condition_no: condition_no} %> -
+ <%= render partial: 'org_admin/conditions/new_condition_form', + locals: { condition_no: condition_no, + name_start: name_start, + question: question + } + %> + <% 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 - %> -
- <%= qopt[:text]&.slice(0, 25) %> - <%= hidden_field_tag(name_start + "[question_option][]", condition[:question_option_id]) %> -
-
- <%= condition[:action_type] == 'remove' ? 'Remove' : 'Email' %> - <%= hidden_field_tag(name_start + "[action_type]", condition[:action_type]) %> -
-
- <% if !rquesArray.nil? %> - <% rquesArray.each do |rques| %> - Question <%= rques[:number] %>: <%= rques.text.gsub(%r{}, '').slice(0, 50) %> - <%= '...' if rques.text.gsub(%r{}, '').length > 50 %> -
- <% 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']}" - %> - <%= condition[:webhook_data]['email'] %> -
(<%= view_email_content_info %>) + <%= render partial: 'org_admin/conditions/existing_condition_display', + locals: { condition: condition, + condition_no: condition_no, + name_start: name_start, + question: question + } + %> - <%= 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) %> -
-
- <%= _('Remove') %> -
<% end %>
diff --git a/app/views/org_admin/conditions/_new_condition_form.erb b/app/views/org_admin/conditions/_new_condition_form.erb new file mode 100644 index 0000000000..49222c9de6 --- /dev/null +++ b/app/views/org_admin/conditions/_new_condition_form.erb @@ -0,0 +1,34 @@ + <% + action_type_arr = [["removes", :remove], ["adds notification", :add_webhook]] + remove_question_collection = later_question_list(question) + remove_question_group = grouped_options_for_select(remove_question_collection) + %> + +
Add condition
+
+
+
<%= _('Option') %>
+ <%= select_tag(:question_option, options_from_collection_for_select(question.question_options.sort_by(&:number), "id", "text", + 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][]"}) %> +
+
+
<%= _('Action') %>
+ <%= select_tag(:action_type, options_for_select(action_type_arr, :remove), {name: name_start + "[action_type]", class: 'action-type form-select narrow', 'data-bs-style': 'dropdown-toggle bg-white px-4 py-3'}) %> +
+
+
+
+
<%= _('Target') %>
+
+ <%= 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'}) %> +
+
+ <%= link_to _('Edit email'), '#' %> +
+ <%= hidden_field_tag(name_start + "[number]", condition_no) %> +
+
+ <%= _('Remove') %> +
+ <%= render partial: 'org_admin/conditions/webhook_form', locals: {name_start: name_start, condition_no: condition_no} %> +