Skip to content

Commit 478fdad

Browse files
authored
Merge pull request #3502 from DMPRoadmap/aaron/refactor-conditions-form
Refactor `org_admin/conditions/_form.html.erb`
2 parents c879520 + ae5786e commit 478fdad

File tree

4 files changed

+93
-76
lines changed

4 files changed

+93
-76
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- 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)
1414
- Bumped dependencies via `bundle update && yarn upgrade` [#3483](https://github.com/DMPRoadmap/roadmap/pull/3483)
1515
- 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.
16+
- Refactor `org_admin/conditions/_form.html.erb` [#3502](https://github.com/DMPRoadmap/roadmap/pull/3502)
1617
- Refactor `Question.save_condition` [#3501](https://github.com/DMPRoadmap/roadmap/pull/3501)
1718

1819
## v4.2.0
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<%
2+
qopt = condition[:question_option_id].any? ? QuestionOption.find_by(id: condition[:question_option_id].first): nil
3+
rquesArray = condition[:remove_question_id].any? ? Question.where(id: condition[:remove_question_id]) : nil
4+
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.")
5+
%>
6+
<div class="col-md-3 pe-2">
7+
<%= qopt[:text]&.slice(0, 25) %>
8+
<%= hidden_field_tag(name_start + "[question_option][]", condition[:question_option_id]) %>
9+
</div>
10+
<div class="col-md-3 pe-2">
11+
<%= condition[:action_type] == 'remove' ? 'Remove' : 'Email' %>
12+
<%= hidden_field_tag(name_start + "[action_type]", condition[:action_type]) %>
13+
</div>
14+
<div class="col-md-3 pe-2">
15+
<% if !rquesArray.nil? %>
16+
<% rquesArray.each do |rques| %>
17+
Question <%= rques[:number] %>: <%= rques.text.gsub(%r{</?p>}, '').slice(0, 50) %>
18+
<%= '...' if rques.text.gsub(%r{</?p>}, '').length > 50 %>
19+
<br>
20+
<% end %>
21+
<%= hidden_field_tag(name_start + "[remove_question_id][]", condition[:remove_question_id]) %>
22+
<% else %>
23+
<%
24+
hook_tip = "Name: #{condition[:webhook_data]['name']}\nEmail: #{condition[:webhook_data]['email']}\n"
25+
hook_tip += "Subject: #{condition[:webhook_data]['subject']}\nMessage: #{condition[:webhook_data]['message']}"
26+
%>
27+
<span title="<%= hook_tip %>"><%= condition[:webhook_data]['email'] %></span>
28+
<br>(<%= view_email_content_info %>)
29+
30+
<%= hidden_field_tag(name_start + "[webhook-email]", condition[:webhook_data]['email']) %>
31+
<%= hidden_field_tag(name_start + "[webhook-name]", condition[:webhook_data]['name']) %>
32+
<%= hidden_field_tag(name_start + "[webhook-subject]", condition[:webhook_data]['subject']) %>
33+
<%= hidden_field_tag(name_start + "[webhook-message]", condition[:webhook_data]['message']) %>
34+
<% end %>
35+
<%= hidden_field_tag(name_start + "[number]", condition_no) %>
36+
</div>
37+
<div class="col-md-3">
38+
<a href="#anotherurl" class="delete-condition"><%= _('Remove') %></a>
39+
</div>
Lines changed: 19 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,31 @@
1-
<% condition ||= nil %>
1+
<%# This partial is called from the following files:
2+
- app/controllers/org_admin/conditions_controller.rb
3+
- app/views/org_admin/conditions/_container.html.erb
4+
%>
25

36
<div class="row condition-partial mb-3">
47
<%
5-
action_type_arr = [["removes", :remove], ["adds notification", :add_webhook]]
6-
# name_start = "conditions[]condition_" + condition_no.to_s
8+
condition ||= nil
79
name_start = "conditions[#{condition_no.to_s}]"
8-
remove_question_collection = later_question_list(question)
9-
condition_exists = local_assigns.has_key? :condition
10-
type_default = condition_exists ? (condition[:action_type] == "remove" ? :remove : :add_webhook) : :remove
11-
remove_question_group = condition_exists ?
12-
grouped_options_for_select(remove_question_collection, condition[:remove_question_id]) :
13-
grouped_options_for_select(remove_question_collection)
14-
multiple = (question.question_format.multiselectbox? || question.question_format.checkbox?)
15-
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.")
1610
%>
1711

1812
<%# If this is a new condition then display the interactive controls. otherwise just display the logic %>
1913
<% if condition.nil? %>
20-
<div class="form-label bold">Add condition</div>
21-
<div class="row mb-3">
22-
<div class="col-md-9 pe-2">
23-
<div class="form-label bold"><%= _('Option') %></div>
24-
<%= select_tag(:question_option, options_from_collection_for_select(question.question_options.sort_by(&:number), "id", "text",
25-
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][]"}) %>
26-
</div>
27-
<div class="col-md-3 pe-2">
28-
<div class="form-label bold"><%= _('Action') %></div>
29-
<%= 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'}) %>
30-
</div>
31-
</div>
32-
<div class="row d-flex mb-3">
33-
<div class="col-md-10 pe-2">
34-
<div class="form-label bold display-if-action-remove"><%= _('Target') %></div>
35-
<div class="remove-dropdown">
36-
<%= 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'}) %>
37-
</div>
38-
<div class="webhook-replacement display-off my-auto text-center">
39-
<%= link_to _('Edit email'), '#' %>
40-
</div>
41-
<%= hidden_field_tag(name_start + "[number]", condition_no) %>
42-
</div>
43-
<div class="col-md-2 align-self-center">
44-
<a href="#anotherurl" class="delete-condition btn btn-primary"><%= _('Remove') %></a>
45-
</div>
46-
<%= render partial: 'org_admin/conditions/webhook_form', locals: {name_start: name_start, condition_no: condition_no} %>
47-
</div>
14+
<%= render partial: 'org_admin/conditions/new_condition_form',
15+
locals: { condition_no: condition_no,
16+
name_start: name_start,
17+
question: question
18+
}
19+
%>
20+
4821
<% else %>
49-
<%
50-
qopt = condition[:question_option_id].any? ? QuestionOption.find_by(id: condition[:question_option_id].first): nil
51-
rquesArray = condition[:remove_question_id].any? ? Question.where(id: condition[:remove_question_id]) : nil
52-
%>
53-
<div class="col-md-3 pe-2">
54-
<%= qopt[:text]&.slice(0, 25) %>
55-
<%= hidden_field_tag(name_start + "[question_option][]", condition[:question_option_id]) %>
56-
</div>
57-
<div class="col-md-3 pe-2">
58-
<%= condition[:action_type] == 'remove' ? 'Remove' : 'Email' %>
59-
<%= hidden_field_tag(name_start + "[action_type]", condition[:action_type]) %>
60-
</div>
61-
<div class="col-md-3 pe-2">
62-
<% if !rquesArray.nil? %>
63-
<% rquesArray.each do |rques| %>
64-
Question <%= rques[:number] %>: <%= rques.text.gsub(%r{</?p>}, '').slice(0, 50) %>
65-
<%= '...' if rques.text.gsub(%r{</?p>}, '').length > 50 %>
66-
<br>
67-
<% end %>
68-
<%= hidden_field_tag(name_start + "[remove_question_id][]", condition[:remove_question_id]) %>
69-
<% else %>
70-
<%
71-
hook_tip = "Name: #{condition[:webhook_data]['name']}\nEmail: #{condition[:webhook_data]['email']}\n"
72-
hook_tip += "Subject: #{condition[:webhook_data]['subject']}\nMessage: #{condition[:webhook_data]['message']}"
73-
%>
74-
<span title="<%= hook_tip %>"><%= condition[:webhook_data]['email'] %></span>
75-
<br>(<%= view_email_content_info %>)
22+
<%= render partial: 'org_admin/conditions/existing_condition_display',
23+
locals: { condition: condition,
24+
condition_no: condition_no,
25+
name_start: name_start,
26+
question: question
27+
}
28+
%>
7629

77-
<%= hidden_field_tag(name_start + "[webhook-email]", condition[:webhook_data]['email']) %>
78-
<%= hidden_field_tag(name_start + "[webhook-name]", condition[:webhook_data]['name']) %>
79-
<%= hidden_field_tag(name_start + "[webhook-subject]", condition[:webhook_data]['subject']) %>
80-
<%= hidden_field_tag(name_start + "[webhook-message]", condition[:webhook_data]['message']) %>
81-
<% end %>
82-
<%= hidden_field_tag(name_start + "[number]", condition_no) %>
83-
</div>
84-
<div class="col-md-3">
85-
<a href="#anotherurl" class="delete-condition"><%= _('Remove') %></a>
86-
</div>
8730
<% end %>
8831
</div>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<%
2+
action_type_arr = [["removes", :remove], ["adds notification", :add_webhook]]
3+
remove_question_collection = later_question_list(question)
4+
remove_question_group = grouped_options_for_select(remove_question_collection)
5+
%>
6+
7+
<div class="form-label bold">Add condition</div>
8+
<div class="row mb-3">
9+
<div class="col-md-9 pe-2">
10+
<div class="form-label bold"><%= _('Option') %></div>
11+
<%= select_tag(:question_option, options_from_collection_for_select(question.question_options.sort_by(&:number), "id", "text",
12+
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][]"}) %>
13+
</div>
14+
<div class="col-md-3 pe-2">
15+
<div class="form-label bold"><%= _('Action') %></div>
16+
<%= 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'}) %>
17+
</div>
18+
</div>
19+
<div class="row d-flex mb-3">
20+
<div class="col-md-10 pe-2">
21+
<div class="form-label bold display-if-action-remove"><%= _('Target') %></div>
22+
<div class="remove-dropdown">
23+
<%= 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'}) %>
24+
</div>
25+
<div class="webhook-replacement display-off my-auto text-center">
26+
<%= link_to _('Edit email'), '#' %>
27+
</div>
28+
<%= hidden_field_tag(name_start + "[number]", condition_no) %>
29+
</div>
30+
<div class="col-md-2 align-self-center">
31+
<a href="#anotherurl" class="delete-condition btn btn-primary"><%= _('Remove') %></a>
32+
</div>
33+
<%= render partial: 'org_admin/conditions/webhook_form', locals: {name_start: name_start, condition_no: condition_no} %>
34+
</div>

0 commit comments

Comments
 (0)