summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2026-07-21 22:28:18 +0200
committererdgeist <erdgeist@erdgeist.org>2026-07-21 22:28:18 +0200
commit9c951f3a0f379b0f459988106cf3f839acdadbe2 (patch)
treead51cb1700689bfa0915a1319576412d68f66150
parent987c8224c7f1bafb84d5e284ff0093921b92f1a0 (diff)
More PDF headline eligibility
-rw-r--r--app/controllers/related_assets_controller.rb4
-rw-r--r--app/models/asset.rb6
-rw-r--r--app/views/nodes/edit.html.erb2
-rw-r--r--test/models/asset_test.rb5
4 files changed, 14 insertions, 3 deletions
diff --git a/app/controllers/related_assets_controller.rb b/app/controllers/related_assets_controller.rb
index 2fefaf7..560df75 100644
--- a/app/controllers/related_assets_controller.rb
+++ b/app/controllers/related_assets_controller.rb
@@ -5,10 +5,10 @@ class RelatedAssetsController < ApplicationController
5 def search 5 def search
6 term = params[:search_term].to_s.strip 6 term = params[:search_term].to_s.strip
7 attached_ids = @node.editable_page.related_assets.pluck(:asset_id) 7 attached_ids = @node.editable_page.related_assets.pluck(:asset_id)
8 scope = Asset.images.where.not(id: attached_ids) 8 scope = Asset.headline_eligible.where.not(id: attached_ids)
9 9
10 results = if term.present? 10 results = if term.present?
11 scope.where("name ILIKE ?", "%#{term}%").limit(10) 11 scope.where("name ILIKE :term OR upload_file_name ILIKE :term", term: "%#{term}%").limit(10)
12 else 12 else
13 scope.order(created_at: :desc).limit(5) 13 scope.order(created_at: :desc).limit(5)
14 end 14 end
diff --git a/app/models/asset.rb b/app/models/asset.rb
index 4a295d8..8aa5415 100644
--- a/app/models/asset.rb
+++ b/app/models/asset.rb
@@ -1,5 +1,6 @@
1class Asset < ApplicationRecord 1class Asset < ApplicationRecord
2 IMAGE_CONTENT_TYPES = ["image/gif", "image/jpeg", "image/png", "image/webp"] 2 IMAGE_CONTENT_TYPES = ["image/gif", "image/jpeg", "image/png", "image/webp"]
3 PDF_CONTENT_TYPE = "application/pdf"
3 4
4 include FileAttachment 5 include FileAttachment
5 6
@@ -9,6 +10,7 @@ class Asset < ApplicationRecord
9 scope :images, -> { where(:upload_content_type => IMAGE_CONTENT_TYPES) } 10 scope :images, -> { where(:upload_content_type => IMAGE_CONTENT_TYPES) }
10 scope :documents, -> { where(:upload_content_type => ["application/pdf", "text/plain", "text/rtf"]) } 11 scope :documents, -> { where(:upload_content_type => ["application/pdf", "text/plain", "text/rtf"]) }
11 scope :audio, -> { where(:upload_content_type => ["audio/mpeg", "audio/x-m4a", "audio/wav", "audio/x-wav"]) } 12 scope :audio, -> { where(:upload_content_type => ["audio/mpeg", "audio/x-m4a", "audio/wav", "audio/x-wav"]) }
13 scope :headline_eligible, -> { where(:upload_content_type => IMAGE_CONTENT_TYPES + [PDF_CONTENT_TYPE]) }
12 14
13 validates :license_key, inclusion: { in: -> { AssetLicense.keys } }, allow_blank: true 15 validates :license_key, inclusion: { in: -> { AssetLicense.keys } }, allow_blank: true
14 16
@@ -16,6 +18,10 @@ class Asset < ApplicationRecord
16 IMAGE_CONTENT_TYPES.include?(upload_content_type) 18 IMAGE_CONTENT_TYPES.include?(upload_content_type)
17 end 19 end
18 20
21 def pdf?
22 upload_content_type == PDF_CONTENT_TYPE
23 end
24
19 def has_credit? 25 def has_credit?
20 creator.present? || source_url.present? || license_key.present? 26 creator.present? || source_url.present? || license_key.present?
21 end 27 end
diff --git a/app/views/nodes/edit.html.erb b/app/views/nodes/edit.html.erb
index 07b42d4..f06ccaf 100644
--- a/app/views/nodes/edit.html.erb
+++ b/app/views/nodes/edit.html.erb
@@ -102,7 +102,7 @@
102 </li> 102 </li>
103 <% end %> 103 <% end %>
104 </ul> 104 </ul>
105 <p class="field_hint">The starred photo becomes this page's headline image on the public site. If none is starred, visitors get a link to browse all attached images instead.</p> 105 <p class="field_hint">The starred image or PDF becomes this page's headline on the public site. If none is starred, visitors get a link to browse all attached images instead.</p>
106 <%= text_field_tag nil, nil, id: "related_asset_search_term", placeholder: "Search images to attach…", autocomplete: "off" %> 106 <%= text_field_tag nil, nil, id: "related_asset_search_term", placeholder: "Search images to attach…", autocomplete: "off" %>
107 <div id="related_asset_search_results" class="search_results"></div> 107 <div id="related_asset_search_results" class="search_results"></div>
108 </div> 108 </div>
diff --git a/test/models/asset_test.rb b/test/models/asset_test.rb
index d246abe..cda0a04 100644
--- a/test/models/asset_test.rb
+++ b/test/models/asset_test.rb
@@ -41,4 +41,9 @@ class AssetTest < ActiveSupport::TestCase
41 test "license_key may be blank" do 41 test "license_key may be blank" do
42 assert Asset.new(:license_key => nil).valid? 42 assert Asset.new(:license_key => nil).valid?
43 end 43 end
44
45 test "pdf? is true only for application/pdf" do
46 assert Asset.new(:upload_content_type => "application/pdf").pdf?
47 assert_not Asset.new(:upload_content_type => "image/png").pdf?
48 end
44end 49end