Skip to content

Commit

Permalink
Multimedia gallery from conference media links (#25)
Browse files Browse the repository at this point in the history
* Multimedia gallery from conference media links

* Change multimedia path

* Lock ChromeDriver to 119.0.6045.105

* Apply styles on multimedia page

* Fix .gitignore and configurable local database and secret key base configurable

* Lint files

* Schedule multimedia gallery rake task

* Lint file

* Pinning chrome version to v119
  • Loading branch information
fblupi authored Feb 26, 2024
1 parent c3d9ed5 commit e5b0e01
Show file tree
Hide file tree
Showing 15 changed files with 185 additions and 5 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ jobs:
ruby-version: ${{ env.RUBY_VERSION }}
bundler-cache: true

- uses: nanasess/setup-chromedriver@v2
with:
chromedriver-version: 119.0.6045.105

- name: List Chrome
shell: "bash"
run: apt list --installed | grep chrome

- name: Remove Chrome
shell: "bash"
run: sudo apt remove google-chrome-stable

- uses: browser-actions/setup-chrome@v1
with:
chrome-version: 119.0.6045.105

- name: Bundle Install
run: bundle install

Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ node_modules
yarn-debug.log*
.yarn-integrity

public/sw.js
public/sw.js.map
public/sw.js*
public/sw.js.map*
15 changes: 15 additions & 0 deletions app/controllers/multimedia_gallery_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

class MultimediaGalleryController < Decidim::ApplicationController
helper_method :media_links

private

def media_links
@media_links ||= begin
JSON.parse(File.read(Rails.root.join("tmp/multimedia/#{current_organization.id}.json"))).map(&:deep_symbolize_keys)
rescue Errno::ENOENT
[]
end
end
end
49 changes: 49 additions & 0 deletions app/jobs/plataformess/multimedia/sync_all_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# frozen_string_literal: true

module Plataformess
module Multimedia
class SyncAllJob < ApplicationJob
queue_as :default

def perform(organization_id)
media_links = media_links(organization_id)
Rails.logger.info "SyncAllJob: #{media_links.count} media links to process"
return if media_links.empty?

store_result(organization_id, media_links.map { |media_link| process_media_link(media_link) })
end

private

def store_result(organization_id, result)
File.write(Rails.root.join("tmp/multimedia/#{organization_id}.json"), result.to_json)
end

def media_links(organization_id)
@media_links ||= Decidim::Conferences::MediaLink.left_outer_joins(conference: :scope)
.where(conference: { decidim_organization_id: organization_id })
.order(updated_at: :desc)
end

def process_media_link(media_link)
{
title: media_link.title,
date: media_link.date,
link: process_link(media_link.link),
conference_slug: media_link.conference.slug,
scope: media_link.conference.scope.present? ? media_link.conference.scope.name : nil
}
end

def process_link(link)
return peertube_embed_url(link) if link.match?("peertube")

link
end

def peertube_embed_url(url)
url.match?("watch") ? url.gsub("watch", "embed") : url.gsub("/w/", "/videos/embed/")
end
end
end
end
1 change: 1 addition & 0 deletions app/packs/stylesheets/plataformess.scss
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,4 @@
@import "plataformess/process";
@import "plataformess/social_crowdfunding";
@import "plataformess/tables";
@import "plataformess/multimedia_gallery";
39 changes: 39 additions & 0 deletions app/packs/stylesheets/plataformess/_multimedia_gallery.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
.multimedia_gallery {
.row {
display: flex;
}

@media screen and (max-width: 596px) {
.row {
flex-direction: column-reverse;
padding-bottom: 10%;
}
}

.column {
flex: 1;
}

.info{
flex: 1;
display: flex;
flex-direction: column;
justify-content: left;
align-items: flex-start;
padding: 5%;
overflow: hidden;
}

.tags {
li {
a {
cursor: default;
text-decoration: none;
color: inherit;
&:hover {
border-color: $link-color;
}
}
}
}
}
19 changes: 19 additions & 0 deletions app/views/multimedia_gallery/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<div class="multimedia_gallery">
<% media_links.each do |media_link| %>
<div class="row">
<div class="column">
<div class="responsive-embed widescreen">
<iframe sandbox="allow-same-origin allow-scripts allow-popups" src="<%= media_link[:link] %>" frameborder="0" allowfullscreen></iframe>
</div>
</div>
<div class="info">
<h2 class="heading2"><%= translated_attribute media_link[:title] %></h2>
<p><%= l(Date.parse(media_link[:date]), format: :decidim_short_with_month_name_short) %></p>
<% if media_link[:scope].present? %>
<ul class="tags"><li><a><%= translated_attribute media_link[:scope] %></a></li></ul>
<% end %>
<%= link_to t("conferences.multimedia_gallery.go_to_conference"), Decidim::Conferences::Engine.routes.url_helpers.conference_path(slug: media_link[:conference_slug]), target: "_blank" %>
</div>
</div>
<% end %>
</div>
13 changes: 13 additions & 0 deletions app/workers/multimedia_gallery_worker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

require "rake"

Rails.application.load_tasks

class MultimediaGalleryWorker
include Sidekiq::Worker

def perform(*_args)
Rake::Task["plataformess:multimedia:sync:all"].invoke
end
end
2 changes: 1 addition & 1 deletion config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ default: &default

development:
<<: *default
database: decidim-plataformess_development
database: <%= ENV.fetch("DATABASE_NAME") { "decidim-plataformess_development" } %>

# The specified database role being used to connect to postgres.
# To create additional roles in postgres see `$ createuser --help`.
Expand Down
5 changes: 5 additions & 0 deletions config/locales/ca.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
ca:
conferences:
multimedia_gallery:
go_to_conference: Anar a la jornada
4 changes: 3 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
---
en:
hello: Hello world
conferences:
multimedia_gallery:
go_to_conference: Go to conference
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@

mount Decidim::Core::Engine => "/"
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html

resources :multimedia_gallery, only: :index
end
5 changes: 5 additions & 0 deletions config/schedule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ data_job:
cron: "3 3 * * *"
class: "DataPortabilityWorker"
queue: default

multimedia_gallery_job:
cron: "0 1 * * *"
class: "MultimediaGalleryWorker"
queue: default
2 changes: 1 addition & 1 deletion config/secrets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ default: &default

development:
<<: *default
secret_key_base: d68bdd64e847c12983623875b9c7e1fd16e36b4ea46e5d44c83bfb49b29af647af3b4b2741a6b7032e74e88018db0de5a206caa9b8b198c295aaad820d8b904a
secret_key_base: <%= Decidim::Env.new("SECRET_KEY_BASE", "d68bdd64e847c12983623875b9c7e1fd16e36b4ea46e5d44c83bfb49b29af647af3b4b2741a6b7032e74e88018db0de5a206caa9b8b198c295aaad820d8b904a") %>
omniauth:
developer:
enabled: true
Expand Down
14 changes: 14 additions & 0 deletions lib/tasks/plataformess/multimedia.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

namespace :plataformess do
namespace :multimedia do
namespace :sync do
desc "Sync all media links"
task all: :environment do
Decidim::Organization.find_each do |organization|
Plataformess::Multimedia::SyncAllJob.perform_now(organization.id)
end
end
end
end
end

0 comments on commit e5b0e01

Please sign in to comment.