mrpin-sdk 1.0.16 → 1.0.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mrpin/config/initializers/04_rails_admin_configurator.rb +209 -0
- data/lib/mrpin/core/app_config_base.rb +9 -0
- data/lib/mrpin/core/app_info/app_info_base.rb +10 -8
- data/lib/mrpin/core/app_info/e_app_state.rb +1 -0
- data/lib/mrpin/core/bundles/bundle_base.rb +0 -15
- data/lib/mrpin/core/remote/http/manager_remote_http.rb +41 -27
- data/lib/mrpin/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5aa20e4453caded89dc21f25559f63f651c5274
|
4
|
+
data.tar.gz: 193c2ecfbbb2781b1a765a47862ea53a9ea9b607
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 464ca96876a91dddb8fc4ca2a31d8029f1da33c156dca2eae8e9532f6f764eca634dd08e316fa13b4960b8da5fa604d02418f00315bc0ad9196315fc1ef14a2a
|
7
|
+
data.tar.gz: 0618302415d8b12db41ac54589550bb769d9942de0a4d58937e9fd9df7a2b013d2afb44192b679fae9b643b8d6596f008bae7320160b6d8176584155f508a978
|
@@ -0,0 +1,209 @@
|
|
1
|
+
### More at https://github.com/sferik/rails_admin/wiki/Base-configuration
|
2
|
+
class RailsAdminConfiguratorBase
|
3
|
+
|
4
|
+
#
|
5
|
+
# properties
|
6
|
+
#
|
7
|
+
|
8
|
+
attr_accessor :models_order_first
|
9
|
+
attr_accessor :models_order_last
|
10
|
+
|
11
|
+
#
|
12
|
+
# methods
|
13
|
+
#
|
14
|
+
|
15
|
+
public
|
16
|
+
def initialize
|
17
|
+
@models_names = []
|
18
|
+
@models_names_sorted = []
|
19
|
+
|
20
|
+
@models_order_first = []
|
21
|
+
@models_order_middle = []
|
22
|
+
@models_order_last = []
|
23
|
+
|
24
|
+
@models_groups = []
|
25
|
+
|
26
|
+
@config = nil
|
27
|
+
end
|
28
|
+
|
29
|
+
public
|
30
|
+
def add_models_names(items)
|
31
|
+
@models_names += items
|
32
|
+
|
33
|
+
nil
|
34
|
+
end
|
35
|
+
|
36
|
+
public
|
37
|
+
def configure
|
38
|
+
RailsAdmin.config do |config|
|
39
|
+
@config = config
|
40
|
+
|
41
|
+
@config.included_models += @models_names
|
42
|
+
|
43
|
+
init_model_groups
|
44
|
+
|
45
|
+
configure_auth
|
46
|
+
configure_actions
|
47
|
+
configure_models
|
48
|
+
configure_view
|
49
|
+
end
|
50
|
+
|
51
|
+
nil
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
def init_model_groups
|
56
|
+
# calc models order
|
57
|
+
@config.included_models.each do |model_name|
|
58
|
+
model_class = get_class_by_name(model_name)
|
59
|
+
|
60
|
+
group_name = get_group_name(model_class)
|
61
|
+
|
62
|
+
@models_groups << group_name
|
63
|
+
end
|
64
|
+
|
65
|
+
@models_groups.uniq!
|
66
|
+
|
67
|
+
@models_order_middle = @models_groups - @models_order_first - @models_order_last
|
68
|
+
|
69
|
+
@models_order_middle.sort!
|
70
|
+
|
71
|
+
@models_names_sorted = @models_order_first + @models_order_middle + @models_order_last
|
72
|
+
|
73
|
+
nil
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
def configure_auth
|
78
|
+
# == Devise ==
|
79
|
+
@config.authenticate_with do
|
80
|
+
warden.authenticate! scope: :admin_user
|
81
|
+
end
|
82
|
+
|
83
|
+
@config.current_user_method(&:current_admin_user)
|
84
|
+
|
85
|
+
nil
|
86
|
+
end
|
87
|
+
|
88
|
+
private
|
89
|
+
def configure_actions
|
90
|
+
@config.actions do
|
91
|
+
dashboard do
|
92
|
+
statistics false
|
93
|
+
end
|
94
|
+
|
95
|
+
index
|
96
|
+
new
|
97
|
+
# export
|
98
|
+
# history_show
|
99
|
+
bulk_delete
|
100
|
+
show
|
101
|
+
edit
|
102
|
+
delete
|
103
|
+
show_in_app
|
104
|
+
end
|
105
|
+
|
106
|
+
nil
|
107
|
+
end
|
108
|
+
|
109
|
+
private
|
110
|
+
def configure_models
|
111
|
+
# setup models
|
112
|
+
@config.included_models.each do |model|
|
113
|
+
model_class = get_class_by_name(model)
|
114
|
+
model_class.init_scopes if model_class.respond_to?(:init_scopes)
|
115
|
+
|
116
|
+
|
117
|
+
model_fields = model_class.attribute_names
|
118
|
+
model_relations = model_class.relations.keys
|
119
|
+
|
120
|
+
fields_for_list = model_fields + model_relations
|
121
|
+
fields_for_edit = model_fields
|
122
|
+
fields_for_show = model_fields + model_relations
|
123
|
+
|
124
|
+
configure_model(model_class, fields_for_list, fields_for_edit, fields_for_show)
|
125
|
+
end
|
126
|
+
|
127
|
+
nil
|
128
|
+
end
|
129
|
+
|
130
|
+
private
|
131
|
+
def configure_view
|
132
|
+
@config.show_gravatar = false
|
133
|
+
@config.total_columns_width = 1000
|
134
|
+
@config.default_items_per_page = 25
|
135
|
+
@config.compact_show_view = false
|
136
|
+
|
137
|
+
nil
|
138
|
+
end
|
139
|
+
|
140
|
+
private
|
141
|
+
def configure_model(model_class, fields_for_list, fields_for_edit, fields_for_show)
|
142
|
+
models_names_sorted = @models_names_sorted
|
143
|
+
model_group = get_group_name(model_class)
|
144
|
+
|
145
|
+
configurator = self
|
146
|
+
|
147
|
+
@config.model(model_class.to_s) do
|
148
|
+
|
149
|
+
if model_class.respond_to?(:need_show_for_admin_user?)
|
150
|
+
visible { model_class.need_show_for_admin_user?(bindings[:controller].current_admin_user) }
|
151
|
+
end
|
152
|
+
|
153
|
+
navigation_label(model_group)
|
154
|
+
weight models_names_sorted.index(model_group) || 0
|
155
|
+
|
156
|
+
#configure list
|
157
|
+
list do
|
158
|
+
model_class.filters_for_admin_list(self) if model_class.respond_to?(:filters_for_admin_list)
|
159
|
+
model_class.sort_by_for_admin_list(self) if model_class.respond_to?(:sort_by_for_admin_list)
|
160
|
+
|
161
|
+
configurator.try_configure_admin_for(self, model_class, fields_for_list, :configure_admin_list)
|
162
|
+
|
163
|
+
#init scopes
|
164
|
+
scopes_list = model_class.scopes.keys.dup
|
165
|
+
|
166
|
+
scopes_list.delete(:page)
|
167
|
+
|
168
|
+
if scopes_list.size > 0
|
169
|
+
#add scopes 'all' at first tab
|
170
|
+
scopes_list = [nil] + scopes_list
|
171
|
+
|
172
|
+
scopes(scopes_list)
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
edit { configurator.try_configure_admin_for(self, model_class, fields_for_edit, :configure_admin_edit) }
|
177
|
+
show { configurator.try_configure_admin_for(self, model_class, fields_for_show, :configure_admin_show) }
|
178
|
+
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
private
|
183
|
+
def get_group_name(model_class)
|
184
|
+
result = ''
|
185
|
+
|
186
|
+
if model_class.methods.include?(:admin_group)
|
187
|
+
result = model_class.admin_group
|
188
|
+
else
|
189
|
+
result = model_class.to_s.underscore.split('_').first
|
190
|
+
end
|
191
|
+
|
192
|
+
result
|
193
|
+
end
|
194
|
+
|
195
|
+
public
|
196
|
+
def try_configure_admin_for(context, model_class, fields, method_name)
|
197
|
+
return unless model_class.respond_to?(method_name)
|
198
|
+
|
199
|
+
fields.each do |model_field|
|
200
|
+
|
201
|
+
field_name = model_field.to_sym
|
202
|
+
|
203
|
+
model_class.send(method_name, context, field_name)
|
204
|
+
end
|
205
|
+
|
206
|
+
nil
|
207
|
+
end
|
208
|
+
|
209
|
+
end
|
@@ -33,6 +33,10 @@ class AppInfoBase
|
|
33
33
|
end
|
34
34
|
|
35
35
|
case @state
|
36
|
+
when EAppState::EAS_INIT_CONFIG
|
37
|
+
init_config
|
38
|
+
when EAppState::EAS_INIT_MANAGERS
|
39
|
+
init_managers
|
36
40
|
when EAppState::EAS_POST_INIT
|
37
41
|
call_in_all_managers_with_benchmark('[POST_INIT]', 'post_init')
|
38
42
|
when EAppState::EAS_LOAD_INIT_DATA
|
@@ -186,8 +190,10 @@ class AppInfoBase
|
|
186
190
|
@aws_uploader = AWSUploader.new
|
187
191
|
|
188
192
|
begin
|
189
|
-
|
190
|
-
|
193
|
+
|
194
|
+
self.state = EAppState::EAS_INIT_CONFIG
|
195
|
+
|
196
|
+
self.state = EAppState::EAS_INIT_MANAGERS
|
191
197
|
rescue Exception => e
|
192
198
|
on_server_error(e.to_s, e)
|
193
199
|
|
@@ -214,15 +220,13 @@ class AppInfoBase
|
|
214
220
|
|
215
221
|
protected
|
216
222
|
def init_config
|
217
|
-
config = AppConfigBase.first
|
223
|
+
@config = @config || AppConfigBase.first
|
218
224
|
|
219
|
-
if config.nil?
|
225
|
+
if @config.nil?
|
220
226
|
@logger.warn('config is empty')
|
221
227
|
return
|
222
228
|
end
|
223
229
|
|
224
|
-
@config = config
|
225
|
-
|
226
230
|
if @config.server_on_maintenance
|
227
231
|
self.state = EAppState::EAS_MAINTENANCE
|
228
232
|
end
|
@@ -232,8 +236,6 @@ class AppInfoBase
|
|
232
236
|
|
233
237
|
protected
|
234
238
|
def init_managers
|
235
|
-
self.state = EAppState::EAS_INIT_MANAGERS
|
236
|
-
|
237
239
|
@managers_list = []
|
238
240
|
@managers_with_json_list = []
|
239
241
|
#key - build type, value - manager_bundle
|
@@ -58,7 +58,6 @@ class BundleBase < ModelBase
|
|
58
58
|
#
|
59
59
|
|
60
60
|
after_validation :update_version
|
61
|
-
after_save :callback_after_save
|
62
61
|
|
63
62
|
#
|
64
63
|
# db
|
@@ -133,20 +132,6 @@ class BundleBase < ModelBase
|
|
133
132
|
self.version += 1
|
134
133
|
end
|
135
134
|
|
136
|
-
public
|
137
|
-
def callback_after_save
|
138
|
-
return unless errors.empty?
|
139
|
-
|
140
|
-
return unless self.changed?
|
141
|
-
|
142
|
-
return unless Rails.env.development?
|
143
|
-
|
144
|
-
manager_bundles = AppInfo.instance.managers_bundles_map[self.build_type]
|
145
|
-
|
146
|
-
manager_bundles.invalidate_cache
|
147
|
-
manager_bundles.generate_client_json
|
148
|
-
end
|
149
|
-
|
150
135
|
private
|
151
136
|
def check_uniq
|
152
137
|
if BundleBase.where(build_type: self.build_type, name: self.name, :id.ne => self.id).exists?
|
@@ -1,20 +1,23 @@
|
|
1
1
|
class ManagerRemoteHttp
|
2
2
|
METHODS = [:post, :get]
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
DEFAULT_REDIRECT_LIMIT =
|
4
|
+
DEFAULT_TIMEOUT_READ = 10
|
5
|
+
DEFAULT_TIMEOUT_OPEN = 10
|
6
|
+
DEFAULT_REDIRECT_LIMIT = 10
|
7
7
|
|
8
|
-
|
8
|
+
#
|
9
|
+
# methods
|
10
|
+
#
|
9
11
|
|
12
|
+
def initialize(options = {})
|
10
13
|
url = options.assert_property!(:url)
|
11
14
|
|
12
15
|
faraday_options =
|
13
16
|
{
|
14
17
|
request:
|
15
18
|
{
|
16
|
-
timeout: options[:read_timeout] ||
|
17
|
-
open_timeout: options[:open_timeout] ||
|
19
|
+
timeout: options[:read_timeout] || DEFAULT_TIMEOUT_READ,
|
20
|
+
open_timeout: options[:open_timeout] || DEFAULT_TIMEOUT_OPEN
|
18
21
|
}
|
19
22
|
}
|
20
23
|
|
@@ -50,19 +53,22 @@ class ManagerRemoteHttp
|
|
50
53
|
|
51
54
|
begin
|
52
55
|
|
53
|
-
response = @connection.send
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
56
|
+
response = @connection.send(method, controller, params)
|
57
|
+
|
58
|
+
if response.success?
|
59
|
+
result =
|
60
|
+
{
|
61
|
+
status: EResponseType::ERT_OK,
|
62
|
+
response: response.body
|
63
|
+
}
|
64
|
+
else
|
65
|
+
result =
|
66
|
+
{
|
67
|
+
status: EResponseType::ERT_ERROR,
|
68
|
+
code: response.status,
|
69
|
+
response: response.body
|
70
|
+
}
|
71
|
+
end
|
66
72
|
|
67
73
|
rescue Exception => e
|
68
74
|
result = {status: EResponseType::ERT_ERROR, response: e.message}
|
@@ -88,14 +94,22 @@ class ManagerRemoteHttp
|
|
88
94
|
req.body = params.to_json
|
89
95
|
end
|
90
96
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
97
|
+
if response.success?
|
98
|
+
response_json = JSON.parse(response.body, {symbolize_names: true})
|
99
|
+
|
100
|
+
result =
|
101
|
+
{
|
102
|
+
status: response.body,
|
103
|
+
response: response_json
|
104
|
+
}
|
105
|
+
else
|
106
|
+
result =
|
107
|
+
{
|
108
|
+
status: EResponseType::ERT_ERROR,
|
109
|
+
code: response.status,
|
110
|
+
response: response.body
|
111
|
+
}
|
112
|
+
end
|
99
113
|
|
100
114
|
rescue Exception => e
|
101
115
|
result = {status: EResponseType::ERT_ERROR, response: e.message}
|
data/lib/mrpin/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mrpin-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gregory
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2017-03-
|
14
|
+
date: 2017-03-21 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|
@@ -336,6 +336,7 @@ files:
|
|
336
336
|
- lib/mrpin/config/initializers/01_devise.rb
|
337
337
|
- lib/mrpin/config/initializers/02_mongo.rb
|
338
338
|
- lib/mrpin/config/initializers/03_i18n.rb
|
339
|
+
- lib/mrpin/config/initializers/04_rails_admin_configurator.rb
|
339
340
|
- lib/mrpin/config/locales/rails_admin.en.yml
|
340
341
|
- lib/mrpin/controllers/application_controller_base.rb
|
341
342
|
- lib/mrpin/controllers/system_controller_base.rb
|