madmin 2.0.5 → 2.1.1
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 +4 -4
- data/app/assets/stylesheets/madmin/pagination.css +1 -1
- data/app/assets/stylesheets/madmin/sidebar.css +3 -1
- data/app/controllers/madmin/base_controller.rb +6 -1
- data/app/controllers/madmin/resource_controller.rb +0 -3
- data/app/helpers/madmin/application_helper.rb +1 -1
- data/app/views/madmin/application/index.html.erb +7 -2
- data/app/views/madmin/fields/has_many/_show.html.erb +7 -2
- data/app/views/madmin/fields/nested_has_many/_show.html.erb +7 -2
- data/lib/madmin/fields/belongs_to.rb +2 -6
- data/lib/madmin/fields/has_many.rb +23 -7
- data/lib/madmin/resource.rb +3 -1
- data/lib/madmin/version.rb +1 -1
- data/lib/madmin.rb +22 -15
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a081ce47d7f266c588a04f1998b1156b859e15526677b5b6ba39e5315efbdf45
|
4
|
+
data.tar.gz: 8533a2223231ba545b8a4935ea6b29ca06e3043888f41248bc096162b93f8dd3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a369a69825063d843569625485adf3f46102b31697195abcdb68bc674e23bff86a0208957e502061742947809236da0ae9a2628324aee4f91c9c5a410618d32d
|
7
|
+
data.tar.gz: a7e3acacc31d419440774347c2d571a84e4ff182b1a6e885e73437ec01d76cbe92bb5b7ddf1c66393f4fde6d03c1cc7bfdf819aae7898bda3601e4d1e2de7689
|
@@ -39,6 +39,7 @@
|
|
39
39
|
}
|
40
40
|
|
41
41
|
main {
|
42
|
+
overflow: auto;
|
42
43
|
padding-right: 1rem;
|
43
44
|
padding-bottom: 1rem;
|
44
45
|
padding-left: calc(1rem + var(--sidebar-width));
|
@@ -48,7 +49,8 @@ main {
|
|
48
49
|
#sidebar {
|
49
50
|
position: absolute;
|
50
51
|
inset: 0;
|
51
|
-
|
52
|
+
/* Ensure sidebar is above main content */
|
53
|
+
z-index: 10;
|
52
54
|
|
53
55
|
border-right: 1px solid var(--border-color);
|
54
56
|
height: 100%;
|
@@ -1,7 +1,12 @@
|
|
1
1
|
module Madmin
|
2
2
|
class BaseController < ActionController::Base
|
3
3
|
include ::ActiveStorage::SetCurrent if defined?(::ActiveStorage)
|
4
|
-
|
4
|
+
|
5
|
+
if Gem::Version.new(Pagy::VERSION) >= Gem::Version.new("43.0.0.rc")
|
6
|
+
include Pagy::Method
|
7
|
+
else
|
8
|
+
include Pagy::Backend
|
9
|
+
end
|
5
10
|
|
6
11
|
protect_from_forgery with: :exception
|
7
12
|
end
|
@@ -65,6 +65,11 @@
|
|
65
65
|
</div>
|
66
66
|
|
67
67
|
<div class="pagination">
|
68
|
-
|
69
|
-
|
68
|
+
<% if @pagy.respond_to?(:series_nav) %>
|
69
|
+
<%== @pagy.series_nav if @pagy.last > 1 %>
|
70
|
+
<%== @pagy.info_tag %>
|
71
|
+
<% else %>
|
72
|
+
<%== pagy_nav @pagy if @pagy.last > 1 %>
|
73
|
+
<%== pagy_info @pagy %>
|
74
|
+
<% end %>
|
70
75
|
</div>
|
@@ -8,6 +8,11 @@
|
|
8
8
|
<% end %>
|
9
9
|
|
10
10
|
<div class="pagination">
|
11
|
-
|
12
|
-
|
11
|
+
<% if pagy.respond_to?(:series_nav) %>
|
12
|
+
<%== pagy.series_nav if pagy.last > 1 %>
|
13
|
+
<%== pagy.info_tag %>
|
14
|
+
<% else %>
|
15
|
+
<%== pagy_nav pagy if pagy.last > 1 %>
|
16
|
+
<%== pagy_info pagy %>
|
17
|
+
<% end %>
|
13
18
|
</div>
|
@@ -8,6 +8,11 @@
|
|
8
8
|
<% end %>
|
9
9
|
|
10
10
|
<div class="pagination">
|
11
|
-
|
12
|
-
|
11
|
+
<% if pagy.respond_to?(:series_nav) %>
|
12
|
+
<%== pagy.series_nav if pagy.last > 1 %>
|
13
|
+
<%== pagy.info_tag %>
|
14
|
+
<% else %>
|
15
|
+
<%== pagy_nav pagy if pagy.last > 1 %>
|
16
|
+
<%== pagy_info pagy %>
|
17
|
+
<% end %>
|
13
18
|
</div>
|
@@ -2,12 +2,8 @@ module Madmin
|
|
2
2
|
module Fields
|
3
3
|
class BelongsTo < Field
|
4
4
|
def options_for_select(record)
|
5
|
-
|
6
|
-
|
7
|
-
else
|
8
|
-
associated_resource.model.first(25)
|
9
|
-
end
|
10
|
-
|
5
|
+
current_value = record.send(attribute_name)
|
6
|
+
records = [current_value].compact + associated_resource.model.excluding(current_value).limit(25)
|
11
7
|
records.map { [Madmin.resource_for(_1).display_name(_1), _1.id] }
|
12
8
|
end
|
13
9
|
|
@@ -1,8 +1,6 @@
|
|
1
1
|
module Madmin
|
2
2
|
module Fields
|
3
3
|
class HasMany < Field
|
4
|
-
include Pagy::Backend
|
5
|
-
|
6
4
|
def options_for_select(record)
|
7
5
|
if (records = record.send(attribute_name))
|
8
6
|
return [] unless records.first
|
@@ -35,11 +33,29 @@ module Madmin
|
|
35
33
|
true
|
36
34
|
end
|
37
35
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
36
|
+
if Gem::Version.new(Pagy::VERSION) >= Gem::Version.new("43.0.0.rc")
|
37
|
+
include Pagy::Method
|
38
|
+
|
39
|
+
def paginated_value(record, params)
|
40
|
+
page_key = "#{attribute_name}_page"
|
41
|
+
request = {
|
42
|
+
query: {
|
43
|
+
"#{attribute_name}_page" => [params[page_key].to_i, 1].max
|
44
|
+
}
|
45
|
+
}
|
46
|
+
pagy value(record), page_key: page_key, request: request
|
47
|
+
rescue Pagy::OptionError
|
48
|
+
end
|
49
|
+
else
|
50
|
+
include Pagy::Backend
|
51
|
+
|
52
|
+
def paginated_value(record, params)
|
53
|
+
page_key = "#{attribute_name}_page"
|
54
|
+
page = [params[page_key].to_i, 1].max
|
55
|
+
pagy value(record), page: page, page_param: page_key
|
56
|
+
rescue Pagy::OverflowError, Pagy::VariableError
|
57
|
+
pagy value, page: 1, page_param: page_key
|
58
|
+
end
|
43
59
|
end
|
44
60
|
end
|
45
61
|
end
|
data/lib/madmin/resource.rb
CHANGED
@@ -71,8 +71,10 @@ module Madmin
|
|
71
71
|
)
|
72
72
|
end
|
73
73
|
|
74
|
+
# Returns singular name
|
75
|
+
# For example: "Forum::Post" -> "Forum / Post"
|
74
76
|
def friendly_name
|
75
|
-
model_name.split("::").map { |part| part.underscore.humanize }.join(" / ").titlecase
|
77
|
+
model_name.split("::").map { |part| part.underscore.humanize }.join(" / ").titlecase
|
76
78
|
end
|
77
79
|
|
78
80
|
# Support for isolated namespaces
|
data/lib/madmin/version.rb
CHANGED
data/lib/madmin.rb
CHANGED
@@ -45,30 +45,37 @@ module Madmin
|
|
45
45
|
end
|
46
46
|
|
47
47
|
class << self
|
48
|
+
# Returns a Madmin::Resource class for the given object
|
48
49
|
def resource_for(object)
|
49
|
-
if (resource_name = resource_name_for(object))
|
50
|
+
if (resource_name = resource_name_for(object)) && Object.const_defined?(resource_name)
|
50
51
|
resource_name.constantize
|
51
|
-
end
|
52
|
-
rescue NameError
|
53
|
-
raise MissingResource, <<~MESSAGE
|
54
|
-
#{resource_name} is missing. Create it by running:
|
55
52
|
|
56
|
-
|
57
|
-
|
53
|
+
# STI models should look at the parent
|
54
|
+
elsif (resource_name = sti_resource_name_for(object)) && Object.const_defined?(resource_name)
|
55
|
+
resource_name.constantize
|
56
|
+
|
57
|
+
else
|
58
|
+
raise MissingResource, <<~MESSAGE
|
59
|
+
`#{object.class.name}Resource` is missing.
|
60
|
+
|
61
|
+
Create the Madmin resource by running:
|
62
|
+
|
63
|
+
bin/rails generate madmin:resource #{object.class.name}
|
64
|
+
MESSAGE
|
65
|
+
end
|
58
66
|
end
|
59
67
|
|
60
68
|
def resource_name_for(object)
|
61
69
|
if object.is_a? ::ActiveStorage::Attached
|
62
70
|
"ActiveStorage::AttachmentResource"
|
63
71
|
else
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
end
|
72
|
+
"#{object.class.name}Resource"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def sti_resource_name_for(object)
|
77
|
+
if (column = object.class.inheritance_column) && object.class.column_names.include?(column)
|
78
|
+
"#{object.class.superclass.base_class.name}Resource"
|
72
79
|
end
|
73
80
|
end
|
74
81
|
|