Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# == Schema Information
#
# Table name: communication_website_portfolio_project_localizations
#
# id :uuid not null, primary key
# featured_image_alt :string
# featured_image_credit :text
# meta_description :string
# migration_identifier :string
# published :boolean default(FALSE)
# published_at :datetime
# slug :string
# summary :text
# title :string
# created_at :datetime not null
# updated_at :datetime not null
# about_id :uuid indexed
# communication_website_id :uuid indexed
# language_id :uuid indexed
# university_id :uuid indexed
#
# Indexes
#
# idx_on_about_id_a668ef6090 (about_id)
# idx_on_communication_website_id_e653b6273a (communication_website_id)
# idx_on_language_id_25a0c1e472 (language_id)
# idx_on_university_id_f01fc2c686 (university_id)
#
# Foreign Keys
#
# fk_rails_3145135b3c (communication_website_id => communication_websites.id)
# fk_rails_be29689be2 (language_id => languages.id)
# fk_rails_c1a10dcae3 (university_id => universities.id)
# fk_rails_fbc92c5948 (about_id => communication_website_portfolio_projects.id)
#
class Communication::Website::Portfolio::Project::Localization < ApplicationRecord
include AsLocalization
include Contentful
include Initials
include Permalinkable
include Sanitizable
include Shareable
include WithAccessibility
include WithBlobs
include WithFeaturedImage
include WithGitFiles
include WithPublication
include WithUniversity
belongs_to :website,
class_name: 'Communication::Website',
foreign_key: :communication_website_id
validates :title, presence: true
before_validation :set_communication_website_id, on: :create
scope :ordered, -> (language = nil) { order(year: :desc, title: :asc) }
scope :published, -> { where(published: true) }
scope :draft, -> { where(published: false) }
scope :latest, -> { published.order(updated_at: :desc).limit(5) }
# TODO L10N : To adapt
scope :for_search_term, -> (term) {
where("
unaccent(communication_website_portfolio_projects.meta_description) ILIKE unaccent(:term) OR
unaccent(communication_website_portfolio_projects.summary) ILIKE unaccent(:term) OR
unaccent(communication_website_portfolio_projects.title) ILIKE unaccent(:term)
", term: "%#{sanitize_sql_like(term)}%")
}
def git_path(website)
return unless website.id == communication_website_id && published
git_path_content_prefix(website) + git_path_relative
end
def git_path_relative
"projects/#{about.year}-#{slug}.html"
end
def template_static
"admin/communication/websites/portfolio/projects/static"
end
def dependencies
active_storage_blobs +
contents_dependencies
end
def to_s
"#{title}"
end
protected
def check_accessibility
accessibility_merge_array blocks
end
def explicit_blob_ids
super.concat [
featured_image&.blob_id,
shared_image&.blob_id
]
end
def set_communication_website_id
self.communication_website_id ||= about.communication_website_id
end
end