diff --git a/app/controllers/officing/results_controller.rb b/app/controllers/officing/results_controller.rb
index cffd3e0d0..e716b8c8b 100644
--- a/app/controllers/officing/results_controller.rb
+++ b/app/controllers/officing/results_controller.rb
@@ -18,6 +18,17 @@ class Officing::ResultsController < Officing::BaseController
redirect_to new_officing_poll_result_path(@poll), notice: notice
end
+ def index
+ @booth_assignment = ::Poll::BoothAssignment.includes(:booth).find(index_params[:booth_assignment_id])
+ if current_user.poll_officer.officer_assignments.final.
+ where(booth_assignment_id: @booth_assignment.id).exists?
+
+ @partial_results = ::Poll::PartialResult.includes(:question).
+ where(booth_assignment_id: index_params[:booth_assignment_id]).
+ where(date: index_params[:date])
+ end
+ end
+
private
def check_booth_and_date
@@ -93,4 +104,8 @@ class Officing::ResultsController < Officing::BaseController
params.permit(:officer_assignment_id, :date, :questions)
end
+ def index_params
+ params.permit(:booth_assignment_id, :date)
+ end
+
end
diff --git a/app/views/officing/results/index.html.erb b/app/views/officing/results/index.html.erb
new file mode 100644
index 000000000..a20a944ca
--- /dev/null
+++ b/app/views/officing/results/index.html.erb
@@ -0,0 +1,30 @@
+<%= back_link_to new_officing_poll_result_path(@poll) %>
+
<%= @poll.name %> - <%= t("officing.results.index.results") %>
+
+<% if @partial_results.present? %>
+
+
<%= @booth_assignment.booth.name %> - <%= l @partial_results.first.date, format: :long %>
+
+
+ <% by_question = @partial_results.group_by(&:question_id) %>
+ <% @poll.questions.each do |question| %>
+ <%= question.title %>
+
+
+
+ <% question.valid_answers.each_with_index do |answer, i| %>
+ <% by_answer = by_question[question.id].present? ? by_question[question.id].group_by(&:answer) : {} %>
+
+ | <%= answer %> |
+ <%= by_answer[answer].present? ? by_answer[answer].first.amount : 0 %> |
+
+ <% end %>
+
+
+
+ <% end %>
+<% else %>
+
+ <%= t("officing.results.index.no_results") %>
+
+<% end %>
\ No newline at end of file
diff --git a/app/views/officing/results/new.html.erb b/app/views/officing/results/new.html.erb
index 146a99699..1d8dee7fd 100644
--- a/app/views/officing/results/new.html.erb
+++ b/app/views/officing/results/new.html.erb
@@ -81,13 +81,13 @@
<% results_by_booth[booth_assignment].group_by(&:date).keys.each do |date| %>
|
- <%= l(date.to_date, format: :long) %>
+ <%= l(date, format: :long) %>
|
<%= results_by_booth[booth_assignment].first.booth_assignment.booth.name %>
|
-
+ <%= link_to t("officing.results.new.see_results"), officing_poll_results_path(@poll, date: l(date), booth_assignment_id: booth_assignment) %>
|
<% end %>
diff --git a/config/locales/officing.en.yml b/config/locales/officing.en.yml
index 048002e7f..f5ce67400 100644
--- a/config/locales/officing.en.yml
+++ b/config/locales/officing.en.yml
@@ -70,6 +70,10 @@ en:
ballots_null: "Invalid ballots"
submit: "Save"
results_list: "Your results"
+ see_results: "See results"
+ index:
+ no_results: "No results"
+ results: Results
residence:
flash:
create: "Document verified with Census"
diff --git a/config/locales/officing.es.yml b/config/locales/officing.es.yml
index 645876309..c8c97b1c5 100644
--- a/config/locales/officing.es.yml
+++ b/config/locales/officing.es.yml
@@ -70,6 +70,10 @@ es:
ballots_null: "Papeletas nulas"
submit: "Guardar"
results_list: "Tus resultados"
+ see_results: "Ver resultados"
+ index:
+ no_results: "No hay resultados"
+ results: "Resultados"
residence:
flash:
create: "Documento verificado con el PadrĂ³n"
diff --git a/config/routes.rb b/config/routes.rb
index 2295453b6..41511ef97 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -336,7 +336,7 @@ Rails.application.routes.draw do
resources :recounts, only: [:new, :create]
resources :final_recounts, only: [:new, :create]
- resources :results, only: [:new, :create]
+ resources :results, only: [:new, :create, :index]
end
resource :residence, controller: "residence", only: [:new, :create]
resources :voters, only: [:new, :create]
diff --git a/spec/features/officing/results_spec.rb b/spec/features/officing/results_spec.rb
index b4129645b..141bcd687 100644
--- a/spec/features/officing/results_spec.rb
+++ b/spec/features/officing/results_spec.rb
@@ -72,4 +72,68 @@ feature 'Officing Results' do
end
end
+ scenario 'Edit result' do
+ partial_result = create(:poll_partial_result,
+ officer_assignment: @officer_assignment,
+ booth_assignment: @officer_assignment.booth_assignment,
+ date: @poll.starts_at,
+ question: @question_1,
+ answer: @question_1.valid_answers[0],
+ author: @poll_officer.user,
+ amount: 7777)
+
+ visit officing_poll_results_path(@poll, date: I18n.l(partial_result.date), booth_assignment_id: partial_result.booth_assignment_id)
+
+ expect(page).to have_content('7777')
+
+ visit new_officing_poll_result_path(@poll)
+
+ booth_name = partial_result.booth_assignment.booth.name
+ date = I18n.l(partial_result.date, format: :long)
+ select booth_name, from: 'officer_assignment_id'
+ select date, from: 'date'
+
+ fill_in "questions[#{@question_1.id}][0]", with: '5555'
+ fill_in "questions[#{@question_1.id}][1]", with: '200'
+
+ click_button 'Save'
+
+ within("#results_#{partial_result.booth_assignment_id}_#{partial_result.date.strftime('%Y%m%d')}") do
+ expect(page).to have_content(I18n.l(partial_result.date, format: :long))
+ expect(page).to have_content(partial_result.booth_assignment.booth.name)
+ click_link "See results"
+ end
+
+ expect(page).to_not have_content('7777')
+ within("#question_#{@question_1.id}_0_result") { expect(page).to have_content('5555') }
+ within("#question_#{@question_1.id}_1_result") { expect(page).to have_content('200') }
+ end
+
+ scenario 'Index lists all questions and answers' do
+ partial_result = create(:poll_partial_result,
+ officer_assignment: @officer_assignment,
+ booth_assignment: @officer_assignment.booth_assignment,
+ date: @poll.ends_at,
+ question: @question_1,
+ amount: 33)
+
+ visit officing_poll_results_path(@poll,
+ date: I18n.l(@poll.ends_at.to_date),
+ booth_assignment_id: @officer_assignment.booth_assignment_id)
+
+ expect(page).to have_content(I18n.l(@poll.ends_at.to_date, format: :long))
+ expect(page).to have_content(@officer_assignment.booth_assignment.booth.name)
+
+ expect(page).to have_content(@question_1.title)
+ @question_1.valid_answers.each_with_index do |answer, i|
+ within("#question_#{@question_1.id}_#{i}_result") { expect(page).to have_content(answer) }
+ end
+
+ expect(page).to have_content(@question_2.title)
+ @question_2.valid_answers.each_with_index do |answer, i|
+ within("#question_#{@question_2.id}_#{i}_result") { expect(page).to have_content(answer) }
+ end
+
+ end
+
end
\ No newline at end of file