katalyst-koi 4.5.5 → 4.5.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/components/koi/summary_list/attachment_component.rb +30 -4
- data/app/components/koi/tables/body.rb +27 -3
- data/app/components/koi/tables/body_cell_component.rb +4 -0
- data/app/controllers/concerns/koi/controller/has_attachments.rb +37 -0
- data/app/controllers/concerns/koi/controller/is_admin_controller.rb +1 -0
- data/lib/govuk_design_system_formbuilder/elements/document.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ada22c3c8efe297efe34d45f3adb4b1000753095fc5a822e0381f39d90c04436
|
4
|
+
data.tar.gz: 338f2c71ca31a9e8a825aed39a34ed59d63f7ce5dd8e31beca9abfa7587bae01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1cbce2dad572261f3d65f47f1fc2ef2e4fc97c28eb9c535b5fcc166b06416dd01e98f8f17d0d0f4dd08ff7cce06646e2e0ba811e5d674868c8d4c3ef2b34a1f0
|
7
|
+
data.tar.gz: 7f1ec66083fefbf508c18fb053bcfb714eca35e6e773d0a39ce083762ed014f711a1856d0df028af8141a306f80582baa7eeec5d18bce93e8d44fc9793a4715a
|
@@ -10,12 +10,38 @@ module Koi
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def attribute_value
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
representation
|
14
|
+
end
|
15
|
+
|
16
|
+
def representation
|
17
|
+
if value.try(:variable?) && named_variant.present?
|
18
|
+
image_tag(value.variant(@variant))
|
19
|
+
elsif value.try(:attached?)
|
20
|
+
filename.to_s
|
21
|
+
else
|
22
|
+
""
|
17
23
|
end
|
18
24
|
end
|
25
|
+
|
26
|
+
def filename
|
27
|
+
value.blob.filename
|
28
|
+
end
|
29
|
+
|
30
|
+
# Utility for accessing the path Rails provides for retrieving the
|
31
|
+
# attachment for use in cells. Example:
|
32
|
+
# <% row.attachment :file do |cell| %>
|
33
|
+
# <%= link_to "Download", cell.internal_path %>
|
34
|
+
# <% end %>
|
35
|
+
def internal_path
|
36
|
+
rails_blob_path(value, disposition: :attachment)
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
# Find the reflective variant by name (i.e. :thumb by default)
|
42
|
+
def named_variant
|
43
|
+
value.record.attachment_reflections[@attribute.to_s].named_variants[@variant.to_sym]
|
44
|
+
end
|
19
45
|
end
|
20
46
|
end
|
21
47
|
end
|
@@ -190,14 +190,38 @@ module Koi
|
|
190
190
|
end
|
191
191
|
|
192
192
|
def rendered_value
|
193
|
-
|
194
|
-
|
193
|
+
representation
|
194
|
+
end
|
195
|
+
|
196
|
+
def representation
|
197
|
+
if value.try(:variable?) && named_variant.present?
|
198
|
+
image_tag(value.variant(@variant))
|
195
199
|
elsif value.try(:attached?)
|
196
|
-
|
200
|
+
filename.to_s
|
197
201
|
else
|
198
202
|
""
|
199
203
|
end
|
200
204
|
end
|
205
|
+
|
206
|
+
def filename
|
207
|
+
value.blob.filename
|
208
|
+
end
|
209
|
+
|
210
|
+
# Utility for accessing the path Rails provides for retrieving the
|
211
|
+
# attachment for use in cells. Example:
|
212
|
+
# <% row.attachment :file do |cell| %>
|
213
|
+
# <%= link_to "Download", cell.internal_path %>
|
214
|
+
# <% end %>
|
215
|
+
def internal_path
|
216
|
+
rails_blob_path(value, disposition: :attachment)
|
217
|
+
end
|
218
|
+
|
219
|
+
private
|
220
|
+
|
221
|
+
# Find the reflective variant by name (i.e. :thumb by default)
|
222
|
+
def named_variant
|
223
|
+
value.record.attachment_reflections[@attribute.to_s].named_variants[@variant.to_sym]
|
224
|
+
end
|
201
225
|
end
|
202
226
|
end
|
203
227
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Koi
|
4
|
+
module Controller
|
5
|
+
module HasAttachments
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
# Store attachments in the given object so that they can be preserved for
|
9
|
+
# the next form submission.
|
10
|
+
#
|
11
|
+
# Example:
|
12
|
+
# def create
|
13
|
+
# @document = Document.new(document_params)
|
14
|
+
# if @document.save
|
15
|
+
# redirect_to [:admin, @document], status: :see_other
|
16
|
+
# else
|
17
|
+
# store_attachments(@document)
|
18
|
+
# render :new, status: :unprocessable_entity
|
19
|
+
# end
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
# @param resource [ActiveRecord::Base] The object being edited
|
23
|
+
def save_attachments!(resource)
|
24
|
+
resource.attachment_changes.each_value do |change|
|
25
|
+
case change
|
26
|
+
when ActiveStorage::Attached::Changes::CreateOne
|
27
|
+
change.upload
|
28
|
+
change.blob.save!
|
29
|
+
when ActiveStorage::Attached::Changes::CreateMany
|
30
|
+
change.upload
|
31
|
+
change.blobs.each(&:save!)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -55,7 +55,7 @@ module GOVUKDesignSystemFormBuilder
|
|
55
55
|
# Generates a +div+ element with an +input+ with +type=file+ with a label, optional hint.
|
56
56
|
#
|
57
57
|
# @example A upload field with label as a proc
|
58
|
-
# = f.
|
58
|
+
# = f.govuk_document_field :data, label: -> { tag.h3('Upload your document') }
|
59
59
|
#
|
60
60
|
def govuk_document_field(attribute_name, label: {}, caption: {}, hint: {}, form_group: {}, **kwargs, &block)
|
61
61
|
Elements::Document.new(self, object_name, attribute_name, label:, caption:, hint:, form_group:, **kwargs,
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: katalyst-koi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.5.
|
4
|
+
version: 4.5.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Katalyst Interactive
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-03-
|
11
|
+
date: 2024-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -331,6 +331,7 @@ files:
|
|
331
331
|
- app/controllers/admin/tokens_controller.rb
|
332
332
|
- app/controllers/admin/url_rewrites_controller.rb
|
333
333
|
- app/controllers/concerns/koi/controller/has_admin_users.rb
|
334
|
+
- app/controllers/concerns/koi/controller/has_attachments.rb
|
334
335
|
- app/controllers/concerns/koi/controller/has_webauthn.rb
|
335
336
|
- app/controllers/concerns/koi/controller/is_admin_controller.rb
|
336
337
|
- app/controllers/concerns/koi/controller/json_web_token.rb
|