Skip to content

Commit

Permalink
🚚 Rename video url (#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
cprodhomme authored Nov 25, 2024
1 parent c7d49b2 commit 17966d5
Show file tree
Hide file tree
Showing 10 changed files with 313 additions and 283 deletions.
6 changes: 3 additions & 3 deletions app/avo/resources/video.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ class Avo::Resources::Video < Avo::BaseResource
def fields
field :id, as: :id
field :title, as: :text
field :vimeo_thumbnail, as: :text, as_html: true, hide_on: [ :forms ] do
"<img src='#{record.vimeo_thumbnail}' width='100' />"
field :thumbnail_url, as: :text, as_html: true, hide_on: [ :forms ] do
"<img src='#{record.thumbnail_url}' width='100' />"
end
field :vimeo_url, as: :text, hide_on: [ :index ]
field :url, as: :text, hide_on: [ :index ]
field :description, as: :textarea, hide_on: [ :index ]
field :event_date, as: :date
field :slug, as: :text, hide_on: [ :index ], help: "Laissez le champs vide pour qu'il soit complété automatiquement"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useIntersection } from 'stimulus-use'
//
// Somethime we need to transition element only if they are within the view port
// This controller is used to the view transition name to the element when it is visible only
// <%= image_tag video.vimeo_thumbnail, data: { controller: "view-transition-intersection", view_transition_intersection_name_value: dom_id(video, :preview) } %>
// <%= image_tag video.thumbnail_url, data: { controller: "view-transition-intersection", view_transition_intersection_name_value: dom_id(video, :preview) } %>
export default class extends Controller {
static values = { name: String }

Expand Down
25 changes: 25 additions & 0 deletions app/models/lineup.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
# == Schema Information
#
# Table name: talks
#
# id :bigint not null, primary key
# duration :string
# happened_at :date
# level :string
# preferred_month_talk :string
# priority :string
# slides :string
# speaker_email :string
# speaker_name :string
# speaker_twitter :string
# time_position :datetime
# title :string
# video_url :string
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_talks_on_created_at (created_at)
# index_talks_on_happened_at (happened_at)
#
# this sub model is used to display a custom view in the Admin
class Lineup < Talk
default_scope { lineup }
Expand Down
29 changes: 14 additions & 15 deletions app/models/video.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
#
# Table name: videos
#
# id :bigint not null, primary key
# description :text
# event_date :date
# slug :string
# title :string
# vimeo_thumbnail :string
# vimeo_url :string
# created_at :datetime not null
# updated_at :datetime not null
# id :bigint not null, primary key
# description :text
# event_date :date
# slug :string
# thumbnail_url :string
# title :string
# url :string
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
Expand Down Expand Up @@ -44,33 +44,32 @@ def provider_id
}[provider]
end

def vimeo_thumbnail
def thumbnail_url
return "https://img.youtube.com/vi/#{youtube_id}/maxresdefault.jpg" if youtube?

self[:vimeo_thumbnail].presence || "#"
self[:thumbnail_url].presence || "#"
end

def short_description
description&.truncate(170, separator: " ")
end

def self.ransackable_attributes(auth_object = nil)
%w[vimeo_url title description slug]
%w[url title description slug]
end

private

def vimeo_id
vimeo_url[/vimeo.com\/(\d+)/, 1]
url[/vimeo.com\/(\d+)/, 1]
end


def vimeo?
vimeo_id.present?
end

def youtube_id
vimeo_url[/youtube.com\/watch\?v=(.*)/, 1]
url[/youtube.com\/watch\?v=(.*)/, 1]
end

def youtube?
Expand Down
2 changes: 1 addition & 1 deletion app/views/videos/_card.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<div class="bg-white shadow-lg rounded-lg overflow-hidden">
<%= link_to video_path(video.slug), target: "_top" do %>
<%= image_tag video.vimeo_thumbnail,
<%= image_tag video.thumbnail_url,
class: 'w-full object-cover',
alt: t('videos.card.thumbnail_alt', title: video.title),
style: "view-transition-name: #{dom_id(video, :preview)}" %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/videos/_compact_card.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<div class="bg-white shadow-lg rounded-lg overflow-hidden">
<%= link_to video_path(video.slug), target: "_top" do %>
<%= image_tag video.vimeo_thumbnail,
<%= image_tag video.thumbnail_url,
data: { controller: "view-transition-intersection",
view_transition_intersection_name_value: dom_id(video, :preview) },
alt: t('videos.card.thumbnail_alt', title: video.title),
Expand Down
2 changes: 1 addition & 1 deletion app/views/videos/_youtube.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<div role="tabpanel" class="tab-content bg-base-100 border-base-300 rounded-box p-6">
<div class="font-semibold mb-8"><%= video.title %></div>
<p class="mb-8"><%= video.description %></p>
<%= link_to video.vimeo_url, class: "link flex items-center gap-2", target: "_blank" do %>
<%= link_to video.url, class: "link flex items-center gap-2", target: "_blank" do %>
<%= lucide_icon("youtube", "aria-hidden": true) %>
<%= t(".link") %>
<% end %>
Expand Down
6 changes: 6 additions & 0 deletions db/migrate/20241124204014_rename_vimeo_url_from_videos.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class RenameVimeoUrlFromVideos < ActiveRecord::Migration[7.1]
def change
rename_column :videos, :vimeo_url, :url
rename_column :videos, :vimeo_thumbnail, :thumbnail_url
end
end
6 changes: 3 additions & 3 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.1].define(version: 2024_05_14_173919) do
ActiveRecord::Schema[7.1].define(version: 2024_11_24_204014) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

Expand Down Expand Up @@ -135,8 +135,8 @@
end

create_table "videos", force: :cascade do |t|
t.string "vimeo_url"
t.string "vimeo_thumbnail"
t.string "url"
t.string "thumbnail_url"
t.string "title"
t.text "description"
t.date "event_date"
Expand Down
Loading

0 comments on commit 17966d5

Please sign in to comment.