Merge branch 'master' into proposal-dashboard

This commit is contained in:
decabeza
2019-04-23 17:12:47 +02:00
643 changed files with 2814 additions and 1417 deletions

View File

@@ -1,4 +1,4 @@
class Poll::Answer < ActiveRecord::Base
class Poll::Answer < ApplicationRecord
belongs_to :question, -> { with_hidden }
belongs_to :author, -> { with_hidden }, class_name: "User", foreign_key: "author_id"

36
app/models/poll/ballot.rb Normal file
View File

@@ -0,0 +1,36 @@
class Poll::Ballot < ActiveRecord::Base
belongs_to :ballot_sheet, class_name: Poll::BallotSheet
validates :ballot_sheet_id, presence: true
def verify
investments.each do |investment_id|
add_investment(investment_id)
end
end
def add_investment(investment_id)
investment = find_investment(investment_id)
if investment.present? && not_already_added?(investment)
ballot.add_investment(investment)
end
end
def investments
data.split(",")
end
def ballot
Budget::Ballot.where(poll_ballot: self).first
end
def find_investment(investment_id)
ballot.budget.investments.where(id: investment_id).first
end
def not_already_added?(investment)
ballot.lines.where(investment: investment).blank?
end
end

View File

@@ -0,0 +1,42 @@
class Poll::BallotSheet < ActiveRecord::Base
belongs_to :poll
belongs_to :officer_assignment
has_many :ballots, class_name: Poll::Ballot
validates :data, presence: true
validates :poll_id, presence: true
validates :officer_assignment_id, presence: true
def author
officer_assignment.officer.name
end
def verify_ballots
parsed_ballots.each_with_index do |investment_ids, index|
ballot = create_ballots(investment_ids, index)
ballot.verify
end
end
def parsed_ballots
data.split(/[;\n]/)
end
private
def create_ballots(investment_ids, index)
poll_ballot = Poll::Ballot.where(ballot_sheet: self,
data: investment_ids,
external_id: index).first_or_create
create_ballot(poll_ballot)
poll_ballot
end
def create_ballot(poll_ballot)
Budget::Ballot.where(physical: true,
user: nil,
poll_ballot: poll_ballot,
budget: poll.budget).first_or_create
end
end

View File

@@ -1,5 +1,5 @@
class Poll
class Booth < ActiveRecord::Base
class Booth < ApplicationRecord
has_many :booth_assignments, class_name: "Poll::BoothAssignment"
has_many :polls, through: :booth_assignments
has_many :shifts
@@ -12,7 +12,7 @@ class Poll
end
def self.available
where(polls: { id: Poll.current_or_recounting }).includes(:polls)
where(polls: { id: Poll.current_or_recounting }).joins(polls: :translations)
end
def assignment_on_poll(poll)

View File

@@ -1,5 +1,5 @@
class Poll
class BoothAssignment < ActiveRecord::Base
class BoothAssignment < ApplicationRecord
belongs_to :booth
belongs_to :poll

View File

@@ -1,5 +1,5 @@
class Poll
class Officer < ActiveRecord::Base
class Officer < ApplicationRecord
belongs_to :user
has_many :officer_assignments, class_name: "Poll::OfficerAssignment"
has_many :shifts, class_name: "Poll::Shift"

View File

@@ -1,7 +1,8 @@
class Poll
class OfficerAssignment < ActiveRecord::Base
class OfficerAssignment < ApplicationRecord
belongs_to :officer
belongs_to :booth_assignment
has_many :ballot_sheets
has_many :partial_results
has_many :recounts
has_many :voters

View File

@@ -1,4 +1,4 @@
class Poll::PartialResult < ActiveRecord::Base
class Poll::PartialResult < ApplicationRecord
VALID_ORIGINS = %w{web booth}

View File

@@ -1,4 +1,4 @@
class Poll::Question < ActiveRecord::Base
class Poll::Question < ApplicationRecord
include Measurable
include Searchable

View File

@@ -1,4 +1,4 @@
class Poll::Question::Answer < ActiveRecord::Base
class Poll::Question::Answer < ApplicationRecord
include Galleryable
include Documentable

View File

@@ -1,4 +1,4 @@
class Poll::Question::Answer::Video < ActiveRecord::Base
class Poll::Question::Answer::Video < ApplicationRecord
belongs_to :answer, class_name: "Poll::Question::Answer", foreign_key: "answer_id"
VIMEO_REGEX = /vimeo.*(staffpicks\/|channels\/|videos\/|video\/|\/)([^#\&\?]*).*/

View File

@@ -1,4 +1,4 @@
class Poll::Recount < ActiveRecord::Base
class Poll::Recount < ApplicationRecord
VALID_ORIGINS = %w{web booth letter}.freeze

View File

@@ -1,5 +1,5 @@
class Poll
class Shift < ActiveRecord::Base
class Shift < ApplicationRecord
belongs_to :booth
belongs_to :officer

View File

@@ -1,5 +1,5 @@
class Poll
class Voter < ActiveRecord::Base
class Voter < ApplicationRecord
VALID_ORIGINS = %w{web booth}.freeze