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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: effe2cef8e6d737651ad3f18b60445620d28b3f8cbadedf8981e866d27a087ca
4
- data.tar.gz: 97b00adc461c766b00ee2bae3df3c950d04a44a41fc654e93553ee4a5f8dc8f1
3
+ metadata.gz: a081ce47d7f266c588a04f1998b1156b859e15526677b5b6ba39e5315efbdf45
4
+ data.tar.gz: 8533a2223231ba545b8a4935ea6b29ca06e3043888f41248bc096162b93f8dd3
5
5
  SHA512:
6
- metadata.gz: e052d7299477fc54e9c3a8713de32f6c995a58794eaa3a3458dcd3fd48b642ee75dec8aa1ae4e8a8a8f8985994695f2830c3bdb8db0e35158126e03f6acbf79a
7
- data.tar.gz: e00c4c786ccb379546abef4c07d4b4405a7df23d5da382bbfec2032c29b320dd44a80026705d2a2f43bca3afc647ce9e2b2bbfabc758ec5c42c0e27ec2dc51a2
6
+ metadata.gz: a369a69825063d843569625485adf3f46102b31697195abcdb68bc674e23bff86a0208957e502061742947809236da0ae9a2628324aee4f91c9c5a410618d32d
7
+ data.tar.gz: a7e3acacc31d419440774347c2d571a84e4ff182b1a6e885e73437ec01d76cbe92bb5b7ddf1c66393f4fde6d03c1cc7bfdf819aae7898bda3601e4d1e2de7689
@@ -35,7 +35,7 @@
35
35
  cursor: default;
36
36
  }
37
37
 
38
- a.current {
38
+ a[aria-current="page"] {
39
39
  color: #ffffff;
40
40
  background-color: var(--primary-color);
41
41
  }
@@ -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
- z-index: 10; /* Ensure sidebar is above main content */
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
- include Pagy::Backend
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
@@ -16,9 +16,6 @@ module Madmin
16
16
  render json: @records.map { |r| {name: @resource.display_name(r), id: r.id} }
17
17
  }
18
18
  end
19
- rescue Pagy::OverflowError
20
- params[:page] = 1
21
- retry
22
19
  end
23
20
 
24
21
  def show
@@ -1,6 +1,6 @@
1
1
  module Madmin
2
2
  module ApplicationHelper
3
- include Pagy::Frontend
3
+ include Pagy::Frontend if defined? Pagy::Frontend
4
4
  include Rails.application.routes.url_helpers
5
5
 
6
6
  def clear_search_params
@@ -65,6 +65,11 @@
65
65
  </div>
66
66
 
67
67
  <div class="pagination">
68
- <%== pagy_nav @pagy if @pagy.pages > 1 %>
69
- <%== pagy_info @pagy %>
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
- <%== pagy_nav pagy if pagy.pages > 1 %>
12
- <%== pagy_info pagy %>
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
- <%== pagy_nav pagy if pagy.pages > 1 %>
12
- <%== pagy_info pagy %>
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
- records = if (record = record.send(attribute_name))
6
- [record]
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
- def paginated_value(record, params)
39
- param_name = "#{attribute_name}_page"
40
- pagy value(record), page: params[param_name].to_i, page_param: param_name
41
- rescue Pagy::OverflowError, Pagy::VariableError
42
- pagy value(record), page: 1, page_param: param_name
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
@@ -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.pluralize
77
+ model_name.split("::").map { |part| part.underscore.humanize }.join(" / ").titlecase
76
78
  end
77
79
 
78
80
  # Support for isolated namespaces
@@ -1,3 +1,3 @@
1
1
  module Madmin
2
- VERSION = "2.0.5"
2
+ VERSION = "2.1.1"
3
3
  end
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
- bin/rails generate madmin:resource #{resource_name.split("Resource").first}
57
- MESSAGE
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
- begin
65
- "#{object.class.name}Resource"
66
- rescue
67
- # For STI models, see if there's a superclass resource available
68
- if (column = object.class.inheritance_column) && object.class.column_names.include?(column)
69
- "#{object.class.superclass.base_class.name}Resource"
70
- end
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: madmin
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.5
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Oliver