administrate-base_controller 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -2
- data/administrate-base_controller.gemspec +1 -2
- data/lib/administrate/base_controller.rb +71 -71
- data/lib/administrate/base_controller/version.rb +1 -1
- metadata +14 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21f4165f46349b93a8dc74edf92e906db55833b900d32ec1a7e19e33e14dcc50
|
4
|
+
data.tar.gz: 36f6d49ffb71ae71268324341600f106db12f1cffc51a845105ca892742cf109
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1dd8d6a755aeef649810168e200a1f44eddb407441044f58e8e57b9c55079df50ca7b5de45292dbf2c7303b2a5b521a8098cb1c3901aa6e1de2d24b0a70ff77
|
7
|
+
data.tar.gz: 2f9c350f7122e5a54a2f5e065ae9ddaa7d2c8f4dd45194c88a134547185d070c71c2c8e49e498f2697a0a9332b0cf5605e62f868cc800ef245db6639fd8c771d
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -34,10 +34,9 @@ Gem::Specification.new do |spec|
|
|
34
34
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
35
35
|
spec.require_paths = ['lib']
|
36
36
|
|
37
|
-
spec.add_dependency 'activesupport'
|
38
37
|
spec.add_development_dependency 'administrate', '>= 0.11.0', '< 1'
|
39
38
|
spec.add_development_dependency 'bundler', '~> 2.0'
|
39
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
40
40
|
spec.add_development_dependency 'rake', '~> 10.0'
|
41
41
|
spec.add_development_dependency 'rails'
|
42
|
-
spec.add_development_dependency 'minitest', '~> 5.0'
|
43
42
|
end
|
@@ -1,96 +1,96 @@
|
|
1
|
-
require 'active_support/concern'
|
2
|
-
require 'active_support/lazy_load_hooks'
|
3
1
|
require 'administrate/base_controller/version'
|
2
|
+
require 'administrate/engine'
|
4
3
|
|
5
4
|
module Administrate
|
5
|
+
class Engine < Rails::Engine
|
6
|
+
config.after_initialize do
|
7
|
+
::Administrate::ApplicationController.class_eval do
|
8
|
+
def index
|
9
|
+
resources = index_resources
|
10
|
+
resources = apply_resource_includes(resources)
|
11
|
+
resources = order.apply(resources)
|
12
|
+
resources = resources.page(params[:page]).per(records_per_page)
|
13
|
+
page = index_page
|
14
|
+
|
15
|
+
render locals: {
|
16
|
+
resources: resources,
|
17
|
+
search_term: search_term,
|
18
|
+
page: page,
|
19
|
+
show_search_bar: show_search_bar?,
|
20
|
+
}
|
21
|
+
end
|
6
22
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
resources = order.apply(resources)
|
13
|
-
resources = resources.page(params[:page]).per(records_per_page)
|
14
|
-
page = index_page
|
15
|
-
|
16
|
-
render locals: {
|
17
|
-
resources: resources,
|
18
|
-
search_term: search_term,
|
19
|
-
page: page,
|
20
|
-
show_search_bar: show_search_bar?,
|
21
|
-
}
|
22
|
-
end
|
23
|
-
|
24
|
-
def new
|
25
|
-
resource = new_resource
|
26
|
-
authorize_resource(resource)
|
27
|
-
render locals: { page: new_page(resource) }
|
28
|
-
end
|
23
|
+
def new
|
24
|
+
resource = new_resource
|
25
|
+
authorize_resource(resource)
|
26
|
+
render locals: { page: new_page(resource) }
|
27
|
+
end
|
29
28
|
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
def edit
|
30
|
+
render locals: { page: edit_page(requested_resource) }
|
31
|
+
end
|
33
32
|
|
34
|
-
|
35
|
-
|
36
|
-
|
33
|
+
def show
|
34
|
+
render locals: { page: show_page }
|
35
|
+
end
|
37
36
|
|
38
|
-
|
37
|
+
protected
|
39
38
|
|
40
|
-
|
41
|
-
|
42
|
-
|
39
|
+
def search_term
|
40
|
+
@search_term ||= params[:search].to_s.strip
|
41
|
+
end
|
43
42
|
|
44
|
-
|
45
|
-
|
46
|
-
|
43
|
+
def index_scoped_resource
|
44
|
+
scoped_resource
|
45
|
+
end
|
47
46
|
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
def index_resources
|
48
|
+
Administrate::Search.new(index_scoped_resource, dashboard_class, search_term).run
|
49
|
+
end
|
51
50
|
|
52
|
-
|
53
|
-
|
54
|
-
|
51
|
+
def index_page
|
52
|
+
Administrate::Page::Collection.new(dashboard, order: order)
|
53
|
+
end
|
55
54
|
|
56
|
-
|
57
|
-
|
58
|
-
|
55
|
+
def show_page
|
56
|
+
Administrate::Page::Show.new(dashboard, requested_resource)
|
57
|
+
end
|
59
58
|
|
60
|
-
|
61
|
-
|
62
|
-
|
59
|
+
def new_page(resource)
|
60
|
+
Administrate::Page::Form.new(dashboard, resource)
|
61
|
+
end
|
63
62
|
|
64
|
-
|
65
|
-
|
66
|
-
|
63
|
+
def edit_page(resource)
|
64
|
+
new_page(resource)
|
65
|
+
end
|
67
66
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
67
|
+
def authorize_resource(resource)
|
68
|
+
return if show_action?(action_name.to_sym, resource)
|
69
|
+
raise "That's not a valid action."
|
70
|
+
end
|
72
71
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
72
|
+
def resource_params
|
73
|
+
permitted = params.require(resource_class.model_name.param_key)
|
74
|
+
.permit(dashboard.permitted_attributes)
|
75
|
+
.to_h
|
77
76
|
|
78
|
-
|
79
|
-
|
77
|
+
permitted.each_with_object(permitted) do |(k, v), result|
|
78
|
+
result[k] = read_param(k, v)
|
79
|
+
end
|
80
80
|
end
|
81
|
-
end
|
82
81
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
82
|
+
def read_param(_, data)
|
83
|
+
if data.is_a?(ActionController::Parameters) && data[:type]
|
84
|
+
return read_param_value(data)
|
85
|
+
end
|
87
86
|
|
88
|
-
|
89
|
-
|
87
|
+
data
|
88
|
+
end
|
90
89
|
|
91
|
-
|
90
|
+
private
|
92
91
|
|
93
|
-
|
92
|
+
attr_writer :search_term
|
93
|
+
end
|
94
94
|
end
|
95
95
|
end
|
96
96
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: administrate-base_controller
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Derk-Jan Karrenbeld
|
@@ -10,20 +10,6 @@ bindir: exe
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2019-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: activesupport
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: administrate
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -59,47 +45,47 @@ dependencies:
|
|
59
45
|
- !ruby/object:Gem::Version
|
60
46
|
version: '2.0'
|
61
47
|
- !ruby/object:Gem::Dependency
|
62
|
-
name:
|
48
|
+
name: minitest
|
63
49
|
requirement: !ruby/object:Gem::Requirement
|
64
50
|
requirements:
|
65
51
|
- - "~>"
|
66
52
|
- !ruby/object:Gem::Version
|
67
|
-
version: '
|
53
|
+
version: '5.0'
|
68
54
|
type: :development
|
69
55
|
prerelease: false
|
70
56
|
version_requirements: !ruby/object:Gem::Requirement
|
71
57
|
requirements:
|
72
58
|
- - "~>"
|
73
59
|
- !ruby/object:Gem::Version
|
74
|
-
version: '
|
60
|
+
version: '5.0'
|
75
61
|
- !ruby/object:Gem::Dependency
|
76
|
-
name:
|
62
|
+
name: rake
|
77
63
|
requirement: !ruby/object:Gem::Requirement
|
78
64
|
requirements:
|
79
|
-
- - "
|
65
|
+
- - "~>"
|
80
66
|
- !ruby/object:Gem::Version
|
81
|
-
version: '0'
|
67
|
+
version: '10.0'
|
82
68
|
type: :development
|
83
69
|
prerelease: false
|
84
70
|
version_requirements: !ruby/object:Gem::Requirement
|
85
71
|
requirements:
|
86
|
-
- - "
|
72
|
+
- - "~>"
|
87
73
|
- !ruby/object:Gem::Version
|
88
|
-
version: '0'
|
74
|
+
version: '10.0'
|
89
75
|
- !ruby/object:Gem::Dependency
|
90
|
-
name:
|
76
|
+
name: rails
|
91
77
|
requirement: !ruby/object:Gem::Requirement
|
92
78
|
requirements:
|
93
|
-
- - "
|
79
|
+
- - ">="
|
94
80
|
- !ruby/object:Gem::Version
|
95
|
-
version: '
|
81
|
+
version: '0'
|
96
82
|
type: :development
|
97
83
|
prerelease: false
|
98
84
|
version_requirements: !ruby/object:Gem::Requirement
|
99
85
|
requirements:
|
100
|
-
- - "
|
86
|
+
- - ">="
|
101
87
|
- !ruby/object:Gem::Version
|
102
|
-
version: '
|
88
|
+
version: '0'
|
103
89
|
description:
|
104
90
|
email:
|
105
91
|
- derk-jan@xpbytes.com
|