Merge branch 'master' into community

This commit is contained in:
Raimond Garcia
2017-09-05 15:40:03 +02:00
committed by GitHub
31 changed files with 436 additions and 202 deletions

View File

@@ -32,35 +32,6 @@ class Admin::Poll::OfficerAssignmentsController < Admin::BaseController
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_params = { poll_id: create_params[:poll_id], officer_id: create_params[:officer_id] }
redirect_to by_officer_admin_poll_officer_assignments_path(redirect_params), 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_params = { poll_id: @officer_assignment.poll_id, officer_id: @officer_assignment.officer_id }
redirect_to by_officer_admin_poll_officer_assignments_path(redirect_params), notice: notice
end
private
def officer_assignment_params

View File

@@ -0,0 +1,53 @@
class Admin::Poll::ShiftsController < Admin::BaseController
before_action :load_booth
before_action :load_polls
def new
load_officers
load_shifts
@shift = ::Poll::Shift.new
end
def create
@shift = ::Poll::Shift.new(shift_params)
if @shift.save
notice = t("admin.poll_shifts.flash.create")
redirect_to new_admin_booth_shift_path(@shift.booth), notice: notice
else
load_officers
load_shifts
render :new
end
end
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
end
private
def load_booth
@booth = ::Poll::Booth.find(params[:booth_id])
end
def load_polls
@polls = ::Poll.current_or_incoming
end
def load_officers
@officers = ::Poll::Officer.all
end
def load_shifts
@shifts = @booth.shifts
end
def shift_params
params.require(:shift).permit(:booth_id, :officer_id, :date)
end
end