+
<%= label(:text, _('Action'), class: "control-label") %>
- <%= _('Remove')%>
+ <%= label(:text, _('Target'), class: "control-label") %>
-
+
+ <%= label(:text, _('Remove'), class: "control-label") %>
<% conditions_params = conditions_to_param_form(conditions).sort_by { |key| key }.to_h %>
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..85ad7efdac
--- /dev/null
+++ b/app/views/org_admin/conditions/_existing_condition_display.erb
@@ -0,0 +1,41 @@
+ <%
+ 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{?p>}, '').slice(0, 50) %>
+ <%= '...' if rques.text.gsub(%r{?p>}, '').length > 50 %>
+
+ <% end %>
+ <%= hidden_field_tag(name_start + "[remove_question_id][]", condition[:remove_question_id]) %>
+ <% else %>
+ <%
+ hook_tip = "#{_('Name')}: #{condition[:webhook_data]['name']}\n"
+ hook_tip += "#{_('Email')}: #{condition[:webhook_data]['email']}\n"
+ hook_tip += "#{_('Subject')}: #{condition[:webhook_data]['subject']}\n"
+ hook_tip += "#{_('Message')}: #{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) %>
+
+
diff --git a/app/views/org_admin/conditions/_form.html.erb b/app/views/org_admin/conditions/_form.html.erb
index 8a48a3fc5c..0fe405972b 100644
--- a/app/views/org_admin/conditions/_form.html.erb
+++ b/app/views/org_admin/conditions/_form.html.erb
@@ -1,35 +1,31 @@
+<%# 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
- 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?)
+ condition ||= nil
+ name_start = "conditions[#{condition_no.to_s}]"
%>
-
- <%= 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][]"}) %>
-
-
- <%= 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'}) %>
-
-
-
- <%= 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) %>
+
+ <%# If this is a new condition then display the interactive controls. otherwise just display the logic %>
+ <% if condition.nil? %>
+ <%= render partial: 'org_admin/conditions/new_condition_form',
+ locals: { condition_no: condition_no,
+ name_start: name_start,
+ question: question
+ }
+ %>
-
+ <% else %>
+ <%= render partial: 'org_admin/conditions/existing_condition_display',
+ locals: { condition: condition,
+ condition_no: condition_no,
+ name_start: name_start,
+ question: question
+ }
+ %>
- <%= render partial: 'org_admin/conditions/webhook_form', locals: {name_start: name_start, condition_no: condition_no} %>
+ <% 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..7b42c99f10
--- /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) %>
+
+
+ <%= render partial: 'org_admin/conditions/webhook_form', locals: {name_start: name_start, condition_no: condition_no} %>
+
diff --git a/app/views/org_admin/conditions/_webhook_form.html.erb b/app/views/org_admin/conditions/_webhook_form.html.erb
index 8871af47c4..9b80a56743 100644
--- a/app/views/org_admin/conditions/_webhook_form.html.erb
+++ b/app/views/org_admin/conditions/_webhook_form.html.erb
@@ -9,25 +9,25 @@
- <%= label_tag name_start + "[webhook-name]", _('Name'), {'data-error': 'wrong', 'data-success': 'right', class: 'form-label'} %>
+ <%= label_tag name_start + "[webhook-name]", _('Name'), {'data-error': 'wrong', 'data-success': 'right', class: 'form-label', "aria-required": true, required: true} %>
<%= text_field_tag name_start + "[webhook-name]", nil, class: 'form-control validate' %>
- <%= label_tag name_start + "[webhook-email]", _('Email'), {'data-error': 'wrong', 'data-success': 'right', class: 'form-label'} %>
+ <%= label_tag name_start + "[webhook-email]", _('Email'), {'data-error': 'wrong', 'data-success': 'right', class: 'form-label', "aria-required": true, required: true} %>
<%= email_field_tag name_start + "[webhook-email]", nil, { placeholder: _('recipient_email@example.com'), class: 'form-control validate'} %>
- <%= label_tag name_start + "[webhook-subject]", _('Subject'), {'data-error': 'wrong', 'data-success': 'right', class: 'form-label'} %>
+ <%= label_tag name_start + "[webhook-subject]", _('Subject'), {'data-error': 'wrong', 'data-success': 'right', class: 'form-label', "aria-required": true, required: true} %>
<%= text_field_tag name_start + "[webhook-subject]", nil, class: 'form-control validate' %>
- <%= label_tag name_start + "[webhook-message]", _('Message'), {'data-error': 'wrong', 'data-success': 'right', class: 'form-label'} %>
+ <%= label_tag name_start + "[webhook-message]", _('Message'), {'data-error': 'wrong', 'data-success': 'right', class: 'form-label', "aria-required": true, required: true}%>
<%= text_area_tag name_start + "[webhook-message]", nil, { placeholder: _('Email content'), class: 'form-control md-textarea', rows: 4 } %>
diff --git a/app/views/org_admin/questions/_form.html.erb b/app/views/org_admin/questions/_form.html.erb
index f966845301..5d715390d1 100644
--- a/app/views/org_admin/questions/_form.html.erb
+++ b/app/views/org_admin/questions/_form.html.erb
@@ -45,8 +45,10 @@
<%= render "/org_admin/question_options/option_fields", f: f, q: question %>
+
<% if question.id != nil && question.question_options[0].text != nil %>
- <%= link_to _('Add Conditions'), org_admin_question_open_conditions_path(question_id: question.id, conditions: conditions), class: "add-logic btn btn-secondary", 'data-loaded': (conditions.size > 0).to_s, remote: true %>
+ <% cond_lbl = conditions&.any? ? 'Edit Conditions' : 'Add Conditions' %>
+ <%= link_to cond_lbl, org_admin_question_open_conditions_path(question_id: question.id, conditions: conditions), class: "add-logic btn btn-secondary", 'data-loaded': (conditions.size > 0).to_s, remote: true %>
<%= render partial: 'org_admin/conditions/container', locals: { f: f, question: question, conditions: conditions } %>
@@ -54,7 +56,7 @@
<% else %>
- <%= link_to _('Add Conditions'), '#', class: "add-logic btn btn-secondary disabled" %>
+ <%= link_to _('Edit Conditions'), '#', class: "add-logic btn btn-secondary disabled" %>
<% end %>
diff --git a/db/migrate/20250115102816_update_conditions_json_columns_data.rb b/db/migrate/20250115102816_update_conditions_json_columns_data.rb
new file mode 100644
index 0000000000..21605b7212
--- /dev/null
+++ b/db/migrate/20250115102816_update_conditions_json_columns_data.rb
@@ -0,0 +1,91 @@
+# This migration runs SQL for MySQL databases or POSTGRESQL database (default).
+class UpdateConditionsJsonColumnsData < ActiveRecord::Migration[7.1]
+ # rubocop:disable Metrics/MethodLength
+ def change
+ if ActiveRecord::Base.connection.adapter_name.downcase.include?('mysql')
+ # MySQL sql
+ execute <<-SQL
+ UPDATE conditions
+ SET
+ option_list = CONCAT(
+ '[',
+ REPLACE(
+ REPLACE(
+ REPLACE(option_list, '---\r\n-', ''),
+ '\r\n-',
+ ','
+ ),
+ '\r\n',
+ ''
+ ),
+ ']'
+ ),
+ remove_data = CONCAT(
+ '[',
+ REPLACE(
+ REPLACE(
+ REPLACE(remove_data, '---\r\n-', ''),
+ '\r\n-',
+ ','
+ ),
+ '\r\n',
+ ''
+ ),
+ ']'
+ )
+ WHERE option_list LIKE '---%';
+ SQL
+ else
+ # POSTGRES SQL
+ execute <<-SQL
+ UPDATE conditions
+SET
+ option_list = concat (
+ '[',
+ regexp_replace (
+ regexp_replace (
+ regexp_replace (
+ regexp_replace (option_list, '---(\r|\n)-', '', 'g'),
+ '(\r|\n)-',
+ ',',
+ 'g'
+ ),
+ '\r|\n',
+ '',
+ 'g'
+ ),
+ '''',
+ '"',
+ 'g'),
+ ']'
+ ),
+ remove_data = concat (
+ '[',
+ regexp_replace (
+ regexp_replace (
+ regexp_replace (
+ regexp_replace (remove_data, '---(\r|\n)-', '', 'g'),
+ '(\r|\n)-',
+ ',',
+ 'g'
+ ),
+ '\r|\n',
+ '',
+ 'g'
+ ),
+ '''',
+ '"',
+ 'g'),
+ ']'
+ )
+WHERE
+ option_list LIKE '---%';
+ SQL
+ end
+ end
+ # rubocop:enable Metrics/MethodLength
+
+ def down
+ # Add rollback logic if needed
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index ac3ee9619c..3b6036f2bf 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema[7.1].define(version: 2024_06_13_141451) do
+ActiveRecord::Schema[7.1].define(version: 2025_01_15_102816) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"