Sha256: 5513e88cfbb13183fb30e586507c9f37f42429179587c2f5d914fd1a4440af9e

Contents?: true

Size: 1.67 KB

Versions: 46

Compression:

Stored size: 1.67 KB

Contents

require 'active_admin/helpers/collection'

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

      include ActiveAdmin::ScopeChain
      include ::ActiveAdmin::Helpers::Collection


      def default_class_name
        "scopes table_tools_segmented_control"
      end

      def tag_name
        'ul'
      end

      def build(scopes, options = {})
        scopes.each do |scope|
          build_scope(scope, options) if call_method_or_proc_on(self, scope.display_if_block)
        end
      end

      protected

      def build_scope(scope, options)
        li :class => classes_for_scope(scope) do
          scope_name = I18n.t("active_admin.scopes.#{scope.id}", :default => scope.name)

          a :href => url_for(params.merge(:scope => scope.id, :page => 1)), :class => "table_tools_button" do
            text_node scope_name
            span :class => 'count' do
              "(#{get_scope_count(scope)})"
            end if options[:scope_count] && scope.show_count
          end
        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

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

Version data entries

46 entries across 46 versions & 2 rubygems

Version Path
lalala-4.0.0.dev.141 vendor/deps/active_admin/lib/active_admin/views/components/scopes.rb
lalala-4.0.0.dev.136 vendor/deps/active_admin/lib/active_admin/views/components/scopes.rb
lalala-4.0.0.dev.135 vendor/deps/active_admin/lib/active_admin/views/components/scopes.rb
lalala-4.0.0.dev.134 vendor/deps/active_admin/lib/active_admin/views/components/scopes.rb
lalala-4.0.0.dev.133 vendor/deps/active_admin/lib/active_admin/views/components/scopes.rb
lalala-4.0.0.dev.132 vendor/deps/active_admin/lib/active_admin/views/components/scopes.rb
lalala-4.0.0.dev.131 vendor/deps/active_admin/lib/active_admin/views/components/scopes.rb
lalala-4.0.0.dev.129 vendor/deps/active_admin/lib/active_admin/views/components/scopes.rb
lalala-4.0.0.dev.128 vendor/deps/active_admin/lib/active_admin/views/components/scopes.rb
lalala-4.0.0.dev.126 vendor/deps/active_admin/lib/active_admin/views/components/scopes.rb
lalala-4.0.0.dev.125 vendor/deps/active_admin/lib/active_admin/views/components/scopes.rb
lalala-4.0.0.dev.124 vendor/deps/active_admin/lib/active_admin/views/components/scopes.rb
lalala-4.0.0.dev.123 vendor/deps/active_admin/lib/active_admin/views/components/scopes.rb
lalala-4.0.0.dev.118 vendor/deps/active_admin/lib/active_admin/views/components/scopes.rb
lalala-4.0.0.dev.116 vendor/deps/active_admin/lib/active_admin/views/components/scopes.rb
lalala-4.0.0.dev.114 vendor/deps/active_admin/lib/active_admin/views/components/scopes.rb
lalala-4.0.0.dev.113 vendor/deps/active_admin/lib/active_admin/views/components/scopes.rb
lalala-4.0.0.dev.111 vendor/deps/active_admin/lib/active_admin/views/components/scopes.rb
lalala-4.0.0.dev.109 vendor/deps/active_admin/lib/active_admin/views/components/scopes.rb
lalala-4.0.0.dev.107 vendor/deps/active_admin/lib/active_admin/views/components/scopes.rb