motor-admin 0.1.28 → 0.1.29
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/concerns/motor/wrap_io_params.rb +25 -0
- data/app/controllers/motor/active_storage_attachments_controller.rb +12 -5
- data/app/controllers/motor/data_controller.rb +14 -13
- data/lib/motor/build_schema/load_from_rails.rb +26 -15
- data/lib/motor/build_schema/persist_resource_configs.rb +3 -3
- data/lib/motor/version.rb +1 -1
- data/ui/dist/{main-4da1a5102d7bc66aefd0.css.gz → main-482137e0bc1ba9f875dc.css.gz} +0 -0
- data/ui/dist/main-482137e0bc1ba9f875dc.js.gz +0 -0
- data/ui/dist/manifest.json +5 -5
- metadata +5 -4
- data/ui/dist/main-4da1a5102d7bc66aefd0.js.gz +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f18c5fae6ca2c70b739f68d0a9b45f456b6c9f9592b4c44d216210a067b2e33
|
4
|
+
data.tar.gz: 4a65316ecce576b9de027fe93ff14bf9307826269af771fbfc9a7bbf3699f051
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f51029e47fe84f67f34ced365523f2214c44986f241ad35a77405f067a556bbca8ca124cb09812b007a709101729ae3dfc35aa94284c46dbbf2f63a990459001
|
7
|
+
data.tar.gz: 555b5570c50258d3ee00a317795868cee3281e0d3675d894e25773f26977d21d40781b031a4e3835469fa580d39b3e1ba5b87f11dcad83986b0bd144f612bc5c
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Motor
|
4
|
+
module WrapIoParams
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
before_action :wrap_io_params, only: %i[update create]
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def wrap_io_params(hash = params)
|
14
|
+
hash.each do |key, value|
|
15
|
+
if key == 'io'
|
16
|
+
hash[key] = StringIO.new(value.encode('ISO-8859-1'))
|
17
|
+
elsif value.is_a?(ActionController::Parameters)
|
18
|
+
wrap_io_params(value)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
hash
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -2,16 +2,15 @@
|
|
2
2
|
|
3
3
|
module Motor
|
4
4
|
class ActiveStorageAttachmentsController < ApiBaseController
|
5
|
+
include Motor::WrapIoParams
|
6
|
+
|
5
7
|
wrap_parameters :data, except: %i[include fields]
|
6
8
|
|
7
9
|
load_and_authorize_resource :attachment, class: 'ActiveStorage::Attachment', parent: false
|
8
10
|
|
9
11
|
def create
|
10
12
|
if attachable?(@attachment.record)
|
11
|
-
@attachment.record.public_send(@attachment.name).attach(
|
12
|
-
io: StringIO.new(params.dig(:data, :file, :io).to_s.encode('ISO-8859-1')),
|
13
|
-
filename: params.dig(:data, :file, :filename)
|
14
|
-
)
|
13
|
+
@attachment.record.public_send(@attachment.name).attach(file_params)
|
15
14
|
|
16
15
|
head :ok
|
17
16
|
else
|
@@ -26,8 +25,16 @@ module Motor
|
|
26
25
|
record.respond_to?("#{@attachment.name}_attachments=")
|
27
26
|
end
|
28
27
|
|
28
|
+
def file_params
|
29
|
+
params.require(:data).require(:file).permit(:io, :filename).to_h
|
30
|
+
end
|
31
|
+
|
29
32
|
def attachment_params
|
30
|
-
params
|
33
|
+
if params[:data].present?
|
34
|
+
params.require(:data).except(:file).permit!
|
35
|
+
else
|
36
|
+
{}
|
37
|
+
end
|
31
38
|
end
|
32
39
|
end
|
33
40
|
end
|
@@ -2,13 +2,14 @@
|
|
2
2
|
|
3
3
|
module Motor
|
4
4
|
class DataController < ApiBaseController
|
5
|
+
include Motor::WrapIoParams
|
6
|
+
|
5
7
|
INSTANCE_VARIABLE_NAME = 'resource'
|
6
8
|
|
7
9
|
wrap_parameters :data, except: %i[include fields]
|
8
10
|
|
9
11
|
before_action :load_and_authorize_resource
|
10
12
|
before_action :load_and_authorize_association
|
11
|
-
before_action :wrap_io_params
|
12
13
|
|
13
14
|
def index
|
14
15
|
@resources = Motor::ApiQuery.call(@resources, params)
|
@@ -27,12 +28,20 @@ module Motor
|
|
27
28
|
@resource.save!
|
28
29
|
|
29
30
|
render json: { data: Motor::ApiQuery::BuildJson.call(@resource, params) }
|
31
|
+
rescue ActiveRecord::RecordInvalid
|
32
|
+
render json: { errors: @resource.errors }, status: :unprocessable_entity
|
33
|
+
rescue StandardError => e
|
34
|
+
render json: { errors: [e.message] }, status: :unprocessable_entity
|
30
35
|
end
|
31
36
|
|
32
37
|
def update
|
33
38
|
@resource.update!(resource_params)
|
34
39
|
|
35
40
|
render json: { data: Motor::ApiQuery::BuildJson.call(@resource, params) }
|
41
|
+
rescue ActiveRecord::RecordInvalid
|
42
|
+
render json: { errors: @resource.errors }, status: :unprocessable_entity
|
43
|
+
rescue StandardError => e
|
44
|
+
render json: { errors: [e.message] }, status: :unprocessable_entity
|
36
45
|
end
|
37
46
|
|
38
47
|
def destroy
|
@@ -77,6 +86,8 @@ module Motor
|
|
77
86
|
self,
|
78
87
|
options
|
79
88
|
).load_and_authorize_resource
|
89
|
+
rescue StandardError => e
|
90
|
+
render json: { errors: [e.message] }, status: :unprocessable_entity
|
80
91
|
end
|
81
92
|
|
82
93
|
def load_and_authorize_association
|
@@ -96,6 +107,8 @@ module Motor
|
|
96
107
|
else
|
97
108
|
render json: { message: 'Unknown association' }, status: :not_found
|
98
109
|
end
|
110
|
+
rescue StandardError => e
|
111
|
+
render json: { errors: [e.message] }, status: :unprocessable_entity
|
99
112
|
end
|
100
113
|
|
101
114
|
def resource_params
|
@@ -105,17 +118,5 @@ module Motor
|
|
105
118
|
{}
|
106
119
|
end
|
107
120
|
end
|
108
|
-
|
109
|
-
def wrap_io_params(hash = params)
|
110
|
-
hash.each do |key, value|
|
111
|
-
if key == 'io'
|
112
|
-
hash[key] = StringIO.new(value.encode('ISO-8859-1'))
|
113
|
-
elsif value.is_a?(ActionController::Parameters)
|
114
|
-
wrap_io_params(value)
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
hash
|
119
|
-
end
|
120
121
|
end
|
121
122
|
end
|
@@ -133,7 +133,7 @@ module Motor
|
|
133
133
|
column_type: is_attachment ? 'file' : 'integer',
|
134
134
|
access_type: access_type,
|
135
135
|
default_value: default_attrs[column_name],
|
136
|
-
validators: fetch_validators(model, column_name),
|
136
|
+
validators: fetch_validators(model, column_name, ref),
|
137
137
|
format: {},
|
138
138
|
reference: {
|
139
139
|
name: name,
|
@@ -172,23 +172,34 @@ module Motor
|
|
172
172
|
end.compact
|
173
173
|
end
|
174
174
|
|
175
|
-
def fetch_validators(model, column_name)
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
{ includes: validator.send(:delimiter) }
|
180
|
-
when ActiveRecord::Validations::PresenceValidator
|
181
|
-
{ required: true }
|
182
|
-
when ActiveModel::Validations::FormatValidator
|
183
|
-
{ format: JsRegex.new(validator.options[:with]).to_h.slice(:source, :options) }
|
184
|
-
when ActiveRecord::Validations::LengthValidator
|
185
|
-
{ length: validator.options }
|
186
|
-
when ActiveModel::Validations::NumericalityValidator
|
187
|
-
{ numeric: validator.options }
|
175
|
+
def fetch_validators(model, column_name, reflection = nil)
|
176
|
+
validators =
|
177
|
+
if reflection&.belongs_to? && !reflection.options[:optional]
|
178
|
+
[{ required: true }]
|
188
179
|
else
|
189
|
-
|
180
|
+
[]
|
190
181
|
end
|
182
|
+
|
183
|
+
validators += model.validators_on(column_name).map do |validator|
|
184
|
+
build_validator_hash(validator)
|
191
185
|
end.compact
|
186
|
+
|
187
|
+
validators.uniq
|
188
|
+
end
|
189
|
+
|
190
|
+
def build_validator_hash(validator)
|
191
|
+
case validator
|
192
|
+
when ActiveModel::Validations::InclusionValidator
|
193
|
+
{ includes: validator.send(:delimiter) }
|
194
|
+
when ActiveRecord::Validations::PresenceValidator
|
195
|
+
{ required: true }
|
196
|
+
when ActiveModel::Validations::FormatValidator
|
197
|
+
{ format: JsRegex.new(validator.options[:with]).to_h.slice(:source, :options) }
|
198
|
+
when ActiveRecord::Validations::LengthValidator
|
199
|
+
{ length: validator.options }
|
200
|
+
when ActiveModel::Validations::NumericalityValidator
|
201
|
+
{ numeric: validator.options }
|
202
|
+
end
|
192
203
|
end
|
193
204
|
|
194
205
|
def eager_load_models!
|
@@ -90,9 +90,9 @@ module Motor
|
|
90
90
|
return preferences if new_prefs[configs_name].blank?
|
91
91
|
|
92
92
|
normalized_configs = public_send("normalize_#{configs_name}",
|
93
|
-
default_prefs[
|
94
|
-
existing_prefs.fetch(
|
95
|
-
new_prefs.fetch(
|
93
|
+
default_prefs[configs_name],
|
94
|
+
existing_prefs.fetch(configs_name, []),
|
95
|
+
new_prefs.fetch(configs_name, []))
|
96
96
|
|
97
97
|
preferences[configs_name] = normalized_configs
|
98
98
|
|
data/lib/motor/version.rb
CHANGED
Binary file
|
Binary file
|
data/ui/dist/manifest.json
CHANGED
@@ -5,9 +5,9 @@
|
|
5
5
|
"fonts/ionicons.ttf?v=3.0.0-alpha.3": "fonts/ionicons.ttf",
|
6
6
|
"fonts/ionicons.woff2?v=3.0.0-alpha.3": "fonts/ionicons.woff2",
|
7
7
|
"fonts/ionicons.woff?v=3.0.0-alpha.3": "fonts/ionicons.woff",
|
8
|
-
"main-
|
9
|
-
"main-
|
10
|
-
"main-
|
11
|
-
"main.css": "main-
|
12
|
-
"main.js": "main-
|
8
|
+
"main-482137e0bc1ba9f875dc.css.gz": "main-482137e0bc1ba9f875dc.css.gz",
|
9
|
+
"main-482137e0bc1ba9f875dc.js.LICENSE.txt": "main-482137e0bc1ba9f875dc.js.LICENSE.txt",
|
10
|
+
"main-482137e0bc1ba9f875dc.js.gz": "main-482137e0bc1ba9f875dc.js.gz",
|
11
|
+
"main.css": "main-482137e0bc1ba9f875dc.css",
|
12
|
+
"main.js": "main-482137e0bc1ba9f875dc.js"
|
13
13
|
}
|
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.1.
|
4
|
+
version: 0.1.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-05-
|
11
|
+
date: 2021-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord-filter
|
@@ -132,6 +132,7 @@ files:
|
|
132
132
|
- LICENSE
|
133
133
|
- README.md
|
134
134
|
- Rakefile
|
135
|
+
- app/controllers/concerns/motor/wrap_io_params.rb
|
135
136
|
- app/controllers/motor/active_storage_attachments_controller.rb
|
136
137
|
- app/controllers/motor/alerts_controller.rb
|
137
138
|
- app/controllers/motor/api_base_controller.rb
|
@@ -214,8 +215,8 @@ files:
|
|
214
215
|
- lib/motor/ui_configs.rb
|
215
216
|
- lib/motor/version.rb
|
216
217
|
- ui/dist/fonts/ionicons.woff2
|
217
|
-
- ui/dist/main-
|
218
|
-
- ui/dist/main-
|
218
|
+
- ui/dist/main-482137e0bc1ba9f875dc.css.gz
|
219
|
+
- ui/dist/main-482137e0bc1ba9f875dc.js.gz
|
219
220
|
- ui/dist/manifest.json
|
220
221
|
homepage:
|
221
222
|
licenses:
|
Binary file
|