Merge branch 'master' into polls-admin-polish

This commit is contained in:
decabeza
2017-10-11 19:12:34 +02:00
29 changed files with 776 additions and 41 deletions

View File

@@ -15,6 +15,7 @@
//= require jquery-ui/widgets/datepicker
//= require jquery-ui/i18n/datepicker-es
//= require jquery-ui/widgets/autocomplete
//= require jquery-ui/widgets/sortable
//= require jquery-fileupload/basic
//= require foundation
//= require turbolinks
@@ -71,6 +72,7 @@
//= require leaflet
//= require map
//= require polls
//= require sortable
var initialize_modules = function() {
App.Comments.initialize();
@@ -110,6 +112,7 @@ var initialize_modules = function() {
App.PollsAdmin.initialize();
App.Map.initialize();
App.Polls.initialize();
App.Sortable.initialize();
};
$(function(){

View File

@@ -0,0 +1,9 @@
App.Sortable =
initialize: ->
$(".sortable").sortable
update: (event, ui) ->
new_order = $(this).sortable('toArray', {attribute: 'data-answer-id'});
$.ajax
url: $('.sortable').data('js-url'),
data: {ordered_list: new_order},
type: 'POST'

View File

@@ -18,4 +18,5 @@
@import 'datepicker_overrides';
@import 'jquery-ui/autocomplete';
@import 'autocomplete_overrides';
@import 'jquery-ui/sortable';
@import 'leaflet';

View File

@@ -1596,7 +1596,7 @@
height: 100%;
&.short {
height: $line-height * 12;
height: rem-calc(300);
overflow: hidden;
}
}

View File

@@ -39,6 +39,11 @@ class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController
render 'admin/poll/questions/answers/documents'
end
def order_answers
::Poll::Question::Answer.order_answers(params[:ordered_list])
render nothing: true
end
private
def answer_params

View File

@@ -1,10 +1,10 @@
class PollsController < ApplicationController
include PollsHelper
load_and_authorize_resource
has_filters %w{current expired incoming}
has_orders %w{most_voted newest oldest}, only: :show
::Poll::Answer # trigger autoload
@@ -15,11 +15,16 @@ class PollsController < ApplicationController
def show
@questions = @poll.questions.for_render.sort_for_list
@token = poll_voter_token(@poll, current_user)
@poll_questions_answers = Poll::Question::Answer.where(question: @poll.questions)
@answers_by_question_id = {}
poll_answers = ::Poll::Answer.by_question(@poll.question_ids).by_author(current_user.try(:id))
poll_answers.each do |answer|
@answers_by_question_id[answer.question_id] = answer.answer
end
@commentable = @poll
@comment_tree = CommentTree.new(@commentable, params[:page], @current_order)
end
end

View File

@@ -12,7 +12,7 @@ module FlagsHelper
def flagged?(flaggable)
if flaggable.is_a? Comment
@comment_flags[flaggable.id]
@comment_flags[flaggable.id] unless flaggable.commentable_type == "Poll"
else
Flag.flagged?(current_user, flaggable)
end

View File

@@ -3,7 +3,7 @@ class Comment < ActiveRecord::Base
include HasPublicAuthor
include Graphqlable
COMMENTABLE_TYPES = %w(Debate Proposal Budget::Investment Poll::Question Legislation::Question Legislation::Annotation Topic).freeze
COMMENTABLE_TYPES = %w(Debate Proposal Budget::Investment Poll::Question Legislation::Question Legislation::Annotation Topic Poll).freeze
acts_as_paranoid column: :hidden_at
include ActsAsParanoidAliases

View File

@@ -22,6 +22,7 @@ class CommentNotifier
end
def email_on_comment?
return false if @comment.commentable.is_a?(Poll)
commentable_author = @comment.commentable.author
commentable_author != @author && commentable_author.email_on_comment?
end

View File

@@ -1,6 +1,7 @@
class Poll < ActiveRecord::Base
include Imageable
acts_as_paranoid column: :hidden_at
include ActsAsParanoidAliases
has_many :booth_assignments, class_name: "Poll::BoothAssignment"
has_many :booths, through: :booth_assignments
has_many :partial_results, through: :booth_assignments
@@ -9,8 +10,10 @@ class Poll < ActiveRecord::Base
has_many :officer_assignments, through: :booth_assignments
has_many :officers, through: :officer_assignments
has_many :questions
has_many :comments, as: :commentable
has_and_belongs_to_many :geozones
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
validates :name, presence: true
@@ -24,6 +27,10 @@ class Poll < ActiveRecord::Base
scope :sort_for_list, -> { order(:geozone_restricted, :starts_at, :name) }
def title
name
end
def current?(timestamp = Date.current.beginning_of_day)
starts_at <= timestamp && timestamp <= ends_at
end

View File

@@ -10,7 +10,7 @@ class Poll::Question < ActiveRecord::Base
has_many :comments, as: :commentable
has_many :answers, class_name: 'Poll::Answer'
has_many :question_answers, class_name: 'Poll::Question::Answer'
has_many :question_answers, -> { order 'given_order asc' }, class_name: 'Poll::Question::Answer'
has_many :partial_results
belongs_to :proposal

View File

@@ -1,5 +1,5 @@
class Poll::Question::Answer < ActiveRecord::Base
include Galleryable
include Galleryable
include Documentable
documentable max_documents_allowed: 3,
max_file_size: 3.megabytes,
@@ -10,8 +10,25 @@ class Poll::Question::Answer < ActiveRecord::Base
has_many :videos, class_name: 'Poll::Question::Answer::Video'
validates :title, presence: true
validates :given_order, presence: true, uniqueness: { scope: :question_id }
before_validation :set_order, on: :create
def description
super.try :html_safe
end
def self.order_answers(ordered_array)
ordered_array.each_with_index do |answer_id, order|
find(answer_id).update_attribute(:given_order, (order + 1))
end
end
def set_order
self.given_order = self.class.last_position(question_id) + 1
end
def self.last_position(question_id)
where(question_id: question_id).maximum('given_order') || 0
end
end

View File

@@ -47,30 +47,32 @@
<th scope="col" class="text-center"><%= t("admin.questions.show.answers.videos") %></th>
</tr>
<% @question.question_answers.each do |answer| %>
<tr id="<%= dom_id(answer) %>" class="poll_question_answer">
<td class="align-top"><%= link_to answer.title, admin_answer_path(answer) %></td>
<td class="align-top break"><%= answer.description %></td>
<td class="align-top text-center">
(<%= answer.images.count %>)
<br>
<%= link_to t("admin.questions.show.answers.images_list"),
admin_answer_images_path(answer) %>
</td>
<td class="align-top 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="align-top text-center">
(<%= answer.videos.count %>)
<br>
<%= link_to t("admin.questions.show.answers.video_list"),
admin_answer_videos_path(answer) %>
</td>
</tr>
<% end %>
<tbody class="sortable" data-js-url="<%= admin_question_answers_order_answers_path(@question.id) %>">
<% @question.question_answers.each do |answer| %>
<tr id="<%= dom_id(answer) %>" class="poll_question_answer" data-answer-id="<%= answer.id %>">
<td class="align-top"><%= link_to answer.title, admin_answer_path(answer) %></td>
<td class="align-top break"><%= answer.description %></td>
<td class="align-top text-center">
(<%= answer.images.count %>)
<br>
<%= link_to t("admin.questions.show.answers.images_list"),
admin_answer_images_path(answer) %>
</td>
<td class="align-top 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="align-top text-center">
(<%= answer.videos.count %>)
<br>
<%= link_to t("admin.questions.show.answers.video_list"),
admin_answer_videos_path(answer) %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% if @question.video_url.present? %>

View File

@@ -1,7 +1,7 @@
<div class="row">
<div class="small-12 column margin-top">
<%= back_link_to commentable_path(@comment),
t("comments.show.return_to_commentable") + @comment.commentable.title %>
t("comments.show.return_to_commentable") + @comment.commentable.title unless @commentable.class == Poll %>
</div>
</div>

View File

@@ -0,0 +1,24 @@
<% cache [locale_and_user_status, @current_order, commentable_cache_key(@poll), @comment_tree.comments, @comment_tree.comment_authors, @poll.comments_count, @comment_flags] do %>
<div class="row comments">
<div id="comments" class="small-12 column">
<%= render 'shared/wide_order_selector', i18n_namespace: "comments" %>
<% if user_signed_in? %>
<%= render 'comments/form', {commentable: @poll, parent_id: nil, toggeable: false} %>
<% else %>
<br>
<div data-alert class="callout primary">
<%= t("polls.show.login_to_comment",
signin: link_to(t("votes.signin"), new_user_session_path),
signup: link_to(t("votes.signup"), new_user_registration_path)).html_safe %>
</div>
<% end %>
<% @comment_tree.root_comments.each do |comment| %>
<%= render 'comments/comment', comment: comment %>
<% end %>
<%= paginate @comment_tree.root_comments %>
</div>
</div>
<% end %>

View File

@@ -0,0 +1,14 @@
<div class="row">
<div class="small-12 column">
<ul class="tabs" data-tabs id="polls-tabs">
<li class="tabs-title is-active">
<%= link_to "#tab-comments" do %>
<h3>
<%= t("polls.show.comments_tab") %>
<span class="js-comments-count">(<%= @poll.comments_count %>)</span>
</h3>
<% end %>
</li>
</ul>
</div>
</div>

View File

@@ -79,7 +79,7 @@
<div class="expanded poll-more-info-answers">
<div class="row padding">
<% @poll.questions.map(&:question_answers).flatten.each do |answer| %>
<% @poll_questions_answers.each do |answer| %>
<div class="small-12 medium-6 column end" id="answer_<%= answer.id %>"
data-toggler="medium-6 answer-divider">
@@ -128,5 +128,14 @@
</div>
<% end %>
</div>
</div>
</div>
<div class="tabs-content" data-tabs-content="proposals-tabs" role="tablist">
<%= render "filter_subnav" %>
<div class="tabs-panel is-active" id="tab-comments">
<%= render "comments" %>
</div>
</div>