Merge pull request #1960 from consul/polls_minor_changes

Requested polls admin section improvements
This commit is contained in:
María Checa
2017-10-03 21:36:08 +02:00
committed by GitHub
20 changed files with 36 additions and 216 deletions

View File

@@ -1,7 +1,7 @@
class Admin::Poll::PollsController < Admin::Poll::BaseController
load_and_authorize_resource
before_action :load_search, only: [:search_booths, :search_questions, :search_officers]
before_action :load_search, only: [:search_booths, :search_officers]
before_action :load_geozones, only: [:new, :create, :edit, :update]
def index
@@ -47,25 +47,6 @@ class Admin::Poll::PollsController < Admin::Poll::BaseController
redirect_to admin_poll_path(@poll), notice: notice
end
def remove_question
question = ::Poll::Question.find(params[:question_id])
if @poll.questions.include? question
@poll.questions.delete(question)
notice = t("admin.polls.flash.question_removed")
else
notice = t("admin.polls.flash.error_on_question_removed")
end
redirect_to admin_poll_path(@poll), notice: notice
end
def search_questions
@questions = ::Poll::Question.where("poll_id IS ? OR poll_id != ?", nil, @poll.id).search(search: @search).order(title: :asc)
respond_to do |format|
format.js
end
end
private
def load_geozones

View File

@@ -56,7 +56,7 @@ module Abilities
can [:index, :create, :edit, :update, :destroy], Geozone
can [:read, :create, :update, :destroy, :add_question, :remove_question, :search_booths, :search_questions, :search_officers], Poll
can [:read, :create, :update, :destroy, :add_question, :search_booths, :search_officers], Poll
can [:read, :create, :update, :destroy, :available], Poll::Booth
can [:search, :create, :index, :destroy], ::Poll::Officer
can [:create, :destroy], ::Poll::BoothAssignment

View File

@@ -14,15 +14,15 @@
<div class="tabs-content" data-tabs-content="booths-tabs">
<ul class="tabs" data-tabs id="booths-tabs">
<li class="tabs-title is-active">
<li class="tabs-title">
<%= link_to t("admin.poll_booth_assignments.show.officers"), "#tab-officers" %>
</li>
<li class="tabs-title">
<li class="tabs-title is-active">
<%= link_to t("admin.poll_booth_assignments.show.recounts"), "#tab-recounts" %>
</li>
</ul>
<div class="tabs-panel is-active" id="tab-officers">
<div class="tabs-panel" id="tab-officers">
<% if @booth_assignment.officers.empty? %>
<div class="callout primary margin-top">
<%= t("admin.poll_booth_assignments.show.no_officers") %>
@@ -43,7 +43,7 @@
<% end %>
</div>
<div class="tabs-panel" id="tab-recounts">
<div class="tabs-panel is-active" id="tab-recounts">
<h3><%= t("admin.poll_booth_assignments.show.recounts_list") %></h3>
<table id="totals">

View File

@@ -6,11 +6,13 @@
<%= booth.location %>
</td>
<td class="text-right">
<%= link_to t("admin.booths.booth.shifts"),
new_admin_booth_shift_path(booth),
class: "button hollow" %>
<%= link_to t("admin.actions.edit"),
edit_admin_booth_path(booth),
class: "button hollow" %>
<% if controller_name == "shifts" || controller_name == "booths" && action_name == "available" %>
<%= link_to t("admin.booths.booth.shifts"),
new_admin_booth_shift_path(booth),
class: "button hollow" %>
<%= link_to t("admin.actions.edit"),
edit_admin_booth_path(booth),
class: "button hollow" %>
<% end %>
</td>
</tr>
</tr>

View File

@@ -1,7 +1,8 @@
<h2 class="inline-block"><%= t("admin.booths.index.title") %></h2>
<%= link_to t("admin.booths.index.add_booth"), new_admin_booth_path,
class: "button success float-right" %>
<% if controller_name == "booths" && action_name != "available" %>
<%= link_to t("admin.booths.index.add_booth"), new_admin_booth_path, class: "button success float-right" %>
<% end %>
<% if @booths.empty? %>
<div class="callout primary">

View File

@@ -12,29 +12,19 @@
<tr>
<th><%= t("admin.poll_officer_assignments.index.table_name") %></th>
<th><%= t("admin.poll_officer_assignments.index.table_email") %></th>
<th class="text-center"><%= t("admin.polls.show.table_assignment") %></th>
</tr>
</thead>
<tbody>
<% @officers.each do |user| %>
<tr>
<td>
<%= user.name %>
<strong>
<%= link_to user.name, by_officer_admin_poll_officer_assignments_path(@poll, officer_id: user.id) %>
</strong>
</td>
<td>
<%= user.email %>
</td>
<td class="text-center">
<% if @poll.officer_ids.include?(user.poll_officer.id) %>
<%= link_to t("admin.poll_officer_assignments.index.edit_officer_assignments"),
by_officer_admin_poll_officer_assignments_path(@poll, officer_id: user.poll_officer.id),
class: "button hollow alert" %>
<% else %>
<%= link_to t("admin.poll_officer_assignments.index.add_officer_assignments"),
by_officer_admin_poll_officer_assignments_path(@poll, officer_id: user.poll_officer.id),
class: "button hollow" %>
<% end %>
</td>
</tr>
<% end %>
</tbody>

View File

@@ -27,30 +27,4 @@
<% end %>
</tbody>
</table>
<h3><%= t("admin.poll_officer_assignments.by_officer.total_recounts") %></h3>
<table id="total_recount_list" class="fixed">
<thead>
<tr>
<th><%= t("admin.poll_officer_assignments.by_officer.date") %></th>
<th><%= t("admin.poll_officer_assignments.by_officer.booth") %></th>
<th class="text-right"><%= t("admin.poll_officer_assignments.by_officer.total_recount") %></th>
</tr>
</thead>
<tbody>
<% @officer_assignments.each do |officer_assignment| %>
<tr id="total_recount_<%= officer_assignment.date.to_date.strftime('%Y%m%d') %>">
<td><%= l(officer_assignment.date.to_date) %></td>
<td><%= booth_name_with_location(officer_assignment.booth_assignment.booth) %></td>
<td class="text-right">
<% if officer_assignment.recounts.any? %>
<%= officer_assignment.recounts.to_a.sum(&:total_amount) %>
<% else %>
<span>-</span>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% end %>

View File

@@ -16,7 +16,7 @@
<td class="text-right">
<% if officer.persisted? %>
<%= link_to t('admin.poll_officers.officer.delete'),
admin_poll_officer_path(officer),
admin_officer_path(officer),
method: :delete,
class: "button hollow alert" %>
<% else %>

View File

@@ -9,7 +9,6 @@
<thead>
<tr>
<th><%= t('admin.polls.show.table_title') %></th>
<th class="text-right"><%= t('admin.polls.show.table_assignment') %></th>
</tr>
</thead>
<% @poll.questions.each do |question| %>
@@ -19,12 +18,6 @@
<%= link_to question.title, admin_question_path(question) %>
</strong>
</td>
<td class="text-right">
<%= link_to t('admin.polls.show.remove_question'),
remove_question_admin_poll_path(poll_id: @poll.id, question_id: question.id),
class: "button hollow alert",
method: :patch %>
</td>
</tr>
<% end %>
</table>

View File

@@ -1,17 +0,0 @@
<div class="row">
<div class="small-12 medium-6 column">
<%= form_tag(search_questions_admin_poll_path(@poll), method: :get, remote: true) do |f| %>
<div class="input-group">
<%= text_field_tag :search,
@search,
placeholder: t("admin.shared.poll_questions_search.placeholder"), id: "search-questions" %>
<div class="input-group-button">
<%= submit_tag t("admin.shared.poll_questions_search.button"), class: "button" %>
</div>
</div>
<% end %>
</div>
</div>
<div id="search-questions-results"></div>

View File

@@ -1,33 +0,0 @@
<% if @questions.blank? %>
<div class="callout alert margin-bottom">
<%= t('admin.shared.no_search_results') %>
</div>
<% else %>
<h3><%= t('admin.shared.search_results') %></h3>
<% end %>
<% if @questions.any? %>
<table>
<thead>
<tr>
<th><%= t("admin.polls.show.table_name") %></th>
<th class="text-center"><%= t("admin.polls.show.table_assignment") %></th>
</tr>
</thead>
<tbody>
<% @questions.each do |question| %>
<tr>
<td>
<%= question.title %>
</td>
<td class="text-center">
<%= link_to t("admin.polls.show.add_question"),
add_question_admin_poll_path(poll_id: @poll.id, question_id: question.id),
method: :patch,
class: "button hollow" %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% end %>

View File

@@ -1 +0,0 @@
$("#search-questions-results").html("<%= j render 'search_questions_results' %>");

View File

@@ -3,6 +3,5 @@
<div id="poll-resources">
<%= render "subnav" %>
<%= render "search_questions" %>
<%= render "questions" %>
</div>

View File

@@ -55,7 +55,5 @@
<a href="<%= @question.documents.first.attachment.url %>"><%= @question.documents.first.title %></a>
</p>
<% end %>
<%= link_to t("admin.questions.show.preview"), question_path(@question) %>
</div>
</div>

View File

@@ -489,15 +489,11 @@ en:
no_officers: "There are no officers assigned to this poll."
table_name: "Name"
table_email: "Email"
add_officer_assignments: "Add shifts as officer"
edit_officer_assignments: "Edit officing shifts"
by_officer:
date: "Date"
booth: "Booth"
assignments: "Officing shifts in this poll"
no_assignments: "This user has no officing shifts in this poll."
total_recounts: "Total recounts"
total_recount: "Total recount (by officer)"
poll_shifts:
new:
add_shift: "Add shift"
@@ -570,16 +566,10 @@ en:
results_tab: Results
no_questions: "There are no questions assigned to this poll."
questions_title: "List of questions"
remove_question: "Remove question from poll"
add_question: "Include question"
table_title: "Title"
table_assignment: "Assignment"
table_name: "Name"
flash:
question_added: "Question added to this poll"
error_on_question_added: "Question could not be assigned to this poll"
question_removed: "Question removed from this poll"
error_on_question_removed: "Question could not be removed from this poll"
questions:
index:
title: "Questions"
@@ -606,7 +596,6 @@ en:
description: Description
video_url: External video
documents: Documents (1)
preview: View on website
recounts:
index:
title: "Recounts"

View File

@@ -489,15 +489,11 @@ es:
no_officers: "No hay presidentes de mesa asignados a esta votación."
table_name: "Nombre"
table_email: "Email"
add_officer_assignments: "Añadir turnos como presidente de mesa"
edit_officer_assignments: "Editar turnos"
by_officer:
date: "Fecha"
booth: "Urna"
assignments: "Turnos como presidente de mesa en esta votación"
no_assignments: "No tiene turnos como presidente de mesa en esta votación."
total_recounts: "Recuentos totales"
total_recount: "Recuento total (presidente de mesa)"
poll_shifts:
new:
add_shift: "Añadir turno"
@@ -570,16 +566,10 @@ es:
results_tab: Resultados
no_questions: "No hay preguntas asignadas a esta votación."
questions_title: "Listado de preguntas asignadas"
remove_question: "Desasignar pregunta"
add_question: "Incluir pregunta"
table_title: "Título"
table_assignment: "Asignación"
table_name: "Nombre"
flash:
question_added: "Pregunta añadida a esta votación"
error_on_question_added: "No se pudo asignar la pregunta"
question_removed: "Pregunta eliminada de esta votación"
error_on_question_removed: "No se pudo quitar la pregunta"
questions:
index:
title: "Preguntas ciudadanas"
@@ -606,7 +596,6 @@ es:
description: Descripción
video_url: Video externo
documents: Documentos (1)
preview: Ver en la web
recounts:
index:
title: "Recuentos"

View File

@@ -273,9 +273,7 @@ Rails.application.routes.draw do
scope module: :poll do
resources :polls do
get :search_questions, on: :member
patch :add_question, on: :member
patch :remove_question, on: :member
resources :booth_assignments, only: [:index, :show, :create, :destroy] do
get :search_booths, on: :collection

View File

@@ -87,9 +87,11 @@ feature 'Admin booths' do
end
scenario "Edit" do
poll = create(:poll, :current)
booth = create(:poll_booth)
assignment = create(:poll_booth_assignment, poll: poll, booth: booth)
visit admin_booths_path
visit available_admin_booths_path
within("#booth_#{booth.id}") do
click_link "Edit"
@@ -109,4 +111,4 @@ feature 'Admin booths' do
end
end
end
end

View File

@@ -181,54 +181,6 @@ feature 'Admin polls' do
expect(page).to_not have_content "There are no questions assigned to this poll"
end
scenario 'Add question to poll', :js do
poll = create(:poll)
question = create(:poll_question, title: 'Should we rebuild the city?')
visit admin_poll_path(poll)
expect(page).to have_content 'Questions (0)'
expect(page).to have_content 'There are no questions assigned to this poll'
fill_in 'search-questions', with: 'rebuild'
click_button 'Search'
within('#search-questions-results') do
click_link 'Include question'
end
expect(page).to have_content 'Question added to this poll'
visit admin_poll_path(poll)
expect(page).to have_content 'Questions (1)'
expect(page).to_not have_content 'There are no questions assigned to this poll'
expect(page).to have_content question.title
end
scenario 'Remove question from poll', :js do
poll = create(:poll)
question = create(:poll_question, poll: poll)
visit admin_poll_path(poll)
expect(page).to have_content 'Questions (1)'
expect(page).to_not have_content 'There are no questions assigned to this poll'
expect(page).to have_content question.title
within("#poll_question_#{question.id}") do
click_link 'Remove question from poll'
end
expect(page).to have_content 'Question removed from this poll'
visit admin_poll_path(poll)
expect(page).to have_content 'Questions (0)'
expect(page).to have_content 'There are no questions assigned to this poll'
expect(page).to_not have_content question.title
end
end
end

View File

@@ -31,13 +31,14 @@ feature 'Admin shifts' do
end
scenario "Create Vote Collection Shift and Recount & Scrutiny Shift on same date", :js do
poll = create(:poll)
poll = create(:poll, :current)
booth = create(:poll_booth)
assignment = create(:poll_booth_assignment, poll: poll, booth: booth)
officer = create(:poll_officer)
vote_collection_dates = (poll.starts_at.to_date..poll.ends_at.to_date).to_a.map { |date| I18n.l(date, format: :long) }
recount_scrutiny_dates = (poll.ends_at.to_date..poll.ends_at.to_date + 1.week).to_a.map { |date| I18n.l(date, format: :long) }
visit admin_booths_path
visit available_admin_booths_path
within("#booth_#{booth.id}") do
click_link "Manage shifts"
@@ -61,7 +62,7 @@ feature 'Admin shifts' do
expect(page).to have_content(officer.name)
end
visit admin_booths_path
visit available_admin_booths_path
within("#booth_#{booth.id}") do
click_link "Manage shifts"
@@ -89,11 +90,12 @@ feature 'Admin shifts' do
end
scenario "Error on create", :js do
poll = create(:poll)
poll = create(:poll, :current)
booth = create(:poll_booth)
assignment = create(:poll_booth_assignment, poll: poll, booth: booth)
officer = create(:poll_officer)
visit admin_booths_path
visit available_admin_booths_path
within("#booth_#{booth.id}") do
click_link "Manage shifts"
@@ -108,13 +110,14 @@ feature 'Admin shifts' do
end
scenario "Destroy" do
poll = create(:poll)
poll = create(:poll, :current)
booth = create(:poll_booth)
assignment = create(:poll_booth_assignment, poll: poll, booth: booth)
officer = create(:poll_officer)
shift = create(:poll_shift, officer: officer, booth: booth)
visit admin_booths_path
visit available_admin_booths_path
within("#booth_#{booth.id}") do
click_link "Manage shifts"