diff --git a/app/assets/stylesheets/decidim/consultations/consultations/introductory_image.scss b/app/assets/stylesheets/decidim/consultations/consultations/introductory_image.scss new file mode 100644 index 0000000..bf95564 --- /dev/null +++ b/app/assets/stylesheets/decidim/consultations/consultations/introductory_image.scss @@ -0,0 +1,3 @@ +.introductory-image { + min-height: 290px; +} diff --git a/app/commands/decidim/consultations/admin/create_consultation.rb b/app/commands/decidim/consultations/admin/create_consultation.rb index 155240e..b9c1c04 100644 --- a/app/commands/decidim/consultations/admin/create_consultation.rb +++ b/app/commands/decidim/consultations/admin/create_consultation.rb @@ -27,6 +27,7 @@ def call broadcast(:ok, consultation) else form.errors.add(:banner_image, consultation.errors[:banner_image]) if consultation.errors.include? :banner_image + form.errors.add(:introductory_image, consultation.errors[:introductory_image]) if consultation.errors.include? :introductory_image broadcast(:invalid) end end @@ -46,7 +47,8 @@ def create_consultation highlighted_scope: form.highlighted_scope, introductory_video_url: form.introductory_video_url, start_voting_date: form.start_voting_date, - end_voting_date: form.end_voting_date + end_voting_date: form.end_voting_date, + introductory_image: form.introductory_image ) return consultation unless consultation.valid? diff --git a/app/commands/decidim/consultations/admin/update_consultation.rb b/app/commands/decidim/consultations/admin/update_consultation.rb index a163265..9d901ec 100644 --- a/app/commands/decidim/consultations/admin/update_consultation.rb +++ b/app/commands/decidim/consultations/admin/update_consultation.rb @@ -29,6 +29,7 @@ def call broadcast(:ok, consultation) else form.errors.add(:banner_image, consultation.errors[:banner_image]) if consultation.errors.include? :banner_image + form.errors.add(:introductory_image, consultation.errors[:introductory_image]) if consultation.errors.include? :introductory_image broadcast(:invalid) end end @@ -53,7 +54,8 @@ def attributes highlighted_scope: form.highlighted_scope, introductory_video_url: form.introductory_video_url, start_voting_date: form.start_voting_date, - end_voting_date: form.end_voting_date + end_voting_date: form.end_voting_date, + introductory_image: form.introductory_image } end end diff --git a/app/forms/decidim/consultations/admin/consultation_form.rb b/app/forms/decidim/consultations/admin/consultation_form.rb index 4a0ed6e..6df2b4e 100644 --- a/app/forms/decidim/consultations/admin/consultation_form.rb +++ b/app/forms/decidim/consultations/admin/consultation_form.rb @@ -16,6 +16,7 @@ class ConsultationForm < Form attribute :banner_image attribute :remove_banner_image attribute :introductory_video_url, String + attribute :introductory_image, String attribute :decidim_highlighted_scope_id, Integer attribute :start_voting_date, Date attribute :end_voting_date, Date @@ -28,6 +29,7 @@ class ConsultationForm < Form validate :slug_uniqueness validates :banner_image, file_size: { less_than_or_equal_to: ->(_record) { Decidim.maximum_attachment_size } }, file_content_type: { allow: ["image/jpeg", "image/png"] } + validates :introductory_image, file_size: { less_than_or_equal_to: ->(_record) { Decidim.maximum_attachment_size } }, file_content_type: { allow: ["image/jpeg", "image/png"] } def highlighted_scope @scope ||= current_organization.scopes.where(id: decidim_highlighted_scope_id).first diff --git a/app/models/decidim/consultation.rb b/app/models/decidim/consultation.rb index 3332b9e..211c27e 100644 --- a/app/models/decidim/consultation.rb +++ b/app/models/decidim/consultation.rb @@ -25,6 +25,7 @@ class Consultation < ApplicationRecord validates :slug, presence: true, format: { with: Decidim::Consultation.slug_format } mount_uploader :banner_image, Decidim::BannerImageUploader + mount_uploader :introductory_image, Decidim::BannerImageUploader scope :upcoming, -> { published.where("start_voting_date > ?", Time.now.utc) } scope :active, lambda { diff --git a/app/views/decidim/consultations/admin/consultations/_form.html.erb b/app/views/decidim/consultations/admin/consultations/_form.html.erb index 42a48a2..3ecc28e 100644 --- a/app/views/decidim/consultations/admin/consultations/_form.html.erb +++ b/app/views/decidim/consultations/admin/consultations/_form.html.erb @@ -42,13 +42,17 @@
<%= decidim_sanitize translated_attribute consultation.description %>