diff --git a/README.md b/README.md index b5e6e281..daa6128d 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ translating app by non-technicals. Highly inspired by Copycopter by thoughtbot. -[![travis status](https://travis-ci.org/prograils/lit.svg)](https://travis-ci.org/prograils/lit) +[![travis status](https://api.travis-ci.org/3eggert/lit.svg?branch=js_translations)](https://api.travis-ci.org/3eggert/lit.svg?branch=js_translations) ### Features diff --git a/app/controllers/lit/dashboard_controller.rb b/app/controllers/lit/dashboard_controller.rb index e4e32936..8f949187 100644 --- a/app/controllers/lit/dashboard_controller.rb +++ b/app/controllers/lit/dashboard_controller.rb @@ -5,5 +5,10 @@ class DashboardController < ::Lit::ApplicationController def index @locales = Lit::Locale.ordered.visible end + + def clear_usage_data + Lit::LocalizationKey.where.not(used_last_at: nil).update_all(usage_count: 0, used_last_at: nil) + redirect_to root_path + end end end diff --git a/app/controllers/lit/localization_keys_controller.rb b/app/controllers/lit/localization_keys_controller.rb index a55f9644..bf80d0ef 100644 --- a/app/controllers/lit/localization_keys_controller.rb +++ b/app/controllers/lit/localization_keys_controller.rb @@ -9,6 +9,16 @@ def index get_localization_keys end + def not_used + @scope = @scope.not_used + get_localization_keys + end + + def used + @scope = @scope.used + get_localization_keys + end + def not_translated @scope = @scope.not_completed get_localization_keys diff --git a/app/jobs/lit/persit_global_hits_counters_job.rb b/app/jobs/lit/persit_global_hits_counters_job.rb new file mode 100644 index 00000000..40d50744 --- /dev/null +++ b/app/jobs/lit/persit_global_hits_counters_job.rb @@ -0,0 +1,11 @@ +module Lit + if defined?(::ActiveJob) + class PersitGlobalHitsCountersJob < ::ActiveJob::Base + queue_as :default + + def perform(update_array) + PersitGlobalHitsCountersService.new(update_array).execute + end + end + end +end diff --git a/app/models/lit/localization_key.rb b/app/models/lit/localization_key.rb index b3d3bf3e..41836354 100644 --- a/app/models/lit/localization_key.rb +++ b/app/models/lit/localization_key.rb @@ -3,6 +3,8 @@ class LocalizationKey < Lit::Base attr_accessor :interpolated_key ## SCOPES + scope :used, -> { where.not(used_last_at: nil) } + scope :not_used, -> { where(used_last_at: nil) } scope :completed, -> { where(is_completed: true) } scope :not_completed, -> { where(is_completed: false) } scope :starred, -> { where(is_starred: true) } diff --git a/app/services/persit_global_hits_counters_service.rb b/app/services/persit_global_hits_counters_service.rb new file mode 100644 index 00000000..73ba9a6f --- /dev/null +++ b/app/services/persit_global_hits_counters_service.rb @@ -0,0 +1,12 @@ +class PersitGlobalHitsCountersService + def initialize(update_array) + @update_array = update_array + end + + def execute + @update_array.each do |a| + Lit::LocalizationKey.find(a[0]).update_columns(usage_count: a[1], used_last_at: Time.now) + end + end + +end diff --git a/app/views/lit/dashboard/index.html.erb b/app/views/lit/dashboard/index.html.erb index f9dcd4d4..f63dd54b 100644 --- a/app/views/lit/dashboard/index.html.erb +++ b/app/views/lit/dashboard/index.html.erb @@ -1,4 +1,6 @@ All localization keys <%= Lit::LocalizationKey.active.count(:id) %>
+Used localization keys <%= Lit::LocalizationKey.where.not(used_last_at: nil).count(:id) %>
+<%= button_to("clear usage data", {action: "clear_usage_data"}, data: {confirm: "Are you sure you want to clear the usage data?" }) %> <% @locales.each do |l| %> <%= EmojiFlag.new(l.locale) %> <%= I18n.t("lit.locale_to_languages.#{l.locale}", :default=>l.locale) %>: "><%= l.translated_percentage %>%
<% end %> diff --git a/app/views/lit/localization_keys/_localizations_list.html.erb b/app/views/lit/localization_keys/_localizations_list.html.erb index 7e99693b..0889831d 100644 --- a/app/views/lit/localization_keys/_localizations_list.html.erb +++ b/app/views/lit/localization_keys/_localizations_list.html.erb @@ -3,7 +3,13 @@ <%= lk.localization_key %> - <%= Lit.init.cache.get_global_hits_counter(lk.localization_key) %> + <% if lk.used_last_at.present? %> + <%= "#{I18n.t('lit.used', default: 'used')} #{lk.usage_count} #{I18n.t('lit.times_since', default: 'times since')} #{l(Lit::LocalizationKey.maximum(:used_last_at), :format => :short4rb)}, #{I18n.t('lit.times_since', default: 'last use')} #{l(lk.used_last_at, :format => :short4rb)}" %> + <% elsif Lit::LocalizationKey.maximum(:used_last_at).present? %> + <%= "#{I18n.t('lit.not_used', default: 'not used since')} #{l(Lit::LocalizationKey.maximum(:used_last_at), :format => :short4rb)}" %> + <% else %> + <%= "#{I18n.t('lit.not_used', default: 'not used since')}" %> + <% end %>
<% if Lit.store_request_info %> <%= link_to '#', class: 'request_info_link title', title: 'Show / hide request' do %> diff --git a/app/views/lit/localization_keys/_sidebar.html.erb b/app/views/lit/localization_keys/_sidebar.html.erb index 7de3365e..a836f856 100644 --- a/app/views/lit/localization_keys/_sidebar.html.erb +++ b/app/views/lit/localization_keys/_sidebar.html.erb @@ -12,7 +12,19 @@
<% end %>