madmin 2.0.1 → 2.0.3

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: 531eb134ff2fc5b4f8d16f24167561fcd7836f1f5e8886d39f103a156ccffc6b
4
- data.tar.gz: 28cec8a6ae99f9a36e6ecdc65383fe10306f2880ec7ae499e08a50093b38b7e1
3
+ metadata.gz: 1e151654e85ee04e468708ebcb264633db5647e24964ea20a8b94f29850059fc
4
+ data.tar.gz: b709f0e2c7cae8461fc4ff7fc7470fc720b7c84bd4eecea9b647e61c2a647d21
5
5
  SHA512:
6
- metadata.gz: 122ff7eda3d0bc65945b4e34b9b23d6ddc700d711b9fa7381e8c3fd9bdfcd73113a083f2dcaded130978b6716bf79e3233bcc0e132c80704436b42d5065d407b
7
- data.tar.gz: 92e06ee0cfcba0279947e46972efc5f2463b35b020b97bc5d830f7554cf5b004cc242f4203d3cc124919df49d8ecf1a4b16ac1e94b5e70715961b8e2afa8a1aa
6
+ metadata.gz: 3b8de42f8febe633ac7398b4e69be0acca9c20cd0b1ea1025079a81508b233c75e2ec3aa14969acf6685fdbef6ff7d9461818b753734731c97549e3f8973410c
7
+ data.tar.gz: ec7843b7ec7e89a521d39150bdde71b9359369b2de988711aa50b75399a70252947516e15387dced3f0161ecb04d0ca4094b0914f7a836e3f13197ae9fefdbd7
data/README.md CHANGED
@@ -9,9 +9,9 @@ Why another Ruby on Rails admin? We wanted an admin that was:
9
9
  - Familiar and customizable like Rails scaffolds (less DSL)
10
10
  - Supports all the Rails features out of the box (ActionText, ActionMailbox, has_secure_password, etc)
11
11
  - Stimulus / Turbolinks / Hotwire ready
12
+ - Works with Import maps and Sprockets
12
13
 
13
14
  ![Madmin Screenshot](docs/images/screenshot.png)
14
- _We're still working on the design!_
15
15
 
16
16
  ## Installation
17
17
 
@@ -103,9 +103,9 @@ The `attribute` method in model_resource.rb gives you that flexibility.
103
103
  ```
104
104
 
105
105
  ```ruby
106
- class UserResource < Madmin::Resource
106
+ class BookResource < Madmin::Resource
107
107
  attribute :id, form: false
108
- attribute :tile
108
+ attribute :title
109
109
  attribute :subtitle, index: false
110
110
  attribute :author
111
111
  attribute :genre
@@ -120,6 +120,18 @@ rails generate madmin:views:index Book
120
120
  # -> app/views/madmin/books/index.html.erb
121
121
  ```
122
122
 
123
+ ### Specifying Field Types
124
+
125
+ You can set a field type as the second argument. Field types may have additional options to render the field UI.
126
+
127
+
128
+ For example, we can use a select for the genre attribute and specify the collection of options to choose from.
129
+
130
+ ```ruby
131
+ class BookResource < Madmin::Resource
132
+ attribute :genre, :select, collection: ["Fiction", "Mystery", "Thriller"]
133
+ end
134
+
123
135
  ## Custom Fields
124
136
 
125
137
  You can generate a custom field with:
data/lib/madmin/field.rb CHANGED
@@ -14,7 +14,7 @@ module Madmin
14
14
  end
15
15
 
16
16
  def value(record)
17
- record.public_send(attribute_name)
17
+ record.try(attribute_name)
18
18
  end
19
19
 
20
20
  def to_partial_path(name)
@@ -26,14 +26,10 @@ module Madmin
26
26
  end
27
27
 
28
28
  def paginated_value(record, params)
29
- pagy value(record), params: params, page_param: "#{attribute_name}_page"
30
- end
31
-
32
- # Override to access params from vars since we're not in a controller/view
33
- def pagy_get_page(vars, force_integer: true)
34
- params = vars[:params]
35
- page = params[vars[:page_param] || DEFAULT[:page_param]]
36
- force_integer ? (page || 1).to_i : page
29
+ param_name = "#{attribute_name}_page"
30
+ pagy value(record), page: params[param_name].to_i, page_param: param_name
31
+ rescue Pagy::OverflowError, Pagy::VariableError
32
+ pagy value(record), page: 1, page_param: param_name
37
33
  end
38
34
  end
39
35
  end
@@ -24,8 +24,7 @@ module Madmin
24
24
  end
25
25
 
26
26
  def model_find(id)
27
- record = friendly_model? ? model.friendly.find(id) : model.find(id)
28
- becomes(record)
27
+ friendly_model? ? model.friendly.find(id) : model.find(id)
29
28
  end
30
29
 
31
30
  def model_name
@@ -46,10 +45,8 @@ module Madmin
46
45
 
47
46
  if field.nil?
48
47
  Rails.logger.warn <<~MESSAGE
49
- WARNING: Madmin could not infer a field type for `#{name}` attribute. Defaulting to a String type.
50
- You can set the type by specifying the type on the attribute:
51
-
52
- attribute :#{name}, :boolean
48
+ WARNING: Madmin could not infer a field type for `#{name}` attribute in `#{self.name}`. Defaulting to a String type.
49
+ #{caller.find { _1.start_with? Rails.root.to_s }}
53
50
  MESSAGE
54
51
  field = Fields::String
55
52
  end
@@ -1,3 +1,3 @@
1
1
  module Madmin
2
- VERSION = "2.0.1"
2
+ VERSION = "2.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: madmin
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Oliver
8
8
  - Andrea Fomera
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-02-25 00:00:00.000000000 Z
11
+ date: 1980-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -255,7 +255,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
255
255
  - !ruby/object:Gem::Version
256
256
  version: '0'
257
257
  requirements: []
258
- rubygems_version: 3.6.5
258
+ rubygems_version: 3.6.9
259
259
  specification_version: 4
260
260
  summary: A modern admin for Ruby on Rails apps
261
261
  test_files: []