DRY supported_languages

This commit is contained in:
2026-01-23 21:55:06 +01:00
parent a7713b962f
commit b3726e0777
8 changed files with 46 additions and 23 deletions
+4 -6
View File
@@ -2,7 +2,6 @@ class EntriesController < ApplicationController
before_action :set_entry, only: [ :show ]
def index
@supported_languages = SupportedLanguage.where(active: true).order(:sort_order, :name)
@language_code = params[:language].presence
@category = params[:category].presence
@query = params[:q].to_s.strip
@@ -24,21 +23,21 @@ class EntriesController < ApplicationController
@entry_count = Entry.count
@verified_count = Entry.where(verified: true).count
@needs_review_count = @entry_count - @verified_count
@complete_entries_count = @supported_languages.reduce(Entry.all) do |scope, language|
@complete_entries_count = supported_languages.reduce(Entry.all) do |scope, language|
scope.where.not(language.code => [ nil, "" ])
end.count
@missing_entries_count = @entry_count - @complete_entries_count
@language_completion = @supported_languages.index_with do |language|
@language_completion = supported_languages.index_with do |language|
next 0 if @entry_count.zero?
(Entry.where.not(language.code => [ nil, "" ]).count * 100.0 / @entry_count).round
end
if @language_code.present?
primary_language, other_languages = @supported_languages.partition { |language| language.code == @language_code }
primary_language, other_languages = supported_languages.partition { |language| language.code == @language_code }
@display_languages = primary_language + other_languages
else
@display_languages = @supported_languages
@display_languages = supported_languages
end
respond_to do |format|
@@ -48,7 +47,6 @@ class EntriesController < ApplicationController
end
def show
@supported_languages = SupportedLanguage.where(active: true).order(:sort_order, :name)
end
def download