activeadmin 0.4.0 → 0.4.1

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.

Files changed (57) hide show
  1. data/CHANGELOG.md +46 -0
  2. data/Gemfile +1 -0
  3. data/README.rdoc +1 -1
  4. data/activeadmin.gemspec +1 -1
  5. data/app/assets/stylesheets/active_admin/_base.css.scss +2 -1
  6. data/app/assets/stylesheets/active_admin/components/_columns.scss +3 -0
  7. data/app/assets/stylesheets/active_admin/mixins/_sections.css.scss +1 -1
  8. data/app/views/active_admin/devise/sessions/new.html.erb +1 -1
  9. data/docs/2-resource-customization.md +13 -0
  10. data/docs/3-index-pages.md +23 -0
  11. data/docs/3-index-pages/index-as-grid.md +2 -2
  12. data/docs/7-sidebars.md +7 -0
  13. data/docs/8-custom-actions.md +6 -0
  14. data/features/action_item.feature +73 -0
  15. data/features/index/filters.feature +55 -22
  16. data/features/index/index_parameters.feature +12 -0
  17. data/features/index/index_scope_to.feature +29 -0
  18. data/features/index/index_scopes.feature +13 -0
  19. data/features/index/pagination.feature +14 -5
  20. data/features/sidebar_sections.feature +45 -0
  21. data/features/step_definitions/action_item_steps.rb +4 -0
  22. data/features/step_definitions/factory_steps.rb +3 -2
  23. data/features/step_definitions/filter_steps.rb +17 -0
  24. data/features/step_definitions/format_steps.rb +4 -0
  25. data/features/step_definitions/index_scope_steps.rb +5 -0
  26. data/lib/active_admin/arbre/html/tag.rb +9 -1
  27. data/lib/active_admin/helpers/optional_display.rb +13 -3
  28. data/lib/active_admin/locales/da.yml +15 -0
  29. data/lib/active_admin/locales/es.yml +18 -2
  30. data/lib/active_admin/locales/he_il.yml +45 -0
  31. data/lib/active_admin/menu_item.rb +0 -21
  32. data/lib/active_admin/page.rb +9 -0
  33. data/lib/active_admin/page_controller.rb +4 -0
  34. data/lib/active_admin/page_dsl.rb +7 -0
  35. data/lib/active_admin/reloader.rb +0 -1
  36. data/lib/active_admin/resource.rb +6 -0
  37. data/lib/active_admin/resource/action_items.rb +2 -2
  38. data/lib/active_admin/resource/pagination.rb +19 -0
  39. data/lib/active_admin/resource/sidebars.rb +2 -2
  40. data/lib/active_admin/resource_controller/callbacks.rb +13 -1
  41. data/lib/active_admin/resource_controller/collection.rb +17 -10
  42. data/lib/active_admin/router.rb +3 -0
  43. data/lib/active_admin/version.rb +1 -1
  44. data/lib/active_admin/views/components/columns.rb +115 -12
  45. data/lib/active_admin/views/components/scopes.rb +4 -4
  46. data/lib/active_admin/views/index_as_table.rb +14 -2
  47. data/lib/active_admin/views/pages/base.rb +2 -2
  48. data/lib/active_admin/views/pages/index.rb +25 -13
  49. data/lib/active_admin/views/tabbed_navigation.rb +14 -2
  50. data/spec/unit/menu_item_spec.rb +0 -14
  51. data/spec/unit/namespace/register_resource_spec.rb +1 -1
  52. data/spec/unit/resource/pagination_spec.rb +38 -0
  53. data/spec/unit/resource_controller/collection_spec.rb +1 -1
  54. data/spec/unit/views/components/columns_spec.rb +61 -4
  55. data/spec/unit/views/tabbed_navigation_spec.rb +2 -2
  56. metadata +20 -11
  57. data/features/index/filter_with_check_boxes.feature +0 -25
@@ -76,6 +76,51 @@ Feature: Sidebar Sections
76
76
  When I follow "New Post"
77
77
  Then I should see a sidebar titled "Help"
78
78
 
79
+ Scenario: Create a sidebar for only one action with if clause that returns false
80
+ Given a configuration of:
81
+ """
82
+ ActiveAdmin.register Post do
83
+ sidebar :help, :only => :index, :if => proc{ current_active_admin_user.nil? } do
84
+ "Need help? Email us at help@example.com"
85
+ end
86
+ end
87
+ """
88
+ When I am on the index page for posts
89
+ Then I should not see a sidebar titled "Help"
90
+
91
+ When I follow "View"
92
+ Then I should not see a sidebar titled "Help"
93
+
94
+ When I follow "Edit Post"
95
+ Then I should not see a sidebar titled "Help"
96
+
97
+ When I am on the index page for posts
98
+ When I follow "New Post"
99
+ Then I should not see a sidebar titled "Help"
100
+
101
+ Scenario: Create a sidebar for only one action with if clause that returns true
102
+ Given a configuration of:
103
+ """
104
+ ActiveAdmin.register Post do
105
+ sidebar :help, :only => :show, :if => proc{ !current_active_admin_user.nil? } do
106
+ "Need help? Email us at help@example.com"
107
+ end
108
+ end
109
+ """
110
+ When I am on the index page for posts
111
+ Then I should not see a sidebar titled "Help"
112
+
113
+ When I follow "View"
114
+ Then I should see a sidebar titled "Help"
115
+ Then I should see /Need help/ within the "Help" sidebar
116
+
117
+ When I follow "Edit Post"
118
+ Then I should not see a sidebar titled "Help"
119
+
120
+ When I am on the index page for posts
121
+ When I follow "New Post"
122
+ Then I should not see a sidebar titled "Help"
123
+
79
124
  Scenario: Create a sidebar with deep content
80
125
  Given a configuration of:
81
126
  """
@@ -1,3 +1,7 @@
1
1
  Then /^I should see an action item link to "([^"]*)"$/ do |link|
2
2
  page.should have_css('.action_item a', :text => link)
3
3
  end
4
+
5
+ Then /^I should not see an action item link to "([^"]*)"$/ do |link|
6
+ page.should_not have_css('.action_item a', :text => link)
7
+ end
@@ -6,10 +6,11 @@ Given /^a post with the title "([^"]*)" and body "([^"]*)" exists$/ do |title, b
6
6
  Post.create! :title => title, :body => body
7
7
  end
8
8
 
9
- Given /^a post with the title "([^"]*)" written by "([^"]*)" exists$/ do |title, author_name|
9
+ Given /^a (published )?post with the title "([^"]*)" written by "([^"]*)" exists$/ do |published, title, author_name|
10
10
  first, last = author_name.split(' ')
11
11
  author = User.find_or_create_by_first_name_and_last_name(first, last, :username => author_name.gsub(' ', '').underscore)
12
- Post.create! :title => title, :author => author
12
+ published_at = published ? Time.now : nil
13
+ Post.create! :title => title, :author => author, :published_at => published_at
13
14
  end
14
15
 
15
16
  Given /^(\d+)( published)? posts? exists?$/ do |count, published|
@@ -0,0 +1,17 @@
1
+ Then /^I should see a select filter for "([^"]*)"$/ do |label|
2
+ page.should have_css(".filter_select label", :text => label)
3
+ end
4
+
5
+ Then /^I should see a string filter for "([^"]*)"$/ do |label|
6
+ page.should have_css(".filter_string label", :text => "Search #{label}")
7
+ end
8
+
9
+ Then /^I should see a date range filter for "([^"]*)"$/ do |label|
10
+ page.should have_css(".filter_date_range label", :text => label)
11
+ end
12
+
13
+ Then /^I should see the following filters:$/ do |table|
14
+ table.rows_hash.each do |label, type|
15
+ step "I should see a #{type} filter for \"#{label}\""
16
+ end
17
+ end
@@ -14,6 +14,10 @@ Then /^I should see a link to download "([^"]*)"$/ do |format_type|
14
14
  page.should have_css("#index_footer a", :text => format_type)
15
15
  end
16
16
 
17
+ Then /^I should not see a link to download "([^"]*)"$/ do |format_type|
18
+ page.should_not have_css("#index_footer a", :text => format_type)
19
+ end
20
+
17
21
  # Check first rows of the displayed CSV.
18
22
  Then /^I should download a CSV file for "([^"]*)" containing:$/ do |resource_name, table|
19
23
  page.response_headers['Content-Type'].should == 'text/csv; charset=utf-8'
@@ -19,6 +19,11 @@ Then /^I should see the scope "([^"]*)" with the count (\d+)$/ do |name, count|
19
19
  step %{I should see "#{count}" within ".scopes .#{name.gsub(" ", "").underscore.downcase} .count"}
20
20
  end
21
21
 
22
+ Then /^I should see the scope "([^"]*)" with no count$/ do |name|
23
+ page.should have_css(".scopes .#{name.gsub(" ", "").underscore.downcase}")
24
+ page.should_not have_css(".scopes .#{name.gsub(" ", "").underscore.downcase} .count")
25
+ end
26
+
22
27
  Then /^I should see (\d+) ([\w]*) in the table$/ do |count, resource_type|
23
28
  begin
24
29
  page.should have_css("table##{resource_type} tr > td:first", :count => count.to_i)
@@ -73,11 +73,19 @@ module Arbre
73
73
  end
74
74
 
75
75
  def to_s
76
- indent("<#{tag_name}#{attributes_html}>", content, "</#{tag_name}>").html_safe
76
+ indent(opening_tag, content, closing_tag).html_safe
77
77
  end
78
78
 
79
79
  private
80
80
 
81
+ def opening_tag
82
+ "<#{tag_name}#{attributes_html}>"
83
+ end
84
+
85
+ def closing_tag
86
+ "</#{tag_name}>"
87
+ end
88
+
81
89
  INDENT_SIZE = 2
82
90
 
83
91
  def indent(open_tag, child_content, close_tag)
@@ -14,9 +14,19 @@ module ActiveAdmin
14
14
  # to ensure that the display options are setup correctly
15
15
 
16
16
  module OptionalDisplay
17
- def display_on?(action)
18
- return @options[:only].include?(action.to_sym) if @options[:only]
19
- return !@options[:except].include?(action.to_sym) if @options[:except]
17
+ def display_on?(action, render_context = nil)
18
+ return false if @options[:only] && !@options[:only].include?(action.to_sym)
19
+ return false if @options[:except] && @options[:except].include?(action.to_sym)
20
+ if @options[:if]
21
+ symbol_or_proc = @options[:if]
22
+ return case symbol_or_proc
23
+ when Symbol, String
24
+ self.send(symbol_or_proc)
25
+ when Proc
26
+ render_context ? render_context.instance_exec(&symbol_or_proc) : instance_exec(&symbol_or_proc)
27
+ else symbol_or_proc
28
+ end
29
+ end
20
30
  true
21
31
  end
22
32
 
@@ -1,6 +1,7 @@
1
1
  da:
2
2
  active_admin:
3
3
  dashboard_welcome:
4
+ dashboard: "Kontrolpanel"
4
5
  welcome: "Velkommen til Active Admin. Dette er standardoversigtssiden."
5
6
  call_to_action: "Rediger 'app/admin/dashboards.rb' for at tilføje nye elementer til oversigtssiden."
6
7
  view: "Vis"
@@ -26,3 +27,17 @@ da:
26
27
  less_than: "mindre end"
27
28
  main_content: "Implementer venligst %{model}#main_content for at vise noget indhold."
28
29
  logout: "Log ud"
30
+ sidebars:
31
+ filters: "Filtre"
32
+ pagination:
33
+ empty: "Ingen %{model} fundet"
34
+ one: "Viser <b>1</b> %{model}"
35
+ one_page: "Viser <b>alle %{n}</b> %{model}"
36
+ multiple: "Viser %{model} <b>%{from}&nbsp;-&nbsp;%{to}</b> af <b>%{total}</b> i alt"
37
+ entry:
38
+ one: "post"
39
+ other: "poster"
40
+ any: "Alle"
41
+ blank_slate:
42
+ content: "Der er ingen %{resource_name} endnu."
43
+ link: "Opret"
@@ -34,7 +34,23 @@ es:
34
34
  one: "Mostrando <b>1</b> %{model}"
35
35
  one_page: "Mostrando <b>todos(as) los(as) %{n}</b> %{model}"
36
36
  multiple: "Mostrando %{model} <b>%{from}&nbsp;-&nbsp;%{to}</b> de un total de <b>%{total}</b>"
37
- any: "Todos"
37
+ any: "Cualquiera"
38
38
  blank_slate:
39
39
  content: "No hay %{resource_name} aún."
40
- link: "Crea uno(a)"
40
+ link: "Crea uno(a)"
41
+ views:
42
+ pagination:
43
+ truncate: "..."
44
+ first: "Inicio"
45
+ previous: "Anterior"
46
+ next: "Siguiente"
47
+ last: "Ultimo"
48
+ formtastic:
49
+ yes: "Sí"
50
+ no: "No"
51
+ create: "Guardar %{model}"
52
+ update: "Guardar %{model}"
53
+ submit: "Aceptar"
54
+ cancel: "Cancelar"
55
+ reset: "Resetear %{model}"
56
+ required: "requerido"
@@ -0,0 +1,45 @@
1
+ he_il:
2
+ active_admin:
3
+ dashboard: פנל ניהול
4
+ dashboard_welcome:
5
+ welcome: "ברוכים הבאים לאקטיב אדמין. זהו פנל הניהול"
6
+ call_to_action: "כדי להוסיף אזורים בפנל הניהול, אנא בדוק את, 'app/admin/dashboards.rb'"
7
+ view: "צפייה"
8
+ edit: "עריכה"
9
+ delete: "מחיקה"
10
+ delete_confirmation: "האם אתה בטוח שאתה רוצה למחוק את זה?"
11
+ new_model: "%{model} חדש"
12
+ create_model: "יצירת %{model} חדש"
13
+ edit_model: "ערוך %{model}"
14
+ update_model: "עדכון %{model}"
15
+ delete_model: "מחיקת %{model}"
16
+ details: "פרטים על %{model}"
17
+ cancel: "ביטול"
18
+ empty: "ריק"
19
+ previous: "הקודם"
20
+ next: "הבא"
21
+ download: "הורד:"
22
+ has_many_new: "הוספת %{model חדש}"
23
+ has_many_delete: "מחיקה"
24
+ filter: "סינון"
25
+ clear_filters: "איפוס שדות"
26
+ search_field: "חיפוש %{field}"
27
+ equal_to: "שווה ל"
28
+ greater_than: "גדול מ"
29
+ less_than: "פחות מ"
30
+ main_content: "יש ליישם את התוכן של %{כדי להציג אותו כאן content."
31
+ logout: "התנתקות"
32
+ sidebars:
33
+ filters: "סינון"
34
+ pagination:
35
+ empty: "אין %{model} בנמצא"
36
+ one: "מציג <b>1</b> %{model}"
37
+ one_page: "הצגת <b>כל %{n}</b> %{model}"
38
+ multiple: "מציג %{model} <b>%{from}&nbsp;-&nbsp;%{to}</b> מתוך <b>%{total}</b> בסך הכל"
39
+ entry:
40
+ one: "רשומה בודדה"
41
+ other: "רשומות"
42
+ any: "Any"
43
+ blank_slate:
44
+ content: "כרגע אין עוד אף %{resource_name}."
45
+ link: "צור אחד"
@@ -1,16 +1,6 @@
1
1
  module ActiveAdmin
2
2
  class MenuItem
3
3
 
4
-
5
- # Generates a route using the rails application url helpers
6
- #
7
- # @param [Symbol] named_route
8
- #
9
- # @returns [String] The generated route
10
- def self.generate_url(named_route)
11
- Rails.application.routes.url_helpers.send(named_route)
12
- end
13
-
14
4
  attr_accessor :name, :url, :priority, :parent, :display_if_block
15
5
 
16
6
  def initialize(name, url, priority = 10, options = {})
@@ -41,16 +31,6 @@ module ActiveAdmin
41
31
  name.downcase.gsub( " ", '_' ).gsub( /[^a-z0-9_]/, '' )
42
32
  end
43
33
 
44
- def url
45
- case @url
46
- when Symbol
47
- generated = self.class.generate_url(@url) # Call the named route
48
- else
49
- generated = @url
50
- end
51
- @cached_url[@url] ||= generated
52
- end
53
-
54
34
  # Returns an array of the ancestory of this menu item
55
35
  # The first item is the immediate parent fo the item
56
36
  def ancestors
@@ -76,6 +56,5 @@ module ActiveAdmin
76
56
  @display_if_block || lambda { |_| true }
77
57
  end
78
58
 
79
-
80
59
  end
81
60
  end
@@ -15,11 +15,15 @@ module ActiveAdmin
15
15
  # The name of the page
16
16
  attr_reader :name
17
17
 
18
+ # An array of custom actions defined for this page
19
+ attr_reader :page_actions
20
+
18
21
  module Base
19
22
  def initialize(namespace, name, options)
20
23
  @namespace = namespace
21
24
  @name = name
22
25
  @options = options
26
+ @page_actions = []
23
27
  end
24
28
  end
25
29
 
@@ -60,6 +64,11 @@ module ActiveAdmin
60
64
 
61
65
  def add_default_sidebar_sections
62
66
  end
67
+
68
+ # Clears all the custom actions this page knows about
69
+ def clear_page_actions!
70
+ @page_actions = []
71
+ end
63
72
 
64
73
  end
65
74
  end
@@ -11,5 +11,9 @@ module ActiveAdmin
11
11
  def index(options={}, &block)
12
12
  render "active_admin/page/index"
13
13
  end
14
+
15
+ def clear_page_actions!
16
+ active_admin_config.clear_page_actions!
17
+ end
14
18
  end
15
19
  end
@@ -17,5 +17,12 @@ module ActiveAdmin
17
17
  def content(options = {}, &block)
18
18
  config.set_page_presenter :index, ActiveAdmin::PagePresenter.new(options, &block)
19
19
  end
20
+
21
+ def page_action(name, options = {}, &block)
22
+ config.page_actions << ControllerAction.new(name, options)
23
+ controller do
24
+ define_method(name, &block || Proc.new{})
25
+ end
26
+ end
20
27
  end
21
28
  end
@@ -70,7 +70,6 @@ module ActiveAdmin
70
70
 
71
71
  class FileUpdateChecker < ::ActiveSupport::FileUpdateChecker
72
72
  def paths
73
- Rails.logger.info [@files, @paths].inspect
74
73
  # hack to support both Rails 3.1 and 3.2
75
74
  @files || @paths
76
75
  end
@@ -2,6 +2,7 @@ require 'active_admin/resource/action_items'
2
2
  require 'active_admin/resource/controllers'
3
3
  require 'active_admin/resource/menu'
4
4
  require 'active_admin/resource/page_presenters'
5
+ require 'active_admin/resource/pagination'
5
6
  require 'active_admin/resource/naming'
6
7
  require 'active_admin/resource/scopes'
7
8
  require 'active_admin/resource/sidebars'
@@ -59,6 +60,7 @@ module ActiveAdmin
59
60
  include Base
60
61
  include Controllers
61
62
  include PagePresenters
63
+ include Pagination
62
64
  include ActionItems
63
65
  include Naming
64
66
  include Scopes
@@ -75,6 +77,10 @@ module ActiveAdmin
75
77
  resource_class.quoted_table_name
76
78
  end
77
79
 
80
+ def resource_quoted_column_name(column)
81
+ resource_class.connection.quote_column_name(column)
82
+ end
83
+
78
84
  # Returns the named route for an instance of this resource
79
85
  def route_instance_path
80
86
  [route_prefix, controller.resources_configuration[:self][:route_instance_name], 'path'].compact.join('_').to_sym
@@ -33,8 +33,8 @@ module ActiveAdmin
33
33
  # @param [String, Symbol] action the action to retrieve action items for
34
34
  #
35
35
  # @return [Array] Array of ActionItems for the controller actions
36
- def action_items_for(action)
37
- action_items.select{|item| item.display_on?(action) }
36
+ def action_items_for(action, render_context = nil)
37
+ action_items.select{|item| item.display_on?(action, render_context) }
38
38
  end
39
39
 
40
40
  # Clears all the existing action items for this resource
@@ -0,0 +1,19 @@
1
+ module ActiveAdmin
2
+
3
+ class Resource
4
+ module Pagination
5
+
6
+ # The default number of records to display per page
7
+ attr_accessor :per_page
8
+
9
+ # Enable / disable pagination (defaults to true)
10
+ attr_accessor :paginate
11
+
12
+ def initialize(*args)
13
+ super
14
+ @paginate = true
15
+ @per_page = namespace.default_per_page
16
+ end
17
+ end
18
+ end
19
+ end
@@ -18,8 +18,8 @@ module ActiveAdmin
18
18
  @sidebar_sections = []
19
19
  end
20
20
 
21
- def sidebar_sections_for(action)
22
- sidebar_sections.select{|section| section.display_on?(action) }
21
+ def sidebar_sections_for(action, render_context = nil)
22
+ sidebar_sections.select{|section| section.display_on?(action, render_context) }
23
23
  end
24
24
 
25
25
  def sidebar_sections?
@@ -30,7 +30,19 @@ module ActiveAdmin
30
30
  end
31
31
 
32
32
  def update_resource(object, attributes)
33
- object.attributes = attributes
33
+ # Inherited resources 1.3.0 calls the method passing an array instead of a parameters hash.
34
+ # The array contains in the first position the parameters which update the object and in the second position
35
+ # possibly contains the role, it's optional, to use in mass assignment. This feature is provided by Rails 3.1
36
+ if attributes.is_a?(Array)
37
+ if object.respond_to?(:assign_attributes)
38
+ object.assign_attributes(*attributes)
39
+ else
40
+ object.attributes = attributes[0]
41
+ end
42
+ else
43
+ object.attributes = attributes
44
+ end
45
+
34
46
  run_update_callbacks object do
35
47
  save_resource(object)
36
48
  end