motor-admin 0.2.25 → 0.2.29

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: 2a53555a0c69ed075e09c63deb22a53381efb7d1935542d8ac760f6bbd168044
4
- data.tar.gz: 99437be8cbf015ad29890152e45163fc0efbe5f3e747c6d74014640f548f1b28
3
+ metadata.gz: df2bbffc1e4cccc31af216322ef484259e7acc71741bf721dc2359bbd9267c4e
4
+ data.tar.gz: 8f8f8cfa03ab51e5f3ac697aaa3caf04803523689e8c240df130f2e59696b021
5
5
  SHA512:
6
- metadata.gz: 532dfb71de17b84ca9f70c546290ca35261cf8d886a64cb8764bb1c72c512b3d5170ef9572075db026be9c28a64ddd5a4ce455d28c1d0595fbce0eb0e17a8389
7
- data.tar.gz: 05c1f902bedf840dca52bf6b3a0229606e43ffcbe156b48431bd72988c81310d5731fe56b55130ddb8260a866d2e789702632502b758bcb9df77d57839d38725
6
+ metadata.gz: aaa0388d363a6d3a0116a6f78e6d212027152226cd89faabdcb832f622395426d7487d27a2dd3268d97d6112fb2df6175113183dd689940a9f6748ad306ca134
7
+ data.tar.gz: b8837f8486c38a10e86f11415ceac1ace48f5bcb113db9a97cf2f0a3cd11cc798f8b401e03015b62594d5f75e1decb7e54c1be51001c60aa0d18e8540859ec97
@@ -9,8 +9,8 @@ module Motor
9
9
  load_and_authorize_resource :attachment, class: 'ActiveStorage::Attachment', parent: false
10
10
 
11
11
  def create
12
- if attachable?(@attachment.record)
13
- @attachment.record.public_send(@attachment.name).attach(file_params)
12
+ if attachable?(record)
13
+ record.public_send(@attachment.name).attach(file_params)
14
14
 
15
15
  head :ok
16
16
  else
@@ -20,6 +20,15 @@ module Motor
20
20
 
21
21
  private
22
22
 
23
+ def record
24
+ record_pk = @attachment.record.class.primary_key
25
+
26
+ Motor::Resources::FetchConfiguredModel.call(
27
+ @attachment.record.class,
28
+ cache_key: Motor::Resource.maximum(:updated_at)
29
+ ).find_by(record_pk => @attachment.record[record_pk])
30
+ end
31
+
23
32
  def attachable?(record)
24
33
  record.respond_to?("#{@attachment.name}_attachment=") ||
25
34
  record.respond_to?("#{@attachment.name}_attachments=")
@@ -278,3 +278,9 @@ en:
278
278
  there_is_nothing_here_yet: There is nothing here yet 🤷‍♂️
279
279
  is_null: Is null
280
280
  is_not_null: Is not null
281
+ split_tags_by: Split tags by
282
+ do_not_split: Do not split
283
+ semicolon: Semicolon
284
+ hyphen: Hyphen
285
+ comma: Comma
286
+ slash: Slash
@@ -278,6 +278,12 @@ es:
278
278
  there_is_nothing_here_yet: Todavía no hay nada aquí 🤷‍♂️
279
279
  is_null: Es nulo
280
280
  is_not_null: No es nulo
281
+ split_tags_by: Dividir las etiquetas por
282
+ do_not_split: No dividir
283
+ semicolon: Punto y coma
284
+ hyphen: Guión
285
+ comma: Coma
286
+ slash: Slash
281
287
  i:
282
288
  locale: es
283
289
  select:
@@ -274,6 +274,12 @@ pt:
274
274
  there_is_nothing_here_yet: Ainda não há nada aqui 🤷‍♂️
275
275
  is_null: É nulo
276
276
  is_not_null: Não é nulo
277
+ split_tags_by: Dividir as etiquetas por
278
+ do_not_split: Não dividir
279
+ semicolon: Ponto-e-vírgula
280
+ hyphen: Hífen
281
+ comma: Vírgula
282
+ slash: Slash
277
283
  i:
278
284
  locale: pt
279
285
  select:
@@ -23,7 +23,8 @@ module Motor
23
23
  'citext' => 'string',
24
24
  'jsonb' => 'json',
25
25
  'bool' => 'boolean',
26
- 'timestamp' => 'datetime'
26
+ 'timestamp' => 'datetime',
27
+ 'timestamptz' => 'datetime'
27
28
  }.freeze
28
29
 
29
30
  module_function
@@ -116,13 +116,20 @@ module Motor
116
116
  end
117
117
 
118
118
  def build_table_column(column, model, default_attrs)
119
+ access_type =
120
+ if model.primary_key == column.name
121
+ ColumnAccessTypes::READ_ONLY
122
+ else
123
+ COLUMN_NAME_ACCESS_TYPES.fetch(column.name, ColumnAccessTypes::READ_WRITE)
124
+ end
125
+
119
126
  {
120
127
  name: column.name,
121
128
  display_name: Utils.humanize_column_name(model.human_attribute_name(column.name)),
122
129
  column_type: fetch_column_type(column, model),
123
130
  column_source: ColumnSources::TABLE,
124
131
  is_array: column.array?,
125
- access_type: COLUMN_NAME_ACCESS_TYPES.fetch(column.name, ColumnAccessTypes::READ_WRITE),
132
+ access_type: access_type,
126
133
  default_value: default_attrs[column.name],
127
134
  validators: fetch_validators(model, column.name),
128
135
  reference: nil,
@@ -5,11 +5,14 @@ module Motor
5
5
  module FetchConfiguredModel
6
6
  CACHE_HASH = HashWithIndifferentAccess.new
7
7
 
8
+ HAS_AND_BELONGS_TO_MANY_JOIN_MODEL_PREFIX = 'HABTM_'
9
+
8
10
  module_function
9
11
 
10
12
  def call(model, cache_key:)
11
13
  configs = Motor::Configs::LoadFromCache.load_resources(cache_key: cache_key)
12
14
 
15
+ return model if model.name == 'ActiveStorage::Attachment'
13
16
  return model if configs.blank? || sti_model?(model)
14
17
 
15
18
  maybe_fetch_from_cache(
@@ -126,17 +129,16 @@ module Motor
126
129
 
127
130
  options = options.merge(config[:options] || {})
128
131
 
129
- klass.has_one(config[:name].to_sym, **options.symbolize_keys)
132
+ if config[:model_name] == 'active_storage/attachment'
133
+ klass.has_one_attached config[:name].delete_suffix('_attachment').to_sym
134
+ else
135
+ klass.has_one(config[:name].to_sym, **options.symbolize_keys)
136
+ end
130
137
  end
131
138
 
132
139
  def configure_reflection_classes(klass, cache_key)
133
- klass.reflections.each do |key, ref|
134
- begin
135
- next unless ref.klass
136
- next if ref.klass.anonymous?
137
- rescue StandardError
138
- next
139
- end
140
+ klass._reflections.each do |key, ref|
141
+ next unless configure_reflection_class?(ref)
140
142
 
141
143
  ref_dup = ref.dup
142
144
 
@@ -162,11 +164,17 @@ module Motor
162
164
 
163
165
  filters = options.delete(:filters)
164
166
 
165
- if filters.present?
166
- klass.has_many(association[:name].to_sym, -> { filter(filters).tap(&:arel) }, **options.symbolize_keys)
167
- else
168
- klass.has_many(association[:name].to_sym, **options.symbolize_keys)
169
- end
167
+ define_association(klass, association[:name], options, filters)
168
+ end
169
+ end
170
+
171
+ def define_association(klass, name, options, filters)
172
+ if options[:class_name] == 'ActiveStorage::Attachment'
173
+ klass.has_many_attached name.delete_suffix('_attachments').to_sym
174
+ elsif filters.present?
175
+ klass.has_many(name.to_sym, -> { filter(filters).tap(&:arel) }, **options.symbolize_keys)
176
+ else
177
+ klass.has_many(name.to_sym, **options.symbolize_keys)
170
178
  end
171
179
  end
172
180
 
@@ -203,6 +211,19 @@ module Motor
203
211
  end
204
212
  end
205
213
 
214
+ def configure_reflection_class?(ref)
215
+ begin
216
+ return false unless ref.klass
217
+ rescue StandardError
218
+ return false
219
+ end
220
+
221
+ return false if ref.klass.anonymous?
222
+ return false if ref.klass.name.demodulize.starts_with?(HAS_AND_BELONGS_TO_MANY_JOIN_MODEL_PREFIX)
223
+
224
+ true
225
+ end
226
+
206
227
  def sti_model?(model)
207
228
  !model.superclass.abstract_class && model.columns_hash[model.inheritance_column.to_s]
208
229
  end
data/lib/motor/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Motor
4
- VERSION = '0.2.25'
4
+ VERSION = '0.2.29'
5
5
  end
@@ -2601,9 +2601,9 @@
2601
2601
  "icons/zoom-out.svg.gz": "icons/zoom-out.svg.gz",
2602
2602
  "icons/zoom-question.svg": "icons/zoom-question.svg",
2603
2603
  "icons/zoom-question.svg.gz": "icons/zoom-question.svg.gz",
2604
- "main-0bcdc9f1a27b26d23abd.css.gz": "main-0bcdc9f1a27b26d23abd.css.gz",
2605
- "main-0bcdc9f1a27b26d23abd.js.LICENSE.txt": "main-0bcdc9f1a27b26d23abd.js.LICENSE.txt",
2606
- "main-0bcdc9f1a27b26d23abd.js.gz": "main-0bcdc9f1a27b26d23abd.js.gz",
2607
- "main.css": "main-0bcdc9f1a27b26d23abd.css",
2608
- "main.js": "main-0bcdc9f1a27b26d23abd.js"
2604
+ "main-67a3a033614f741d7e27.css.gz": "main-67a3a033614f741d7e27.css.gz",
2605
+ "main-67a3a033614f741d7e27.js.LICENSE.txt": "main-67a3a033614f741d7e27.js.LICENSE.txt",
2606
+ "main-67a3a033614f741d7e27.js.gz": "main-67a3a033614f741d7e27.js.gz",
2607
+ "main.css": "main-67a3a033614f741d7e27.css",
2608
+ "main.js": "main-67a3a033614f741d7e27.js"
2609
2609
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: motor-admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.25
4
+ version: 0.2.29
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pete Matsyburka
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-15 00:00:00.000000000 Z
11
+ date: 2021-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord-filter
@@ -1525,8 +1525,8 @@ files:
1525
1525
  - ui/dist/icons/zoom-money.svg.gz
1526
1526
  - ui/dist/icons/zoom-out.svg.gz
1527
1527
  - ui/dist/icons/zoom-question.svg.gz
1528
- - ui/dist/main-0bcdc9f1a27b26d23abd.css.gz
1529
- - ui/dist/main-0bcdc9f1a27b26d23abd.js.gz
1528
+ - ui/dist/main-67a3a033614f741d7e27.css.gz
1529
+ - ui/dist/main-67a3a033614f741d7e27.js.gz
1530
1530
  - ui/dist/manifest.json
1531
1531
  homepage:
1532
1532
  licenses: