simpleadmin 1.2.7 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +17 -1
- data/.travis.yml +6 -3
- data/Gemfile +13 -0
- data/Gemfile.lock +51 -1
- data/README.md +5 -4
- data/app/controllers/simple_admin/base_controller.rb +5 -1
- data/app/controllers/simple_admin/entities_controller.rb +9 -20
- data/app/controllers/simple_admin/entity_field_type_actions_controller.rb +7 -3
- data/app/controllers/simple_admin/resources_controller.rb +12 -17
- data/app/services/entity_service.rb +33 -0
- data/app/services/resource_search_service.rb +22 -0
- data/app/services/{resources_service.rb → resource_service.rb} +10 -23
- data/lib/simpleadmin/routes.rb +5 -17
- data/lib/simpleadmin/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0675ea91b122e24a24afa25b104acde743d73131
|
4
|
+
data.tar.gz: cd45192036a06b9ba99e14339b32f31fdc33699e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6065774f68b225cd6028d1f20a9c2f7ea41a75adfd3d23a8e964ee1c93ac8930afdfb9a696a1696fdbafc42596c79dca84c9dfdbe963b6276848fa0fef98cf6e
|
7
|
+
data.tar.gz: 929b39f84960a580dd8734d967e8183ecdf406958e4e414ace26b03d692fda526ac8b618bb77f299d2b368488911a9a17c6d3e9291ce1091d7e0e7fcc89d385c
|
data/.rubocop.yml
CHANGED
@@ -1,7 +1,14 @@
|
|
1
1
|
AllCops:
|
2
2
|
Exclude:
|
3
|
+
- 'spec/fixtures/**/*'
|
3
4
|
- 'bin/*'
|
4
|
-
|
5
|
+
- 'spec/support'
|
6
|
+
- 'spec/factories'
|
7
|
+
- 'spec/fixtures'
|
8
|
+
- 'spec/support/*'
|
9
|
+
- 'spec/spec_helper.rb'
|
10
|
+
- 'spec/rails_helper.rb'
|
11
|
+
TargetRubyVersion: 2.5.1
|
5
12
|
DisplayCopNames: true
|
6
13
|
|
7
14
|
Style/Encoding:
|
@@ -45,6 +52,9 @@ Metrics/PerceivedComplexity:
|
|
45
52
|
Metrics/CyclomaticComplexity:
|
46
53
|
Max: 20
|
47
54
|
|
55
|
+
Metrics/ParameterLists:
|
56
|
+
Max: 10
|
57
|
+
|
48
58
|
Style/ClassAndModuleChildren:
|
49
59
|
Enabled: false
|
50
60
|
|
@@ -56,3 +66,9 @@ Layout/IndentationConsistency:
|
|
56
66
|
|
57
67
|
Style/AccessModifierDeclarations:
|
58
68
|
Enabled: false
|
69
|
+
|
70
|
+
Layout/AlignHash:
|
71
|
+
Enabled: false
|
72
|
+
|
73
|
+
Layout/IndentHash:
|
74
|
+
Enabled: false
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
simpleadmin (1.2.
|
4
|
+
simpleadmin (1.2.7)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -43,16 +43,36 @@ GEM
|
|
43
43
|
i18n (>= 0.7, < 2)
|
44
44
|
minitest (~> 5.1)
|
45
45
|
tzinfo (~> 1.1)
|
46
|
+
addressable (2.6.0)
|
47
|
+
public_suffix (>= 2.0.2, < 4.0)
|
46
48
|
arel (7.1.4)
|
47
49
|
builder (3.2.3)
|
50
|
+
codecov (0.1.14)
|
51
|
+
json
|
52
|
+
simplecov
|
53
|
+
url
|
54
|
+
coderay (1.1.2)
|
48
55
|
concurrent-ruby (1.1.4)
|
56
|
+
crack (0.4.3)
|
57
|
+
safe_yaml (~> 1.0.0)
|
49
58
|
crass (1.0.4)
|
59
|
+
database_cleaner (1.7.0)
|
50
60
|
diff-lcs (1.3)
|
61
|
+
docile (1.3.1)
|
51
62
|
erubis (2.7.0)
|
63
|
+
factory_bot (4.11.1)
|
64
|
+
activesupport (>= 3.0.0)
|
65
|
+
factory_bot_rails (4.11.1)
|
66
|
+
factory_bot (~> 4.11.1)
|
67
|
+
railties (>= 3.0.0)
|
68
|
+
faker (1.9.1)
|
69
|
+
i18n (>= 0.7)
|
52
70
|
globalid (0.4.1)
|
53
71
|
activesupport (>= 4.2.0)
|
72
|
+
hashdiff (0.3.8)
|
54
73
|
i18n (1.3.0)
|
55
74
|
concurrent-ruby (~> 1.0)
|
75
|
+
json (2.1.0)
|
56
76
|
loofah (2.2.3)
|
57
77
|
crass (~> 1.0.2)
|
58
78
|
nokogiri (>= 1.5.9)
|
@@ -66,6 +86,10 @@ GEM
|
|
66
86
|
nokogiri (1.9.1)
|
67
87
|
mini_portile2 (~> 2.4.0)
|
68
88
|
pg (0.21.0)
|
89
|
+
pry (0.12.2)
|
90
|
+
coderay (~> 1.1.0)
|
91
|
+
method_source (~> 0.9.0)
|
92
|
+
public_suffix (3.0.3)
|
69
93
|
rack (2.0.6)
|
70
94
|
rack-test (0.6.3)
|
71
95
|
rack (>= 1.0)
|
@@ -105,7 +129,21 @@ GEM
|
|
105
129
|
rspec-mocks (3.8.0)
|
106
130
|
diff-lcs (>= 1.2.0, < 2.0)
|
107
131
|
rspec-support (~> 3.8.0)
|
132
|
+
rspec-rails (3.8.2)
|
133
|
+
actionpack (>= 3.0)
|
134
|
+
activesupport (>= 3.0)
|
135
|
+
railties (>= 3.0)
|
136
|
+
rspec-core (~> 3.8.0)
|
137
|
+
rspec-expectations (~> 3.8.0)
|
138
|
+
rspec-mocks (~> 3.8.0)
|
139
|
+
rspec-support (~> 3.8.0)
|
108
140
|
rspec-support (3.8.0)
|
141
|
+
safe_yaml (1.0.4)
|
142
|
+
simplecov (0.16.1)
|
143
|
+
docile (~> 1.1)
|
144
|
+
json (>= 1.8, < 3)
|
145
|
+
simplecov-html (~> 0.10.0)
|
146
|
+
simplecov-html (0.10.2)
|
109
147
|
sprockets (3.7.2)
|
110
148
|
concurrent-ruby (~> 1.0)
|
111
149
|
rack (> 1, < 3)
|
@@ -117,6 +155,11 @@ GEM
|
|
117
155
|
thread_safe (0.3.6)
|
118
156
|
tzinfo (1.2.5)
|
119
157
|
thread_safe (~> 0.1)
|
158
|
+
url (0.3.2)
|
159
|
+
webmock (3.5.1)
|
160
|
+
addressable (>= 2.3.6)
|
161
|
+
crack (>= 0.3.2)
|
162
|
+
hashdiff
|
120
163
|
websocket-driver (0.6.5)
|
121
164
|
websocket-extensions (>= 0.1.0)
|
122
165
|
websocket-extensions (0.1.3)
|
@@ -129,11 +172,18 @@ DEPENDENCIES
|
|
129
172
|
actionview
|
130
173
|
activerecord
|
131
174
|
bundler (~> 1.15)
|
175
|
+
codecov
|
176
|
+
database_cleaner
|
177
|
+
factory_bot_rails
|
178
|
+
faker
|
132
179
|
pg (~> 0.18)
|
180
|
+
pry
|
133
181
|
rails (~> 5.0.6)
|
134
182
|
rake (~> 10.0)
|
135
183
|
rspec (~> 3.0)
|
184
|
+
rspec-rails
|
136
185
|
simpleadmin!
|
186
|
+
webmock
|
137
187
|
|
138
188
|
RUBY VERSION
|
139
189
|
ruby 2.4.1p111
|
data/README.md
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
-
[![Gem Version](https://badge.fury.io/rb/simpleadmin.svg)](https://rubygems.org/gems/simpleadmin)
|
2
|
-
[![Maintainability](https://api.codeclimate.com/v1/badges/ca0015b11992514879c5/maintainability)](https://codeclimate.com/github/getsimpleadmin/simpleadmin/maintainability)
|
1
|
+
[![Build Status](https://secure.travis-ci.org/getsimpleadmin/simpleadmin.svg?branch=master)](http://travis-ci.org/getsimpleadmin/simpleadmin) [![codecov.io](https://codecov.io/github/getsimpleadmin/simpleadmin/coverage.svg?branch=master)](https://codecov.io/github/getsimpleadmin/simpleadmin?branch=master)[![Gem Version](https://badge.fury.io/rb/simpleadmin.svg)](https://rubygems.org/gems/simpleadmin)[![Maintainability](https://api.codeclimate.com/v1/badges/ca0015b11992514879c5/maintainability)](https://codeclimate.com/github/getsimpleadmin/simpleadmin/maintainability)
|
3
2
|
|
4
|
-
# SimpleAdmin
|
3
|
+
# [SimpleAdmin](http://getsimpleadmin.com)
|
5
4
|
|
6
|
-
SimpleAdmin
|
5
|
+
SimpleAdmin is a service for people with no special skills that enables a simple change of interface and decrease of your costs on a webpage development.
|
6
|
+
|
7
|
+
You do not need to waste your time on development and technical support. The Simple Admin team will help you pay focus on the key thing – your Product.
|
7
8
|
|
8
9
|
This is small API library to connect your application with SimpleAdmin service.
|
9
10
|
|
@@ -5,7 +5,11 @@ module SimpleAdmin
|
|
5
5
|
private
|
6
6
|
|
7
7
|
def verify_key_is_valid!
|
8
|
-
return head(:forbidden)
|
8
|
+
return head(:forbidden) if key_is_invalid?
|
9
|
+
end
|
10
|
+
|
11
|
+
def key_is_invalid?
|
12
|
+
request.headers['SimpleAdmin-Secret-Key'] != ENV['SIMPLE_ADMIN_SECRET_KEY']
|
9
13
|
end
|
10
14
|
end
|
11
15
|
end
|
@@ -1,36 +1,25 @@
|
|
1
1
|
module SimpleAdmin
|
2
2
|
class EntitiesController < BaseController
|
3
|
-
before_action :load_models
|
3
|
+
before_action :load_models!
|
4
|
+
before_action :entity_service
|
4
5
|
|
5
6
|
def index
|
6
|
-
|
7
|
-
|
8
|
-
ApplicationRecord.descendants.each do |model|
|
9
|
-
models << {
|
10
|
-
name: model.name,
|
11
|
-
columns: model.columns.map { |column| { name: column.name, type: column.sql_type.parameterize.underscore } }
|
12
|
-
}
|
13
|
-
end
|
14
|
-
|
15
|
-
render json: {
|
16
|
-
models: models
|
17
|
-
}
|
7
|
+
render json: @entity_service.index_action
|
18
8
|
end
|
19
9
|
|
20
10
|
def show
|
21
11
|
resource_klass = params[:id].constantize
|
22
12
|
|
23
|
-
render json:
|
24
|
-
name: resource_klass.name,
|
25
|
-
column_names: resource_klass.column_names,
|
26
|
-
columns: resource_klass.columns.map { |column| { name: column.name, type: column.sql_type.parameterize.underscore } },
|
27
|
-
reflections: resource_klass.reflections.keys
|
28
|
-
}
|
13
|
+
render json: @entity_service.show_action(resource_klass)
|
29
14
|
end
|
30
15
|
|
31
16
|
private
|
32
17
|
|
33
|
-
def
|
18
|
+
def entity_service
|
19
|
+
@entity_service = EntityService.new
|
20
|
+
end
|
21
|
+
|
22
|
+
def load_models!
|
34
23
|
Rails.application.eager_load!
|
35
24
|
end
|
36
25
|
end
|
@@ -1,9 +1,13 @@
|
|
1
1
|
module SimpleAdmin
|
2
2
|
class EntityFieldTypeActionsController < BaseController
|
3
3
|
def create
|
4
|
-
|
5
|
-
|
6
|
-
render json: field_type.new.run(params[:field_name], params[:model_klass_name])
|
4
|
+
render json: entity_field_type.new.run(params[:field_name], params[:model_klass_name])
|
7
5
|
end
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def entity_field_type
|
10
|
+
params[:entity_field_type_name].constantize
|
11
|
+
end
|
8
12
|
end
|
9
13
|
end
|
@@ -1,31 +1,22 @@
|
|
1
1
|
module SimpleAdmin
|
2
2
|
class ResourcesController < BaseController
|
3
3
|
def index
|
4
|
-
resource_service =
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
render json: {
|
10
|
-
resources: resource_service.resources,
|
11
|
-
total: resource_service.total
|
12
|
-
}
|
4
|
+
resource_service = ResourceService.new(model_klass, model_fields)
|
5
|
+
|
6
|
+
render json: resource_service.index_action(params[:per_page], params[:page], params[:sort],
|
7
|
+
params[:query], params[:model_attributes], params[:reflection_tables], params[:reflection_columns])
|
13
8
|
end
|
14
9
|
|
15
10
|
def show
|
16
|
-
|
17
|
-
|
18
|
-
resource = model_klass.find(params[:id]).attributes.slice(*model_fields)
|
11
|
+
resource = model_klass.find(params[:id])
|
19
12
|
|
20
|
-
render json: resource
|
13
|
+
render json: resource.attributes.slice(*model_fields)
|
21
14
|
end
|
22
15
|
|
23
16
|
def show_by
|
24
|
-
|
17
|
+
resource = model_klass.find_by(params[:column_name] => params[:column_value])
|
25
18
|
|
26
|
-
|
27
|
-
|
28
|
-
render json: resource
|
19
|
+
render json: resource.attributes.slice(*model_fields)
|
29
20
|
end
|
30
21
|
|
31
22
|
def show_total
|
@@ -64,6 +55,10 @@ module SimpleAdmin
|
|
64
55
|
params[:model_klass_name].constantize
|
65
56
|
end
|
66
57
|
|
58
|
+
def model_fields
|
59
|
+
params[:model_fields].map { |model_field| model_field['field_name'] }
|
60
|
+
end
|
61
|
+
|
67
62
|
def resource_params
|
68
63
|
params.require(:resource).permit!
|
69
64
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class EntityService
|
2
|
+
def index_action
|
3
|
+
models = []
|
4
|
+
|
5
|
+
ApplicationRecord.descendants.each do |model|
|
6
|
+
name = model.name
|
7
|
+
columns = model.columns.map do |column|
|
8
|
+
{
|
9
|
+
name: column.name,
|
10
|
+
type: column.sql_type.parameterize.underscore
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
models.push(
|
15
|
+
name: name,
|
16
|
+
columns: columns
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
{
|
21
|
+
models: models
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
def show_action(resource_klass)
|
26
|
+
{
|
27
|
+
name: resource_klass.name,
|
28
|
+
column_names: resource_klass.column_names,
|
29
|
+
columns: resource_klass.columns.map { |column| { name: column.name, type: column.sql_type.parameterize.underscore } },
|
30
|
+
reflections: resource_klass.reflections.keys
|
31
|
+
}
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class ResourceSearchService
|
2
|
+
attr_reader :search_query, :model_klass, :model_attributes
|
3
|
+
|
4
|
+
def initialize(search_query, model_klass, model_attributes)
|
5
|
+
@search_query = search_query
|
6
|
+
|
7
|
+
@model_klass = model_klass
|
8
|
+
@model_attributes = model_attributes
|
9
|
+
end
|
10
|
+
|
11
|
+
def run
|
12
|
+
return [] if model_attributes.empty?
|
13
|
+
|
14
|
+
query = model_attributes.map { |model_attribute| "#{model_attribute} LIKE ?" }.join(' OR ')
|
15
|
+
query_arguments = model_attributes.map { "%#{search_query}%" }
|
16
|
+
|
17
|
+
OpenStruct.new(
|
18
|
+
resources: model_klass.where(query, *query_arguments),
|
19
|
+
total: model_klass.where(query, *query_arguments).count
|
20
|
+
)
|
21
|
+
end
|
22
|
+
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
class
|
1
|
+
class ResourceService
|
2
2
|
attr_reader :model_klass, :model_fields
|
3
3
|
|
4
|
-
def initialize(
|
5
|
-
@model_klass =
|
6
|
-
@model_fields = model_fields
|
4
|
+
def initialize(model_klass, model_fields)
|
5
|
+
@model_klass = model_klass
|
6
|
+
@model_fields = model_fields
|
7
7
|
end
|
8
8
|
|
9
9
|
def index_action(per_page, page, sort, query, model_attributes, reflection_tables, reflection_columns)
|
@@ -20,10 +20,11 @@ class ResourcesService
|
|
20
20
|
end
|
21
21
|
|
22
22
|
if query.present?
|
23
|
-
|
23
|
+
resource_search_service_instance = ResourceSearchService.new(query, model_klass_name, model_attributes)
|
24
|
+
resource_search_service_result = resource_search_service_instance.run
|
24
25
|
|
25
|
-
resources =
|
26
|
-
total =
|
26
|
+
resources = resource_search_service_result.resources
|
27
|
+
total = resource_search_service_result.total
|
27
28
|
end
|
28
29
|
|
29
30
|
resources = resources.offset((per_page * page) - per_page) if page.present?
|
@@ -34,23 +35,9 @@ class ResourcesService
|
|
34
35
|
resources.order(id: :asc)
|
35
36
|
end
|
36
37
|
|
37
|
-
|
38
|
+
{
|
38
39
|
resources: resources.pluck(*model_fields).map { |resource| model_fields.zip(resource).to_h },
|
39
40
|
total: total
|
40
|
-
|
41
|
+
}
|
41
42
|
end
|
42
|
-
|
43
|
-
private
|
44
|
-
|
45
|
-
def search(search_query, model_klass, model_attributes)
|
46
|
-
return [] if model_attributes.empty?
|
47
|
-
|
48
|
-
query = model_attributes.map { |model_attribute| "#{model_attribute} LIKE ?" }.join(' OR ')
|
49
|
-
query_arguments = model_attributes.map { "%#{search_query}%" }
|
50
|
-
|
51
|
-
{
|
52
|
-
resources: model_klass.where(query, *query_arguments),
|
53
|
-
total: model_klass.where(query, *query_arguments).count
|
54
|
-
}
|
55
|
-
end
|
56
43
|
end
|
data/lib/simpleadmin/routes.rb
CHANGED
@@ -1,26 +1,14 @@
|
|
1
1
|
module ActionDispatch::Routing
|
2
2
|
class Mapper
|
3
|
-
# Contain built-in routes
|
4
|
-
#
|
5
|
-
# @example
|
6
|
-
#
|
7
|
-
# # config/routes.rb
|
8
|
-
#
|
9
|
-
# Rails.application.routes.draw do
|
10
|
-
# mount_for_simple_admin
|
11
|
-
# end
|
12
|
-
#
|
13
|
-
# @since 1.0.0
|
14
|
-
|
15
3
|
def mount_simpleadmin
|
16
4
|
namespace :simple_admin do
|
17
|
-
resources :entities,
|
5
|
+
resources :entities, only: %i[index show]
|
18
6
|
resources :entity_field_type_actions, only: :create
|
19
7
|
|
20
|
-
resources :resources
|
21
|
-
|
22
|
-
|
23
|
-
|
8
|
+
resources :resources do
|
9
|
+
get :show_by, on: :collection
|
10
|
+
get :show_total, on: :collection
|
11
|
+
end
|
24
12
|
|
25
13
|
get 'version', to: 'versions#show'
|
26
14
|
end
|
data/lib/simpleadmin/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simpleadmin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitriy Strukov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-01-
|
11
|
+
date: 2019-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -116,7 +116,9 @@ files:
|
|
116
116
|
- app/controllers/simple_admin/resources_controller.rb
|
117
117
|
- app/controllers/simple_admin/versions_controller.rb
|
118
118
|
- app/services/entity_field_types/status_field.rb
|
119
|
-
- app/services/
|
119
|
+
- app/services/entity_service.rb
|
120
|
+
- app/services/resource_search_service.rb
|
121
|
+
- app/services/resource_service.rb
|
120
122
|
- bin/console
|
121
123
|
- bin/setup
|
122
124
|
- lib/simpleadmin.rb
|