diff --git a/app/controllers/admin/dashboard_controller.rb b/app/controllers/admin/dashboard_controller.rb index 9a1cdfb..bad4114 100644 --- a/app/controllers/admin/dashboard_controller.rb +++ b/app/controllers/admin/dashboard_controller.rb @@ -22,8 +22,7 @@ class Admin::DashboardController < Admin::BaseController .where("invitation_sent_at > ?", 14.days.ago) .count - @supported_languages = SupportedLanguage.where(active: true).order(:sort_order) - @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 diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 71997a4..7ddd11d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,12 +1,16 @@ class ApplicationController < ActionController::Base - # Changes to the importmap will invalidate the etag for HTML responses stale_when_importmap_changes - helper_method :current_user, :logged_in?, :admin?, :reviewer_or_admin?, :contributor_or_above?, :setup_completed? + helper_method :supported_languages, :current_user, :logged_in?, :admin?, :reviewer_or_admin?, + :contributor_or_above?, :setup_completed? private + def supported_languages + @supported_languages ||= SupportedLanguage.where(active: true).order(:sort_order, :name) + end + def current_user @current_user ||= User.find_by(id: session[:user_id]) if session[:user_id] end diff --git a/app/controllers/entries_controller.rb b/app/controllers/entries_controller.rb index dfa55ce..53ca006 100644 --- a/app/controllers/entries_controller.rb +++ b/app/controllers/entries_controller.rb @@ -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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be79..3923f72 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,5 @@ module ApplicationHelper + def language_name(code) + supported_languages.find { |l| l.code == code }&.name + end end diff --git a/app/views/admin/dashboard/index.html.erb b/app/views/admin/dashboard/index.html.erb index dda36ed..6d3a2f8 100644 --- a/app/views/admin/dashboard/index.html.erb +++ b/app/views/admin/dashboard/index.html.erb @@ -115,7 +115,7 @@
<%= translation %>
+ <% if current_user %> +