compony 0.6.0 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/Gemfile.lock +1 -1
- data/VERSION +1 -1
- data/compony.gemspec +3 -3
- data/config/locales/de.yml +1 -1
- data/config/locales/en.yml +1 -1
- data/config/locales/fr.yml +1 -1
- data/doc/ComponentGenerator.html +1 -1
- data/doc/Components.html +1 -1
- data/doc/ComponentsGenerator.html +1 -1
- data/doc/Compony/Component.html +1 -1
- data/doc/Compony/ComponentMixins/Default/Labelling.html +1 -1
- data/doc/Compony/ComponentMixins/Default/Standalone/ResourcefulVerbDsl.html +1 -1
- data/doc/Compony/ComponentMixins/Default/Standalone/StandaloneDsl.html +1 -1
- data/doc/Compony/ComponentMixins/Default/Standalone/VerbDsl.html +1 -1
- data/doc/Compony/ComponentMixins/Default/Standalone.html +1 -1
- data/doc/Compony/ComponentMixins/Default.html +1 -1
- data/doc/Compony/ComponentMixins/Resourceful.html +1 -1
- data/doc/Compony/ComponentMixins.html +1 -1
- data/doc/Compony/Components/Button.html +1 -1
- data/doc/Compony/Components/Destroy.html +1 -1
- data/doc/Compony/Components/Edit.html +1 -1
- data/doc/Compony/Components/Form.html +1 -1
- data/doc/Compony/Components/Index.html +1 -1
- data/doc/Compony/Components/List.html +235 -146
- data/doc/Compony/Components/New.html +1 -1
- data/doc/Compony/Components/Show.html +1 -1
- data/doc/Compony/Components/WithForm.html +1 -1
- data/doc/Compony/Components.html +1 -1
- data/doc/Compony/ControllerMixin.html +1 -1
- data/doc/Compony/Engine.html +1 -1
- data/doc/Compony/MethodAccessibleHash.html +1 -1
- data/doc/Compony/ModelFields/Anchormodel.html +1 -1
- data/doc/Compony/ModelFields/Association.html +1 -1
- data/doc/Compony/ModelFields/Attachment.html +203 -19
- data/doc/Compony/ModelFields/Base.html +1 -1
- data/doc/Compony/ModelFields/Boolean.html +1 -1
- data/doc/Compony/ModelFields/Color.html +1 -1
- data/doc/Compony/ModelFields/Currency.html +1 -1
- data/doc/Compony/ModelFields/Date.html +1 -1
- data/doc/Compony/ModelFields/Datetime.html +1 -1
- data/doc/Compony/ModelFields/Decimal.html +1 -1
- data/doc/Compony/ModelFields/Email.html +1 -1
- data/doc/Compony/ModelFields/Float.html +1 -1
- data/doc/Compony/ModelFields/Integer.html +1 -1
- data/doc/Compony/ModelFields/Percentage.html +1 -1
- data/doc/Compony/ModelFields/Phone.html +1 -1
- data/doc/Compony/ModelFields/RichText.html +1 -1
- data/doc/Compony/ModelFields/String.html +1 -1
- data/doc/Compony/ModelFields/Text.html +1 -1
- data/doc/Compony/ModelFields/Time.html +1 -1
- data/doc/Compony/ModelFields/Url.html +1 -1
- data/doc/Compony/ModelFields.html +1 -1
- data/doc/Compony/ModelMixin.html +1 -1
- data/doc/Compony/NaturalOrdering.html +1 -1
- data/doc/Compony/RequestContext.html +1 -1
- data/doc/Compony/Version.html +1 -1
- data/doc/Compony/ViewHelpers.html +1 -1
- data/doc/Compony.html +1 -1
- data/doc/ComponyController.html +1 -1
- data/doc/_index.html +1 -1
- data/doc/file.README.html +1 -1
- data/doc/index.html +1 -1
- data/doc/method_list.html +139 -115
- data/doc/top-level-namespace.html +1 -1
- data/lib/compony/components/list.rb +10 -0
- data/lib/compony/model_fields/attachment.rb +42 -3
- metadata +2 -2
@@ -102,7 +102,7 @@
|
|
102
102
|
</div>
|
103
103
|
|
104
104
|
<div id="footer">
|
105
|
-
Generated on
|
105
|
+
Generated on Wed Sep 17 11:13:06 2025 by
|
106
106
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
107
107
|
0.9.34 (ruby-3.3.5).
|
108
108
|
</div>
|
@@ -16,6 +16,7 @@ module Compony
|
|
16
16
|
# @param skip_columns [Array] Column names to be skipped.
|
17
17
|
# @param skip_row_actions [Array] Row action names to be skipped.
|
18
18
|
# @param skip_filters [Array] Filter names to be skipped.
|
19
|
+
# @param default_sorting [String] Default sorting (only relevant for ransack based sorting)
|
19
20
|
def initialize(*,
|
20
21
|
skip_pagination: false,
|
21
22
|
results_per_page: 20,
|
@@ -26,6 +27,7 @@ module Compony
|
|
26
27
|
skip_columns: [],
|
27
28
|
skip_row_actions: [],
|
28
29
|
skip_filters: [],
|
30
|
+
default_sorting: 'id asc',
|
29
31
|
**)
|
30
32
|
@pagination = !skip_pagination
|
31
33
|
@results_per_page = results_per_page
|
@@ -39,6 +41,7 @@ module Compony
|
|
39
41
|
@filters = Compony::NaturalOrdering.new
|
40
42
|
@sorts = Compony::NaturalOrdering.new
|
41
43
|
@skipped_filters = skip_filters.map(&:to_sym)
|
44
|
+
@default_sorting = default_sorting
|
42
45
|
@filter_label_class = 'list-filter-label'
|
43
46
|
@filter_input_class = 'list-filter-input'
|
44
47
|
@filter_select_class = 'list-filter-select'
|
@@ -83,6 +86,12 @@ module Compony
|
|
83
86
|
@sorting_links = false
|
84
87
|
end
|
85
88
|
|
89
|
+
# DSL method
|
90
|
+
# Overrides the default sorting
|
91
|
+
def default_sorting(new_default_sorting)
|
92
|
+
@default_sorting = new_default_sorting
|
93
|
+
end
|
94
|
+
|
86
95
|
# DSL method
|
87
96
|
# Sets the CSS class attribute for form label elements in filters.
|
88
97
|
# @param class_str [String] Space-separated list of CSS classes
|
@@ -230,6 +239,7 @@ module Compony
|
|
230
239
|
# Filtering
|
231
240
|
if filtering_enabled?
|
232
241
|
@q = @data.ransack(controller.params[param_name(:q)], auth_object: controller.current_ability, search_key: param_name(:q))
|
242
|
+
@q.sorts = @default_sorting if @q.sorts.empty?
|
233
243
|
filtered_data = @q.result.accessible_by(controller.current_ability)
|
234
244
|
else
|
235
245
|
filtered_data = @data
|
@@ -3,17 +3,56 @@ module Compony
|
|
3
3
|
# @api description
|
4
4
|
# Model field type representing an ActiveStorage attachment.
|
5
5
|
class Attachment < Base
|
6
|
+
def initialize(...)
|
7
|
+
super
|
8
|
+
resolve_attachment!
|
9
|
+
end
|
10
|
+
|
6
11
|
def value_for(data, controller: nil, **_)
|
7
12
|
return transform_and_join(data.send(@name), controller:) do |el|
|
8
13
|
fail('Must pass controller to generate the link to the attachment.') unless controller
|
9
|
-
|
10
|
-
|
14
|
+
if @multi
|
15
|
+
return nil if el.none?
|
16
|
+
return controller.helpers.safe_join(el.map { |item| controller.helpers.link_to(item.filename, controller.helpers.rails_blob_path(item)) }, ', ')
|
17
|
+
else
|
18
|
+
return nil unless el.attached?
|
19
|
+
return controller.helpers.link_to(el.filename, controller.helpers.rails_blob_path(el))
|
20
|
+
end
|
11
21
|
end
|
12
22
|
end
|
13
23
|
|
14
24
|
def simpleform_input(form, _component, name: nil, accept: nil, **input_opts)
|
25
|
+
name ||= @name
|
15
26
|
input_opts.deep_merge!(input_html: { accept: }) if accept
|
16
|
-
|
27
|
+
if @multi
|
28
|
+
helpers = ActionController::Base.helpers
|
29
|
+
return helpers.capture do
|
30
|
+
helpers.concat form.label(name)
|
31
|
+
# List currently present attachments along with a remove button (done in JS)
|
32
|
+
helpers.div class: 'compony-attachments-item-wrapper' do
|
33
|
+
form.object.send(name).each do |attachment|
|
34
|
+
helpers.div class: 'compony-attachments-item' do
|
35
|
+
helpers.concat helpers.hidden_field_tag("#{form.object.model_name.singular}[#{name}][]", attachment.signed_id)
|
36
|
+
helpers.span attachment.filename, class: 'compony-attachments-filename'
|
37
|
+
helpers.span ' ', class: 'compony-attachments-spacer'
|
38
|
+
helpers.concat helpers.link_to(I18n.t('compony.model_fields.attachment.remove'), '#',
|
39
|
+
onclick: "event.preventDefault(); this.closest('div').remove();")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
helpers.concat form.input(name, **input_opts.deep_merge(input_html: { multiple: :multiple }, label: false, class: 'compony-attachments-input'))
|
44
|
+
end
|
45
|
+
end
|
46
|
+
return form.input(name, **input_opts)
|
47
|
+
end
|
48
|
+
|
49
|
+
protected
|
50
|
+
|
51
|
+
# Uses Rails method to figure out arity and store it.
|
52
|
+
# This can be auto-inferred without accessing the database.
|
53
|
+
def resolve_attachment!
|
54
|
+
attachment_info = model_class.reflect_on_attachment(name)
|
55
|
+
@multi = attachment_info.is_a?(ActiveStorage::Reflection::HasManyAttachedReflection)
|
17
56
|
end
|
18
57
|
end
|
19
58
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: compony
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sandro Kalbermatter
|
@@ -335,7 +335,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
335
335
|
- !ruby/object:Gem::Version
|
336
336
|
version: '0'
|
337
337
|
requirements: []
|
338
|
-
rubygems_version: 3.
|
338
|
+
rubygems_version: 3.7.1
|
339
339
|
specification_version: 4
|
340
340
|
summary: Compony is a Gem that allows you to write your Rails application in component-style
|
341
341
|
fashion. It combines a controller action and route along \ with its view into a
|