activeadmin 0.3.4 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of activeadmin might be problematic. Click here for more details.
- data/.gitignore +1 -0
- data/.travis.yml +3 -0
- data/CHANGELOG.md +164 -5
- data/CONTRIBUTING.md +113 -0
- data/Gemfile +7 -9
- data/LICENSE +1 -1
- data/README.rdoc +19 -20
- data/activeadmin.gemspec +4 -2
- data/app/assets/javascripts/active_admin/application.js +9 -0
- data/app/assets/javascripts/active_admin/base.js +4 -12
- data/app/assets/stylesheets/active_admin/_base.css.scss +17 -341
- data/app/assets/stylesheets/active_admin/_forms.css.scss +13 -7
- data/app/assets/stylesheets/active_admin/_header.css.scss +23 -4
- data/app/assets/stylesheets/active_admin/components/_blank_slates.scss +31 -0
- data/app/assets/stylesheets/active_admin/components/_breadcrumbs.scss +20 -0
- data/app/assets/stylesheets/active_admin/components/_buttons.scss +12 -0
- data/app/assets/stylesheets/active_admin/components/_flash_messages.css.scss +2 -0
- data/app/assets/stylesheets/active_admin/components/_grid.scss +9 -0
- data/app/assets/stylesheets/active_admin/components/_links.scss +5 -0
- data/app/assets/stylesheets/active_admin/components/_pagination.scss +34 -0
- data/app/assets/stylesheets/active_admin/components/_panels.scss +6 -0
- data/app/assets/stylesheets/active_admin/components/_scopes.scss +10 -0
- data/app/assets/stylesheets/active_admin/components/_status_tags.scss +12 -0
- data/app/assets/stylesheets/active_admin/components/_table_tools.css.scss +101 -0
- data/app/assets/stylesheets/active_admin/components/_tables.css.scss +43 -2
- data/app/assets/stylesheets/active_admin/mixins/_all.css.scss +2 -1
- data/app/assets/stylesheets/active_admin/mixins/_buttons.css.scss +50 -13
- data/app/assets/stylesheets/active_admin/mixins/_gradients.css.scss +9 -1
- data/app/assets/stylesheets/active_admin/mixins/_sections.css.scss +7 -5
- data/app/assets/stylesheets/active_admin/mixins/_shadows.css.scss +1 -0
- data/app/assets/stylesheets/active_admin/mixins/_typography.scss +3 -0
- data/app/assets/stylesheets/active_admin/mixins/_utilities.scss +9 -0
- data/app/assets/stylesheets/active_admin/mixins/_variables.css.scss +1 -0
- data/app/assets/stylesheets/active_admin/pages/_dashboard.scss +5 -0
- data/app/assets/stylesheets/active_admin/pages/_logged_out.scss +44 -0
- data/app/assets/stylesheets/active_admin/structure/_footer.scss +14 -0
- data/app/assets/stylesheets/active_admin/structure/_main_structure.scss +26 -0
- data/app/assets/stylesheets/active_admin/structure/_title_bar.scss +44 -0
- data/app/views/active_admin/devise/passwords/edit.html.erb +1 -1
- data/app/views/active_admin/devise/passwords/new.html.erb +1 -1
- data/app/views/active_admin/devise/sessions/new.html.erb +1 -1
- data/app/views/active_admin/devise/shared/_links.erb +1 -1
- data/app/views/active_admin/devise/unlocks/new.html.erb +1 -1
- data/app/views/active_admin/page/index.html.arb +1 -0
- data/app/views/layouts/active_admin_logged_out.html.erb +2 -2
- data/cucumber.yml +3 -2
- data/docs/1-general-configuration.md +46 -10
- data/docs/6-show-screens.md +7 -0
- data/docs/8-custom-actions.md +12 -2
- data/docs/9-custom-pages.md +84 -0
- data/features/belongs_to.feature +27 -0
- data/features/comments/commenting.feature +3 -2
- data/features/dashboard.feature +18 -0
- data/features/development_reloading.feature +43 -0
- data/features/index/filter_with_check_boxes.feature +25 -0
- data/features/index/index_as_table.feature +14 -0
- data/features/index/index_scopes.feature +59 -0
- data/features/index/pagination.feature +19 -1
- data/features/menu.feature +22 -2
- data/features/registering_assets.feature +2 -2
- data/features/registering_pages.feature +66 -0
- data/features/specifying_actions.feature +5 -0
- data/features/step_definitions/action_item_steps.rb +2 -6
- data/features/step_definitions/action_link_steps.rb +7 -0
- data/features/step_definitions/additional_web_steps.rb +11 -3
- data/features/step_definitions/asset_steps.rb +5 -1
- data/features/step_definitions/breadcrumb_steps.rb +5 -0
- data/features/step_definitions/comment_steps.rb +3 -3
- data/features/step_definitions/configuration_steps.rb +69 -13
- data/features/step_definitions/dashboard_steps.rb +7 -3
- data/features/step_definitions/factory_steps.rb +9 -2
- data/features/step_definitions/flash_steps.rb +9 -1
- data/features/step_definitions/format_steps.rb +9 -1
- data/features/step_definitions/index_scope_steps.rb +18 -6
- data/features/step_definitions/member_link_steps.rb +7 -0
- data/features/step_definitions/pagination_steps.rb +2 -2
- data/features/step_definitions/site_title_steps.rb +15 -0
- data/features/step_definitions/tab_steps.rb +1 -1
- data/features/step_definitions/user_steps.rb +1 -1
- data/features/step_definitions/web_steps.rb +4 -4
- data/features/support/paths.rb +6 -0
- data/features/users/logging_out.feature +11 -0
- data/lib/active_admin.rb +26 -10
- data/lib/active_admin/application.rb +64 -22
- data/lib/active_admin/arbre.rb +0 -1
- data/lib/active_admin/arbre/builder.rb +8 -5
- data/lib/active_admin/arbre/context.rb +1 -1
- data/lib/active_admin/arbre/html/attributes.rb +1 -1
- data/lib/active_admin/arbre/html/class_list.rb +0 -4
- data/lib/active_admin/arbre/html/collection.rb +2 -2
- data/lib/active_admin/arbre/html/document.rb +1 -1
- data/lib/active_admin/arbre/html/element.rb +19 -9
- data/lib/active_admin/arbre/html/tag.rb +3 -3
- data/lib/active_admin/arbre/html/text_node.rb +2 -2
- data/lib/active_admin/asset_registration.rb +15 -2
- data/lib/active_admin/base_controller.rb +61 -0
- data/lib/active_admin/{resource_controller → base_controller}/menu.rb +1 -1
- data/lib/active_admin/callbacks.rb +16 -18
- data/lib/active_admin/comments.rb +48 -54
- data/lib/active_admin/comments/comment.rb +13 -2
- data/lib/active_admin/comments/namespace_helper.rb +1 -1
- data/lib/active_admin/comments/views/active_admin_comments.rb +7 -3
- data/lib/active_admin/dashboards.rb +4 -0
- data/lib/active_admin/dashboards/dashboard_controller.rb +21 -5
- data/lib/active_admin/dsl.rb +6 -159
- data/lib/active_admin/event.rb +5 -3
- data/lib/active_admin/filter_form_builder.rb +53 -0
- data/lib/active_admin/form_builder.rb +25 -19
- data/lib/active_admin/helpers/settings.rb +6 -10
- data/lib/active_admin/inputs.rb +14 -0
- data/lib/active_admin/inputs/datepicker_input.rb +11 -0
- data/lib/active_admin/inputs/filter_base.rb +46 -0
- data/lib/active_admin/inputs/filter_check_boxes_input.rb +40 -0
- data/lib/active_admin/inputs/filter_date_range_input.rb +34 -0
- data/lib/active_admin/inputs/filter_numeric_input.rb +55 -0
- data/lib/active_admin/inputs/filter_select_input.rb +23 -0
- data/lib/active_admin/inputs/filter_string_input.rb +22 -0
- data/lib/active_admin/locales/ca.yml +44 -0
- data/lib/active_admin/locales/cs.yml +14 -10
- data/lib/active_admin/locales/de.yml +44 -0
- data/lib/active_admin/locales/en.yml +5 -0
- data/lib/active_admin/locales/hr.yml +40 -0
- data/lib/active_admin/locales/hu.yml +45 -0
- data/lib/active_admin/locales/it.yml +11 -6
- data/lib/active_admin/locales/ko.yml +40 -0
- data/lib/active_admin/locales/lv.yml +43 -0
- data/lib/active_admin/locales/nl.yml +40 -0
- data/lib/active_admin/locales/no-NB.yml +40 -0
- data/lib/active_admin/locales/pl.yml +7 -1
- data/lib/active_admin/locales/pt-BR.yml +6 -2
- data/lib/active_admin/menu_item.rb +25 -17
- data/lib/active_admin/namespace.rb +48 -33
- data/lib/active_admin/page.rb +65 -0
- data/lib/active_admin/page_controller.rb +15 -0
- data/lib/active_admin/page_dsl.rb +21 -0
- data/lib/active_admin/page_presenter.rb +30 -0
- data/lib/active_admin/reloader.rb +109 -42
- data/lib/active_admin/resource.rb +38 -44
- data/lib/active_admin/resource/action_items.rb +5 -0
- data/lib/active_admin/resource/belongs_to.rb +4 -2
- data/lib/active_admin/resource/controllers.rb +35 -0
- data/lib/active_admin/resource/menu.rb +1 -2
- data/lib/active_admin/resource/naming.rb +53 -31
- data/lib/active_admin/resource/page_presenters.rb +28 -0
- data/lib/active_admin/resource/scopes.rb +16 -3
- data/lib/active_admin/resource/sidebars.rb +4 -0
- data/lib/active_admin/resource_collection.rb +88 -0
- data/lib/active_admin/resource_controller.rb +18 -54
- data/lib/active_admin/resource_controller/action_builder.rb +1 -1
- data/lib/active_admin/resource_controller/actions.rb +8 -8
- data/lib/active_admin/resource_controller/callbacks.rb +1 -1
- data/lib/active_admin/resource_controller/collection.rb +8 -4
- data/lib/active_admin/resource_controller/filters.rb +1 -1
- data/lib/active_admin/resource_controller/resource_class_methods.rb +24 -0
- data/lib/active_admin/resource_controller/scoping.rb +1 -1
- data/lib/active_admin/resource_controller/sidebars.rb +1 -1
- data/lib/active_admin/resource_dsl.rb +157 -0
- data/lib/active_admin/router.rb +21 -14
- data/lib/active_admin/scope.rb +15 -3
- data/lib/active_admin/version.rb +1 -1
- data/lib/active_admin/view_factory.rb +4 -3
- data/lib/active_admin/view_helpers/auto_link_helper.rb +1 -10
- data/lib/active_admin/view_helpers/breadcrumb_helper.rb +25 -21
- data/lib/active_admin/view_helpers/filter_form_helper.rb +0 -150
- data/lib/active_admin/views/components/attributes_table.rb +1 -1
- data/lib/active_admin/views/components/columns.rb +4 -4
- data/lib/active_admin/views/components/paginated_collection.rb +42 -13
- data/lib/active_admin/views/components/panel.rb +8 -0
- data/lib/active_admin/views/components/scopes.rb +24 -18
- data/lib/active_admin/views/components/status_tag.rb +6 -5
- data/lib/active_admin/views/components/table_for.rb +6 -2
- data/lib/active_admin/views/header_renderer.rb +31 -12
- data/lib/active_admin/views/index_as_block.rb +2 -2
- data/lib/active_admin/views/index_as_blog.rb +3 -3
- data/lib/active_admin/views/index_as_grid.rb +4 -4
- data/lib/active_admin/views/index_as_table.rb +13 -6
- data/lib/active_admin/views/pages/base.rb +4 -4
- data/lib/active_admin/views/pages/form.rb +49 -0
- data/lib/active_admin/views/pages/index.rb +18 -6
- data/lib/active_admin/views/pages/page.rb +24 -0
- data/lib/active_admin/views/pages/show.rb +1 -1
- data/lib/generators/active_admin/assets/assets_generator.rb +19 -1
- data/lib/generators/active_admin/install/templates/active_admin.rb.erb +38 -12
- data/lib/generators/active_admin/install/templates/dashboards.rb +6 -0
- data/script/use_rails +14 -7
- data/spec/spec_helper.rb +9 -14
- data/spec/spec_helper_without_rails.rb +10 -0
- data/spec/support/detect_rails_version.rb +22 -3
- data/spec/support/integration_example_group.rb +5 -7
- data/spec/support/rails_template.rb +11 -0
- data/spec/support/rails_template_with_data.rb +25 -0
- data/spec/support/templates/cucumber_with_reloading.rb +5 -0
- data/spec/unit/active_admin_spec.rb +8 -0
- data/spec/unit/application_spec.rb +48 -2
- data/spec/unit/arbre/context_spec.rb +1 -1
- data/spec/unit/arbre/html/element_finder_methods_spec.rb +58 -2
- data/spec/unit/arbre/html/element_spec.rb +18 -5
- data/spec/unit/arbre/html/tag_attributes_spec.rb +3 -3
- data/spec/unit/arbre/html/tag_spec.rb +1 -1
- data/spec/unit/arbre/html_spec.rb +32 -22
- data/spec/unit/asset_registration_spec.rb +9 -3
- data/spec/unit/auto_link_spec.rb +2 -2
- data/spec/unit/base_controller_shared_examples.rb +28 -0
- data/spec/unit/base_controller_spec.rb +8 -0
- data/spec/unit/belongs_to_spec.rb +30 -33
- data/spec/unit/comments_spec.rb +45 -15
- data/spec/unit/config_shared_examples.rb +119 -0
- data/spec/unit/dashboard_controller_spec.rb +44 -0
- data/spec/unit/event_spec.rb +6 -0
- data/spec/unit/filter_form_builder_spec.rb +9 -0
- data/spec/unit/form_builder_spec.rb +8 -14
- data/spec/unit/menu_item_spec.rb +25 -20
- data/spec/unit/namespace/register_page_spec.rb +102 -0
- data/spec/unit/namespace/register_resource_spec.rb +188 -0
- data/spec/unit/namespace_spec.rb +11 -183
- data/spec/unit/page_controller_spec.rb +8 -0
- data/spec/unit/page_spec.rb +60 -0
- data/spec/unit/reloader_spec.rb +82 -38
- data/spec/unit/resource/menu_spec.rb +1 -51
- data/spec/unit/resource/naming_spec.rb +25 -20
- data/spec/unit/resource/page_presenters_spec.rb +32 -0
- data/spec/unit/resource/scopes_spec.rb +13 -0
- data/spec/unit/resource_collection_spec.rb +101 -0
- data/spec/unit/resource_controller_spec.rb +40 -32
- data/spec/unit/{registration_spec.rb → resource_registration_spec.rb} +0 -0
- data/spec/unit/resource_spec.rb +8 -24
- data/spec/unit/routing_spec.rb +50 -1
- data/spec/unit/scope_spec.rb +18 -4
- data/spec/unit/views/components/paginated_collection_spec.rb +163 -0
- data/spec/unit/views/components/panel_spec.rb +9 -0
- data/spec/unit/views/components/status_tag_spec.rb +9 -0
- data/spec/unit/views/tabbed_navigation_spec.rb +2 -1
- data/tasks/test.rake +44 -26
- metadata +176 -69
- data/app/assets/javascripts/active_admin/vendor.js +0 -382
- data/lib/active_admin/arbre/core_extensions.rb +0 -5
- data/lib/active_admin/comments/configuration.rb +0 -18
- data/lib/active_admin/page_config.rb +0 -15
- data/lib/active_admin/resource_controller/form.rb +0 -42
- data/lib/active_admin/resource_controller/page_configurations.rb +0 -53
- data/lib/active_admin/views/pages/edit.rb +0 -28
- data/lib/active_admin/views/pages/new.rb +0 -28
- data/lib/generators/active_admin/assets/templates/3.0/active_admin.js +0 -427
- data/spec/integration/belongs_to_spec.rb +0 -42
@@ -2,27 +2,31 @@ module ActiveAdmin
|
|
2
2
|
module ViewHelpers
|
3
3
|
module BreadcrumbHelper
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
5
|
+
# Returns an array of links to use in a breadcrumb
|
6
|
+
def breadcrumb_links(path = nil)
|
7
|
+
path ||= request.fullpath
|
8
|
+
parts = path.gsub(/^\//, '').split('/')
|
9
|
+
parts.pop unless %w{ create update }.include?(params[:action])
|
10
|
+
crumbs = []
|
11
|
+
parts.each_with_index do |part, index|
|
12
|
+
name = ""
|
13
|
+
if part =~ /^\d/ && parent = parts[index - 1]
|
14
|
+
begin
|
15
|
+
parent_class = parent.singularize.camelcase.constantize
|
16
|
+
obj = parent_class.find(part.to_i)
|
17
|
+
name = obj.display_name if obj.respond_to?(:display_name)
|
18
|
+
rescue
|
19
|
+
end
|
20
|
+
end
|
21
|
+
name = part.titlecase if name == ""
|
22
|
+
begin
|
23
|
+
crumbs << link_to( I18n.translate!("activerecord.models.#{part.singularize}", :count => 2), "/" + parts[0..index].join('/'))
|
24
|
+
rescue I18n::MissingTranslationData
|
25
|
+
crumbs << link_to( name, "/" + parts[0..index].join('/'))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
crumbs
|
29
|
+
end
|
26
30
|
|
27
31
|
end
|
28
32
|
end
|
@@ -33,154 +33,4 @@ module ActiveAdmin
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
# This form builder defines methods to build filter forms such
|
37
|
-
# as the one found in the sidebar of the index page of a standard resource.
|
38
|
-
class FilterFormBuilder < FormBuilder
|
39
|
-
|
40
|
-
def filter(method, options = {})
|
41
|
-
return "" if method.nil? || method == ""
|
42
|
-
options[:as] ||= default_filter_type(method)
|
43
|
-
return "" unless options[:as]
|
44
|
-
field_type = options.delete(:as)
|
45
|
-
options[:label] ||= default_filter_label(method)
|
46
|
-
content = with_new_form_buffer do
|
47
|
-
send("filter_#{field_type}_input", method, options)
|
48
|
-
end
|
49
|
-
@form_buffers.last << template.content_tag(:div, content, :class => "filter_form_field filter_#{field_type}")
|
50
|
-
end
|
51
|
-
|
52
|
-
protected
|
53
|
-
|
54
|
-
def filter_string_input(method, options = {})
|
55
|
-
field_name = "#{method}_contains"
|
56
|
-
|
57
|
-
[ label(field_name, I18n.t('active_admin.search_field', :field => options[:label])),
|
58
|
-
text_field(field_name)
|
59
|
-
].join("\n").html_safe
|
60
|
-
end
|
61
|
-
|
62
|
-
def filter_date_range_input(method, options = {})
|
63
|
-
gt_field_name = "#{method}_gte"
|
64
|
-
lt_field_name = "#{method}_lte"
|
65
|
-
|
66
|
-
[ label(gt_field_name, options[:label]),
|
67
|
-
filter_date_text_field(gt_field_name),
|
68
|
-
template.content_tag(:span, "-", :class => "seperator"),
|
69
|
-
filter_date_text_field(lt_field_name)
|
70
|
-
].join("\n").html_safe
|
71
|
-
end
|
72
|
-
|
73
|
-
def filter_date_text_field(method)
|
74
|
-
current_value = @object.send(method)
|
75
|
-
text_field(method, :size => 12, :class => "datepicker", :max => 10, :value => current_value.respond_to?(:strftime) ? current_value.strftime("%Y-%m-%d") : "")
|
76
|
-
end
|
77
|
-
|
78
|
-
def filter_numeric_input(method, options = {})
|
79
|
-
filters = numeric_filters_for_method(method, options.delete(:filters) || default_numeric_filters)
|
80
|
-
current_filter = current_numeric_scope(filters)
|
81
|
-
filter_select = @template.select_tag '', @template.options_for_select(filters, current_filter),
|
82
|
-
:onchange => "document.getElementById('#{method}_numeric').name = 'q[' + this.value + ']';"
|
83
|
-
filter_input = text_field current_filter, :size => 10, :id => "#{method}_numeric"
|
84
|
-
|
85
|
-
[ label(method, options[:label]),
|
86
|
-
filter_select,
|
87
|
-
" ",
|
88
|
-
filter_input
|
89
|
-
].join("\n").html_safe
|
90
|
-
end
|
91
|
-
|
92
|
-
def numeric_filters_for_method(method, filters)
|
93
|
-
filters.collect{|scope| [scope[0], [method,scope[1]].join("_") ] }
|
94
|
-
end
|
95
|
-
|
96
|
-
# Returns the scope for which we are currently searching. If no search is available
|
97
|
-
# it returns the first scope
|
98
|
-
def current_numeric_scope(filters)
|
99
|
-
filters[1..-1].inject(filters.first){|a,b| object.send(b[1].to_sym) ? b : a }[1]
|
100
|
-
end
|
101
|
-
|
102
|
-
def default_numeric_filters
|
103
|
-
[[I18n.t('active_admin.equal_to'), 'eq'], [I18n.t('active_admin.greater_than'), 'gt'], [I18n.t('active_admin.less_than'), 'lt']]
|
104
|
-
end
|
105
|
-
|
106
|
-
def filter_select_input(method, options = {})
|
107
|
-
association_name = method.to_s.gsub(/_id$/, '').to_sym
|
108
|
-
input_name = (generate_association_input_name(method).to_s + "_eq").to_sym
|
109
|
-
collection = find_collection_for_column(association_name, options)
|
110
|
-
|
111
|
-
[ label(input_name, options[:label]),
|
112
|
-
select(input_name, collection, options.merge(:include_blank => I18n.t('active_admin.any')))
|
113
|
-
].join("\n").html_safe
|
114
|
-
end
|
115
|
-
|
116
|
-
def filter_check_boxes_input(method, options = {})
|
117
|
-
input_name = (generate_association_input_name(method).to_s + "_in").to_sym
|
118
|
-
collection = find_collection_for_column(method, options)
|
119
|
-
selected_values = @object.send(input_name) || []
|
120
|
-
checkboxes = template.content_tag :div, :class => "check_boxes_wrapper" do
|
121
|
-
collection.map do |c|
|
122
|
-
label = c.is_a?(Array) ? c.first : c
|
123
|
-
value = c.is_a?(Array) ? c.last : c
|
124
|
-
"<label><input type=\"checkbox\" name=\"q[#{input_name}][]\" value=\"#{value}\" #{selected_values.include?(value) ? "checked" : ""}/> #{label}</label>"
|
125
|
-
end.join("\n").html_safe
|
126
|
-
end
|
127
|
-
|
128
|
-
[ label(input_name, options[:label]),
|
129
|
-
checkboxes
|
130
|
-
].join("\n").html_safe
|
131
|
-
end
|
132
|
-
|
133
|
-
# Override the standard finder to accept a proc
|
134
|
-
def find_collection_for_column(method, options = {})
|
135
|
-
options = options.dup
|
136
|
-
case options[:collection]
|
137
|
-
when Proc
|
138
|
-
options[:collection] = options[:collection].call
|
139
|
-
end
|
140
|
-
super(method, options)
|
141
|
-
end
|
142
|
-
|
143
|
-
# Returns the default filter type for a given attribute
|
144
|
-
def default_filter_type(method)
|
145
|
-
if column = column_for(method)
|
146
|
-
case column.type
|
147
|
-
when :date, :datetime
|
148
|
-
return :date_range
|
149
|
-
when :string, :text
|
150
|
-
return :string
|
151
|
-
when :integer
|
152
|
-
return :select if reflection_for(method.to_s.gsub('_id','').to_sym)
|
153
|
-
return :numeric
|
154
|
-
when :float, :decimal
|
155
|
-
return :numeric
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
if reflection = reflection_for(method)
|
160
|
-
return :select if reflection.macro == :belongs_to && !reflection.options[:polymorphic]
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
# Returns the default label for a given attribute
|
165
|
-
# Will use ActiveModel I18n if possible
|
166
|
-
def default_filter_label(method)
|
167
|
-
if @object.base.respond_to?(:human_attribute_name)
|
168
|
-
@object.base.human_attribute_name(method)
|
169
|
-
else
|
170
|
-
method.to_s.titlecase
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
# Returns the column for an attribute on the object being searched
|
175
|
-
# if it exists. Otherwise returns nil
|
176
|
-
def column_for(method)
|
177
|
-
@object.base.columns_hash[method.to_s] if @object.base.respond_to?(:columns_hash)
|
178
|
-
end
|
179
|
-
|
180
|
-
# Returns the association reflection for the method if it exists
|
181
|
-
def reflection_for(method)
|
182
|
-
@object.base.reflect_on_association(method) if @object.base.respond_to?(:reflect_on_association)
|
183
|
-
end
|
184
|
-
|
185
|
-
end
|
186
36
|
end
|
@@ -14,6 +14,10 @@ module ActiveAdmin
|
|
14
14
|
calculate_columns!
|
15
15
|
end
|
16
16
|
|
17
|
+
def to_s
|
18
|
+
super.to_s + "<div style=\"clear:both;\"></div>".html_safe
|
19
|
+
end
|
20
|
+
|
17
21
|
protected
|
18
22
|
|
19
23
|
def margin_size
|
@@ -35,10 +39,6 @@ module ActiveAdmin
|
|
35
39
|
end
|
36
40
|
end
|
37
41
|
|
38
|
-
def to_html
|
39
|
-
super.to_s + "<div style=\"clear:both;\"></div>".html_safe
|
40
|
-
end
|
41
|
-
|
42
42
|
end
|
43
43
|
|
44
44
|
class Column < ActiveAdmin::Component
|
@@ -23,6 +23,7 @@ module ActiveAdmin
|
|
23
23
|
class PaginatedCollection < ActiveAdmin::Component
|
24
24
|
builder_method :paginated_collection
|
25
25
|
|
26
|
+
attr_reader :collection
|
26
27
|
|
27
28
|
# Builds a new paginated collection component
|
28
29
|
#
|
@@ -30,12 +31,21 @@ module ActiveAdmin
|
|
30
31
|
# @param [Hash] options These options will be passed on to the page_entries_info
|
31
32
|
# method.
|
32
33
|
# Useful keys:
|
33
|
-
#
|
34
|
+
# :entry_name - The name to display for this resource collection
|
35
|
+
# :param_name - Parameter name for page number in the links (:page by default)
|
36
|
+
# :download_links - Set to false to skip download format links
|
34
37
|
def build(collection, options = {})
|
35
38
|
@collection = collection
|
36
|
-
|
39
|
+
@param_name = options.delete(:param_name)
|
40
|
+
@download_links = options.delete(:download_links)
|
41
|
+
|
42
|
+
unless collection.respond_to?(:num_pages)
|
43
|
+
raise(StandardError, "Collection is not a paginated scope. Set collection.page(params[:page]).per(10) before calling :paginated_collection.")
|
44
|
+
end
|
45
|
+
|
46
|
+
|
37
47
|
@contents = div(:class => "paginated_collection_contents")
|
38
|
-
build_pagination_with_formats
|
48
|
+
build_pagination_with_formats(options)
|
39
49
|
@built = true
|
40
50
|
end
|
41
51
|
|
@@ -50,15 +60,19 @@ module ActiveAdmin
|
|
50
60
|
|
51
61
|
protected
|
52
62
|
|
53
|
-
def build_pagination_with_formats
|
63
|
+
def build_pagination_with_formats(options)
|
54
64
|
div :id => "index_footer" do
|
55
|
-
build_download_format_links
|
56
65
|
build_pagination
|
66
|
+
div(page_entries_info(options).html_safe, :class => "pagination_information")
|
67
|
+
build_download_format_links unless @download_links == false
|
57
68
|
end
|
58
69
|
end
|
59
70
|
|
60
71
|
def build_pagination
|
61
|
-
|
72
|
+
options = request.query_parameters.except(:commit, :format)
|
73
|
+
options[:param_name] = @param_name if @param_name
|
74
|
+
|
75
|
+
text_node paginate(collection, options.symbolize_keys)
|
62
76
|
end
|
63
77
|
|
64
78
|
# TODO: Refactor to new HTML DSL
|
@@ -66,24 +80,39 @@ module ActiveAdmin
|
|
66
80
|
links = formats.collect do |format|
|
67
81
|
link_to format.to_s.upcase, { :format => format}.merge(request.query_parameters.except(:commit, :format))
|
68
82
|
end
|
69
|
-
|
83
|
+
div :class => "download_links" do
|
84
|
+
text_node [I18n.t('active_admin.download'), links].flatten.join(" ").html_safe
|
85
|
+
end
|
70
86
|
end
|
71
87
|
|
72
88
|
# modified from will_paginate
|
73
89
|
def page_entries_info(options = {})
|
74
|
-
|
75
|
-
|
90
|
+
if options[:entry_name]
|
91
|
+
entry_name = options[:entry_name]
|
92
|
+
entries_name = options[:entries_name]
|
93
|
+
elsif collection.empty?
|
94
|
+
entry_name = I18n.translate("active_admin.pagination.entry", :count => 1, :default => 'entry')
|
95
|
+
entries_name = I18n.translate("active_admin.pagination.entry", :count => 2, :default => 'entries')
|
96
|
+
else
|
97
|
+
begin
|
98
|
+
entry_name = I18n.translate!("activerecord.models.#{collection.first.class.model_name.i18n_key}", :count => 1)
|
99
|
+
entries_name = I18n.translate!("activerecord.models.#{collection.first.class.model_name.i18n_key}", :count => collection.size)
|
100
|
+
rescue I18n::MissingTranslationData
|
101
|
+
entry_name = collection.first.class.name.underscore.sub('_', ' ')
|
102
|
+
end
|
103
|
+
end
|
104
|
+
entries_name = entry_name.pluralize unless entries_name
|
76
105
|
|
77
106
|
if collection.num_pages < 2
|
78
107
|
case collection.size
|
79
|
-
when 0; I18n.t('active_admin.pagination.empty', :model =>
|
108
|
+
when 0; I18n.t('active_admin.pagination.empty', :model => entries_name)
|
80
109
|
when 1; I18n.t('active_admin.pagination.one', :model => entry_name)
|
81
|
-
else; I18n.t('active_admin.pagination.one_page', :model =>
|
110
|
+
else; I18n.t('active_admin.pagination.one_page', :model => entries_name, :n => collection.total_count)
|
82
111
|
end
|
83
112
|
else
|
84
|
-
offset = collection.current_page *
|
113
|
+
offset = collection.current_page * collection.size
|
85
114
|
total = collection.total_count
|
86
|
-
I18n.t('active_admin.pagination.multiple', :model =>
|
115
|
+
I18n.t('active_admin.pagination.multiple', :model => entries_name, :from => (offset - collection.size + 1), :to => offset > total ? total : offset, :total => total)
|
87
116
|
end
|
88
117
|
end
|
89
118
|
|
@@ -20,6 +20,14 @@ module ActiveAdmin
|
|
20
20
|
super
|
21
21
|
end
|
22
22
|
end
|
23
|
+
|
24
|
+
# Override children? to only report children when the panel's
|
25
|
+
# contents have been added to. This ensures that the panel
|
26
|
+
# correcly appends string values, etc.
|
27
|
+
def children?
|
28
|
+
@contents.children?
|
29
|
+
end
|
30
|
+
|
23
31
|
end
|
24
32
|
|
25
33
|
end
|
@@ -6,30 +6,40 @@ module ActiveAdmin
|
|
6
6
|
class Scopes < ActiveAdmin::Component
|
7
7
|
builder_method :scopes_renderer
|
8
8
|
|
9
|
+
include ActiveAdmin::ScopeChain
|
10
|
+
|
11
|
+
def default_class_name
|
12
|
+
"scopes table_tools_segmented_control"
|
13
|
+
end
|
14
|
+
|
15
|
+
def tag_name
|
16
|
+
'ul'
|
17
|
+
end
|
18
|
+
|
9
19
|
def build(scopes)
|
10
|
-
|
11
|
-
|
20
|
+
unless current_filter_search_empty?
|
21
|
+
scopes.each do |scope|
|
22
|
+
build_scope(scope) if call_method_or_proc_on(self, scope.display_if_block)
|
23
|
+
end
|
12
24
|
end
|
13
25
|
end
|
14
26
|
|
15
27
|
protected
|
16
28
|
|
17
29
|
def build_scope(scope)
|
18
|
-
|
30
|
+
li :class => classes_for_scope(scope) do
|
19
31
|
begin
|
20
|
-
scope_name = I18n.t!("active_admin.scopes.#{scope.
|
32
|
+
scope_name = I18n.t!("active_admin.scopes.#{scope.id}")
|
21
33
|
rescue I18n::MissingTranslationData
|
22
34
|
scope_name = scope.name
|
23
35
|
end
|
24
36
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
37
|
+
a :href => url_for(params.merge(:scope => scope.id, :page => 1)), :class => "table_tools_button" do
|
38
|
+
text_node scope_name
|
39
|
+
span :class => 'count' do
|
40
|
+
"(" + get_scope_count(scope).to_s + ")"
|
41
|
+
end
|
29
42
|
end
|
30
|
-
text_node(" ")
|
31
|
-
scope_count(scope)
|
32
|
-
text_node(" ")
|
33
43
|
end
|
34
44
|
end
|
35
45
|
|
@@ -47,21 +57,17 @@ module ActiveAdmin
|
|
47
57
|
end
|
48
58
|
end
|
49
59
|
|
50
|
-
def
|
51
|
-
|
52
|
-
"(" + get_scope_count(scope).to_s + ")"
|
53
|
-
end
|
60
|
+
def current_filter_search_empty?
|
61
|
+
collection.empty? && params.include?(:q)
|
54
62
|
end
|
55
63
|
|
56
|
-
include ActiveAdmin::ScopeChain
|
57
|
-
|
58
64
|
# Return the count for the scope passed in.
|
59
65
|
def get_scope_count(scope)
|
60
66
|
scope_chain(scope, scoping_class).count
|
61
67
|
end
|
62
68
|
|
63
69
|
def scoping_class
|
64
|
-
assigns["before_scope_collection"] || active_admin_config.
|
70
|
+
assigns["before_scope_collection"] || active_admin_config.resource_class
|
65
71
|
end
|
66
72
|
|
67
73
|
end
|
@@ -16,7 +16,7 @@ module ActiveAdmin
|
|
16
16
|
#
|
17
17
|
# @param [String] status the status to display. One of the span classes will be an underscored version of the status.
|
18
18
|
# @param [Symbol] type type of status. Will become a class of the span. ActiveAdmin provide style for :ok, :warning and :error.
|
19
|
-
# @param [Hash] options such as :class, :id
|
19
|
+
# @param [Hash] options such as :class, :id and :label to override the default label
|
20
20
|
#
|
21
21
|
# @return [ActiveAdmin::Views::StatusTag]
|
22
22
|
#
|
@@ -27,18 +27,19 @@ module ActiveAdmin
|
|
27
27
|
# status_tag('active', :ok)
|
28
28
|
# # => <span class='status active ok'>Active</span>
|
29
29
|
#
|
30
|
-
# status_tag('active', :ok, :class => 'important', :id => 'status_123')
|
31
|
-
# # => <span class='status active ok important' id='status_123'>
|
30
|
+
# status_tag('active', :ok, :class => 'important', :id => 'status_123', :label => 'on')
|
31
|
+
# # => <span class='status active ok important' id='status_123'>on</span>
|
32
32
|
#
|
33
33
|
def build(*args)
|
34
34
|
options = args.extract_options!
|
35
35
|
status = args[0]
|
36
36
|
type = args[1]
|
37
|
+
label = options.delete(:label)
|
37
38
|
classes = options.delete(:class)
|
38
39
|
|
39
|
-
|
40
|
+
content = label || status.titleize if status
|
40
41
|
|
41
|
-
super(
|
42
|
+
super(content, options)
|
42
43
|
|
43
44
|
add_class(status_to_class(status)) if status
|
44
45
|
add_class(type.to_s) if type
|