Skip to content

Commit

Permalink
Merge branch 'master' of github.com:railsadminteam/rails_admin
Browse files Browse the repository at this point in the history
* 'master' of github.com:railsadminteam/rails_admin: (53 commits)
  fix is_blank and is_present filters for uuid columns (railsadminteam#3629)
  Add support for '%-l' option to Flatpickr. (railsadminteam#3616)
  Fix polymorphic association target classes not set correctly in subclasses
  Fix multiple_carrierwave field spec failing due to mocking
  Fix webpacker build
  Relax Rubocop Metrics/ClassLength threshold
  Version 3.1.2
  Postpone introduction of the new event name `rails_admin:dom_ready`
  Fix install failing with importmap setup
  Fix to show non-eager-loaded models which are explicitly configured
  Change dom_ready event name to use colon as the separator
  Restore caching in RailsAdmin::Config::Model#excluded? (railsadminteam#3587)
  Update GitHub Actions Badge URL
  Optimize file path to class name conversion (railsadminteam#3589)
  Switch to the safe navigation operator in spec files (railsadminteam#3588)
  Fix typo: Envinronment ==> Environment (railsadminteam#3586)
  Enable RuboCop Style/Encoding and apply auto-fixes (railsadminteam#3585)
  Add CI testing for Ruby 3.2 (railsadminteam#3583)
  Version 3.1.1
  Fix some typos (railsadminteam#3580)
  ...
  • Loading branch information
jklimke committed Jun 27, 2023
2 parents 8959c84 + 647347c commit 47cba88
Show file tree
Hide file tree
Showing 120 changed files with 1,158 additions and 504 deletions.
9 changes: 6 additions & 3 deletions .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 Expand Up @@ -54,12 +57,12 @@ jobs:
orm: mongoid
adapter: sqlite3
asset: sprockets
- ruby: jruby
- ruby: jruby-9.3
gemfile: gemfiles/rails_6.1.gemfile
orm: active_record
adapter: mysql2
asset: sprockets
- ruby: jruby
- ruby: jruby-9.3
gemfile: gemfiles/rails_6.1.gemfile
orm: mongoid
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
86 changes: 84 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,89 @@

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

[Full Changelog](https://github.com/railsadminteam/rails_admin/compare/v3.1.0.beta...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

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

### Fixed

- Fix to use defer instead of async to ensure script loading order ([2a40976](https://github.com/railsadminteam/rails_admin/commit/2a409764b13a4e23fc848725c604d318e3375484), [#3513](https://github.com/railsadminteam/rails_admin/issues/3513))
- Improve filter method select box appearance ([#3559](https://github.com/railsadminteam/rails_admin/pull/3559))

## [3.1.0.rc2](https://github.com/railsadminteam/rails_admin/tree/v3.1.0.rc2) - 2022-10-02

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

### Fixed

- Fix sidebar style broken in attempt to support Bootstrap 5.2 ([d7abba4](https://github.com/railsadminteam/rails_admin/commit/d7abba4e8a2e380b4d7f8fb3b37302300af63de5), [#3553](https://github.com/railsadminteam/rails_admin/issues/3553))

## [3.1.0.rc](https://github.com/railsadminteam/rails_admin/tree/v3.1.0.rc) - 2022-09-22

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

### Added

- Add ability to limit filter operators ([be9a75e](https://github.com/railsadminteam/rails_admin/commit/be9a75e504edd9a754157a4ddba590e8a5d14149))
- Support filtering has_one associations ([9657774](https://github.com/railsadminteam/rails_admin/commit/9657774b423912357d8ad8a476b644bb4e36dc30))
- Add ability to set default order of PaperTrail versions ([a1c4c67](https://github.com/railsadminteam/rails_admin/commit/a1c4c673041642ae2a2aa07e3f0555e17be9d940), [#3095](https://github.com/railsadminteam/rails_admin/pull/3095))
- Add block-style DSL support for extension adapters ([951b708](https://github.com/railsadminteam/rails_admin/commit/951b70878cb007d54b4a7aeadd708d4c7668727b))
- Make sidebar navigation collapsible ([e8cb8ed](https://github.com/railsadminteam/rails_admin/commit/e8cb8edd39246bf75ed72295b7832faf5056367c), [#3198](https://github.com/railsadminteam/rails_admin/pull/3198))
- Add ability to show a help text under the search box ([94f16fb](https://github.com/railsadminteam/rails_admin/commit/94f16fb5fdfdaa867173e95820583a68e5a306c5))
- Support for ActiveStorage direct uploads ([e13c7e2](https://github.com/railsadminteam/rails_admin/commit/e13c7e23f789ed2a575eff01b75e52a41cc930b7), [#3296](https://github.com/railsadminteam/rails_admin/issues/3296))

### Changed

- Load ActionText assets statically to enable full-featured setup ([458d0fb](https://github.com/railsadminteam/rails_admin/commit/458d0fb56d79d4fa0a252ad1ca715fd0a3b4b900), [#3251](https://github.com/railsadminteam/rails_admin/issues/3251), [#3386](https://github.com/railsadminteam/rails_admin/issues/3386))
- Change ES Module processing not to affect non-RailsAdmin assets ([f8219bf](https://github.com/railsadminteam/rails_admin/commit/f8219bf3bc508c5e42f5d044cf6355a56726f8b2))
- Change RailsAdmin initialization process to evaluate the config block immediately but load constants lazily ([#3541](https://github.com/railsadminteam/rails_admin/pull/3541), [33e9214](https://github.com/railsadminteam/rails_admin/commit/33e92147214975cddace61737cbbde3117663efe))
- Restore the loading indicator back ([32e6b14](https://github.com/railsadminteam/rails_admin/commit/32e6b1463ecf66b38e6fdc7924426d9753d71eab), [b9ee7f0](https://github.com/railsadminteam/rails_admin/commit/b9ee7f0c202abc7c09726bdaa28536e7ec25127e), [#3500](https://github.com/railsadminteam/rails_admin/issues/3500))

### Fixed

- Fix Bootstrap 5.2 compatibility ([ef76fce](https://github.com/railsadminteam/rails_admin/commit/ef76fcea0b23aed04f6568448cd157ccc9ba30a0))
- Fix filtering select widget options being empty on browser back ([3cffc00](https://github.com/railsadminteam/rails_admin/commit/3cffc0002079bc9d515dc0f3b31513c7166aa2b9))
- Fix RailsAdmin widgets not activated after a validation error ([a604da5](https://github.com/railsadminteam/rails_admin/commit/a604da5670378e57da7b5492afad40e4f4ad083d))
- Fix export action didn't use export section for eager loading ([4cc3f30](https://github.com/railsadminteam/rails_admin/commit/4cc3f304cc0bc4a7dbaf41a6e4e12ecbdbba6e22), [#1954](https://github.com/railsadminteam/rails_admin/issues/1954))
- Fix Dart Sass 2.0 division deprecations ([#3544](https://github.com/railsadminteam/rails_admin/pull/3544), [3a177c2](https://github.com/railsadminteam/rails_admin/commit/3a177c2e8c1b1d782186ee5bbb3c0d44cc4c0060))
- Fix unable to focus elements on modals opened from remote forms ([#3539](https://github.com/railsadminteam/rails_admin/pull/3539), [#3538](https://github.com/railsadminteam/rails_admin/issues/3538))
- Improve pagination appearance on smaller screens ([a2e366e](https://github.com/railsadminteam/rails_admin/commit/a2e366e8839c9046b9f9fde219875a05bc1a66bb), [#3516](https://github.com/railsadminteam/rails_admin/issues/3516))
- Fix the value of submit buttons being lost on submission ([60e1150](https://github.com/railsadminteam/rails_admin/commit/60e115053ea34fa42c3099464106cf6e58dbfa03), [#3513](https://github.com/railsadminteam/rails_admin/issues/3513))
- Fix breaking with a has_and_belongs_to_many association with scope given ([c2bf6db](https://github.com/railsadminteam/rails_admin/commit/c2bf6db41a97b46741bc41b56fd9700c8bdfc9e4), [#2067](https://github.com/railsadminteam/rails_admin/issues/2067))
- Fix nested fields don't toggle properly after pushing 'Add a new ...' button ([d1f1154](https://github.com/railsadminteam/rails_admin/commit/d1f115425c4a8d119fdeb37802fe472ae278918d), [#3528](https://github.com/railsadminteam/rails_admin/issues/3528))

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

Expand Down Expand Up @@ -91,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
44 changes: 37 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,43 @@ Here are some ways _you_ can contribute:

### Running tests locally

To run the test suite, you need PhantomJS and ImageMagick (or GraphicsMagick).

Example on macOS using Homebrew:

brew cask install phantomjs
brew install imagemagick
bundle exec rspec
To run the test suite, you need Google Chrome and ImageMagick (or GraphicsMagick).

Example installation on macOS using Homebrew:

```bash
# install imagemagick:
brew install imagemagick
# install google chrome with cask:
brew install brew-cask
brew cask install google-chrome
```

Example installation on Ubuntu:

```bash
# install imagemagick:
sudo apt update -y && sudo apt install imagemagick -y
# install google chrome:
sudo apt update -y && wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb && sudo apt install ./google-chrome-stable_current_amd64.deb -y
```

Then you need to do this one-time setup:

```bash
bundle install
yarn install
# install dependencies for each appraisal:
bundle exec appraisal install
# precompile assets in the dummy app:
cd spec/dummy_app && yarn install && yarn build && yarn build:css && cd -
```

Then you will be able to run the specs:

```bash
bundle exec appraisal rails-7.0 rspec
```

### Tests run against multiple versions of Rails

Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ source 'https://rubygems.org'

gem 'appraisal', '>= 2.0'
gem 'devise'
gem 'net-smtp', require: false
gem 'rails'
gem 'webpacker', require: false
gem 'webrick', '~> 1.7'
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/
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,11 @@
//= require 'rails_admin/sidescroll'
//= require 'rails_admin/ui'
//= require 'rails_admin/custom/ui'

<% if defined?(ActiveStorage) %>
//= require activestorage
<% end %>
<% if defined?(ActionText) && Rails.gem_version >= Gem::Version.new('7.0') %>
//= require trix
//= require actiontext
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@

@import "rails_admin/styles/base/theming";
@import "rails_admin/custom/theming";

<% if defined?(ActionText) && Rails.gem_version >= Gem::Version.new('7.0') %>
@import "trix";
<% end %>
3 changes: 2 additions & 1 deletion app/controllers/rails_admin/main_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ def check_for_cancel
end

def get_collection(model_config, scope, pagination)
eager_loads = model_config.list.fields.flat_map(&:eager_load_values)
section = @action.key == :export ? model_config.export : model_config.list
eager_loads = section.fields.flat_map(&:eager_load_values)
options = {}
options = options.merge(page: (params[Kaminari.config.param_name] || 1).to_i, per: (params[:per] || model_config.list.items_per_page)) if pagination
options = options.merge(include: eager_loads) unless eager_loads.blank?
Expand Down
36 changes: 30 additions & 6 deletions app/helpers/rails_admin/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def main_navigation

label = navigation_label || t('admin.misc.navigation')

%(<li class='dropdown-header'>#{label}</li>#{li_stack}) if li_stack.present?
collapsible_stack(label, 'main', li_stack)
end.join.html_safe
end

Expand All @@ -101,18 +101,17 @@ def root_navigation
end.join.html_safe
label ||= t('admin.misc.root_navigation')

%(<li class='dropdown-header'>#{label}</li>#{li_stack}) if li_stack.present?
collapsible_stack(label, 'action', li_stack)
end.join.html_safe
end

def static_navigation
li_stack = RailsAdmin::Config.navigation_static_links.collect do |title, url|
content_tag(:li, link_to(title.to_s, url, target: '_blank', rel: 'noopener noreferrer', class: 'nav-link'))
end.join
end.join.html_safe

label = RailsAdmin::Config.navigation_static_label || t('admin.misc.navigation_static_label')
li_stack = %(<li class='dropdown-header'>#{label}</li>#{li_stack}).html_safe if li_stack.present?
li_stack
collapsible_stack(label, 'static', li_stack) || ''
end

def navigation(parent_groups, nodes, level = 0)
Expand All @@ -123,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 Expand Up @@ -218,6 +217,15 @@ def handle_asset_dependency_error
raise e
end

# Workaround for https://github.com/rails/rails/issues/31325
def image_tag(source, options = {})
if %w[ActiveStorage::Variant ActiveStorage::VariantWithRecord ActiveStorage::Preview].include? source.class.to_s
super main_app.route_for(ActiveStorage.resolve_model_to_route, source), options
else
super
end
end

private

def edit_user_link_label
Expand All @@ -232,5 +240,21 @@ def edit_user_link_label
def gravatar_url(email)
"https://secure.gravatar.com/avatar/#{Digest::MD5.hexdigest email}?s=30"
end

def collapsible_stack(label, class_prefix, li_stack)
return nil unless li_stack.present?

collapse_classname = "#{class_prefix}-#{Digest::MD5.hexdigest(label)[0..7]}"
content_tag(:li, class: 'mb-1') do
content_tag(:button, 'aria-expanded': true, class: 'btn btn-toggle align-items-center rounded', data: {bs_toggle: "collapse", bs_target: ".sidebar .#{collapse_classname}"}) do
content_tag(:i, '', class: 'fas fa-chevron-down') + html_escape(' ' + label)
end +
content_tag(:div, class: "collapse show #{collapse_classname}") do
content_tag(:ul, class: 'btn-toggle-nav list-unstyled fw-normal pb-1') do
li_stack
end
end
end
end
end
end
20 changes: 5 additions & 15 deletions app/helpers/rails_admin/main_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,18 @@ def ordered_filters
def ordered_filter_options
if ordered_filters
@ordered_filter_options ||= ordered_filters.map do |duplet|
options = {index: duplet[0]}
filter_for_field = duplet[1]
filter_name = filter_for_field.keys.first
filter_hash = filter_for_field.values.first
unless (field = filterable_fields.find { |f| f.name == filter_name.to_sym })
raise "#{filter_name} is not currently filterable; filterable fields are #{filterable_fields.map(&:name).join(', ')}"
end

case field.type
when :enum
options[:select_options] = options_for_select(field.with(object: @abstract_model.model.new).enum, filter_hash['v'])
when :date, :datetime, :time
options[:datetimepicker_options] = field.datepicker_options
end
options[:label] = field.label
options[:name] = field.name
options[:type] = field.type
options[:value] = filter_hash['v']
options[:label] = field.label
options[:operator] = filter_hash['o'] || field.default_filter_operator
options[:required] = field.required
options
field.filter_options.merge(
index: duplet[0],
operator: filter_hash['o'] || field.default_filter_operator,
value: filter_hash['v'],
)
end
end
end
Expand Down
Loading

0 comments on commit 47cba88

Please sign in to comment.