Skip to content

Commit 621e62e

Browse files
authored
Merge pull request #84 from decidim/issue_80
Implements fix for #80
2 parents ada720b + 1337b58 commit 621e62e

File tree

13 files changed

+41
-9
lines changed

13 files changed

+41
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.introductory-image {
2+
min-height: 290px;
3+
}

app/commands/decidim/consultations/admin/create_consultation.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def call
2727
broadcast(:ok, consultation)
2828
else
2929
form.errors.add(:banner_image, consultation.errors[:banner_image]) if consultation.errors.include? :banner_image
30+
form.errors.add(:introductory_image, consultation.errors[:introductory_image]) if consultation.errors.include? :introductory_image
3031
broadcast(:invalid)
3132
end
3233
end
@@ -46,7 +47,8 @@ def create_consultation
4647
highlighted_scope: form.highlighted_scope,
4748
introductory_video_url: form.introductory_video_url,
4849
start_voting_date: form.start_voting_date,
49-
end_voting_date: form.end_voting_date
50+
end_voting_date: form.end_voting_date,
51+
introductory_image: form.introductory_image
5052
)
5153

5254
return consultation unless consultation.valid?

app/commands/decidim/consultations/admin/update_consultation.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def call
2929
broadcast(:ok, consultation)
3030
else
3131
form.errors.add(:banner_image, consultation.errors[:banner_image]) if consultation.errors.include? :banner_image
32+
form.errors.add(:introductory_image, consultation.errors[:introductory_image]) if consultation.errors.include? :introductory_image
3233
broadcast(:invalid)
3334
end
3435
end
@@ -53,7 +54,8 @@ def attributes
5354
highlighted_scope: form.highlighted_scope,
5455
introductory_video_url: form.introductory_video_url,
5556
start_voting_date: form.start_voting_date,
56-
end_voting_date: form.end_voting_date
57+
end_voting_date: form.end_voting_date,
58+
introductory_image: form.introductory_image
5759
}
5860
end
5961
end

app/forms/decidim/consultations/admin/consultation_form.rb

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class ConsultationForm < Form
1616
attribute :banner_image
1717
attribute :remove_banner_image
1818
attribute :introductory_video_url, String
19+
attribute :introductory_image, String
1920
attribute :decidim_highlighted_scope_id, Integer
2021
attribute :start_voting_date, Date
2122
attribute :end_voting_date, Date
@@ -28,6 +29,7 @@ class ConsultationForm < Form
2829
validate :slug_uniqueness
2930

3031
validates :banner_image, file_size: { less_than_or_equal_to: ->(_record) { Decidim.maximum_attachment_size } }, file_content_type: { allow: ["image/jpeg", "image/png"] }
32+
validates :introductory_image, file_size: { less_than_or_equal_to: ->(_record) { Decidim.maximum_attachment_size } }, file_content_type: { allow: ["image/jpeg", "image/png"] }
3133

3234
def highlighted_scope
3335
@scope ||= current_organization.scopes.where(id: decidim_highlighted_scope_id).first

app/models/decidim/consultation.rb

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class Consultation < ApplicationRecord
2525
validates :slug, presence: true, format: { with: Decidim::Consultation.slug_format }
2626

2727
mount_uploader :banner_image, Decidim::BannerImageUploader
28+
mount_uploader :introductory_image, Decidim::BannerImageUploader
2829

2930
scope :upcoming, -> { published.where("start_voting_date > ?", Time.now.utc) }
3031
scope :active, lambda {

app/views/decidim/consultations/admin/consultations/_form.html.erb

+6-2
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,17 @@
4242
</div>
4343

4444
<div class="row">
45-
<div class="columns xlarge-6">
45+
<div class="columns xlarge-4">
4646
<%= form.upload :banner_image %>
4747
</div>
4848

49-
<div class="columns xlarge-6">
49+
<div class="columns xlarge-4">
5050
<%= form.url_field :introductory_video_url %>
5151
</div>
52+
53+
<div class="columns xlarge-4">
54+
<%= form.upload :introductory_image %>
55+
</div>
5256
</div>
5357
</div>
5458
</div>

app/views/decidim/consultations/consultations/_consultation_details.html.erb

+10-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@
33
<p class="lead"><%= decidim_sanitize translated_attribute consultation.description %></p>
44
</div>
55
<div class="columns medium-6 large-5 large-pull-1">
6-
<div class="embed-container">
7-
<iframe src="<%= consultation.introductory_video_url %>" frameborder=0 allowfullscreen>
8-
</iframe>
9-
</div>
6+
<% if consultation.introductory_video_url.blank? %>
7+
<div class="card--full__image consultations-card__image introductory-image"
8+
style="background-image: url(<%= consultation.introductory_image_url %>);">
9+
</div>
10+
<% else %>
11+
<div class="embed-container">
12+
<iframe src="<%= consultation.introductory_video_url %>" frameborder=0 allowfullscreen>
13+
</iframe>
14+
</div>
15+
<% end %>
1016
</div>
1117
</div>

config/locales/ca.yml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ ca:
99
description: Descripció
1010
banner_image: Imatge de bàner
1111
introductory_video_url: URL del vídeo introductori
12+
introductory_image: Imatge introductoria
1213
start_voting_date: Data d'inici
1314
end_voting_date: Data de finalització
1415
decidim_highlighted_scope_id: Àmbit destacat

config/locales/en.yml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ en:
99
description: Description
1010
banner_image: Banner image
1111
introductory_video_url: Introductory video URL
12+
introductory_image: Introductory image
1213
start_voting_date: Start date
1314
end_voting_date: End date
1415
decidim_highlighted_scope_id: Highlighted scope

config/locales/es.yml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ es:
99
description: Descripción
1010
banner_image: Imagen de banner
1111
introductory_video_url: URL del vídeo introductorio
12+
introductory_image: Imagen introductoria
1213
start_voting_date: Fecha de inicio
1314
end_voting_date: Fecha de finalización
1415
decidim_highlighted_scope_id: Ámbito destacado
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
class AddIntroductoryImageToDecidimConsultations < ActiveRecord::Migration[5.1]
4+
def change
5+
add_column :decidim_consultations, :introductory_image, :string
6+
end
7+
end

spec/commands/decidim/consultations/admin/create_consultation_spec.rb

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ module Admin
2828
end_voting_date: end_voting_date,
2929
introductory_video_url: nil,
3030
current_organization: organization,
31+
introductory_image: nil,
3132
errors: errors
3233
)
3334
end

spec/commands/decidim/consultations/admin/update_consultation_spec.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ module Admin
2525
decidim_highlighted_scope_id: consultation.highlighted_scope.id,
2626
start_voting_date: consultation.start_voting_date,
2727
end_voting_date: consultation.end_voting_date,
28-
introductory_video_url: consultation.introductory_video_url
28+
introductory_video_url: consultation.introductory_video_url,
29+
introductory_image: consultation.introductory_image
2930
}
3031
}
3132
end

0 commit comments

Comments
 (0)