adds admin interface for poll questions

This commit is contained in:
rgarcia
2016-11-17 09:30:42 +01:00
parent bd1a0cf1ff
commit d9ad658758
19 changed files with 263 additions and 29 deletions

View File

@@ -0,0 +1,57 @@
class Admin::Poll::QuestionsController < Admin::BaseController
load_and_authorize_resource :question, class: 'Poll::Question'
before_action :load_geozones, only: [:new, :create, :edit, :update]
def index
@questions = @questions.page(params[:page])
end
def new
@question.valid_answers = I18n.t('questions.default_valid_answers')
proposal = Proposal.find(params[:proposal_id]) if params[:proposal_id].present?
@question.copy_attributes_from_proposal(proposal)
end
def create
@question.author = @question.proposal.try(:author) || current_user
if @question.save
redirect_to question_path(@question)
else
render :new
end
end
def edit
end
def update
if @question.update(question_params)
redirect_to question_path(@question), notice: t("flash.actions.save_changes.notice")
else
render :edit
end
end
def destroy
if @question.destroy
notice = "Question destroyed succesfully"
else
notice = t("flash.actions.destroy.error")
end
redirect_to admin_questions_path, notice: notice
end
private
def load_geozones
@geozones = Geozone.all.order(:name)
end
def question_params
params.require(:poll_question).permit(:title, :question, :summary, :description, :proposal_id, :valid_answers, :geozone_ids => [])
end
end

View File

@@ -1,7 +1,7 @@
class Polls::QuestionsController < ApplicationController
load_and_authorize_resource :poll
load_and_authorize_resource :question, class: 'Poll::Question', through: :poll
load_and_authorize_resource :question, class: 'Poll::Question'#, through: :poll
has_filters %w{opened expired incoming}
has_orders %w{most_voted newest oldest}, only: :show

View File

@@ -43,6 +43,10 @@ module Abilities
can :manage, Annotation
can [:read, :update, :destroy, :summary], SpendingProposal
can [:read, :create, :update], Poll::Question
can :destroy, Poll::Question # , comments_count: 0, votes_up: 0
can [:search, :edit, :update, :create, :index, :destroy], Banner
can [:manage], Poll

View File

@@ -35,6 +35,14 @@
</li>
<% end %>
<% if feature?(:polls) %>
<li <%= "class=active" if controller_name == "poll_questions" %>>
<%= link_to admin_questions_path do %>
<span class="icon-checkmark-circle"></span><%= t("admin.menu.poll_questions") %>
<% end %>
</li>
<% end %>
<li <%= "class=active" if controller_name == "banners" %>>
<%= link_to admin_banners_path do %>
<span class="icon-eye"></span><%= t("admin.menu.banner") %>

View File

@@ -0,0 +1,43 @@
<%= form_for(@question, url: form_url) do |f| %>
<%= render 'shared/errors', resource: @question %>
<%= f.hidden_field :proposal_id %>
<div class="row">
<div class="small-12 column">
<%= f.text_field :title, maxlength: Poll::Question.title_max_length %>
<%= f.text_field :question, maxlength: Poll::Question.question_max_length %>
<%= f.text_field :valid_answers %>
<%= f.text_area :summary, rows: 4, maxlength: 200 %>
<div class="ckeditor">
<%= f.cktext_area :description,
maxlength: Poll::Question.description_max_length,
ckeditor: { language: I18n.locale } %>
</div>
<div class="row">
<%= f.collection_check_boxes(:geozone_ids, @geozones, :id, :name) do |b| %>
<div class="small-6 medium-3 column">
<%= b.label do %>
<%= b.check_box + b.text %>
<% end %>
</div>
<% end %>
</div>
<%# TODO include all link %>
<div class="row">
<div class="actions small-12 medium-4 column margin-top">
<%= f.submit(class: "button expanded", value: t("shared.save")) %>
</div>
</div>
</div>
</div>
<% end %>

View File

@@ -0,0 +1,5 @@
<%= render "shared/back_link" %>
<h2><%= t("admin.questions.edit.title") %></h2>
<%= render "form", form_url: admin_question_path(@question) %>

View File

@@ -0,0 +1,22 @@
<h2 class="inline-block"><%= t('admin.questions.index.title') %></h2>
<%= link_to t('admin.questions.index.create'), new_admin_question_path,
class: "button success float-right" %>
<% if @questions.count == 0 %>
<div class="callout primary">
<%= t('admin.questions.index.no_questions') %>
</div>
<% else %>
<table>
<% @questions.each do |question| %>
<tr id="<%= dom_id(question) %>">
<td><%= link_to question.title, question_path(question) %></td>
<td class="text-right">
<%= link_to t('shared.edit'), edit_admin_question_path(question), class: "button hollow" %>
<%= link_to t('shared.delete'), admin_question_path(question), class: "button hollow alert", method: :delete %>
</td>
</tr>
<% end %>
</table>
<% end %>

View File

@@ -0,0 +1,5 @@
<%= render "shared/back_link" %>
<h2><%= t("admin.questions.new.title") %></h2>
<%= render "form", form_url: admin_questions_path %>

View File

@@ -69,6 +69,13 @@ es:
external_url: "Enlace a documentación adicional"
geozone_id: "Ámbito de actuación"
title: "Título"
poll/question:
title: "Título"
question: "Pregunta"
valid_answers: "Posibles respuestas"
summary: "Resumen"
description: "Descripción"
external_url: "Enlace a documentación adicional"
errors:
models:
user:

View File

@@ -95,6 +95,7 @@ en:
activity: Moderator activity
admin: Admin menu
banner: Manage banners
poll_questions: Poll questions
debate_topics: Debate topics
hidden_comments: Hidden comments
hidden_debates: Hidden debates
@@ -175,6 +176,15 @@ en:
name: "Name"
location: "Location"
officers: "Officers"
questions:
index:
title: "Questions"
create: "Create question"
no_enquiries: "There are no questions."
edit:
title: "Edit Question"
new:
title: "Create Question"
booths:
index:
title: "List of booths"

View File

@@ -96,6 +96,7 @@ es:
admin: Menú de administración
banner: Gestionar banners
debate_topics: Temas de debate
poll_questions: Preguntas ciudadanas
hidden_comments: Comentarios ocultos
hidden_debates: Debates ocultos
hidden_proposals: Propuestas ocultas
@@ -175,6 +176,15 @@ es:
name: "Nombre"
location: "Ubicación"
officers: "Presidentes de mesa"
questions:
index:
title: "Preguntas ciudadanas"
create: "Crear pregunta ciudadana"
no_enquiries: "No hay ninguna pregunta ciudadana."
edit:
title: "Editar pregunta ciudadana"
new:
title: "Crear pregunta ciudadana"
booths:
index:
title: "Lista de urnas"

View File

@@ -210,7 +210,7 @@ en:
open_data: Open data
open_gov: Open government
proposals: Proposals
proposal_ballot: Voting
polls: Voting
see_all: See proposals
spending_proposals: Spending proposals
legislation:
@@ -385,19 +385,40 @@ en:
cant_answer_incoming: "This poll has not yet started."
cant_answer_expired: "This poll has finished."
cant_answer_wrong_geozone: "The following questions are not available in your geozone."
poll_questions:
questions:
create_question: "Create question"
default_valid_answers: "Yes, No"
proposal_ballots:
title: "Votings"
description_html: "The following citizen proposals that have reached the <strong>required supports</strong> and will be voted."
date_title: "Dates of participation"
date: "Soon we'll announce the date of vote these proposals."
successfull: "This proposal has reached the required supports and will be voted in the %{voting}."
voting: "next voting"
featured_title: "#NextVoting"
nothing_to_vote: "There is nothing to vote at the moment."
info: "New proposals that have reached the voting phase."
button: "I want to decide"
index:
filters:
opened: "Open"
incoming: "Incoming"
expired: "Expired"
title: "Enquiries"
description_html: "The following citizen proposals that have reached the <strong>required supports</strong> and will be voted."
dates: "From %{open_at} to %{closed_at}"
no_enquiries_opened: "There aren't opened enquiries."
no_enquiries_expired: "There aren't expired enquiries."
no_enquiries_incoming: "There aren't incoming enquiries."
show:
original_proposal: "Original proposal"
author: "Created by"
dates_title: "Participation dates"
dates: "From %{open_at} to %{closed_at}"
external_url: "Additional documentation"
more_info: "More information"
not_logged_in: "You must %{signin} or %{signup} to participate."
signin: Sign in
signup: Sign up
cant_answer_verify_html: "You must %{verify_link} in order to answer."
verify_link: "verify your account"
cant_answer_incoming: "This question has not yet started."
cant_answer_expired: "This question has finished."
cant_answer_wrong_geozone: "This question is not available on your geozone."
vote_answer: "Vote %{answer}"
voted: "You have voted %{answer}"
banner:
featured_title: "#NextVoting"
info: "New proposals that have reached the voting phase."
proposal_notifications:
new:
title: "Send message"
@@ -409,6 +430,12 @@ en:
show:
back: "Go back to my activity"
shared:
edit: 'Edit'
save: 'Save'
delete: 'Delete'
comments:
title: 'Comments'
login_to_comment: 'You must %{signin} or %{signup} to leave a comment.'
advanced_search:
author_type: 'By author category'
author_type_blank: 'Select a category'

View File

@@ -210,7 +210,7 @@ es:
open_data: Datos abiertos
open_gov: Gobierno %{open}
proposals: Propuestas
proposal_ballot: Votaciones
poll_questions: Votaciones
see_all: Ver propuestas
spending_proposals: Presupuestos ciudadanos
legislation:
@@ -375,17 +375,40 @@ es:
update:
form:
submit_button: Guardar cambios
proposal_ballots:
title: "Votaciones"
description_html: "Las siguientes propuestas ciudadanas han alcanzado el <strong>número de apoyos necesarios</strong> y pasarán a votación."
date_title: "Fechas de participación"
date: "En breve anunciaremos la fecha de votación de estas propuestas."
successfull: "Esta propuesta ha alcanzado los apoyos necesarios y pasará a la %{voting}."
voting: "próxima votación"
featured_title: "#PróximaVotación"
nothing_to_vote: "No hay nada que votar en este momento."
info: "Nuevas propuestas ciudadanas han llegado a la fase de votación."
button: "Quiero decidir"
questions:
create_enquiry: "Crear votación"
default_valid_answers: "Sí, No"
index:
filters:
opened: "Abiertas"
incoming: "Próximamente"
expired: "Terminadas"
title: "Votaciones"
description_html: "Las siguientes propuestas ciudadanas han alcanzado el <strong>número de apoyos necesarios</strong> y pasarán a votación."
dates: "Desde el %{open_at} hasta el %{closed_at}"
no_enquiries_opened: "No hay votaciones abiertas."
no_enquiries_expired: "No hay votaciones terminadas."
no_enquiries_incoming: "No hay votaciones próximamente."
show:
original_proposal: "Propuesta original"
author: "Creado por"
dates_title: "Fechas de participación"
dates: "Desde el %{open_at} hasta el %{closed_at}"
external_url: "Documentación adicional"
more_info: "Más información"
not_logged_in: "Necesitas %{signin} o %{signup} para participar."
signin: iniciar sesión
signup: registrarte
cant_answer_verify_html: "Por favor %{verify_link} para poder responder."
verify_link: "verifica tu cuenta"
cant_answer_incoming: "Esta votación todavía no ha comenzado."
cant_answer_expired: "Esta votación ha terminado."
cant_answer_wrong_geozone: "Esta votación no está disponible en tu zona."
vote_answer: "Votar %{answer}"
voted: "Has votado %{answer}"
banner:
featured_title: "#PróximaVotación"
info: "Nuevas propuestas ciudadanas han llegado a la fase de votación."
proposal_notifications:
new:
title: "Enviar mensaje"
@@ -397,6 +420,12 @@ es:
show:
back: "Volver a mi actividad"
shared:
edit: 'Editar'
save: 'Guardar'
delete: 'Borrar'
comments:
title: 'Comentarios'
login_to_comment: 'Necesitas %{signin} o %{signup} para comentar.'
advanced_search:
author_type: 'Por categoría de autor'
author_type_blank: 'Elige una categoría'

View File

@@ -21,4 +21,5 @@ en:
proposal: "Proposal updated successfully."
spending_proposal: "Investment project updated succesfully."
destroy:
spending_proposal: "Spending proposal deleted succesfully."
spending_proposal: "Spending proposal deleted succesfully."
error: "Could not delete"

View File

@@ -21,4 +21,5 @@ es:
poll_booth: "Urna actualizada correctamente."
spending_proposal: "Propuesta de inversión actualizada correctamente."
destroy:
spending_proposal: "Propuesta de inversión eliminada."
spending_proposal: "Propuesta de inversión eliminada."
error: "No se pudo borrar"

View File

@@ -27,6 +27,8 @@ en:
facebook_login: Facebook login
google_login: Google login
debates: Debates
polls: Polls
spending_proposals: Investment projects
spending_proposal_features:
voting_allowed: Voting on investment projects

View File

@@ -27,6 +27,7 @@ es:
facebook_login: Registro con Facebook
google_login: Registro con Google
debates: Debates
polls: Votaciones
spending_proposals: Propuestas de inversión
spending_proposal_features:
voting_allowed: Votaciones sobre propuestas de inversión.

View File

@@ -84,7 +84,7 @@ Rails.application.routes.draw do
end
resources :polls, only: [:show, :index] do
resources :questions, only: [:show], controller: 'polls/questions' do
resources :questions, only: [:show], controller: 'polls/questions', shallow: true do
post :answer, on: :member
end
end
@@ -190,6 +190,7 @@ Rails.application.routes.draw do
resources :polls do
resources :booths
end
resources :questions, except: :show
end
resources :verifications, controller: :verifications, only: :index do

View File

@@ -25,6 +25,7 @@ Setting.create(key: 'url', value: 'http://localhost:3000')
Setting.create(key: 'org_name', value: 'Consul')
Setting.create(key: 'place_name', value: 'City')
Setting.create(key: 'feature.debates', value: "true")
Setting.create(key: 'feature.polls', value: "true")
Setting.create(key: 'feature.spending_proposals', value: "true")
Setting.create(key: 'feature.spending_proposal_features.voting_allowed', value: "true")
Setting.create(key: 'feature.twitter_login', value: "true")