1diff --git a/app/controllers/collection_items_controller.rb b/app/controllers/collection_items_controller.rb
2index f3cc41724..00156750a 100644
3--- a/app/controllers/collection_items_controller.rb
4+++ b/app/controllers/collection_items_controller.rb
5@@ -23,7 +23,7 @@ class CollectionItemsController < ApplicationController
6 @collection_items.unreviewed_by_collection
7 end
8 elsif params[:user_id] && (@user = User.find_by(login: params[:user_id])) && @user == current_user
9- @collection_items = CollectionItem.for_user(@user).includes(:collection)
10+ @collection_items = CollectionItem.for_user(@user).includes(:collection).merge(Collection.with_attached_icon)
11 @collection_items = case params[:status]
12 when "approved"
13 @collection_items.approved_by_both
14diff --git a/app/controllers/collections_controller.rb b/app/controllers/collections_controller.rb
15index 3edd902a2..e5f980b5e 100644
16--- a/app/controllers/collections_controller.rb
17+++ b/app/controllers/collections_controller.rb
18@@ -25,11 +25,20 @@ class CollectionsController < ApplicationController
19
20 def index
21 if params[:work_id] && (@work = Work.find_by(id: params[:work_id]))
22- @collections = @work.approved_collections.by_title.includes(:parent, :moderators, :children, :collection_preference, owners: [:user]).paginate(page: params[:page])
23+ @collections = @work.approved_collections
24+ .by_title
25+ .for_blurb
26+ .paginate(page: params[:page])
27 elsif params[:collection_id] && (@collection = Collection.find_by(name: params[:collection_id]))
28- @collections = @collection.children.by_title.includes(:parent, :moderators, :children, :collection_preference, owners: [:user]).paginate(page: params[:page])
29+ @collections = @collection.children
30+ .by_title
31+ .for_blurb
32+ .paginate(page: params[:page])
33 elsif params[:user_id] && (@user = User.find_by(login: params[:user_id]))
34- @collections = @user.maintained_collections.by_title.includes(:parent, :moderators, :children, :collection_preference, owners: [:user]).paginate(page: params[:page])
35+ @collections = @user.maintained_collections
36+ .by_title
37+ .for_blurb
38+ .paginate(page: params[:page])
39 @page_subtitle = ts("%{username} - Collections", username: @user.login)
40 else
41 if params[:user_id]
42diff --git a/app/helpers/collections_helper.rb b/app/helpers/collections_helper.rb
43index 59fcc53ef..b1561ee7a 100644
44--- a/app/helpers/collections_helper.rb
45+++ b/app/helpers/collections_helper.rb
46@@ -123,4 +123,15 @@ module CollectionsHelper
47 [t("#{key}.rejected"), :rejected]
48 ]
49 end
50+
51+ def standard_icon_url(collection)
52+ return "/images/skins/iconsets/default/icon_collection.png" unless collection.icon.attached?
53+ url_for(collection.icon.variant(resize_to_limit: [100, 100], loader: { page: nil }))
54+ end
55+
56+ # Wraps the collection's standard_icon_url in an image tag
57+ def collection_icon_display(collection)
58+ image_tag(standard_icon_url(collection), class: "icon")
59+ end
60+
61 end
62diff --git a/app/models/collection.rb b/app/models/collection.rb
63index 1aefaf8c7..1545e62df 100755
64--- a/app/models/collection.rb
65+++ b/app/models/collection.rb
66@@ -3,8 +3,6 @@ class Collection < ApplicationRecord
67 include UrlHelpers
68 include WorksOwner
69
70- has_one_attached :icon
71-
72 # has_attached_file :icon,
73 # styles: { standard: "100x100>" },
74 # path: %w(staging unproduction).include?(Rails.env) ? ":rails_root/system/collections/icons/:id_partition/:style/:filename" : ":rails_root/public:url",
75@@ -14,6 +12,8 @@ class Collection < ApplicationRecord
76 # bucket: %w(staging unproduction).include?(Rails.env) ? YAML.load_file("#{Rails.root}/config/s3.yml")['bucket'] : "",
77 # default_url: "/images/skins/iconsets/default/icon_collection.png"
78
79+ has_one_attached :icon
80+
81 validates :icon, file_content_type: {
82 allow: ["image/jpeg", "image/png", "image/gif"],
83 if: -> { icon.attached? },
84@@ -180,6 +180,7 @@ class Collection < ApplicationRecord
85 scope :prompt_meme, -> { where(challenge_type: 'PromptMeme') }
86 scope :name_only, -> { select("collections.name") }
87 scope :by_title, -> { order(:title) }
88+ scope :for_blurb, -> { includes(:parent, :moderators, :children, :collection_preference, owners: [:user]).with_attached_icon }
89
90 before_validation :cleanup_url
91 def cleanup_url
92@@ -417,17 +418,35 @@ class Collection < ApplicationRecord
93 end
94 end
95
96- # Delete current icon (thus reverting to archive default icon)
97 def delete_icon=(value)
98 @delete_icon = !value.to_i.zero?
99 end
100
101 def delete_icon
102- !!@delete_icon
103+ !!@delete_icon
104 end
105- alias_method :delete_icon?, :delete_icon
106+ alias delete_icon? delete_icon
107
108 def clear_icon
109- self.icon = nil if delete_icon?
110+ return unless delete_icon?
111+
112+ self.icon.purge
113+ self.icon_alt_text = nil
114+ self.icon_comment_text = nil
115 end
116+
117+
118+ # Delete current icon (thus reverting to archive default icon)
119+ # def delete_icon=(value)
120+ # @delete_icon = !value.to_i.zero?
121+ # end
122+
123+# def delete_icon
124+# !!@delete_icon
125+# end
126+# alias_method :delete_icon?, :delete_icon
127+#
128+# def clear_icon
129+# self.icon = nil if delete_icon?
130+# end
131 end
132diff --git a/app/views/collection_items/_item_fields.html.erb b/app/views/collection_items/_item_fields.html.erb
133index de0f79510..286838217 100755
134--- a/app/views/collection_items/_item_fields.html.erb
135+++ b/app/views/collection_items/_item_fields.html.erb
136@@ -33,7 +33,7 @@
137 <p class="datetime"><%= collection_item.item_date.to_date %></p>
138 <% end %>
139 <div class="icon">
140- <%= image_tag(collection_item.collection.icon.url(:standard), size: "100x100", alt: collection_item.collection.icon_alt_text, class: "icon", skip_pipeline: true) %>
141+ <%= collection_icon_display(collection_item.collection) %>
142 </div>
143 </div>
144
145diff --git a/app/views/collections/_collection_blurb.html.erb b/app/views/collections/_collection_blurb.html.erb
146index 862da4095..eabc8445a 100644
147--- a/app/views/collections/_collection_blurb.html.erb
148+++ b/app/views/collections/_collection_blurb.html.erb
149@@ -12,11 +12,7 @@
150 </h4>
151 <!--collections header iconised header image-->
152 <div class="icon">
153- <% if collection.icon.attached? %>
154- <%= image_tag(collection.icon.variant(resize_to_limit: [100, 100])) %>
155- <% else %>
156- <%= image_tag('/images/skins/iconsets/default/icon_user.png', class: 'icon') %>
157- <% end %>
158+ <%= collection_icon_display(collection) %>
159 </div>
160 <p class="datetime"><%= set_format_for_date(collection.updated_at) %></p>
161 <% if collection.all_moderators.length > 0%>
162diff --git a/app/views/collections/_form.html.erb b/app/views/collections/_form.html.erb
163index 7b3de25bc..79a50ef16 100644
164--- a/app/views/collections/_form.html.erb
165+++ b/app/views/collections/_form.html.erb
166@@ -66,23 +66,17 @@
167 <ul class="notes">
168 <% unless @collection.new_record? %>
169 <li>
170- <% if @collection.icon.attached? %>
171- <%= image_tag(@collection.icon, skip_pipeline: true) %>
172+ <%= collection_icon_display(@collection) %>
173 <%= ts("This is the collection's icon.") %>
174- <% else %>
175- <%= image_tag('/images/skins/iconsets/default/icon_user.png', class: 'icon') %>
176- <% end %>
177 </li>
178 <% end %>
179 <li><%= ts("Each collection can have one icon") %></li>
180 <li><%= ts("Icons can be in png, jpeg or gif form") %></li>
181 <li><%= ts("Icons should be sized 100x100 pixels for best results") %></li>
182 </ul>
183- <% if @collection.icon %>
184+ <% if @collection.icon.attached? %>
185 <%= collection_form.check_box :delete_icon, {:checked => false} %>
186 <%= collection_form.label :delete_icon, ts("Delete collection icon and revert to our default") %>
187- <% else %>
188- <% link_to image_tag('/images/skins/iconsets/default/icon_user.png', class: 'icon') %>
189 <% end %>
190 </dd>
191
192diff --git a/app/views/collections/_header.html.erb b/app/views/collections/_header.html.erb
193index 0aca6ca78..087ffbdc2 100644
194--- a/app/views/collections/_header.html.erb
195+++ b/app/views/collections/_header.html.erb
196@@ -2,11 +2,7 @@
197 <div class="primary header module">
198 <h2 class="heading"><%= link_to_unless_current(@collection.title, @collection) %></h2>
199 <div class="icon">
200- <% if @collection.icon.attached? %>
201- <%= image_tag(@collection.icon.variant(resize_to_limit: [100, 100])) %>
202- <% else %>
203- <%= image_tag('/images/skins/iconsets/default/icon_user.png', class: 'icon') %>
204- <% end %>
205+ <%= collection_icon_display(@collection) %>
206 </div>
207 <!--/descriptions-->
208