madmin 0.1.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +50 -63
  4. data/Rakefile +5 -6
  5. data/app/assets/config/manifest.js +2 -0
  6. data/app/assets/stylesheets/actiontext.scss +36 -0
  7. data/app/assets/stylesheets/{madmin/application.css → application.css} +2 -9
  8. data/app/controllers/madmin/base_controller.rb +5 -9
  9. data/app/controllers/madmin/dashboard_controller.rb +1 -3
  10. data/app/controllers/madmin/resource_controller.rb +81 -0
  11. data/app/helpers/madmin/application_helper.rb +10 -8
  12. data/app/views/layouts/madmin/application.html.erb +23 -25
  13. data/app/views/madmin/application/_form.html.erb +25 -0
  14. data/app/views/madmin/application/_javascript.html.erb +24 -0
  15. data/app/views/madmin/application/_navigation.html.erb +6 -0
  16. data/app/views/madmin/application/edit.html.erb +3 -0
  17. data/app/views/madmin/application/index.html.erb +47 -0
  18. data/app/views/madmin/application/new.html.erb +3 -0
  19. data/app/views/madmin/application/show.html.erb +24 -0
  20. data/app/views/madmin/dashboard/show.html.erb +1 -0
  21. data/app/views/madmin/fields/attachment/_form.html.erb +2 -0
  22. data/app/views/madmin/fields/attachment/_index.html.erb +3 -0
  23. data/app/views/madmin/fields/attachment/_show.html.erb +3 -0
  24. data/app/views/madmin/fields/attachments/_form.html.erb +2 -0
  25. data/app/views/madmin/fields/attachments/_index.html.erb +1 -0
  26. data/app/views/madmin/fields/attachments/_show.html.erb +7 -0
  27. data/app/views/madmin/fields/belongs_to/_form.html.erb +2 -14
  28. data/app/views/madmin/fields/belongs_to/_index.html.erb +3 -7
  29. data/app/views/madmin/fields/belongs_to/_show.html.erb +3 -8
  30. data/app/views/madmin/fields/boolean/_form.html.erb +2 -0
  31. data/app/views/madmin/fields/boolean/_index.html.erb +1 -0
  32. data/app/views/madmin/fields/boolean/_show.html.erb +1 -0
  33. data/app/views/madmin/fields/date/_form.html.erb +2 -0
  34. data/app/views/madmin/fields/date/_index.html.erb +1 -0
  35. data/app/views/madmin/fields/date/_show.html.erb +1 -0
  36. data/app/views/madmin/fields/date_time/_form.html.erb +2 -0
  37. data/app/views/madmin/fields/date_time/_index.html.erb +1 -0
  38. data/app/views/madmin/fields/date_time/_show.html.erb +1 -0
  39. data/app/views/madmin/fields/decimal/_form.html.erb +2 -0
  40. data/app/views/madmin/fields/decimal/_index.html.erb +1 -0
  41. data/app/views/madmin/fields/decimal/_show.html.erb +1 -0
  42. data/app/views/madmin/fields/enum/_form.html.erb +2 -0
  43. data/app/views/madmin/fields/enum/_index.html.erb +1 -0
  44. data/app/views/madmin/fields/enum/_show.html.erb +1 -0
  45. data/app/views/madmin/fields/float/_form.html.erb +2 -0
  46. data/app/views/madmin/fields/float/_index.html.erb +1 -0
  47. data/app/views/madmin/fields/float/_show.html.erb +1 -0
  48. data/app/views/madmin/fields/has_many/_form.html.erb +2 -0
  49. data/app/views/madmin/fields/has_many/_index.html.erb +1 -0
  50. data/app/views/madmin/fields/has_many/_show.html.erb +4 -14
  51. data/app/views/madmin/fields/has_one/_form.html.erb +3 -0
  52. data/app/views/madmin/fields/has_one/_index.html.erb +3 -0
  53. data/app/views/madmin/fields/has_one/_show.html.erb +3 -12
  54. data/app/views/madmin/fields/integer/_form.html.erb +2 -0
  55. data/app/views/madmin/fields/integer/_index.html.erb +1 -0
  56. data/app/views/madmin/fields/integer/_show.html.erb +1 -0
  57. data/app/views/madmin/fields/json/_form.html.erb +2 -0
  58. data/app/views/madmin/fields/json/_index.html.erb +1 -0
  59. data/app/views/madmin/fields/json/_show.html.erb +1 -0
  60. data/app/views/madmin/fields/polymorphic/_form.html.erb +5 -32
  61. data/app/views/madmin/fields/polymorphic/_index.html.erb +3 -1
  62. data/app/views/madmin/fields/polymorphic/_show.html.erb +3 -14
  63. data/app/views/madmin/fields/rich_text/_form.html.erb +4 -0
  64. data/app/views/madmin/fields/rich_text/_index.html.erb +1 -0
  65. data/app/views/madmin/fields/rich_text/_show.html.erb +3 -0
  66. data/app/views/madmin/fields/string/_form.html.erb +2 -0
  67. data/app/views/madmin/fields/string/_index.html.erb +1 -0
  68. data/app/views/madmin/fields/string/_show.html.erb +1 -0
  69. data/app/views/madmin/fields/text/_form.html.erb +2 -4
  70. data/app/views/madmin/fields/text/_index.html.erb +1 -1
  71. data/app/views/madmin/fields/text/_show.html.erb +1 -8
  72. data/app/views/madmin/fields/time/_form.html.erb +2 -0
  73. data/app/views/madmin/fields/time/_index.html.erb +1 -0
  74. data/app/views/madmin/fields/time/_show.html.erb +1 -0
  75. data/lib/generators/madmin/install/install_generator.rb +31 -12
  76. data/lib/generators/madmin/install/templates/controller.rb.tt +22 -0
  77. data/lib/generators/madmin/resource/resource_generator.rb +83 -47
  78. data/lib/generators/madmin/resource/templates/controller.rb.tt +4 -0
  79. data/lib/generators/madmin/resource/templates/resource.rb.tt +11 -0
  80. data/lib/generators/madmin/views/edit_generator.rb +16 -0
  81. data/lib/generators/madmin/views/form_generator.rb +15 -0
  82. data/lib/generators/madmin/views/index_generator.rb +15 -0
  83. data/lib/generators/madmin/views/layout_generator.rb +21 -0
  84. data/lib/generators/madmin/views/navigation_generator.rb +15 -0
  85. data/lib/generators/madmin/views/new_generator.rb +16 -0
  86. data/lib/generators/madmin/views/show_generator.rb +15 -0
  87. data/lib/generators/madmin/views/views_generator.rb +8 -8
  88. data/lib/madmin.rb +34 -23
  89. data/lib/madmin/engine.rb +5 -2
  90. data/lib/madmin/field.rb +22 -46
  91. data/lib/madmin/fields/attachment.rb +6 -0
  92. data/lib/madmin/fields/attachments.rb +9 -0
  93. data/lib/madmin/fields/belongs_to.rb +18 -0
  94. data/lib/madmin/fields/boolean.rb +6 -0
  95. data/lib/madmin/fields/date.rb +6 -0
  96. data/lib/madmin/fields/date_time.rb +6 -0
  97. data/lib/madmin/fields/decimal.rb +6 -0
  98. data/lib/madmin/fields/enum.rb +9 -0
  99. data/lib/madmin/fields/float.rb +6 -0
  100. data/lib/madmin/fields/has_many.rb +18 -0
  101. data/lib/madmin/fields/has_one.rb +6 -0
  102. data/lib/madmin/fields/integer.rb +6 -0
  103. data/lib/madmin/fields/json.rb +6 -0
  104. data/lib/madmin/fields/polymorphic.rb +17 -0
  105. data/lib/madmin/fields/rich_text.rb +6 -0
  106. data/lib/madmin/fields/string.rb +6 -0
  107. data/lib/madmin/fields/text.rb +6 -0
  108. data/lib/madmin/fields/time.rb +6 -0
  109. data/lib/madmin/generator_helpers.rb +24 -0
  110. data/lib/madmin/namespace.rb +35 -0
  111. data/lib/madmin/resource.rb +176 -0
  112. data/lib/madmin/version.rb +1 -1
  113. data/lib/madmin/view_generator.rb +42 -0
  114. data/lib/tasks/madmin_tasks.rake +7 -0
  115. metadata +106 -111
  116. data/app/assets/config/madmin_manifest.js +0 -2
  117. data/app/assets/javascripts/madmin/application.js +0 -15
  118. data/app/assets/javascripts/madmin/dashboard.js +0 -2
  119. data/app/assets/javascripts/madmin/resources.js +0 -36
  120. data/app/assets/stylesheets/madmin/dashboard.css +0 -4
  121. data/app/assets/stylesheets/madmin/resources.css +0 -4
  122. data/app/controllers/madmin/application_controller.rb +0 -16
  123. data/app/controllers/madmin/resources_controller.rb +0 -97
  124. data/app/decorators/madmin/resource_decorator.rb +0 -16
  125. data/app/helpers/madmin/fields/polymorphic_helper.rb +0 -25
  126. data/app/jobs/madmin/application_job.rb +0 -4
  127. data/app/mailers/madmin/application_mailer.rb +0 -6
  128. data/app/models/madmin/application_record.rb +0 -5
  129. data/app/views/application/_navigation.html.erb +0 -17
  130. data/app/views/madmin/dashboard/index.html.erb +0 -6
  131. data/app/views/madmin/fields/check_box/_form.html.erb +0 -4
  132. data/app/views/madmin/fields/check_box/_index.html.erb +0 -1
  133. data/app/views/madmin/fields/check_box/_show.html.erb +0 -8
  134. data/app/views/madmin/fields/email/_form.html.erb +0 -4
  135. data/app/views/madmin/fields/email/_index.html.erb +0 -1
  136. data/app/views/madmin/fields/email/_show.html.erb +0 -8
  137. data/app/views/madmin/fields/number/_form.html.erb +0 -4
  138. data/app/views/madmin/fields/number/_index.html.erb +0 -1
  139. data/app/views/madmin/fields/number/_show.html.erb +0 -8
  140. data/app/views/madmin/fields/password/_form.html.erb +0 -4
  141. data/app/views/madmin/fields/password/_index.html.erb +0 -1
  142. data/app/views/madmin/fields/password/_show.html.erb +0 -8
  143. data/app/views/madmin/fields/select/_form.html.erb +0 -4
  144. data/app/views/madmin/fields/select/_index.html.erb +0 -1
  145. data/app/views/madmin/fields/select/_show.html.erb +0 -8
  146. data/app/views/madmin/fields/text_area/_form.html.erb +0 -4
  147. data/app/views/madmin/fields/text_area/_index.html.erb +0 -1
  148. data/app/views/madmin/fields/text_area/_show.html.erb +0 -8
  149. data/app/views/madmin/resources/_form.html.erb +0 -15
  150. data/app/views/madmin/resources/_scopes.html.erb +0 -10
  151. data/app/views/madmin/resources/edit.html.erb +0 -2
  152. data/app/views/madmin/resources/index.html.erb +0 -13
  153. data/app/views/madmin/resources/index/_content.html.erb +0 -33
  154. data/app/views/madmin/resources/new.html.erb +0 -2
  155. data/app/views/madmin/resources/show.html.erb +0 -10
  156. data/config/routes.rb +0 -11
  157. data/lib/generators/madmin/controller/USAGE +0 -8
  158. data/lib/generators/madmin/controller/controller_generator.rb +0 -10
  159. data/lib/generators/madmin/page/USAGE +0 -8
  160. data/lib/generators/madmin/page/page_generator.rb +0 -20
  161. data/lib/generators/madmin/page/templates/template.html.erb +0 -2
  162. data/lib/generators/madmin/page/templates/template.rb.erb +0 -10
  163. data/lib/generators/madmin/resource/templates/resource.rb.erb +0 -11
  164. data/lib/madmin/field/associatable.rb +0 -58
  165. data/lib/madmin/field/belongs_to.rb +0 -9
  166. data/lib/madmin/field/check_box.rb +0 -8
  167. data/lib/madmin/field/date_time.rb +0 -8
  168. data/lib/madmin/field/email.rb +0 -8
  169. data/lib/madmin/field/has_many.rb +0 -9
  170. data/lib/madmin/field/has_one.rb +0 -9
  171. data/lib/madmin/field/number.rb +0 -8
  172. data/lib/madmin/field/password.rb +0 -8
  173. data/lib/madmin/field/polymorphic.rb +0 -57
  174. data/lib/madmin/field/select.rb +0 -13
  175. data/lib/madmin/field/text.rb +0 -8
  176. data/lib/madmin/field/text_area.rb +0 -8
  177. data/lib/madmin/resourceable.rb +0 -72
  178. data/lib/madmin/resourceable/class_methods.rb +0 -152
  179. data/lib/madmin/resources.rb +0 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: be4b01320deccbc46e6184ae804f74e278c909ec7b11f74274f09dc4442e78d4
4
- data.tar.gz: cdecb4f3ca23924befe03dc43ec4dda63626adabc24c70cbc892e3e21dd0ca62
3
+ metadata.gz: f149452559626564a6b3888b89ddeaf7fb2bf1c3fedbbc4ac4ba3dc2a1df4e58
4
+ data.tar.gz: 8536e397b8d032d704b7e10c938af1ee1eda4911d9c6933ecd9c11f68fbac8f7
5
5
  SHA512:
6
- metadata.gz: 7f8691c029a1f37cf1b515c1ec399481d12ee2a4320c1e564f586e38b2d7e12610796df1c3b391356496dfca4c6b1d156b5459850873dd6bda54940e69a2f951
7
- data.tar.gz: 36e1b5138b977c5a7bb46b7e1a96078c645c204865de2df919fdef9909c4ac9ba6930b18ad905ca6489ff6e8b11656776561aa1c424b38d79ba3e9db3beee204
6
+ metadata.gz: e6a4a123086ee55711728e9f2b1bff5ca90d28c7238690d5f51e9b834f1f5eb15170b7e8e3b1aac7a79e08d4b55ee2500dc11f16d4f62c4a31cc4d0d5ab0b6ba
7
+ data.tar.gz: 49a20396c04c22fbe8001d53ed4cc567b441171943a090cd888b98e94cbf11b31ad5ec89fc67dd9cae98af03282adf8bdacec159075c73605ac743c994338e51
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2019 Jason Charnes
1
+ Copyright 2020 Chris Oliver
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,102 +1,89 @@
1
1
  # Madmin
2
2
 
3
- Short description and motivation.
3
+ ### 🛠 A robust Admin Interface for Ruby on Rails apps
4
4
 
5
- ## Usage
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
- How to use my plugin.
7
+ Why another Ruby on Rails admin? We wanted an admin that was:
8
8
 
9
- ## Installation
10
-
11
- Add this line to your application's Gemfile:
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
- ```ruby
14
- gem 'madmin'
15
- ```
16
-
17
- And then execute:
13
+ ## Installation
14
+ Add `madmin` to your application's Gemfile:
18
15
 
19
16
  ```bash
20
- $ bundle
17
+ bundle add madmin
21
18
  ```
22
19
 
23
- Or install it yourself as:
20
+ Then run the madmin generator:
24
21
 
25
22
  ```bash
26
- $ gem install madmin
23
+ rails g madmin:install
27
24
  ```
28
25
 
29
- Then you can run the installer to generate resources for all models in
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
- ```bash
33
- rails generate madmin:install
34
- ```
28
+ ## Resources
29
+
30
+ Madmin uses `Resource` classes to add models to the admin area.
35
31
 
36
- ## Generating Resources
32
+ ### Generate a Resource
37
33
 
38
- To generate (or re-generate) a Madmin dashboard for a resource, you
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 generate madmin:install User
37
+ rails g madmin:resource ActionText::RichText
43
38
  ```
44
39
 
45
- ## Implementing Authentication
40
+ ## Configuring Views
46
41
 
47
- To implement user authentication for your admin dashboard, you can override `authenticate!` in `app/controllers/madmin/application_controller.rb`.
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
- To access this controller run the following command
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:controller Application
48
+ rails generate madmin:views
53
49
  ```
54
50
 
55
- If you're using Devise, simply have `authenticate!` authenticate your resource
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
- ```ruby
58
- class Madmin::ApplicationController < Madmin::BaseController
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
- def authenticate!
64
- authenticate_user!
65
- end
66
- end
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're wanting to use simple HTTP Basic authentication, have `authenticate!` use `authenticate_with_http_basic` like the following
70
-
71
- ```ruby
72
- class Madmin::ApplicationController < Madmin::BaseController
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
- ## Autoloading Lib
88
-
89
- If you want to avoid having to restart your Rails application everytime you make an adjustment to a `lib/madmin/resources.rb`, add the following to `config/application.rb`:
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
- ## Contributing
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
- Contribution directions go here.
84
+ ## 🙏 Contributing
99
85
 
100
- ## License
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 = "Madmin"
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,2 @@
1
+ //= link_tree ../images
2
+ //= link_directory ../stylesheets .css
@@ -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, vendor/assets/stylesheets,
6
- * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
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
- before_action :validate_resources
3
+ include Pagy::Backend
6
4
 
7
- private
5
+ protect_from_forgery with: :exception
8
6
 
9
- # Taking a peek at all the resources will raise an error if one isn't found.
10
- # Let's inform the user if we can't find a resource no matter what page
11
- # they're on. This should fail to prevent surprises at run time.
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
@@ -1,8 +1,6 @@
1
- require_dependency "madmin/application_controller"
2
-
3
1
  module Madmin
4
2
  class DashboardController < ApplicationController
5
- def index
3
+ def show
6
4
  end
7
5
  end
8
6
  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
- def available_resources
4
- @available_resources ||= Madmin::Resources.gather.map { |model| madmin_resource_for(model: model) }
5
- end
3
+ include Pagy::Frontend
6
4
 
7
- def madmin_resource_for(model:)
8
- Object.const_get("::Madmin::Resources::#{model}").new
9
- end
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
- def pages
12
- Madmin::Pages.all
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
- <title>Madmin</title>
5
- <%= csrf_meta_tags %>
6
- <%= csp_meta_tag %>
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
- <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
9
-
10
- <%= stylesheet_link_tag "madmin/application", media: "all" %>
11
- </head>
12
- <body>
13
- <div class="container-fluid">
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
- </div>
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>