madmin 0.1.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +50 -63
- data/Rakefile +5 -6
- data/app/assets/config/manifest.js +2 -0
- data/app/assets/stylesheets/actiontext.scss +36 -0
- data/app/assets/stylesheets/{madmin/application.css → application.css} +2 -9
- data/app/controllers/madmin/base_controller.rb +5 -9
- data/app/controllers/madmin/dashboard_controller.rb +1 -3
- data/app/controllers/madmin/resource_controller.rb +81 -0
- data/app/helpers/madmin/application_helper.rb +10 -8
- data/app/views/layouts/madmin/application.html.erb +23 -25
- data/app/views/madmin/application/_form.html.erb +25 -0
- data/app/views/madmin/application/_javascript.html.erb +24 -0
- data/app/views/madmin/application/_navigation.html.erb +6 -0
- data/app/views/madmin/application/edit.html.erb +3 -0
- data/app/views/madmin/application/index.html.erb +47 -0
- data/app/views/madmin/application/new.html.erb +3 -0
- data/app/views/madmin/application/show.html.erb +24 -0
- data/app/views/madmin/dashboard/show.html.erb +1 -0
- data/app/views/madmin/fields/attachment/_form.html.erb +2 -0
- data/app/views/madmin/fields/attachment/_index.html.erb +3 -0
- data/app/views/madmin/fields/attachment/_show.html.erb +3 -0
- data/app/views/madmin/fields/attachments/_form.html.erb +2 -0
- data/app/views/madmin/fields/attachments/_index.html.erb +1 -0
- data/app/views/madmin/fields/attachments/_show.html.erb +7 -0
- data/app/views/madmin/fields/belongs_to/_form.html.erb +2 -14
- data/app/views/madmin/fields/belongs_to/_index.html.erb +3 -7
- data/app/views/madmin/fields/belongs_to/_show.html.erb +3 -8
- data/app/views/madmin/fields/boolean/_form.html.erb +2 -0
- data/app/views/madmin/fields/boolean/_index.html.erb +1 -0
- data/app/views/madmin/fields/boolean/_show.html.erb +1 -0
- data/app/views/madmin/fields/date/_form.html.erb +2 -0
- data/app/views/madmin/fields/date/_index.html.erb +1 -0
- data/app/views/madmin/fields/date/_show.html.erb +1 -0
- data/app/views/madmin/fields/date_time/_form.html.erb +2 -0
- data/app/views/madmin/fields/date_time/_index.html.erb +1 -0
- data/app/views/madmin/fields/date_time/_show.html.erb +1 -0
- data/app/views/madmin/fields/decimal/_form.html.erb +2 -0
- data/app/views/madmin/fields/decimal/_index.html.erb +1 -0
- data/app/views/madmin/fields/decimal/_show.html.erb +1 -0
- data/app/views/madmin/fields/enum/_form.html.erb +2 -0
- data/app/views/madmin/fields/enum/_index.html.erb +1 -0
- data/app/views/madmin/fields/enum/_show.html.erb +1 -0
- data/app/views/madmin/fields/float/_form.html.erb +2 -0
- data/app/views/madmin/fields/float/_index.html.erb +1 -0
- data/app/views/madmin/fields/float/_show.html.erb +1 -0
- data/app/views/madmin/fields/has_many/_form.html.erb +2 -0
- data/app/views/madmin/fields/has_many/_index.html.erb +1 -0
- data/app/views/madmin/fields/has_many/_show.html.erb +4 -14
- data/app/views/madmin/fields/has_one/_form.html.erb +3 -0
- data/app/views/madmin/fields/has_one/_index.html.erb +3 -0
- data/app/views/madmin/fields/has_one/_show.html.erb +3 -12
- data/app/views/madmin/fields/integer/_form.html.erb +2 -0
- data/app/views/madmin/fields/integer/_index.html.erb +1 -0
- data/app/views/madmin/fields/integer/_show.html.erb +1 -0
- data/app/views/madmin/fields/json/_form.html.erb +2 -0
- data/app/views/madmin/fields/json/_index.html.erb +1 -0
- data/app/views/madmin/fields/json/_show.html.erb +1 -0
- data/app/views/madmin/fields/polymorphic/_form.html.erb +5 -32
- data/app/views/madmin/fields/polymorphic/_index.html.erb +3 -1
- data/app/views/madmin/fields/polymorphic/_show.html.erb +3 -14
- data/app/views/madmin/fields/rich_text/_form.html.erb +4 -0
- data/app/views/madmin/fields/rich_text/_index.html.erb +1 -0
- data/app/views/madmin/fields/rich_text/_show.html.erb +3 -0
- data/app/views/madmin/fields/string/_form.html.erb +2 -0
- data/app/views/madmin/fields/string/_index.html.erb +1 -0
- data/app/views/madmin/fields/string/_show.html.erb +1 -0
- data/app/views/madmin/fields/text/_form.html.erb +2 -4
- data/app/views/madmin/fields/text/_index.html.erb +1 -1
- data/app/views/madmin/fields/text/_show.html.erb +1 -8
- data/app/views/madmin/fields/time/_form.html.erb +2 -0
- data/app/views/madmin/fields/time/_index.html.erb +1 -0
- data/app/views/madmin/fields/time/_show.html.erb +1 -0
- data/lib/generators/madmin/install/install_generator.rb +31 -12
- data/lib/generators/madmin/install/templates/controller.rb.tt +22 -0
- data/lib/generators/madmin/resource/resource_generator.rb +83 -47
- data/lib/generators/madmin/resource/templates/controller.rb.tt +4 -0
- data/lib/generators/madmin/resource/templates/resource.rb.tt +11 -0
- data/lib/generators/madmin/views/edit_generator.rb +16 -0
- data/lib/generators/madmin/views/form_generator.rb +15 -0
- data/lib/generators/madmin/views/index_generator.rb +15 -0
- data/lib/generators/madmin/views/layout_generator.rb +21 -0
- data/lib/generators/madmin/views/navigation_generator.rb +15 -0
- data/lib/generators/madmin/views/new_generator.rb +16 -0
- data/lib/generators/madmin/views/show_generator.rb +15 -0
- data/lib/generators/madmin/views/views_generator.rb +8 -8
- data/lib/madmin.rb +34 -23
- data/lib/madmin/engine.rb +5 -2
- data/lib/madmin/field.rb +22 -46
- data/lib/madmin/fields/attachment.rb +6 -0
- data/lib/madmin/fields/attachments.rb +9 -0
- data/lib/madmin/fields/belongs_to.rb +18 -0
- data/lib/madmin/fields/boolean.rb +6 -0
- data/lib/madmin/fields/date.rb +6 -0
- data/lib/madmin/fields/date_time.rb +6 -0
- data/lib/madmin/fields/decimal.rb +6 -0
- data/lib/madmin/fields/enum.rb +9 -0
- data/lib/madmin/fields/float.rb +6 -0
- data/lib/madmin/fields/has_many.rb +18 -0
- data/lib/madmin/fields/has_one.rb +6 -0
- data/lib/madmin/fields/integer.rb +6 -0
- data/lib/madmin/fields/json.rb +6 -0
- data/lib/madmin/fields/polymorphic.rb +17 -0
- data/lib/madmin/fields/rich_text.rb +6 -0
- data/lib/madmin/fields/string.rb +6 -0
- data/lib/madmin/fields/text.rb +6 -0
- data/lib/madmin/fields/time.rb +6 -0
- data/lib/madmin/generator_helpers.rb +24 -0
- data/lib/madmin/namespace.rb +35 -0
- data/lib/madmin/resource.rb +176 -0
- data/lib/madmin/version.rb +1 -1
- data/lib/madmin/view_generator.rb +42 -0
- data/lib/tasks/madmin_tasks.rake +7 -0
- metadata +106 -111
- data/app/assets/config/madmin_manifest.js +0 -2
- data/app/assets/javascripts/madmin/application.js +0 -15
- data/app/assets/javascripts/madmin/dashboard.js +0 -2
- data/app/assets/javascripts/madmin/resources.js +0 -36
- data/app/assets/stylesheets/madmin/dashboard.css +0 -4
- data/app/assets/stylesheets/madmin/resources.css +0 -4
- data/app/controllers/madmin/application_controller.rb +0 -16
- data/app/controllers/madmin/resources_controller.rb +0 -97
- data/app/decorators/madmin/resource_decorator.rb +0 -16
- data/app/helpers/madmin/fields/polymorphic_helper.rb +0 -25
- data/app/jobs/madmin/application_job.rb +0 -4
- data/app/mailers/madmin/application_mailer.rb +0 -6
- data/app/models/madmin/application_record.rb +0 -5
- data/app/views/application/_navigation.html.erb +0 -17
- data/app/views/madmin/dashboard/index.html.erb +0 -6
- data/app/views/madmin/fields/check_box/_form.html.erb +0 -4
- data/app/views/madmin/fields/check_box/_index.html.erb +0 -1
- data/app/views/madmin/fields/check_box/_show.html.erb +0 -8
- data/app/views/madmin/fields/email/_form.html.erb +0 -4
- data/app/views/madmin/fields/email/_index.html.erb +0 -1
- data/app/views/madmin/fields/email/_show.html.erb +0 -8
- data/app/views/madmin/fields/number/_form.html.erb +0 -4
- data/app/views/madmin/fields/number/_index.html.erb +0 -1
- data/app/views/madmin/fields/number/_show.html.erb +0 -8
- data/app/views/madmin/fields/password/_form.html.erb +0 -4
- data/app/views/madmin/fields/password/_index.html.erb +0 -1
- data/app/views/madmin/fields/password/_show.html.erb +0 -8
- data/app/views/madmin/fields/select/_form.html.erb +0 -4
- data/app/views/madmin/fields/select/_index.html.erb +0 -1
- data/app/views/madmin/fields/select/_show.html.erb +0 -8
- data/app/views/madmin/fields/text_area/_form.html.erb +0 -4
- data/app/views/madmin/fields/text_area/_index.html.erb +0 -1
- data/app/views/madmin/fields/text_area/_show.html.erb +0 -8
- data/app/views/madmin/resources/_form.html.erb +0 -15
- data/app/views/madmin/resources/_scopes.html.erb +0 -10
- data/app/views/madmin/resources/edit.html.erb +0 -2
- data/app/views/madmin/resources/index.html.erb +0 -13
- data/app/views/madmin/resources/index/_content.html.erb +0 -33
- data/app/views/madmin/resources/new.html.erb +0 -2
- data/app/views/madmin/resources/show.html.erb +0 -10
- data/config/routes.rb +0 -11
- data/lib/generators/madmin/controller/USAGE +0 -8
- data/lib/generators/madmin/controller/controller_generator.rb +0 -10
- data/lib/generators/madmin/page/USAGE +0 -8
- data/lib/generators/madmin/page/page_generator.rb +0 -20
- data/lib/generators/madmin/page/templates/template.html.erb +0 -2
- data/lib/generators/madmin/page/templates/template.rb.erb +0 -10
- data/lib/generators/madmin/resource/templates/resource.rb.erb +0 -11
- data/lib/madmin/field/associatable.rb +0 -58
- data/lib/madmin/field/belongs_to.rb +0 -9
- data/lib/madmin/field/check_box.rb +0 -8
- data/lib/madmin/field/date_time.rb +0 -8
- data/lib/madmin/field/email.rb +0 -8
- data/lib/madmin/field/has_many.rb +0 -9
- data/lib/madmin/field/has_one.rb +0 -9
- data/lib/madmin/field/number.rb +0 -8
- data/lib/madmin/field/password.rb +0 -8
- data/lib/madmin/field/polymorphic.rb +0 -57
- data/lib/madmin/field/select.rb +0 -13
- data/lib/madmin/field/text.rb +0 -8
- data/lib/madmin/field/text_area.rb +0 -8
- data/lib/madmin/resourceable.rb +0 -72
- data/lib/madmin/resourceable/class_methods.rb +0 -152
- data/lib/madmin/resources.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f149452559626564a6b3888b89ddeaf7fb2bf1c3fedbbc4ac4ba3dc2a1df4e58
|
4
|
+
data.tar.gz: 8536e397b8d032d704b7e10c938af1ee1eda4911d9c6933ecd9c11f68fbac8f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6a4a123086ee55711728e9f2b1bff5ca90d28c7238690d5f51e9b834f1f5eb15170b7e8e3b1aac7a79e08d4b55ee2500dc11f16d4f62c4a31cc4d0d5ab0b6ba
|
7
|
+
data.tar.gz: 49a20396c04c22fbe8001d53ed4cc567b441171943a090cd888b98e94cbf11b31ad5ec89fc67dd9cae98af03282adf8bdacec159075c73605ac743c994338e51
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,102 +1,89 @@
|
|
1
1
|
# Madmin
|
2
2
|
|
3
|
-
|
3
|
+
### 🛠 A robust Admin Interface for Ruby on Rails apps
|
4
4
|
|
5
|
-
|
5
|
+
[![Build Status](https://github.com/excid3/madmin/workflows/Tests/badge.svg)](https://github.com/excid3/madmin/actions) [![Gem Version](https://badge.fury.io/rb/madmin.svg)](https://badge.fury.io/rb/madmin)
|
6
6
|
|
7
|
-
|
7
|
+
Why another Ruby on Rails admin? We wanted an admin that was:
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
* Familiar and customizable like Rails scaffolds (less DSL)
|
10
|
+
* Supports all the Rails features out of the box (ActionText, ActionMailbox, etc)
|
11
|
+
* Stimulus / Turbolinks / Hotwire ready
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
```
|
16
|
-
|
17
|
-
And then execute:
|
13
|
+
## Installation
|
14
|
+
Add `madmin` to your application's Gemfile:
|
18
15
|
|
19
16
|
```bash
|
20
|
-
|
17
|
+
bundle add madmin
|
21
18
|
```
|
22
19
|
|
23
|
-
|
20
|
+
Then run the madmin generator:
|
24
21
|
|
25
22
|
```bash
|
26
|
-
|
23
|
+
rails g madmin:install
|
27
24
|
```
|
28
25
|
|
29
|
-
|
30
|
-
your app that inherit from `ActiveRecord::Base` by running:
|
26
|
+
This will install Madmin and generate resources for each of the models it finds.
|
31
27
|
|
32
|
-
|
33
|
-
|
34
|
-
|
28
|
+
## Resources
|
29
|
+
|
30
|
+
Madmin uses `Resource` classes to add models to the admin area.
|
35
31
|
|
36
|
-
|
32
|
+
### Generate a Resource
|
37
33
|
|
38
|
-
To generate
|
39
|
-
can run the following command and pass in the model name
|
34
|
+
To generate a resource for a model, you can run:
|
40
35
|
|
41
36
|
```bash
|
42
|
-
rails
|
37
|
+
rails g madmin:resource ActionText::RichText
|
43
38
|
```
|
44
39
|
|
45
|
-
##
|
40
|
+
## Configuring Views
|
46
41
|
|
47
|
-
|
42
|
+
The views packaged within the gem are a great starting point, but inevitably people will need to be able to customize those views.
|
48
43
|
|
49
|
-
|
44
|
+
You can use the included generator to create the appropriate view files, which can then be customized.
|
50
45
|
|
46
|
+
For example, running the following will copy over all of the views into your application that will be used for every resource:
|
51
47
|
```bash
|
52
|
-
rails generate madmin:
|
48
|
+
rails generate madmin:views
|
53
49
|
```
|
54
50
|
|
55
|
-
|
51
|
+
The view files that are copied over in this case includes all of the standard Rails action views (index, new, edit, show, and _form), as well as:
|
52
|
+
* `application.html.erb` (layout file)
|
53
|
+
* `_javascript.html.erb` (default JavaScript setup)
|
54
|
+
* `_navigation.html.erb` (renders the navigation/sidebar menu)
|
56
55
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
private
|
56
|
+
As with the other views, you can specifically run the views generator for only the navigation or application layout views:
|
57
|
+
```bash
|
58
|
+
rails g madmin:views:navigation
|
59
|
+
# -> app/views/madmin/_navigation.html.erb
|
62
60
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
61
|
+
rails g madmin:views:layout # Note the layout generator includes the layout, javascript, and navigation files.
|
62
|
+
# -> app/views/madmin/application.html.erb
|
63
|
+
# -> app/views/madmin/_javascript.html.erb
|
64
|
+
# -> app/views/madmin/_navigation.html.erb
|
67
65
|
```
|
68
66
|
|
69
|
-
If you
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
...
|
74
|
-
|
75
|
-
private
|
76
|
-
|
77
|
-
def authenticate!
|
78
|
-
authenticated = authenticate_with_http_basic { |user, password|
|
79
|
-
user == "user" && password == "password"
|
80
|
-
}
|
81
|
-
|
82
|
-
request_http_basic_authentication unless authenticated
|
83
|
-
end
|
84
|
-
end
|
67
|
+
If you only need to customize specific views, you can restrict which views are copied by the generator:
|
68
|
+
```bash
|
69
|
+
rails g madmin:views:index
|
70
|
+
# -> app/views/madmin/application/index.html.erb
|
85
71
|
```
|
86
72
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
```ruby
|
92
|
-
# Autoload Madmin
|
93
|
-
config.autoload_paths += Dir["#{config.root}/lib/madmin/**/"]
|
73
|
+
You can also scope the copied view(s) to a specific Resource/Model:
|
74
|
+
```bash
|
75
|
+
rails generate madmin:views:index Book
|
76
|
+
# -> app/views/madmin/books/index.html.erb
|
94
77
|
```
|
95
78
|
|
96
|
-
##
|
79
|
+
## Authentication
|
80
|
+
|
81
|
+
You can use a couple of strategies to authenticate users who are trying to
|
82
|
+
access your madmin panel: [Authentication Docs](docs/authentication.md)
|
97
83
|
|
98
|
-
|
84
|
+
## 🙏 Contributing
|
99
85
|
|
100
|
-
|
86
|
+
This project uses Standard for formatting Ruby code. Please make sure to run standardrb before submitting pull requests.
|
101
87
|
|
88
|
+
## 📝 License
|
102
89
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
CHANGED
@@ -8,21 +8,20 @@ require "rdoc/task"
|
|
8
8
|
|
9
9
|
RDoc::Task.new(:rdoc) do |rdoc|
|
10
10
|
rdoc.rdoc_dir = "rdoc"
|
11
|
-
rdoc.title
|
11
|
+
rdoc.title = "Madmin"
|
12
12
|
rdoc.options << "--line-numbers"
|
13
13
|
rdoc.rdoc_files.include("README.md")
|
14
14
|
rdoc.rdoc_files.include("lib/**/*.rb")
|
15
15
|
end
|
16
16
|
|
17
|
-
APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
|
18
|
-
load "rails/tasks/engine.rake"
|
19
|
-
|
20
|
-
load "rails/tasks/statistics.rake"
|
21
|
-
|
22
17
|
require "bundler/gem_tasks"
|
23
18
|
|
24
19
|
require "rake/testtask"
|
25
20
|
|
21
|
+
APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
|
22
|
+
load "rails/tasks/engine.rake"
|
23
|
+
load "rails/tasks/statistics.rake"
|
24
|
+
|
26
25
|
Rake::TestTask.new(:test) do |t|
|
27
26
|
t.libs << "test"
|
28
27
|
t.pattern = "test/**/*_test.rb"
|
@@ -0,0 +1,36 @@
|
|
1
|
+
//
|
2
|
+
// Provides a drop-in pointer for the default Trix stylesheet that will format the toolbar and
|
3
|
+
// the trix-editor content (whether displayed or under editing). Feel free to incorporate this
|
4
|
+
// inclusion directly in any other asset bundle and remove this file.
|
5
|
+
//
|
6
|
+
//= require trix/dist/trix
|
7
|
+
|
8
|
+
// We need to override trix.css’s image gallery styles to accommodate the
|
9
|
+
// <action-text-attachment> element we wrap around attachments. Otherwise,
|
10
|
+
// images in galleries will be squished by the max-width: 33%; rule.
|
11
|
+
.trix-content {
|
12
|
+
.attachment-gallery {
|
13
|
+
> action-text-attachment,
|
14
|
+
> .attachment {
|
15
|
+
flex: 1 0 33%;
|
16
|
+
padding: 0 0.5em;
|
17
|
+
max-width: 33%;
|
18
|
+
}
|
19
|
+
|
20
|
+
&.attachment-gallery--2,
|
21
|
+
&.attachment-gallery--4 {
|
22
|
+
> action-text-attachment,
|
23
|
+
> .attachment {
|
24
|
+
flex-basis: 50%;
|
25
|
+
max-width: 50%;
|
26
|
+
}
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
action-text-attachment {
|
31
|
+
.attachment {
|
32
|
+
padding: 0 !important;
|
33
|
+
max-width: 100% !important;
|
34
|
+
}
|
35
|
+
}
|
36
|
+
}
|
@@ -2,8 +2,8 @@
|
|
2
2
|
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
3
|
* listed below.
|
4
4
|
*
|
5
|
-
* Any CSS and SCSS file within this directory, lib/assets/stylesheets,
|
6
|
-
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's
|
6
|
+
* vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
7
|
*
|
8
8
|
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
9
|
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
@@ -13,10 +13,3 @@
|
|
13
13
|
*= require_tree .
|
14
14
|
*= require_self
|
15
15
|
*/
|
16
|
-
|
17
|
-
.sidebar {
|
18
|
-
height: 100%;
|
19
|
-
left: 0;
|
20
|
-
position: fixed;
|
21
|
-
top: 0;
|
22
|
-
}
|
@@ -1,16 +1,12 @@
|
|
1
|
-
require_dependency "madmin/resources"
|
2
|
-
|
3
1
|
module Madmin
|
4
2
|
class BaseController < ActionController::Base
|
5
|
-
|
3
|
+
include Pagy::Backend
|
6
4
|
|
7
|
-
|
5
|
+
protect_from_forgery with: :exception
|
8
6
|
|
9
|
-
#
|
10
|
-
|
11
|
-
|
12
|
-
def validate_resources
|
13
|
-
Madmin::Resources.all
|
7
|
+
# Loads all the models for the sidebar
|
8
|
+
before_action do
|
9
|
+
Rails.application.eager_load!
|
14
10
|
end
|
15
11
|
end
|
16
12
|
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module Madmin
|
2
|
+
class ResourceController < ApplicationController
|
3
|
+
before_action :set_record, except: [:index, :new, :create]
|
4
|
+
|
5
|
+
def index
|
6
|
+
@pagy, @records = pagy(scoped_resources)
|
7
|
+
end
|
8
|
+
|
9
|
+
def show
|
10
|
+
end
|
11
|
+
|
12
|
+
def new
|
13
|
+
@record = resource.model.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def create
|
17
|
+
@record = resource.model.new(resource_params)
|
18
|
+
if @record.save
|
19
|
+
redirect_to resource.show_path(@record)
|
20
|
+
else
|
21
|
+
render :new, status: :unprocessable_entity
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def edit
|
26
|
+
end
|
27
|
+
|
28
|
+
def update
|
29
|
+
if @record.update(resource_params)
|
30
|
+
redirect_to resource.show_path(@record)
|
31
|
+
else
|
32
|
+
render :edit, status: :unprocessable_entity
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def destroy
|
37
|
+
@record.destroy
|
38
|
+
redirect_to resource.index_path
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def set_record
|
44
|
+
@record = resource.model.find(params[:id])
|
45
|
+
end
|
46
|
+
|
47
|
+
def resource
|
48
|
+
@resource ||= resource_name.constantize
|
49
|
+
end
|
50
|
+
helper_method :resource
|
51
|
+
|
52
|
+
def resource_name
|
53
|
+
"#{controller_path.singularize}_resource".delete_prefix("madmin/").classify
|
54
|
+
end
|
55
|
+
|
56
|
+
def scoped_resources
|
57
|
+
resource.model.send(valid_scope)
|
58
|
+
end
|
59
|
+
|
60
|
+
def valid_scope
|
61
|
+
scope = params.fetch(:scope, "all")
|
62
|
+
resource.scopes.include?(scope.to_sym) ? scope : :all
|
63
|
+
end
|
64
|
+
|
65
|
+
def resource_params
|
66
|
+
params.require(resource.param_key)
|
67
|
+
.permit(*resource.permitted_params)
|
68
|
+
.transform_values { |v| change_polymorphic(v) }
|
69
|
+
end
|
70
|
+
|
71
|
+
def change_polymorphic(data)
|
72
|
+
return data unless data.is_a?(ActionController::Parameters) && data[:type]
|
73
|
+
|
74
|
+
if data[:type] == "polymorphic"
|
75
|
+
GlobalID::Locator.locate(data[:value])
|
76
|
+
else
|
77
|
+
raise "Unrecognised param data: #{data.inspect}"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -1,15 +1,17 @@
|
|
1
1
|
module Madmin
|
2
2
|
module ApplicationHelper
|
3
|
-
|
4
|
-
@available_resources ||= Madmin::Resources.gather.map { |model| madmin_resource_for(model: model) }
|
5
|
-
end
|
3
|
+
include Pagy::Frontend
|
6
4
|
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
# Converts a Rails version to a NPM version
|
6
|
+
def npm_rails_version
|
7
|
+
version = [
|
8
|
+
Rails::VERSION::MAJOR,
|
9
|
+
Rails::VERSION::MINOR,
|
10
|
+
Rails::VERSION::TINY
|
11
|
+
].join(".")
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
+
version += "-#{Rails::VERSION::PRE}" if Rails::VERSION::PRE
|
14
|
+
version
|
13
15
|
end
|
14
16
|
end
|
15
17
|
end
|
@@ -1,30 +1,28 @@
|
|
1
1
|
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
<html lang="<%= I18n.locale %>">
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<meta name="ROBOTS" content="NOODP">
|
6
|
+
<meta name="viewport" content="initial-scale=1">
|
7
|
+
<title>
|
8
|
+
Madmin: <%= Rails.application.class %>
|
9
|
+
</title>
|
10
|
+
<link href="https://unpkg.com/tailwindcss@^2.0/dist/tailwind.min.css" rel="stylesheet" />
|
11
|
+
<link href="https://unpkg.com/@tailwindcss/forms/dist/forms.min.css" rel="stylesheet" />
|
12
|
+
<link href="https://unpkg.com/@tailwindcss/typography/dist/typography.min.css" rel="stylesheet" />
|
13
|
+
<%= csrf_meta_tags %>
|
7
14
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
<
|
13
|
-
|
14
|
-
<div class="row">
|
15
|
-
<%= render 'application/navigation' %>
|
16
|
-
<div class="col-10 ml-sm-auto mt-4">
|
17
|
-
<div class="container">
|
18
|
-
<%= yield %>
|
19
|
-
</div>
|
15
|
+
<%= render "javascript" %>
|
16
|
+
</head>
|
17
|
+
<body class="prose" style="max-width:none">
|
18
|
+
<div class="flex w-full p-4">
|
19
|
+
<div id="sidebar" class="w-64 flex-shrink-0">
|
20
|
+
<%= render "navigation" -%>
|
20
21
|
</div>
|
22
|
+
<main class="w-full" role="main">
|
23
|
+
<%#= render "flashes" -%>
|
24
|
+
<%= yield %>
|
25
|
+
</main>
|
21
26
|
</div>
|
22
|
-
</
|
23
|
-
|
24
|
-
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
|
25
|
-
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
|
26
|
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
|
27
|
-
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
|
28
|
-
<%= javascript_include_tag "madmin/application" %>
|
29
|
-
</body>
|
27
|
+
</body>
|
30
28
|
</html>
|