para 0.12.0 → 0.12.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fe01ca1218169f3178bd25a9c3746a21395744dbf12e6d8066d0cbb9ffcda7c9
4
- data.tar.gz: ccee709b747dc51b11443e63c5cc8811ad2c1773c060b56e6702603a44353932
3
+ metadata.gz: e5f4c1a9a889b3800d615452bda318bac05fc3d49b88c612af3cd2a714cb3fe8
4
+ data.tar.gz: a665a5affd7b2a3938baf185c41221eed335b42be7dabf8ff1d17145212dfecb
5
5
  SHA512:
6
- metadata.gz: 8e5417ba55ba7d12c132390c3241f683cd198c151bdf220fb47bae4cfe7c2d4e71f967aea0a69e0e84c729133fd1f2e8f0f18b4a2bbe268d447dc4a2c5985eb2
7
- data.tar.gz: 9cd765135e8cd68246460275adb56b89f75c2c6c0377ec8290392480fba4480fb625e640413d55c5fc917598c7022cb1023a4ce2bae73494b3e60557c89c7d71
6
+ metadata.gz: 7a71ed497361f0b442965a7331159d9c2c2dfd7f745674f8698f446e1a6651f3bdfacd96f314f2e00d657ba13390f55ca317221aca45284d6770419bd820be79
7
+ data.tar.gz: 6e1bb4347edeacd0f067dc401e77ce72926ed9ae9d4e61326799376d3ca7063db196a275c58b79d96c29e21ba5004d56f8cdbb976c98dfac22f91522b352955a
@@ -31,12 +31,15 @@
31
31
  content: "\f0dc";
32
32
  opacity: .3;
33
33
  }
34
+
34
35
  .sort_link.asc:before {
35
- content: "\f0d7";
36
+ content: "\f0d8";
36
37
  }
38
+
37
39
  .sort_link.desc:before {
38
- content: "\f0d8";
40
+ content: "\f0d7";
39
41
  }
42
+
40
43
  .sort_link.asc.disabled:before,
41
44
  .sort_link.desc.disabled:before {
42
45
  opacity: .1;
@@ -22,11 +22,11 @@ function trackProgressFor(element, jobStatusUrl) {
22
22
  }
23
23
 
24
24
  document.documentElement.addEventListener('turbo:frame-load', function(e) {
25
- if (e.target.id != 'para_admin_modal') return;
25
+ if (e.target.id !== 'para_admin_modal') return;
26
26
 
27
27
  loadedElement = e.target.childNodes[0];
28
28
 
29
- var jobStatusUrl = loadedElement && loadedElement.dataset.jobStatusUrl;
29
+ var jobStatusUrl = loadedElement?.dataset?.jobStatusUrl;
30
30
  if (!jobStatusUrl) return;
31
31
 
32
32
  trackProgressFor(loadedElement, jobStatusUrl);
@@ -14,8 +14,6 @@ import "./vendor/jquery.sortable";
14
14
 
15
15
  import "./application";
16
16
 
17
- import "./lib/page-loading";
18
-
19
17
  import "./inputs/material-input";
20
18
  import "./inputs/multi-select-input";
21
19
  import "./inputs/nested_many";
@@ -56,6 +56,10 @@ module Para
56
56
 
57
57
  reference = model.reflect_on_all_associations.find do |association|
58
58
  association.foreign_key == name
59
+ rescue ArgumentError
60
+ # This can happen when the association is polymorphic and the foreign key can't
61
+ # be determined, in this case, we just ignore the association.
62
+ false
59
63
  end
60
64
 
61
65
  if reference
@@ -75,12 +79,11 @@ module Para
75
79
  true
76
80
  end
77
81
 
78
- #
79
82
  def searchable?
80
83
  options[:searchable] != false && (
81
- [:string, :text].include?(type.to_sym) && !name.match(/password/)
84
+ %i[string text].include?(type.to_sym) && !name.match(/password/)
82
85
  ) && (
83
- !model.respond_to?(:ransackable_attributes) ||
86
+ !model.respond_to?(:ransackable_attributes) ||
84
87
  model.ransackable_attributes.include?(name.to_s)
85
88
  )
86
89
  end
@@ -94,7 +97,7 @@ module Para
94
97
  def field_options
95
98
  self.class._field_options.each_with_object({}) do |params, hash|
96
99
  value = send(params[:method_name])
97
- hash[params[:key]] = value if value != nil || params[:options][:allow_nil]
100
+ hash[params[:key]] = value if !value.nil? || params[:options][:allow_nil]
98
101
  end
99
102
  end
100
103
 
@@ -60,13 +60,11 @@ module Para
60
60
  sections.each do |section|
61
61
  section.components.each do |component|
62
62
  # If one of the section component has the searched identifier return it
63
- if component.identifier.to_s == identifier.to_s
64
- return component
65
- else
66
- component.child_components.each do |child_component|
67
- # If one of the component children has the searched identifier return it
68
- return child_component if child_component.identifier.to_s == identifier.to_s
69
- end
63
+ return component if component.identifier.to_s == identifier.to_s
64
+
65
+ component.child_components.each do |child_component|
66
+ # If one of the component children has the searched identifier return it
67
+ return child_component if child_component.identifier.to_s == identifier.to_s
70
68
  end
71
69
  end
72
70
  end
@@ -139,7 +137,7 @@ module Para
139
137
  #
140
138
  def eager_load_components!
141
139
  $LOAD_PATH.each do |path|
142
- next unless path.match(%r{/(para_)?components$})
140
+ next unless path.match(%r{/#{Para.config.components_directory}$})
143
141
 
144
142
  glob = File.join(path, '**', '*_component.rb')
145
143
 
@@ -189,10 +187,10 @@ module Para
189
187
  # Build child components if a block is provided
190
188
  instance_eval(&block) if block
191
189
 
192
- unless type
193
- raise UndefinedComponentTypeError, "Undefined Para component : #{type_identifier}. " +
194
- 'Please ensure that your app or gems define this component type.'
195
- end
190
+ return if type
191
+
192
+ raise UndefinedComponentTypeError, "Undefined Para component : #{type_identifier}. " +
193
+ 'Please ensure that your app or gems define this component type.'
196
194
  end
197
195
 
198
196
  def component(*args, **child_options, &block)
data/lib/para/config.rb CHANGED
@@ -16,11 +16,15 @@ module Para
16
16
  @@default_tree_max_depth = 3
17
17
 
18
18
  mattr_accessor :resource_name_methods
19
- @@resource_name_methods = [:admin_name, :admin_title, :name, :title]
19
+ @@resource_name_methods = %i[admin_name admin_title name title]
20
20
 
21
21
  mattr_accessor :enable_app_breadcrumbs
22
22
  @@enable_app_breadcrumbs = true
23
23
 
24
+ # Allow changing this directory to allow using view_component gem
25
+ mattr_accessor :components_directory
26
+ @@para_components_directory = 'components'
27
+
24
28
  mattr_reader :plugins
25
29
  @@plugins = Para::Plugins::Set.new
26
30
 
@@ -64,7 +68,7 @@ module Para
64
68
  # that limit after writing new keys
65
69
  #
66
70
  mattr_accessor :database_cache_store_max_items
67
- @@database_cache_store_max_items = 10000
71
+ @@database_cache_store_max_items = 10_000
68
72
 
69
73
  # Allows accessing plugins root module to configure them through a method
70
74
  # from the Para::Config class.
@@ -42,8 +42,10 @@ module Para
42
42
  # attributes mappings above
43
43
  next if AttributeField::RelationField == fields_hash[name]
44
44
 
45
- # Remove foreign key, if existing, from fields
46
- fields_hash.delete(reflection.foreign_key.to_s)
45
+ unless through_polymorphic_reflection?(reflection)
46
+ # Remove foreign key, if existing, from fields
47
+ fields_hash.delete(reflection.foreign_key.to_s)
48
+ end
47
49
 
48
50
  # Do not process polymorphic belongs to for now ...
49
51
  if reflection.options[:polymorphic] == true
@@ -52,27 +54,25 @@ module Para
52
54
  end
53
55
 
54
56
  if model.nested_attributes_options[name]
55
- if reflection.collection?
56
- fields_hash[name] = AttributeField::NestedManyField.new(
57
- model, name: name, type: 'has_many', field_type: 'nested_many'
58
- )
59
- else
60
- fields_hash[name] = AttributeField::NestedOneField.new(
61
- model, name: name, type: 'belongs_to', field_type: 'nested_one'
62
- )
63
- end
64
- else
65
- if reflection.collection?
66
- remove_counter_cache_column!(name, reflection)
57
+ fields_hash[name] = if reflection.collection?
58
+ AttributeField::NestedManyField.new(
59
+ model, name: name, type: 'has_many', field_type: 'nested_many'
60
+ )
61
+ else
62
+ AttributeField::NestedOneField.new(
63
+ model, name: name, type: 'belongs_to', field_type: 'nested_one'
64
+ )
65
+ end
66
+ elsif reflection.collection?
67
+ remove_counter_cache_column!(name, reflection)
67
68
 
68
- fields_hash[name] = AttributeField::HasManyField.new(
69
- model, name: name, type: 'has_many', field_type: 'multi_select'
70
- )
71
- elsif !reflection.options[:through]
72
- fields_hash[name] = AttributeField::BelongsToField.new(
73
- model, name: name, type: 'belongs_to', field_type: 'selectize'
74
- )
75
- end
69
+ fields_hash[name] = AttributeField::HasManyField.new(
70
+ model, name: name, type: 'has_many', field_type: 'multi_select'
71
+ )
72
+ elsif !reflection.options[:through]
73
+ fields_hash[name] = AttributeField::BelongsToField.new(
74
+ model, name: name, type: 'belongs_to', field_type: 'selectize'
75
+ )
76
76
  end
77
77
  end
78
78
  end
@@ -84,14 +84,23 @@ module Para
84
84
  return unless (inverse_relation = reflection.inverse_of)
85
85
  return unless (counter_name = inverse_relation.options[:counter_cache])
86
86
 
87
- counter_name = if String === counter_name
88
- counter_name
89
- else
90
- "#{ name }_count"
91
- end
87
+ counter_name = if counter_name.is_a?(String)
88
+ counter_name
89
+ else
90
+ "#{name}_count"
91
+ end
92
92
 
93
93
  fields_hash.delete(counter_name)
94
94
  end
95
+
96
+ def through_polymorphic_reflection?(reflection)
97
+ reflection.through_reflection? && (
98
+ (
99
+ reflection.through_reflection.options[:polymorphic] &&
100
+ !reflection.through_reflection.options[:source_type]
101
+ ) || through_polymorphic_reflection?(reflection.through_reflection)
102
+ )
103
+ end
95
104
  end
96
105
  end
97
106
  end
data/lib/para/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Para
4
- VERSION = '0.12.0'
4
+ VERSION = '0.12.2'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: para
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.12.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Valentin Ballestrino
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-06 00:00:00.000000000 Z
11
+ date: 2024-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_decorator
@@ -487,7 +487,6 @@ files:
487
487
  - app/javascripts/para/inputs/multi-select-input.js
488
488
  - app/javascripts/para/inputs/nested_many.js
489
489
  - app/javascripts/para/lib/fetch.js
490
- - app/javascripts/para/lib/page-loading.js
491
490
  - app/javascripts/para/plugins-includes.js.erb
492
491
  - app/javascripts/para/simple_form_extension/colorpicker.js
493
492
  - app/javascripts/para/simple_form_extension/datetimepicker.js
@@ -1,42 +0,0 @@
1
- Para.PageLoading = class PageLoading {
2
- constructor() {
3
- this.start = this.start.bind(this);
4
- this.stop = this.stop.bind(this);
5
- }
6
-
7
- start() {
8
- return this.addLoadingMarkup();
9
- }
10
-
11
- stop() {
12
- return this.removeLoadingMarkup();
13
- }
14
-
15
- addLoadingMarkup() {
16
- $('<div/>', {
17
- class: 'loading-overlay',
18
- 'data-loading-overlay': true
19
- }).prependTo('body');
20
-
21
- $('<div/>', {
22
- class: 'loading-spinner',
23
- 'data-loading-spinner': true
24
- }).prependTo('body');
25
- }
26
-
27
- removeLoadingMarkup() {
28
- $('[data-loading-overlay]').remove();
29
- return $('[data-loading-spinner]').remove();
30
- }
31
-
32
- };
33
-
34
- // Global loading manager allowing to
35
- Para.loadingManager = new Para.PageLoading();
36
-
37
- $(document).on('turbo:before-fetch-request', Para.loadingManager.start);
38
-
39
- $(document).on('turbo:load turbo:frame-load turbo:before-stream-render turbo:frame-missing turbo:fetch-request-error', function() {
40
- Para.loadingManager.stop();
41
- return $('body').on('submit', '[data-para-form]:not([data-remote])', Para.loadingManager.start);
42
- });