Sha256: 4a127e31df36be8ad3c5e89bc3ed2029a516c4404a5a9fae60b77c8093635f64

Contents?: true

Size: 1.25 KB

Versions: 9

Compression:

Stored size: 1.25 KB

Contents

module ActiveAdmin
  module Dashboards

    autoload :DashboardController,  'active_admin/dashboards/dashboard_controller'
    autoload :Section,              'active_admin/dashboards/section'

    @@sections = {}
    mattr_accessor :sections

    class << self

      # Eval an entire block in the context of this module to build 
      # dashboards quicker. 
      #
      # Example:
      #
      #   ActiveAdmin::Dashboards.build do
      #     section "Recent Post" do
      #       # return a list of posts
      #     end
      #   end
      #
      def build(&block)
        module_eval(&block)
      end

      # Add a new dashboard section to a namespace. If no namespace is given
      # it will be added to the default namespace.
      def add_section(name, options = {}, &block)
        namespace = options.delete(:namespace) || ActiveAdmin.application.default_namespace || :root
        self.sections[namespace] ||= [] 
        self.sections[namespace] << Section.new(namespace, name, options, &block)
        self.sections[namespace].sort!
      end
      alias_method :section, :add_section

      def sections_for_namespace(namespace)
        @@sections[namespace] || []
      end

      def clear_all_sections!
        @@sections = {}
      end

    end

  end
end

Version data entries

9 entries across 9 versions & 4 rubygems

Version Path
andrewroth_activeadmin-0.3.4 lib/active_admin/dashboards.rb
activeadmin-0.3.4 lib/active_admin/dashboards.rb
activeadmin-0.3.3 lib/active_admin/dashboards.rb
activeadmin-0.3.2 lib/active_admin/dashboards.rb
activeadmin-0.3.1 lib/active_admin/dashboards.rb
activeadmin-0.3.0 lib/active_admin/dashboards.rb
nsm-activeadmin-0.2.2 lib/active_admin/dashboards.rb
saulolso-activeadmin-0.2.2.1 lib/active_admin/dashboards.rb
saulolso-activeadmin-0.2.2 lib/active_admin/dashboards.rb