Skip to content

Commit 834e8e3

Browse files
authored
Consolidate image display (#606)
* Decorate * Change redirect_to_external to use noopener noreferrer * Don't support external urls for Resources anymore * Allow stories to open show page if no_redirect param is passed * Fix leader_spotlights to be found correctly * Remove the old main_image_url and instead use display_image and default_display_image methods * Support pdf's for main_image and gallery_image * Remove main_image_url method * Add back in resource kinds for now * Separate directly-associated resources from resources through: workshop_resources * Delete bookmarks flex, since it's unused * Remove unused index.js.erb * Consolidate media/image partials so there's a shared interface * No need to conditionally check responds to title, since all decorators have title implemented * Delete bookmarks/index.js.erb * Replace quotes * Show bookmarks personal_row on bookmarks show * Don't update led_count via turbo stream anymore since it's a static value * Move all dashboard content 'cards' to their respective views folder * Add new media partials for a consolidated interface for image display * Update event_registration displays * Update resources form -- url field needs to be re-attached. and, attachments need to be reattached as 'images' * Don't show cursor-pointer for the whole resource card * Remove external_link reference from resource bc the 'url' field is being used for pdf's rn, not external links * Move the Resource kind_display logic to the decorator * Allow sizes and variants to be sent to the resource_icon svg partial * Show resource windows_type, if present * Fix indentation * Don't show Attachments on Resource show anymore * Only iterate over present attachments * Change form_image_field partials and related calls to them * Add organizations and facilitators to nav * Pre-select story details from params * Make stories index view button pass param to open show page rather than external link * Show image on story_ideas index * Correct color call on workshop_ideas index * Fix indentation * Add /n * Fix LeaderSpotlight display on Workshop show show_associations * Change capitalization and indentation of workshop sections, and add spanish translation for Age range * Tweak image storage settings to support pdf previews in dev, prod, staging (will prob need to install some libraries on DO) * WIP rake task to convert resource pdf's stored in 'url' field into real image uploads * Futz w names of resource assns on workshop * Fix tests that refer to alt titles * Don't validate external url for resources anymore * Test on classes not alt text * Properly assign decorated index collection in tests * Replace tabs w spaces * Fix tabs and spacing * Adjust decorator so we don't need to call html_safe anymore to appease rubocop
1 parent 0a93b4b commit 834e8e3

File tree

93 files changed

+1010
-1112
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+1010
-1112
lines changed

app/controllers/bookmarks_controller.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ class BookmarksController < ApplicationController
33

44
def index
55
per_page = params[:number_of_items_per_page] || 25
6-
bookmarks = Bookmark.search(params)
7-
bookmarks = bookmarks.sorted(params[:sort])
6+
unfiltered = Bookmark.all
7+
filtered = unfiltered.search(params)
8+
filtered = filtered.sorted(params[:sort])
89

9-
@bookmarks = bookmarks.paginate(page: params[:page], per_page: per_page)
10-
@bookmarks_count = bookmarks.length
10+
@bookmarks = filtered.paginate(page: params[:page], per_page: per_page).decorate
11+
@bookmarks_count = unfiltered.length
1112
@windows_types_array = WindowsType::TYPES
1213
set_index_variables
1314
respond_to do |format|

app/controllers/concerns/externally_redirectable.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ module ExternallyRedirectable
22
extend ActiveSupport::Concern
33

44
def redirect_to_external(url)
5-
redirect_to url, allow_other_host: true
5+
redirect_to url, allow_other_host: true, rel: "noopener noreferrer"
66
end
77
end

app/controllers/resources_controller.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@ def show
4141
@resource = Resource.find(resource_id_param).decorate
4242
@resource.increment_view_count!(session: session, request: request)
4343
load_forms
44-
45-
if @resource.external_url.present?
46-
redirect_to_external @resource.link_target
47-
nil
48-
end
4944
end
5045

5146
def rhino_text

app/controllers/stories_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def show
2121
@story = @story.decorate
2222
@story.increment_view_count!(session: session, request: request)
2323

24-
if @story.external_url.present?
24+
if @story.external_url.present? && !params[:no_redirect].present?
2525
redirect_to_external @story.link_target
2626
nil
2727
end

app/controllers/story_ideas_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def index
77

88
story_ideas = StoryIdea.includes(:windows_type, :project, :workshop, :created_by, :updated_by)
99
@story_ideas = story_ideas.order(created_at: :desc)
10-
.paginate(page: params[:page], per_page: per_page)
10+
.paginate(page: params[:page], per_page: per_page).decorate
1111

1212
@story_ideas_count = story_ideas.size
1313
end

app/controllers/workshop_ideas_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ def index
55
per_page = params[:number_of_items_per_page].presence || 25
66
workshop_ideas = WorkshopIdea.search(params.slice(:title, :author_name))
77
@workshop_ideas_count = workshop_ideas.size
8-
@workshop_ideas = workshop_ideas.paginate(page: params[:page], per_page: per_page)
8+
@workshop_ideas = workshop_ideas.paginate(page: params[:page], per_page: per_page).decorate
99
end
1010

1111
def show

app/controllers/workshops_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def search
151151
def set_show
152152
@workshop = Workshop.find(params[:id]).decorate
153153
@quotes = Quote.where(workshop_id: @workshop.id).active
154-
@leader_spotlights = @workshop.resources.published.leader_spotlights
154+
@leader_spotlights = @workshop.associated_resources.leader_spotlights.where(inactive: false)
155155
@workshop_variations = @workshop.workshop_variations.active
156156
@sectors = @workshop.sectorable_items.published.map { |item| item.sector if item.sector.published }.compact if @workshop.sectorable_items.any?
157157
end

app/decorators/application_decorator.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
class ApplicationDecorator < Draper::Decorator
22
delegate_all
33

4+
def display_image
5+
return main_image.file if object.respond_to?(:main_image) && main_image&.file&.attached?
6+
return gallery_images.first.file if object.respond_to?(:gallery_images) && gallery_images.first&.file&.attached?
7+
return images.first.file if object.respond_to?(:images) && images.first&.file&.attached?
8+
return attachments.first.file if object.respond_to?(:attachments) && attachments.first&.file&.attached?
9+
default_display_image
10+
end
11+
12+
def default_display_image
13+
"theme_default.png"
14+
end
15+
416
def link_target
517
h.polymorphic_path(object)
618
end

app/decorators/bookmark_decorator.rb

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ def detail
1010
"Bookmarkable: #{bookmarkable_class_name} ##{bookmarkable.id} (#{bookmarkable.title})"
1111
end
1212

13+
def display_image
14+
bookmarkable.decorate.display_image
15+
end
16+
1317
def breadcrumbs
1418
"#{bookmarks_link} >> #{bookmarkable_link}".html_safe
1519
end
@@ -36,14 +40,4 @@ def bookmarkable_link
3640
bookmarkable.breadcrumb_link
3741
end
3842
end
39-
40-
def bookmarkable_image_url(fallback: "missing.png")
41-
if bookmarkable.respond_to?(:images) && bookmarkable.images.first&.file&.attached?
42-
Rails.application.routes.url_helpers.rails_blob_path(bookmarkable.images.first.file, only_path: true)
43-
elsif bookmarkable_type == "Workshop"
44-
ActionController::Base.helpers.asset_path("workshop_default.jpg")
45-
else
46-
ActionController::Base.helpers.asset_path(fallback)
47-
end
48-
end
4943
end

app/decorators/community_news_decorator.rb

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,4 @@ def external_url
1212
def inactive?
1313
!published?
1414
end
15-
16-
def main_image_url
17-
if main_image&.file&.attached?
18-
Rails.application.routes.url_helpers.url_for(main_image.file)
19-
elsif gallery_images.first&.file&.attached?
20-
Rails.application.routes.url_helpers.url_for(gallery_images.first.file)
21-
else
22-
ActionController::Base.helpers.asset_path("theme_default.png")
23-
end
24-
end
2515
end

0 commit comments

Comments
 (0)