adds index view for poll results in officing
This commit is contained in:
@@ -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
|
||||
|
||||
30
app/views/officing/results/index.html.erb
Normal file
30
app/views/officing/results/index.html.erb
Normal file
@@ -0,0 +1,30 @@
|
||||
<%= back_link_to new_officing_poll_result_path(@poll) %>
|
||||
<h2><%= @poll.name %> - <%= t("officing.results.index.results") %></h2>
|
||||
|
||||
<% if @partial_results.present? %>
|
||||
<div class="callout primary">
|
||||
<h3><%= @booth_assignment.booth.name %> - <%= l @partial_results.first.date, format: :long %></h3>
|
||||
</div>
|
||||
|
||||
<% by_question = @partial_results.group_by(&:question_id) %>
|
||||
<% @poll.questions.each do |question| %>
|
||||
<h3><%= question.title %></h3>
|
||||
|
||||
<table>
|
||||
<tbody>
|
||||
<% question.valid_answers.each_with_index do |answer, i| %>
|
||||
<% by_answer = by_question[question.id].present? ? by_question[question.id].group_by(&:answer) : {} %>
|
||||
<tr id="question_<%= question.id %>_<%= i %>_result">
|
||||
<td><%= answer %></td>
|
||||
<td><%= by_answer[answer].present? ? by_answer[answer].first.amount : 0 %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<% end %>
|
||||
<% else %>
|
||||
<div class="callout primary">
|
||||
<%= t("officing.results.index.no_results") %>
|
||||
</div>
|
||||
<% end %>
|
||||
@@ -81,13 +81,13 @@
|
||||
<% results_by_booth[booth_assignment].group_by(&:date).keys.each do |date| %>
|
||||
<tr id="results_<%= booth_assignment %>_<%= date.strftime('%Y%m%d') %>">
|
||||
<td>
|
||||
<%= l(date.to_date, format: :long) %>
|
||||
<%= l(date, format: :long) %>
|
||||
</td>
|
||||
<td>
|
||||
<%= results_by_booth[booth_assignment].first.booth_assignment.booth.name %>
|
||||
</td>
|
||||
<td>
|
||||
|
||||
<%= link_to t("officing.results.new.see_results"), officing_poll_results_path(@poll, date: l(date), booth_assignment_id: booth_assignment) %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user