Merge branch 'master' into 1856-legislation_processes_proposals_phase
This commit is contained in:
@@ -18,21 +18,29 @@ class Admin::Poll::BoothAssignmentsController < Admin::Poll::BaseController
|
||||
@booth_assignment = @poll.booth_assignments.includes(:recounts, :voters,
|
||||
officer_assignments: [officer: [:user]]).find(params[:id])
|
||||
@voters_by_date = @booth_assignment.voters.group_by {|v| v.created_at.to_date}
|
||||
@partial_results = @booth_assignment.partial_results
|
||||
@recounts = @booth_assignment.recounts
|
||||
end
|
||||
|
||||
def create
|
||||
@booth_assignment = ::Poll::BoothAssignment.new(poll_id: booth_assignment_params[:poll_id],
|
||||
booth_id: booth_assignment_params[:booth_id])
|
||||
@poll = Poll.find(booth_assignment_params[:poll_id])
|
||||
@booth = Poll::Booth.find(booth_assignment_params[:booth_id])
|
||||
@booth_assignment = ::Poll::BoothAssignment.new(poll: @poll,
|
||||
booth: @booth)
|
||||
|
||||
if @booth_assignment.save
|
||||
notice = t("admin.poll_booth_assignments.flash.create")
|
||||
else
|
||||
notice = t("admin.poll_booth_assignments.flash.error_create")
|
||||
end
|
||||
redirect_to admin_poll_booth_assignments_path(@booth_assignment.poll_id), notice: notice
|
||||
respond_to do |format|
|
||||
format.js { render layout: false }
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@poll = Poll.find(booth_assignment_params[:poll_id])
|
||||
@booth = Poll::Booth.find(booth_assignment_params[:booth_id])
|
||||
@booth_assignment = ::Poll::BoothAssignment.find(params[:id])
|
||||
|
||||
if @booth_assignment.destroy
|
||||
@@ -40,7 +48,14 @@ class Admin::Poll::BoothAssignmentsController < Admin::Poll::BaseController
|
||||
else
|
||||
notice = t("admin.poll_booth_assignments.flash.error_destroy")
|
||||
end
|
||||
redirect_to admin_poll_booth_assignments_path(@booth_assignment.poll_id), notice: notice
|
||||
respond_to do |format|
|
||||
format.js { render layout: false }
|
||||
end
|
||||
end
|
||||
|
||||
def manage
|
||||
@booths = ::Poll::Booth.all
|
||||
@poll = Poll.find(params[:poll_id])
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -25,7 +25,9 @@ class Admin::Poll::OfficerAssignmentsController < Admin::Poll::BaseController
|
||||
|
||||
def search_officers
|
||||
load_search
|
||||
@officers = User.joins(:poll_officer).search(@search).order(username: :asc)
|
||||
|
||||
poll_officers = User.where(id: @poll.officers.pluck(:user_id))
|
||||
@officers = poll_officers.search(@search).order(username: :asc)
|
||||
|
||||
respond_to do |format|
|
||||
format.js
|
||||
|
||||
@@ -47,6 +47,10 @@ class Admin::Poll::PollsController < Admin::Poll::BaseController
|
||||
redirect_to admin_poll_path(@poll), notice: notice
|
||||
end
|
||||
|
||||
def booth_assignments
|
||||
@polls = Poll.current_or_incoming
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def load_geozones
|
||||
@@ -54,9 +58,10 @@ class Admin::Poll::PollsController < Admin::Poll::BaseController
|
||||
end
|
||||
|
||||
def poll_params
|
||||
params.require(:poll).permit(:name, :starts_at, :ends_at, :geozone_restricted, :summary, :description,
|
||||
geozone_ids: [],
|
||||
image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy])
|
||||
params.require(:poll).permit(:name, :starts_at, :ends_at, :geozone_restricted,
|
||||
:summary, :description, :results_enabled, :stats_enabled,
|
||||
geozone_ids: [],
|
||||
image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy])
|
||||
end
|
||||
|
||||
def search_params
|
||||
|
||||
@@ -5,7 +5,7 @@ class Admin::Poll::Questions::Answers::ImagesController < Admin::Poll::BaseContr
|
||||
end
|
||||
|
||||
def new
|
||||
@answer = ::Poll::Question::Answer.find(params[:answer_id])
|
||||
@answer = ::Poll::Question::Answer.find(params[:answer_id])
|
||||
end
|
||||
|
||||
def create
|
||||
|
||||
@@ -33,11 +33,11 @@ class Admin::Poll::Questions::Answers::VideosController < Admin::Poll::BaseContr
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @video.destroy
|
||||
notice = t("flash.actions.destroy.poll_question_answer_video")
|
||||
else
|
||||
notice = t("flash.actions.destroy.error")
|
||||
end
|
||||
notice = if @video.destroy
|
||||
t("flash.actions.destroy.poll_question_answer_video")
|
||||
else
|
||||
t("flash.actions.destroy.error")
|
||||
end
|
||||
redirect_to :back, notice: notice
|
||||
end
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -15,7 +15,6 @@ class Admin::Poll::QuestionsController < Admin::Poll::BaseController
|
||||
|
||||
def new
|
||||
@polls = Poll.all
|
||||
@question.valid_answers = I18n.t('poll_questions.default_valid_answers')
|
||||
proposal = Proposal.find(params[:proposal_id]) if params[:proposal_id].present?
|
||||
@question.copy_attributes_from_proposal(proposal)
|
||||
end
|
||||
@@ -56,7 +55,7 @@ class Admin::Poll::QuestionsController < Admin::Poll::BaseController
|
||||
private
|
||||
|
||||
def question_params
|
||||
params.require(:poll_question).permit(:poll_id, :title, :question, :proposal_id, :valid_answers, :video_url)
|
||||
params.require(:poll_question).permit(:poll_id, :title, :question, :proposal_id, :video_url)
|
||||
end
|
||||
|
||||
def search_params
|
||||
|
||||
@@ -6,6 +6,8 @@ class Admin::Poll::ShiftsController < Admin::Poll::BaseController
|
||||
def new
|
||||
load_shifts
|
||||
@shift = ::Poll::Shift.new
|
||||
@voting_polls = @booth.polls.current_or_incoming
|
||||
@recount_polls = @booth.polls.current_or_recounting_or_incoming
|
||||
end
|
||||
|
||||
def create
|
||||
@@ -49,7 +51,7 @@ class Admin::Poll::ShiftsController < Admin::Poll::BaseController
|
||||
end
|
||||
|
||||
def shift_params
|
||||
shift_params = params.require(:shift).permit(:booth_id, :officer_id, :task, date:[:vote_collection_date, :recount_scrutiny_date])
|
||||
shift_params = params.require(:shift).permit(:booth_id, :officer_id, :task, date: [:vote_collection_date, :recount_scrutiny_date])
|
||||
shift_params.merge(date: shift_params[:date]["#{shift_params[:task]}_date".to_sym])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -18,8 +18,7 @@ class DirectUploadsController < ApplicationController
|
||||
render json: { cached_attachment: @direct_upload.relation.cached_attachment,
|
||||
filename: @direct_upload.relation.attachment.original_filename,
|
||||
destroy_link: render_destroy_upload_link(@direct_upload).html_safe,
|
||||
attachment_url: @direct_upload.relation.attachment.url
|
||||
}
|
||||
attachment_url: @direct_upload.relation.attachment.url}
|
||||
else
|
||||
@direct_upload.destroy_attachment
|
||||
render json: { errors: @direct_upload.errors[:attachment].join(", ") },
|
||||
@@ -28,7 +27,7 @@ class DirectUploadsController < ApplicationController
|
||||
end
|
||||
|
||||
def destroy
|
||||
@direct_upload = DirectUpload.new(direct_upload_params.merge(user: current_user) )
|
||||
@direct_upload = DirectUpload.new(direct_upload_params.merge(user: current_user))
|
||||
@direct_upload.relation.set_attachment_from_cached_attachment
|
||||
|
||||
if @direct_upload.destroy_attachment
|
||||
|
||||
@@ -29,6 +29,8 @@ class NotificationsController < ApplicationController
|
||||
case notification.linkable_resource.class.name
|
||||
when "Budget::Investment"
|
||||
budget_investment_path @notification.linkable_resource.budget, @notification.linkable_resource
|
||||
when "Topic"
|
||||
community_topic_path @notification.linkable_resource.community, @notification.linkable_resource
|
||||
else
|
||||
url_for @notification.linkable_resource
|
||||
end
|
||||
|
||||
@@ -7,6 +7,6 @@ class Officing::BaseController < ApplicationController
|
||||
skip_authorization_check
|
||||
|
||||
def verify_officer
|
||||
raise CanCan::AccessDenied unless current_user.try(:poll_officer?) || current_user.try(:administrator?)
|
||||
raise CanCan::AccessDenied unless current_user.try(:poll_officer?)
|
||||
end
|
||||
end
|
||||
@@ -5,7 +5,7 @@ class Officing::ResultsController < Officing::BaseController
|
||||
before_action :load_partial_results, only: :new
|
||||
|
||||
before_action :load_officer_assignment, only: :create
|
||||
before_action :check_booth_and_date, only: :create
|
||||
before_action :check_officer_assignment, only: :create
|
||||
before_action :build_results, only: :create
|
||||
|
||||
def new
|
||||
@@ -32,13 +32,9 @@ class Officing::ResultsController < Officing::BaseController
|
||||
|
||||
private
|
||||
|
||||
def check_booth_and_date
|
||||
def check_officer_assignment
|
||||
if @officer_assignment.blank?
|
||||
go_back_to_new(t("officing.results.flash.error_wrong_booth"))
|
||||
elsif results_params[:date].blank? ||
|
||||
Date.parse(results_params[:date]) < @poll.starts_at.to_date ||
|
||||
Date.parse(results_params[:date]) > @poll.ends_at.to_date
|
||||
go_back_to_new(t("officing.results.flash.error_wrong_date"))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -51,11 +47,11 @@ class Officing::ResultsController < Officing::BaseController
|
||||
|
||||
results.each_pair do |answer_index, count|
|
||||
next if count.blank?
|
||||
answer = question.valid_answers[answer_index.to_i]
|
||||
answer = question.question_answers.where(given_order: answer_index.to_i + 1).first.title
|
||||
go_back_to_new if question.blank?
|
||||
|
||||
partial_result = ::Poll::PartialResult.find_or_initialize_by(booth_assignment_id: @officer_assignment.booth_assignment_id,
|
||||
date: results_params[:date],
|
||||
date: Date.current,
|
||||
question_id: question_id,
|
||||
answer: answer)
|
||||
partial_result.officer_assignment_id = @officer_assignment.id
|
||||
@@ -71,7 +67,7 @@ class Officing::ResultsController < Officing::BaseController
|
||||
|
||||
def build_recounts
|
||||
recount = ::Poll::Recount.find_or_initialize_by(booth_assignment_id: @officer_assignment.booth_assignment_id,
|
||||
date: results_params[:date])
|
||||
date: Date.current)
|
||||
recount.officer_assignment_id = @officer_assignment.id
|
||||
recount.author = current_user
|
||||
recount.origin = 'booth'
|
||||
@@ -84,7 +80,7 @@ class Officing::ResultsController < Officing::BaseController
|
||||
end
|
||||
|
||||
def go_back_to_new(alert = nil)
|
||||
params[:d] = results_params[:date]
|
||||
params[:d] = Date.current
|
||||
params[:oa] = results_params[:officer_assignment_id]
|
||||
flash.now[:alert] = (alert || t("officing.results.flash.error_create"))
|
||||
load_officer_assignments
|
||||
@@ -108,7 +104,7 @@ class Officing::ResultsController < Officing::BaseController
|
||||
final.
|
||||
where(id: current_user.poll_officer.officer_assignment_ids).
|
||||
where("poll_booth_assignments.poll_id = ?", @poll.id).
|
||||
order(date: :asc)
|
||||
where(date: Date.current)
|
||||
end
|
||||
|
||||
def load_partial_results
|
||||
@@ -119,7 +115,7 @@ class Officing::ResultsController < Officing::BaseController
|
||||
end
|
||||
|
||||
def results_params
|
||||
params.permit(:officer_assignment_id, :date, :questions, :whites, :nulls, :total)
|
||||
params.permit(:officer_assignment_id, :questions, :whites, :nulls, :total)
|
||||
end
|
||||
|
||||
def index_params
|
||||
|
||||
@@ -13,6 +13,9 @@ class Polls::QuestionsController < ApplicationController
|
||||
answer.touch if answer.persisted?
|
||||
answer.save!
|
||||
answer.record_voter_participation(token)
|
||||
@question.question_answers.where(question_id: @question).each do |answer|
|
||||
answer.set_most_voted
|
||||
end
|
||||
|
||||
@answers_by_question_id = { @question.id => params[:answer] }
|
||||
end
|
||||
|
||||
@@ -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,23 @@ 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).where.not(description: "").order(:given_order)
|
||||
|
||||
@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
|
||||
|
||||
def stats
|
||||
@stats = Poll::Stats.new(@poll).generate
|
||||
end
|
||||
|
||||
def results
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user