lib/active_admin/views/components/scopes.rb in andrewroth_activeadmin-0.3.4 vs lib/active_admin/views/components/scopes.rb in andrewroth_activeadmin-0.3.4.1

- old
+ new

@@ -4,34 +4,40 @@ # Renders a collection of ActiveAdmin::Scope objects as a # simple list with a seperator class Scopes < ActiveAdmin::Component builder_method :scopes_renderer + def default_class_name + "scopes table_tools_segmented_control" + end + + def tag_name + 'ul' + end + def build(scopes) scopes.each do |scope| - build_scope(scope) + build_scope(scope) if call_method_or_proc_on(self, scope.display_if_block) end end protected def build_scope(scope) - span :class => classes_for_scope(scope) do + li :class => classes_for_scope(scope) do begin - scope_name = I18n.t!("active_admin.scopes.#{scope.scope_method}") + scope_name = I18n.t!("active_admin.scopes.#{scope.id}") 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))) + 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).to_s + ")" + end end - text_node(" ") - scope_count(scope) - text_node(" ") end end def classes_for_scope(scope) classes = ["scope", scope.id] @@ -45,24 +51,18 @@ 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 + assigns["before_scope_collection"] || active_admin_config.resource_class end end end end