diff --git a/app/controllers/admin/poll/questions_controller.rb b/app/controllers/admin/poll/questions_controller.rb
new file mode 100644
index 000000000..25b14251c
--- /dev/null
+++ b/app/controllers/admin/poll/questions_controller.rb
@@ -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
\ No newline at end of file
diff --git a/app/controllers/polls/questions_controller.rb b/app/controllers/polls/questions_controller.rb
index 07d7aa28f..4ab83332b 100644
--- a/app/controllers/polls/questions_controller.rb
+++ b/app/controllers/polls/questions_controller.rb
@@ -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
diff --git a/app/models/abilities/administrator.rb b/app/models/abilities/administrator.rb
index 79999cd04..14cf86a30 100644
--- a/app/models/abilities/administrator.rb
+++ b/app/models/abilities/administrator.rb
@@ -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
diff --git a/app/views/admin/_menu.html.erb b/app/views/admin/_menu.html.erb
index 11e46814d..45c450a06 100644
--- a/app/views/admin/_menu.html.erb
+++ b/app/views/admin/_menu.html.erb
@@ -35,6 +35,14 @@
<% end %>
+ <% if feature?(:polls) %>
+
>
+ <%= link_to admin_questions_path do %>
+ <%= t("admin.menu.poll_questions") %>
+ <% end %>
+
+ <% end %>
+
>
<%= link_to admin_banners_path do %>
<%= t("admin.menu.banner") %>
diff --git a/app/views/admin/poll/questions/_form.html.erb b/app/views/admin/poll/questions/_form.html.erb
new file mode 100644
index 000000000..32f16c773
--- /dev/null
+++ b/app/views/admin/poll/questions/_form.html.erb
@@ -0,0 +1,43 @@
+<%= form_for(@question, url: form_url) do |f| %>
+
+ <%= render 'shared/errors', resource: @question %>
+
+ <%= f.hidden_field :proposal_id %>
+
+
+
+
+ <%= 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 %>
+
+
+ <%= f.cktext_area :description,
+ maxlength: Poll::Question.description_max_length,
+ ckeditor: { language: I18n.locale } %>
+
+
+
+ <%= f.collection_check_boxes(:geozone_ids, @geozones, :id, :name) do |b| %>
+
+ <%= b.label do %>
+ <%= b.check_box + b.text %>
+ <% end %>
+
+ <% end %>
+
+ <%# TODO include all link %>
+
+
+
+ <%= f.submit(class: "button expanded", value: t("shared.save")) %>
+
+
+
+
+
+<% end %>
\ No newline at end of file
diff --git a/app/views/admin/poll/questions/edit.html.erb b/app/views/admin/poll/questions/edit.html.erb
new file mode 100644
index 000000000..6c4d24adf
--- /dev/null
+++ b/app/views/admin/poll/questions/edit.html.erb
@@ -0,0 +1,5 @@
+<%= render "shared/back_link" %>
+
+<%= t("admin.questions.edit.title") %>
+
+<%= render "form", form_url: admin_question_path(@question) %>
\ No newline at end of file
diff --git a/app/views/admin/poll/questions/index.html.erb b/app/views/admin/poll/questions/index.html.erb
new file mode 100644
index 000000000..eb0698780
--- /dev/null
+++ b/app/views/admin/poll/questions/index.html.erb
@@ -0,0 +1,22 @@
+<%= t('admin.questions.index.title') %>
+
+<%= link_to t('admin.questions.index.create'), new_admin_question_path,
+ class: "button success float-right" %>
+
+<% if @questions.count == 0 %>
+
+ <%= t('admin.questions.index.no_questions') %>
+
+<% else %>
+
+ <% @questions.each do |question| %>
+
+ | <%= link_to question.title, question_path(question) %> |
+
+ <%= 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 %>
+ |
+
+ <% end %>
+
+<% end %>
\ No newline at end of file
diff --git a/app/views/admin/poll/questions/new.html.erb b/app/views/admin/poll/questions/new.html.erb
new file mode 100644
index 000000000..830492d6d
--- /dev/null
+++ b/app/views/admin/poll/questions/new.html.erb
@@ -0,0 +1,5 @@
+<%= render "shared/back_link" %>
+
+<%= t("admin.questions.new.title") %>
+
+<%= render "form", form_url: admin_questions_path %>
\ No newline at end of file
diff --git a/config/locales/activerecord.es.yml b/config/locales/activerecord.es.yml
index a439a6c5c..8ce255739 100644
--- a/config/locales/activerecord.es.yml
+++ b/config/locales/activerecord.es.yml
@@ -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:
diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml
index 1d80aa4cd..c86f57266 100755
--- a/config/locales/admin.en.yml
+++ b/config/locales/admin.en.yml
@@ -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"
diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml
index cce743dcc..b579bfec5 100644
--- a/config/locales/admin.es.yml
+++ b/config/locales/admin.es.yml
@@ -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"
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 7c9abd2b9..74f267bc3 100755
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -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 required supports 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 required supports 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'
diff --git a/config/locales/es.yml b/config/locales/es.yml
index 80541466b..c8ac24ed2 100755
--- a/config/locales/es.yml
+++ b/config/locales/es.yml
@@ -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 número de apoyos necesarios 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 número de apoyos necesarios 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'
diff --git a/config/locales/responders.en.yml b/config/locales/responders.en.yml
index 68d77b0d2..ffe883d6c 100755
--- a/config/locales/responders.en.yml
+++ b/config/locales/responders.en.yml
@@ -21,4 +21,5 @@ en:
proposal: "Proposal updated successfully."
spending_proposal: "Investment project updated succesfully."
destroy:
- spending_proposal: "Spending proposal deleted succesfully."
\ No newline at end of file
+ spending_proposal: "Spending proposal deleted succesfully."
+ error: "Could not delete"
\ No newline at end of file
diff --git a/config/locales/responders.es.yml b/config/locales/responders.es.yml
index 54c4c7035..4c9087557 100644
--- a/config/locales/responders.es.yml
+++ b/config/locales/responders.es.yml
@@ -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."
\ No newline at end of file
+ spending_proposal: "Propuesta de inversión eliminada."
+ error: "No se pudo borrar"
\ No newline at end of file
diff --git a/config/locales/settings.en.yml b/config/locales/settings.en.yml
index 0de4e5feb..8d4c55b5e 100755
--- a/config/locales/settings.en.yml
+++ b/config/locales/settings.en.yml
@@ -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
+
diff --git a/config/locales/settings.es.yml b/config/locales/settings.es.yml
index 05ba6c076..e6736e982 100644
--- a/config/locales/settings.es.yml
+++ b/config/locales/settings.es.yml
@@ -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.
\ No newline at end of file
diff --git a/config/routes.rb b/config/routes.rb
index 0d227717b..2b0965314 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -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
diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb
index 2c2f106ee..8b4693ea0 100644
--- a/db/dev_seeds.rb
+++ b/db/dev_seeds.rb
@@ -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")