Skip to content

Commit

Permalink
Merge branch 'feature/DEMAD-104'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben Blazquez Garcia committed Dec 18, 2020
2 parents 2f5d5b1 + 7aa35e2 commit 8be27b0
Show file tree
Hide file tree
Showing 18 changed files with 111 additions and 32 deletions.
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ gem "whenever", "~> 0.10.0", require: false
gem "wicked_pdf", "~> 1.1.0"
gem "wkhtmltopdf-binary", "0.12.4"
gem 'starrr'
gem 'paperclip-ffmpeg'
gem 'paperclip-av-transcoder'
gem "cocaine"
gem 'jw_player_helper'

source "https://rails-assets.org" do
gem "rails-assets-leaflet"
Expand Down
13 changes: 13 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ GEM
ast (2.4.1)
autoprefixer-rails (8.2.0)
execjs
av (0.9.0)
cocaine (~> 0.5.3)
babel-source (5.8.35)
babel-transpiler (0.7.0)
babel-source (>= 4.0, < 6)
Expand Down Expand Up @@ -248,6 +250,7 @@ GEM
jquery-ui-rails (6.0.1)
railties (>= 3.2.16)
json (2.3.1)
jw_player_helper (0.0.1)
jwt (1.5.6)
kaminari (1.1.1)
activesupport (>= 4.1.0)
Expand Down Expand Up @@ -337,6 +340,12 @@ GEM
cocaine (~> 0.5.5)
mime-types
mimemagic (~> 0.3.0)
paperclip-av-transcoder (0.6.4)
av (~> 0.9.0)
paperclip (>= 2.5.2)
paperclip-ffmpeg (1.2.0)
paperclip (>= 2.5.2)
rails
parallel (1.19.2)
paranoia (2.4.2)
activerecord (>= 4.0, < 6.1)
Expand Down Expand Up @@ -558,6 +567,7 @@ DEPENDENCIES
capistrano3-delayed-job (~> 1.7.3)
capybara (~> 2.17.0)
ckeditor (~> 4.2.3)
cocaine
cocoon (~> 1.2.9)
coffee-rails (~> 4.2.2)
coveralls (~> 0.8.22)
Expand Down Expand Up @@ -585,6 +595,7 @@ DEPENDENCIES
jquery-fileupload-rails
jquery-rails (~> 4.3.3)
jquery-ui-rails (~> 6.0.1)
jw_player_helper
kaminari (~> 1.1.1)
knapsack_pro (~> 1.1.0)
launchy (~> 2.4.3)
Expand All @@ -596,6 +607,8 @@ DEPENDENCIES
omniauth-google-oauth2 (~> 0.4.0)
omniauth-twitter (~> 1.4.0)
paperclip (~> 5.2.1)
paperclip-av-transcoder
paperclip-ffmpeg
paranoia (~> 2.4.1)
pg (~> 0.21.0)
pg_search (~> 2.0.1)
Expand Down
12 changes: 10 additions & 2 deletions app/assets/javascripts/imageable.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,19 @@ App.Imageable =
$(data.errorContainer).append(errors)

setPreview: (data) ->

video_preview = "<video id='player' width='320' height='240' playsinline controls><source src='#{data.result.attachment_url}' type='video/mp4'></video>"
image_preview = "<div class='small-12 column text-center image-preview'><figure><img src='#{data.result.attachment_url}' class='cached-image'></figure></div>"
if $(data.preview).length > 0
$(data.preview).replaceWith(image_preview)
if "mp4".indexOf(data.result.filename)
$(data.preview).replaceWith(data.result.filename)
else
$(data.preview).replaceWith(image_preview)
else
$(image_preview).insertBefore($(data.wrapper).find(".attachment-actions"))
if "mp4".indexOf(data.result.filename)
$(video_preview).insertBefore($(data.wrapper).find(".attachment-actions"))
else
$(image_preview).insertBefore($(data.wrapper).find(".attachment-actions"))
data.preview = $(data.wrapper).find(".image-preview")

doDeleteCachedAttachmentRequest: (url, data) ->
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/settings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def settings_params
end

def content_type_params
params.permit(:jpg, :png, :gif, :pdf, :doc, :docx, :xls, :xlsx, :csv, :zip)
params.permit(:jpg, :png, :gif, :pdf, :doc, :docx, :xls, :xlsx, :csv, :zip, :mp4)
end

def hidden_settings
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/imageables_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def bytes_to_megabytes(bytes)
end

def imageable_accepted_content_types
Setting["uploads.images.content_types"]&.split(" ") || [ "image/jpeg" ]
Setting["uploads.images.content_types"]&.split(" ") || [ "image/jpeg", "image/gif", "video/mp4" ]
end

def imageable_accepted_content_types_extensions
Expand Down
28 changes: 18 additions & 10 deletions app/models/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,23 @@ class Image < ApplicationRecord
include ImagesHelper
include ImageablesHelper

has_attached_file :attachment, styles: {
large: "x#{Setting["uploads.images.min_height"]}",
medium: "300x300#",
thumb: "140x245#"
},
url: "/system/:class/:prefix/:style/:hash.:extension",
hash_data: ":class/:style",
use_timestamp: false,
hash_secret: Rails.application.secrets.secret_key_base
has_attached_file :attachment,
styles: lambda{ |a|
return {} unless a.content_type.in? %w(image/jpeg image/jpg image/png image/gif)
{ large: "x#{Setting["uploads.images.min_height"]}", medium: "300x300#", thumb: "140x245#" }
},
url: "/system/:class/:prefix/:style/:hash.:extension",
hash_data: ":class/:style",
use_timestamp: false,
processors: lambda { |a|
begin
a.is_video? ? [ :ffmpeg ] : [ :thumbnail ]
rescue => exception
[ :thumbnail ]
end
},
hash_secret: Rails.application.secrets.secret_key_base

attr_accessor :cached_attachment

belongs_to :user
Expand All @@ -27,7 +35,7 @@ class Image < ApplicationRecord
validates :user_id, presence: true
validates :imageable_id, presence: true, if: -> { persisted? }
validates :imageable_type, presence: true, if: -> { persisted? }
validate :validate_image_dimensions, if: -> { attachment.present? && attachment.dirty? }
validate :validate_image_dimensions, if: -> { attachment.present? && attachment.dirty? && attachment.content_type != 'video/mp4' }

before_save :set_attachment_from_cached_attachment, if: -> { cached_attachment.present? }
after_save :remove_cached_attachment, if: -> { cached_attachment.present? }
Expand Down
9 changes: 7 additions & 2 deletions app/models/setting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ def mime_types
"images" => {
"jpg" => "image/jpeg",
"png" => "image/png",
"gif" => "image/gif"
"gif" => "image/gif",
"mp4" => "video/mp4"
},
"documents" => {
"pdf" => "application/pdf",
Expand All @@ -72,6 +73,9 @@ def mime_types
"xlsx" => "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"csv" => "text/plain",
"zip" => "application/zip"
},
"videos" => {
"mp4" => "video/mp4"
}
}
end
Expand Down Expand Up @@ -164,13 +168,14 @@ def defaults
"transparency_url": "http://transparencia.madrid.es/",
"twitter_handle": "abriendomadrid",
"twitter_hashtag": "#decidemadrid",
# Images and Documents
# Images, videos and Documents
"uploads.images.title.min_length": 4,
"uploads.images.title.max_length": 80,
"uploads.images.min_width": 0,
"uploads.images.min_height": 475,
"uploads.images.max_size": 1,
"uploads.images.content_types": "image/jpeg",
"uploads.videos.content_types": "video/mp4",
"uploads.documents.max_amount": 3,
"uploads.documents.max_size": 3,
"uploads.documents.content_types": "application/pdf",
Expand Down
16 changes: 14 additions & 2 deletions app/models/site_customization/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,22 @@ class SiteCustomization::Image < ApplicationRecord
"logo_email" => [400, 80]
}

has_attached_file :image
has_attached_file :image, styles: lambda{ |a|
return {} unless a.content_type.in? %w(image/jpeg image/jpg image/png image/gif)
{ medium: "640x480", thumb: "100x100#" }
}, processors: lambda { |a|
begin
a.is_video? ? [ :ffmpeg ] : [ :thumbnail ]
rescue => exception
[ :thumbnail ]
end
}

validates_attachment_content_type :image, content_type: [ 'image/jpg', 'image/jpeg', 'image/png', 'video/mp4', 'image/gif']
# has_attached_file :image

validates :name, presence: true, uniqueness: true, inclusion: { in: VALID_IMAGES.keys }
validates_attachment_content_type :image, content_type: ["image/png", "image/jpeg"]
# validates_attachment_content_type :image, content_type: ["image/png", "image/jpeg", "image/gif", "video/mp4"]
validate :check_image

def self.all_images
Expand Down
1 change: 1 addition & 0 deletions app/views/admin/banners/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<%= javascript_include_tag 'swfobject' %>
<%= render "admin/shared/globalize_locales", resource: @banner %>
<%= translatable_form_for [:admin, @banner] do |f| %>
Expand Down
7 changes: 5 additions & 2 deletions app/views/custom/welcome/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,18 @@

<h2 class="show-for-sr"><%= t("welcome.title") %></h2>

<%= render "feeds" %>
<div class="row">
<%= render "feeds" %>
</div>

<div class="row">
<% if @cards.any? %>
<div class="small-12 column">
<%= render "cards" %>
</div>
<% end %>

</div>
<div class="row">
<div class="small-12 column">
<%= render "processes" %>
</div>
Expand Down
15 changes: 11 additions & 4 deletions app/views/images/_image.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
<%= javascript_include_tag 'swfobject' %>
<div id="image" class="small-12 column text-center image-preview">
<figure>
<%= image_tag image.attachment.url(version),
class: image_class(image),
alt: image.title.unicode_normalize,
title: image.title.unicode_normalize %>
<% if image.attachment.url(version).include? "mp4" %>

<video id='player' width='320' height='240' playsinline controls><source src='<%= image.attachment.url %>' type='video/mp4'></video>

<%else%>
<%= image_tag image.attachment.url(version),
class: image_class(image),
alt: image.title.unicode_normalize,
title: image.title.unicode_normalize %>
<%end%>
<% if show_caption %>
<figcaption class="text-right">
<em><%= image.title.unicode_normalize %></em>
Expand Down
1 change: 1 addition & 0 deletions app/views/images/_image_fields.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<%= javascript_include_tag 'swfobject' %>
<div id="<%= dom_id(f.object) %>" class="image direct-upload nested-fields">
<%= f.hidden_field :id %>
<%= f.hidden_field :user_id, value: current_user.id %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/welcome/_card.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div id="<%= dom_id(card) %>"
class="card small-12 medium-<%= card.columns %> column margin-bottom end" data-equalizer-watch>
class="card small-12 medium-<%= card.columns %> column margin-bottom end" >
<%= link_to card.link_url do %>
<figure class="figure-card">
<% if card.image.present? %>
Expand Down
6 changes: 3 additions & 3 deletions app/views/welcome/_feeds.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<% if feed_proposals?(feed) %>
<div id="feed_proposals" class="small-12 column margin-top
<%= "medium-12" if feed_debates_and_proposals_enabled? %>" style="float: left">
<div class="feed-content" data-equalizer-watch>
<div class="feed-content" >
<h3 class="title"><%= t("welcome.feed.most_active.#{feed.kind}") %></h3>

<div class="row">
Expand Down Expand Up @@ -34,7 +34,7 @@
<% if feed_debates?(feed) %>
<div id="feed_debates" class="small-12 column margin-top
<%= "medium-6" if feed_debates_and_proposals_enabled? %><%= "medium-6" if feed_debates_and_topics_enabled? %>" style="float: left">
<div class="feed-content" data-equalizer-watch>
<div class="feed-content" >
<h3 class="title"><%= t("welcome.feed.most_active.#{feed.kind}") %></h3>

<% feed.items.each do |item| %>
Expand All @@ -51,7 +51,7 @@
<% if feed_topics?(feed) %>
<div id="feed_debates" class="small-12 column margin-top
<%= "medium-6" if feed_debates_and_proposals_enabled? %><%= "medium-6" if feed_debates_and_topics_enabled? %>" style="float: left">
<div class="feed-content" data-equalizer-watch>
<div class="feed-content" >
<h3 class="title"><%= t("welcome.feed.most_active.#{feed.kind}") %></h3>

<% feed.items.each do |item| %>
Expand Down
12 changes: 9 additions & 3 deletions app/views/welcome/_header.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<%= javascript_include_tag 'swfobject' %>
<% if header.present? %>
<hr style="max-width: 100%">
<div>
Expand All @@ -13,9 +14,14 @@

<% if header.image.present? %>
<div class="small-12 medium-6 column">
<%= image_tag(header.image_url(:large),
class: "margin",
alt: header.image.title) %>
<% if header.image.title.include? "mp4" %>
<video width='500' height='300' controls="controls" autoplay loop><source src="<%=header.image.attachment.url %>"/></video>
<%else%>
<%= image_tag(header.image_url(:large),
class: "margin",
alt: header.image.title) %>
<%end%>

</div>
<% end %>
</div>
Expand Down
3 changes: 2 additions & 1 deletion config/locales/custom/es/general.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ es:
participation_title: Participación
participation_text: Decide cómo debe ser la ciudad de Madrid que quieres.
decide_madrid_title: Decide Madrid
decide_madrid_text: Es un espacio para fomentar la participación de la ciudadanía en la generación de ideas para mejorar la gestión de la ciudad.
decide_madrid_text: Es un espacio para fomentar la participación de la ciudadanía en la generación de ideas para mejorar la gestión de la ciudad.<br>
<a href='https://decide.madrid.es/siparticipasdecides'>Si participas, decides</a>
problem_title: ¿Problemas técnicos?
problem_text: "Lee las preguntas frecuentes y resuelve tus dudas: <br>
<a href='mas-informacion/faq'>Preguntas frecuentes</a><br><br>
Expand Down
4 changes: 4 additions & 0 deletions config/locales/es/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ es:
max_size: "Tamaño máximo de imagen"
max_size_description: "Tamaño máximo permitido al subir una imagen (en Megabytes/MB)"
content_types: "Tipos de imagenes permitidos"
mp4_active: "Tipos de videos permitidos"
content_types_description: "Selecciona todos los tipos permitidos para las imágenes subidas"
title:
min_length: "Longitud mínima del título de la imagen"
Expand All @@ -193,3 +194,6 @@ es:
max_size_description: "Tamaño máximo permitido al subir un documento (en Megabytes/MB)"
content_types: "Tipos de documentos permitidos"
content_types_description: "Selecciona todos los tipos permitidos para los documentos subidos"
videos:
content_types: "Tipos de videos permitidos"
content_types_description: "Selecciona todos los tipos permitidos para los videos subidos"
6 changes: 6 additions & 0 deletions lib/tasks/settings.rake
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,10 @@ namespace :settings do
puts "Temas añadidos a la página principal"
end
end

task add_video_content_types: :environment do
if Setting.new(key: "uploads.videos.content_types", value: "video/mp4").save!
puts "Tipos de videos añadidos a la página principal"
end
end
end

0 comments on commit 8be27b0

Please sign in to comment.