simpleadmin 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.gitignore +0 -3
- data/.rspec +0 -2
- data/.rubocop.yml +10 -58
- data/.travis.yml +1 -11
- data/Gemfile +3 -17
- data/Gemfile.lock +14 -150
- data/LICENSE.txt +21 -0
- data/README.md +35 -19
- data/Rakefile +2 -4
- data/bin/console +4 -3
- data/lib/simpleadmin.rb +104 -2
- data/lib/simpleadmin/adapters/base.rb +50 -0
- data/lib/simpleadmin/adapters/postgres.rb +132 -0
- data/lib/simpleadmin/config.rb +83 -0
- data/lib/simpleadmin/database_connector.rb +35 -0
- data/lib/simpleadmin/decorators/fields/base.rb +34 -0
- data/lib/simpleadmin/decorators/fields/image.rb +19 -0
- data/lib/simpleadmin/decorators/fields_decorator.rb +44 -0
- data/lib/simpleadmin/version.rb +3 -1
- data/simpleadmin.gemspec +18 -14
- metadata +29 -35
- data/CODE_OF_CONDUCT.md +0 -74
- data/app/controllers/simple_admin/base_controller.rb +0 -15
- data/app/controllers/simple_admin/entities_controller.rb +0 -26
- data/app/controllers/simple_admin/entity_field_type_actions_controller.rb +0 -13
- data/app/controllers/simple_admin/resources_controller.rb +0 -80
- data/app/controllers/simple_admin/versions_controller.rb +0 -9
- data/app/services/entity_field_types/status_field.rb +0 -8
- data/app/services/entity_service.rb +0 -33
- data/app/services/resource_search_service.rb +0 -22
- data/app/services/resource_service.rb +0 -43
- data/lib/rails/application.rb +0 -13
- data/lib/simpleadmin/application.rb +0 -11
- data/lib/simpleadmin/engine.rb +0 -6
- data/lib/simpleadmin/routes.rb +0 -17
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Simpleadmin
|
4
|
+
module Decorators
|
5
|
+
module Fields
|
6
|
+
class Image < Base
|
7
|
+
def call
|
8
|
+
record = model.find(resource[:id])
|
9
|
+
|
10
|
+
if record.public_send(table_field_name).respond_to?(:url)
|
11
|
+
record.public_send(table_field_name).url
|
12
|
+
else
|
13
|
+
raise TypeError, "The column #{table_field_name} doesn't support image format"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'simpleadmin/decorators/fields/base'
|
4
|
+
require 'simpleadmin/decorators/fields/image'
|
5
|
+
|
6
|
+
module Simpleadmin
|
7
|
+
module Decorators
|
8
|
+
module FieldDecorator
|
9
|
+
FIELDS_MAPPER = {
|
10
|
+
'image' => Fields::Image
|
11
|
+
}.freeze
|
12
|
+
|
13
|
+
def call(resources, table_name, table_fields)
|
14
|
+
resources.map do |resource|
|
15
|
+
resource_attributes = {}
|
16
|
+
|
17
|
+
table_fields.each do |table_field|
|
18
|
+
table_field_name, table_field_type = *table_field.values
|
19
|
+
|
20
|
+
if table_field_match?(table_field_type)
|
21
|
+
field_class = FIELDS_MAPPER[table_field_type]
|
22
|
+
|
23
|
+
resource_attributes[table_field_name] = field_class.new(table_name, table_field_name, resource).call
|
24
|
+
else
|
25
|
+
resource_attributes[table_field_name] = resource[table_field_name.to_sym]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
resource_attributes
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
module_function :call
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def table_field_match?(table_field_type)
|
38
|
+
FIELDS_MAPPER.key?(table_field_type)
|
39
|
+
end
|
40
|
+
|
41
|
+
module_function :table_field_match?
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/simpleadmin/version.rb
CHANGED
data/simpleadmin.gemspec
CHANGED
@@ -1,30 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
lib = File.expand_path('lib', __dir__)
|
2
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
5
|
require 'simpleadmin/version'
|
4
6
|
|
5
7
|
Gem::Specification.new do |spec|
|
6
|
-
spec.name
|
7
|
-
spec.version
|
8
|
-
spec.authors
|
9
|
-
spec.email
|
8
|
+
spec.name = 'simpleadmin'
|
9
|
+
spec.version = Simpleadmin::VERSION
|
10
|
+
spec.authors = ['Dmitriy Strukov']
|
11
|
+
spec.email = ['dmitriy.strukov@outlook.com']
|
12
|
+
|
13
|
+
spec.homepage = 'https://getsimpleadmin.com'
|
14
|
+
spec.summary = 'SimpleAdmin - Dashboard for modern applications without wasting time'
|
15
|
+
spec.description = 'SimpleAdmin - Dashboard for modern applications without wasting time'
|
10
16
|
|
11
|
-
spec.
|
12
|
-
spec.description = 'simple-admin'
|
13
|
-
spec.homepage = 'https://github.com/evil-raccoon/simple_admin'
|
17
|
+
spec.license = 'MIT'
|
14
18
|
|
15
|
-
spec.files
|
16
|
-
f.match(%r{^(test|spec|features)/})
|
19
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
21
|
end
|
18
22
|
|
19
23
|
spec.bindir = 'exe'
|
20
24
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
25
|
spec.require_paths = ['lib']
|
22
26
|
|
23
|
-
spec.add_development_dependency 'bundler', '~> 1.
|
27
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
24
28
|
spec.add_development_dependency 'rake', '~> 10.0'
|
25
|
-
spec.add_development_dependency 'rspec'
|
29
|
+
spec.add_development_dependency 'rspec'
|
26
30
|
|
27
|
-
spec.
|
28
|
-
spec.
|
29
|
-
spec.
|
31
|
+
spec.add_dependency 'bcrypt'
|
32
|
+
spec.add_dependency 'rack-app'
|
33
|
+
spec.add_dependency 'sequel'
|
30
34
|
end
|
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.5.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-
|
11
|
+
date: 2019-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.16'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
26
|
+
version: '1.16'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -42,24 +42,24 @@ dependencies:
|
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: bcrypt
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
|
-
type: :
|
62
|
+
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
@@ -67,13 +67,13 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: rack-app
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
|
-
type: :
|
76
|
+
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
@@ -81,22 +81,22 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: sequel
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
|
-
type: :
|
90
|
+
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
-
description:
|
97
|
+
description: SimpleAdmin - Dashboard for modern applications without wasting time
|
98
98
|
email:
|
99
|
-
-
|
99
|
+
- dmitriy.strukov@outlook.com
|
100
100
|
executables: []
|
101
101
|
extensions: []
|
102
102
|
extra_rdoc_files: []
|
@@ -105,31 +105,26 @@ files:
|
|
105
105
|
- ".rspec"
|
106
106
|
- ".rubocop.yml"
|
107
107
|
- ".travis.yml"
|
108
|
-
- CODE_OF_CONDUCT.md
|
109
108
|
- Gemfile
|
110
109
|
- Gemfile.lock
|
110
|
+
- LICENSE.txt
|
111
111
|
- README.md
|
112
112
|
- Rakefile
|
113
|
-
- app/controllers/simple_admin/base_controller.rb
|
114
|
-
- app/controllers/simple_admin/entities_controller.rb
|
115
|
-
- app/controllers/simple_admin/entity_field_type_actions_controller.rb
|
116
|
-
- app/controllers/simple_admin/resources_controller.rb
|
117
|
-
- app/controllers/simple_admin/versions_controller.rb
|
118
|
-
- app/services/entity_field_types/status_field.rb
|
119
|
-
- app/services/entity_service.rb
|
120
|
-
- app/services/resource_search_service.rb
|
121
|
-
- app/services/resource_service.rb
|
122
113
|
- bin/console
|
123
114
|
- bin/setup
|
124
|
-
- lib/rails/application.rb
|
125
115
|
- lib/simpleadmin.rb
|
126
|
-
- lib/simpleadmin/
|
127
|
-
- lib/simpleadmin/
|
128
|
-
- lib/simpleadmin/
|
116
|
+
- lib/simpleadmin/adapters/base.rb
|
117
|
+
- lib/simpleadmin/adapters/postgres.rb
|
118
|
+
- lib/simpleadmin/config.rb
|
119
|
+
- lib/simpleadmin/database_connector.rb
|
120
|
+
- lib/simpleadmin/decorators/fields/base.rb
|
121
|
+
- lib/simpleadmin/decorators/fields/image.rb
|
122
|
+
- lib/simpleadmin/decorators/fields_decorator.rb
|
129
123
|
- lib/simpleadmin/version.rb
|
130
124
|
- simpleadmin.gemspec
|
131
|
-
homepage: https://
|
132
|
-
licenses:
|
125
|
+
homepage: https://getsimpleadmin.com
|
126
|
+
licenses:
|
127
|
+
- MIT
|
133
128
|
metadata: {}
|
134
129
|
post_install_message:
|
135
130
|
rdoc_options: []
|
@@ -146,9 +141,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
146
141
|
- !ruby/object:Gem::Version
|
147
142
|
version: '0'
|
148
143
|
requirements: []
|
149
|
-
|
150
|
-
rubygems_version: 2.6.11
|
144
|
+
rubygems_version: 3.0.1
|
151
145
|
signing_key:
|
152
146
|
specification_version: 4
|
153
|
-
summary:
|
147
|
+
summary: SimpleAdmin - Dashboard for modern applications without wasting time
|
154
148
|
test_files: []
|
data/CODE_OF_CONDUCT.md
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
# Contributor Covenant Code of Conduct
|
2
|
-
|
3
|
-
## Our Pledge
|
4
|
-
|
5
|
-
In the interest of fostering an open and welcoming environment, we as
|
6
|
-
contributors and maintainers pledge to making participation in our project and
|
7
|
-
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
-
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
-
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
-
orientation.
|
11
|
-
|
12
|
-
## Our Standards
|
13
|
-
|
14
|
-
Examples of behavior that contributes to creating a positive environment
|
15
|
-
include:
|
16
|
-
|
17
|
-
* Using welcoming and inclusive language
|
18
|
-
* Being respectful of differing viewpoints and experiences
|
19
|
-
* Gracefully accepting constructive criticism
|
20
|
-
* Focusing on what is best for the community
|
21
|
-
* Showing empathy towards other community members
|
22
|
-
|
23
|
-
Examples of unacceptable behavior by participants include:
|
24
|
-
|
25
|
-
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
-
advances
|
27
|
-
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
-
* Public or private harassment
|
29
|
-
* Publishing others' private information, such as a physical or electronic
|
30
|
-
address, without explicit permission
|
31
|
-
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
-
professional setting
|
33
|
-
|
34
|
-
## Our Responsibilities
|
35
|
-
|
36
|
-
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
-
behavior and are expected to take appropriate and fair corrective action in
|
38
|
-
response to any instances of unacceptable behavior.
|
39
|
-
|
40
|
-
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
-
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
-
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
-
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
-
threatening, offensive, or harmful.
|
45
|
-
|
46
|
-
## Scope
|
47
|
-
|
48
|
-
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
-
when an individual is representing the project or its community. Examples of
|
50
|
-
representing a project or community include using an official project e-mail
|
51
|
-
address, posting via an official social media account, or acting as an appointed
|
52
|
-
representative at an online or offline event. Representation of a project may be
|
53
|
-
further defined and clarified by project maintainers.
|
54
|
-
|
55
|
-
## Enforcement
|
56
|
-
|
57
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
-
reported by contacting the project team at dmitiry_strukov2011@mail.ru. All
|
59
|
-
complaints will be reviewed and investigated and will result in a response that
|
60
|
-
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
-
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
-
Further details of specific enforcement policies may be posted separately.
|
63
|
-
|
64
|
-
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
-
faith may face temporary or permanent repercussions as determined by other
|
66
|
-
members of the project's leadership.
|
67
|
-
|
68
|
-
## Attribution
|
69
|
-
|
70
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
-
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
-
|
73
|
-
[homepage]: http://contributor-covenant.org
|
74
|
-
[version]: http://contributor-covenant.org/version/1/4/
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module SimpleAdmin
|
2
|
-
class BaseController < ActionController::API
|
3
|
-
before_action :verify_key_is_valid!
|
4
|
-
|
5
|
-
private
|
6
|
-
|
7
|
-
def verify_key_is_valid!
|
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']
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
module SimpleAdmin
|
2
|
-
class EntitiesController < BaseController
|
3
|
-
before_action :load_models!
|
4
|
-
before_action :entity_service
|
5
|
-
|
6
|
-
def index
|
7
|
-
render json: @entity_service.index_action
|
8
|
-
end
|
9
|
-
|
10
|
-
def show
|
11
|
-
resource_klass = params[:id].constantize
|
12
|
-
|
13
|
-
render json: @entity_service.show_action(resource_klass)
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
def entity_service
|
19
|
-
@entity_service = EntityService.new
|
20
|
-
end
|
21
|
-
|
22
|
-
def load_models!
|
23
|
-
Rails.application.eager_load!
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
module SimpleAdmin
|
2
|
-
class EntityFieldTypeActionsController < BaseController
|
3
|
-
def create
|
4
|
-
render json: entity_field_type.new.run(params[:field_name], params[:model_klass_name])
|
5
|
-
end
|
6
|
-
|
7
|
-
private
|
8
|
-
|
9
|
-
def entity_field_type
|
10
|
-
params[:entity_field_type_name].constantize
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
@@ -1,80 +0,0 @@
|
|
1
|
-
module SimpleAdmin
|
2
|
-
class ResourcesController < BaseController
|
3
|
-
before_action :load_models!
|
4
|
-
|
5
|
-
def index
|
6
|
-
resource_service = ResourceService.new(model_klass, model_fields)
|
7
|
-
|
8
|
-
render json: resource_service.index_action(params[:per_page], params[:page], params[:sort],
|
9
|
-
params[:query], params[:model_attributes], params[:reflection_tables], params[:reflection_columns])
|
10
|
-
end
|
11
|
-
|
12
|
-
def show
|
13
|
-
resource = model_klass.find(params[:id])
|
14
|
-
|
15
|
-
render json: resource.attributes.slice(*model_fields)
|
16
|
-
end
|
17
|
-
|
18
|
-
def show_by
|
19
|
-
resource = model_klass.find_by(params[:column_name] => params[:column_value])
|
20
|
-
|
21
|
-
render json: resource.attributes.slice(*model_fields)
|
22
|
-
end
|
23
|
-
|
24
|
-
def show_total
|
25
|
-
render json: model_klass.count
|
26
|
-
end
|
27
|
-
|
28
|
-
def create
|
29
|
-
resource = model_klass.new(resource_params)
|
30
|
-
|
31
|
-
if resource.save
|
32
|
-
render json: resource
|
33
|
-
else
|
34
|
-
render json: resource.errors
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def update
|
39
|
-
resource = model_klass.find(params[:id])
|
40
|
-
|
41
|
-
if resource.update(resource_params)
|
42
|
-
render json: resource
|
43
|
-
else
|
44
|
-
render json: resource.errors
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def destroy
|
49
|
-
resource = model_klass.find(params[:id])
|
50
|
-
|
51
|
-
resource.destroy
|
52
|
-
end
|
53
|
-
|
54
|
-
private
|
55
|
-
|
56
|
-
def load_models!
|
57
|
-
Rails.application.load_models!
|
58
|
-
end
|
59
|
-
|
60
|
-
def model_klass
|
61
|
-
model = params[:model_klass_name].safe_constantize
|
62
|
-
|
63
|
-
if ApplicationRecord.descendants.include?(model)
|
64
|
-
model
|
65
|
-
elsif model.nil?
|
66
|
-
raise ArgumentError
|
67
|
-
else
|
68
|
-
raise SecurityError
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def model_fields
|
73
|
-
params[:model_fields].map { |model_field| model_field['field_name'] }
|
74
|
-
end
|
75
|
-
|
76
|
-
def resource_params
|
77
|
-
params.require(:resource).permit!
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|