diff --git a/Gemfile b/Gemfile index d1c4057aeb2..a0784a635ea 100644 --- a/Gemfile +++ b/Gemfile @@ -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" diff --git a/Gemfile.lock b/Gemfile.lock index 22b278fb90c..2e583920a16 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/app/assets/javascripts/imageable.js.coffee b/app/assets/javascripts/imageable.js.coffee index bdb71f4f97a..c3de68e9216 100644 --- a/app/assets/javascripts/imageable.js.coffee +++ b/app/assets/javascripts/imageable.js.coffee @@ -121,11 +121,19 @@ App.Imageable = $(data.errorContainer).append(errors) setPreview: (data) -> + + video_preview = "" image_preview = "
" 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) -> diff --git a/app/controllers/admin/settings_controller.rb b/app/controllers/admin/settings_controller.rb index 2e4f1ad8a3f..9e159df7df0 100644 --- a/app/controllers/admin/settings_controller.rb +++ b/app/controllers/admin/settings_controller.rb @@ -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 diff --git a/app/helpers/imageables_helper.rb b/app/helpers/imageables_helper.rb index 7c8d872981d..4093040df82 100644 --- a/app/helpers/imageables_helper.rb +++ b/app/helpers/imageables_helper.rb @@ -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 diff --git a/app/models/image.rb b/app/models/image.rb index 6929f5f96aa..b884f414b7c 100644 --- a/app/models/image.rb +++ b/app/models/image.rb @@ -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 @@ -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? } diff --git a/app/models/setting.rb b/app/models/setting.rb index 91aa42595ae..cc091c34149 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -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", @@ -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 @@ -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", diff --git a/app/models/site_customization/image.rb b/app/models/site_customization/image.rb index a98ba62acbe..5a9ef3d4198 100644 --- a/app/models/site_customization/image.rb +++ b/app/models/site_customization/image.rb @@ -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 diff --git a/app/views/admin/banners/_form.html.erb b/app/views/admin/banners/_form.html.erb index 8e8d423e814..9e144363db4 100644 --- a/app/views/admin/banners/_form.html.erb +++ b/app/views/admin/banners/_form.html.erb @@ -1,3 +1,4 @@ +<%= javascript_include_tag 'swfobject' %> <%= render "admin/shared/globalize_locales", resource: @banner %> <%= translatable_form_for [:admin, @banner] do |f| %> diff --git a/app/views/custom/welcome/index.html.erb b/app/views/custom/welcome/index.html.erb index 6d7a4a56fe8..e5842ec28a3 100644 --- a/app/views/custom/welcome/index.html.erb +++ b/app/views/custom/welcome/index.html.erb @@ -29,7 +29,9 @@

<%= t("welcome.title") %>

- <%= render "feeds" %> +
+ <%= render "feeds" %> +
<% if @cards.any? %> @@ -37,7 +39,8 @@ <%= render "cards" %>
<% end %> - + +
<%= render "processes" %>
diff --git a/app/views/images/_image.html.erb b/app/views/images/_image.html.erb index 65ef9324e49..5b260505460 100644 --- a/app/views/images/_image.html.erb +++ b/app/views/images/_image.html.erb @@ -1,9 +1,16 @@ +<%= javascript_include_tag 'swfobject' %>
- <%= 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" %> + + + + <%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 %>
<%= image.title.unicode_normalize %> diff --git a/app/views/images/_image_fields.html.erb b/app/views/images/_image_fields.html.erb index 7fbfb0f01de..679209cc226 100644 --- a/app/views/images/_image_fields.html.erb +++ b/app/views/images/_image_fields.html.erb @@ -1,3 +1,4 @@ +<%= javascript_include_tag 'swfobject' %>
<%= f.hidden_field :id %> <%= f.hidden_field :user_id, value: current_user.id %> diff --git a/app/views/welcome/_card.html.erb b/app/views/welcome/_card.html.erb index bd8274c3449..8418b88b50e 100644 --- a/app/views/welcome/_card.html.erb +++ b/app/views/welcome/_card.html.erb @@ -1,5 +1,5 @@
+ class="card small-12 medium-<%= card.columns %> column margin-bottom end" > <%= link_to card.link_url do %>
<% if card.image.present? %> diff --git a/app/views/welcome/_feeds.html.erb b/app/views/welcome/_feeds.html.erb index 8c9357efff3..526ab52a71b 100644 --- a/app/views/welcome/_feeds.html.erb +++ b/app/views/welcome/_feeds.html.erb @@ -4,7 +4,7 @@ <% if feed_proposals?(feed) %>
" style="float: left"> -
+

<%= t("welcome.feed.most_active.#{feed.kind}") %>

@@ -34,7 +34,7 @@ <% if feed_debates?(feed) %>
<%= "medium-6" if feed_debates_and_topics_enabled? %>" style="float: left"> -
+

<%= t("welcome.feed.most_active.#{feed.kind}") %>

<% feed.items.each do |item| %> @@ -51,7 +51,7 @@ <% if feed_topics?(feed) %>
<%= "medium-6" if feed_debates_and_topics_enabled? %>" style="float: left"> -
+

<%= t("welcome.feed.most_active.#{feed.kind}") %>

<% feed.items.each do |item| %> diff --git a/app/views/welcome/_header.html.erb b/app/views/welcome/_header.html.erb index f678fc62e2f..d9d53198173 100644 --- a/app/views/welcome/_header.html.erb +++ b/app/views/welcome/_header.html.erb @@ -1,3 +1,4 @@ +<%= javascript_include_tag 'swfobject' %> <% if header.present? %>
@@ -13,9 +14,14 @@ <% if header.image.present? %>
- <%= image_tag(header.image_url(:large), - class: "margin", - alt: header.image.title) %> + <% if header.image.title.include? "mp4" %> + + <%else%> + <%= image_tag(header.image_url(:large), + class: "margin", + alt: header.image.title) %> + <%end%> +
<% end %>
diff --git a/config/locales/custom/es/general.yml b/config/locales/custom/es/general.yml index 12da29ce707..61ac435dff0 100644 --- a/config/locales/custom/es/general.yml +++ b/config/locales/custom/es/general.yml @@ -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.
+ Si participas, decides problem_title: ¿Problemas técnicos? problem_text: "Lee las preguntas frecuentes y resuelve tus dudas:
Preguntas frecuentes

diff --git a/config/locales/es/settings.yml b/config/locales/es/settings.yml index 00b11e39d3e..745d4762181 100644 --- a/config/locales/es/settings.yml +++ b/config/locales/es/settings.yml @@ -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" @@ -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" diff --git a/lib/tasks/settings.rake b/lib/tasks/settings.rake index ce420ff8e76..1b6f83fea86 100644 --- a/lib/tasks/settings.rake +++ b/lib/tasks/settings.rake @@ -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