Sha256: eb3418ffb55d9f90b442c13f45c60c406deca4cb330ea1c9511c36cab6e2f8fd

Contents?: true

Size: 1.65 KB

Versions: 6

Compression:

Stored size: 1.65 KB

Contents

module ActiveAdmin
  module Views

    # Renders a collection of ActiveAdmin::Scope objects as a
    # simple list with a seperator
    class Scopes < ActiveAdmin::Component
      builder_method :scopes_renderer

      def build(scopes)
        scopes.each do |scope|
          build_scope(scope)
        end
      end

      protected

      def build_scope(scope)
        span :class => classes_for_scope(scope) do
          begin
            scope_name = I18n.t!("active_admin.scopes.#{scope.scope_method}")
          rescue I18n::MissingTranslationData
            scope_name = scope.name
          end

          if current_scope?(scope)
            em(scope_name)
          else
            a(scope_name, :href => url_for(params.merge(:scope => scope.id, :page => 1)))
          end
          text_node(" ")
          scope_count(scope)
          text_node(" ")
        end
      end

      def classes_for_scope(scope)
        classes = ["scope", scope.id]
        classes << "selected" if current_scope?(scope)
        classes.join(" ")
      end

      def current_scope?(scope)
        if params[:scope]
          params[:scope] == scope.id
        else
          active_admin_config.default_scope == scope
        end
      end

      def scope_count(scope)
        span :class => 'count' do
          "(" + get_scope_count(scope).to_s + ")"
        end
      end

      include ActiveAdmin::ScopeChain

      # Return the count for the scope passed in.
      def get_scope_count(scope)
        scope_chain(scope, scoping_class).count
      end

      def scoping_class
        assigns["before_scope_collection"] || active_admin_config.resource
      end

    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
andrewroth_activeadmin-0.3.4 lib/active_admin/views/components/scopes.rb
activeadmin-0.3.4 lib/active_admin/views/components/scopes.rb
activeadmin-0.3.3 lib/active_admin/views/components/scopes.rb
activeadmin-0.3.2 lib/active_admin/views/components/scopes.rb
activeadmin-0.3.1 lib/active_admin/views/components/scopes.rb
activeadmin-0.3.0 lib/active_admin/views/components/scopes.rb