diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 2d8805553..1be22b348 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -29,6 +29,7 @@ @import "management/**/*"; @import "milestones/**/*"; @import "moderation/**/*"; +@import "officing/**/*"; @import "polls/**/*"; @import "proposals/**/*"; @import "relationable/**/*"; diff --git a/app/assets/stylesheets/officing/results/form.scss b/app/assets/stylesheets/officing/results/form.scss new file mode 100644 index 000000000..97649145c --- /dev/null +++ b/app/assets/stylesheets/officing/results/form.scss @@ -0,0 +1,5 @@ +.officing-results-form { + legend { + @include header-font-size(h3); + } +} diff --git a/app/components/attachable/fields_component.html.erb b/app/components/attachable/fields_component.html.erb index 45d9770ba..bf48fb959 100644 --- a/app/components/attachable/fields_component.html.erb +++ b/app/components/attachable/fields_component.html.erb @@ -4,7 +4,7 @@ <%= f.hidden_field :cached_attachment %>
- <%= f.text_field :title, placeholder: t("#{plural_name}.form.title_placeholder") %> + <%= f.text_field :title %>
<% if attachable.attachment.attached? && attachable.attachment.image? %> diff --git a/app/components/officing/results/form_component.html.erb b/app/components/officing/results/form_component.html.erb new file mode 100644 index 000000000..d1c7870ec --- /dev/null +++ b/app/components/officing/results/form_component.html.erb @@ -0,0 +1,47 @@ +<%= form_tag(officing_poll_results_path(poll), { id: "officer_assignment_form", class: "officing-results-form" }) do %> +
+
+ <%= label_tag :officer_assignment_id, t("officing.results.new.booth") %> + <%= select_tag :officer_assignment_id, + booths_for_officer_select_options(officer_assignments), + { prompt: t("officing.results.new.select_booth") } %> +
+
+ + <% poll.questions.each do |question| %> +
+ <%= question.title %> + <% question.question_options.each_with_index do |option, i| %> +
+ <%= label_tag "questions_#{question.id}_#{i}", option.title %> + <%= number_field_tag "questions[#{question.id}][#{i}]", answer_result_value(question.id, i), min: 0 %> +
+ <% end %> +
+
+ <% end %> + +
+
+ <%= label_tag :whites, t("officing.results.new.ballots_white") %> + <%= number_field_tag :whites, params[:whites].to_i, min: 0 %> +
+ +
+ <%= label_tag :nulls, t("officing.results.new.ballots_null") %> + <%= number_field_tag :nulls, params[:nulls].to_i, min: 0 %> +
+ +
+ <%= label_tag :total, t("officing.results.new.ballots_total") %> + <%= number_field_tag :total, params[:total].to_i, min: 0 %> +
+
+
+ +
+
+ <%= submit_tag t("officing.results.new.submit"), class: "button expanded" %> +
+
+<% end %> diff --git a/app/components/officing/results/form_component.rb b/app/components/officing/results/form_component.rb new file mode 100644 index 000000000..a21979a1c --- /dev/null +++ b/app/components/officing/results/form_component.rb @@ -0,0 +1,15 @@ +class Officing::Results::FormComponent < ApplicationComponent + attr_reader :poll, :officer_assignments + use_helpers :booths_for_officer_select_options + + def initialize(poll, officer_assignments) + @poll = poll + @officer_assignments = officer_assignments + end + + private + + def answer_result_value(question_id, option_index) + params.dig(:questions, question_id.to_s, option_index.to_s).to_i + end +end diff --git a/app/helpers/officing_helper.rb b/app/helpers/officing_helper.rb index 3078f3c84..15c2e7788 100644 --- a/app/helpers/officing_helper.rb +++ b/app/helpers/officing_helper.rb @@ -6,12 +6,4 @@ module OfficingHelper options.sort_by! { |x| x[0] } options_for_select(options, params[:oa]) end - - def answer_result_value(question_id, option_index) - return nil if params.blank? - return nil if params[:questions].blank? - return nil if params[:questions][question_id.to_s].blank? - - params[:questions][question_id.to_s][option_index.to_s] - end end diff --git a/app/views/admin/legislation/questions/_form.html.erb b/app/views/admin/legislation/questions/_form.html.erb index cdab0e727..a9c467bf9 100644 --- a/app/views/admin/legislation/questions/_form.html.erb +++ b/app/views/admin/legislation/questions/_form.html.erb @@ -17,24 +17,26 @@
-
- <%= f.label :question_options, t("admin.legislation.questions.form.question_options") %> -
+
+ + <%= t("admin.legislation.questions.form.question_options") %> + -
- <%= f.fields_for :question_options do |ff| %> - <%= render "question_option_fields", f: ff %> - <% end %> +
+ <%= f.fields_for :question_options do |ff| %> + <%= render "question_option_fields", f: ff %> + <% end %> -
-
- <%= link_to_add_association t("admin.legislation.questions.form.add_option"), - f, - :question_options, - class: "button hollow" %> +
+
+ <%= link_to_add_association t("admin.legislation.questions.form.add_option"), + f, + :question_options, + class: "button hollow" %> +
-
+
<%= f.submit(class: "button success expanded", value: t("admin.legislation.questions.#{admin_submit_action(@question)}.submit_button")) %> diff --git a/app/views/admin/legislation/questions/_question_option_fields.html.erb b/app/views/admin/legislation/questions/_question_option_fields.html.erb index c610c298c..6e6b3080c 100644 --- a/app/views/admin/legislation/questions/_question_option_fields.html.erb +++ b/app/views/admin/legislation/questions/_question_option_fields.html.erb @@ -3,8 +3,7 @@
<%= f.translatable_fields do |translations_form| %> <%= translations_form.text_field :value, - placeholder: t("admin.legislation.questions.form.value_placeholder"), - label: false %> + label: t("admin.legislation.questions.form.value_placeholder") %> <% end %>
diff --git a/app/views/officing/results/new.html.erb b/app/views/officing/results/new.html.erb index c53ff92d5..c1b6c43b3 100644 --- a/app/views/officing/results/new.html.erb +++ b/app/views/officing/results/new.html.erb @@ -1,56 +1,6 @@ <% if @officer_assignments.any? %>

<%= t("officing.results.new.title", poll: @poll.name) %>

- - <%= form_tag(officing_poll_results_path(@poll), { id: "officer_assignment_form" }) do %> -
-
- <%= label_tag :officer_assignment_id, t("officing.results.new.booth") %> - <%= select_tag :officer_assignment_id, - booths_for_officer_select_options(@officer_assignments), - { prompt: t("officing.results.new.select_booth") } %> -
-
- - <% @poll.questions.each do |question| %> -
-
-

<%= question.title %>

-
- <% question.question_options.each_with_index do |option, i| %> -
- - <%= text_field_tag "questions[#{question.id}][#{i}]", answer_result_value(question.id, i), placeholder: "0" %> -
- <% end %> -
-
- <% end %> - -
-
-

<%= t("officing.results.new.ballots_white") %>

- <%= text_field_tag :whites, params[:whites].presence, placeholder: "0" %> -
- -
-

<%= t("officing.results.new.ballots_null") %>

- <%= text_field_tag :nulls, params[:nulls].presence, placeholder: "0" %> -
- -
-

<%= t("officing.results.new.ballots_total") %>

- <%= text_field_tag :total, params[:total].presence, placeholder: "0" %> -
-
-
- -
-
- <%= submit_tag t("officing.results.new.submit"), class: "button expanded" %> -
-
- <% end %> - + <%= render Officing::Results::FormComponent.new(@poll, @officer_assignments) %> <% else %>

<%= @poll.name %>

diff --git a/app/views/proposals/retire_form.html.erb b/app/views/proposals/retire_form.html.erb index fef9e5c6d..641028774 100644 --- a/app/views/proposals/retire_form.html.erb +++ b/app/views/proposals/retire_form.html.erb @@ -28,7 +28,7 @@ <%= translations_form.text_area :retired_explanation, rows: 4, maxlength: 500, - placeholder: t("proposals.retire_form.retired_explanation_placeholder") %> + hint: t("proposals.retire_form.retired_explanation_placeholder") %>
<% end %>
diff --git a/config/locales/en/documents.yml b/config/locales/en/documents.yml index d60fd5c9d..5630b10a3 100644 --- a/config/locales/en/documents.yml +++ b/config/locales/en/documents.yml @@ -5,7 +5,6 @@ en: additional: Additional documentation form: title: Documents - title_placeholder: Add a descriptive title for the document delete_button: Remove document cancel_button: Cancel note: "You can upload up to a maximum of %{max_documents_allowed} documents of following content types: %{accepted_content_types}, up to %{max_file_size} MB per file." diff --git a/config/locales/en/images.yml b/config/locales/en/images.yml index 155056604..93a74fc50 100644 --- a/config/locales/en/images.yml +++ b/config/locales/en/images.yml @@ -3,7 +3,6 @@ en: remove_image: Remove image form: title: Descriptive image - title_placeholder: Add a descriptive title for the image delete_button: Remove image note: "You can upload one image of following content types: %{accepted_content_types}, up to %{max_file_size} MB." add_new_image: Add image diff --git a/config/locales/es/documents.yml b/config/locales/es/documents.yml index 88121ace3..afa9fb542 100644 --- a/config/locales/es/documents.yml +++ b/config/locales/es/documents.yml @@ -5,7 +5,6 @@ es: additional: Documentación adicional form: title: Documentos - title_placeholder: Añade un título descriptivo para el documento delete_button: Eliminar documento cancel_button: Cancelar note: "Puedes subir hasta un máximo de %{max_documents_allowed} documentos en los formatos: %{accepted_content_types}, y de hasta %{max_file_size} MB por archivo." diff --git a/config/locales/es/images.yml b/config/locales/es/images.yml index ed197fa7d..32e5cb5a4 100644 --- a/config/locales/es/images.yml +++ b/config/locales/es/images.yml @@ -3,7 +3,6 @@ es: remove_image: Eliminar imagen form: title: Imagen descriptiva - title_placeholder: Añade un título descriptivo para la imagen delete_button: Eliminar imagen note: "Puedes subir una imagen en los formatos: %{accepted_content_types}, y de hasta %{max_file_size} MB por archivo." add_new_image: Añadir imagen diff --git a/spec/components/officing/results/form_component_spec.rb b/spec/components/officing/results/form_component_spec.rb new file mode 100644 index 000000000..81f19e38e --- /dev/null +++ b/spec/components/officing/results/form_component_spec.rb @@ -0,0 +1,19 @@ +require "rails_helper" + +describe Officing::Results::FormComponent do + let(:poll) { create(:poll, ends_at: 1.day.ago) } + before { create(:poll_question, :yes_no, poll: poll, title: "Agreed?") } + + it "uses number fields with 0 as a default value" do + render_inline Officing::Results::FormComponent.new(poll, Poll::OfficerAssignment.none) + + page.find(:fieldset, "Agreed?") do |fieldset| + expect(fieldset).to have_field "Yes", with: 0, type: :number + expect(fieldset).to have_field "No", with: 0, type: :number + end + + expect(page).to have_field "Totally blank ballots", with: 0, type: :number + expect(page).to have_field "Invalid ballots", with: 0, type: :number + expect(page).to have_field "Valid ballots", with: 0, type: :number + end +end diff --git a/spec/system/admin/legislation/questions_spec.rb b/spec/system/admin/legislation/questions_spec.rb index 0573c7dcd..ad0376280 100644 --- a/spec/system/admin/legislation/questions_spec.rb +++ b/spec/system/admin/legislation/questions_spec.rb @@ -107,7 +107,7 @@ describe "Admin legislation questions", :admin do create(:legislation_question_option, question: question, value: "Original") visit edit_question_url - find("#nested_question_options input").set("Changed") + fill_in "Add a closed answer", with: "Changed" click_button "Save changes" expect(page).to have_content "Question updated successfully" @@ -154,11 +154,11 @@ describe "Admin legislation questions", :admin do click_link "Add option" - find("#nested_question_options input").set("Option 1") + fill_in "Add a closed answer", with: "Option 1" select "Español", from: "Current language" - find("#nested_question_options input").set("Opción 1") + fill_in "Add a closed answer", with: "Opción 1" click_button "Save changes" @@ -180,11 +180,11 @@ describe "Admin legislation questions", :admin do click_link "Add option" - find("#nested_question_options input").set("Opción 1") + fill_in "Add a closed answer", with: "Opción 1" select "English", from: "Current language" - find("#nested_question_options input").set("Option 1") + fill_in "Add a closed answer", with: "Option 1" click_button "Save changes" diff --git a/spec/system/officing/results_spec.rb b/spec/system/officing/results_spec.rb index 59abe9497..9eb49ad59 100644 --- a/spec/system/officing/results_spec.rb +++ b/spec/system/officing/results_spec.rb @@ -59,15 +59,19 @@ describe "Officing Results", :with_frozen_time do select booth.name, from: "Booth" - fill_in "questions[#{question_1.id}][0]", with: "100" - fill_in "questions[#{question_1.id}][1]", with: "200" + within_fieldset question_1.title do + fill_in "Yes", with: "100" + fill_in "No", with: "200" + end - fill_in "questions[#{question_2.id}][0]", with: "333" - fill_in "questions[#{question_2.id}][1]", with: "444" + within_fieldset question_2.title do + fill_in "Today", with: "333" + fill_in "Tomorrow", with: "444" + end - fill_in "whites", with: "66" - fill_in "nulls", with: "77" - fill_in "total", with: "88" + fill_in "Totally blank ballots", with: "66" + fill_in "Invalid ballots", with: "77" + fill_in "Valid ballots", with: "88" click_button "Save" @@ -102,11 +106,14 @@ describe "Officing Results", :with_frozen_time do booth_name = partial_result.booth_assignment.booth.name select booth_name, from: "Booth" - fill_in "questions[#{question_1.id}][0]", with: "5555" - fill_in "questions[#{question_1.id}][1]", with: "200" - fill_in "whites", with: "6" - fill_in "nulls", with: "7" - fill_in "total", with: "8" + within_fieldset question_1.title do + fill_in "Yes", with: "5555" + fill_in "No", with: "200" + end + + fill_in "Totally blank ballots", with: "6" + fill_in "Invalid ballots", with: "7" + fill_in "Valid ballots", with: "8" click_button "Save"