Skip to content

Commit

Permalink
Merge branch 'railsadminteam:master' into order-csv-exports
Browse files Browse the repository at this point in the history
  • Loading branch information
pcai authored Jul 12, 2023
2 parents d994430 + e158beb commit d90183f
Show file tree
Hide file tree
Showing 54 changed files with 281 additions and 67 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: ["3.0", 3.1]
ruby:
- "3.0"
- "3.1"
- "3.2"
gemfile: [gemfiles/rails_7.0.gemfile]
orm: [active_record]
adapter: [sqlite3]
Expand Down
6 changes: 2 additions & 4 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ AllCops:
- "node_modules/**/*"
- "spec/dummy_app/bin/**/*"
- "spec/dummy_app/db/schema.rb"
- "spec/dummy_app/node_modules/**/*"
- "spec/dummy_app/tmp/**/*"
- "vendor/bundle/**/*"
NewCops: disable
Expand Down Expand Up @@ -108,7 +109,7 @@ Metrics/BlockNesting:

Metrics/ClassLength:
CountComments: false
Max: 132 # TODO: Lower to 100
Max: 200 # TODO: Lower to 100

Metrics/CyclomaticComplexity:
Max: 15 # TODO: Lower to 6
Expand Down Expand Up @@ -162,9 +163,6 @@ Style/DoubleNegation:
Style/EachWithObject:
Enabled: false

Style/Encoding:
Enabled: false

Style/EndlessMethod:
Enabled: true

Expand Down
35 changes: 33 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,38 @@

## [Unreleased](https://github.com/railsadminteam/rails_admin/tree/HEAD)

[Full Changelog](https://github.com/railsadminteam/rails_admin/compare/v3.1.0...HEAD)
[Full Changelog](https://github.com/railsadminteam/rails_admin/compare/v3.1.2...HEAD)

## [3.1.2](https://github.com/railsadminteam/rails_admin/tree/v3.1.2) - 2023-03-23

[Full Changelog](https://github.com/railsadminteam/rails_admin/compare/v3.1.1...v3.1.2)

### Fixed

- Fix install failing with importmap setup ([aca22b6](https://github.com/railsadminteam/rails_admin/commit/aca22b6ba1eca1ac618525334cf14fc946e1c99e), [#3609](https://github.com/railsadminteam/rails_admin/issues/3609))
- Fix to show non-eager-loaded models which are explicitly configured ([87c9d5b](https://github.com/railsadminteam/rails_admin/commit/87c9d5bc5b6ffb423e72054b3cfe8f949c12c178), [#3604](https://github.com/railsadminteam/rails_admin/issues/3604))
- Fix `rails_admin.dom_ready` event not triggered with jQuery `on` ([2ee43de](https://github.com/railsadminteam/rails_admin/commit/2ee43deb1fa8d3a9e3ea0e589c1687d684e19ad6), [33773d7](https://github.com/railsadminteam/rails_admin/commit/33773d7f8dd43eeb0f6a7c125c4bee170132e5d2), [#3600](https://github.com/railsadminteam/rails_admin/discussions/3600))
- Restore caching in RailsAdmin::Config::Model#excluded? ([#3587](https://github.com/railsadminteam/rails_admin/pull/3587))
- Optimize/simplify viable_models file path to class name logic ([#3589](https://github.com/railsadminteam/rails_admin/pull/3589))

## [3.1.1](https://github.com/railsadminteam/rails_admin/tree/v3.1.1) - 2022-12-18

[Full Changelog](https://github.com/railsadminteam/rails_admin/compare/v3.1.0...v3.1.1)

### Changed

- Relax Font-Awesome dependency to allow Webpacker users to stay on 5.x ([3a7f348](https://github.com/railsadminteam/rails_admin/commit/3a7f34875248e446b48fd76870f0c337fee6dcf9), [#3565](https://github.com/railsadminteam/rails_admin/issues/3565))

### Removed

- Remove unused glphyicon assets ([#3578](https://github.com/railsadminteam/rails_admin/pull/3578))

### Fixed

- Simplify uses of defined? ([#3561](https://github.com/railsadminteam/rails_admin/pull/3561))
- Define jQuery object in separate file to support esbuild ([#3571](https://github.com/railsadminteam/rails_admin/pull/3571))
- Fix filter box being duplicated on browser back ([c6b1893](https://github.com/railsadminteam/rails_admin/commit/c6b18934cff3db0768836d799ee1bea54045709c), [#3570](https://github.com/railsadminteam/rails_admin/issues/3570))
- Fix sidebar menu expanding horizontally, preventing vertical scroll ([9997c10](https://github.com/railsadminteam/rails_admin/commit/9997c1095066aaac39afb27bf8de705cf6ccb1ef), [#3564](https://github.com/railsadminteam/rails_admin/issues/3564))

## [3.1.0](https://github.com/railsadminteam/rails_admin/tree/v3.1.0) - 2022-11-06

Expand Down Expand Up @@ -142,7 +173,7 @@
### Added

- Support Mongoid's Storage Field Names ([cefa23c](https://github.com/railsadminteam/rails_admin/commit/cefa23c9d23d06dc1134228e142e6f0aa4655c54), [#1745](https://github.com/railsadminteam/rails_admin/issues/1745))
- Allow save/delete oprations to be disabled based on an object's `#read_only?` status ([9cd7541](https://github.com/railsadminteam/rails_admin/commit/9cd7541a2e6af4ae4941b200840a1474baeb2f06), [#1684](https://github.com/railsadminteam/rails_admin/issues/1684))
- Allow save/delete operations to be disabled based on an object's `#read_only?` status ([9cd7541](https://github.com/railsadminteam/rails_admin/commit/9cd7541a2e6af4ae4941b200840a1474baeb2f06), [#1684](https://github.com/railsadminteam/rails_admin/issues/1684))
- Allow customizing model's last created time ([d6d380a](https://github.com/railsadminteam/rails_admin/commit/d6d380a02e955c3b14ff7dc30f1809a2a6cd0f47), [#3010](https://github.com/railsadminteam/rails_admin/issues/3010))
- Add ability to hide the dashboard history section ([#3189](https://github.com/railsadminteam/rails_admin/pull/3189))
- Add model scope configuration option, which enables 'unscoped' mode ([8d905f9](https://github.com/railsadminteam/rails_admin/commit/8d905f9e2f1102e8addf324b496720e3fd47bf1d), [#1348](https://github.com/railsadminteam/rails_admin/issues/1348))
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# RailsAdmin

[![Gem Version](https://img.shields.io/gem/v/rails_admin.svg)][gem]
[![Build Status](https://img.shields.io/github/workflow/status/railsadminteam/rails_admin/Test)][ghactions]
[![Build Status](https://github.com/railsadminteam/rails_admin/actions/workflows/test.yml/badge.svg)][ghactions]
[![Coverage Status](https://img.shields.io/coveralls/railsadminteam/rails_admin.svg)][coveralls]
[![Code Climate](https://codeclimate.com/github/railsadminteam/rails_admin.svg)][codeclimate]
[![SemVer](https://api.dependabot.com/badges/compatibility_score?dependency-name=rails_admin&package-manager=bundler&version-scheme=semver)][semver]

[gem]: https://rubygems.org/gems/rails_admin
[ghactions]: https://github.com/railsadminteam/rails_admin/actions
[ghactions]: https://github.com/railsadminteam/rails_admin/actions/workflows/test.yml
[coveralls]: https://coveralls.io/r/railsadminteam/rails_admin
[codeclimate]: https://codeclimate.com/github/railsadminteam/rails_admin
[semver]: https://dependabot.com/compatibility-score.html?dependency-name=rails_admin&package-manager=bundler&version-scheme=semver
Expand Down Expand Up @@ -98,6 +98,8 @@ This library aims to support and is [tested against][ghactions] the following Ru
- Ruby 2.6
- Ruby 2.7
- Ruby 3.0
- Ruby 3.1
- Ruby 3.2
- [JRuby][]

[jruby]: http://jruby.org/
6 changes: 5 additions & 1 deletion app/controllers/rails_admin/main_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ def respond_to_missing?(sym, include_private)
end

def back_or_index
params[:return_to].presence && params[:return_to].include?(request.host) && (params[:return_to] != request.fullpath) ? params[:return_to] : index_path
allowed_return_to?(params[:return_to].to_s) ? params[:return_to] : index_path
end

def allowed_return_to?(url)
url != request.fullpath && url.start_with?(request.base_url, '/') && !url.start_with?('//')
end

def get_sort_hash(model_config)
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/rails_admin/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def navigation(parent_groups, nodes, level = 0)
nav_icon = node.navigation_icon ? %(<i class="#{node.navigation_icon}"></i>).html_safe : ''
css_classes = ['nav-link']
css_classes.push("nav-level-#{level}") if level > 0
css_classes.push('active') if defined?(@action) && current_action?(@action, model_param)
css_classes.push('active') if @action && current_action?(@action, model_param)
li = content_tag :li, data: {model: model_param} do
link_to nav_icon + " " + node.label_plural, url, class: css_classes.join(' ')
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/rails_admin/main/delete.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h4>
<%= t("admin.form.are_you_sure_you_want_to_delete_the_object", model_name: @abstract_model.pretty_name.downcase) %>
&ldquo;<strong><%= @model_config.with(object: @object).object_label %></strong>&rdquo;
<q><strong><%= @model_config.with(object: @object).object_label %></strong></q>
<%= t("admin.form.all_of_the_following_related_items_will_be_deleted") %>
</h4>
<ul>
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rails_admin/importmap_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def initialize(path = 'confing/importmap.rails_admin.rb')
end

def format
imports = packager.import("rails_admin@#{RailsAdmin::Version.js}")
imports = packager.import("rails_admin@#{RailsAdmin::Version.js}", from: 'jspm.io')

# Use ESM compatible version to work around https://github.com/cljsjs/packages/issues/1579
imports['@popperjs/core'].gsub!('lib/index.js', 'dist/esm/popper.js')
Expand Down
27 changes: 15 additions & 12 deletions lib/generators/rails_admin/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ def configure_for_webpacker5
run "yarn add rails_admin@#{RailsAdmin::Version.js}"
template 'rails_admin.webpacker.js', 'app/javascript/packs/rails_admin.js'
template 'rails_admin.scss.erb', 'app/javascript/stylesheets/rails_admin.scss'
# To work around https://github.com/railsadminteam/rails_admin/issues/3565
add_package_json_field('resolutions', {'rails_admin/@fortawesome/fontawesome-free' => '^5.15.0'})
end

def configure_for_webpack
Expand Down Expand Up @@ -99,28 +101,29 @@ def setup_css(additional_script_entries = {})
else
add_file 'config/initializers/assets.rb', asset_config
end
add_scripts(additional_script_entries.merge({'build:css' => 'sass ./app/assets/stylesheets/rails_admin.scss:./app/assets/builds/rails_admin.css --no-source-map --load-path=node_modules'}))
add_package_json_field('scripts', additional_script_entries.merge({'build:css' => 'sass ./app/assets/stylesheets/rails_admin.scss:./app/assets/builds/rails_admin.css --no-source-map --load-path=node_modules'}), <<~INSTRUCTION)
Taking 'build:css' as an example, if you're already have application.sass.css for the sass build, the resulting script would look like:
sass ./app/assets/stylesheets/application.sass.scss:./app/assets/builds/application.css ./app/assets/stylesheets/rails_admin.scss:./app/assets/builds/rails_admin.css --no-source-map --load-path=node_modules
INSTRUCTION
end

def add_scripts(entries)
display 'Add scripts to package.json'
def add_package_json_field(name, entries, instruction = nil)
display "Add #{name} to package.json"
package = begin
JSON.parse(File.read(File.join(destination_root, 'package.json')))
rescue Errno::ENOENT, JSON::ParserError
{}
end
if package['scripts'] && (package['scripts'].keys & entries.keys).any?
say <<-MESSAGE.gsub(/^ {10}/, ''), :red
You need to merge "scripts": #{JSON.pretty_generate(entries)} into the existing scripts in your package.json .
Taking 'build:css' as an example, if you're already have application.sass.css for the sass build, the resulting script would look like:
sass ./app/assets/stylesheets/application.sass.scss:./app/assets/builds/application.css ./app/assets/stylesheets/rails_admin.scss:./app/assets/builds/rails_admin.css --no-source-map --load-path=node_modules
if package[name] && (package[name].keys & entries.keys).any?
say <<~MESSAGE, :red
You need to merge "#{name}": #{JSON.pretty_generate(entries)} into the existing #{name} in your package.json.#{instruction && "\n#{instruction}"}
MESSAGE
else
package['scripts'] ||= {}
entries.each do |entry, build_script|
package['scripts'][entry] = build_script
package[name] ||= {}
entries.each do |entry, value|
package[name][entry] = value
end
add_file 'package.json', JSON.pretty_generate(package)
add_file 'package.json', "#{JSON.pretty_generate(package)}\n"
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rails_admin/templates/rails_admin.scss.erb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<%= instance_variable_defined?(:@fa_font_path) ? %{$fa-font-path: "#{@fa_font_path}";\n} : '' %>@import "rails_admin/src/rails_admin/styles/base";
<%= @fa_font_path ? %{$fa-font-path: "#{@fa_font_path}";\n} : '' %>@import "rails_admin/src/rails_admin/styles/base";
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import "rails_admin/src/rails_admin/base";
import "../stylesheets/rails_admin.scss";
import "../stylesheets/rails_admin.scss";
3 changes: 3 additions & 0 deletions lib/rails_admin/adapters/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ def unary_operators
case @type
when :boolean
boolean_unary_operators
when :uuid
uuid_unary_operators
when :integer, :decimal, :float
numeric_unary_operators
else
Expand Down Expand Up @@ -230,6 +232,7 @@ def boolean_unary_operators
)
end
alias_method :numeric_unary_operators, :boolean_unary_operators
alias_method :uuid_unary_operators, :boolean_unary_operators

def range_filter(min, max)
if min && max && min == max
Expand Down
2 changes: 1 addition & 1 deletion lib/rails_admin/adapters/active_record/association.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def field_type

def klass
if options[:polymorphic]
polymorphic_parents(:active_record, model.name.to_s, name) || []
polymorphic_parents(:active_record, association.active_record.name.to_s, name) || []
else
association.klass
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rails_admin/adapters/mongoid/association.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def field_type

def klass
if polymorphic? && %i[referenced_in belongs_to].include?(macro)
polymorphic_parents(:mongoid, model.name, name) || []
polymorphic_parents(:mongoid, association.inverse_class_name, name) || []
else
association.klass
end
Expand Down
9 changes: 4 additions & 5 deletions lib/rails_admin/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -364,23 +364,22 @@ def visible_models(bindings)

private

def lchomp(base, arg)
base.to_s.reverse.chomp(arg.to_s.reverse).reverse
end

def viable_models
included_models.collect(&:to_s).presence || begin
@@system_models ||= # memoization for tests
([Rails.application] + Rails::Engine.subclasses.collect(&:instance)).flat_map do |app|
(app.paths['app/models'].to_a + app.config.eager_load_paths).collect do |load_path|
Dir.glob(app.root.join(load_path)).collect do |load_dir|
path_prefix = "#{app.root.join(load_dir)}/"
Dir.glob("#{load_dir}/**/*.rb").collect do |filename|
# app/models/module/class.rb => module/class.rb => module/class => Module::Class
lchomp(filename, "#{app.root.join(load_dir)}/").chomp('.rb').camelize
filename.delete_prefix(path_prefix).chomp('.rb').camelize
end
end
end
end.flatten.reject { |m| m.starts_with?('Concerns::') } # rubocop:disable Style/MultilineBlockChain

@@system_models + @registry.keys.collect(&:to_s)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/rails_admin/config/lazy_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def target
# :
# end
#
# Thus, sort all blocks to excute for a resource by Proc.source_path,
# Thus, sort all blocks to execute for a resource by Proc.source_path,
# to guarantee that blocks from 'config/initializers' evaluate before
# blocks defined within a model class.
unless @deferred_blocks.empty?
Expand Down
2 changes: 1 addition & 1 deletion lib/rails_admin/extensions/paper_trail/auditing_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def listing_for_model_or_object(model, object, query, sort, sort_reverse, all, p
versions = object.nil? ? versions_for_model(model) : object.public_send(model.model.versions_association_name)
versions = versions.where('event LIKE ?', "%#{query}%") if query.present?
versions = versions.order(sort)
versions = all ? versions : versions.send(Kaminari.config.page_method_name, current_page).per(per_page)
versions = versions.send(Kaminari.config.page_method_name, current_page).per(per_page) unless all
paginated_proxies = Kaminari.paginate_array([], total_count: versions.try(:total_count) || versions.count)
paginated_proxies = paginated_proxies.send(
paginated_proxies.respond_to?(Kaminari.config.page_method_name) ? Kaminari.config.page_method_name : :page,
Expand Down
1 change: 0 additions & 1 deletion lib/rails_admin/support/csv_converter.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# encoding: UTF-8
# frozen_string_literal: true

require 'csv'
Expand Down
1 change: 1 addition & 0 deletions lib/rails_admin/support/datetime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Datetime
'%-I' => 'h', # Hour of the day, 12-hour clock (1..12)
'%k' => 'H', # Hour of the day, 24-hour clock (0..23)
'%l' => 'h', # Hour of the day, 12-hour clock (1..12)
'%-l' => 'h', # Hour of the day, 12-hour clock (1..12)
'%M' => 'i', # Minute of the hour (00..59)
'%-M' => 'i', # Minute of the hour (00..59)
'%m' => 'm', # Month of the year (01..12)
Expand Down
2 changes: 1 addition & 1 deletion lib/rails_admin/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module RailsAdmin
class Version
MAJOR = 3
MINOR = 1
PATCH = 0
PATCH = 2
PRE = nil

class << self
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rails_admin",
"version": "3.1.0",
"version": "3.1.2",
"description": "RailsAdmin is a Rails engine that provides an easy-to-use interface for managing your data.",
"homepage": "https://github.com/railsadminteam/rails_admin",
"license": "MIT",
Expand All @@ -15,7 +15,7 @@
},
"dependencies": {
"@babel/runtime": "^7.16.7",
"@fortawesome/fontawesome-free": "^6.1.1",
"@fortawesome/fontawesome-free": ">=5.15.0 <7.0.0",
"@hotwired/turbo-rails": "^7.1.0",
"@popperjs/core": "^2.11.0",
"@rails/ujs": "^6.1.4-1",
Expand Down
1 change: 0 additions & 1 deletion rails_admin.gemspec
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: utf-8
# frozen_string_literal: true

lib = File.expand_path('lib', __dir__)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

it 'works for dynamic names in the controller context' do
RailsAdmin.config do |config|
config.main_app_name = proc { |controller| [Rails.application.engine_name.try(:titleize), controller.params[:action].titleize] }
config.main_app_name = proc { |controller| [Rails.application.engine_name&.titleize, controller.params[:action].titleize] }
end
controller.params[:action] = 'dashboard'
expect(controller.send(:_get_plugin_name)).to eq(['Dummy App Application', 'Dashboard'])
Expand Down
Loading

0 comments on commit d90183f

Please sign in to comment.