diff --git a/app/assets/stylesheets/lit/application.css b/app/assets/stylesheets/lit/application.css index f0918856..ee26cf96 100644 --- a/app/assets/stylesheets/lit/application.css +++ b/app/assets/stylesheets/lit/application.css @@ -11,17 +11,17 @@ *= require './backend/jquery-te-1.4.0.css' *= require_self */ -.detail_wrapper{ - padding: 10px 0 0 50px; +.detail_wrapper { + padding: 10px 0 0 10px; } -.detail_wrapper table tr td.locale_row{ +.detail_wrapper table tr td.locale_row { width: 75px; } -.localization_key_row .localization_keys_options{ +.localization_key_row .localization_keys_options { display: none; float: right; } -.localization_key_row:hover .localization_keys_options{ +.localization_key_row:hover .localization_keys_options { display: block; } @@ -29,29 +29,29 @@ li.key_prefix .fa-chevron-right { float: right; margin-top: 2px; margin-right: -6px; - opacity: .25; + opacity: 0.25; } -.hidden{ +.hidden { display: none; } -i.fa{ +i.fa { color: black; } -.nav.nav-stacked>li>a { -padding: 5px 7px; +.nav.nav-stacked > li > a { + padding: 5px 7px; } -.well{ +.well { background-color: white; border-radius: 0px; } -.well label{ +.well label { font-weight: normal; } .well .form-search { margin-bottom: 15px; } -.localization_row em{ +.localization_row em { color: #bbb; } .loading { diff --git a/app/controllers/lit/localization_keys_controller.rb b/app/controllers/lit/localization_keys_controller.rb index a55f9644..5738e14e 100644 --- a/app/controllers/lit/localization_keys_controller.rb +++ b/app/controllers/lit/localization_keys_controller.rb @@ -1,9 +1,7 @@ module Lit class LocalizationKeysController < ::Lit::ApplicationController - before_action :find_localization_scope, - except: %i[destroy find_localization] - before_action :find_localization_key, - only: %i[star destroy change_completed restore_deleted] + before_action :find_localization_scope, except: %i[destroy find_localization] + before_action :find_localization_key, only: %i[star destroy change_completed restore_deleted] def index get_localization_keys @@ -20,27 +18,19 @@ def visited_again end def find_localization - localization_key = Lit::LocalizationKey.find_by!( - localization_key: params[:key] - ) + localization_key = Lit::LocalizationKey.find_by!(localization_key: params[:key]) locale = Lit::Locale.find_by!(locale: params[:locale]) localization = localization_key.localizations.find_by(locale_id: locale) - render json: { - path: localization_key_localization_path(localization_key, localization) - } + render json: { path: localization_key_localization_path(localization_key, localization) } end def starred @scope = @scope.where(is_starred: true) - if defined?(Kaminari) && - @scope.respond_to?(Kaminari.config.page_method_name) + if defined?(Kaminari) && @scope.respond_to?(Kaminari.config.page_method_name) @scope = @scope.send(Kaminari.config.page_method_name, params[:page]) end - if defined?(WillPaginate) && - @scope.respond_to?(:paginate) - @scope = @scope.paginate(page: params[:page]) - end + @scope = @scope.paginate(page: params[:page]) if defined?(WillPaginate) && @scope.respond_to?(:paginate) get_localization_keys render action: :index end @@ -66,6 +56,16 @@ def destroy respond_to :js end + def batch_touch + get_localization_keys + localization_key_ids = @scope.distinct(false).pluck(:id) + if localization_key_ids.any? + @scope.distinct(false).update_all updated_at: Time.current + Localization.where(localization_key_id: localization_key_ids).update_all updated_at: Time.current + end + respond_to :js + end + private def find_localization_key @@ -73,19 +73,16 @@ def find_localization_key end def find_localization_scope - @search_options = if params.respond_to?(:permit) - params.permit(*valid_keys) - else - params.slice(*valid_keys) - end - @scope = LocalizationKey.distinct.active - .preload(localizations: :locale) - .search(@search_options) + @search_options = params.respond_to?(:permit) ? params.permit(*valid_keys) : params.slice(*valid_keys) + @scope = LocalizationKey.distinct.active.preload(localizations: :locale).search(@search_options) end def get_localization_keys key_parts = @search_options[:key_prefix].to_s.split('.').length - @prefixes = @scope.reorder(nil).distinct.pluck(:localization_key).map { |lk| lk.split('.').shift(key_parts + 1).join('.') }.uniq.sort + @prefixes = + @scope.reorder(nil).distinct.pluck(:localization_key).map do |lk| + lk.split('.').shift(key_parts + 1).join('.') + end.uniq.sort if @search_options[:key_prefix].present? parts = @search_options[:key_prefix].split('.') @parent_prefix = parts[0, parts.length - 1].join('.') @@ -104,16 +101,15 @@ def valid_keys end def grouped_localizations - @_grouped_localizations ||= begin - {}.tap do |hash| - @localization_keys.each do |lk| - hash[lk] = {} - lk.localizations.each do |l| - hash[lk][l.locale.locale.to_sym] = l + @_grouped_localizations ||= + begin + {}.tap do |hash| + @localization_keys.each do |lk| + hash[lk] = {} + lk.localizations.each { |l| hash[lk][l.locale.locale.to_sym] = l } end end end - end end def localization_for(locale, localization_key) @@ -136,12 +132,16 @@ def localization_for(locale, localization_key) helper_method :localization_for def versions?(localization) - @_versions ||= begin - ids = grouped_localizations.values.map(&:values).flatten.map(&:id) - Lit::Localization.active.where(id: ids).joins(:versions).group( - "#{Lit::Localization.quoted_table_name}.id" - ).count - end + @_versions ||= + begin + ids = grouped_localizations.values.map(&:values).flatten.map(&:id) + Lit::Localization + .active + .where(id: ids) + .joins(:versions) + .group("#{Lit::Localization.quoted_table_name}.id") + .count + end @_versions[localization.id].to_i > 0 end helper_method :versions? diff --git a/app/views/lit/localization_keys/_localizations_list.html.erb b/app/views/lit/localization_keys/_localizations_list.html.erb index 7e99693b..6681ce36 100644 --- a/app/views/lit/localization_keys/_localizations_list.html.erb +++ b/app/views/lit/localization_keys/_localizations_list.html.erb @@ -1,4 +1,7 @@ - +
+ <%= link_to "batch touch", lit.batch_touch_localization_keys_path(key: params[:key], key_prefix: params[:key_prefix]), method: :post, remote: true, class: 'btn btn-sm btn-primary', data: { confirm: 'This will "touch" all search results making them subject of synchronization. Proceed?'} %> +
+
<%- @localization_keys.each do |lk| %>
@@ -30,26 +33,30 @@
- - + + + <% unless lk.is_deleted? %> - + <% end %> <%- available_locales.each do |locale| %> <%- localization = localization_for(locale, lk) %> + <% unless lk.is_deleted? %> -
TranslationLocaleTranslationLocaleCompletedCompleted
+ <% if localization %> + <%= draw_icon 'clock-o', title: "Last updated at #{localization.updated_at.to_s(:db)}" %> + <%= link_to lit.previous_versions_localization_key_localization_path(lk, localization, format: :js), class: "js-show_prev_versions #{'hidden' unless versions?(localization)}", remote: true do %> + <%= draw_icon 'random', title: I18n.t('lit.common.previous_versions', default: 'Previous versions') %> + <% end %> + <% end %> + <%= render partial: 'localization_row', locals: {localization: Lit.init.cache["#{locale}.#{lk.localization_key}"]} %> <%= EmojiFlag.new(locale) %> <%= locale %> - <% if localization %> - <%= link_to lit.previous_versions_localization_key_localization_path(lk, localization, format: :js), class: "show_prev_versions #{'hidden' unless versions?(localization)}", remote: true do %> - <%= draw_icon 'random', title: I18n.t('lit.common.previous_versions', default: 'Previous versions') %> - <% end %> - <% end %> @@ -65,7 +72,7 @@ <% end %> <% if Lit.store_request_info %>