Skip to content

Commit

Permalink
Merge branch 'main' of github.com:excid3/madmin
Browse files Browse the repository at this point in the history
  • Loading branch information
excid3 committed Oct 21, 2024
2 parents 80fc94a + c3009f7 commit 7565dbd
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 69 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby: ['3.1', '3.2', '3.3']
ruby: ['3.2', '3.3']
gemfile:
- sprockets
- rails_7
Expand Down Expand Up @@ -51,7 +51,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby: ['3.1', '3.2', '3.3']
ruby: ['3.2', '3.3']
gemfile:
- sprockets
- rails_7
Expand Down Expand Up @@ -97,7 +97,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby: ['3.1', '3.2', '3.3']
ruby: ['3.2', '3.3']
gemfile:
- sprockets
- rails_7
Expand Down
4 changes: 1 addition & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ PATH
specs:
madmin (1.2.11)
importmap-rails
ostruct
pagy (>= 3.5)
propshaft
rails (>= 7.0.0)
Expand Down Expand Up @@ -150,7 +149,6 @@ GEM
racc (~> 1.4)
nokogiri (1.16.7-x86_64-linux)
racc (~> 1.4)
ostruct (0.6.0)
pagy (9.0.6)
parallel (1.26.3)
parser (3.3.4.2)
Expand Down Expand Up @@ -269,7 +267,7 @@ GEM
activemodel (>= 6.0.0)
bindex (>= 0.4.0)
railties (>= 6.0.0)
webrick (1.8.1)
webrick (1.8.2)
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
Expand Down
9 changes: 4 additions & 5 deletions app/views/madmin/fields/nested_has_many/_fields.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<%= content_tag :div, class: "nested-fields border border-gray-200 rounded-lg p-5", data: { new_record: f.object.new_record? } do %>
<% field.nested_attributes.each do |name, nested_attribute| %>
<% next if nested_attribute[:field].nil? %>
<% next unless nested_attribute[:field].visible?(action_name) %>
<% next unless nested_attribute[:field].visible?(:form) %>
<% nested_field = nested_attribute[:field] %>
<% nested_field = nested_attribute.field %>
<% next if nested_field.nil? %>
<% next unless nested_field.visible?(action_name) %>
<% next unless nested_field.visible?(:form) %>

<div class="mb-4 flex">
<%= render partial: nested_field.to_partial_path("form"), locals: { field: nested_field, record: f.object, form: f, resource: field.resource } %>
Expand Down
6 changes: 3 additions & 3 deletions lib/madmin/resource.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "ostruct"

module Madmin
class Resource
Attribute = Data.define(:name, :type, :field)

class_attribute :attributes, default: ActiveSupport::OrderedHash.new
class_attribute :member_actions, default: []
class_attribute :scopes, default: []
Expand Down Expand Up @@ -55,7 +55,7 @@ def attribute(name, type = nil, **options)
config.update = value
end

attributes[name] = OpenStruct.new(
attributes[name] = Attribute.new(
name: name,
type: type,
field: field.new(attribute_name: name, model: model, resource: self, options: config)
Expand Down
2 changes: 1 addition & 1 deletion lib/madmin/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def query_template
end

def searchable_fields(attr)
[attr[:name]]
[attr.name]
end

def query_values
Expand Down
3 changes: 1 addition & 2 deletions madmin.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ Gem::Specification.new do |spec|

spec.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"]

spec.required_ruby_version = ">= 2.5.0"
spec.required_ruby_version = ">= 3.2.0"

spec.add_dependency "rails", ">= 7.0.0"
spec.add_dependency "pagy", ">= 3.5"
spec.add_dependency "importmap-rails"
spec.add_dependency "propshaft"
spec.add_dependency "ostruct"
end
1 change: 1 addition & 0 deletions test/dummy/app/madmin/resources/user_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class UserResource < Madmin::Resource
attribute :weekly_email
attribute :monthly_newsletter
attribute :avatar, index: false
attribute :something, :string, index: false, form: false

# Associations
attribute :posts, :nested_has_many, skip: %I[attachments]
Expand Down
4 changes: 4 additions & 0 deletions test/dummy/app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ class User < ApplicationRecord
attribute :virtual_attribute, default: "virtual"

accepts_nested_attributes_for :posts, allow_destroy: true

def something
"Something"
end
end
Loading

0 comments on commit 7565dbd

Please sign in to comment.