katalyst-koi 4.5.5 → 4.5.7
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 +29 -3
- 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: 13cd00ba07e90a830f3a858db1fdd1f22181bf68448b0716441b66c2ce17eb84
|
4
|
+
data.tar.gz: 96bbf769605e6b8b4091f500e475cdb033039e037b784c7469a9ce52ade9866c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8c065374fc75587b31288078435eb2e9ad801a3e1dbf19984868d4377f0e6cf31b8e992c9b2f7a0b6761669506087c08d742faebe31a79356d6fe869c67c921
|
7
|
+
data.tar.gz: b159be789bf941acab6882e460ccf85858b4a5016f10195d4351b2050eb33260ae1835e404a43cee3c763a68af4a1321d017e879a7fe56225d608a9e0a58b945
|
@@ -10,12 +10,38 @@ module Koi
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def attribute_value
|
13
|
-
|
14
|
-
|
13
|
+
representation
|
14
|
+
end
|
15
|
+
|
16
|
+
def representation
|
17
|
+
if raw_value.try(:variable?) && named_variant.present?
|
18
|
+
image_tag(raw_value.variant(@variant))
|
15
19
|
elsif raw_value.try(:attached?)
|
16
|
-
|
20
|
+
filename.to_s
|
21
|
+
else
|
22
|
+
""
|
17
23
|
end
|
18
24
|
end
|
25
|
+
|
26
|
+
def filename
|
27
|
+
raw_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(raw_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
|
+
@model.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
|
+
object.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.7
|
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
|