diff --git a/app/assets/stylesheets/admin.scss b/app/assets/stylesheets/admin.scss index 52c989f55..8f6912716 100644 --- a/app/assets/stylesheets/admin.scss +++ b/app/assets/stylesheets/admin.scss @@ -149,6 +149,7 @@ $sidebar-active: #f4fcd0; } table { + .break { word-break: break-word; } diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index 15b984f17..2df8292f6 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -1591,6 +1591,10 @@ .orbit-container { height: 100% !important; max-height: none !important; + + li { + margin-bottom: 0 !important; + } } .orbit-slide { diff --git a/app/controllers/admin/poll/questions/answers/images_controller.rb b/app/controllers/admin/poll/questions/answers/images_controller.rb new file mode 100644 index 000000000..4074eb371 --- /dev/null +++ b/app/controllers/admin/poll/questions/answers/images_controller.rb @@ -0,0 +1,32 @@ +class Admin::Poll::Questions::Answers::ImagesController < Admin::Poll::BaseController + before_action :load_answer + + def index + end + + def new + @answer = ::Poll::Question::Answer.find(params[:answer_id]) + end + + def create + @answer = ::Poll::Question::Answer.find(params[:answer_id]) + @answer.attributes = images_params + + if @answer.save + redirect_to admin_answer_images_path(@answer), + notice: "Image uploaded successfully" + else + render :new + end + end + + private + + def images_params + params.permit(images_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy]) + end + + def load_answer + @answer = ::Poll::Question::Answer.find(params[:answer_id]) + end +end diff --git a/app/controllers/admin/poll/shifts_controller.rb b/app/controllers/admin/poll/shifts_controller.rb index 97bb2f614..1f60b2b4e 100644 --- a/app/controllers/admin/poll/shifts_controller.rb +++ b/app/controllers/admin/poll/shifts_controller.rb @@ -1,7 +1,6 @@ class Admin::Poll::ShiftsController < Admin::Poll::BaseController before_action :load_booth - before_action :load_polls before_action :load_officer def new @@ -39,10 +38,6 @@ class Admin::Poll::ShiftsController < Admin::Poll::BaseController @booth = ::Poll::Booth.find(params[:booth_id]) end - def load_polls - @polls = ::Poll.current_or_incoming - end - def load_shifts @shifts = @booth.shifts end diff --git a/app/controllers/officing/voters_controller.rb b/app/controllers/officing/voters_controller.rb index 2c3867416..2b7ed329f 100644 --- a/app/controllers/officing/voters_controller.rb +++ b/app/controllers/officing/voters_controller.rb @@ -3,7 +3,8 @@ class Officing::VotersController < Officing::BaseController def new @user = User.find(params[:id]) - @polls = Poll.answerable_by(@user) + booths = current_user.poll_officer.shifts.current.vote_collection.pluck(:booth_id).uniq + @polls = Poll.answerable_by(@user).where(id: Poll::BoothAssignment.where(booth: booths).pluck(:poll_id).uniq) end def create diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb index 2cefcdf27..e508cf813 100644 --- a/app/helpers/admin_helper.rb +++ b/app/helpers/admin_helper.rb @@ -25,7 +25,7 @@ module AdminHelper end def menu_polls? - %w[polls questions officers booths officer_assignments booth_assignments recounts results shifts].include? controller_name + %w[polls questions officers booths officer_assignments booth_assignments recounts results shifts questions answers].include? controller_name end def menu_profiles? diff --git a/app/models/concerns/galleryable.rb b/app/models/concerns/galleryable.rb new file mode 100644 index 000000000..1063c5571 --- /dev/null +++ b/app/models/concerns/galleryable.rb @@ -0,0 +1,12 @@ +module Galleryable + extend ActiveSupport::Concern + + included do + has_many :images, as: :imageable, dependent: :destroy + accepts_nested_attributes_for :images, allow_destroy: true, update_only: true + + def image_url(style) + image.attachment.url(style) if image && image.attachment.exists? + end + end +end \ No newline at end of file diff --git a/app/models/direct_upload.rb b/app/models/direct_upload.rb index a6b6ef276..192f06d04 100644 --- a/app/models/direct_upload.rb +++ b/app/models/direct_upload.rb @@ -19,7 +19,9 @@ class DirectUpload if @resource_type.present? && @resource_relation.present? && (@attachment.present? || @cached_attachment.present?) @resource = @resource_type.constantize.find_or_initialize_by(id: @resource_id) - if @resource.class.reflections[@resource_relation].macro == :has_one + if @resource.respond_to?(:images) + @relation = @resource.images.send("build", relation_attributtes) + elsif @resource.class.reflections[@resource_relation].macro == :has_one @relation = @resource.send("build_#{resource_relation}", relation_attributtes) else @relation = @resource.send(@resource_relation).build(relation_attributtes) diff --git a/app/models/poll/officer.rb b/app/models/poll/officer.rb index bf4c73c36..384202455 100644 --- a/app/models/poll/officer.rb +++ b/app/models/poll/officer.rb @@ -2,6 +2,7 @@ class Poll class Officer < ActiveRecord::Base belongs_to :user has_many :officer_assignments, class_name: "Poll::OfficerAssignment" + has_many :shifts, class_name: "Poll::Shift" has_many :failed_census_calls, foreign_key: :poll_officer_id validates :user_id, presence: true, uniqueness: true diff --git a/app/models/poll/question/answer.rb b/app/models/poll/question/answer.rb index cb43e2d44..fb32de9fc 100644 --- a/app/models/poll/question/answer.rb +++ b/app/models/poll/question/answer.rb @@ -1,4 +1,6 @@ class Poll::Question::Answer < ActiveRecord::Base + include Galleryable + belongs_to :question, class_name: 'Poll::Question', foreign_key: 'question_id' has_many :videos, class_name: 'Poll::Question::Answer::Video' diff --git a/app/models/poll/shift.rb b/app/models/poll/shift.rb index 4edeb26ef..e3cfd2280 100644 --- a/app/models/poll/shift.rb +++ b/app/models/poll/shift.rb @@ -10,6 +10,10 @@ class Poll enum task: { vote_collection: 0, recount_scrutiny: 1 } + scope :vote_collection, -> { where(task: 'vote_collection') } + scope :recount_scrutiny, -> { where(task: 'recount_scrutiny') } + scope :current, -> { where(date: Date.current) } + before_create :persist_data after_create :create_officer_assignments before_destroy :destroy_officer_assignments diff --git a/app/views/admin/_menu.html.erb b/app/views/admin/_menu.html.erb index bb246cb6c..81e1ae9bd 100644 --- a/app/views/admin/_menu.html.erb +++ b/app/views/admin/_menu.html.erb @@ -60,12 +60,14 @@ <%= t("admin.menu.title_polls") %> -