Merge branch 'master' into iagirre-remove-documents-questions

This commit is contained in:
Raimond Garcia
2017-10-06 01:02:56 +02:00
committed by GitHub
29 changed files with 294 additions and 186 deletions

View File

@@ -149,6 +149,7 @@ $sidebar-active: #f4fcd0;
} }
table { table {
.break { .break {
word-break: break-word; word-break: break-word;
} }

View File

@@ -1591,6 +1591,10 @@
.orbit-container { .orbit-container {
height: 100% !important; height: 100% !important;
max-height: none !important; max-height: none !important;
li {
margin-bottom: 0 !important;
}
} }
.orbit-slide { .orbit-slide {

View File

@@ -0,0 +1,32 @@
class Admin::Poll::Questions::Answers::ImagesController < Admin::Poll::BaseController
before_action :load_answer
def index
end
def new
@answer = ::Poll::Question::Answer.find(params[:answer_id])
end
def create
@answer = ::Poll::Question::Answer.find(params[:answer_id])
@answer.attributes = images_params
if @answer.save
redirect_to admin_answer_images_path(@answer),
notice: "Image uploaded successfully"
else
render :new
end
end
private
def images_params
params.permit(images_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy])
end
def load_answer
@answer = ::Poll::Question::Answer.find(params[:answer_id])
end
end

View File

@@ -25,7 +25,7 @@ module AdminHelper
end end
def menu_polls? def menu_polls?
%w[polls questions officers booths officer_assignments booth_assignments recounts results shifts].include? controller_name %w[polls questions officers booths officer_assignments booth_assignments recounts results shifts questions answers].include? controller_name
end end
def menu_profiles? def menu_profiles?

View File

@@ -0,0 +1,12 @@
module Galleryable
extend ActiveSupport::Concern
included do
has_many :images, as: :imageable, dependent: :destroy
accepts_nested_attributes_for :images, allow_destroy: true, update_only: true
def image_url(style)
image.attachment.url(style) if image && image.attachment.exists?
end
end
end

View File

@@ -19,7 +19,9 @@ class DirectUpload
if @resource_type.present? && @resource_relation.present? && (@attachment.present? || @cached_attachment.present?) if @resource_type.present? && @resource_relation.present? && (@attachment.present? || @cached_attachment.present?)
@resource = @resource_type.constantize.find_or_initialize_by(id: @resource_id) @resource = @resource_type.constantize.find_or_initialize_by(id: @resource_id)
if @resource.class.reflections[@resource_relation].macro == :has_one if @resource.respond_to?(:images)
@relation = @resource.images.send("build", relation_attributtes)
elsif @resource.class.reflections[@resource_relation].macro == :has_one
@relation = @resource.send("build_#{resource_relation}", relation_attributtes) @relation = @resource.send("build_#{resource_relation}", relation_attributtes)
else else
@relation = @resource.send(@resource_relation).build(relation_attributtes) @relation = @resource.send(@resource_relation).build(relation_attributtes)

View File

@@ -1,4 +1,6 @@
class Poll::Question::Answer < ActiveRecord::Base class Poll::Question::Answer < ActiveRecord::Base
include Galleryable
belongs_to :question, class_name: 'Poll::Question', foreign_key: 'question_id' belongs_to :question, class_name: 'Poll::Question', foreign_key: 'question_id'
validates :title, presence: true validates :title, presence: true

View File

@@ -60,12 +60,14 @@
<span class="icon-checkmark-circle"></span> <span class="icon-checkmark-circle"></span>
<strong><%= t("admin.menu.title_polls") %></strong> <strong><%= t("admin.menu.title_polls") %></strong>
</a> </a>
<ul id="polls_menu" <%= "class=is-active" if menu_polls? && controller.class.parent == Admin::Poll %>> <ul id="polls_menu" <%= "class=is-active" if menu_polls? || controller.class.parent == Admin::Poll::Questions::Answers %>>
<li <%= "class=active" if ["polls", "officer_assignments", "booth_assignments", "recounts", "results"].include? controller_name %>> <li <%= "class=active" if ["polls", "officer_assignments", "booth_assignments", "recounts", "results"].include? controller_name %>>
<%= link_to t('admin.menu.polls'), admin_polls_path %> <%= link_to t('admin.menu.polls'), admin_polls_path %>
</li> </li>
<li <%= "class=active" if current_page?(admin_questions_path) %>> <li <%= "class=active" if controller_name == "questions" ||
controller_name == "answers" ||
controller.class.parent == Admin::Poll::Questions::Answers %>>
<%= link_to t("admin.menu.poll_questions"), admin_questions_path %> <%= link_to t("admin.menu.poll_questions"), admin_questions_path %>
</li> </li>
@@ -158,12 +160,14 @@
<span class="icon-settings"></span> <span class="icon-settings"></span>
<strong><%= t("admin.menu.title_site_customization") %></strong> <strong><%= t("admin.menu.title_site_customization") %></strong>
</a> </a>
<ul <%= "class=is-active" if menu_customization? %>> <ul <%= "class=is-active" if menu_customization? &&
controller.class.parent != Admin::Poll::Questions::Answers %>>
<li <%= "class=active" if controller_name == "pages" %>> <li <%= "class=active" if controller_name == "pages" %>>
<%= link_to t("admin.menu.site_customization.pages"), admin_site_customization_pages_path %> <%= link_to t("admin.menu.site_customization.pages"), admin_site_customization_pages_path %>
</li> </li>
<li <%= "class=active" if controller_name == "images" %>> <li <%= "class=active" if controller_name == "images" &&
controller.class.parent != Admin::Poll::Questions::Answers %>>
<%= link_to t("admin.menu.site_customization.images"), admin_site_customization_images_path %> <%= link_to t("admin.menu.site_customization.images"), admin_site_customization_images_path %>
</li> </li>

View File

@@ -4,30 +4,25 @@
<%= f.hidden_field :proposal_id %> <%= f.hidden_field :proposal_id %>
<div class="row"> <div class="small-12">
<div class="small-12 medium-6 large-4">
<%= f.select :poll_id,
options_for_select(Poll.pluck(:name, :id)),
prompt: t("admin.questions.index.select_poll"),
label: t("admin.questions.new.poll_label") %>
</div>
<div class="small-12 column"> <%= f.text_field :title, maxlength: Poll::Question.title_max_length %>
<div class="small-12 medium-6 large-4">
<%= f.select :poll_id,
options_for_select(Poll.pluck(:name, :id)),
prompt: t("admin.questions.index.select_poll"),
label: t("admin.questions.new.poll_label") %>
</div>
<%= f.text_field :title, maxlength: Poll::Question.title_max_length %> <div class="small-12">
<%= f.label :video_url, t("proposals.form.proposal_video_url") %>
<p class="help-text" id="video-url-help-text"><%= t("proposals.form.proposal_video_url_note") %></p>
<%= f.text_field :video_url, placeholder: t("proposals.form.proposal_video_url"), label: false,
aria: {describedby: "video-url-help-text"} %>
</div>
<div class="small-12"> <div class="small-12 medium-6 large-4 margin-top">
<%= f.label :video_url, t("proposals.form.proposal_video_url") %> <%= f.submit(class: "button expanded", value: t("shared.save")) %>
<p class="help-text" id="video-url-help-text"><%= t("proposals.form.proposal_video_url_note") %></p>
<%= f.text_field :video_url, placeholder: t("proposals.form.proposal_video_url"), label: false,
aria: {describedby: "video-url-help-text"} %>
</div>
<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>
</div> </div>

View File

@@ -4,21 +4,19 @@
<%= f.hidden_field :question_id, value: @question.id %> <%= f.hidden_field :question_id, value: @question.id %>
<div class="row"> <%= f.label :title, t('admin.questions.new.form.title') %>
<div class="small-12 column"> <%= f.text_field :title, label: false %>
<%= f.text_field :title %>
<div class="ckeditor"> <div class="ckeditor">
<%= f.cktext_area :description, <%= f.label :description, t('admin.questions.new.form.description') %>
maxlength: Poll::Question.description_max_length, <%= f.cktext_area :description,
ckeditor: { language: I18n.locale } %> maxlength: Poll::Question.description_max_length,
</div> ckeditor: { language: I18n.locale },
label: false %>
<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> </div>
<div class="small-12 medium-6 large-4">
<%= f.submit(class: "button expanded", value: t("shared.save")) %>
</div>
<% end %> <% end %>

View File

@@ -0,0 +1,16 @@
<%= back_link_to admin_question_path(@answer.question) %>
<%= link_to t("admin.questions.answers.images.add_image"),
new_admin_answer_image_path(@answer),
class: "button hollow float-right" %>
<ul class="breadcrumbs margin-top">
<li><%= @answer.question.title %></li>
<li><%= @answer.title %></li>
</ul>
<% @answer.images.each do |image| %>
<div class="small-12 medium-4 column end">
<%= render_image(image, :large, true) if image.present? %>
</div>
<% end %>

View File

@@ -0,0 +1,13 @@
<div class="poll-question-form">
<%= form_for(Poll::Question::Answer.new,
url: admin_answer_images_path(@answer),
method: :post) do |f| %>
<%= render 'shared/errors', resource: @answer %>
<div class="images">
<%= render 'images/nested_image', imageable: @answer, f: f, image_fields: :images %>
</div>
<%= f.submit t("admin.questions.answers.images.save_image"), class: "button success" %>
<% end %>
</div>

View File

@@ -1,5 +1,10 @@
<%= back_link_to %> <%= back_link_to %>
<ul class="breadcrumbs margin-top">
<li><%= @question.title %></li>
<li><%= t('admin.answers.new.title') %></li>
</ul>
<h2><%= t('admin.answers.new.title') %></h2> <h2><%= t('admin.answers.new.title') %></h2>
<div class="poll-question-answer-form"> <div class="poll-question-answer-form">

View File

@@ -1,6 +1,6 @@
<%= back_link_to %> <%= back_link_to %>
<h2><%= t("admin.questions.edit.title") %></h2> <h2 class="margin-top"><%= t("admin.questions.edit.title") %></h2>
<div class="poll-question-form"> <div class="poll-question-form">
<%= render "form", form_url: admin_question_path(@question) %> <%= render "form", form_url: admin_question_path(@question) %>

View File

@@ -3,10 +3,8 @@
<%= link_to t('admin.questions.index.create'), new_admin_question_path, <%= link_to t('admin.questions.index.create'), new_admin_question_path,
class: "button success float-right" %> class: "button success float-right" %>
<div class="row"> <div class="small-12 medium-6">
<div class="small-12 medium-6 column"> <%= render 'search' %>
<%= render 'search' %>
</div>
</div> </div>
<div class="tabs-content" data-tabs-content="questions-tabs"> <div class="tabs-content" data-tabs-content="questions-tabs">

View File

@@ -1,6 +1,6 @@
<%= back_link_to %> <%= back_link_to %>
<h2><%= t("admin.questions.new.title") %></h2> <h2 class="margin-top"><%= t("admin.questions.new.title") %></h2>
<div class="poll-question-form"> <div class="poll-question-form">
<%= render "form", form_url: admin_questions_path %> <%= render "form", form_url: admin_questions_path %>

View File

@@ -5,10 +5,19 @@
<div class="clear"></div> <div class="clear"></div>
<div class="row"> <div class="small-12 medium-6">
<div class="small-12 medium-9 column"> <div class="callout highlight">
<strong><%= t("admin.questions.show.title") %></strong> <p>
<h1><%= @question.title %></h1> <strong><%= t("admin.questions.show.title") %></strong>
<br>
<%= @question.title %>
</p>
<p>
<strong><%= t("admin.questions.show.author") %></strong>
<br>
<%= link_to @question.author.name, user_path(@question.author) %>
</p>
<% if @question.proposal.present? %> <% if @question.proposal.present? %>
<p> <p>
@@ -17,44 +26,42 @@
<%= link_to @question.proposal.title, proposal_path(@question.proposal) %> <%= link_to @question.proposal.title, proposal_path(@question.proposal) %>
</p> </p>
<% end %> <% end %>
<p>
<strong><%= t("admin.questions.show.author") %></strong>
<br>
<%= link_to @question.author.name, user_path(@question.author) %>
</p>
<table>
<tr>
<th colspan="1" scope="colgroup">
<%= t('admin.questions.show.valid_answers') %>
</th>
<th colspan="1" scope="colgroup">
<%= link_to t("admin.questions.show.add_answer"),
new_admin_question_answer_path(@question),
class: "button hollow float-right" %>
</th>
</tr>
<tr>
<th scope="col"><%= t("admin.questions.show.answers.title") %></th>
<th scope="col"><%= t("admin.questions.show.answers.description") %></th>
</tr>
<% @question.question_answers.each do |answer| %>
<tr id="<%= dom_id(answer) %>" class="poll_question_answer">
<th scope="col"><%= answer.title %></th>
<th scope="col"><%= answer.description %></th>
</tr>
<% end %>
</table>
<% if @question.video_url.present? %>
<p>
<strong><%= t("admin.questions.show.video_url") %></strong>
<br>
<a href="<%= @question.video_url %>"><%= @question.video_url %></a>
</p>
<% end %>
</div> </div>
</div> </div>
<table class="margin-top">
<tr>
<th colspan="3" scope="col" class="with-button">
<%= t('admin.questions.show.valid_answers') %>
<%= link_to t("admin.questions.show.add_answer"),
new_admin_question_answer_path(@question),
class: "button hollow float-right" %>
</th>
</tr>
<tr>
<th><%= t("admin.questions.show.answers.title") %></th>
<th class="medium-7"><%= t("admin.questions.show.answers.description") %></th>
<th class="text-center"><%= t("admin.questions.show.answers.images") %></th>
</tr>
<% @question.question_answers.each do |answer| %>
<tr id="<%= dom_id(answer) %>" class="poll_question_answer">
<td><%= answer.title %></td>
<td><%= answer.description %></td>
<td class="text-center">
(<%= answer.images.count %>)<br>
<%= link_to t("admin.questions.show.answers.images_list"),
admin_answer_images_path(answer) %>
</td>
</tr>
<% end %>
</table>
<% if @question.video_url.present? %>
<p>
<strong><%= t("admin.questions.show.video_url") %></strong>
<br>
<a href="<%= @question.video_url %>"><%= @question.video_url %></a>
</p>
<% end %>

View File

@@ -1,17 +1,20 @@
<%= f.label :image, t("images.form.title") %> <% image_fields ||= :image %>
<%= f.label image_fields, t("images.form.title") %>
<p class="help-text"><%= imageables_note(imageable) %></p> <p class="help-text"><%= imageables_note(imageable) %></p>
<div id="nested-image"> <div id="nested-image">
<%= f.fields_for :image do |image_builder| %> <%= f.fields_for image_fields do |image_builder| %>
<%= render 'images/image_fields', f: image_builder, imageable: imageable %> <%= render 'images/image_fields', f: image_builder, imageable: imageable %>
<% end %> <% end %>
</div> </div>
<%= link_to_add_association t('images.form.add_new_image'), f, :image, <%= link_to_add_association t('images.form.add_new_image'), f, image_fields,
force_non_association_create: true, force_non_association_create: true,
partial: "images/image_fields", partial: "images/image_fields",
id: "new_image_link", id: "new_image_link",
class: "button hollow #{"hide" if imageable.image.present?}", class: "button hollow
#{"hide" if image_fields == :image && imageable.image.present?}",
render_options: { render_options: {
locals: { imageable: imageable } locals: { imageable: imageable }
}, },

View File

@@ -1,5 +1,5 @@
<div class="orbit margin-bottom" role="region" aria-label="Answer 1" data-orbit data-auto-play="false"> <div class="orbit margin-bottom" role="region" aria-label="<%= answer.title %>" data-orbit data-auto-play="false">
<a data-toggle="answer_1" class="zoom-link show-for-medium-up"> <a data-toggle="answer_<%= answer.id %>" class="zoom-link show-for-medium-up">
<span class="icon-search-plus"></span> <span class="icon-search-plus"></span>
<span class="show-for-sr"><%= t("polls.show.zoom_plus") %></span> <span class="show-for-sr"><%= t("polls.show.zoom_plus") %></span>
</a> </a>
@@ -15,32 +15,25 @@
<span class="show-for-sr"><%= t("shared.orbit.next_slide") %></span>&#9654;&#xFE0E; <span class="show-for-sr"><%= t("shared.orbit.next_slide") %></span>&#9654;&#xFE0E;
</button> </button>
</li> </li>
<!-- each image do -->
<li class="is-active orbit-slide"> <% answer.images.each_with_index do |image, index| %>
<%= link_to "/assets/example_vertical.jpg", target: "_blank" do %> <li class="orbit-slide <%= active_class(index) %>">
<%= image_tag "example_horizontal.jpg", class: "orbit-image" %> <%= link_to image.attachment.url(:original), target: "_blank" do %>
<% end %> <%= image_tag image.attachment.url(:medium),
<!-- replace this with image title --> class: "orbit-image",
<span class="orbit-caption">Image title 1</span> alt: image.title %>
<!-- /. replace this with image title --> <% end %>
</li> <span class="orbit-caption"><%= image.title %></span>
<!-- end --> </li>
<li class="orbit-slide"> <% end %>
<%= link_to "/assets/example_vertical.jpg", target: "_blank" do %>
<%= image_tag "example_vertical.jpg", class: "orbit-image" %>
<% end %>
<span class="orbit-caption">Image title 2</span>
</li>
</ul> </ul>
<nav class="orbit-bullets"> <nav class="orbit-bullets">
<button class="is-active" data-slide="0"> <% answer.images.each_with_index do |image, index| %>
<!-- replace this with image title --> <button class="<%= active_class(index) %>" data-slide="<%= index %>">
<span class="show-for-sr">Image title 1</span> <span class="show-for-sr"><%= image.title %></span>
<!-- /. replace this with image title --> </button>
</button> <% end %>
<button data-slide="1">
<span class="show-for-sr">Image title 2</span>
</button>
</nav> </nav>
</div> </div>

View File

@@ -1,37 +1,9 @@
<% poll_group.each do |poll| %> <% poll_group.each do |poll| %>
<div class="poll with-image"> <div class="poll with-image">
<% if poll.answerable_by?(current_user) && poll.votable_by?(current_user) %> <% if user_signed_in? && !poll.votable_by?(current_user) %>
<%= link_to poll,
class: "icon-poll-answer can-answer",
title: t("polls.index.can_answer") do %>
<span class="show-for-sr">
<%= t("polls.index.can_answer") %>
</span>
<% end %>
<% elsif current_user.nil? %>
<%= link_to new_user_session_path,
class: "icon-poll-answer not-logged-in",
title: t("polls.index.cant_answer_not_logged_in") do %>
<span class="show-for-sr">
<%= t("polls.index.cant_answer_not_logged_in") %>
</span>
<% end %>
<% elsif current_user.unverified? %>
<%= link_to verification_path,
class: "icon-poll-answer unverified",
title: t("polls.index.cant_answer_verify") do %>
<span class="show-for-sr">
<%= t("polls.index.cant_answer_verify") %>
</span>
<% end %>
<% elsif !poll.votable_by?(current_user) %>
<div class="icon-poll-answer already-answer" title="<%= t("polls.index.already_answer") %>"> <div class="icon-poll-answer already-answer" title="<%= t("polls.index.already_answer") %>">
<span class="show-for-sr"><%= t("polls.index.already_answer") %></span> <span class="show-for-sr"><%= t("polls.index.already_answer") %></span>
</div> </div>
<% else %>
<div class="icon-poll-answer cant-answer" title="<%= t("polls.index.cant_answer") %>">
<span class="show-for-sr"><%= t("polls.index.cant_answer") %></span>
</div>
<% end %> <% end %>
<div class="row" data-equalizer> <div class="row" data-equalizer>
<div class="small-12 medium-3 column"> <div class="small-12 medium-3 column">

View File

@@ -62,27 +62,23 @@
<div class="expanded poll-more-info-answers"> <div class="expanded poll-more-info-answers">
<div class="row padding"> <div class="row padding">
<!-- EACH ANSWER DO --> <% @poll.questions.map(&:question_answers).flatten.each do |answer| %>
<div class="small-12 medium-6 column end" id="answer_1" data-toggler=".medium-6"> <div class="small-12 medium-6 column end" id="answer_<%= answer.id %>"
data-toggler=".medium-6">
<!-- REPLACE THIS WITH answer title --> <h3><%= answer.title %></h3>
<h3>Answer 1</h3>
<!-- /. REPLACE THIS WITH answer title -->
<!-- If Answer have images render this: <% if answer.images.any? %>
Maybe something like <%# render "gallery", gallery: answer.gallery %> --> <%= render "gallery", answer: answer %>
<%= render "gallery" %> <% end %>
<!-- If Answer have images render this -->
<div class="margin-top">
<%= safe_html_with_links simple_format(answer.description) %>
</div>
<!-- REPLACE THIS WITH answer description -->
<div class="margin-top">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div> </div>
<!-- /. REPLACE THIS WITH answer description --> <% end %>
</div>
</div> </div>
<!-- /. EACH ANSWER DO -->
</div> </div>
</div> </div>

View File

@@ -587,6 +587,13 @@ en:
new: new:
title: "Create Question" title: "Create Question"
poll_label: "Poll" poll_label: "Poll"
form:
title: Title
description: Description
answers:
images:
add_image: "Add image"
save_image: "Save image"
show: show:
proposal: Original proposal proposal: Original proposal
author: Author author: Author
@@ -597,6 +604,8 @@ en:
answers: answers:
title: Answer title: Answer
description: Description description: Description
images: Images
images_list: Images list
answers: answers:
new: new:
title: "New answer" title: "New answer"

View File

@@ -180,6 +180,7 @@ en:
spending_proposal: Spending proposal spending_proposal: Spending proposal
budget/investment: Investment budget/investment: Investment
poll/shift: Shift poll/shift: Shift
poll/question/answer: Answer
user: Account user: Account
verification/sms: phone verification/sms: phone
signature_sheet: Signature sheet signature_sheet: Signature sheet
@@ -466,10 +467,6 @@ en:
no_geozone_restricted: "All city" no_geozone_restricted: "All city"
geozone_restricted: "Districts" geozone_restricted: "Districts"
geozone_info: "Can participate people in the Census of: " geozone_info: "Can participate people in the Census of: "
can_answer: "You can participate in this poll!"
cant_answer: "This poll is not available on your geozone"
cant_answer_not_logged_in: "You must sign in or sign up to participate"
cant_answer_verify: "You must verify your account in order to answer"
already_answer: "You already have participated in this poll" already_answer: "You already have participated in this poll"
section_header: section_header:
icon_alt: Voting icon icon_alt: Voting icon

View File

@@ -587,6 +587,13 @@ es:
new: new:
title: "Crear pregunta ciudadana" title: "Crear pregunta ciudadana"
poll_label: "Votación" poll_label: "Votación"
form:
title: Título
description: Descripción
answers:
images:
add_image: "Añadir imagen"
save_image: "Guardar imagen"
show: show:
proposal: Propuesta ciudadana original proposal: Propuesta ciudadana original
author: Autor author: Autor
@@ -599,6 +606,8 @@ es:
answers: answers:
title: Respuesta title: Respuesta
description: Descripción description: Descripción
images: Imágenes
images_list: Lista de imágenes
answers: answers:
new: new:
title: "Nueva respuesta" title: "Nueva respuesta"

View File

@@ -180,6 +180,7 @@ es:
spending_proposal: la propuesta de gasto spending_proposal: la propuesta de gasto
budget/investment: la propuesta de inversión budget/investment: la propuesta de inversión
poll/shift: el turno poll/shift: el turno
poll/question/answer: la respuesta
user: la cuenta user: la cuenta
verification/sms: el teléfono verification/sms: el teléfono
signature_sheet: la hoja de firmas signature_sheet: la hoja de firmas
@@ -466,10 +467,6 @@ es:
no_geozone_restricted: "Toda la ciudad" no_geozone_restricted: "Toda la ciudad"
geozone_restricted: "Distritos" geozone_restricted: "Distritos"
geozone_info: "Pueden participar las personas empadronadas en: " geozone_info: "Pueden participar las personas empadronadas en: "
can_answer: "¡Puedes participar en esta votación!"
cant_answer: "Esta votación no está disponible en tu zona"
cant_answer_not_logged_in: "Necesitas iniciar sesión o registrarte para participar"
cant_answer_verify: "Por favor verifica tu cuenta para poder responder"
already_answer: "Ya has participado en esta votación" already_answer: "Ya has participado en esta votación"
section_header: section_header:
icon_alt: Icono de Votaciones icon_alt: Icono de Votaciones

View File

@@ -301,7 +301,10 @@ Rails.application.routes.draw do
end end
resources :questions do resources :questions do
resources :answers, only: [:new, :create], controller: 'questions/answers' resources :answers, only: [:new, :create], controller: 'questions/answers', shallow: true do
resources :images, controller: 'questions/answers/images'
end
end end
end end

View File

@@ -0,0 +1,14 @@
require 'rails_helper'
feature 'Images' do
background do
admin = create(:administrator)
login_as(admin.user)
end
pending "Index"
pending "Create"
pending "Destroy"
end

View File

@@ -42,4 +42,16 @@ feature 'Answers' do
pending "Update" pending "Update"
pending "Destroy" pending "Destroy"
context "Gallery" do
it_behaves_like "nested imageable",
"poll_question_answer",
"new_admin_answer_image_path",
{ "answer_id": "id" },
nil,
"Save image",
"Image uploaded successfully",
true
end
end end

View File

@@ -1,21 +1,23 @@
shared_examples "nested imageable" do |imageable_factory_name, path, imageable_path_arguments, fill_resource_method_name, submit_button, imageable_success_notice| shared_examples "nested imageable" do |imageable_factory_name, path, imageable_path_arguments, fill_resource_method_name, submit_button, imageable_success_notice, has_many_images=false|
include ActionView::Helpers include ActionView::Helpers
include ImagesHelper include ImagesHelper
include ImageablesHelper include ImageablesHelper
let!(:administrator) { create(:user) }
let!(:user) { create(:user, :level_two) } let!(:user) { create(:user, :level_two) }
let!(:administrator) { create(:administrator, user: user) }
let!(:arguments) { {} } let!(:arguments) { {} }
let!(:imageable) { create(imageable_factory_name, author: user) } let!(:imageable) { create(imageable_factory_name) }
before do before do
create(:administrator, user: administrator)
if imageable_path_arguments if imageable_path_arguments
imageable_path_arguments.each do |argument_name, path_to_value| imageable_path_arguments.each do |argument_name, path_to_value|
arguments.merge!("#{argument_name}": imageable.send(path_to_value)) arguments.merge!("#{argument_name}": imageable.send(path_to_value))
end end
end end
if imageable.respond_to?(:author)
imageable.update(author: user)
end
end end
describe "at #{path}" do describe "at #{path}" do
@@ -66,7 +68,11 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
image_input = find(".image").find("input[type=file]", visible: false) image_input = find(".image").find("input[type=file]", visible: false)
attach_file(image_input[:id], "spec/fixtures/files/clippy.jpg", make_visible: true) attach_file(image_input[:id], "spec/fixtures/files/clippy.jpg", make_visible: true)
expect(find("##{imageable_factory_name}_image_attributes_title").value).to eq "Title" if has_many_images
expect(find("input[id$='_title']").value).to eq "Title"
else
expect(find("##{imageable_factory_name}_image_attributes_title").value).to eq "Title"
end
end end
scenario "Should update loading bar style after valid file upload", :js do scenario "Should update loading bar style after valid file upload", :js do
@@ -78,7 +84,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
expect(page).to have_selector ".loading-bar.complete" expect(page).to have_selector ".loading-bar.complete"
end end
scenario "Should update loading bar style after unvalid file upload", :js do scenario "Should update loading bar style after invalid file upload", :js do
login_as user login_as user
visit send(path, arguments) visit send(path, arguments)
@@ -112,8 +118,12 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
click_link "Add image" click_link "Add image"
click_on submit_button click_on submit_button
within "#nested-image .image" do if has_many_images
expect(page).to have_content("can't be blank", count: 2) #Pending. Review soon and test
else
within "#nested-image .image" do
expect(page).to have_content("can't be blank", count: 2)
end
end end
end end
@@ -159,8 +169,12 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
click_on submit_button click_on submit_button
imageable_redirected_to_resource_show_or_navigate_to imageable_redirected_to_resource_show_or_navigate_to
expect(page).to have_selector "figure img" if has_many_images
expect(page).to have_selector "figure figcaption" #Pending. Review soon and test
else
expect(page).to have_selector "figure img"
expect(page).to have_selector "figure figcaption"
end
end end
if path.include? "edit" if path.include? "edit"