Merge pull request #1835 from consul/1677-poll_questions_documents
Poll questions document and video
This commit is contained in:
@@ -314,6 +314,7 @@
|
||||
|
||||
.debate-show,
|
||||
.proposal-show,
|
||||
.poll-question-show,
|
||||
.investment-project-show,
|
||||
.budget-investment-show,
|
||||
.polls-show,
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
class Admin::Poll::QuestionsController < Admin::BaseController
|
||||
include CommentableActions
|
||||
|
||||
load_and_authorize_resource :poll
|
||||
load_and_authorize_resource :question, class: 'Poll::Question'
|
||||
|
||||
@@ -20,6 +22,7 @@ class Admin::Poll::QuestionsController < Admin::BaseController
|
||||
|
||||
def create
|
||||
@question.author = @question.proposal.try(:author) || current_user
|
||||
recover_documents_from_cache(@question)
|
||||
|
||||
if @question.save
|
||||
redirect_to admin_question_path(@question)
|
||||
@@ -29,6 +32,7 @@ class Admin::Poll::QuestionsController < Admin::BaseController
|
||||
end
|
||||
|
||||
def show
|
||||
@document = Document.new(documentable: @question)
|
||||
end
|
||||
|
||||
def edit
|
||||
@@ -54,7 +58,8 @@ class Admin::Poll::QuestionsController < Admin::BaseController
|
||||
private
|
||||
|
||||
def question_params
|
||||
params.require(:poll_question).permit(:poll_id, :title, :question, :description, :proposal_id, :valid_answers)
|
||||
params.require(:poll_question).permit(:poll_id, :title, :question, :description, :proposal_id, :valid_answers, :video_url,
|
||||
documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id])
|
||||
end
|
||||
|
||||
def search_params
|
||||
|
||||
@@ -10,6 +10,8 @@ class Polls::QuestionsController < ApplicationController
|
||||
@comment_tree = CommentTree.new(@commentable, params[:page], @current_order)
|
||||
set_comment_flags(@comment_tree.comments)
|
||||
|
||||
@document = Document.new(documentable: @question)
|
||||
|
||||
question_answer = @question.answers.where(author_id: current_user.try(:id)).first
|
||||
@answers_by_question_id = {@question.id => question_answer.try(:answer)}
|
||||
end
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
class Poll::Question < ActiveRecord::Base
|
||||
include Measurable
|
||||
include Searchable
|
||||
include Documentable
|
||||
documentable max_documents_allowed: 1,
|
||||
max_file_size: 3.megabytes,
|
||||
accepted_content_types: [ "application/pdf" ]
|
||||
accepts_nested_attributes_for :documents, allow_destroy: true
|
||||
|
||||
acts_as_paranoid column: :hidden_at
|
||||
include ActsAsParanoidAliases
|
||||
|
||||
@@ -26,6 +26,17 @@
|
||||
ckeditor: { language: I18n.locale } %>
|
||||
</div>
|
||||
|
||||
<div class="documents small-12" data-max-documents="<%= Poll::Question.max_documents_allowed %>">
|
||||
<%= render 'documents/nested_documents', documentable: @question %>
|
||||
</div>
|
||||
|
||||
<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="row">
|
||||
<div class="actions small-12 medium-4 column margin-top">
|
||||
<%= f.submit(class: "button expanded", value: t("shared.save")) %>
|
||||
|
||||
@@ -40,6 +40,21 @@
|
||||
<%= @question.description %>
|
||||
</p>
|
||||
|
||||
<% 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 %>
|
||||
|
||||
<% if @question.documents.any? %>
|
||||
<p>
|
||||
<strong><%= t("admin.questions.show.documents") %></strong>
|
||||
<br>
|
||||
<a href="<%= @question.documents.first.attachment.url %>"><%= @question.documents.first.title %></a>
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
<%= link_to t("admin.questions.show.preview"), question_path(@question) %>
|
||||
</div>
|
||||
|
||||
22
app/views/polls/questions/_filter_subnav.html.erb
Normal file
22
app/views/polls/questions/_filter_subnav.html.erb
Normal file
@@ -0,0 +1,22 @@
|
||||
<div class="row">
|
||||
<div class="small-12 column">
|
||||
<ul class="tabs" data-tabs id="questions-tabs">
|
||||
<li class="tabs-title is-active">
|
||||
<%= link_to "#tab-comments" do %>
|
||||
<h3>
|
||||
<%= t("proposals.show.comments_tab") %>
|
||||
<span class="js-comments-count">(<%= @question.comments_count %>)</span>
|
||||
</h3>
|
||||
<% end %>
|
||||
</li>
|
||||
<li class="tabs-title">
|
||||
<%= link_to "#tab-documents" do %>
|
||||
<h3>
|
||||
<%= t("documents.tab") %>
|
||||
(<%= @question.documents.count %>)
|
||||
</h3>
|
||||
<% end %>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@@ -55,6 +55,21 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<% if @question.video_url.present? %>
|
||||
<div class="row margin-top poll-question-show">
|
||||
<div class="small-12 medium-9 column">
|
||||
<div class="video-link">
|
||||
<p>
|
||||
<span class="icon-video"></span>
|
||||
<strong><%= t('proposals.show.title_video_url') %></strong>
|
||||
</p>
|
||||
<%= text_with_links @question.video_url %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<% end %>
|
||||
|
||||
<div class="row margin-top">
|
||||
<div class="small-12 medium-9 column">
|
||||
<h3><%= t('poll_questions.show.more_info') %></h3>
|
||||
@@ -62,4 +77,16 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%= render "comments" %>
|
||||
<div class="tabs-content" data-tabs-content="questions-tabs" role="tablist">
|
||||
<%= render "polls/questions/filter_subnav" %>
|
||||
|
||||
<div class="tabs-panel is-active" id="tab-comments">
|
||||
<%= render "polls/questions/comments" %>
|
||||
</div>
|
||||
|
||||
<div class="tabs-panel" id="tab-documents">
|
||||
<%= render 'documents/documents',
|
||||
documents: @question.documents,
|
||||
max_documents_allowed: Poll::Question.max_documents_allowed %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -596,6 +596,8 @@ en:
|
||||
title: Title
|
||||
valid_answers: Valid answers
|
||||
description: Description
|
||||
video_url: External video
|
||||
documents: Documents
|
||||
preview: View on website
|
||||
recounts:
|
||||
index:
|
||||
|
||||
@@ -596,6 +596,8 @@ es:
|
||||
title: Título
|
||||
valid_answers: Respuestas válidas
|
||||
description: Descripción
|
||||
video_url: Video externo
|
||||
documents: Documentos
|
||||
preview: Ver en la web
|
||||
recounts:
|
||||
index:
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddVideoUrlToPollQuestions < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :poll_questions, :video_url, :string
|
||||
end
|
||||
end
|
||||
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20170822144743) do
|
||||
ActiveRecord::Schema.define(version: 20170905111444) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@@ -669,6 +669,7 @@ ActiveRecord::Schema.define(version: 20170822144743) do
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.tsvector "tsv"
|
||||
t.string "video_url"
|
||||
end
|
||||
|
||||
add_index "poll_questions", ["author_id"], name: "index_poll_questions_on_author_id", using: :btree
|
||||
@@ -971,7 +972,7 @@ ActiveRecord::Schema.define(version: 20170822144743) do
|
||||
t.boolean "email_digest", default: true
|
||||
t.boolean "email_on_direct_message", default: true
|
||||
t.boolean "official_position_badge", default: false
|
||||
t.datetime "password_changed_at", default: '2017-08-07 11:14:09', null: false
|
||||
t.datetime "password_changed_at", default: '2017-09-06 18:19:39', null: false
|
||||
t.boolean "created_from_signature", default: false
|
||||
t.integer "failed_email_digests_count", default: 0
|
||||
t.text "former_users_data_log", default: ""
|
||||
|
||||
@@ -380,6 +380,10 @@ FactoryGirl.define do
|
||||
trait :budget_investment_document do
|
||||
association :documentable, factory: :budget_investment
|
||||
end
|
||||
|
||||
trait :poll_question_document do
|
||||
association :documentable, factory: :poll_question
|
||||
end
|
||||
end
|
||||
|
||||
factory :comment do
|
||||
|
||||
@@ -38,6 +38,7 @@ feature 'Admin poll questions' do
|
||||
Pursued by the Empire's sinister agents, Princess Leia races home aboard her starship, custodian of the stolen plans that can save her
|
||||
people and restore freedom to the galaxy....
|
||||
}
|
||||
video_url = "https://puppyvideos.com"
|
||||
|
||||
visit admin_questions_path
|
||||
click_link "Create question"
|
||||
@@ -45,11 +46,13 @@ feature 'Admin poll questions' do
|
||||
select 'Movies', from: 'poll_question_poll_id'
|
||||
fill_in 'poll_question_title', with: title
|
||||
fill_in 'poll_question_description', with: description
|
||||
fill_in 'poll_question_video_url', with: video_url
|
||||
|
||||
click_button 'Save'
|
||||
|
||||
expect(page).to have_content(title)
|
||||
expect(page).to have_content(description)
|
||||
expect(page).to have_content(video_url)
|
||||
end
|
||||
|
||||
scenario 'Create from successful proposal index' do
|
||||
|
||||
@@ -25,6 +25,25 @@ feature 'Poll Questions' do
|
||||
expect(page).to have_content(question_with_author_visible_name.author_visible_name)
|
||||
end
|
||||
|
||||
scenario '#show view has video_url present' do
|
||||
poll = create(:poll)
|
||||
normal_question = create(:poll_question, poll: poll, video_url: "https://puppyvideos.com")
|
||||
|
||||
visit question_path(normal_question)
|
||||
|
||||
expect(page).to have_link(normal_question.video_url)
|
||||
end
|
||||
|
||||
scenario '#show view has document present' do
|
||||
poll = create(:poll)
|
||||
normal_question = create(:poll_question, poll: poll)
|
||||
document = create(:document, documentable: normal_question)
|
||||
|
||||
visit question_path(normal_question)
|
||||
|
||||
expect(page).to have_content(document.title)
|
||||
end
|
||||
|
||||
context 'Answering' do
|
||||
let(:geozone) { create(:geozone) }
|
||||
let(:poll) { create(:poll, geozone_restricted: true, geozone_ids: [geozone.id]) }
|
||||
|
||||
@@ -14,9 +14,11 @@ describe "Abilities::Administrator" do
|
||||
let(:proposal) { create(:proposal) }
|
||||
let(:budget_investment) { create(:budget_investment) }
|
||||
let(:legislation_question) { create(:legislation_question) }
|
||||
let(:poll_question) { create(:poll_question) }
|
||||
|
||||
let(:proposal_document) { build(:document, documentable: proposal) }
|
||||
let(:budget_investment_document) { build(:document, documentable: budget_investment) }
|
||||
let(:poll_question_document) { build(:document, documentable: poll_question) }
|
||||
|
||||
let(:hidden_debate) { create(:debate, :hidden) }
|
||||
let(:hidden_comment) { create(:comment, :hidden) }
|
||||
@@ -83,4 +85,8 @@ describe "Abilities::Administrator" do
|
||||
it { should be_able_to(:new, budget_investment_document) }
|
||||
it { should be_able_to(:create, budget_investment_document) }
|
||||
it { should be_able_to(:destroy, budget_investment_document) }
|
||||
|
||||
it { should be_able_to(:new, poll_question_document) }
|
||||
it { should be_able_to(:create, poll_question_document) }
|
||||
it { should be_able_to(:destroy, poll_question_document) }
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user