Rename Poll::Question::Answer to Poll::Question::Option
Having a class named `Poll::Question::Answer` and another class named `Poll::Answer` was so confusing that no developer working on the project has ever been capable of remembering which is which for more than a few seconds. Furthermore, we're planning to add open answers to polls, and we might add a reference from the `poll_answers` table to the `poll_question_answers` table to property differentiate between open answers and closed answers. Having yet another thing named answer would be more than what our brains can handle (we know it because we did this once in a prototype). So we're renaming `Poll::Question::Answer` to `Poll::Question::Option`. Hopefully that'll make it easier to remember. The name is also (more or less) consistent with the `Legislation::QuestionOption` class, which is similar. We aren't changing the table or columns names for now in order to avoid possible issues when upgrading (old code running with the new database tables/columns after running the migrations but before deployment has finished, for instance). We might do it in the future. I've tried not to change the internationalization keys either so existing translations would still be valid. However, since we have to change the keys in `activerecord.yml` so methods like `human_attribute_name` keep working, I'm also changing them in places where similar keys were used (like `poll_question_answer` or `poll/question/answer`). Note that it isn't clear whether we should use `option` or `question_option` in some cases. In order to keep things simple, we're using `option` where we were using `answer` and `question_option` where we were using `question_answer`. Also note we're adding tests for the admin menu component, since at first I forgot to change the `answers` reference there and all tests passed.
This commit is contained in:
@@ -1 +0,0 @@
|
||||
<%= render Admin::Poll::Questions::Answers::Documents::IndexComponent.new(@answer) %>
|
||||
@@ -1,9 +0,0 @@
|
||||
<%= back_link_to admin_answer_videos_path(@answer) %>
|
||||
|
||||
<h2>
|
||||
<%= t("admin.answers.videos.new.title") %>
|
||||
</h2>
|
||||
|
||||
<div class="poll-question-answer-video-form">
|
||||
<%= render "form", form_url: admin_answer_videos_path(@answer) %>
|
||||
</div>
|
||||
@@ -1,11 +1,11 @@
|
||||
<%= render "shared/globalize_locales", resource: @answer %>
|
||||
<%= render "shared/globalize_locales", resource: @option %>
|
||||
|
||||
<%= translatable_form_for(@answer, url: form_url) do |f| %>
|
||||
<%= translatable_form_for(@option, url: form_url) do |f| %>
|
||||
|
||||
<%= render "shared/errors", resource: @answer %>
|
||||
<%= render "shared/errors", resource: @option %>
|
||||
|
||||
<%= f.hidden_field :given_order,
|
||||
value: @answer.persisted? ? @answer.given_order : @answer.class.last_position(@answer.question_id || @question.id) + 1 %>
|
||||
value: @option.persisted? ? @option.given_order : @option.class.last_position(@option.question_id || @question.id) + 1 %>
|
||||
|
||||
<div class="row">
|
||||
<%= f.translatable_fields do |translations_form| %>
|
||||
@@ -0,0 +1 @@
|
||||
<%= render Admin::Poll::Questions::Options::Documents::IndexComponent.new(@option) %>
|
||||
@@ -1,7 +1,7 @@
|
||||
<%= back_link_to admin_question_path(@question) %>
|
||||
|
||||
<ul class="breadcrumbs margin-top">
|
||||
<li><%= @answer.title %></li>
|
||||
<li><%= @option.title %></li>
|
||||
<li><%= t("admin.answers.edit.title") %></li>
|
||||
</ul>
|
||||
|
||||
@@ -10,5 +10,5 @@
|
||||
</h2>
|
||||
|
||||
<div class="poll-question-answer-form">
|
||||
<%= render "form", form_url: admin_question_answer_path(@question, @answer) %>
|
||||
<%= render "form", form_url: admin_question_option_path(@question, @option) %>
|
||||
</div>
|
||||
@@ -1,4 +1,4 @@
|
||||
<%= back_link_to admin_question_path(@answer.question) %>
|
||||
<%= back_link_to admin_question_path(@option.question) %>
|
||||
|
||||
<div class="clear"></div>
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
<%= t("admin.answers.images.index.title") %>
|
||||
</h2>
|
||||
|
||||
<% if can?(:update, @answer) %>
|
||||
<% if can?(:update, @option) %>
|
||||
<%= link_to t("admin.questions.answers.images.add_image"),
|
||||
new_admin_answer_image_path(@answer),
|
||||
new_admin_option_image_path(@option),
|
||||
class: "button hollow float-right" %>
|
||||
<% else %>
|
||||
<div class="callout warning">
|
||||
@@ -17,11 +17,11 @@
|
||||
<% end %>
|
||||
|
||||
<ul class="breadcrumbs margin-top">
|
||||
<li><%= @answer.question.title %></li>
|
||||
<li><%= @answer.title %></li>
|
||||
<li><%= @option.question.title %></li>
|
||||
<li><%= @option.title %></li>
|
||||
</ul>
|
||||
|
||||
<% @answer.images.each do |image| %>
|
||||
<% @option.images.each do |image| %>
|
||||
<div class="small-12 medium-4 column end">
|
||||
<%= render_image(image, :large, true) if image.present? %>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<div class="poll-question-form">
|
||||
<%= form_for(@answer, url: admin_answer_images_path(@answer), method: :post) do |f| %>
|
||||
<%= render "shared/errors", resource: @answer %>
|
||||
<%= form_for(@option, url: admin_option_images_path(@option), method: :post) do |f| %>
|
||||
<%= render "shared/errors", resource: @option %>
|
||||
|
||||
<%= render Images::NestedComponent.new(f, image_fields: :images) %>
|
||||
|
||||
@@ -8,5 +8,5 @@
|
||||
<h2><%= t("admin.answers.new.title") %></h2>
|
||||
|
||||
<div class="poll-question-answer-form">
|
||||
<%= render "form", form_url: admin_question_answers_path %>
|
||||
<%= render "form", form_url: admin_question_options_path %>
|
||||
</div>
|
||||
@@ -1,9 +1,9 @@
|
||||
<%= back_link_to admin_answer_videos_path(@answer) %>
|
||||
<%= back_link_to admin_option_videos_path(@option) %>
|
||||
|
||||
<h2>
|
||||
<%= t("admin.answers.videos.edit.title") %>
|
||||
</h2>
|
||||
|
||||
<div class="poll-question-answer-video-form">
|
||||
<%= render "form", form_url: admin_answer_video_path(@answer, @video) %>
|
||||
<%= render "form", form_url: admin_option_video_path(@option, @video) %>
|
||||
</div>
|
||||
@@ -1,4 +1,4 @@
|
||||
<%= back_link_to admin_question_path(@answer.question) %>
|
||||
<%= back_link_to admin_question_path(@option.question) %>
|
||||
|
||||
<div class="clear"></div>
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
<%= t("admin.answers.videos.index.title") %>
|
||||
</h2>
|
||||
|
||||
<% if can?(:create, Poll::Question::Answer.new(question: @answer.question)) %>
|
||||
<% if can?(:create, Poll::Question::Option.new(question: @option.question)) %>
|
||||
<%= link_to t("admin.answers.videos.index.add_video"),
|
||||
new_admin_answer_video_path(@answer),
|
||||
new_admin_option_video_path(@option),
|
||||
class: "button success float-right" %>
|
||||
<% else %>
|
||||
<div class="callout warning">
|
||||
@@ -33,7 +33,7 @@
|
||||
<td><%= video.title %></td>
|
||||
<td><%= link_to video.url, video.url %></td>
|
||||
<td>
|
||||
<%= render Admin::Poll::Questions::Answers::Videos::TableActionsComponent.new(video) %>
|
||||
<%= render Admin::Poll::Questions::Options::Videos::TableActionsComponent.new(video) %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
@@ -0,0 +1,9 @@
|
||||
<%= back_link_to admin_option_videos_path(@option) %>
|
||||
|
||||
<h2>
|
||||
<%= t("admin.answers.videos.new.title") %>
|
||||
</h2>
|
||||
|
||||
<div class="poll-question-answer-video-form">
|
||||
<%= render "form", form_url: admin_option_videos_path(@option) %>
|
||||
</div>
|
||||
@@ -47,8 +47,8 @@
|
||||
</div>
|
||||
|
||||
<div class="clear">
|
||||
<% if can?(:create, Poll::Question::Answer.new(question: @question)) %>
|
||||
<%= link_to t("admin.questions.show.add_answer"), new_admin_question_answer_path(@question),
|
||||
<% if can?(:create, Poll::Question::Option.new(question: @question)) %>
|
||||
<%= link_to t("admin.questions.show.add_answer"), new_admin_question_option_path(@question),
|
||||
class: "button float-right" %>
|
||||
<% else %>
|
||||
<div class="callout warning">
|
||||
@@ -70,8 +70,8 @@
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody class="sortable" data-js-url="<%= admin_question_answers_order_answers_path(@question.id) %>">
|
||||
<% @question.question_answers.each do |answer| %>
|
||||
<tbody class="sortable" data-js-url="<%= admin_question_options_order_options_path(@question.id) %>">
|
||||
<% @question.question_options.each do |answer| %>
|
||||
<tr id="<%= dom_id(answer) %>" class="poll_question_answer" data-answer-id="<%= answer.id %>">
|
||||
<td class="align-top"><%= answer.title %></td>
|
||||
<td class="align-top break"><%= wysiwyg(answer.description) %></td>
|
||||
@@ -79,22 +79,22 @@
|
||||
(<%= answer.images.count %>)
|
||||
<br>
|
||||
<%= link_to t("admin.questions.show.answers.images_list"),
|
||||
admin_answer_images_path(answer) %>
|
||||
admin_option_images_path(answer) %>
|
||||
</td>
|
||||
<td class="align-top text-center">
|
||||
(<%= answer.documents.count rescue 0 %>)
|
||||
<br>
|
||||
<%= link_to t("admin.questions.show.answers.documents_list"),
|
||||
admin_answer_documents_path(answer) %>
|
||||
admin_option_documents_path(answer) %>
|
||||
</td>
|
||||
<td class="align-top text-center">
|
||||
(<%= answer.videos.count %>)
|
||||
<br>
|
||||
<%= link_to t("admin.questions.show.answers.video_list"),
|
||||
admin_answer_videos_path(answer) %>
|
||||
admin_option_videos_path(answer) %>
|
||||
</td>
|
||||
<td>
|
||||
<%= render Admin::Poll::Questions::Answers::TableActionsComponent.new(answer) %>
|
||||
<%= render Admin::Poll::Questions::Options::TableActionsComponent.new(answer) %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
||||
@@ -9,11 +9,11 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% question.question_answers.each_with_index do |answer, i| %>
|
||||
<% question.question_options.each_with_index do |option, i| %>
|
||||
<% by_answer = by_question[question.id].present? ? by_question[question.id].group_by(&:answer) : {} %>
|
||||
<tr id="question_<%= question.id %>_<%= i %>_result">
|
||||
<td><%= answer.title %></td>
|
||||
<td class="text-center"><%= by_answer[answer.title].present? ? by_answer[answer.title].sum(&:amount) : 0 %></td>
|
||||
<td><%= option.title %></td>
|
||||
<td class="text-center"><%= by_answer[option.title].present? ? by_answer[option.title].sum(&:amount) : 0 %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
||||
@@ -13,14 +13,14 @@
|
||||
</div>
|
||||
|
||||
<div class="js-answers">
|
||||
<%= f.fields_for :question_answers do |answer| %>
|
||||
<%= render "question_answer_fields", f: answer %>
|
||||
<%= f.fields_for :question_options do |answer| %>
|
||||
<%= render "question_option_fields", f: answer %>
|
||||
<% end %>
|
||||
|
||||
<div class="answer-links links row expanded">
|
||||
<div class="small-12 column">
|
||||
<%= link_to_add_association t("dashboard.polls.question_fields.add_answer"),
|
||||
f, :question_answers, class: "button hollow" %>
|
||||
f, :question_options, class: "button hollow" %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -39,11 +39,11 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% question.question_answers.each_with_index do |answer, i| %>
|
||||
<% question.question_options.each_with_index do |option, i| %>
|
||||
<% by_answer = by_question[question.id].present? ? by_question[question.id].group_by(&:answer) : {} %>
|
||||
<tr id="question_<%= question.id %>_<%= i %>_result">
|
||||
<td><%= answer.title %></td>
|
||||
<td><%= by_answer[answer.title].present? ? by_answer[answer.title].first.amount : 0 %></td>
|
||||
<td><%= option.title %></td>
|
||||
<td><%= by_answer[option.title].present? ? by_answer[option.title].first.amount : 0 %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
<div class="small-12 column">
|
||||
<h3><%= question.title %></h3>
|
||||
</div>
|
||||
<% question.question_answers.each_with_index do |answer, i| %>
|
||||
<% question.question_options.each_with_index do |answer, i| %>
|
||||
<div class="small-12 medium-6 large-3 column end">
|
||||
<label><%= answer.title %></label>
|
||||
<%= text_field_tag "questions[#{question.id}][#{i}]", answer_result_value(question.id, i), placeholder: "0" %>
|
||||
|
||||
@@ -1 +1 @@
|
||||
$("#<%= dom_id(@question) %>_answers").html("<%= j render Polls::Questions::AnswersComponent.new(@question) %>");
|
||||
$("#<%= dom_id(@question) %>_answers").html("<%= j render Polls::Questions::OptionsComponent.new(@question) %>");
|
||||
Reference in New Issue
Block a user