Skip to content

Commit

Permalink
Merge pull request #84 from decidim/issue_80
Browse files Browse the repository at this point in the history
Implements fix for #80
  • Loading branch information
jsperezg authored Mar 20, 2018
2 parents ada720b + 1337b58 commit 621e62e
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.introductory-image {
min-height: 290px;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/forms/decidim/consultations/admin/consultation_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/models/decidim/consultation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,17 @@
</div>

<div class="row">
<div class="columns xlarge-6">
<div class="columns xlarge-4">
<%= form.upload :banner_image %>
</div>

<div class="columns xlarge-6">
<div class="columns xlarge-4">
<%= form.url_field :introductory_video_url %>
</div>

<div class="columns xlarge-4">
<%= form.upload :introductory_image %>
</div>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@
<p class="lead"><%= decidim_sanitize translated_attribute consultation.description %></p>
</div>
<div class="columns medium-6 large-5 large-pull-1">
<div class="embed-container">
<iframe src="<%= consultation.introductory_video_url %>" frameborder=0 allowfullscreen>
</iframe>
</div>
<% if consultation.introductory_video_url.blank? %>
<div class="card--full__image consultations-card__image introductory-image"
style="background-image: url(<%= consultation.introductory_image_url %>);">
</div>
<% else %>
<div class="embed-container">
<iframe src="<%= consultation.introductory_video_url %>" frameborder=0 allowfullscreen>
</iframe>
</div>
<% end %>
</div>
</div>
1 change: 1 addition & 0 deletions config/locales/ca.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 621e62e

Please sign in to comment.