Merge branch 'master' into dashboard
This commit is contained in:
36
app/controllers/admin/poll/active_polls_controller.rb
Normal file
36
app/controllers/admin/poll/active_polls_controller.rb
Normal file
@@ -0,0 +1,36 @@
|
||||
class Admin::Poll::ActivePollsController < Admin::Poll::BaseController
|
||||
include Translatable
|
||||
|
||||
before_action :load_active_poll
|
||||
|
||||
def create
|
||||
if @active_poll.update(active_poll_params)
|
||||
redirect_to admin_polls_url, notice: t("flash.actions.update.active_poll")
|
||||
else
|
||||
render :edit
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
if @active_poll.update(active_poll_params)
|
||||
redirect_to admin_polls_url, notice: t("flash.actions.update.active_poll")
|
||||
else
|
||||
render :edit
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def load_active_poll
|
||||
@active_poll = ::ActivePoll.first_or_initialize
|
||||
end
|
||||
|
||||
def active_poll_params
|
||||
params.require(:active_poll).permit(translation_params(ActivePoll))
|
||||
end
|
||||
|
||||
end
|
||||
@@ -3,7 +3,7 @@ class Admin::Poll::BoothAssignmentsController < Admin::Poll::BaseController
|
||||
before_action :load_poll, except: [:create, :destroy]
|
||||
|
||||
def index
|
||||
@booth_assignments = @poll.booth_assignments.includes(:booth).order('poll_booths.name')
|
||||
@booth_assignments = @poll.booth_assignments.includes(:booth).order("poll_booths.name")
|
||||
.page(params[:page]).per(50)
|
||||
end
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Admin::Poll::BoothsController < Admin::Poll::BaseController
|
||||
load_and_authorize_resource class: 'Poll::Booth'
|
||||
load_and_authorize_resource class: "Poll::Booth"
|
||||
|
||||
def index
|
||||
@booths = @booths.order(name: :asc).page(params[:page])
|
||||
|
||||
@@ -7,7 +7,7 @@ class Admin::Poll::OfficerAssignmentsController < Admin::Poll::BaseController
|
||||
def index
|
||||
@officers = ::Poll::Officer.
|
||||
includes(:user).
|
||||
order('users.username').
|
||||
order("users.username").
|
||||
where(
|
||||
id: @poll.officer_assignments.select(:officer_id).distinct.map(&:officer_id)
|
||||
).page(params[:page]).per(50)
|
||||
|
||||
@@ -30,10 +30,4 @@ class Admin::Poll::OfficersController < Admin::Poll::BaseController
|
||||
redirect_to admin_officers_path
|
||||
end
|
||||
|
||||
def show
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
class Admin::Poll::PollsController < Admin::Poll::BaseController
|
||||
include Translatable
|
||||
include ImageAttributes
|
||||
load_and_authorize_resource
|
||||
|
||||
before_action :load_search, only: [:search_booths, :search_officers]
|
||||
before_action :load_geozones, only: [:new, :create, :edit, :update]
|
||||
|
||||
def index
|
||||
@polls = Poll.order(starts_at: :desc)
|
||||
end
|
||||
|
||||
def show
|
||||
@poll = Poll.includes(:questions).
|
||||
order('poll_questions.title').
|
||||
order("poll_questions.title").
|
||||
find(params[:id])
|
||||
end
|
||||
|
||||
@@ -50,7 +52,7 @@ class Admin::Poll::PollsController < Admin::Poll::BaseController
|
||||
end
|
||||
|
||||
def booth_assignments
|
||||
@polls = Poll.current_or_incoming
|
||||
@polls = Poll.current
|
||||
end
|
||||
|
||||
private
|
||||
@@ -60,11 +62,10 @@ class Admin::Poll::PollsController < Admin::Poll::BaseController
|
||||
end
|
||||
|
||||
def poll_params
|
||||
image_attributes = [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy]
|
||||
attributes = [:name, :starts_at, :ends_at, :geozone_restricted, :summary, :description,
|
||||
:results_enabled, :stats_enabled, geozone_ids: [],
|
||||
attributes = [:name, :starts_at, :ends_at, :geozone_restricted, :results_enabled,
|
||||
:stats_enabled, geozone_ids: [],
|
||||
image_attributes: image_attributes]
|
||||
params.require(:poll).permit(*attributes, *translation_params(Poll))
|
||||
params.require(:poll).permit(*attributes, translation_params(Poll))
|
||||
end
|
||||
|
||||
def search_params
|
||||
|
||||
@@ -11,9 +11,10 @@ class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController
|
||||
|
||||
def create
|
||||
@answer = ::Poll::Question::Answer.new(answer_params)
|
||||
@question = @answer.question
|
||||
|
||||
if @answer.save
|
||||
redirect_to admin_question_path(@answer.question),
|
||||
redirect_to admin_question_path(@question),
|
||||
notice: t("flash.actions.create.poll_question_answer")
|
||||
else
|
||||
render :new
|
||||
@@ -31,14 +32,14 @@ class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController
|
||||
redirect_to admin_question_path(@answer.question),
|
||||
notice: t("flash.actions.save_changes.notice")
|
||||
else
|
||||
redirect_to :back
|
||||
render :edit
|
||||
end
|
||||
end
|
||||
|
||||
def documents
|
||||
@documents = @answer.documents
|
||||
|
||||
render 'admin/poll/questions/answers/documents'
|
||||
render "admin/poll/questions/answers/documents"
|
||||
end
|
||||
|
||||
def order_answers
|
||||
@@ -52,7 +53,10 @@ class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController
|
||||
documents_attributes = [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy]
|
||||
attributes = [:title, :description, :given_order, :question_id,
|
||||
documents_attributes: documents_attributes]
|
||||
params.require(:poll_question_answer).permit(*attributes, *translation_params(Poll::Question::Answer))
|
||||
|
||||
params.require(:poll_question_answer).permit(
|
||||
*attributes, translation_params(Poll::Question::Answer)
|
||||
)
|
||||
end
|
||||
|
||||
def load_answer
|
||||
|
||||
@@ -3,7 +3,7 @@ class Admin::Poll::QuestionsController < Admin::Poll::BaseController
|
||||
include Translatable
|
||||
|
||||
load_and_authorize_resource :poll
|
||||
load_and_authorize_resource :question, class: 'Poll::Question'
|
||||
load_and_authorize_resource :question, class: "Poll::Question"
|
||||
|
||||
def index
|
||||
@polls = Poll.all
|
||||
@@ -56,8 +56,8 @@ class Admin::Poll::QuestionsController < Admin::Poll::BaseController
|
||||
private
|
||||
|
||||
def question_params
|
||||
attributes = [:poll_id, :title, :question, :proposal_id]
|
||||
params.require(:poll_question).permit(*attributes, *translation_params(Poll::Question))
|
||||
attributes = [:poll_id, :question, :proposal_id]
|
||||
params.require(:poll_question).permit(*attributes, translation_params(Poll::Question))
|
||||
end
|
||||
|
||||
def search_params
|
||||
|
||||
@@ -6,6 +6,10 @@ class Admin::Poll::RecountsController < Admin::Poll::BaseController
|
||||
includes(:booth, :recounts, :voters).
|
||||
order("poll_booths.name").
|
||||
page(params[:page]).per(50)
|
||||
@all_booths_counts = {
|
||||
final: ::Poll::Recount.select(:total_amount).where(booth_assignment_id: @poll.booth_assignment_ids).sum(:total_amount),
|
||||
system: ::Poll::Voter.where(booth_assignment_id: @poll.booth_assignment_ids).count
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -6,8 +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
|
||||
@voting_polls = @booth.polls.current
|
||||
@recount_polls = @booth.polls.current_or_recounting
|
||||
end
|
||||
|
||||
def create
|
||||
@@ -26,9 +26,14 @@ class Admin::Poll::ShiftsController < Admin::Poll::BaseController
|
||||
|
||||
def destroy
|
||||
@shift = Poll::Shift.find(params[:id])
|
||||
@shift.destroy
|
||||
notice = t("admin.poll_shifts.flash.destroy")
|
||||
redirect_to new_admin_booth_shift_path(@booth), notice: notice
|
||||
if @shift.unable_to_destroy?
|
||||
alert = t("admin.poll_shifts.flash.unable_to_destroy")
|
||||
redirect_to new_admin_booth_shift_path(@booth), alert: alert
|
||||
else
|
||||
@shift.destroy
|
||||
notice = t("admin.poll_shifts.flash.destroy")
|
||||
redirect_to new_admin_booth_shift_path(@booth), notice: notice
|
||||
end
|
||||
end
|
||||
|
||||
def search_officers
|
||||
|
||||
Reference in New Issue
Block a user