Skip to content

Commit 6878670

Browse files
Upgrade Bootstrap to 5.1.3 with migrating datetimepicker to Flatpickr (#3455)
* Upgrade Bootstrap to 5.1.3 Closes #3083 * Upgrade vendored Bootstrap as well Also removed old theming functionality, since existing ones are not compatible with Bootstrap 5 * Migrate datetimepicker widget to flatpickr * Reflect review and minor fix - Fix inconsistent breakpoint - Remove debug stuffs * Apply form-control-sm to make datepicker field have the same size with other inputs Co-authored-by: Alex Schmitt <codealchemy@users.noreply.github.com> * Reflect review suggetions - Prevent `true` showing up as a css class - form-control-sm must come with form-control: https://getbootstrap.com/docs/5.1/forms/form-control/#sizing - btn-small didn't have any effect - Fix action menu having too narrow gap between icon and text * Fix invalid closing tag </input> * Update styles in Export and History action * Fix spec issue, with removing the workaround https://github.com/railsadminteam/rails_admin/runs/4747523252?check_suite_focus=true * Add additional datetime format used somewhere in rails-i18n * ProvidePlugin is no longer necessary since all JS dependencies are ES module ready now Co-authored-by: Alex Schmitt <codealchemy@users.noreply.github.com>
1 parent cefa23c commit 6878670

228 files changed

Lines changed: 27361 additions & 34469 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Rakefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,14 @@ rescue LoadError
2222
end
2323

2424
task default: %i[spec rubocop]
25+
26+
namespace :vendorize do
27+
desc 'Tasks for vendorizing assets'
28+
29+
task :flatpickr do
30+
Dir.chdir(__dir__)
31+
flatpickr = File.read('node_modules/flatpickr/dist/flatpickr.js')
32+
locales = Dir.glob('node_modules/flatpickr/dist/l10n/*.js').map { |f| File.read(f) }
33+
File.write('vendor/assets/javascripts/rails_admin/flatpickr-with-locales.js', ([flatpickr] + locales).join("\n"))
34+
end
35+
end

app/assets/javascripts/rails_admin.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
//= require 'rails_admin/jquery-ui/effect'
66
//= require 'rails_admin/jquery-ui/widgets/sortable'
77
//= require 'rails_admin/jquery-ui/widgets/autocomplete'
8-
//= require 'rails_admin/moment-with-locales'
9-
//= require 'rails_admin/bootstrap-datetimepicker'
10-
//= require 'rails_admin/bootstrap/bootstrap'
8+
//= require 'rails_admin/flatpickr-with-locales'
9+
//= require 'rails_admin/popper'
10+
//= require 'rails_admin/bootstrap'
1111

1212
//= require 'rails_admin/filter-box'
1313
//= require 'rails_admin/filtering-multiselect'
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
@charset "UTF-8";
2+
3+
/*** Variables ***/
4+
5+
@import "rails_admin/custom/variables";
6+
@import "rails_admin/styles/base/variables";
7+
8+
/*** Mixins ***/
9+
10+
@import "rails_admin/styles/base/mixins";
11+
@import "rails_admin/custom/mixins";
12+
13+
/*** Bootstrap ***/
14+
15+
@import "rails_admin/bootstrap/bootstrap";
16+
17+
/*** Libraries ***/
18+
19+
@import "rails_admin/flatpickr";
20+
@import "rails_admin/styles/filtering-select";
21+
@import "rails_admin/styles/filtering-multiselect";
22+
@import "rails_admin/styles/widgets";
23+
24+
/*** Font-awesome ***/
25+
26+
@import "rails_admin/font-awesome";
27+
28+
/*** RailsAdmin Theming ***/
29+
30+
@import "rails_admin/styles/base/theming";
31+
@import "rails_admin/custom/theming";

app/assets/stylesheets/rails_admin.scss.erb

Lines changed: 0 additions & 76 deletions
This file was deleted.

app/helpers/rails_admin/application_helper.rb

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def edit_user_link
2828
content_tag(:span, _current_user.email),
2929
].compact.join.html_safe
3030
if (edit_action = RailsAdmin::Config::Actions.find(:edit, controller: controller, abstract_model: abstract_model, object: _current_user)).try(:authorized?)
31-
link_to content, rails_admin.url_for(action: edit_action.action_name, model_name: abstract_model.to_param, id: _current_user.id, controller: 'rails_admin/main')
31+
link_to content, rails_admin.url_for(action: edit_action.action_name, model_name: abstract_model.to_param, id: _current_user.id, controller: 'rails_admin/main'), class: 'nav-link'
3232
else
3333
content_tag :span, content
3434
end
@@ -87,7 +87,7 @@ def root_navigation
8787
url = rails_admin.url_for(action: node.action_name, controller: 'rails_admin/main')
8888
nav_icon = node.link_icon ? %(<i class="#{node.link_icon}"></i>).html_safe : ''
8989
content_tag :li do
90-
link_to nav_icon + " " + wording_for(:menu, node), url, class: "pjax"
90+
link_to nav_icon + " " + wording_for(:menu, node), url, class: "nav-link pjax"
9191
end
9292
end.join.html_safe
9393
label ||= t('admin.misc.root_navigation')
@@ -98,7 +98,7 @@ def root_navigation
9898

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

104104
label = RailsAdmin::Config.navigation_static_label || t('admin.misc.navigation_static_label')
@@ -114,7 +114,7 @@ def navigation(parent_groups, nodes, level = 0)
114114
level_class = " nav-level-#{level}" if level > 0
115115
nav_icon = node.navigation_icon ? %(<i class="#{node.navigation_icon}"></i>).html_safe : ''
116116
li = content_tag :li, data: {model: model_param} do
117-
link_to nav_icon + node.label_plural, url, class: "pjax#{level_class}"
117+
link_to nav_icon + node.label_plural, url, class: "nav-link pjax#{level_class}"
118118
end
119119
child_nodes = parent_groups[abstract_model.model_name]
120120
child_nodes ? li + navigation(parent_groups, child_nodes, level + 1) : li
@@ -130,7 +130,7 @@ def breadcrumb(action = @action, _acc = [])
130130
parent_actions.collect do |a|
131131
am = a.send(:eval, 'bindings[:abstract_model]')
132132
o = a.send(:eval, 'bindings[:object]')
133-
content_tag(:li, class: current_action?(a, am, o) && 'active') do
133+
content_tag(:li, class: ['breadcrumb-item', current_action?(a, am, o) && 'active']) do
134134
if current_action?(a, am, o)
135135
wording_for(:breadcrumb, a, am, o)
136136
elsif a.http_methods.include?(:get)
@@ -151,19 +151,18 @@ def menu_for(parent, abstract_model = nil, object = nil, only_icon = false)
151151
actions = actions(parent, abstract_model, object).select { |a| a.http_methods.include?(:get) && a.show_in_menu }
152152
actions.collect do |action|
153153
wording = wording_for(:menu, action)
154-
li_class = ['icon', "#{action.key}_#{parent}_link"].
155-
concat(current_action?(action) ? ['active'] : []).
154+
li_class = ['nav-item', 'icon', "#{action.key}_#{parent}_link"].
156155
concat(action.enabled? ? [] : ['disabled'])
157156
content_tag(:li, {class: li_class}.merge(only_icon ? {title: wording, rel: 'tooltip'} : {})) do
158-
label = content_tag(:i, '', {class: action.link_icon}) + content_tag(:span, wording, (only_icon ? {style: 'display:none'} : {}))
157+
label = content_tag(:i, '', {class: action.link_icon}) + ' ' + content_tag(:span, wording, (only_icon ? {style: 'display:none'} : {}))
159158
if action.enabled? || !only_icon
160159
href =
161160
if action.enabled?
162161
rails_admin.url_for(action: action.action_name, controller: 'rails_admin/main', model_name: abstract_model.try(:to_param), id: (object.try(:persisted?) && object.try(:id) || nil))
163162
else
164163
'javascript:void(0)'
165164
end
166-
content_tag(:a, label, {href: href, target: action.link_target}.merge(action.pjax? ? {class: ['pjax']} : {}))
165+
content_tag(:a, label, {href: href, target: action.link_target, class: ['nav-link', action.pjax? && 'pjax', current_action?(action) && 'active', !action.enabled? && 'disabled'].compact})
167166
else
168167
content_tag(:span, label)
169168
end
@@ -175,12 +174,12 @@ def bulk_menu(abstract_model = @abstract_model)
175174
actions = actions(:bulkable, abstract_model)
176175
return '' if actions.empty?
177176

178-
content_tag :li, class: 'dropdown', style: 'float:right' do
179-
content_tag(:a, class: 'dropdown-toggle', data: {toggle: 'dropdown'}, href: '#') { t('admin.misc.bulk_menu_title').html_safe + ' ' + '<b class="caret"></b>'.html_safe } +
177+
content_tag :li, class: 'nav-item dropdown dropdown-menu-end' do
178+
content_tag(:a, class: 'nav-link dropdown-toggle', data: {'bs-toggle': 'dropdown'}, href: '#') { t('admin.misc.bulk_menu_title').html_safe + ' ' + '<b class="caret"></b>'.html_safe } +
180179
content_tag(:ul, class: 'dropdown-menu', style: 'left:auto; right:0;') do
181180
actions.collect do |action|
182181
content_tag :li do
183-
link_to wording_for(:bulk_link, action, abstract_model), '#', class: 'bulk-link', data: {action: action.action_name}
182+
link_to wording_for(:bulk_link, action, abstract_model), '#', class: 'dropdown-item bulk-link', data: {action: action.action_name}
184183
end
185184
end.join.html_safe
186185
end

app/helpers/rails_admin/form_builder.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ def field_wrapper_for(field, nested_in)
4343
# do not show nested field if the target is the origin
4444
return if nested_field_association?(field, nested_in)
4545

46-
@template.content_tag(:div, class: "form-group control-group #{field.type_css_class} #{field.css_class} #{'error' if field.errors.present?}", id: "#{dom_id(field)}_field") do
46+
@template.content_tag(:div, class: "control-group row mb-3 #{field.type_css_class} #{field.css_class} #{'error' if field.errors.present?}", id: "#{dom_id(field)}_field") do
4747
if field.label
48-
label(field.method_name, field.label, class: 'col-sm-2 control-label') +
48+
label(field.method_name, field.label, class: 'col-sm-2 col-form-label text-md-end') +
4949
(field.nested_form ? field_for(field) : input_for(field))
5050
else
5151
field.nested_form ? field_for(field) : input_for(field)
@@ -68,7 +68,7 @@ def errors_for(field)
6868
end
6969

7070
def help_for(field)
71-
field.help.present? ? @template.content_tag(:span, field.help, class: 'help-block') : ''.html_safe
71+
field.help.present? ? @template.content_tag(:div, field.help, class: 'form-text') : ''.html_safe
7272
end
7373

7474
def field_for(field)

app/helpers/rails_admin/main_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def ordered_filter_options
5252
when :enum
5353
options[:select_options] = options_for_select(field.with(object: @abstract_model.model.new).enum, filter_hash['v'])
5454
when :date, :datetime, :time
55-
options[:datetimepicker_format] = field.momentjs_format
55+
options[:datetimepicker_options] = field.datepicker_options
5656
end
5757
options[:label] = field.label
5858
options[:name] = field.name
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
<li class="disabled">
2-
<a href="#">
1+
<li class="page-item disabled">
2+
<a href="#" class="page-link">
33
<%= raw(t 'admin.pagination.truncate') %>
44
</a>
55
</li>
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<% if current_page.last? %>
2-
<li class="next disabled">
3-
<%= link_to raw(t 'admin.pagination.next'), '#' %>
2+
<li class="page-item next disabled">
3+
<%= link_to raw(t 'admin.pagination.next'), '#', class: 'page-link' %>
44
</li>
55
<% else %>
6-
<li class="next">
7-
<%= link_to raw(t 'admin.pagination.next'), url, class: (remote ? 'pjax' : '') %>
6+
<li class="page-item next">
7+
<%= link_to raw(t 'admin.pagination.next'), url, class: ['page-link', ('pjax' if remote)].compact %>
88
</li>
99
<% end %>
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<% if page.current? %>
2-
<li class="active">
3-
<%= link_to page, url, class: (remote ? 'pjax' : '') %>
2+
<li class="page-item active">
3+
<%= link_to page, url, class: ['page-link', ('pjax' if remote)].compact %>
44
</li>
55
<% else %>
6-
<li>
7-
<%= link_to page, url, class: (remote ? 'pjax' : '') %>
6+
<li class="page-item">
7+
<%= link_to page, url, class: ['page-link', ('pjax' if remote)].compact %>
88
</li>
99
<% end %>

0 commit comments

Comments
 (0)