Skip to content

Commit

Permalink
Do not suggest labels from DB
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-illi committed Oct 9, 2024
1 parent a0d6240 commit 7410642
Showing 1 changed file with 8 additions and 21 deletions.
29 changes: 8 additions & 21 deletions app/models/die_mitte/normalized_labels.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,17 @@
# https://github.com/hitobito/hitobito_die_mitte.

module DieMitte::NormalizedLabels
def available_labels(lang = I18n.locale)
Rails.cache.fetch(labels_cache_key(lang)) do
load_available_labels(lang)
end
end

def sweep_available_labels
Settings.application.languages.keys.each do |key|
Rails.cache.delete(labels_cache_key(key))
end
def self.extended(base)
# #normalize_label works only for the current locale. If we want this feature
# for the die_mitte wagon, we need to implement the callback to normalize all
# translations of the label field.
base.skip_callback(:save, :before, :normalize_label)
end

private

def load_available_labels(lang)
predefined_labels(lang) |
base_class.with_translations(lang).order(:label).distinct.pluck(:label).compact
end
def available_labels(lang = I18n.locale) = predefined_labels(lang)

def predefined_labels(_lang)
[]
end
private

def labels_cache_key(lang)
"#{base_class.name}.Labels.#{lang}"
end
def predefined_labels(_lang = I18n.locale) = []
end

0 comments on commit 7410642

Please sign in to comment.