Skip to content

Commit

Permalink
Merge branch 'master' into mongoid
Browse files Browse the repository at this point in the history
* master:
  fixed another ambiguity
  fix to prevent coffeescript from misinterpreting
  allow tabs to be used in sidebar
  Update 1-general-configuration.md
  Fixes activeadmin#3583: Associates comments with STI base classes
  use inherited_resources from rubygems
  remove rails 4.2 section from readme
  change inherited_resources to 1.6 to support rails 4.2
  Do not auto link to inaccessible actions
  Fixed some JS initializers to run on turbolinks page:load also
  Rename print.css.scss to print.scss
  use render_in_context for eval form block
  change exec context for batch_action form option
  improve documentation
  remove  param from uri when changing per_page
  Allow pagination to be controller with dynamic per_page
  • Loading branch information
Zhomart committed Jan 31, 2015
2 parents 5b4a3e3 + b3a9f4b commit 33f5550
Show file tree
Hide file tree
Showing 30 changed files with 193 additions and 44 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#### Minor

* Do not auto link to inaccessible actions [#3686][] by [@pranas][]
* Allow to enable comments on per-resource basis [#3695][] by [@pranas][]
* Unify DSL for index `actions` and `actions dropdown: true` [#3463][] by [@timoschilling][]
* Add DSL method `includes` for `ActiveRecord::Relation#includes` [#3464][] by [@timoschilling][]
Expand Down Expand Up @@ -989,6 +990,7 @@ of the highlights. 250 commits. Enough said.
[#3486]: https://github.com/activeadmin/activeadmin/issues/3486
[#3519]: https://github.com/activeadmin/activeadmin/issues/3519
[#3606]: https://github.com/activeadmin/activeadmin/issues/3606
[#3686]: https://github.com/activeadmin/activeadmin/issues/3686
[#3695]: https://github.com/activeadmin/activeadmin/issues/3695
[#3731]: https://github.com/activeadmin/activeadmin/issues/3731
[@Bishop]: https://github.com/Bishop
Expand Down
2 changes: 0 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ require File.expand_path 'spec/support/detect_rails_version', File.dirname(__FIL
rails_version = detect_rails_version
gem 'rails', rails_version

gem 'inherited_resources', github: 'josevalim/inherited_resources', branch: 'rails-4-2'

# Optional dependencies
gem 'cancan'
gem 'devise'
Expand Down
12 changes: 0 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,6 @@ You can get Rails 4.x support by tracking master:
gem 'activeadmin', github: 'activeadmin'
```

#### Rails 4.2

To use ActiveAdmin with Rails 4.2, you need to change your Gemfile like this:

```ruby
gem 'activeadmin', github: 'activeadmin'
gem 'inherited_resources', github: 'josevalim/inherited_resources', branch: 'rails-4-2'
```

*But keep in mind that `inherited_resources` still don't support Rails 4.2 officially.*
*Track [josevalim/inherited_resources#381](https://github.com/josevalim/inherited_resources/issues/381) for details.*

### 0.6.x

The plan is to follow [semantic versioning](http://semver.org/) as of 1.0.0. The 0.6.x line will
Expand Down
2 changes: 1 addition & 1 deletion activeadmin.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Gem::Specification.new do |s|
s.add_dependency 'coffee-rails'
s.add_dependency 'formtastic', '~> 3.1'
s.add_dependency 'formtastic_i18n'
s.add_dependency 'inherited_resources', '~> 1.4', '!= 1.5.0'
s.add_dependency 'inherited_resources', '~> 1.6'
s.add_dependency 'jquery-rails'
s.add_dependency 'jquery-ui-rails', '~> 5.0'
s.add_dependency 'kaminari', '~> 0.15'
Expand Down
6 changes: 3 additions & 3 deletions app/assets/javascripts/active_admin/application.js.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Initializers
$ ->
$(document).on 'ready page:load', ->
# jQuery datepickers (also evaluates dynamically added HTML)
$(document).on 'focus', '.datepicker:not(.hasDatepicker)', ->
defaults = dateFormat: 'yy-mm-dd'
Expand All @@ -24,8 +24,8 @@ $ ->
$('.filter_form_field.select_and_search select').change ->
$(@).siblings('input').prop name: "q[#{@value}]"

# Tab navigation in the show page
$('#main_content .tabs').tabs()
# Tab navigation
$('#active_admin_content .tabs').tabs()

# In order for index scopes to overflow properly onto the next line, we have
# to manually set its width based on the width of the batch action button.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$ ->
$(document).on 'ready page:load', ->

#
# Use ActiveAdmin.modal_dialog to prompt user if confirmation is required for current Batch Action
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class ActiveAdmin.CheckboxToggler
constructor: (@options, @container)->
defaults = {}
@options = $.extend defaults, options
@options = $.extend defaults, @options
@_init()
@_bind()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ActiveAdmin.DropdownMenu
onClickActionItemCallback: null
}

@options = $.extend defaults, options
@options = $.extend defaults, @options
@isOpen = false

@$menuButton = @$element.find '.dropdown_menu_button'
Expand Down Expand Up @@ -97,5 +97,5 @@ class ActiveAdmin.DropdownMenu

$.widget.bridge 'aaDropdownMenu', ActiveAdmin.DropdownMenu

$ ->
$(document).on 'ready page:load', ->
$('.dropdown_menu').aaDropdownMenu()
27 changes: 27 additions & 0 deletions app/assets/javascripts/active_admin/lib/per_page.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class ActiveAdmin.PerPage
constructor: (@options, @element)->
@$element = $(@element)
@_init()
@_bind()

_init: ->
@$params = @_queryParams()

_bind: ->
@$element.change =>
@$params['per_page'] = @$element.val()
delete @$params['page']
location.search = $.param(@$params)

_queryParams: ->
query = window.location.search.substring(1)
params = {}
re = /([^&=]+)=([^&]*)/g
while m = re.exec(query)
params[decodeURIComponent(m[1])] = decodeURIComponent(m[2])
params

$.widget.bridge 'perPage', ActiveAdmin.PerPage

$ ->
$('.pagination_per_page select').perPage()
10 changes: 10 additions & 0 deletions app/assets/stylesheets/active_admin/components/_pagination.scss
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,13 @@
.download_links {
float: left;
}

.pagination_per_page {
float: right;
margin-left: 4px;
select {
@include light-button;
@include rounded(0px);
padding: 1px 5px;
}
}
1 change: 1 addition & 0 deletions docs/1-general-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ config.site_title = "My Admin Site"
config.site_title_link = "/"
config.site_title_image = "site_image.png"
config.site_title_image = "http://www.google.com/images/logos/google_logo_41.png"
config.site_title_image = ->(context) { context.current_user.company.logo_url }
```

## Internationalization (I18n)
Expand Down
2 changes: 1 addition & 1 deletion docs/6-show-pages.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ ActiveAdmin.register Ad do
show do
attributes_table do
row :title
row :image do
row :image do |ad|
image_tag ad.image.url
end
end
Expand Down
2 changes: 0 additions & 2 deletions features/comments/commenting.feature
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,6 @@ Feature: Commenting
When I add a comment "Hello World"
Then I should see a flash with "Comment was successfully created"
And I should be in the resource section for publishers
When I am on the index page for comments
Then I should see the content "Publisher"
And I should see "Hello World"

Scenario: Commenting on a class with string id
Expand Down
7 changes: 4 additions & 3 deletions lib/active_admin/batch_actions/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ module Controller
# Controller action that is called when submitting the batch action form
def batch_action
if action_present?
selection = params[:collection_selection] || []
inputs = JSON.parse params[:batch_action_inputs] || '{}'
inputs = inputs.with_indifferent_access.slice *current_batch_action.inputs.keys
selection = params[:collection_selection] || []
inputs = JSON.parse params[:batch_action_inputs] || '{}'
valid_keys = render_in_context(self, current_batch_action.inputs).try(:keys)
inputs = inputs.with_indifferent_access.slice *valid_keys
instance_exec selection, inputs, &current_batch_action.block
else
raise "Couldn't find batch action \"#{params[:batch_action]}\""
Expand Down
3 changes: 1 addition & 2 deletions lib/active_admin/batch_actions/resource_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ def confirm
end

def inputs
HashWithIndifferentAccess.new \
@options[:form].is_a?(Proc) ? @options[:form].call : @options[:form]
@options[:form]
end

# Returns the display if block. If the block was not explicitly defined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def build_drop_down
:class => "batch_action",
"data-action" => batch_action.sym,
"data-confirm" => confirmation_text,
"data-inputs" => batch_action.inputs.to_json
"data-inputs" => render_in_context(self, batch_action.inputs).to_json
}

default_title = render_or_call_method_or_proc_on(self, batch_action.title)
Expand Down
4 changes: 2 additions & 2 deletions lib/active_admin/namespace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ def add_logout_button_to_menu(menu, priority = 20, html_options = {})
def add_current_user_to_menu(menu, priority = 10, html_options = {})
if current_user_method
menu.add id: 'current_user', priority: priority, html_options: html_options,
label: ->{ display_name current_active_admin_user },
url: ->{ auto_url_for(current_active_admin_user) || '#' },
label: -> { display_name current_active_admin_user },
url: -> { auto_url_for(current_active_admin_user) },
if: :current_active_admin_user?
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Comment < ActiveRecord::Base

# @return [String] The name of the record to use for the polymorphic relationship
def self.resource_type(resource)
ResourceController::Decorators.undecorate(resource).class.name.to_s
ResourceController::Decorators.undecorate(resource).class.base_class.name.to_s
end

# Postgres adapters won't compare strings to numbers (issue 34)
Expand Down
20 changes: 18 additions & 2 deletions lib/active_admin/resource/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ def route_instance_path(resource)
RouteBuilder.new(self).instance_path(resource)
end

def route_edit_instance_path(resource)
RouteBuilder.new(self).edit_instance_path(resource)
end

# Returns the routes prefix for this config
def route_prefix
namespace.module_name.try(:underscore)
Expand All @@ -36,7 +40,7 @@ def initialize(resource)
def collection_path(params)
route_name = route_name(
resource.resources_configuration[:self][:route_collection_name],
(resource.route_uncountable? ? 'index_path' : 'path')
suffix: (resource.route_uncountable? ? "index_path" : "path")
)

routes.public_send route_name, *route_collection_params(params)
Expand All @@ -51,13 +55,25 @@ def instance_path(instance)
routes.public_send route_name, *route_instance_params(instance)
end

# @return [String] the path to the edit page of this resource
# @param instance [ActiveRecord::Base] the instance we want the path of
# @example "/admin/posts/1/edit"
def edit_instance_path(instance)
path = resource.resources_configuration[:self][:route_instance_name]
route_name = route_name(path, action: :edit)

routes.public_send route_name, *route_instance_params(instance)
end

private

attr_reader :resource

def route_name(resource_path_name, suffix = 'path')
def route_name(resource_path_name, options = {})
suffix = options[:suffix] || "path"
route = []

route << options[:action] # "edit" or "new"
route << resource.route_prefix # "admin"
route << belongs_to_name if nested? # "category"
route << resource_path_name # "posts" or "post"
Expand Down
14 changes: 13 additions & 1 deletion lib/active_admin/resource_controller/data_access.rb
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,24 @@ def apply_pagination(chain)

def per_page
if active_admin_config.paginate
@per_page || active_admin_config.per_page
dynamic_per_page || configured_per_page
else
max_per_page
end
end

def dynamic_per_page
params[:per_page] || @per_page
end

def configured_per_page
if active_admin_config.per_page.is_a?(Array)
active_admin_config.per_page[0]
else
active_admin_config.per_page
end
end

def max_per_page
10_000
end
Expand Down
9 changes: 8 additions & 1 deletion lib/active_admin/view_helpers/auto_link_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,15 @@ def auto_link(resource, content = display_name(resource))

# Like `auto_link`, except that it only returns a URL instead of a full <a> tag
def auto_url_for(resource)
if config = active_admin_resource_for(resource.class)
config = active_admin_resource_for(resource.class)
return unless config

if config.controller.action_methods.include?("show") &&
authorized?(ActiveAdmin::Auth::READ, resource)
url_for config.route_instance_path resource
elsif config.controller.action_methods.include?("edit") &&
authorized?(ActiveAdmin::Auth::UPDATE, resource)
url_for config.route_edit_instance_path resource
end
end

Expand Down
17 changes: 17 additions & 0 deletions lib/active_admin/views/components/paginated_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def build(collection, options = {})
@param_name = options.delete(:param_name)
@download_links = options.delete(:download_links)
@display_total = options.delete(:pagination_total) { true }
@per_page = options.delete(:per_page)

unless collection.respond_to?(:num_pages)
raise(StandardError, "Collection is not a paginated scope. Set collection.page(params[:page]).per(10) before calling :paginated_collection.")
Expand All @@ -63,6 +64,7 @@ def add_child(*args, &block)

def build_pagination_with_formats(options)
div id: "index_footer" do
build_per_page_select if @per_page.is_a?(Array)
build_pagination
div(page_entries_info(options).html_safe, class: "pagination_information")

Expand All @@ -76,6 +78,21 @@ def build_pagination_with_formats(options)
end
end

def build_per_page_select
div class: "pagination_per_page" do
text_node "Per page:"
select do
@per_page.each do |per_page|
option(
per_page,
value: per_page,
selected: collection.limit_value == per_page ? "selected" : nil
)
end
end
end
end

def build_pagination
options = {}
options[:param_name] = @param_name if @param_name
Expand Down
3 changes: 2 additions & 1 deletion lib/active_admin/views/pages/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,13 @@ def render_index
paginator = config.fetch(:paginator, true)
download_links = config.fetch(:download_links, active_admin_config.namespace.download_links)
pagination_total = config.fetch(:pagination_total, true)
per_page = config.fetch(:per_page, active_admin_config.per_page)

paginated_collection(collection, entry_name: active_admin_config.resource_label,
entries_name: active_admin_config.plural_resource_label(count: collection_size),
download_links: download_links,
paginator: paginator,
per_page: per_page,
pagination_total: pagination_total) do
div class: 'index_content' do
insert_tag(renderer_class, config, collection)
Expand Down Expand Up @@ -159,4 +161,3 @@ def default_blank_slate_link
end
end
end

6 changes: 5 additions & 1 deletion lib/active_admin/views/tabbed_navigation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ def build_menu_item(item)
li id: item.id do |li|
li.add_class "current" if item.current? assigns[:current_tab]

text_node link_to item.label(self), item.url(self), item.html_options
if url = item.url(self)
text_node link_to item.label(self), url, item.html_options
else
span item.label(self), item.html_options
end

if children = item.items(self).presence
li.add_class "has_nested"
Expand Down
Loading

0 comments on commit 33f5550

Please sign in to comment.