Gem Version Build Status Code Climate Test Coverage

ActiveAdmin::AsyncPanel

ActiveAdmin Async Panel control

This gem allows you to create ActiveAdmin panels with content loaded dynamically via AJAX requests.

Prerequisites

This extension assumes that you're using Active Admin

Installation

Add this line to your application's Gemfile:

gem 'activeadmin-async_panel'

And then execute:

$ bundle

Or install it yourself as:

$ gem install activeadmin-async_panel

Usage

Include this line in your JavaScript code (active_admin.js.coffee)

#= require activeadmin-async_panel

Include this line in your CSS code (active_admin.scss)

@import "activeadmin-async_panel";

To use this stuff do next steps:

Step 1. Define async panel

panel 'Name', class: 'async-panel', 'data-url' => some_action_admin_resources_path, 'data-period' => 1.minute

If you setup data-period, panel will be periodically updated. If not, it will be loaded once right after page load

If you set data-clickable to a truthy value, the panel will not be loaded upon initial page load. Instead, the panel will load upon clicking the panel header. Upon page load, the panel header will have a label of 'Click to Load'. Example:

panel 'Name', class: 'async-panel', 'data-url' => some_action_admin_resources_path, 'data-clickable' => 1

Step 2. Define action

Define member_action or collection_action to handle request specified by path helper

collection_action :some_action do
  @resources = Resource.some_scope
  render layout: false # mandatory line, layout should be disaled to render template only
end

Step 3. Define view

Define you view template to render action above in file views/admin/resources/some_action.html.arbcan also be (slim, erb), for e.g. arb template:

table_for resources do
  column :value1
  column :value2
end

Note that in step 2 you can pass template variables with @, but inside arb template you should use them without @, and inside erb, slim with.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/holyketzer/activeadmin-async_panel. This project is intended to be a safe, welcoming space for collaboration.

License

The gem is available as open source under the terms of the MIT License.