Skip to content

Commit f7fc8b7

Browse files
committed
Merge pull request #2181 from alphagov/remove-multiple-question-per-page-code
Remove multiple question per page code
2 parents d688a83 + 7c7a1b6 commit f7fc8b7

File tree

415 files changed

+23682
-25933
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

415 files changed

+23682
-25933
lines changed

app/helpers/current_question_helper.rb

+10-18
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,17 @@ def calculate_current_question_path(presenter)
55
smart_answer_path(attrs)
66
end
77

8-
def previous_response_key(question_number)
9-
if question_number
10-
previous_response_key = "previous_response_#{question_number}".to_sym
11-
else
12-
previous_response_key = :previous_response
13-
end
14-
end
15-
16-
def prefill_value_is?(value, question_number = nil)
17-
if params[previous_response_key(question_number)]
18-
params[previous_response_key(question_number)] == value
8+
def prefill_value_is?(value)
9+
if params[:previous_response]
10+
params[:previous_response] == value
1911
elsif params[:response]
2012
params[:response] == value
2113
end
2214
end
2315

24-
def prefill_value_includes?(question, value, question_number = nil)
25-
if params[previous_response_key(question_number)]
26-
question.to_response(params[previous_response_key(question_number)]).include?(value)
16+
def prefill_value_includes?(question, value)
17+
if params[:previous_response]
18+
question.to_response(params[:previous_response]).include?(value)
2719
elsif params[:response]
2820
params[:response].include?(value)
2921
end
@@ -33,11 +25,11 @@ def default_for_date(value)
3325
value.blank? ? nil : value.to_i
3426
end
3527

36-
def prefill_value_for(question, question_number = nil, attribute = nil)
37-
response = if params[previous_response_key(question_number)]
38-
question.to_response(params[previous_response_key(question_number)])
28+
def prefill_value_for(question, attribute = nil)
29+
if params[:previous_response]
30+
response = question.to_response(params[:previous_response])
3931
elsif params[:response]
40-
params[:response]
32+
response = params[:response]
4133
end
4234
if !response.blank? && attribute
4335
begin

app/presenters/flow_presenter.rb

-10
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,6 @@ def current_state
4343
@current_state ||= @flow.process(all_responses)
4444
end
4545

46-
def collapsed_question_pages
47-
collapsed_questions.map do |collapsed_question|
48-
OpenStruct.new(questions: [collapsed_question])
49-
end
50-
end
51-
5246
def collapsed_questions
5347
@flow.path(all_responses).map do |name|
5448
presenter_for(@flow.node(name))
@@ -85,10 +79,6 @@ def current_question_number
8579
current_state.path.size + 1
8680
end
8781

88-
def questions
89-
(current_node.is_a? QuestionPresenter) ? [current_node] : []
90-
end
91-
9282
def current_node
9383
presenter_for(@flow.node(current_state.current_node))
9484
end
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,19 @@
1-
<%- if question_page.title -%>
2-
<tr class="section">
3-
<td class="section-title">
4-
<%= question_page.title %>
5-
</td>
6-
<td>
7-
</td>
8-
<td class="link-right">
9-
<% if question_page.questions.count == 1 %>
10-
<%= link_to @presenter.change_collapsed_question_link(number_questions_so_far + 1) do %>
11-
Change<span class="visuallyhidden"> answer to "<%=question_page.title%>"</span>
12-
<% end %>
13-
<% else %>
14-
<%= link_to @presenter.change_collapsed_question_link(number_questions_so_far + 1, question_page.questions.count) do %>
15-
Change<span class="visuallyhidden"> answer to "<%=question_page.title%>"</span>
16-
<% end %>
17-
<% end %>
18-
</td>
19-
</tr>
20-
<% end %>
21-
22-
<% question_page.questions.each_with_index do |question, question_index|%>
23-
<%- if !question_page.title -%>
24-
<tr class="section">
25-
<% else %>
26-
<tr>
27-
<% end %>
28-
<td class="previous-question-title"><%= question.title %></td>
29-
<%- if question.multiple_responses? -%>
30-
<td class="previous-question-body"><ul>
31-
<%- question.response_labels(@presenter.accepted_responses[number_questions_so_far + question_index]).each do |label| -%>
32-
<li><%= label %></li>
33-
<%- end -%>
34-
</ul></td>
35-
<%- else -%>
36-
<td class="previous-question-body">
37-
<%= question.response_label(@presenter.accepted_responses[number_questions_so_far + question_index]) %></td>
1+
<tr class="section">
2+
<td class="previous-question-title"><%= question.title %></td>
3+
<%- if question.multiple_responses? -%>
4+
<td class="previous-question-body"><ul>
5+
<%- question.response_labels(@presenter.accepted_responses[number_questions_so_far]).each do |label| -%>
6+
<li><%= label %></li>
387
<%- end -%>
8+
</ul></td>
9+
<%- else -%>
10+
<td class="previous-question-body">
11+
<%= question.response_label(@presenter.accepted_responses[number_questions_so_far]) %></td>
12+
<%- end -%>
3913

40-
<%- if !question_page.title -%>
41-
<td class="link-right">
42-
<% if question_page.questions.count == 1 %>
43-
<%= link_to @presenter.change_collapsed_question_link(number_questions_so_far + 1) do %>
44-
Change<span class="visuallyhidden"> answer to "<%=question_page.questions.first.title%>"</span>
45-
<% end %>
46-
<% else %>
47-
<%= link_to @presenter.change_collapsed_question_link(number_questions_so_far + 1, question_page.questions.count) do %>
48-
<% titles = question_page.questions.map { |question| "\"#{question.title}\"" }.join(",") %>
49-
Change<span class="visuallyhidden"> answer to <%=titles%></span>
50-
<% end %>
51-
<% end %>
52-
</td>
14+
<td class="link-right">
15+
<%= link_to @presenter.change_collapsed_question_link(number_questions_so_far + 1) do %>
16+
Change<span class="visuallyhidden"> answer to "<%= question.title %>"</span>
5317
<% end %>
54-
</tr>
55-
<% end %>
18+
</td>
19+
</tr>

app/views/smart_answers/_content.html.erb

+2-8
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,7 @@
2020
<div class="step current">
2121
<%= form_tag calculate_current_question_path(@presenter), :method => :get %>
2222
<div class="current-question" id="current-question">
23-
<% if @presenter.questions.count > 1 %>
24-
<% @presenter.questions.each_with_index do |question, question_index| %>
25-
<%= render partial: "current_question", locals: {question: question, number: question_index + 1} %>
26-
<% end %>
27-
<% else %>
28-
<%= render partial: "current_question", locals: {question: @presenter.questions.first, number: nil} %>
29-
<% end %>
23+
<%= render partial: "current_question", locals: { question: @presenter.current_node } %>
3024
<div class="next-question">
3125
<input type="hidden" name="next" value="1" />
3226
<button type="submit" class="medium button">Next step</button>
@@ -35,5 +29,5 @@
3529
</form>
3630
</div>
3731
<% end %>
38-
<%= render "previous_answers", with_title: true %>
32+
<%= render "previous_answers" %>
3933
<% end %>

app/views/smart_answers/_current_question.html.erb

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
<div class="question">
22
<h2>
3-
<% if number %>
4-
<span class="question-number"><%=number%> </span>
5-
<% end %>
63
<%= question.title %>
74
</h2>
85
<div class="question-body">
@@ -19,7 +16,7 @@
1916
</p>
2017
<% end %>
2118

22-
<%= render partial: question.partial_template_name, locals: { question: question, number: number } %>
19+
<%= render partial: question.partial_template_name, locals: { question: question } %>
2320

2421
<%= question.post_body %>
2522
</div>
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
<fieldset>
2-
<% response_prefix = number ? "response_#{number}" : "response" %>
32
<% unless question.default_day %>
4-
<label for="<%=response_prefix%>_day">Day
5-
<%= select_day default_for_date(prefill_value_for(question, number, :day)), prefix: response_prefix, :prompt => '' %>
3+
<label for="response_day">Day
4+
<%= select_day default_for_date(prefill_value_for(question, :day)), prefix: "response", :prompt => '' %>
65
</label>
76
<% end %>
87
<% unless question.default_month %>
9-
<label for="<%=response_prefix%>_month">Month
10-
<%= select_month default_for_date(prefill_value_for(question, number, :month)), prefix: response_prefix, prompt: '' %>
8+
<label for="response_month">Month
9+
<%= select_month default_for_date(prefill_value_for(question, :month)), prefix: "response", prompt: '' %>
1110
</label>
1211
<% end %>
1312
<% unless question.default_year %>
14-
<label for="<%=response_prefix%>_year">Year
15-
<%= select_year default_for_date(prefill_value_for(question, number, :year)), prefix: response_prefix, prompt: '', :start_year => question.start_date.year, :end_year => question.end_date.year %>
13+
<label for="response_year">Year
14+
<%= select_year default_for_date(prefill_value_for(question, :year)), prefix: "response", prompt: '', :start_year => question.start_date.year, :end_year => question.end_date.year %>
1615
</label>
1716
<% end %>
1817
</fieldset>

app/views/smart_answers/_multiple_choice_question.html.erb

+4-11
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,10 @@
33
<ul class="<%= style %>">
44
<% question.options.each.with_index do |option, i| %>
55
<li>
6-
<% if number %>
7-
<label for="response_<%=number%>_<%= i %>" class="selectable">
8-
<%= radio_button_tag "response_#{number}", option.value, prefill_value_is?(option.value, number), id: "response_#{number}_#{i}" %>
9-
<%= option.label %>
10-
</label>
11-
<% else %>
12-
<label for="response_<%= i %>" class="selectable">
13-
<%= radio_button_tag "response", option.value, prefill_value_is?(option.value), id: "response_#{i}" %>
14-
<%= option.label %>
15-
</label>
16-
<% end %>
6+
<label for="response_<%= i %>" class="selectable">
7+
<%= radio_button_tag "response", option.value, prefill_value_is?(option.value), id: "response_#{i}" %>
8+
<%= option.label %>
9+
</label>
1710
</li>
1811
<% end %>
1912
</ul>
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
<% identifier = number ? "response_#{number}" : "response" %>
2-
<label for="<%= identifier %>"><%= question.hint %>
3-
<%= text_field_tag(identifier, prefill_value_for(question, number)) %>
1+
<label for="response"><%= question.hint %>
2+
<%= text_field_tag("response", prefill_value_for(question)) %>
43
</label>
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
11
<% if @presenter.current_question_number > 1 %>
2-
<div class="previous-answers <%= "previous-answers-top" unless with_title %>">
2+
<div class="previous-answers">
33
<div class="done-questions">
44
<article>
5-
<% if with_title %>
6-
<h3 class="previous-answers-title">
7-
Previous answers
8-
</h3>
9-
<% end %>
5+
<h3 class="previous-answers-title">
6+
Previous answers
7+
</h3>
108
<%= link_to "Start again", smart_answer_path(params[:id]), :class => "start-right" %>
119
<table>
1210
<tbody>
13-
<% number_questions_so_far = 0 %>
14-
<% @presenter.collapsed_question_pages.each do |question_page| %>
15-
<%= render partial: "collapsed_question", locals: {question_page: question_page, number_questions_so_far: number_questions_so_far} %>
16-
<% number_questions_so_far += question_page.questions.count %>
11+
<% @presenter.collapsed_questions.each_with_index do |question, number_questions_so_far| %>
12+
<%= render partial: "collapsed_question", locals: {question: question, number_questions_so_far: number_questions_so_far} %>
1713
<% end %>
1814
</tbody>
1915
</table>
2016
</article>
2117
</div>
2218
</div>
2319
<% end %>
24-
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
<fieldset>
2-
<% response_prefix = number ? "response_#{number}" : "response" %>
32
<label for="response_amount">
4-
&pound; <%= text_field_tag(response_prefix+"[amount]", nil, size: 5, value: prefill_value_for(question, number, :amount)) %>
3+
&pound; <%= text_field_tag("response[amount]", nil, size: 5, value: prefill_value_for(question, :amount)) %>
54
</label>
65
<label for="response_period">
7-
per <select name="<%=response_prefix%>[period]">
8-
<%= options_for_select %w{week month year}, prefill_value_for(question, number, :period) %>
6+
per <select name="response[period]">
7+
<%= options_for_select %w{week month year}, prefill_value_for(question, :period) %>
98
</select>
109
</label>
1110
</fieldset>
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
<% identifier = number ? "response_#{number}" : "response" %>
2-
<label for="<%= identifier %>"><%= question.hint %>
3-
<%= text_field_tag(identifier, prefill_value_for(question)) %>
1+
<label for="response"><%= question.hint %>
2+
<%= text_field_tag("response", prefill_value_for(question)) %>
43
</label>

0 commit comments

Comments
 (0)