Add controllers/views for Poll::Question::Answer::Video
This commit is contained in:
@@ -0,0 +1,57 @@
|
|||||||
|
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]
|
||||||
|
|
||||||
|
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")
|
||||||
|
else
|
||||||
|
render :new
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
if @video.update(video_params)
|
||||||
|
redirect_to admin_answer_videos_path(@video.answer_id),
|
||||||
|
notice: t("flash.actions.save_changes.notice")
|
||||||
|
else
|
||||||
|
render :edit
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
if @video.destroy
|
||||||
|
notice = t("flash.actions.destroy.poll_question_answer_video")
|
||||||
|
else
|
||||||
|
notice = t("flash.actions.destroy.error")
|
||||||
|
end
|
||||||
|
redirect_to :back, notice: notice
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def video_params
|
||||||
|
params.require(:poll_question_answer_video).permit(: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])
|
||||||
|
end
|
||||||
|
end
|
||||||
21
app/views/admin/poll/questions/answers/videos/_form.html.erb
Normal file
21
app/views/admin/poll/questions/answers/videos/_form.html.erb
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<%= form_for(@video, url: form_url) do |f| %>
|
||||||
|
|
||||||
|
<%= render 'shared/errors', resource: @video %>
|
||||||
|
|
||||||
|
<%= f.hidden_field :answer_id, value: @video.answer_id || @answer.id %>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="small-12 column">
|
||||||
|
|
||||||
|
<%= f.text_field :title %>
|
||||||
|
<%= f.text_field :url %>
|
||||||
|
|
||||||
|
<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>
|
||||||
|
<% end %>
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<%= back_link_to %>
|
||||||
|
|
||||||
|
<h2>
|
||||||
|
<%= t("admin.answers.videos.edit.title") %>
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
<div class="poll-question-answer-video-form">
|
||||||
|
<%= render "form", form_url: admin_video_path(@video) %>
|
||||||
|
</div>
|
||||||
47
app/views/admin/poll/questions/answers/videos/index.html.erb
Normal file
47
app/views/admin/poll/questions/answers/videos/index.html.erb
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
<%= back_link_to admin_question_path(@answer.question_id) %>
|
||||||
|
|
||||||
|
<div class="clear"></div>
|
||||||
|
|
||||||
|
<h2 class="inline-block">
|
||||||
|
<%= t("admin.answers.videos.index.title") %>
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
<%= link_to t("admin.answers.videos.index.add_video"),
|
||||||
|
new_admin_answer_video_path,
|
||||||
|
class: "button success float-right" %>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th><%= t("admin.answers.videos.index.video_title") %></th>
|
||||||
|
<th><%= t("admin.answers.videos.index.video_url") %></th>
|
||||||
|
<th class="text-right">
|
||||||
|
<%= t("admin.actions.actions") %>
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
|
||||||
|
<tbody>
|
||||||
|
<% @answer.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>
|
||||||
|
<td class="text-right">
|
||||||
|
|
||||||
|
<%= link_to t("shared.edit"),
|
||||||
|
edit_admin_video_path(video),
|
||||||
|
class: "button hollow" %>
|
||||||
|
|
||||||
|
<%= link_to t("shared.delete"),
|
||||||
|
admin_video_path(video),
|
||||||
|
class: "button hollow alert",
|
||||||
|
method: :delete %>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<%= back_link_to admin_answer_videos_path(@answer) %>
|
||||||
|
|
||||||
|
<h2>
|
||||||
|
<%= t('admin.answers.videos.new.title') %>
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
<div class="poll-question-answer-video-form">
|
||||||
|
<%= render "form", form_url: admin_answer_videos_path %>
|
||||||
|
</div>
|
||||||
@@ -24,13 +24,13 @@
|
|||||||
<%= link_to @question.author.name, user_path(@question.author) %>
|
<%= link_to @question.author.name, user_path(@question.author) %>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<table cellspacing="0" cellpadding="0">
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th colspan="1" scope="col">
|
<th>
|
||||||
<%= t('admin.questions.show.valid_answers') %>
|
<%= t('admin.questions.show.valid_answers') %>
|
||||||
</th>
|
</th>
|
||||||
<th colspan="2" scope="col">
|
<th colspan="2">
|
||||||
<%= 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),
|
||||||
class: "button hollow float-right" %>
|
class: "button hollow float-right" %>
|
||||||
@@ -38,9 +38,9 @@
|
|||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col"><%= t("admin.questions.show.answers.title") %></th>
|
<th><%= t("admin.questions.show.answers.title") %></th>
|
||||||
<th scope="col"><%= t("admin.questions.show.answers.description") %></th>
|
<th><%= t("admin.questions.show.answers.description") %></th>
|
||||||
<th scope="col"><%= t("admin.questions.show.answers.videos") %></th>
|
<th><%= t("admin.questions.show.answers.videos") %></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
||||||
@@ -49,7 +49,9 @@
|
|||||||
<tr id="<%= dom_id(answer) %>" class="poll_question_answer">
|
<tr id="<%= dom_id(answer) %>" class="poll_question_answer">
|
||||||
<td><%= answer.title %></td>
|
<td><%= answer.title %></td>
|
||||||
<td><%= answer.description %></td>
|
<td><%= answer.description %></td>
|
||||||
<td><%= link_to t("admin.questions.show.answers.video_list", count: 0), "#" %></td>
|
<td><%= link_to t("admin.questions.show.answers.video_list",
|
||||||
|
count: answer.videos.count),
|
||||||
|
admin_answer_videos_path(answer) %></td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
@@ -216,6 +216,9 @@ en:
|
|||||||
poll/question/answer:
|
poll/question/answer:
|
||||||
title: "Answer"
|
title: "Answer"
|
||||||
description: "Description"
|
description: "Description"
|
||||||
|
poll/question/answer/video:
|
||||||
|
title: Title
|
||||||
|
url: External video
|
||||||
errors:
|
errors:
|
||||||
models:
|
models:
|
||||||
user:
|
user:
|
||||||
|
|||||||
@@ -602,7 +602,17 @@ en:
|
|||||||
video_list: Video list (%{count})
|
video_list: Video list (%{count})
|
||||||
answers:
|
answers:
|
||||||
new:
|
new:
|
||||||
title: "New answer"
|
title: New answer
|
||||||
|
videos:
|
||||||
|
index:
|
||||||
|
title: Videos
|
||||||
|
add_video: Add video
|
||||||
|
video_title: Title
|
||||||
|
video_url: External video
|
||||||
|
new:
|
||||||
|
title: New video
|
||||||
|
edit:
|
||||||
|
title: Edit video
|
||||||
recounts:
|
recounts:
|
||||||
index:
|
index:
|
||||||
title: "Recounts"
|
title: "Recounts"
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ en:
|
|||||||
poll: "Poll created successfully."
|
poll: "Poll created successfully."
|
||||||
poll_booth: "Booth created successfully."
|
poll_booth: "Booth created successfully."
|
||||||
poll_question_answer: "Answer created successfully"
|
poll_question_answer: "Answer created successfully"
|
||||||
|
poll_question_answer_video: "Video created successfully"
|
||||||
proposal: "Proposal created successfully."
|
proposal: "Proposal created successfully."
|
||||||
proposal_notification: "Your message has been sent correctly."
|
proposal_notification: "Your message has been sent correctly."
|
||||||
spending_proposal: "Spending proposal created successfully. You can access it from %{activity}"
|
spending_proposal: "Spending proposal created successfully. You can access it from %{activity}"
|
||||||
@@ -31,3 +32,4 @@ en:
|
|||||||
budget_investment: "Investment project deleted succesfully."
|
budget_investment: "Investment project deleted succesfully."
|
||||||
error: "Could not delete"
|
error: "Could not delete"
|
||||||
topic: "Topic deleted successfully."
|
topic: "Topic deleted successfully."
|
||||||
|
poll_question_answer_video: "Answer video deleted successfully."
|
||||||
|
|||||||
@@ -210,6 +210,9 @@ es:
|
|||||||
poll/question/answer:
|
poll/question/answer:
|
||||||
title: "Respuesta"
|
title: "Respuesta"
|
||||||
description: "Descripción"
|
description: "Descripción"
|
||||||
|
poll/question/answer/video:
|
||||||
|
title: Título
|
||||||
|
url: Vídeo externo
|
||||||
errors:
|
errors:
|
||||||
models:
|
models:
|
||||||
user:
|
user:
|
||||||
|
|||||||
@@ -606,6 +606,16 @@ es:
|
|||||||
title: "Nueva respuesta"
|
title: "Nueva respuesta"
|
||||||
video_url: Video externo
|
video_url: Video externo
|
||||||
documents: Documentos (1)
|
documents: Documentos (1)
|
||||||
|
videos:
|
||||||
|
index:
|
||||||
|
title: Vídeos
|
||||||
|
add_video: Añadir vídeo
|
||||||
|
video_title: Título
|
||||||
|
video_url: External video
|
||||||
|
new:
|
||||||
|
title: Nuevo video
|
||||||
|
edit:
|
||||||
|
title: Editar vídeo
|
||||||
recounts:
|
recounts:
|
||||||
index:
|
index:
|
||||||
title: "Recuentos"
|
title: "Recuentos"
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ es:
|
|||||||
poll: "Votación creada correctamente."
|
poll: "Votación creada correctamente."
|
||||||
poll_booth: "Urna creada correctamente."
|
poll_booth: "Urna creada correctamente."
|
||||||
poll_question_answer: "Respuesta creada correctamente"
|
poll_question_answer: "Respuesta creada correctamente"
|
||||||
|
poll_question_answer_video: "Vídeo creado correctamente"
|
||||||
proposal: "Propuesta creada correctamente."
|
proposal: "Propuesta creada correctamente."
|
||||||
proposal_notification: "Tu message ha sido enviado correctamente."
|
proposal_notification: "Tu message ha sido enviado correctamente."
|
||||||
spending_proposal: "Propuesta de inversión creada correctamente. Puedes acceder a ella desde %{activity}"
|
spending_proposal: "Propuesta de inversión creada correctamente. Puedes acceder a ella desde %{activity}"
|
||||||
@@ -31,3 +32,4 @@ es:
|
|||||||
budget_investment: "Propuesta de inversión eliminada."
|
budget_investment: "Propuesta de inversión eliminada."
|
||||||
error: "No se pudo borrar"
|
error: "No se pudo borrar"
|
||||||
topic: "Tema eliminado."
|
topic: "Tema eliminado."
|
||||||
|
poll_question_answer_video: "Vídeo de respuesta eliminado."
|
||||||
|
|||||||
@@ -150,6 +150,9 @@ fr:
|
|||||||
poll/question/answer:
|
poll/question/answer:
|
||||||
title: "Réponse"
|
title: "Réponse"
|
||||||
description: "Description"
|
description: "Description"
|
||||||
|
poll/question/answer/video:
|
||||||
|
title: Titre
|
||||||
|
url: Vidéo externe
|
||||||
errors:
|
errors:
|
||||||
models:
|
models:
|
||||||
user:
|
user:
|
||||||
|
|||||||
@@ -393,6 +393,16 @@ fr:
|
|||||||
answers:
|
answers:
|
||||||
new:
|
new:
|
||||||
title: "Nouvelle réponse"
|
title: "Nouvelle réponse"
|
||||||
|
videos:
|
||||||
|
index:
|
||||||
|
title: Vidéos
|
||||||
|
add_video: Ajouter une vidéo
|
||||||
|
video_title: Titre
|
||||||
|
video_url: Vidéo externe
|
||||||
|
new:
|
||||||
|
title: Nouveau vidéo
|
||||||
|
edit:
|
||||||
|
title: Modifier la vidéo
|
||||||
recounts:
|
recounts:
|
||||||
index:
|
index:
|
||||||
title: "Dépouillements"
|
title: "Dépouillements"
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ fr:
|
|||||||
direct_message: "Votre message a été envoyé avec succès."
|
direct_message: "Votre message a été envoyé avec succès."
|
||||||
poll: "Vote créé avec succès."
|
poll: "Vote créé avec succès."
|
||||||
poll_booth: "Urne créée avec succès."
|
poll_booth: "Urne créée avec succès."
|
||||||
|
poll_question_answer: "Réponse créée avec succès"
|
||||||
|
poll_question_answer_video: "Vidéo créée avec succès"
|
||||||
proposal: "Proposition créée avec succès."
|
proposal: "Proposition créée avec succès."
|
||||||
proposal_notification: "Votre message a correctement été envoyé."
|
proposal_notification: "Votre message a correctement été envoyé."
|
||||||
spending_proposal: "Proposition de dépense créée avec succès. Vous pouvez y accéder depuis %{activity}"
|
spending_proposal: "Proposition de dépense créée avec succès. Vous pouvez y accéder depuis %{activity}"
|
||||||
@@ -27,3 +29,4 @@ fr:
|
|||||||
spending_proposal: "Proposition de dépense supprimée avec succès."
|
spending_proposal: "Proposition de dépense supprimée avec succès."
|
||||||
budget_investment: "Budget d'investissement supprimé avec succès."
|
budget_investment: "Budget d'investissement supprimé avec succès."
|
||||||
error: "Suppression impossible"
|
error: "Suppression impossible"
|
||||||
|
poll_question_answer_video: "Réponse vidéo supprimée avec succès."
|
||||||
|
|||||||
@@ -300,8 +300,10 @@ Rails.application.routes.draw do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
resources :questions do
|
resources :questions, shallow: true do
|
||||||
resources :answers, only: [:new, :create], controller: 'questions/answers'
|
resources :answers, only: [:new, :create], controller: 'questions/answers' do
|
||||||
|
resources :videos, controller: 'questions/answers/videos'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
feature 'Videos' do
|
||||||
|
|
||||||
|
background do
|
||||||
|
admin = create(:administrator)
|
||||||
|
login_as(admin.user)
|
||||||
|
end
|
||||||
|
|
||||||
|
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"
|
||||||
|
|
||||||
|
visit admin_question_path(question)
|
||||||
|
|
||||||
|
within("#poll_question_answer_#{answer.id}") do
|
||||||
|
click_link "Video list (#{answer.videos.count})"
|
||||||
|
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
|
||||||
|
|
||||||
|
click_button "Save"
|
||||||
|
|
||||||
|
expect(page).to have_content(video_title)
|
||||||
|
expect(page).to have_content(video_url)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user