madmin 2.1.0 → 2.1.2

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: de0ee3515b8f8689bbd5c7b6b99675c2724f0be4cf7774e97d71da99076f3b68
4
- data.tar.gz: 4224940c11670cfbc2a481cc0001ad64d846595929993f5971490c1f53e0343c
3
+ metadata.gz: 67db829bf99130d9746ef0d3bd416f0c38e9ecaf70530db4c4066a60032e934d
4
+ data.tar.gz: 91694aac3e2db7fad14918af8be8ab97029ca542848e6ccc1f36d493d2bd4f1e
5
5
  SHA512:
6
- metadata.gz: eaf9f28c5e3dac557dceaff92f823b3372d9c927a2c429d296da83bee28c3f14cd78b31bf198bde7d43bfc8025aaa01d96e1586edc42ebef5c49e3f827929cfc
7
- data.tar.gz: e0b561bb2c7d0367238ba4c9af7794161480396ccf2bc625ffad2a3adfbeb1b6919490f59a8fc24c1eac89eec4f0162e202186dc47913f41351b893972c2fb13
6
+ metadata.gz: bfa374d40d58292a97885e238681bd6bfb91dbe2618f501bda0e25ada1b5490fa8a69b5e80b86cf7262fce44a501a1e1935b672bb6b46a5456e322b11939f93d
7
+ data.tar.gz: 2cf03a691fcda333691547743b7879495bb2de3ed8fc992761a505c154d92d81cb47d994209cca501bcf7b91f26343ccc9b9f007441f641a71440164864b80e4
data/Rakefile CHANGED
@@ -20,7 +20,6 @@ require "rake/testtask"
20
20
 
21
21
  APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
22
22
  load "rails/tasks/engine.rake"
23
- load "rails/tasks/statistics.rake"
24
23
 
25
24
  Rake::TestTask.new(:test) do |t|
26
25
  t.libs << "test"
@@ -11,10 +11,17 @@
11
11
  padding-left: 0.75rem;
12
12
  padding-right: 0.75rem;
13
13
 
14
- &:hover {
14
+ &:hover,
15
+ &:focus {
16
+ cursor: pointer;
15
17
  text-decoration: none !important;
16
18
  }
17
19
 
20
+ &:disabled {
21
+ opacity: 60%;
22
+ cursor: not-allowed;
23
+ }
24
+
18
25
  &.btn-primary {
19
26
  background-color: var(--primary-color);
20
27
  color: white;
@@ -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%;
@@ -22,7 +22,7 @@
22
22
  <button id="hamburger-menu" type="button" data-action="click->mobile-nav#toggle" aria-label="Open menu" aria-expanded="false" aria-controls="sidebar">
23
23
  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" class="size-5"> <path fill-rule="evenodd" d="M2 4.75A.75.75 0 0 1 2.75 4h14.5a.75.75 0 0 1 0 1.5H2.75A.75.75 0 0 1 2 4.75ZM2 10a.75.75 0 0 1 .75-.75h14.5a.75.75 0 0 1 0 1.5H2.75A.75.75 0 0 1 2 10Zm0 5.25a.75.75 0 0 1 .75-.75h14.5a.75.75 0 0 1 0 1.5H2.75a.75.75 0 0 1-.75-.75Z" clip-rule="evenodd" /> </svg>
24
24
  </button>
25
- <%= link_to_if respond_to?(:root_url), Madmin.site_name, root_url, data: {turbo: false} %>
25
+ <%= link_to Madmin.site_name, try(:root_url) || madmin_root_url, data: {turbo: false} %>
26
26
  </div>
27
27
  </header>
28
28
 
@@ -33,7 +33,7 @@
33
33
 
34
34
  <div>
35
35
  <%= yield %>
36
- </div.>
36
+ </div>
37
37
  </main>
38
38
 
39
39
  <div data-mobile-nav-target="overlay" data-action="click->mobile-nav#close" class="mobile-nav-overlay"></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
 
@@ -41,7 +41,8 @@ module Madmin
41
41
  request = {
42
42
  query: {
43
43
  "#{attribute_name}_page" => [params[page_key].to_i, 1].max
44
- }
44
+ },
45
+ params: params
45
46
  }
46
47
  pagy value(record), page_key: page_key, request: request
47
48
  rescue Pagy::OptionError
@@ -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
data/lib/madmin/search.rb CHANGED
@@ -42,7 +42,7 @@ module Madmin
42
42
  fields_count = search_attributes.sum do |attr|
43
43
  searchable_fields(attr).count
44
44
  end
45
- ["%#{@query.mb_chars.downcase}%"] * fields_count
45
+ ["%#{@query.downcase}%"] * fields_count
46
46
  end
47
47
 
48
48
  def search_attributes
@@ -1,3 +1,3 @@
1
1
  module Madmin
2
- VERSION = "2.1.0"
2
+ VERSION = "2.1.2"
3
3
  end
@@ -5,6 +5,7 @@ require "madmin/namespace"
5
5
  module Madmin
6
6
  class ViewGenerator < Rails::Generators::Base
7
7
  include Madmin::GeneratorHelpers
8
+
8
9
  class_option :namespace, type: :string, default: "madmin"
9
10
 
10
11
  def self.template_source_path
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.1.0
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Oliver
@@ -257,7 +257,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
257
257
  - !ruby/object:Gem::Version
258
258
  version: '0'
259
259
  requirements: []
260
- rubygems_version: 3.7.1
260
+ rubygems_version: 3.7.2
261
261
  specification_version: 4
262
262
  summary: A modern admin for Ruby on Rails apps
263
263
  test_files: []