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/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/question/answer.rb b/app/models/poll/question/answer.rb index 3f8f4a172..1746c480c 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' validates :title, presence: true 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") %> -