Merge branch 'master' into site-customization
This commit is contained in:
66
app/controllers/admin/poll/booth_assignments_controller.rb
Normal file
66
app/controllers/admin/poll/booth_assignments_controller.rb
Normal file
@@ -0,0 +1,66 @@
|
||||
class Admin::Poll::BoothAssignmentsController < Admin::BaseController
|
||||
|
||||
before_action :load_poll, except: [:create, :destroy]
|
||||
|
||||
def index
|
||||
@booth_assignments = @poll.booth_assignments.includes(:booth).order('poll_booths.name').page(params[:page]).per(50)
|
||||
end
|
||||
|
||||
def search_booths
|
||||
load_search
|
||||
@booths = ::Poll::Booth.search(@search)
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
@booth_assignment = @poll.booth_assignments.includes(:recounts, :final_recounts, :voters, officer_assignments: [officer: [:user]]).find(params[:id])
|
||||
@voters_by_date = @booth_assignment.voters.group_by {|v| v.created_at.to_date}
|
||||
end
|
||||
|
||||
def create
|
||||
@booth_assignment = ::Poll::BoothAssignment.new(poll_id: booth_assignment_params[:poll_id], booth_id: booth_assignment_params[:booth_id])
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
def destroy
|
||||
@booth_assignment = ::Poll::BoothAssignment.find(params[:id])
|
||||
|
||||
if @booth_assignment.destroy
|
||||
notice = t("admin.poll_booth_assignments.flash.destroy")
|
||||
else
|
||||
notice = t("admin.poll_booth_assignments.flash.error_destroy")
|
||||
end
|
||||
redirect_to admin_poll_booth_assignments_path(@booth_assignment.poll_id), notice: notice
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def load_booth_assignment
|
||||
@booth_assignment = ::Poll::BoothAssignment.find(params[:id])
|
||||
end
|
||||
|
||||
def booth_assignment_params
|
||||
params.permit(:booth_id, :poll_id)
|
||||
end
|
||||
|
||||
def load_poll
|
||||
@poll = ::Poll.find(params[:poll_id])
|
||||
end
|
||||
|
||||
def search_params
|
||||
params.permit(:poll_id, :search)
|
||||
end
|
||||
|
||||
def load_search
|
||||
@search = search_params[:search]
|
||||
end
|
||||
|
||||
end
|
||||
39
app/controllers/admin/poll/booths_controller.rb
Normal file
39
app/controllers/admin/poll/booths_controller.rb
Normal file
@@ -0,0 +1,39 @@
|
||||
class Admin::Poll::BoothsController < Admin::BaseController
|
||||
load_and_authorize_resource class: 'Poll::Booth'
|
||||
|
||||
def index
|
||||
@booths = @booths.order(name: :asc).page(params[:page])
|
||||
end
|
||||
|
||||
def show
|
||||
end
|
||||
|
||||
def new
|
||||
end
|
||||
|
||||
def create
|
||||
if @booth.save
|
||||
redirect_to admin_booths_path, notice: t("flash.actions.create.poll_booth")
|
||||
else
|
||||
render :new
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
if @booth.update(booth_params)
|
||||
redirect_to admin_booth_path(@booth), notice: t("flash.actions.update.poll_booth")
|
||||
else
|
||||
render :edit
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def booth_params
|
||||
params.require(:poll_booth).permit(:name, :location)
|
||||
end
|
||||
|
||||
end
|
||||
92
app/controllers/admin/poll/officer_assignments_controller.rb
Normal file
92
app/controllers/admin/poll/officer_assignments_controller.rb
Normal file
@@ -0,0 +1,92 @@
|
||||
class Admin::Poll::OfficerAssignmentsController < Admin::BaseController
|
||||
|
||||
before_action :load_poll
|
||||
before_action :redirect_if_blank_required_params, only: [:by_officer]
|
||||
before_action :load_booth_assignment, only: [:create]
|
||||
|
||||
def index
|
||||
@officers = ::Poll::Officer.
|
||||
includes(:user).
|
||||
order('users.username').
|
||||
where(
|
||||
id: @poll.officer_assignments.select(:officer_id).distinct.map(&:officer_id)
|
||||
).page(params[:page]).per(50)
|
||||
end
|
||||
|
||||
def by_officer
|
||||
@poll = ::Poll.includes(:booths).find(params[:poll_id])
|
||||
@officer = ::Poll::Officer.includes(:user).find(officer_assignment_params[:officer_id])
|
||||
@officer_assignments = ::Poll::OfficerAssignment.
|
||||
joins(:booth_assignment).
|
||||
includes(:recount, :final_recounts, booth_assignment: :booth).
|
||||
where("officer_id = ? AND poll_booth_assignments.poll_id = ?", @officer.id, @poll.id).
|
||||
order(:date)
|
||||
end
|
||||
|
||||
def search_officers
|
||||
load_search
|
||||
@officers = User.joins(:poll_officer).search(@search).order(username: :asc)
|
||||
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
@officer_assignment = ::Poll::OfficerAssignment.new(booth_assignment: @booth_assignment,
|
||||
officer_id: create_params[:officer_id],
|
||||
date: create_params[:date])
|
||||
@officer_assignment.final = true if @officer_assignment.date > @booth_assignment.poll.ends_at.to_date
|
||||
|
||||
if @officer_assignment.save
|
||||
notice = t("admin.poll_officer_assignments.flash.create")
|
||||
else
|
||||
notice = t("admin.poll_officer_assignments.flash.error_create")
|
||||
end
|
||||
redirect_to by_officer_admin_poll_officer_assignments_path(poll_id: create_params[:poll_id], officer_id: create_params[:officer_id]), notice: notice
|
||||
end
|
||||
|
||||
def destroy
|
||||
@officer_assignment = ::Poll::OfficerAssignment.includes(:booth_assignment).find(params[:id])
|
||||
|
||||
if @officer_assignment.destroy
|
||||
notice = t("admin.poll_officer_assignments.flash.destroy")
|
||||
else
|
||||
notice = t("admin.poll_officer_assignments.flash.error_destroy")
|
||||
end
|
||||
redirect_to by_officer_admin_poll_officer_assignments_path(poll_id: @officer_assignment.poll_id, officer_id: @officer_assignment.officer_id), notice: notice
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def officer_assignment_params
|
||||
params.permit(:officer_id)
|
||||
end
|
||||
|
||||
def create_params
|
||||
params.permit(:poll_id, :booth_id, :date, :officer_id)
|
||||
end
|
||||
|
||||
def load_booth_assignment
|
||||
@booth_assignment = ::Poll::BoothAssignment.includes(:poll).find_by(poll_id: create_params[:poll_id], booth_id: create_params[:booth_id])
|
||||
end
|
||||
|
||||
def load_poll
|
||||
@poll = ::Poll.find(params[:poll_id])
|
||||
end
|
||||
|
||||
def redirect_if_blank_required_params
|
||||
if officer_assignment_params[:officer_id].blank?
|
||||
redirect_to admin_poll_path(@poll)
|
||||
end
|
||||
end
|
||||
|
||||
def search_params
|
||||
params.permit(:poll_id, :search)
|
||||
end
|
||||
|
||||
def load_search
|
||||
@search = search_params[:search]
|
||||
end
|
||||
|
||||
end
|
||||
39
app/controllers/admin/poll/officers_controller.rb
Normal file
39
app/controllers/admin/poll/officers_controller.rb
Normal file
@@ -0,0 +1,39 @@
|
||||
class Admin::Poll::OfficersController < Admin::BaseController
|
||||
load_and_authorize_resource :officer, class: "Poll::Officer", except: [:edit, :show]
|
||||
|
||||
def index
|
||||
@officers = @officers.page(params[:page])
|
||||
end
|
||||
|
||||
def search
|
||||
@user = User.find_by(email: params[:email])
|
||||
|
||||
respond_to do |format|
|
||||
if @user
|
||||
@officer = Poll::Officer.find_or_initialize_by(user: @user)
|
||||
format.js
|
||||
else
|
||||
format.js { render "user_not_found" }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
@officer.user_id = params[:user_id]
|
||||
@officer.save
|
||||
|
||||
redirect_to admin_officers_path
|
||||
end
|
||||
|
||||
def destroy
|
||||
@officer.destroy
|
||||
redirect_to admin_officers_path
|
||||
end
|
||||
|
||||
def show
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
end
|
||||
86
app/controllers/admin/poll/polls_controller.rb
Normal file
86
app/controllers/admin/poll/polls_controller.rb
Normal file
@@ -0,0 +1,86 @@
|
||||
class Admin::Poll::PollsController < Admin::BaseController
|
||||
load_and_authorize_resource
|
||||
|
||||
before_action :load_search, only: [:search_booths, :search_questions, :search_officers]
|
||||
before_action :load_geozones, only: [:new, :create, :edit, :update]
|
||||
|
||||
def index
|
||||
end
|
||||
|
||||
def show
|
||||
@poll = Poll.includes(:questions).
|
||||
order('poll_questions.title').
|
||||
find(params[:id])
|
||||
end
|
||||
|
||||
def new
|
||||
end
|
||||
|
||||
def create
|
||||
if @poll.save
|
||||
redirect_to [:admin, @poll], notice: t("flash.actions.create.poll")
|
||||
else
|
||||
render :new
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
if @poll.update(poll_params)
|
||||
redirect_to [:admin, @poll], notice: t("flash.actions.update.poll")
|
||||
else
|
||||
render :edit
|
||||
end
|
||||
end
|
||||
|
||||
def add_question
|
||||
question = ::Poll::Question.find(params[:question_id])
|
||||
|
||||
if question.present?
|
||||
@poll.questions << question
|
||||
notice = t("admin.polls.flash.question_added")
|
||||
else
|
||||
notice = t("admin.polls.flash.error_on_question_added")
|
||||
end
|
||||
redirect_to admin_poll_path(@poll), notice: notice
|
||||
end
|
||||
|
||||
def remove_question
|
||||
question = ::Poll::Question.find(params[:question_id])
|
||||
|
||||
if @poll.questions.include? question
|
||||
@poll.questions.delete(question)
|
||||
notice = t("admin.polls.flash.question_removed")
|
||||
else
|
||||
notice = t("admin.polls.flash.error_on_question_removed")
|
||||
end
|
||||
redirect_to admin_poll_path(@poll), notice: notice
|
||||
end
|
||||
|
||||
def search_questions
|
||||
@questions = ::Poll::Question.where("poll_id IS ? OR poll_id != ?", nil, @poll.id).search({search: @search}).order(title: :asc)
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def load_geozones
|
||||
@geozones = Geozone.all.order(:name)
|
||||
end
|
||||
|
||||
def poll_params
|
||||
params.require(:poll).permit(:name, :starts_at, :ends_at, :geozone_restricted, geozone_ids: [])
|
||||
end
|
||||
|
||||
def search_params
|
||||
params.permit(:poll_id, :search)
|
||||
end
|
||||
|
||||
def load_search
|
||||
@search = search_params[:search]
|
||||
end
|
||||
|
||||
end
|
||||
64
app/controllers/admin/poll/questions_controller.rb
Normal file
64
app/controllers/admin/poll/questions_controller.rb
Normal file
@@ -0,0 +1,64 @@
|
||||
class Admin::Poll::QuestionsController < Admin::BaseController
|
||||
load_and_authorize_resource :poll
|
||||
load_and_authorize_resource :question, class: 'Poll::Question'
|
||||
|
||||
def index
|
||||
@polls = Poll.all
|
||||
@search = search_params[:search]
|
||||
|
||||
@questions = @questions.search(search_params).page(params[:page]).order("created_at DESC")
|
||||
|
||||
@proposals = Proposal.successful.sort_by_confidence_score
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
def create
|
||||
@question.author = @question.proposal.try(:author) || current_user
|
||||
|
||||
if @question.save
|
||||
redirect_to admin_question_path(@question)
|
||||
else
|
||||
render :new
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
if @question.update(question_params)
|
||||
redirect_to admin_question_path(@question), notice: t("flash.actions.save_changes.notice")
|
||||
else
|
||||
render :edit
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @question.destroy
|
||||
notice = "Question destroyed succesfully"
|
||||
else
|
||||
notice = t("flash.actions.destroy.error")
|
||||
end
|
||||
redirect_to admin_questions_path, notice: notice
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def question_params
|
||||
params.require(:poll_question).permit(:poll_id, :title, :question, :description, :proposal_id, :valid_answers)
|
||||
end
|
||||
|
||||
def search_params
|
||||
params.permit(:poll_id, :search)
|
||||
end
|
||||
|
||||
end
|
||||
16
app/controllers/admin/poll/recounts_controller.rb
Normal file
16
app/controllers/admin/poll/recounts_controller.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
class Admin::Poll::RecountsController < Admin::BaseController
|
||||
before_action :load_poll
|
||||
|
||||
def index
|
||||
@booth_assignments = @poll.booth_assignments.
|
||||
includes(:booth, :recounts, :final_recounts, :voters).
|
||||
order("poll_booths.name").
|
||||
page(params[:page]).per(50)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def load_poll
|
||||
@poll = ::Poll.find(params[:poll_id])
|
||||
end
|
||||
end
|
||||
13
app/controllers/admin/poll/results_controller.rb
Normal file
13
app/controllers/admin/poll/results_controller.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
class Admin::Poll::ResultsController < Admin::BaseController
|
||||
before_action :load_poll
|
||||
|
||||
def index
|
||||
@partial_results = @poll.partial_results
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def load_poll
|
||||
@poll = ::Poll.includes(:questions).find(params[:poll_id])
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user