Merge branch 'master' into aperez-edit-poll-question-answers
This commit is contained in:
@@ -23,7 +23,8 @@ class Admin::Poll::Questions::Answers::ImagesController < Admin::Poll::BaseContr
|
|||||||
private
|
private
|
||||||
|
|
||||||
def images_params
|
def images_params
|
||||||
params.permit(images_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy])
|
params.require(:poll_question_answer).permit(:answer_id,
|
||||||
|
images_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy])
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_answer
|
def load_answer
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController
|
class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController
|
||||||
before_action :load_question, except: [:show, :edit, :update]
|
before_action :load_question, except: [:show, :edit, :update]
|
||||||
before_action :load_answer, only: [:show, :edit, :update]
|
before_action :load_answer, only: [:show, :edit, :update, :documents]
|
||||||
|
|
||||||
load_and_authorize_resource :question, class: "::Poll::Question"
|
load_and_authorize_resource :question, class: "::Poll::Question"
|
||||||
|
|
||||||
@@ -30,21 +30,24 @@ class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController
|
|||||||
redirect_to admin_answer_path(@answer),
|
redirect_to admin_answer_path(@answer),
|
||||||
notice: t("flash.actions.save_changes.notice")
|
notice: t("flash.actions.save_changes.notice")
|
||||||
else
|
else
|
||||||
render :edit
|
redirect_to :back
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def documents
|
||||||
|
@documents = @answer.documents
|
||||||
|
|
||||||
|
render 'admin/poll/questions/answers/documents'
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def answer_params
|
def answer_params
|
||||||
params.require(:poll_question_answer).permit(:title, :description, :question_id)
|
params.require(:poll_question_answer).permit(:title, :description, :question_id, documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy])
|
||||||
end
|
|
||||||
|
|
||||||
def load_question
|
|
||||||
@question = ::Poll::Question.find(params[:question_id])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_answer
|
def load_answer
|
||||||
@answer = ::Poll::Question::Answer.find(params[:id])
|
@answer = ::Poll::Question::Answer.find(params[:id] || params[:answer_id])
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -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.respond_to?(:images)
|
#Refactor
|
||||||
|
if @resource.respond_to?(:images) &&
|
||||||
|
((@attachment.present? && !@attachment.content_type.match(/pdf/)) || @cached_attachment.present?)
|
||||||
@relation = @resource.images.send("build", relation_attributtes)
|
@relation = @resource.images.send("build", relation_attributtes)
|
||||||
elsif @resource.class.reflections[@resource_relation].macro == :has_one
|
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)
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
class Poll::Question::Answer < ActiveRecord::Base
|
class Poll::Question::Answer < ActiveRecord::Base
|
||||||
include Galleryable
|
include Galleryable
|
||||||
|
include Documentable
|
||||||
|
documentable max_documents_allowed: 3,
|
||||||
|
max_file_size: 3.megabytes,
|
||||||
|
accepted_content_types: [ "application/pdf" ]
|
||||||
|
accepts_nested_attributes_for :documents, allow_destroy: true
|
||||||
|
|
||||||
belongs_to :question, class_name: 'Poll::Question', foreign_key: 'question_id'
|
belongs_to :question, class_name: 'Poll::Question', foreign_key: 'question_id'
|
||||||
has_many :videos, class_name: 'Poll::Question::Answer::Video'
|
has_many :videos, class_name: 'Poll::Question::Answer::Video'
|
||||||
|
|||||||
@@ -53,7 +53,6 @@
|
|||||||
</li>
|
</li>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
|
||||||
<% if feature?(:polls) %>
|
<% if feature?(:polls) %>
|
||||||
<li class="section-title">
|
<li class="section-title">
|
||||||
<a href="#">
|
<a href="#">
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
<% @officer_assignments.each do |officer_assignment| %>
|
<% @officer_assignments.each do |officer_assignment| %>
|
||||||
<tr id="<%= dom_id officer_assignment %>">
|
<tr id="<%= dom_id officer_assignment %>">
|
||||||
<td><%= officer_assignment.final? ? t('polls.final_date') : l(officer_assignment.date.to_date) %></td>
|
<td><%= l(officer_assignment.date.to_date)%> <%= content_tag :strong, t('polls.final_date') if officer_assignment.final %></td>
|
||||||
<td><%= booth_name_with_location(officer_assignment.booth_assignment.booth) %></td>
|
<td><%= booth_name_with_location(officer_assignment.booth_assignment.booth) %></td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
ckeditor: { language: I18n.locale } %>
|
ckeditor: { language: I18n.locale } %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="small-12 medium-6 large-4">
|
<div class="small-12 medium-6 large-4 margin-top">
|
||||||
<%= f.submit(class: "button expanded", value: t("shared.save")) %>
|
<%= f.submit(class: "button expanded", value: t("shared.save")) %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
55
app/views/admin/poll/questions/answers/documents.html.erb
Normal file
55
app/views/admin/poll/questions/answers/documents.html.erb
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
<%= back_link_to %>
|
||||||
|
|
||||||
|
<h2><%= t("admin.questions.show.answers.documents_list") %></h2>
|
||||||
|
|
||||||
|
<ul class="breadcrumbs">
|
||||||
|
<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 %>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="small-12 column">
|
||||||
|
<div class="documents small-12">
|
||||||
|
<%= render 'documents/nested_documents', documentable: @answer, f: f %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="actions small-12 medium-4 margin-top">
|
||||||
|
<%= f.submit(class: "button expanded", value: t("shared.save")) %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<% if @answer.documents.present? %>
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th scope="col"><%= t("admin.questions.show.answers.document_title") %></th>
|
||||||
|
<th scope="col" class="text-right"><%= t("admin.questions.show.answers.document_actions") %></th>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<% @answer.documents.each do |document| %>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<%= link_to document.title, document.attachment.url %>
|
||||||
|
</td>
|
||||||
|
<td class="text-right">
|
||||||
|
<%= link_to t('documents.buttons.download_document'),
|
||||||
|
document.attachment.url,
|
||||||
|
target: "_blank",
|
||||||
|
rel: "nofollow",
|
||||||
|
class: 'button hollow' %>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</table>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
|
|
||||||
<table class="margin-top">
|
<table class="margin-top">
|
||||||
<tr>
|
<tr>
|
||||||
<th colspan="3" class="with-button">
|
<th colspan="5" scope="col" class="with-button">
|
||||||
<%= t('admin.questions.show.valid_answers') %>
|
<%= t('admin.questions.show.valid_answers') %>
|
||||||
<%= link_to t("admin.questions.show.add_answer"),
|
<%= link_to t("admin.questions.show.add_answer"),
|
||||||
new_admin_question_answer_path(@question),
|
new_admin_question_answer_path(@question),
|
||||||
@@ -41,9 +41,10 @@
|
|||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<th><%= t("admin.questions.show.answers.title") %></th>
|
<th><%= t("admin.questions.show.answers.title") %></th>
|
||||||
<th class="medium-7"><%= t("admin.questions.show.answers.description") %></th>
|
<th scope="col" class="medium-7"><%= t("admin.questions.show.answers.description") %></th>
|
||||||
<th class="text-center"><%= t("admin.questions.show.answers.images") %></th>
|
<th scope="col" class="text-center"><%= t("admin.questions.show.answers.images") %></th>
|
||||||
<th><%= t("admin.questions.show.answers.videos") %></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>
|
</tr>
|
||||||
|
|
||||||
<% @question.question_answers.each do |answer| %>
|
<% @question.question_answers.each do |answer| %>
|
||||||
@@ -51,12 +52,22 @@
|
|||||||
<td><%= link_to answer.title, admin_answer_path(answer) %></td>
|
<td><%= link_to answer.title, admin_answer_path(answer) %></td>
|
||||||
<td><%= answer.description %></td>
|
<td><%= answer.description %></td>
|
||||||
<td class="text-center">
|
<td class="text-center">
|
||||||
(<%= answer.images.count %>)<br>
|
(<%= answer.images.count %>)
|
||||||
|
<br>
|
||||||
<%= link_to t("admin.questions.show.answers.images_list"),
|
<%= link_to t("admin.questions.show.answers.images_list"),
|
||||||
admin_answer_images_path(answer) %></td>
|
admin_answer_images_path(answer) %>
|
||||||
<td><%= link_to t("admin.questions.show.answers.video_list",
|
</td>
|
||||||
|
<td class="text-center">
|
||||||
|
(<%= answer.documents.count rescue 0 %>)
|
||||||
|
<br>
|
||||||
|
<%= link_to t("admin.questions.show.answers.documents_list"),
|
||||||
|
admin_answer_documents_path(answer) %>
|
||||||
|
</td>
|
||||||
|
<td class="text-center">
|
||||||
|
<%= link_to t("admin.questions.show.answers.video_list",
|
||||||
count: answer.videos.count),
|
count: answer.videos.count),
|
||||||
admin_answer_videos_path(answer) %></td>
|
admin_answer_videos_path(answer) %>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
@@ -608,6 +608,10 @@ en:
|
|||||||
video_list: Video list (%{count})
|
video_list: Video list (%{count})
|
||||||
images: Images
|
images: Images
|
||||||
images_list: Images list
|
images_list: Images list
|
||||||
|
documents: Documents
|
||||||
|
documents_list: Documents list
|
||||||
|
document_title: Title
|
||||||
|
document_actions: Actions
|
||||||
answers:
|
answers:
|
||||||
new:
|
new:
|
||||||
title: New answer
|
title: New answer
|
||||||
|
|||||||
@@ -601,7 +601,6 @@ es:
|
|||||||
valid_answers: Respuestas válidas
|
valid_answers: Respuestas válidas
|
||||||
add_answer: Añadir respuesta
|
add_answer: Añadir respuesta
|
||||||
video_url: Video externo
|
video_url: Video externo
|
||||||
preview: Ver en la web
|
|
||||||
answers:
|
answers:
|
||||||
title: Respuesta
|
title: Respuesta
|
||||||
description: Descripción
|
description: Descripción
|
||||||
@@ -609,6 +608,10 @@ es:
|
|||||||
video_list: Lista de vídeos (%{count})
|
video_list: Lista de vídeos (%{count})
|
||||||
images: Imágenes
|
images: Imágenes
|
||||||
images_list: Lista de imágenes
|
images_list: Lista de imágenes
|
||||||
|
documents: Documentos
|
||||||
|
documents_list: Lista de documentos
|
||||||
|
document_title: Título
|
||||||
|
document_actions: Acciones
|
||||||
answers:
|
answers:
|
||||||
new:
|
new:
|
||||||
title: Nueva respuesta
|
title: Nueva respuesta
|
||||||
|
|||||||
@@ -301,9 +301,10 @@ Rails.application.routes.draw do
|
|||||||
end
|
end
|
||||||
|
|
||||||
resources :questions, shallow: true do
|
resources :questions, shallow: true do
|
||||||
resources :answers, except: [:index, :destroy, :delete], controller: 'questions/answers', shallow: true do
|
resources :answers, except: [:index, :destroy], controller: 'questions/answers', shallow: true do
|
||||||
resources :images, controller: 'questions/answers/images'
|
resources :images, controller: 'questions/answers/images'
|
||||||
resources :videos, controller: 'questions/answers/videos'
|
resources :videos, controller: 'questions/answers/videos'
|
||||||
|
get :documents, to: 'questions/answers#documents'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -191,9 +191,17 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
|
|||||||
|
|
||||||
documentable_attach_new_file(documentable_factory_name, 0, "spec/fixtures/files/empty.pdf")
|
documentable_attach_new_file(documentable_factory_name, 0, "spec/fixtures/files/empty.pdf")
|
||||||
click_on submit_button
|
click_on submit_button
|
||||||
|
|
||||||
documentable_redirected_to_resource_show_or_navigate_to
|
documentable_redirected_to_resource_show_or_navigate_to
|
||||||
|
|
||||||
expect(page).to have_content "Documents (1)"
|
expect(page).to have_content "Documents"
|
||||||
|
|
||||||
|
find("#tab-documents-label").click
|
||||||
|
expect(page).to have_content "empty.pdf"
|
||||||
|
|
||||||
|
#Review
|
||||||
|
#Doble check why the file is stored with a name different to empty.pdf
|
||||||
|
expect(page).to have_css("a[href$='.pdf']")
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Should show resource with new document after successful creation with maximum allowed uploaded files", :js do
|
scenario "Should show resource with new document after successful creation with maximum allowed uploaded files", :js do
|
||||||
|
|||||||
@@ -146,8 +146,12 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
|
|||||||
send(fill_resource_method_name) if fill_resource_method_name
|
send(fill_resource_method_name) if fill_resource_method_name
|
||||||
click_on submit_button
|
click_on submit_button
|
||||||
|
|
||||||
|
if has_many_images
|
||||||
|
skip "no need to test, there are no attributes for the parent resource"
|
||||||
|
else
|
||||||
expect(page).to have_content imageable_success_notice
|
expect(page).to have_content imageable_success_notice
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
scenario "Should show successful notice when resource filled correctly and after valid file uploads", :js do
|
scenario "Should show successful notice when resource filled correctly and after valid file uploads", :js do
|
||||||
login_as user
|
login_as user
|
||||||
|
|||||||
Reference in New Issue
Block a user