thecore_ui_rails_admin 3.2.14 → 3.2.16

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cb07f74d47545d610485c94eacf90a0e434a1257bdf21dff10035a3ab6fe3406
4
- data.tar.gz: '0940afcd49c9058d998bcb818c3bf5c8ccd98abebed9ba99dfb7f17bea14c60e'
3
+ metadata.gz: 1fe9b6993cff6a3c3d8ee78aed6cd6d1bd98aeaeabf257860a50e9382f52d389
4
+ data.tar.gz: e525e46b1a3b393084995a69c7d5acd211508966fe32affb126f09b46a31a0ab
5
5
  SHA512:
6
- metadata.gz: 93c82926aed8c38b369f1998a55e3e8c9030c7d6e8c32555b04dc75567301d72b49364a733f335b368c1b1fd7963d402d4ad0707033258e25f333b0e63052e1b
7
- data.tar.gz: 548b8f38f240847150a028a72779381d074eabe13e065a8dec882619f0fc8577ff1e2a428cb564278955a692560d911e7f3f02bae8c5e4239ab27e87f1a89618
6
+ metadata.gz: c614b3909fb97866672972fb3ac944f688e82d869ac1fe9fd49004a43e1d78d2f8bad232b5428778fe9aa63972c20ed41afd9341e23eadb3b605c64d519f056c
7
+ data.tar.gz: a4ae887f09b03705cc39e87b6a630ce901634c3bb4dfd6fdc91c397c505c7a08eae3bf8446f16535dcc1a15445d205f050383b9a369544612ec80ba12035e593
@@ -1,4 +1,5 @@
1
1
  <!DOCTYPE html>
2
+ <!-- Language is set using I18n.locale, which is set in the controller -->
2
3
  <html lang="<%= I18n.locale %>">
3
4
  <head>
4
5
  <%= render "layouts/rails_admin/head" %>
@@ -6,6 +6,8 @@ Rails.application.configure do
6
6
  ApplicationController.send(:include, ConcernRAApplicationController)
7
7
  RailsAdmin::ApplicationController.send(:include, ConcernRAApplicationController)
8
8
  ## Rails Admin
9
+ require 'rails_admin_abstract_controller'
10
+ RailsAdmin::Config.parent_controller = '::RailsAdminAbstractController'
9
11
  ### More at https://github.com/sferik/rails_admin/wiki/Base-configuration
10
12
  ## == Devise ==
11
13
  RailsAdmin::Config.authenticate_with do
@@ -18,7 +20,7 @@ Rails.application.configure do
18
20
 
19
21
  # RailsAdmin::Config.sidescroll = { num_frozen_columns: 2 }
20
22
 
21
- RailsAdmin::Config.main_app_name = Proc.new { |controller| [ ((ENV["APP_NAME"].presence || Settings.app_name.presence) rescue "Thecore"), "" ] }
23
+ RailsAdmin::Config.main_app_name = Proc.new { |controller| [ ((ThecoreSettings::Setting.where(ns: :main, key: :app_name).pluck(:raw).first.presence || ENV["APP_NAME"]) rescue "Thecore"), "" ] }
22
24
 
23
25
  RailsAdmin::Config.show_gravatar = false
24
26
 
@@ -7,12 +7,15 @@ module ConcernRAApplicationController
7
7
  included do
8
8
  # Redirects on successful sign in
9
9
  def after_sign_in_path_for resource
10
- puts "after_sign_in_path_for #{resource}"
10
+ # Setting locale from user if locale field exists in the model, otherwise set it from the Settings in the end, use the default locale
11
+ I18n.locale = resource.is_a?(User) && resource.respond_to?(:locale) && !resource.locale.blank? ? resource.locale.to_sym : I18n.default_locale
12
+
13
+ Rails.logger.debug "after_sign_in_path_for #{resource}"
11
14
  root_actions = RailsAdmin::Config::Actions.all(:root).select {|action| can? :read, action.action_name }.collect(&:action_name)
12
15
 
13
16
  # Default root action as landing page: the first to which I have authorization to read
14
17
  action = root_actions.first
15
- puts "after_sign_in_path_for action: #{action}"
18
+ Rails.logger.debug "after_sign_in_path_for action: #{action}"
16
19
  # Otherwise, if I set a Manual override for landing actions in config, I can test if I'm authorized to see it
17
20
  override_landing_page = Settings.ns(:main).after_sign_in_redirect_to_root_action
18
21
  action = override_landing_page.to_sym if !override_landing_page.blank? && root_actions.include?(override_landing_page.to_sym)
@@ -20,17 +23,17 @@ module ConcernRAApplicationController
20
23
  # If I ask for a specific page, Let's try to go back there if I need to login or re-login
21
24
  # This takes precedence on automatic computed action
22
25
  stored_location = stored_location_for(resource)
23
- puts "after_sign_in_path_for stored_location: #{stored_location}"
26
+ Rails.logger.debug "after_sign_in_path_for stored_location: #{stored_location}"
24
27
  if !stored_location.blank? && can?(resource, :all)
25
28
  # Go to the latest navigated page
26
- puts "after_sign_in_path_for Redirect to stored_location"
29
+ Rails.logger.debug "after_sign_in_path_for Redirect to stored_location"
27
30
  return stored_location
28
31
  elsif action
29
32
  path = rails_admin.send("#{action}_path").sub("#{ENV['RAILS_RELATIVE_URL_ROOT']}#{ENV['RAILS_RELATIVE_URL_ROOT']}", "#{ENV['RAILS_RELATIVE_URL_ROOT']}")
30
- puts "after_sign_in_path_for Redirect to action #{path}"
33
+ Rails.logger.debug "after_sign_in_path_for Redirect to action #{path}"
31
34
  return path
32
35
  else
33
- puts "after_sign_in_path_for ERROR! Signing out user :-("
36
+ Rails.logger.debug "after_sign_in_path_for ERROR! Signing out user :-("
34
37
  sign_out current_user
35
38
  user_session = nil
36
39
  current_user = nil
@@ -13,6 +13,14 @@ module ThecoreUiRailsAdminUserConcern
13
13
  # def locked_enum
14
14
  # [["✔",true],['✘',false]]
15
15
  # end
16
+ #
17
+
18
+ # locale field is a string which can be chosen from the list of available locales: it and en
19
+ # The default locale is the one set in the I18n.default_locale
20
+ # The locale is used to set the language of the user
21
+ def locale_enum
22
+ [['Italiano', 'it'], ['English', 'en']]
23
+ end
16
24
 
17
25
  rails_admin do
18
26
  navigation_label I18n.t("admin.settings.label")
@@ -14,6 +14,6 @@ en:
14
14
  breadcrumb: Change Password
15
15
  menu: Change Password
16
16
  success: Your password has been changed successfully
17
- error: An error occurred while changing your password
17
+ error: Error! %{errors}
18
18
  scopes:
19
19
  _all: All
@@ -11,7 +11,7 @@ it:
11
11
  root_actions: "Operazioni"
12
12
  admin:
13
13
  misc:
14
- root_navigation: Azioni
14
+ root_navigation: Operazioni
15
15
  flash:
16
16
  error: "Impossibile eseguire l'azione %{action} (%{name})"
17
17
  model_not_found: Impossibile trovare il modello '%{model}'
@@ -6,14 +6,14 @@ it:
6
6
  index:
7
7
  no_records: Nessun record da mostrare
8
8
  active_job_monitor:
9
- menu: Async Worker Monitor
10
- title: Async Worker Monitor
11
- breadcrumb: Async Worker Monitor
9
+ menu: Monitoraggio Servizi
10
+ title: Monitoraggio Servizi
11
+ breadcrumb: Monitoraggio Servizi
12
12
  change_password:
13
13
  title: Cambia Password
14
14
  breadcrumb: Cambia Password
15
15
  menu: Cambia Password
16
16
  success: La tua password è stata cambiata con successo
17
- error: Si è verificato un errore durante il cambio della password
17
+ error: Attenzione! %{errors}
18
18
  scopes:
19
19
  _all: Tutti
@@ -0,0 +1,6 @@
1
+ class AddLocaleToUser < ActiveRecord::Migration[7.2]
2
+ def change
3
+ add_column :users, :locale, :string, default: I18n.default_locale.to_s
4
+ add_index :users, :locale
5
+ end
6
+ end
@@ -13,11 +13,12 @@ RailsAdmin::Config::Actions.add_action "change_password", :base, :member do
13
13
  proc do
14
14
  # if it's a form submission, then update the password
15
15
  if request.patch?
16
- if ::User.find(@object.id).update(password: params[:user][:password], password_confirmation: params[:user][:password_confirmation])
16
+ u = ::User.find(@object.id)
17
+ if u.update(password: params[:user][:password], password_confirmation: params[:user][:password_confirmation])
17
18
  flash[:success] = I18n.t("admin.actions.change_password.success")
18
19
  else
19
20
  # Add errors to the object
20
- flash[:error] = I18n.t("admin.actions.change_password.error")
21
+ flash[:error] = I18n.t("admin.actions.change_password.error", errors: u.errors.full_messages.join(', '))
21
22
  end
22
23
  # Redirect to the object
23
24
  redirect_to index_path(model_name: @abstract_model.to_param)
@@ -0,0 +1,9 @@
1
+ class RailsAdminAbstractController < ActionController::Base
2
+ before_action :set_locale
3
+
4
+ private
5
+
6
+ def set_locale
7
+ I18n.locale = current_user.locale if current_user
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module ThecoreUiRailsAdmin
2
- VERSION = "3.2.14".freeze
2
+ VERSION = "3.2.16".freeze
3
3
  end
@@ -1,11 +1,6 @@
1
1
  require "thecore_ui_commons"
2
- # https://github.com/dalpo/rails_admin_clone
3
- # require "rails_admin_clone"
4
2
  require "rails_admin"
5
3
  require "rails_admin-i18n"
6
- # require "rails_admin_toggleable"
7
- # https://github.com/stephskardal/rails_admin_import
8
- # require "rails_admin_import"
9
4
 
10
5
  require "thecore_ui_rails_admin/engine"
11
6
 
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.2.14
4
+ version: 3.2.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriele Tassoni
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-02-05 00:00:00.000000000 Z
10
+ date: 2025-02-12 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: thecore_ui_commons
@@ -107,8 +107,10 @@ files:
107
107
  - config/locales/it.rails_admin.yml
108
108
  - config/locales/it.rollincode.yml
109
109
  - config/routes.rb
110
+ - db/migrate/20250206222412_add_locale_to_user.rb
110
111
  - db/seeds.rb
111
112
  - lib/member_actions/change_password.rb
113
+ - lib/rails_admin_abstract_controller.rb
112
114
  - lib/root_actions/active_job_monitor.rb
113
115
  - lib/tasks/thecore_ui_rails_admin_tasks.rake
114
116
  - lib/thecore_ui_rails_admin.rb