lato_settings 3.0.2 → 3.0.4

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: f41650d6341281014bd726dc82189daebc59dd927be768e97abbe30ad815900f
4
- data.tar.gz: 66fe16b506ff92ce3bf8ffeec3fff9b3c2db3f5b6a035fce177077751627fd91
3
+ metadata.gz: f7846bd6973838754257a88b5bf060b39a4d0935cbaa7aff241b4c168da26471
4
+ data.tar.gz: d2edd11c94389baf016177ef70abddb461995d0f68741a5bcc11a664b27cf61a
5
5
  SHA512:
6
- metadata.gz: 2dbfc2621d28ed3ec18c7efdc18939cdf523f63cc80596c872ffb612a301328cfa3bc9893706915dade0d07f6a0055ef9e9d9dd02a031c0a5494e52fd9f93755
7
- data.tar.gz: b5fdb1ea4dd6e24f92878814718d4707486bee01163618eb2f5661c874d2a860b5fd0689bf6d04691763afa63852b7474607af84f26cc24fb006a7dbc26051f5
6
+ metadata.gz: a1c19bd6a38bf6fa666bd4910a555676740e672e60cf1894f7db72686fa448689b56ca6580ad5f328488d41e7289d0dfe204e4708a5b724588ecc20233ea463c
7
+ data.tar.gz: cb84a9f9e4801a48db34e65f1935388817276e5f7a3f228272cbc785da83a5af5256055ff41b9e23c1540d19d244bdb1477bcab48afd84063e5db799d526096b
@@ -12,7 +12,7 @@ module LatoSettings
12
12
  protected
13
13
 
14
14
  def authenticate_lato_settings_admin
15
- return true if @session.user.lato_settings_admin
15
+ return true if @session.user&.lato_settings_admin
16
16
 
17
17
  redirect_to lato.root_path, alert: 'You have not access to this section.'
18
18
  end
@@ -3,7 +3,7 @@ module LatoSettings
3
3
  def index
4
4
  @settings = lato_index_collection(
5
5
  Setting.all,
6
- columns: %i[key label value updated_at actions],
6
+ columns: %i[label value key updated_at actions],
7
7
  searchable_columns: %i[key label value],
8
8
  sortable_columns: %i[updated_at],
9
9
  pagination: true,
@@ -1,5 +1,13 @@
1
1
  module LatoSettings
2
2
  module SettingsHelper
3
+ def lato_settings_setting_key(setting)
4
+ print_content(setting, setting.key, :key)
5
+ end
6
+
7
+ def lato_settings_setting_value(setting)
8
+ print_content(setting, setting.value_formatted, :value)
9
+ end
10
+
3
11
  def lato_settings_setting_label(setting)
4
12
  content_tag(:div, class: 'd-flex flex-column') do
5
13
  concat content_tag(:strong, setting.label)
@@ -18,9 +26,20 @@ module LatoSettings
18
26
  concat link_to(I18n.t('lato_settings.cta_edit'), lato_settings.edit_setting_path(setting), class: 'btn btn-primary', data: { lato_action_target: 'trigger', turbo_frame: dom_id(setting, 'form'), action_title: I18n.t('lato_settings.edit_setting') })
19
27
 
20
28
  unless setting.required
21
- concat link_to(I18n.t('lato_settings.cta_delete'), lato_settings.setting_path(setting), class: 'btn btn-danger', data: { turbo_confirm: 'Are you sure?', turbo_method: :delete })
29
+ concat link_to(I18n.t('lato_settings.cta_delete'), lato_settings.setting_path(setting), class: 'btn btn-danger', data: { turbo_confirm: I18n.t('lato_settings.cta_delete_confirm'), turbo_method: :delete })
22
30
  end
23
31
  end
24
32
  end
33
+
34
+ def print_content(setting, content, type)
35
+ raw "
36
+ <div class=\"input-group input-group-sm\" data-controller=\"lato-copyclip\">
37
+ <input type=\"text\" class=\"form-control\" placeholder=\"#{setting.label || setting.key}\" aria-label=\"#{setting.label || setting.key}\" aria-describedby=\"#{type}_#{setting.id}\" value=\"#{content}\" data-lato-copyclip-target=\"input\" readonly>
38
+ <button class=\"btn btn-primary\" type=\"button\" id=\"#{type}_#{setting.id}\" data-lato-copyclip-target=\"button\" data-action=\"lato-copyclip#onButtonClick\" title=\"#{I18n.t('lato_settings.cta_copy')}\" aria-label=\"#{I18n.t('lato_settings.cta_copy')}\" data-copy-text=\"<i class='bi bi-clipboard-check'></i>\">
39
+ <i class=\"bi bi-clipboard\"></i>
40
+ </button>
41
+ </div>
42
+ "
43
+ end
25
44
  end
26
45
  end
@@ -7,6 +7,7 @@ module LatoSettings
7
7
  number: 1,
8
8
  date: 2,
9
9
  select: 3,
10
+ integer: 4,
10
11
  }, prefix: true
11
12
 
12
13
  validates :key, presence: true, uniqueness: true, format: { with: /\A[a-zA-Z0-9_]+\z/ }
@@ -30,13 +31,31 @@ module LatoSettings
30
31
  after_save :reload_cache
31
32
  after_destroy :reload_cache
32
33
  def reload_cache
33
- Rails.cache.delete('LatoSettings::Setting/cache')
34
- @@cache = nil
34
+ LatoSettings.reset_cache
35
35
  end
36
36
 
37
37
  # Helpers
38
38
  ##
39
39
 
40
+ def value_formatted
41
+ return nil if value.nil?
42
+
43
+ case typology
44
+ when 'string'
45
+ value.to_s
46
+ when 'number'
47
+ value.to_f
48
+ when 'date'
49
+ Date.parse(value)
50
+ when 'select'
51
+ option_values.include?(value) ? value : nil
52
+ when 'integer'
53
+ value.to_i
54
+ else
55
+ value.to_s
56
+ end
57
+ end
58
+
40
59
  def option_min
41
60
  options&.dig('min') || nil
42
61
  end
@@ -56,27 +75,16 @@ module LatoSettings
56
75
  # Class
57
76
  ##
58
77
 
78
+ # DEPRECATED METHOD: TO BE REMOVED IN FUTURE VERSIONS
59
79
  def self.get(key, default = nil)
60
- load_cache
61
-
62
- @@cache[key] || default
80
+ Rails.logger.warn "LatoSettings::Setting.get is deprecated. Use LatoSettings.get instead."
81
+ LatoSettings.get(key, default)
63
82
  end
64
83
 
84
+ # DEPRECATED METHOD: TO BE REMOVED IN FUTURE VERSIONS
65
85
  def self.load_cache
66
- return true if defined?(@@cache) && @@cache
67
-
68
- @@cache = Rails.cache.fetch('LatoSettings::Setting/cache') do
69
- cache = {}
70
- LatoSettings::Setting.all.select(:key, :value, :typology).each do |setting|
71
- cache[setting.key] = setting.value
72
- cache[setting.key] = setting.value.to_f if setting.typology_number?
73
- end
74
-
75
- cache
76
- end
77
-
78
- true
86
+ Rails.logger.warn "LatoSettings::Setting.load_cache is deprecated. Use LatoSettings.reset_cache instead."
87
+ LatoSettings.reset_cache
79
88
  end
80
-
81
89
  end
82
90
  end
@@ -12,9 +12,16 @@ setting ||= LatoSettings::Setting.new
12
12
  <% if setting.typology %>
13
13
  <%= form.hidden_field :typology %>
14
14
 
15
- <div class="mb-3">
16
- <%= lato_form_item_label form, :key %>
17
- <%= lato_form_item_input_text form, :key, required: true, disabled: setting.persisted? %>
15
+ <div class="row">
16
+ <div class="col col-12 col-md-6 mb-3">
17
+ <%= lato_form_item_label form, :key %>
18
+ <%= lato_form_item_input_text form, :key, required: true, disabled: setting.persisted? %>
19
+ </div>
20
+
21
+ <div class="col col-12 col-md-6 mb-3">
22
+ <%= lato_form_item_label form, :label %>
23
+ <%= lato_form_item_input_text form, :label, required: true %>
24
+ </div>
18
25
  </div>
19
26
 
20
27
  <% if setting.typology == 'number' %>
@@ -22,6 +29,11 @@ setting ||= LatoSettings::Setting.new
22
29
  <%= lato_form_item_label form, :value %>
23
30
  <%= lato_form_item_input_number form, :value, required: true, min: setting.option_min, max: setting.option_max, step: setting.option_step %>
24
31
  </div>
32
+ <% elsif setting.typology == 'integer' %>
33
+ <div class="mb-3">
34
+ <%= lato_form_item_label form, :value %>
35
+ <%= lato_form_item_input_number form, :value, required: true, min: setting.option_min, max: setting.option_max, step: 1 %>
36
+ </div>
25
37
  <% elsif setting.typology == 'date' %>
26
38
  <div class="mb-3">
27
39
  <%= lato_form_item_label form, :value %>
@@ -39,11 +51,6 @@ setting ||= LatoSettings::Setting.new
39
51
  </div>
40
52
  <% end %>
41
53
 
42
- <div class="mb-3">
43
- <%= lato_form_item_label form, :label %>
44
- <%= lato_form_item_input_text form, :label, required: true %>
45
- </div>
46
-
47
54
  <div class="mb-3">
48
55
  <%= lato_form_item_label form, :description %>
49
56
  <%= lato_form_item_input_textarea form, :description %>
@@ -6,4 +6,6 @@ en:
6
6
  cta_edit: Edit
7
7
  cta_update: Update
8
8
  cta_delete: Delete
9
- cta_confirm: Confirm
9
+ cta_confirm: Confirm
10
+ cta_copy: Copy
11
+ cta_delete_confirm: Are you sure you want to delete this setting?
@@ -7,6 +7,8 @@ it:
7
7
  cta_update: Aggiorna
8
8
  cta_delete: Cancella
9
9
  cta_confirm: Conferma
10
+ cta_copy: Copia
11
+ cta_delete_confirm: Sei sicuro di voler cancellare questa impostazione?
10
12
  activerecord:
11
13
  attributes:
12
14
  lato_settings/setting:
@@ -1,3 +1,3 @@
1
1
  module LatoSettings
2
- VERSION = "3.0.2"
2
+ VERSION = "3.0.4"
3
3
  end
data/lib/lato_settings.rb CHANGED
@@ -11,5 +11,31 @@ module LatoSettings
11
11
  def configure
12
12
  yield config
13
13
  end
14
+
15
+ def get(key, default = nil)
16
+ load_cache
17
+
18
+ @cache[key] || default
19
+ end
20
+
21
+ def load_cache
22
+ return true if defined?(@cache) && @cache
23
+
24
+ @cache = Rails.cache.fetch('LatoSettings/cache') do
25
+ cache = {}
26
+ LatoSettings::Setting.all.select(:key, :value, :typology).each do |setting|
27
+ cache[setting.key] = setting.value_formatted
28
+ end
29
+
30
+ cache
31
+ end
32
+
33
+ @cache
34
+ end
35
+
36
+ def reset_cache
37
+ @cache = nil
38
+ Rails.cache.delete('LatoSettings/cache')
39
+ end
14
40
  end
15
41
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lato_settings
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.2
4
+ version: 3.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregorio Galante
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-04-03 00:00:00.000000000 Z
11
+ date: 2025-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails