Adds ballot sheets controller and main views

This commit is contained in:
María Checa
2018-06-21 18:09:50 +02:00
committed by Javi Martín
parent 3ccdf039e4
commit ccf8d3a8e2
14 changed files with 275 additions and 9 deletions

View File

@@ -0,0 +1,77 @@
class Officing::BallotSheetsController < Officing::BaseController
before_action :verify_booth
before_action :load_poll
before_action :load_officer_assignments, only: [:new, :create]
helper_method :namespace
def index
load_ballot_sheets
end
def show
load_ballot_sheet
end
def new
end
def create
load_officer_assignment
check_officer_assignment
@ballot_sheet = Poll::BallotSheet.new(ballot_sheet_params)
if @ballot_sheet.save
redirect_to officing_poll_ballot_sheet_path(@poll, @ballot_sheet)
else
render :new
end
end
private
def namespace
"officing"
end
def load_poll
@poll = Poll.find(params[:poll_id])
end
def load_ballot_sheets
@ballot_sheets = Poll::BallotSheet.where(poll: @poll)
end
def load_ballot_sheet
@ballot_sheet = Poll::BallotSheet.find(params[:id])
end
def load_officer_assignments
@officer_assignments = ::Poll::OfficerAssignment.
includes(booth_assignment: [:booth]).
joins(:booth_assignment).
final.
where(id: current_user.poll_officer.officer_assignment_ids).
where("poll_booth_assignments.poll_id = ?", @poll.id).
where(date: Date.current)
end
def load_officer_assignment
@officer_assignment = current_user.poll_officer.officer_assignments.final
.find_by(id: ballot_sheet_params[:officer_assignment_id])
end
def check_officer_assignment
if @officer_assignment.blank?
flash.now[:alert] = t("officing.results.flash.error_wrong_booth")
render :new
end
end
def ballot_sheet_params
params.permit(:data, :poll_id, :officer_assignment_id)
end
end

View File

@@ -13,6 +13,12 @@ class Officing::BaseController < ApplicationController
raise CanCan::AccessDenied unless current_user.try(:poll_officer?)
end
def check_officer_assignment
if @officer_assignment.blank?
go_back_to_new(t("officing.results.flash.error_wrong_booth"))
end
end
def load_officer_assignment
@officer_assignments ||= current_user.poll_officer.
officer_assignments.

View File

@@ -0,0 +1,61 @@
class Officing::PollBallotSheetsController < Officing::BaseController
before_action :verify_booth
before_action :load_poll
before_action :load_ballot_sheets, only: :index
before_action :load_ballot_sheet, only: :show
before_action :load_officer_assignments, only: :new
before_action :load_officer_assignment, only: :create
before_action :check_officer_assignment, only: :create
helper_method :namespace
def index
end
def show
end
def new
end
def create
Poll::BallotSheet.create(ballot_sheet_params)
render :show
end
private
def namespace
"officing"
end
def load_poll
@poll = Poll.find(params[:poll_id])
end
def load_ballot_sheets
@ballot_sheets = Poll::BallotSheet.where(poll: @poll)
end
def load_ballot_sheet
@ballot_sheet = Poll::BallotSheet.find(params[:ballot_sheet_id])
end
def load_officer_assignments
@officer_assignments = ::Poll::OfficerAssignment.
includes(booth_assignment: [:booth]).
joins(:booth_assignment).
final.
where(id: current_user.poll_officer.officer_assignment_ids).
where("poll_booth_assignments.poll_id = ?", @poll_budget.id).
where(date: Date.current)
end
def ballot_sheet_params
params.permit(:csv_data, :poll_id, :officer_assignment_id)
end
end

View File

@@ -33,12 +33,6 @@ class Officing::ResultsController < Officing::BaseController
private
def check_officer_assignment
if @officer_assignment.blank?
go_back_to_new(t("officing.results.flash.error_wrong_booth"))
end
end
def build_results
@results = []