Merge pull request #4990 from consul/improve-polls
Refactor admin poll section
This commit is contained in:
@@ -1,18 +1,15 @@
|
||||
<%= back_link_to %>
|
||||
<%= back_link_to admin_question_path(@answer.question) %>
|
||||
|
||||
<h2><%= t("admin.questions.show.answers.documents_list") %></h2>
|
||||
|
||||
<ul class="breadcrumbs">
|
||||
<li><%= @answer.question.title %></li>
|
||||
<li><%= @answer.title %></li>
|
||||
<li><%= answer.question.title %></li>
|
||||
<li><%= answer.title %></li>
|
||||
</ul>
|
||||
|
||||
<div class="poll-question-form">
|
||||
<%= form_for(Poll::Question::Answer.new,
|
||||
url: admin_answer_path(@answer),
|
||||
method: :put) do |f| %>
|
||||
|
||||
<%= render "shared/errors", resource: @answer %>
|
||||
<%= form_for(Poll::Question::Answer.new, url: admin_answer_documents_path(answer)) do |f| %>
|
||||
<%= render "shared/errors", resource: answer %>
|
||||
|
||||
<div class="documents">
|
||||
<%= render "documents/nested_documents", f: f %>
|
||||
@@ -23,14 +20,14 @@
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% if @answer.documents.present? %>
|
||||
<% if answer.documents.present? %>
|
||||
<table>
|
||||
<tr>
|
||||
<th scope="col"><%= t("admin.questions.show.answers.document_title") %></th>
|
||||
<th scope="col"><%= t("admin.questions.show.answers.document_actions") %></th>
|
||||
</tr>
|
||||
|
||||
<% @answer.documents.each do |document| %>
|
||||
<% answer.documents.each do |document| %>
|
||||
<tr>
|
||||
<td>
|
||||
<%= link_to document.title, document.attachment %>
|
||||
@@ -0,0 +1,7 @@
|
||||
class Admin::Poll::Questions::Answers::Documents::IndexComponent < ApplicationComponent
|
||||
attr_reader :answer
|
||||
|
||||
def initialize(answer)
|
||||
@answer = answer
|
||||
end
|
||||
end
|
||||
@@ -4,22 +4,21 @@ class Admin::Poll::PollsController < Admin::Poll::BaseController
|
||||
include ReportAttributes
|
||||
load_and_authorize_resource
|
||||
|
||||
before_action :load_search, only: [:search_booths, :search_officers]
|
||||
before_action :load_geozones, only: [:new, :create, :edit, :update]
|
||||
|
||||
def index
|
||||
@polls = Poll.not_budget.created_by_admin.order(starts_at: :desc)
|
||||
@polls = @polls.not_budget.created_by_admin.order(starts_at: :desc)
|
||||
end
|
||||
|
||||
def show
|
||||
@poll = Poll.find(params[:id])
|
||||
end
|
||||
|
||||
def new
|
||||
end
|
||||
|
||||
def create
|
||||
@poll = Poll.new(poll_params.merge(author: current_user))
|
||||
@poll.author = current_user
|
||||
|
||||
if @poll.save
|
||||
notice = t("flash.actions.create.poll")
|
||||
if @poll.budget.present?
|
||||
@@ -43,18 +42,6 @@ class Admin::Poll::PollsController < Admin::Poll::BaseController
|
||||
end
|
||||
end
|
||||
|
||||
def add_question
|
||||
question = ::Poll::Question.find(params[:question_id])
|
||||
|
||||
if question.present?
|
||||
@poll.questions << question
|
||||
notice = t("admin.polls.flash.question_added")
|
||||
else
|
||||
notice = t("admin.polls.flash.error_on_question_added")
|
||||
end
|
||||
redirect_to admin_poll_path(@poll), notice: notice
|
||||
end
|
||||
|
||||
def booth_assignments
|
||||
@polls = Poll.current.created_by_admin
|
||||
end
|
||||
@@ -85,16 +72,4 @@ class Admin::Poll::PollsController < Admin::Poll::BaseController
|
||||
|
||||
[*attributes, *report_attributes, translation_params(Poll)]
|
||||
end
|
||||
|
||||
def search_params
|
||||
params.permit(:poll_id, :search)
|
||||
end
|
||||
|
||||
def load_search
|
||||
@search = search_params[:search]
|
||||
end
|
||||
|
||||
def resource
|
||||
@poll ||= Poll.find(params[:id])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
class Admin::Poll::Questions::Answers::DocumentsController < Admin::Poll::BaseController
|
||||
include DocumentAttributes
|
||||
|
||||
load_and_authorize_resource :answer, class: "::Poll::Question::Answer"
|
||||
|
||||
def index
|
||||
end
|
||||
|
||||
def create
|
||||
@answer.attributes = documents_params
|
||||
|
||||
if @answer.save
|
||||
redirect_to admin_answer_documents_path(@answer),
|
||||
notice: t("admin.documents.create.success_notice")
|
||||
else
|
||||
render :new
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def documents_params
|
||||
params.require(:poll_question_answer).permit(allowed_params)
|
||||
end
|
||||
|
||||
def allowed_params
|
||||
[documents_attributes: document_attributes]
|
||||
end
|
||||
end
|
||||
@@ -1,7 +1,7 @@
|
||||
class Admin::Poll::Questions::Answers::ImagesController < Admin::Poll::BaseController
|
||||
include ImageAttributes
|
||||
|
||||
before_action :load_answer, except: :destroy
|
||||
load_and_authorize_resource :answer, class: "::Poll::Question::Answer"
|
||||
|
||||
def index
|
||||
end
|
||||
@@ -38,8 +38,4 @@ class Admin::Poll::Questions::Answers::ImagesController < Admin::Poll::BaseContr
|
||||
def allowed_params
|
||||
[:answer_id, images_attributes: image_attributes]
|
||||
end
|
||||
|
||||
def load_answer
|
||||
@answer = ::Poll::Question::Answer.find(params[:answer_id])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
class Admin::Poll::Questions::Answers::VideosController < Admin::Poll::BaseController
|
||||
before_action :load_answer, only: [:index, :new, :create]
|
||||
before_action :load_video, only: [:edit, :update, :destroy]
|
||||
load_and_authorize_resource :answer, class: "::Poll::Question::Answer"
|
||||
load_and_authorize_resource class: "::Poll::Question::Answer::Video", through: :answer
|
||||
|
||||
def index
|
||||
end
|
||||
|
||||
def new
|
||||
@video = ::Poll::Question::Answer::Video.new
|
||||
end
|
||||
|
||||
def create
|
||||
@video = ::Poll::Question::Answer::Video.new(video_params)
|
||||
|
||||
if @video.save
|
||||
redirect_to admin_answer_videos_path(@answer),
|
||||
notice: t("flash.actions.create.poll_question_answer_video")
|
||||
@@ -25,20 +22,16 @@ class Admin::Poll::Questions::Answers::VideosController < Admin::Poll::BaseContr
|
||||
|
||||
def update
|
||||
if @video.update(video_params)
|
||||
redirect_to admin_answer_videos_path(@video.answer_id),
|
||||
notice: t("flash.actions.save_changes.notice")
|
||||
redirect_to admin_answer_videos_path(@answer), notice: t("flash.actions.save_changes.notice")
|
||||
else
|
||||
render :edit
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
notice = if @video.destroy
|
||||
t("flash.actions.destroy.poll_question_answer_video")
|
||||
else
|
||||
t("flash.actions.destroy.error")
|
||||
end
|
||||
redirect_back(fallback_location: (request.referer || root_path), notice: notice)
|
||||
@video.destroy!
|
||||
notice = t("flash.actions.destroy.poll_question_answer_video")
|
||||
redirect_to admin_answer_videos_path(@answer), notice: notice
|
||||
end
|
||||
|
||||
private
|
||||
@@ -48,14 +41,6 @@ class Admin::Poll::Questions::Answers::VideosController < Admin::Poll::BaseContr
|
||||
end
|
||||
|
||||
def allowed_params
|
||||
[:title, :url, :answer_id]
|
||||
end
|
||||
|
||||
def load_answer
|
||||
@answer = ::Poll::Question::Answer.find(params[:answer_id])
|
||||
end
|
||||
|
||||
def load_video
|
||||
@video = ::Poll::Question::Answer::Video.find(params[:id])
|
||||
[:title, :url]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,19 +1,15 @@
|
||||
class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController
|
||||
include Translatable
|
||||
include DocumentAttributes
|
||||
|
||||
before_action :load_answer, only: [:show, :edit, :update, :documents]
|
||||
|
||||
load_and_authorize_resource :question, class: "::Poll::Question"
|
||||
load_and_authorize_resource class: "::Poll::Question::Answer",
|
||||
through: :question,
|
||||
through_association: :question_answers
|
||||
|
||||
def new
|
||||
@answer = ::Poll::Question::Answer.new
|
||||
end
|
||||
|
||||
def create
|
||||
@answer = ::Poll::Question::Answer.new(answer_params)
|
||||
@question = @answer.question
|
||||
|
||||
if @answer.save
|
||||
redirect_to admin_question_path(@question),
|
||||
notice: t("flash.actions.create.poll_question_answer")
|
||||
@@ -22,27 +18,18 @@ class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
if @answer.update(answer_params)
|
||||
redirect_to admin_question_path(@answer.question),
|
||||
redirect_to admin_question_path(@question),
|
||||
notice: t("flash.actions.save_changes.notice")
|
||||
else
|
||||
render :edit
|
||||
end
|
||||
end
|
||||
|
||||
def documents
|
||||
@documents = @answer.documents
|
||||
|
||||
render "admin/poll/questions/answers/documents"
|
||||
end
|
||||
|
||||
def order_answers
|
||||
::Poll::Question::Answer.order_answers(params[:ordered_list])
|
||||
head :ok
|
||||
@@ -55,18 +42,8 @@ class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController
|
||||
end
|
||||
|
||||
def allowed_params
|
||||
attributes = [:title, :description, :given_order, :question_id,
|
||||
documents_attributes: document_attributes]
|
||||
attributes = [:title, :description, :given_order]
|
||||
|
||||
[*attributes, translation_params(Poll::Question::Answer)]
|
||||
end
|
||||
|
||||
def load_answer
|
||||
@answer = ::Poll::Question::Answer.find(params[:id] || params[:answer_id])
|
||||
end
|
||||
|
||||
def resource
|
||||
load_answer unless @answer
|
||||
@answer
|
||||
end
|
||||
end
|
||||
|
||||
@@ -43,12 +43,8 @@ class Admin::Poll::QuestionsController < Admin::Poll::BaseController
|
||||
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
|
||||
@question.destroy!
|
||||
redirect_to admin_poll_path(@question.poll), notice: t("admin.questions.destroy.notice")
|
||||
end
|
||||
|
||||
private
|
||||
@@ -66,8 +62,4 @@ class Admin::Poll::QuestionsController < Admin::Poll::BaseController
|
||||
def search_params
|
||||
params.permit(:poll_id, :search)
|
||||
end
|
||||
|
||||
def resource
|
||||
@poll_question ||= Poll::Question.find(params[:id])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -83,13 +83,18 @@ module Abilities
|
||||
|
||||
can [:index, :create, :update, :destroy], Geozone
|
||||
|
||||
can [:read, :create, :update, :destroy, :add_question, :search_booths, :search_officers, :booth_assignments], Poll
|
||||
can [:read, :create, :update, :destroy, :booth_assignments], Poll
|
||||
can [:read, :create, :update, :destroy, :available], Poll::Booth
|
||||
can [:search, :create, :index, :destroy], ::Poll::Officer
|
||||
can [:create, :destroy, :manage], ::Poll::BoothAssignment
|
||||
can [:create, :destroy], ::Poll::OfficerAssignment
|
||||
can [:read, :create, :update], Poll::Question
|
||||
can :destroy, Poll::Question
|
||||
can :manage, Poll::Question::Answer
|
||||
can :manage, Poll::Question::Answer::Video
|
||||
can [:create, :destroy], Image do |image|
|
||||
image.imageable_type == "Poll::Question::Answer"
|
||||
end
|
||||
|
||||
can :manage, SiteCustomization::Page
|
||||
can :manage, SiteCustomization::Image
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<%= back_link_to %>
|
||||
<%= back_link_to admin_polls_path %>
|
||||
|
||||
<h2><%= t("admin.polls.edit.title") %></h2>
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<div class="row">
|
||||
<div class="small-12 column">
|
||||
<%= back_link_to %>
|
||||
<%= back_link_to admin_polls_path %>
|
||||
|
||||
<h2><%= t("admin.polls.new.title") %></h2>
|
||||
</div>
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
<%= f.hidden_field :given_order,
|
||||
value: @answer.persisted? ? @answer.given_order : @answer.class.last_position(@answer.question_id || @question.id) + 1 %>
|
||||
|
||||
<%= f.hidden_field :question_id, value: @answer.question_id || @question.id %>
|
||||
|
||||
<div class="row">
|
||||
<%= f.translatable_fields do |translations_form| %>
|
||||
<div class="column end">
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
<%= render Admin::Poll::Questions::Answers::Documents::IndexComponent.new(@answer) %>
|
||||
@@ -1,4 +1,4 @@
|
||||
<%= back_link_to %>
|
||||
<%= back_link_to admin_question_path(@question) %>
|
||||
|
||||
<ul class="breadcrumbs margin-top">
|
||||
<li><%= @answer.title %></li>
|
||||
@@ -10,5 +10,5 @@
|
||||
</h2>
|
||||
|
||||
<div class="poll-question-answer-form">
|
||||
<%= render "form", form_url: admin_answer_path(@answer) %>
|
||||
<%= render "form", form_url: admin_question_answer_path(@question, @answer) %>
|
||||
</div>
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
<div class="poll-question-form">
|
||||
<%= form_for(@answer,
|
||||
url: admin_answer_images_path(@answer),
|
||||
method: :post) do |f| %>
|
||||
<%= form_for(@answer, url: admin_answer_images_path(@answer), method: :post) do |f| %>
|
||||
<%= render "shared/errors", resource: @answer %>
|
||||
|
||||
<div class="images">
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<%= back_link_to %>
|
||||
<%= back_link_to admin_question_path(@question) %>
|
||||
|
||||
<ul class="breadcrumbs margin-top">
|
||||
<li><%= @question.title %></li>
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
<%= back_link_to %>
|
||||
|
||||
<%= link_to t("admin.answers.show.edit"), edit_admin_answer_path(@answer),
|
||||
class: "button hollow float-right" %>
|
||||
|
||||
<ul class="breadcrumbs margin-top">
|
||||
<li><%= @answer.question.title %></li>
|
||||
<li><%= @answer.title %></li>
|
||||
</ul>
|
||||
|
||||
<div class="clear"></div>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col"><%= t("admin.answers.show.title") %></th>
|
||||
<th scope="col"><%= t("admin.answers.show.description") %></th>
|
||||
<th scope="col" class="text-center"><%= t("admin.answers.show.images") %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><%= @answer.title %></td>
|
||||
<td><%= wysiwyg(@answer.description) %></td>
|
||||
<td class="text-center">
|
||||
(<%= @answer.images.count %>)<br>
|
||||
<%= link_to t("admin.answers.show.images_list"), admin_answer_images_path(@answer) %>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
<%= render "shared/errors", resource: @video %>
|
||||
|
||||
<%= f.hidden_field :answer_id, value: @video.answer_id || @answer.id %>
|
||||
|
||||
<div class="row">
|
||||
<div class="small-12 column">
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<%= back_link_to %>
|
||||
<%= back_link_to admin_answer_videos_path(@answer) %>
|
||||
|
||||
<h2>
|
||||
<%= t("admin.answers.videos.edit.title") %>
|
||||
</h2>
|
||||
|
||||
<div class="poll-question-answer-video-form">
|
||||
<%= render "form", form_url: admin_video_path(@video) %>
|
||||
<%= render "form", form_url: admin_answer_video_path(@answer, @video) %>
|
||||
</div>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<%= back_link_to admin_question_path(@answer.question_id) %>
|
||||
<%= back_link_to admin_question_path(@answer.question) %>
|
||||
|
||||
<div class="clear"></div>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
</h2>
|
||||
|
||||
<%= link_to t("admin.answers.videos.index.add_video"),
|
||||
new_admin_answer_video_path,
|
||||
new_admin_answer_video_path(@answer),
|
||||
class: "button success float-right" %>
|
||||
|
||||
<div>
|
||||
@@ -22,7 +22,7 @@
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% @answer.videos.each do |video| %>
|
||||
<% @videos.each do |video| %>
|
||||
<tr id="<%= dom_id(video) %>" class="poll_question_answer_video">
|
||||
<td><%= video.title %></td>
|
||||
<td><%= link_to video.url, video.url %></td>
|
||||
|
||||
@@ -5,5 +5,5 @@
|
||||
</h2>
|
||||
|
||||
<div class="poll-question-answer-video-form">
|
||||
<%= render "form", form_url: admin_answer_videos_path %>
|
||||
<%= render "form", form_url: admin_answer_videos_path(@answer) %>
|
||||
</div>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<%= back_link_to %>
|
||||
<%= back_link_to admin_poll_path(@question.poll) %>
|
||||
|
||||
<h2 class="margin-top"><%= t("admin.questions.edit.title") %></h2>
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<%= back_link_to %>
|
||||
<%= back_link_to admin_poll_path(@question.poll) %>
|
||||
|
||||
<%= link_to t("admin.questions.show.edit_question"), edit_admin_question_path(@question),
|
||||
class: "button hollow float-right" %>
|
||||
@@ -35,24 +35,22 @@
|
||||
</div>
|
||||
|
||||
<table class="margin-top">
|
||||
<tr>
|
||||
<th colspan="5" scope="col" class="with-button">
|
||||
<%= t("admin.questions.show.valid_answers") %>
|
||||
</th>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th><%= t("admin.questions.show.answers.title") %></th>
|
||||
<th scope="col" class="medium-7"><%= t("admin.questions.show.answers.description") %></th>
|
||||
<th scope="col" class="text-center"><%= t("admin.questions.show.answers.images") %></th>
|
||||
<th scope="col" class="text-center"><%= t("admin.questions.show.answers.documents") %></th>
|
||||
<th scope="col" class="text-center"><%= t("admin.questions.show.answers.videos") %></th>
|
||||
</tr>
|
||||
<caption><%= t("admin.questions.show.valid_answers") %></caption>
|
||||
<thead>
|
||||
<tr>
|
||||
<th><%= t("admin.questions.show.answers.title") %></th>
|
||||
<th scope="col" class="medium-7"><%= t("admin.questions.show.answers.description") %></th>
|
||||
<th scope="col" class="text-center"><%= t("admin.questions.show.answers.images") %></th>
|
||||
<th scope="col" class="text-center"><%= t("admin.questions.show.answers.documents") %></th>
|
||||
<th scope="col" class="text-center"><%= t("admin.questions.show.answers.videos") %></th>
|
||||
<th><%= t("admin.actions.actions") %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody class="sortable" data-js-url="<%= admin_question_answers_order_answers_path(@question.id) %>">
|
||||
<% @question.question_answers.each do |answer| %>
|
||||
<tr id="<%= dom_id(answer) %>" class="poll_question_answer" data-answer-id="<%= answer.id %>">
|
||||
<td class="align-top"><%= link_to answer.title, admin_answer_path(answer) %></td>
|
||||
<td class="align-top"><%= answer.title %></td>
|
||||
<td class="align-top break"><%= wysiwyg(answer.description) %></td>
|
||||
<td class="align-top text-center">
|
||||
(<%= answer.images.count %>)
|
||||
@@ -72,6 +70,9 @@
|
||||
<%= link_to t("admin.questions.show.answers.video_list"),
|
||||
admin_answer_videos_path(answer) %>
|
||||
</td>
|
||||
<td>
|
||||
<%= render Admin::TableActionsComponent.new(answer, actions: [:edit]) %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
||||
@@ -25,7 +25,7 @@ module ActionDispatch::Routing::UrlFor
|
||||
|
||||
def namespaced_polymorphic_path(namespace, resource, options = {})
|
||||
if %w[Budget::Group Budget::Heading Poll::Booth Poll::BoothAssignment Poll::Officer
|
||||
Poll::Question Poll::Question::Answer::Video Poll::Shift
|
||||
Poll::Question Poll::Question::Answer Poll::Question::Answer::Video Poll::Shift
|
||||
SDG::LocalTarget].include?(resource.class.name)
|
||||
resolve = resolve_for(resource)
|
||||
resolve_options = resolve.pop
|
||||
|
||||
@@ -1103,9 +1103,6 @@ en:
|
||||
table_title: "Title"
|
||||
edit_answers: Edit answers
|
||||
see_proposal: "(See proposal)"
|
||||
flash:
|
||||
question_added: "Question added to this poll"
|
||||
error_on_question_added: "Question could not be assigned to this poll"
|
||||
destroy:
|
||||
alert: "This action will remove the poll and all its associated questions."
|
||||
success_notice: "Poll deleted successfully"
|
||||
@@ -1129,6 +1126,8 @@ en:
|
||||
new:
|
||||
title: "Create question to poll %{poll}"
|
||||
title_proposal: "Create question"
|
||||
destroy:
|
||||
notice: "Question deleted succesfully"
|
||||
answers:
|
||||
images:
|
||||
add_image: "Add image"
|
||||
@@ -1155,12 +1154,6 @@ en:
|
||||
answers:
|
||||
new:
|
||||
title: New answer
|
||||
show:
|
||||
title: Title
|
||||
description: Description
|
||||
images: Images
|
||||
images_list: Images list
|
||||
edit: Edit answer
|
||||
edit:
|
||||
title: Edit answer
|
||||
videos:
|
||||
|
||||
@@ -32,7 +32,6 @@ en:
|
||||
translation: "Translation updated successfully"
|
||||
destroy:
|
||||
budget_investment: "Investment project deleted succesfully."
|
||||
error: "Could not delete"
|
||||
topic: "Topic deleted successfully."
|
||||
poll_question_answer_video: "Answer video deleted successfully."
|
||||
valuator_group: "Valuator group deleted successfully"
|
||||
|
||||
@@ -1102,9 +1102,6 @@ es:
|
||||
table_title: "Título"
|
||||
edit_answers: Editar respuestas
|
||||
see_proposal: "(Ver propuesta)"
|
||||
flash:
|
||||
question_added: "Pregunta añadida a esta votación"
|
||||
error_on_question_added: "No se pudo asignar la pregunta"
|
||||
destroy:
|
||||
alert: "Esta acción eliminará la votación y todas sus preguntas asociadas."
|
||||
success_notice: "Votación eliminada correctamente"
|
||||
@@ -1128,6 +1125,8 @@ es:
|
||||
new:
|
||||
title: "Crear pregunta ciudadana para la votación %{poll}"
|
||||
title_proposal: "Crear pregunta ciudadana"
|
||||
destroy:
|
||||
notice: "Pregunta eliminada correctamente"
|
||||
answers:
|
||||
images:
|
||||
add_image: "Añadir imagen"
|
||||
@@ -1154,12 +1153,6 @@ es:
|
||||
answers:
|
||||
new:
|
||||
title: Nueva respuesta
|
||||
show:
|
||||
title: Título
|
||||
description: Descripción
|
||||
images: Imágenes
|
||||
images_list: Lista de imágenes
|
||||
edit: Editar respuesta
|
||||
edit:
|
||||
title: Editar respuesta
|
||||
videos:
|
||||
|
||||
@@ -32,7 +32,6 @@ es:
|
||||
translation: "Traducción actualizada correctamente"
|
||||
destroy:
|
||||
budget_investment: "Proyecto de gasto eliminado."
|
||||
error: "No se pudo borrar"
|
||||
topic: "Tema eliminado."
|
||||
poll_question_answer_video: "Vídeo de respuesta eliminado."
|
||||
valuator_group: "Grupo de evaluadores eliminado correctamente"
|
||||
|
||||
@@ -141,7 +141,6 @@ namespace :admin do
|
||||
scope module: :poll do
|
||||
resources :polls do
|
||||
get :booth_assignments, on: :collection
|
||||
patch :add_question, on: :member
|
||||
|
||||
resources :booth_assignments, only: [:index, :show, :create, :destroy] do
|
||||
get :search_booths, on: :collection
|
||||
@@ -170,10 +169,11 @@ namespace :admin do
|
||||
end
|
||||
|
||||
resources :questions, shallow: true do
|
||||
resources :answers, except: [:index, :destroy], controller: "questions/answers" do
|
||||
resources :answers, except: [:index, :show, :destroy], controller: "questions/answers", shallow: false
|
||||
resources :answers, only: [], controller: "questions/answers" do
|
||||
resources :images, controller: "questions/answers/images"
|
||||
resources :videos, controller: "questions/answers/videos"
|
||||
get :documents, to: "questions/answers#documents"
|
||||
resources :videos, controller: "questions/answers/videos", shallow: false
|
||||
resources :documents, only: [:index, :create], controller: "questions/answers/documents"
|
||||
end
|
||||
post "/answers/order_answers", to: "questions/answers#order_answers"
|
||||
end
|
||||
@@ -323,6 +323,10 @@ resolve "Poll::Officer" do |officer, options|
|
||||
[:officer, options.merge(id: officer)]
|
||||
end
|
||||
|
||||
resolve "Poll::Question::Answer::Video" do |video, options|
|
||||
[:video, options.merge(id: video)]
|
||||
resolve "Poll::Question::Answer" do |answer, options|
|
||||
[:question, :answer, options.merge(question_id: answer.question, id: answer)]
|
||||
end
|
||||
|
||||
resolve "Poll::Question::Answer::Video" do |video, options|
|
||||
[:answer, :video, options.merge(answer_id: video.answer, id: video)]
|
||||
end
|
||||
|
||||
@@ -1,7 +1 @@
|
||||
resources :documents, only: [:new, :create, :destroy] do
|
||||
collection do
|
||||
get :new_nested
|
||||
delete :destroy_upload
|
||||
post :upload
|
||||
end
|
||||
end
|
||||
resources :documents, only: [:destroy]
|
||||
|
||||
@@ -18,6 +18,8 @@ describe Abilities::Administrator do
|
||||
let(:legislation_question) { create(:legislation_question) }
|
||||
let(:poll) { create(:poll) }
|
||||
let(:poll_question) { create(:poll_question) }
|
||||
let(:poll_question_answer) { create(:poll_question_answer) }
|
||||
let(:answer_image) { build(:image, imageable: poll_question_answer) }
|
||||
|
||||
let(:past_process) { create(:legislation_process, :past) }
|
||||
let(:past_draft_process) { create(:legislation_process, :past, :not_published) }
|
||||
@@ -114,6 +116,13 @@ describe Abilities::Administrator do
|
||||
it { should be_able_to(:create, Poll::Question) }
|
||||
it { should be_able_to(:update, Poll::Question) }
|
||||
|
||||
it { should be_able_to(:manage, Poll::Question::Answer) }
|
||||
|
||||
it { should be_able_to(:manage, Poll::Question::Answer::Video) }
|
||||
|
||||
it { should be_able_to(:create, answer_image) }
|
||||
it { should be_able_to(:destroy, answer_image) }
|
||||
|
||||
it { is_expected.to be_able_to :manage, Dashboard::AdministratorTask }
|
||||
it { is_expected.to be_able_to :manage, dashboard_administrator_task }
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ describe "Polymorphic routes" do
|
||||
it "routes poll answer videos" do
|
||||
video = create(:poll_answer_video)
|
||||
|
||||
expect(admin_polymorphic_path(video)).to eq admin_video_path(video)
|
||||
expect(admin_polymorphic_path(video)).to eq admin_answer_video_path(video.answer, video)
|
||||
end
|
||||
|
||||
it "routes milestones for resources with no hierarchy" do
|
||||
|
||||
@@ -61,6 +61,7 @@ describe "Admin polls", :admin do
|
||||
|
||||
expect(page).not_to have_css("#poll_results_enabled")
|
||||
expect(page).not_to have_css("#poll_stats_enabled")
|
||||
expect(page).to have_link "Go back", href: admin_polls_path
|
||||
|
||||
click_button "Create poll"
|
||||
|
||||
@@ -83,6 +84,7 @@ describe "Admin polls", :admin do
|
||||
end_date = 1.year.from_now.to_date
|
||||
|
||||
expect(page).to have_css("img[alt='#{poll.image.title}']")
|
||||
expect(page).to have_link "Go back", href: admin_polls_path
|
||||
|
||||
fill_in "Name", with: "Next Poll"
|
||||
fill_in "poll_ends_at", with: end_date
|
||||
|
||||
@@ -7,6 +7,8 @@ describe "Answers", :admin do
|
||||
visit admin_question_path(question)
|
||||
click_link "Add answer"
|
||||
|
||||
expect(page).to have_link "Go back", href: admin_question_path(question)
|
||||
|
||||
fill_in "Answer", with: "The answer is always 42"
|
||||
fill_in_ckeditor "Description", with: "The Hitchhiker's Guide To The Universe"
|
||||
|
||||
@@ -33,15 +35,15 @@ describe "Answers", :admin do
|
||||
|
||||
scenario "Update" do
|
||||
question = create(:poll_question)
|
||||
answer = create(:poll_question_answer, question: question, title: "Answer title", given_order: 2)
|
||||
create(:poll_question_answer, question: question, title: "Answer title", given_order: 2)
|
||||
create(:poll_question_answer, question: question, title: "Another title", given_order: 1)
|
||||
|
||||
visit admin_answer_path(answer)
|
||||
visit admin_question_path(question)
|
||||
within("tr", text: "Answer title") { click_link "Edit" }
|
||||
|
||||
click_link "Edit answer"
|
||||
expect(page).to have_link "Go back", href: admin_question_path(question)
|
||||
|
||||
fill_in "Answer", with: "New title"
|
||||
|
||||
click_button "Save"
|
||||
|
||||
expect(page).to have_content "Changes saved"
|
||||
|
||||
@@ -9,6 +9,7 @@ describe "Documents", :admin do
|
||||
visit admin_answer_documents_path(answer)
|
||||
|
||||
expect(page).not_to have_content(document.title)
|
||||
expect(page).to have_link "Go back", href: admin_question_path(answer.question)
|
||||
end
|
||||
|
||||
scenario "Answer with documents" do
|
||||
@@ -21,6 +22,18 @@ describe "Documents", :admin do
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Create document for answer" do
|
||||
answer = create(:poll_question_answer)
|
||||
|
||||
visit admin_answer_documents_path(answer)
|
||||
|
||||
documentable_attach_new_file(Rails.root.join("spec/fixtures/files/clippy.pdf"))
|
||||
click_button "Save"
|
||||
|
||||
expect(page).to have_content "Document uploaded succesfully"
|
||||
expect(page).to have_link "clippy.pdf"
|
||||
end
|
||||
|
||||
scenario "Remove document from answer" do
|
||||
answer = create(:poll_question_answer)
|
||||
document = create(:document, documentable: answer)
|
||||
|
||||
@@ -1,26 +1,55 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe "Videos", :admin do
|
||||
scenario "Create" do
|
||||
question = create(:poll_question)
|
||||
answer = create(:poll_question_answer, question: question)
|
||||
video_title = "'Magical' by Junko Ohashi"
|
||||
video_url = "https://www.youtube.com/watch?v=-JMf43st-1A"
|
||||
let!(:question) { create(:poll_question) }
|
||||
let!(:answer) { create(:poll_question_answer, question: question) }
|
||||
let(:title) { "'Magical' by Junko Ohashi" }
|
||||
let(:url) { "https://www.youtube.com/watch?v=-JMf43st-1A" }
|
||||
|
||||
scenario "Create" do
|
||||
visit admin_question_path(question)
|
||||
|
||||
within("#poll_question_answer_#{answer.id}") do
|
||||
click_link "Video list"
|
||||
end
|
||||
|
||||
click_link "Add video"
|
||||
|
||||
fill_in "poll_question_answer_video_title", with: video_title
|
||||
fill_in "poll_question_answer_video_url", with: video_url
|
||||
fill_in "Title", with: title
|
||||
fill_in "External video", with: url
|
||||
|
||||
click_button "Save"
|
||||
|
||||
expect(page).to have_content(video_title)
|
||||
expect(page).to have_content(video_url)
|
||||
expect(page).to have_content title
|
||||
expect(page).to have_content url
|
||||
end
|
||||
|
||||
scenario "Update" do
|
||||
video = create(:poll_answer_video, answer: answer)
|
||||
|
||||
visit edit_admin_answer_video_path(answer, video)
|
||||
|
||||
expect(page).to have_link "Go back", href: admin_answer_videos_path(answer)
|
||||
|
||||
fill_in "Title", with: title
|
||||
fill_in "External video", with: url
|
||||
|
||||
click_button "Save"
|
||||
|
||||
expect(page).to have_content title
|
||||
expect(page).to have_content url
|
||||
end
|
||||
|
||||
scenario "Destroy" do
|
||||
video = create(:poll_answer_video, answer: answer)
|
||||
|
||||
visit admin_answer_videos_path(answer)
|
||||
|
||||
within("#poll_question_answer_video_#{video.id}") do
|
||||
accept_confirm("Are you sure? This action will delete \"#{video.title}\" and can't be undone.") do
|
||||
click_button "Delete"
|
||||
end
|
||||
end
|
||||
|
||||
expect(page).to have_content "Answer video deleted successfully."
|
||||
end
|
||||
end
|
||||
|
||||
@@ -50,8 +50,9 @@ describe "Admin poll questions", :admin do
|
||||
visit admin_poll_path(poll)
|
||||
click_link "Edit answers"
|
||||
|
||||
expect(page).to have_content(question.title)
|
||||
expect(page).to have_content(question.author.name)
|
||||
expect(page).to have_link "Go back", href: admin_poll_path(poll)
|
||||
expect(page).to have_content question.title
|
||||
expect(page).to have_content question.author.name
|
||||
end
|
||||
|
||||
scenario "Create" do
|
||||
@@ -123,6 +124,7 @@ describe "Admin poll questions", :admin do
|
||||
click_link "Edit"
|
||||
end
|
||||
|
||||
expect(page).to have_link "Go back", href: admin_poll_path(poll)
|
||||
old_title = question1.title
|
||||
new_title = "Potatoes are great and everyone should have one"
|
||||
fill_in "Question", with: new_title
|
||||
@@ -147,8 +149,9 @@ describe "Admin poll questions", :admin do
|
||||
end
|
||||
end
|
||||
|
||||
expect(page).not_to have_content(question1.title)
|
||||
expect(page).to have_content(question2.title)
|
||||
expect(page).not_to have_content question1.title
|
||||
expect(page).to have_content question2.title
|
||||
expect(page).to have_current_path admin_poll_path(poll)
|
||||
end
|
||||
|
||||
context "Poll select box" do
|
||||
|
||||
@@ -216,7 +216,7 @@ describe "Admin edit translatable records", :admin do
|
||||
|
||||
context "CKEditor fields" do
|
||||
let(:translatable) { create(:poll_question_answer) }
|
||||
let(:path) { edit_admin_answer_path(translatable) }
|
||||
let(:path) { edit_admin_question_answer_path(translatable.question, translatable) }
|
||||
|
||||
scenario "Changes the existing translation" do
|
||||
visit path
|
||||
|
||||
Reference in New Issue
Block a user