Merge branch 'master' into aperez-edit-poll-question-answers

This commit is contained in:
Raimond Garcia
2017-10-06 18:47:04 +02:00
committed by GitHub
14 changed files with 122 additions and 26 deletions

View File

@@ -23,7 +23,8 @@ class Admin::Poll::Questions::Answers::ImagesController < Admin::Poll::BaseContr
private
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
def load_answer

View File

@@ -1,6 +1,6 @@
class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController
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"
@@ -30,21 +30,24 @@ class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController
redirect_to admin_answer_path(@answer),
notice: t("flash.actions.save_changes.notice")
else
render :edit
redirect_to :back
end
end
def documents
@documents = @answer.documents
render 'admin/poll/questions/answers/documents'
end
private
def answer_params
params.require(:poll_question_answer).permit(:title, :description, :question_id)
end
def load_question
@question = ::Poll::Question.find(params[: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_answer
@answer = ::Poll::Question::Answer.find(params[:id])
@answer = ::Poll::Question::Answer.find(params[:id] || params[:answer_id])
end
end

View File

@@ -19,7 +19,9 @@ class DirectUpload
if @resource_type.present? && @resource_relation.present? && (@attachment.present? || @cached_attachment.present?)
@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)
elsif @resource.class.reflections[@resource_relation].macro == :has_one
@relation = @resource.send("build_#{resource_relation}", relation_attributtes)

View File

@@ -1,5 +1,10 @@
class Poll::Question::Answer < ActiveRecord::Base
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'
has_many :videos, class_name: 'Poll::Question::Answer::Video'

View File

@@ -53,7 +53,6 @@
</li>
<% end %>
<% if feature?(:polls) %>
<li class="section-title">
<a href="#">

View File

@@ -21,7 +21,7 @@
<tbody>
<% @officer_assignments.each do |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>
</tr>
<% end %>

View File

@@ -12,7 +12,7 @@
ckeditor: { language: I18n.locale } %>
</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")) %>
</div>

View 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>

View File

@@ -31,7 +31,7 @@
<table class="margin-top">
<tr>
<th colspan="3" class="with-button">
<th colspan="5" 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),
@@ -41,9 +41,10 @@
<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>
<th><%= t("admin.questions.show.answers.videos") %></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>
<% @question.question_answers.each do |answer| %>
@@ -51,12 +52,22 @@
<td><%= link_to answer.title, admin_answer_path(answer) %></td>
<td><%= answer.description %></td>
<td class="text-center">
(<%= answer.images.count %>)<br>
(<%= answer.images.count %>)
<br>
<%= link_to t("admin.questions.show.answers.images_list"),
admin_answer_images_path(answer) %></td>
<td><%= link_to t("admin.questions.show.answers.video_list",
admin_answer_images_path(answer) %>
</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),
admin_answer_videos_path(answer) %></td>
admin_answer_videos_path(answer) %>
</td>
</tr>
<% end %>
</table>

View File

@@ -608,6 +608,10 @@ en:
video_list: Video list (%{count})
images: Images
images_list: Images list
documents: Documents
documents_list: Documents list
document_title: Title
document_actions: Actions
answers:
new:
title: New answer

View File

@@ -601,7 +601,6 @@ es:
valid_answers: Respuestas válidas
add_answer: Añadir respuesta
video_url: Video externo
preview: Ver en la web
answers:
title: Respuesta
description: Descripción
@@ -609,6 +608,10 @@ es:
video_list: Lista de vídeos (%{count})
images: Imágenes
images_list: Lista de imágenes
documents: Documentos
documents_list: Lista de documentos
document_title: Título
document_actions: Acciones
answers:
new:
title: Nueva respuesta

View File

@@ -301,9 +301,10 @@ Rails.application.routes.draw do
end
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 :videos, controller: 'questions/answers/videos'
get :documents, to: 'questions/answers#documents'
end
end
end

View File

@@ -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")
click_on submit_button
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
scenario "Should show resource with new document after successful creation with maximum allowed uploaded files", :js do

View File

@@ -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
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
end
end
scenario "Should show successful notice when resource filled correctly and after valid file uploads", :js do
login_as user