motor-admin 0.2.28 → 0.2.32

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: 890e9157c807073892957ebdab77377f9cf36b91f5e00f04fd128f5591764fd2
4
- data.tar.gz: 41aa043a58ec68f713bf2a75e21464eb8bad07f000cabacd9fa364e821329414
3
+ metadata.gz: 4f3ed23b54a556070e9c4ba1d46c5a9ab8fe32be08435afe2340ffb7e5ed885b
4
+ data.tar.gz: c627fbb99941389e0da067583cde8d4d32e0e0325f94a55a03ee5bd50c630384
5
5
  SHA512:
6
- metadata.gz: d5ea14f4ecd4d9deaadac11b12da0d5d689bf8256505a17b632a30a6758fb61e84650f6b997e352f77ccf91a139242aa04f81661d352cfb72087112304383756
7
- data.tar.gz: a4ea641247486ee81239eda91e209e421082d8d45fe0dfffde355749f7e273b1f02964f3e668904a493610b38885da87928dbcee151a5c647c60675d84eb6e6a
6
+ metadata.gz: 624c0c4e27ac1aac78128dc22455dfc1029abe81d06dc1dd7994c96f8660df561d213e4ad8b569dc331d1eb8655e41d1ee075ea5dc0406e8934727265f7dbe66
7
+ data.tar.gz: 783def6366713e85cdfb8bda8cfb9a6843dce7a64e9859409c25b0163fa8ca7b9ecfe212eb20269179b2ca20c4f100db29aa2e570c477735b4f31283e3e748ca
data/README.md CHANGED
@@ -38,6 +38,7 @@ $ rails motor:install && rake db:migrate
38
38
  * [I18n](#i18n)
39
39
  * [Optimized for mobile](#optimized-for-mobile)
40
40
  * [Configurations sync between environments](#configurations-sync)
41
+ * [Authentication](#authentication)
41
42
 
42
43
  ## [Pro](https://www.getmotoradmin.com/pro)
43
44
 
@@ -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=")
@@ -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
@@ -45,7 +45,18 @@ module Motor
45
45
 
46
46
  arel_column = reflection_model.arel_table[field]
47
47
 
48
- direction.present? ? arel_column.desc : arel_column.asc
48
+ arel_direction = direction.present? ? arel_column.desc : arel_column.asc
49
+
50
+ maybe_add_null_last(model, arel_direction)
51
+ end
52
+ end
53
+
54
+ def maybe_add_null_last(model, arel_direction)
55
+ if arel_direction.respond_to?(:nulls_last) &&
56
+ model.connection.class.name == 'ActiveRecord::ConnectionAdapters::PostgreSQLAdapter'
57
+ arel_direction.nulls_last
58
+ else
59
+ arel_direction
49
60
  end
50
61
  end
51
62
  end
@@ -115,7 +115,7 @@ module Motor
115
115
  scopes: [],
116
116
  actions: Motor::BuildSchema::Defaults.actions.reject { |e| e[:name] == 'edit' },
117
117
  tabs: Motor::BuildSchema::Defaults.tabs,
118
- visible: true
118
+ visible: false
119
119
  }.with_indifferent_access
120
120
  end
121
121
  # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
@@ -87,8 +87,8 @@ module Motor
87
87
  'district' => 'building-community',
88
88
  'community' => 'building-community',
89
89
  'activity' => 'activity',
90
- 'invoice' => 'invoice',
91
- 'settlement' => 'invoice',
90
+ 'invoice' => 'file-invoice',
91
+ 'settlement' => 'file-invoice',
92
92
  'state' => 'map',
93
93
  'note' => 'note',
94
94
  'order' => 'truck-delivery',
@@ -12,6 +12,7 @@ module Motor
12
12
  def call(model, cache_key:)
13
13
  configs = Motor::Configs::LoadFromCache.load_resources(cache_key: cache_key)
14
14
 
15
+ return model if model.name == 'ActiveStorage::Attachment'
15
16
  return model if configs.blank? || sti_model?(model)
16
17
 
17
18
  maybe_fetch_from_cache(
@@ -128,7 +129,11 @@ module Motor
128
129
 
129
130
  options = options.merge(config[:options] || {})
130
131
 
131
- 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
132
137
  end
133
138
 
134
139
  def configure_reflection_classes(klass, cache_key)
@@ -159,11 +164,17 @@ module Motor
159
164
 
160
165
  filters = options.delete(:filters)
161
166
 
162
- if filters.present?
163
- klass.has_many(association[:name].to_sym, -> { filter(filters).tap(&:arel) }, **options.symbolize_keys)
164
- else
165
- klass.has_many(association[:name].to_sym, **options.symbolize_keys)
166
- 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)
167
178
  end
168
179
  end
169
180
 
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.28'
4
+ VERSION = '0.2.32'
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-9f6b19ff999e209e9d33.css.gz": "main-9f6b19ff999e209e9d33.css.gz",
2605
- "main-9f6b19ff999e209e9d33.js.LICENSE.txt": "main-9f6b19ff999e209e9d33.js.LICENSE.txt",
2606
- "main-9f6b19ff999e209e9d33.js.gz": "main-9f6b19ff999e209e9d33.js.gz",
2607
- "main.css": "main-9f6b19ff999e209e9d33.css",
2608
- "main.js": "main-9f6b19ff999e209e9d33.js"
2604
+ "main-75c26326d4058b8611c3.css.gz": "main-75c26326d4058b8611c3.css.gz",
2605
+ "main-75c26326d4058b8611c3.js.LICENSE.txt": "main-75c26326d4058b8611c3.js.LICENSE.txt",
2606
+ "main-75c26326d4058b8611c3.js.gz": "main-75c26326d4058b8611c3.js.gz",
2607
+ "main.css": "main-75c26326d4058b8611c3.css",
2608
+ "main.js": "main-75c26326d4058b8611c3.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.28
4
+ version: 0.2.32
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-20 00:00:00.000000000 Z
11
+ date: 2021-11-30 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-9f6b19ff999e209e9d33.css.gz
1529
- - ui/dist/main-9f6b19ff999e209e9d33.js.gz
1528
+ - ui/dist/main-75c26326d4058b8611c3.css.gz
1529
+ - ui/dist/main-75c26326d4058b8611c3.js.gz
1530
1530
  - ui/dist/manifest.json
1531
1531
  homepage:
1532
1532
  licenses: