thecore_ui_rails_admin 3.2.21 → 3.3.0
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 +4 -4
- data/app/assets/javascripts/rails_admin/custom/ui.js.erb +10 -0
- data/app/models/saved_filter.rb +11 -0
- data/app/views/rails_admin/main/load_filters.html.erb +22 -0
- data/app/views/rails_admin/main/save_filter.html.erb +36 -0
- data/config/initializers/after_initialize.rb +2 -0
- data/config/initializers/concern_user.rb +1 -0
- data/config/locales/en.rails_admin.yml +12 -0
- data/config/locales/it.rails_admin.yml +12 -0
- data/db/migrate/20250429155934_create_saved_filters.rb +13 -0
- data/db/migrate/20250430081805_rename_model_name_to_abstract_model_name_in_saved_filter.rb +13 -0
- data/lib/collection_actions/load_filters.rb +29 -0
- data/lib/collection_actions/save_filters.rb +31 -0
- data/lib/rails_admin_filter_controller_helper.rb +52 -0
- data/lib/thecore_ui_rails_admin/version.rb +1 -1
- data/lib/thecore_ui_rails_admin.rb +2 -0
- metadata +11 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69880a90a1c29f74d6118b9bd97e6a60bb323bdc98f3a32332f0bdba3771f0ed
|
4
|
+
data.tar.gz: 6fde8617dea6926e4bb3c30f1df5c2d7ef814d480310087835f40850c664afa4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f173668754ad018a7c267d35f630cd29cfb23eae696f267f8aba3203890123012637a2013a29b158ff6717d2614f45ad5eaea6c3ab8bee4cd27cbd98e036b7f
|
7
|
+
data.tar.gz: 256a28d9e7a4cd7e89b7a14280529cedd1e2db417f4f737c6e580d5657933afbf5e341d43ffb69f4466abbaa466cb18544f452c404a3ed3ca2e6159b7bb89fa6
|
@@ -28,6 +28,16 @@ $(document).on('turbo:load', function (event) {
|
|
28
28
|
// Add the app_logo before the Title
|
29
29
|
const customer_logo_path = "<%= asset_path('app_logo.svg') %>";
|
30
30
|
$(".navbar-brand").prepend(`<img class="navbar-brand-logo" alt="Customer Logo" src="${customer_logo_path}"/>`);
|
31
|
+
|
32
|
+
//This presumes the existence of the save_filter collection custom action for rails_admin
|
33
|
+
const saveFilterLinks = document.querySelectorAll("li.nav-item.icon.save_filters_collection_link > a")
|
34
|
+
saveFilterLinks.forEach(link => {
|
35
|
+
const currentQuery = window.location.search;
|
36
|
+
if (currentQuery) {
|
37
|
+
// Remove the existing query string from the link
|
38
|
+
link.href = link.href.split('?')[0] + currentQuery;
|
39
|
+
}
|
40
|
+
});
|
31
41
|
});
|
32
42
|
|
33
43
|
const sidepanel = "body > div.container-fluid > div > div.col-sm-3.col-md-2.flex-wrap.p-0"
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# app/models/saved_filter.rb
|
2
|
+
class SavedFilter < ApplicationRecord
|
3
|
+
belongs_to :admin_user, optional:true, class_name: 'User', foreign_key: :admin_user_id
|
4
|
+
|
5
|
+
validates :model_name, :name, :query_string, presence: true
|
6
|
+
|
7
|
+
rails_admin do
|
8
|
+
# Set invisible
|
9
|
+
visible false
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<!-- START app/views/rails_admin/main/save_filter.html.erb -->
|
2
|
+
<!-- In Rails Admin Bootstrap, show all the filters which are listed in @saved_filters -->
|
3
|
+
|
4
|
+
<div class="row">
|
5
|
+
<div class="col-sm-12">
|
6
|
+
<h3>Saved Filters</h3>
|
7
|
+
<ul class="list-group">
|
8
|
+
<% @saved_filters.each do |filter| %>
|
9
|
+
<li class="list-group-item">
|
10
|
+
<%= filter.name %>
|
11
|
+
<a href="<%= index_path(model_name: filter.abstract_model_name.underscore) %>?<%= filter.query_string %>" class="float-right">
|
12
|
+
<i class="fas fa-filter"></i>
|
13
|
+
</a>
|
14
|
+
<a href="<%= load_filters_path %>?id_to_delete=<%= filter.id %>" class="float-right" data-method="delete" data-confirm="Are you sure?">
|
15
|
+
<i class="fas fa-trash"></i>
|
16
|
+
</a>
|
17
|
+
</li>
|
18
|
+
<% end %>
|
19
|
+
</ul>
|
20
|
+
</div>
|
21
|
+
</div>
|
22
|
+
<!-- END app/views/rails_admin/main/save_filter.html.erb -->
|
@@ -0,0 +1,36 @@
|
|
1
|
+
<!-- START app/views/rails_admin/main/save_filter.html.erb -->
|
2
|
+
<div class="form-horizontal">
|
3
|
+
<form method="post" action="">
|
4
|
+
<%= hidden_field_tag :authenticity_token, form_authenticity_token %>
|
5
|
+
<%= hidden_field_tag :query_string, @query_string %>
|
6
|
+
|
7
|
+
<% if @query_string.present? %>
|
8
|
+
<div class="form-group row">
|
9
|
+
<label class="col-sm-2 col-form-label" for="filter_name">Filter Name</label>
|
10
|
+
<div class="col-sm-10">
|
11
|
+
<input type="text" name="filter_name" id="filter_name" class="form-control" required />
|
12
|
+
</div>
|
13
|
+
</div>
|
14
|
+
<% end %>
|
15
|
+
|
16
|
+
<!-- A row to show an urldecoded version of the filter in @query_string -->
|
17
|
+
<div class="form-group row">
|
18
|
+
<label class="col-sm-2 col-form-label" for="filter_query">Filter Query</label>
|
19
|
+
<div class="col-sm-10">
|
20
|
+
<%= @query_html %>
|
21
|
+
</div>
|
22
|
+
</div>
|
23
|
+
|
24
|
+
<!-- Allow this button only if @query_string is not empty -->
|
25
|
+
<% if @query_string.present? %>
|
26
|
+
<div class="form-group row">
|
27
|
+
<div class="col-sm-10 offset-sm-2">
|
28
|
+
<button type="submit" class="btn btn-primary">
|
29
|
+
<i class="fas fa-save"></i> Save Filter
|
30
|
+
</button>
|
31
|
+
</div>
|
32
|
+
</div>
|
33
|
+
<% end %>
|
34
|
+
</form>
|
35
|
+
</div>
|
36
|
+
<!-- END app/views/rails_admin/main/save_filter.html.erb -->
|
@@ -15,5 +15,17 @@ en:
|
|
15
15
|
menu: Change Password
|
16
16
|
success: Your password has been changed successfully
|
17
17
|
error: Error! %{errors}
|
18
|
+
save_filters:
|
19
|
+
success: Filters saved successfully
|
20
|
+
error: Error saving filters
|
21
|
+
title: Save Filters
|
22
|
+
breadcrumb: Save Filters
|
23
|
+
menu: Save Filters
|
24
|
+
load_filters:
|
25
|
+
success: Filters loaded successfully
|
26
|
+
error: Error loading filters
|
27
|
+
title: Load Filters
|
28
|
+
breadcrumb: Load Filters
|
29
|
+
menu: Load Filters
|
18
30
|
scopes:
|
19
31
|
_all: All
|
@@ -15,5 +15,17 @@ it:
|
|
15
15
|
menu: Cambia Password
|
16
16
|
success: La tua password è stata cambiata con successo
|
17
17
|
error: Attenzione! %{errors}
|
18
|
+
save_filters:
|
19
|
+
success: Filtri salvati con successo
|
20
|
+
error: Errore durante il salvataggio dei filtri
|
21
|
+
title: Salva Filtri
|
22
|
+
breadcrumb: Salva Filtri
|
23
|
+
menu: Salva Filtri
|
24
|
+
load_filters:
|
25
|
+
success: Filtri caricati con successo
|
26
|
+
error: Errore durante il caricamento dei filtri
|
27
|
+
title: Carica Filtri
|
28
|
+
breadcrumb: Carica Filtri
|
29
|
+
menu: Carica Filtri
|
18
30
|
scopes:
|
19
31
|
_all: Tutti
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# db/migrate/xxxx_create_saved_filters.rb
|
2
|
+
class CreateSavedFilters < ActiveRecord::Migration[7.0]
|
3
|
+
def change
|
4
|
+
create_table :saved_filters do |t|
|
5
|
+
t.string :model_name
|
6
|
+
t.string :name
|
7
|
+
t.text :query_string
|
8
|
+
t.references :admin_user, foreign_key: { to_table: :users }, null: true
|
9
|
+
|
10
|
+
t.timestamps
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class RenameModelNameToAbstractModelNameInSavedFilter < ActiveRecord::Migration[7.2]
|
2
|
+
def change
|
3
|
+
rename_column :saved_filters, :model_name, :abstract_model_name
|
4
|
+
# ThecoreUiRailsAdmin::SavedFilter.reset_column_information
|
5
|
+
# ThecoreUiRailsAdmin::SavedFilter.all.each do |saved_filter|
|
6
|
+
# saved_filter.update_column(:abstract_model_name, saved_filter.model_name)
|
7
|
+
# end
|
8
|
+
rescue ActiveRecord::StatementInvalid => e
|
9
|
+
puts "Error: #{e.message}"
|
10
|
+
ensure
|
11
|
+
# ThecoreUiRailsAdmin::SavedFilter.reset_column_information
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
RailsAdmin::Config::Actions.add_action "load_filters", :base, :collection do
|
4
|
+
link_icon 'fas fa-upload'
|
5
|
+
|
6
|
+
http_methods [:get, :delete]
|
7
|
+
|
8
|
+
# Visible only for the User model
|
9
|
+
visible do
|
10
|
+
authorized?
|
11
|
+
end
|
12
|
+
# Adding the controller which is needed to compute calls from the ui
|
13
|
+
controller do
|
14
|
+
proc do # This is needed because we need that this code is re-evaluated each time is called
|
15
|
+
# Load all the filters which have the current abstract_model_name
|
16
|
+
if params[:id_to_delete]
|
17
|
+
# Delete the filter
|
18
|
+
@saved_filter = SavedFilter.find(params[:id_to_delete])
|
19
|
+
@saved_filter.destroy
|
20
|
+
flash[:success] = "Filter deleted!"
|
21
|
+
# redirect_to back_or_index
|
22
|
+
end
|
23
|
+
# Load the filter
|
24
|
+
Rails.logger.debug "Loading filters for model: #{params[:model_name]}"
|
25
|
+
@saved_filters = SavedFilter.where(abstract_model_name: params[:model_name].classify)
|
26
|
+
Rails.logger.debug "Saved filters: #{@saved_filters.inspect}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
RailsAdmin::Config::Actions.add_action "save_filters", :base, :collection do
|
4
|
+
link_icon 'fas fa-floppy-disk'
|
5
|
+
|
6
|
+
http_methods [:get, :post]
|
7
|
+
|
8
|
+
# Visible only for the User model
|
9
|
+
visible do
|
10
|
+
authorized?
|
11
|
+
end
|
12
|
+
# Adding the controller which is needed to compute calls from the ui
|
13
|
+
controller do
|
14
|
+
proc do # This is needed because we need that this code is re-evaluated each time is called
|
15
|
+
if request.post?
|
16
|
+
SavedFilter.create!(
|
17
|
+
abstract_model_name: @abstract_model,
|
18
|
+
name: params[:filter_name],
|
19
|
+
query_string: request.referer.split('?')[1] # Get filters from referrer
|
20
|
+
)
|
21
|
+
flash[:success] = "Filter saved!"
|
22
|
+
redirect_to back_or_index
|
23
|
+
else
|
24
|
+
@query_string = request.referer.split('?')[1] # Get filters from referrer
|
25
|
+
@query_html = RailsAdminFilterControllerHelper.filters_html_list(@query_string, @abstract_model).html_safe
|
26
|
+
@model_name = @abstract_model
|
27
|
+
render :save_filter
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# app/helpers/rails_admin_filter_helper.rb
|
2
|
+
module RailsAdminFilterControllerHelper
|
3
|
+
def self.filters_html_list(query_string, model_name)
|
4
|
+
params = Rack::Utils.parse_nested_query(query_string)
|
5
|
+
return '<p>No filters to be saved</p>'.html_safe unless params['f'].is_a?(Hash)
|
6
|
+
|
7
|
+
model_class = model_name.to_s.camelize.safe_constantize
|
8
|
+
return '<p>Unknown model</p>'.html_safe unless model_class
|
9
|
+
|
10
|
+
abstract_model = RailsAdmin::AbstractModel.new(model_class)
|
11
|
+
|
12
|
+
filters = []
|
13
|
+
|
14
|
+
params['f'].each do |field_name, condition_group|
|
15
|
+
# Use Rails i18n to get field label
|
16
|
+
label = model_class.human_attribute_name(field_name)
|
17
|
+
|
18
|
+
condition_group.each do |_idx, condition|
|
19
|
+
op_key = condition['o']
|
20
|
+
value = condition['v']
|
21
|
+
|
22
|
+
next if op_key.blank? || value.blank?
|
23
|
+
|
24
|
+
op_label = rails_admin_operator_label(op_key, abstract_model.properties.find { |p| p.name.to_s == field_name.to_s })
|
25
|
+
|
26
|
+
value_str = case value
|
27
|
+
when Array
|
28
|
+
value.join(', ')
|
29
|
+
when 'true'
|
30
|
+
'Yes'
|
31
|
+
when 'false'
|
32
|
+
'No'
|
33
|
+
else
|
34
|
+
value.to_s
|
35
|
+
end
|
36
|
+
|
37
|
+
filters << "#{label} #{op_label} #{value_str}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
filters.join('<br>').html_safe
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.rails_admin_operator_label(op_key, field = nil)
|
45
|
+
scope = [:admin, :filters, :operators]
|
46
|
+
type = field&.type&.to_sym
|
47
|
+
key = "#{op_key}_#{type}".to_sym
|
48
|
+
|
49
|
+
# Try field-specific operator label, then general one
|
50
|
+
I18n.t(key, scope: scope, default: I18n.t(op_key.to_sym, scope: scope, default: op_key.humanize))
|
51
|
+
end
|
52
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thecore_ui_rails_admin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriele Tassoni
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: thecore_ui_commons
|
@@ -77,6 +77,7 @@ files:
|
|
77
77
|
- app/assets/stylesheets/rails_admin/custom/thecore/variables.scss
|
78
78
|
- app/assets/stylesheets/rails_admin/custom/theming.scss
|
79
79
|
- app/assets/stylesheets/rails_admin/custom/variables.scss
|
80
|
+
- app/models/saved_filter.rb
|
80
81
|
- app/views/layouts/rails_admin/_controller_assets.html.erb
|
81
82
|
- app/views/layouts/rails_admin/application.html.erb
|
82
83
|
- app/views/rails_admin/main/_dashboard_block.html.erb
|
@@ -84,6 +85,8 @@ files:
|
|
84
85
|
- app/views/rails_admin/main/active_job_monitor.html.erb
|
85
86
|
- app/views/rails_admin/main/change_password.html.erb
|
86
87
|
- app/views/rails_admin/main/dashboard.html.erb
|
88
|
+
- app/views/rails_admin/main/load_filters.html.erb
|
89
|
+
- app/views/rails_admin/main/save_filter.html.erb
|
87
90
|
- config/initializers/abilities.rb
|
88
91
|
- config/initializers/add_to_db_migrations.rb
|
89
92
|
- config/initializers/after_initialize.rb
|
@@ -108,9 +111,14 @@ files:
|
|
108
111
|
- config/locales/it.rollincode.yml
|
109
112
|
- config/routes.rb
|
110
113
|
- db/migrate/20250206222412_add_locale_to_user.rb
|
114
|
+
- db/migrate/20250429155934_create_saved_filters.rb
|
115
|
+
- db/migrate/20250430081805_rename_model_name_to_abstract_model_name_in_saved_filter.rb
|
111
116
|
- db/seeds.rb
|
117
|
+
- lib/collection_actions/load_filters.rb
|
118
|
+
- lib/collection_actions/save_filters.rb
|
112
119
|
- lib/member_actions/change_password.rb
|
113
120
|
- lib/rails_admin_abstract_controller.rb
|
121
|
+
- lib/rails_admin_filter_controller_helper.rb
|
114
122
|
- lib/root_actions/active_job_monitor.rb
|
115
123
|
- lib/tasks/thecore_ui_rails_admin_tasks.rake
|
116
124
|
- lib/thecore_ui_rails_admin.rb
|
@@ -137,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
145
|
- !ruby/object:Gem::Version
|
138
146
|
version: '0'
|
139
147
|
requirements: []
|
140
|
-
rubygems_version: 3.6.
|
148
|
+
rubygems_version: 3.6.7
|
141
149
|
specification_version: 4
|
142
150
|
summary: Thecore Backend UI based on Rails Admin.
|
143
151
|
test_files: []
|