Sha256: 6b522d331949c11d5508e41d5bcca8db95ede749895198eb6aa221017be60cd9

Contents?: true

Size: 1.65 KB

Versions: 12

Compression:

Stored size: 1.65 KB

Contents

class AwesomeTranslations::HandlersController < AwesomeTranslations::ApplicationController
  before_action :set_handler, only: [:show, :update_groups_cache]

  def index
    @handlers = AwesomeTranslations::CacheDatabaseGenerator::Handler.order(:name)
  end

  def update_cache
    generator = AwesomeTranslations::CacheDatabaseGenerator.current
    generator.update_handlers

    redirect_to :back
  end

  def update_groups_cache
    generator = AwesomeTranslations::CacheDatabaseGenerator.current
    generator.update_handlers do |handler_model|
      next unless handler_model.identifier == @handler.identifier
      generator.update_groups_for_handler(handler_model)
    end

    redirect_to :back
  end

  def show
    if params[:q]
      @ransack_values = params[:q]
    else
      @ransack_values = {
        with_translations: "only_with"
      }
    end

    @ransack = @handler
      .groups
      .ransack(@ransack_values)

    @groups = @ransack
      .result
      .includes(handler_translations: :translation_key)
      .order(:name)

    case @ransack_values[:with_translations]
    when "only_with"
      @groups = @groups.select { |group| group.handler_translations.any? }
    when "only_without"
      @groups = @groups.select { |group| group.handler_translations.empty? }
    end
  end

private

  def set_handler
    @handler = AwesomeTranslations::CacheDatabaseGenerator::Handler.find_by(identifier: params[:id])
    raise "No such handler: #{params[:id]}" unless @handler
  end

  helper_method :with_translations_collection
  def with_translations_collection
    {"Only with translations" => "only_with", "Only without translations" => "only_without"}
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
awesome_translations-0.0.38 app/controllers/awesome_translations/handlers_controller.rb
awesome_translations-0.0.37 app/controllers/awesome_translations/handlers_controller.rb
awesome_translations-0.0.36 app/controllers/awesome_translations/handlers_controller.rb
awesome_translations-0.0.35 app/controllers/awesome_translations/handlers_controller.rb
awesome_translations-0.0.34 app/controllers/awesome_translations/handlers_controller.rb
awesome_translations-0.0.33 app/controllers/awesome_translations/handlers_controller.rb
awesome_translations-0.0.32 app/controllers/awesome_translations/handlers_controller.rb
awesome_translations-0.0.31 app/controllers/awesome_translations/handlers_controller.rb
awesome_translations-0.0.30 app/controllers/awesome_translations/handlers_controller.rb
awesome_translations-0.0.29 app/controllers/awesome_translations/handlers_controller.rb
awesome_translations-0.0.28 app/controllers/awesome_translations/handlers_controller.rb
awesome_translations-0.0.27 app/controllers/awesome_translations/handlers_controller.rb