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 @@
-
+
<%= form.upload :banner_image %>
-
+
<%= form.url_field :introductory_video_url %>
+ +
+ <%= form.upload :introductory_image %> +
diff --git a/app/views/decidim/consultations/consultations/_consultation_details.html.erb b/app/views/decidim/consultations/consultations/_consultation_details.html.erb index d1b9050..59519d9 100644 --- a/app/views/decidim/consultations/consultations/_consultation_details.html.erb +++ b/app/views/decidim/consultations/consultations/_consultation_details.html.erb @@ -3,9 +3,15 @@

<%= decidim_sanitize translated_attribute consultation.description %>

-
- -
+ <% if consultation.introductory_video_url.blank? %> +
+
+ <% else %> +
+ +
+ <% end %>
diff --git a/config/locales/ca.yml b/config/locales/ca.yml index 4b968c3..c6c60da 100644 --- a/config/locales/ca.yml +++ b/config/locales/ca.yml @@ -9,6 +9,7 @@ ca: description: Descripció banner_image: Imatge de bàner introductory_video_url: URL del vídeo introductori + introductory_image: Imatge introductoria start_voting_date: Data d'inici end_voting_date: Data de finalització decidim_highlighted_scope_id: Àmbit destacat diff --git a/config/locales/en.yml b/config/locales/en.yml index e33882f..c278f75 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -9,6 +9,7 @@ en: description: Description banner_image: Banner image introductory_video_url: Introductory video URL + introductory_image: Introductory image start_voting_date: Start date end_voting_date: End date decidim_highlighted_scope_id: Highlighted scope diff --git a/config/locales/es.yml b/config/locales/es.yml index 0a193f2..991317c 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -9,6 +9,7 @@ es: description: Descripción banner_image: Imagen de banner introductory_video_url: URL del vídeo introductorio + introductory_image: Imagen introductoria start_voting_date: Fecha de inicio end_voting_date: Fecha de finalización decidim_highlighted_scope_id: Ámbito destacado diff --git a/db/migrate/20180320100658_add_introductory_image_to_decidim_consultations.rb b/db/migrate/20180320100658_add_introductory_image_to_decidim_consultations.rb new file mode 100644 index 0000000..32d4387 --- /dev/null +++ b/db/migrate/20180320100658_add_introductory_image_to_decidim_consultations.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddIntroductoryImageToDecidimConsultations < ActiveRecord::Migration[5.1] + def change + add_column :decidim_consultations, :introductory_image, :string + end +end diff --git a/spec/commands/decidim/consultations/admin/create_consultation_spec.rb b/spec/commands/decidim/consultations/admin/create_consultation_spec.rb index b44d752..1ff515b 100644 --- a/spec/commands/decidim/consultations/admin/create_consultation_spec.rb +++ b/spec/commands/decidim/consultations/admin/create_consultation_spec.rb @@ -28,6 +28,7 @@ module Admin end_voting_date: end_voting_date, introductory_video_url: nil, current_organization: organization, + introductory_image: nil, errors: errors ) end diff --git a/spec/commands/decidim/consultations/admin/update_consultation_spec.rb b/spec/commands/decidim/consultations/admin/update_consultation_spec.rb index cb24e28..b2c357b 100644 --- a/spec/commands/decidim/consultations/admin/update_consultation_spec.rb +++ b/spec/commands/decidim/consultations/admin/update_consultation_spec.rb @@ -25,7 +25,8 @@ module Admin decidim_highlighted_scope_id: consultation.highlighted_scope.id, start_voting_date: consultation.start_voting_date, end_voting_date: consultation.end_voting_date, - introductory_video_url: consultation.introductory_video_url + introductory_video_url: consultation.introductory_video_url, + introductory_image: consultation.introductory_image } } end