app/controllers/admin/manager_controller.rb in ab_admin-0.3.6 vs app/controllers/admin/manager_controller.rb in ab_admin-0.4.0
- old
+ new
@@ -1,14 +1,14 @@
class ::Admin::ManagerController < ::Admin::BaseController
include AbAdmin::Utils::EvalHelpers
include AbAdmin::Controllers::Tree
- prepend_before_filter :manager
+ prepend_before_action :manager
load_and_authorize_resource
- helper_method :manager, :admin_partial_name
+ helper_method :manager, :admin_partial_name, :history_resource_path, :fetch_admin_template
def custom_action
custom_action = manager.custom_action_for(params[:custom_action], self)
if custom_action.options[:method] && custom_action.options[:method] != request.method_symbol
raise ActionController::RoutingError.new("AbAdmin custom action for #{params[:custom_action]} not found")
@@ -67,11 +67,13 @@
for_resource = params[:id].present? && resource.persisted?
manager.default_action_items_for(action_name.to_sym, for_resource) + manager.action_items_for(action_name.to_sym)
end
def apply_batch_action(item, batch_action)
- call_method_or_proc_on item, manager.batch_action_list.detect{|a| a.name == batch_action }.data, exec: false
+ success = call_method_or_proc_on item, manager.batch_action_list.detect{|a| a.name == batch_action }.data, exec: false
+ track_action!("batch_#{batch_action}", item) if settings[:history]
+ success
end
def allow_batch_action?(batch_action)
manager.batch_action_list.detect { |a| a.name == batch_action }
end
@@ -108,22 +110,26 @@
end
end
def preview_resource_path(item)
return unless manager.preview_path
- manager.preview_path.is_a?(Proc) ? manager.preview_path.bind(self).call(item) : send(manager.preview_path, item)
+ manager.preview_path.is_a?(Proc) ? instance_exec(item, &manager.preview_path) : send(manager.preview_path, item)
end
def admin_partial_name(builder)
builder.partial ||= begin
#if template_exists?(builder.partial_name, "admin/#{resource_collection_name}", true)
- if Dir[Rails.root.join("app/views/admin/#{resource_collection_name}/_#{builder.partial_name}.html.*")].present?
- "admin/#{resource_collection_name}/#{builder.partial_name}"
- end
+ fetch_admin_template(builder.partial_name, true)
end
end
+ def fetch_admin_template(template_name, partial=false)
+ if Dir[Rails.root.join("app/views/admin/#{resource_collection_name}/#{'_' if partial}#{template_name}.html.*")].present?
+ "admin/#{resource_collection_name}/#{template_name}"
+ end
+ end
+
def resource_collection_name
resource_class.model_name.plural
end
def resource_instance_name
@@ -140,17 +146,22 @@
def new_resource_path(options={})
admin_new_path(options.merge(model_name: resource_collection_name))
end
+ def resource_path(record=nil, options={})
+ record ||= resource
+ admin_show_path(options.merge(model_name: record.class.model_name.plural, id: record.id))
+ end
+
def edit_resource_path(record=nil, options={})
record ||= resource
admin_edit_path(options.merge(model_name: record.class.model_name.plural, id: record.id))
end
- def resource_path(record=nil, options={})
+ def history_resource_path(record=nil, options={})
record ||= resource
- admin_show_path(options.merge(model_name: record.class.model_name.plural, id: record.id))
+ admin_history_path(options.merge(model_name: record.class.model_name.plural, id: record.id))
end
def self.cancan_resource_class
AbAdmin::Controllers::CanCanManagerResource
end