simple_admin 0.6.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +0 -0
  3. data/.rspec +0 -0
  4. data/Gemfile +1 -0
  5. data/LICENSE +0 -0
  6. data/README.rdoc +0 -0
  7. data/Rakefile +0 -0
  8. data/TODO.rdoc +0 -0
  9. data/app/assets/images/simple_admin/active_admin/admin_notes_icon.png +0 -0
  10. data/app/assets/images/simple_admin/active_admin/loading.gif +0 -0
  11. data/app/assets/images/simple_admin/active_admin/nested_menu_arrow.gif +0 -0
  12. data/app/assets/images/simple_admin/active_admin/nested_menu_arrow_dark.gif +0 -0
  13. data/app/assets/images/simple_admin/active_admin/orderable.png +0 -0
  14. data/app/assets/javascripts/simple_admin/active_admin.js +0 -0
  15. data/app/assets/stylesheets/simple_admin/active_admin.css +0 -0
  16. data/app/controllers/simple_admin/admin_controller.rb +5 -9
  17. data/app/helpers/simple_admin/admin_helper.rb +0 -0
  18. data/app/helpers/simple_admin/assets_helper.rb +0 -0
  19. data/app/helpers/simple_admin/display_helper.rb +4 -4
  20. data/app/helpers/simple_admin/filter_helper.rb +7 -6
  21. data/app/helpers/simple_admin/form_helper.rb +8 -8
  22. data/app/helpers/simple_admin/header_helper.rb +2 -2
  23. data/app/helpers/simple_admin/path_helper.rb +0 -0
  24. data/app/helpers/simple_admin/sidebar_helper.rb +0 -0
  25. data/app/helpers/simple_admin/table_helper.rb +2 -2
  26. data/app/helpers/simple_admin/title_helper.rb +0 -0
  27. data/app/views/layouts/simple_admin.html.erb +0 -0
  28. data/app/views/simple_admin/admin/_form.html.erb +9 -0
  29. data/app/views/simple_admin/admin/dashboard.html.erb +0 -0
  30. data/app/views/simple_admin/admin/edit.html.erb +0 -0
  31. data/app/views/simple_admin/admin/index.csv.erb +4 -4
  32. data/app/views/simple_admin/admin/index.html.erb +47 -15
  33. data/app/views/simple_admin/admin/new.html.erb +0 -0
  34. data/app/views/simple_admin/admin/show.html.erb +1 -1
  35. data/config/routes.rb +0 -0
  36. data/lib/rails/generators/simple_admin/assets/assets_generator.rb +0 -0
  37. data/lib/rails/generators/simple_admin/install/install_generator.rb +0 -0
  38. data/lib/rails/generators/simple_admin/templates/initializer.rb +0 -0
  39. data/lib/simple_admin/attributes.rb +35 -30
  40. data/lib/simple_admin/breadcrumbs.rb +0 -0
  41. data/lib/simple_admin/builder.rb +3 -1
  42. data/lib/simple_admin/engine.rb +0 -0
  43. data/lib/simple_admin/filters.rb +0 -0
  44. data/lib/simple_admin/interface.rb +14 -5
  45. data/lib/simple_admin/section.rb +5 -5
  46. data/lib/simple_admin/version.rb +1 -1
  47. data/lib/simple_admin.rb +1 -1
  48. data/lib/tasks/routes.rake +0 -0
  49. data/simple_admin.gemspec +0 -0
  50. data/spec/acceptance/admin_thing_spec.rb +0 -0
  51. data/spec/controllers/simple_admin/admin_controller_spec.rb +0 -0
  52. data/spec/factories.rb +0 -0
  53. data/spec/simple_admin/attributes_spec.rb +0 -0
  54. data/spec/simple_admin/breadcrumbs_spec.rb +0 -0
  55. data/spec/simple_admin/builder_spec.rb +0 -0
  56. data/spec/simple_admin/engine_spec.rb +0 -0
  57. data/spec/simple_admin/filters_spec.rb +0 -0
  58. data/spec/simple_admin/interface_spec.rb +0 -0
  59. data/spec/simple_admin/section_spec.rb +0 -0
  60. data/spec/simple_admin/simple_admin_spec.rb +0 -0
  61. data/spec/spec_helper.rb +0 -0
  62. metadata +129 -159
  63. data/rails/init.rb +0 -2
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d36a2905ec91d7b2e29f5e78812363ca6756a644
4
+ data.tar.gz: d80c00b2d2bf5aecc500883cf35d61197f82a875
5
+ SHA512:
6
+ metadata.gz: 3f0dcd1246477179b1a639829ac5410cd126e79894cd923eb53a9468837450c859802684f8fc56fa0a7684977d04f41bbb5d7b5b5776fbd97ebd706646d617c4
7
+ data.tar.gz: a9afe1755bf3bdb5f8e006337e0bad0e08cadd19858ebe9a8e85848ff8db21106907585917d42016e9caa05fcc3069d97a61418395851c34caf237bf8ba021f5
data/.gitignore CHANGED
File without changes
data/.rspec CHANGED
File without changes
data/Gemfile CHANGED
@@ -9,4 +9,5 @@ gem "formtastic", ">= 0"
9
9
  gem "ransack"
10
10
  gem "fastercsv" if RUBY_VERSION =~ /^1.8/
11
11
  gem "fuubar"
12
+ gem "sqlite3", ">= 1.3.5"
12
13
 
data/LICENSE CHANGED
File without changes
data/README.rdoc CHANGED
File without changes
data/Rakefile CHANGED
File without changes
data/TODO.rdoc CHANGED
File without changes
File without changes
File without changes
@@ -1,6 +1,3 @@
1
- require 'kaminari'
2
- require 'ransack'
3
-
4
1
  module SimpleAdmin
5
2
  class AdminController < ::ApplicationController
6
3
  before_filter :require_user
@@ -9,8 +6,6 @@ module SimpleAdmin
9
6
  before_filter :lookup_resource, :only => [:show, :edit, :update, :destroy]
10
7
  before_filter :check_action, :except => [:dashboard]
11
8
 
12
- unloadable
13
-
14
9
  respond_to :json, :xml, :html, :except => :index
15
10
 
16
11
  helper SimpleAdmin::AdminHelper
@@ -18,7 +13,8 @@ module SimpleAdmin
18
13
  layout 'simple_admin'
19
14
 
20
15
  def index
21
- @collection = @interface.constant rescue nil
16
+ @collection ||= @interface.constant rescue nil
17
+
22
18
  if @collection
23
19
  @collection = @collection.search(clean_search_params(params)).result
24
20
  @collection = @collection.order("#{@interface.constant.table_name}.#{$1} #{$2}") if params[:order] && params[:order] =~ /^([\w\_\.]+)_(desc|asc)$/
@@ -37,7 +33,7 @@ module SimpleAdmin
37
33
  end
38
34
 
39
35
  def new
40
- @resource = @interface.constant.new
36
+ @resource ||= @interface.constant.new
41
37
  respond_with(@resource)
42
38
  end
43
39
 
@@ -46,7 +42,7 @@ module SimpleAdmin
46
42
  end
47
43
 
48
44
  def create
49
- @resource = @interface.constant.new(params[@interface.member.to_sym])
45
+ @resource = @interface.constant.new(params.require(@interface.member.to_sym).permit!)
50
46
  # respond_with will fail without explicit urls
51
47
  respond_to do |format|
52
48
  if @resource.save
@@ -64,7 +60,7 @@ module SimpleAdmin
64
60
  def update
65
61
  # respond_with will fail without explicit urls
66
62
  respond_to do |format|
67
- if @resource.update_attributes(params[@interface.member.to_sym])
63
+ if @resource.update_attributes(params.require(@interface.member.to_sym).permit!)
68
64
  format.html { redirect_to send("simple_admin_#{@interface.member}_path", @resource), :notice => "#{@interface.member.titleize} was successfully updated." }
69
65
  format.json { head :ok }
70
66
  format.xml { head :ok }
File without changes
File without changes
@@ -25,12 +25,12 @@ module SimpleAdmin
25
25
  end
26
26
 
27
27
  def data_for(col)
28
- value = if col.data
29
- instance_exec(@resource, &col.data)
30
- elsif col.attribute.to_s =~ /^([\w]+)_id$/ && @resource.respond_to?($1.to_sym)
28
+ value = if col[:data]
29
+ instance_exec(@resource, &col[:data])
30
+ elsif col[:attribute].to_s =~ /^([\w]+)_id$/ && @resource.respond_to?($1.to_sym)
31
31
  pretty_format(@resource.send($1))
32
32
  else
33
- pretty_format(@resource.send(col.attribute))
33
+ pretty_format(@resource.send(col[:attribute]))
34
34
  end
35
35
  value ||= content_tag(:span, 'Empty', :class => 'empty')
36
36
  end
@@ -2,23 +2,23 @@ module SimpleAdmin
2
2
  module FilterHelper
3
3
  def filter_fields(attributes)
4
4
  attributes.map do |col|
5
- options = col.options.dup
5
+ options = col[:options].dup
6
6
  expand_block_options!(options)
7
- case col.kind
7
+ case col[:kind]
8
8
  when :attribute, :filter
9
- filter_for(col.attribute, @interface.constant, options)
9
+ filter_for(col[:attribute], @interface.constant, options)
10
10
  when :content
11
- instance_exec(self, &col.data)
11
+ instance_exec(self, &col[:data])
12
12
  when :fieldset
13
13
  content_tag :fieldset, options do
14
14
  content_tag :legend do
15
15
  options[:legend]
16
16
  end unless options[:legend].blank
17
- filter_fields(col.attributes)
17
+ filter_fields(col[:attributes])
18
18
  end
19
19
  else
20
20
  content_tag :div, options do
21
- filter_fields(col.attributes)
21
+ filter_fields(col[:attributes])
22
22
  end
23
23
  end
24
24
  end.join.html_safe
@@ -127,6 +127,7 @@ module SimpleAdmin
127
127
  end
128
128
 
129
129
  def find_collection_for_column(klass, column, options) #:nodoc:
130
+ Rails.logger.info("******** find_collection_for_column #{klass}, #{column}, #{options.to_json}")
130
131
  collection = if options[:collection]
131
132
  collection = options.delete(:collection)
132
133
  collection = collection.to_a if collection.is_a?(Hash)
@@ -2,33 +2,33 @@ module SimpleAdmin
2
2
  module FormHelper
3
3
  def form_fields(form, attributes)
4
4
  attributes.map do |col|
5
- options = (col.options || {}).dup
5
+ options = (col[:options] || {}).dup
6
6
  expand_block_options!(options)
7
7
 
8
- case col.kind
8
+ case col[:kind]
9
9
  when :attribute
10
- form.input col.attribute, options
10
+ form.input col[:attribute], options
11
11
  when :content
12
- instance_exec(@resource, form, col, &col.data)
12
+ instance_exec(@resource, form, col, &col[:data])
13
13
  when :fieldset
14
14
  content_tag :fieldset, options do
15
15
  content_tag :legend do
16
16
  options[:legend]
17
17
  end unless options[:legend].blank
18
- form_fields(form, col.attributes)
18
+ form_fields(form, col[:attributes])
19
19
  end
20
20
  else
21
21
  content_tag :div, options do
22
- form_fields(form, col.attributes)
22
+ form_fields(form, col[:attributes])
23
23
  end
24
24
  end
25
25
  end.join.html_safe
26
26
  end
27
27
 
28
28
  def form_field(form, col)
29
- options = (col.options || {}).dup
29
+ options = (col[:options] || {}).dup
30
30
  expand_block_options!(options)
31
- form.input col.attribute, options
31
+ form.input col[:attribute], options
32
32
  end
33
33
  end
34
34
  end
@@ -37,12 +37,12 @@ module SimpleAdmin
37
37
  if params[:action].to_sym == :show
38
38
  if @interface.actions.include?(:edit)
39
39
  content << link_to("Edit #{@interface.member.titlecase}",
40
- send("edit_simple_admin_#{@interface.member}_path", @object))
40
+ send("edit_simple_admin_#{@interface.member}_path", @resource))
41
41
  end
42
42
  content << "&nbsp;"
43
43
  if @interface.actions.include?(:destroy)
44
44
  content << link_to("Delete #{@interface.member.titlecase}",
45
- send("simple_admin_#{@interface.member}_path", @object),
45
+ send("simple_admin_#{@interface.member}_path", @resource),
46
46
  :method => :delete, :confirm => "Are you sure you want to delete this?")
47
47
  end
48
48
  end
File without changes
File without changes
@@ -3,8 +3,8 @@ module SimpleAdmin
3
3
  def sortable_header_classes_for(col)
4
4
  sort = current_sort
5
5
  classes = []
6
- classes << "sortable" if col.sortable
7
- classes << "sorted-#{sort[1]}" if sort[0] == col.sort_key
6
+ classes << "sortable" if col[:sortable]
7
+ classes << "sorted-#{sort[1]}" if sort[0] == col[:sort_key]
8
8
  classes.join(' ')
9
9
  end
10
10
 
File without changes
File without changes
@@ -1,5 +1,14 @@
1
1
  <%= send(SimpleAdmin.form_for_helper, @resource, :as => @interface.member.to_sym,
2
2
  :url => resource_path(@resource), :html => {:class => "simple_form formtastic #{@interface.member}"}) do |form| %>
3
+ <% if @resource.errors.any? %>
4
+ <div class="admin-form-errors">
5
+ <ul>
6
+ <% @resource.errors.full_messages.each do |err| %>
7
+ <%= content_tag :li, err %>
8
+ <% end %>
9
+ </ul>
10
+ </div>
11
+ <% end %>
3
12
  <fieldset class="inputs">
4
13
  <ol>
5
14
  <%= form_fields(form, @interface.attributes_for(:form)) %>
File without changes
File without changes
@@ -4,13 +4,13 @@
4
4
 
5
5
  output = generator.generate do |csv|
6
6
  cols = @interface.attributes_for(:index)
7
- csv << cols.map(&:title)
7
+ csv << cols.map{|col| col[:title]}
8
8
  @collection.each do |object|
9
9
  csv << cols.map do |col|
10
- if col.data
11
- instance_exec(object, &col.data)
10
+ if col[:data]
11
+ instance_exec(object, &col[:data])
12
12
  else
13
- pretty_format(object.send(col.attribute))
13
+ pretty_format(object.send(col[:attribute]))
14
14
  end
15
15
  end
16
16
  end
@@ -18,35 +18,65 @@
18
18
  <b><%= (@collection.current_page * (params[:per_page] || SimpleAdmin.default_per_page).to_i) - (params[:per_page] || SimpleAdmin.default_per_page).to_i + 1 %>&nbsp;-&nbsp;<%= (@collection.current_page * (params[:per_page] || SimpleAdmin.default_per_page).to_i) > @collection.total_count ? @collection.total_count : (@collection.current_page * (params[:per_page] || SimpleAdmin.default_per_page).to_i) %></b>
19
19
  of <b><%= @collection.total_count %></b> in total
20
20
  <% end %>
21
- <% editable = @interface.attributes_for(:index).any? {|a| a.editable} %>
21
+ <% editable = @interface.attributes_for(:index).any? {|a| a[:editable] } %>
22
22
  <% if editable %>
23
23
  | <%= link_to((params[:editing] ? 'Stop Editing' : 'Edit'), request.query_parameters.merge(:editing => (params[:editing] ? nil : 1))) %>
24
- | <%= link_to((params[:mode] == 'approvals' ? 'Rows' : 'Approvals'), request.query_parameters.merge(
25
- :mode => (params[:mode] == 'approvals' ? nil : 'approvals'),
26
- :per_page => (params[:mode] == 'approvals' ? nil : 1))) %>
24
+ | <%= link_to(@interface.options[:rows_name] || 'Rows', request.query_parameters.merge(:mode => 'rows', :per_page => nil)) %>
25
+ | <%= link_to(@interface.options[:pages_name] || 'Pages', request.query_parameters.merge(:mode => 'pages', :per_page => 1)) %>
26
+ | <%= link_to(@interface.options[:quick_edit_name] || 'QuickEdit', request.query_parameters.merge(:mode => 'quick_edit', :per_page => 1)) %>
27
+ | <%= link_to(@interface.options[:gallery_name] || 'Gallery', request.query_parameters.merge(:mode => 'gallery', :per_page => nil)) %>
27
28
  <% end %>
28
29
  </div>
29
30
  <div class="paginated_collection_contents <%= params[:mode] || 'rows' %> <%= 'editing' if params[:editing] %>">
30
31
  <div class="index_content">
31
- <% if params[:mode] == 'approvals' %>
32
+ <% if params[:mode] == 'pages' %>
32
33
  <div class="index_as_pages">
33
34
  <%= paginate(@collection) %>
34
35
  <% if @resource = @collection.first %>
35
36
  <%= send(SimpleAdmin.form_for_helper, @resource, :as => @interface.member.to_sym,
36
37
  :url => resource_path(@resource), :id => "#{@interface.member}_#{@resource.id}", :html => {:onsubmit => "return false", :class => "inline simple_form formtastic #{@interface.member}"}) do |form| %>
37
- <%= form_fields(form, @interface.attributes_for(:index, 'approvals')) %>
38
+ <%= form_fields(form, @interface.attributes_for(:index, 'pages')) %>
38
39
  <% end %>
39
40
  <% end %>
40
41
  </div>
42
+ <% elsif params[:mode] == 'quick_edit' %>
43
+ <div class="index_as_quick_edit">
44
+ <%= paginate(@collection) %>
45
+ <% if @resource = @collection.first %>
46
+ <%= send(SimpleAdmin.form_for_helper, @resource, :as => @interface.member.to_sym,
47
+ :url => resource_path(@resource), :id => "#{@interface.member}_#{@resource.id}", :html => {:onsubmit => "return false", :class => "inline simple_form formtastic #{@interface.member}"}) do |form| %>
48
+ <%= form_fields(form, @interface.attributes_for(:index, 'quick_edit')) %>
49
+ <% end %>
50
+ <% end %>
51
+ </div>
52
+ <% elsif params[:mode] == 'gallery' %>
53
+ <%= paginate(@collection) %>
54
+ <div class="index_as_gallery">
55
+ <ul>
56
+ <% @collection.each do |object| %>
57
+ <li>
58
+ <% @interface.attributes_for(:index, 'gallery').each do |col| %>
59
+ <div class="<%= col[:attribute] %>">
60
+ <% if col[:data] %>
61
+ <%= instance_exec(object, &col[:data]) %>
62
+ <% else %>
63
+ <%= pretty_format(object.send(col[:attribute])) %>
64
+ <% end %>
65
+ </div>
66
+ <% end %>
67
+ </li>
68
+ <% end %>
69
+ </ul>
70
+ </div>
41
71
  <% else %>
42
72
  <div class="index_as_table">
43
73
  <table border="0" class="index_table" cellspacing="0" cellpadding="0" id="<%= @interface.collection %>">
44
74
  <thead>
45
75
  <tr>
46
76
  <% @interface.attributes_for(:index).each do |col| %>
47
- <th class="<%= sortable_header_classes_for(col) %> <%= col.attribute %>">
48
- <%= link_to(col.title,
49
- request.query_parameters.merge(:order => "#{col.sort_key}_#{order_for_sort_key(col.sort_key)}").except(:page)) %>
77
+ <th class="<%= sortable_header_classes_for(col) %> <%= col[:attribute] %>">
78
+ <%= link_to(col[:title],
79
+ request.query_parameters.merge(:order => "#{col[:sort_key]}_#{order_for_sort_key(col[:sort_key])}").except(:page)) %>
50
80
  </th>
51
81
  <% end %>
52
82
  <th>&nbsp;</th>
@@ -56,16 +86,16 @@
56
86
  <% @collection.each do |object| %>
57
87
  <tr class="<%= cycle('odd', 'even') %>">
58
88
  <% @interface.attributes_for(:index).each do |col| %>
59
- <td class="<%= col.attribute %>">
60
- <% if col.editable && params[:editing] %>
89
+ <td class="<%= col[:attribute] %>">
90
+ <% if col[:editable] && params[:editing] %>
61
91
  <%= send(SimpleAdmin.form_for_helper, object, :as => @interface.member.to_sym,
62
92
  :url => resource_path(object), :id => "#{@interface.member}_#{object.id}", :html => {:class => "inline simple_form formtastic #{@interface.member}"}) do |form| %>
63
93
  <%= form_field(form, col) %>
64
94
  <% end %>
65
- <% elsif col.data %>
66
- <%= instance_exec(object, &col.data) %>
95
+ <% elsif col[:data] %>
96
+ <%= instance_exec(object, &col[:data]) %>
67
97
  <% else %>
68
- <%= pretty_format(object.send(col.attribute)) %>
98
+ <%= pretty_format(object.send(col[:attribute])) %>
69
99
  <% end %>
70
100
  </td>
71
101
  <% end %>
@@ -78,7 +108,8 @@
78
108
  <% end %>
79
109
  </div>
80
110
  </div>
81
- <% if params[:mode] != 'approvals' %>
111
+ <% if params[:mode] != 'pages' && params[:mode] != 'quick_edit' %>
112
+ <div style="float:none;clear:both;"></div>
82
113
  <div id="index_footer">
83
114
  Download:&nbsp;
84
115
  <% [:csv, :xml, :json].each do |format| %>
@@ -99,6 +130,7 @@
99
130
  <h3>Filters</h3>
100
131
  <div class="panel_contents">
101
132
  <%= form_tag '', :class => "q_search", :id => "q_search", :method => "get" do %>
133
+ <%= hidden_field_tag "mode", params["mode"] %>
102
134
  <%= filter_fields(filters) %>
103
135
  <div class="buttons">
104
136
  <input name="commit" type="submit" value="Filter" />
File without changes
@@ -7,7 +7,7 @@
7
7
  <table border="0" cellspacing="0" cellpadding="0">
8
8
  <% @interface.attributes_for(:show).each do |attr| %>
9
9
  <tr>
10
- <th><%= attr.title %></th>
10
+ <th><%= attr[:title] %></th>
11
11
  <td><%= data_for(attr) %></td>
12
12
  </tr>
13
13
  <% end %>
data/config/routes.rb CHANGED
File without changes
@@ -23,6 +23,7 @@ module SimpleAdmin
23
23
  # Clear the attributes for this section
24
24
  def clear
25
25
  @attributes = []
26
+ @attributes_hash = {}
26
27
  end
27
28
 
28
29
  # Define or override an attribute for this section
@@ -33,20 +34,22 @@ module SimpleAdmin
33
34
  # :sort_key a column name used when sorting this column (defaults to the column for this attribute)
34
35
  #
35
36
  def attribute(name, options={}, &block)
36
- attr = @attributes.find {|attr| attr.attribute == name.to_sym && attr.mode == options[:mode]}
37
+ key = "#{name}:#{options[:mode]}"
38
+ attr = @attributes_hash[key]
37
39
  unless attr
38
- attr = OpenStruct.new
40
+ attr = {}
39
41
  @attributes << attr
42
+ @attributes_hash[key] = attr
40
43
  end
41
- attr.kind = :attribute
42
- attr.attribute = name.to_sym
43
- attr.options = options
44
- attr.data = block
45
- attr.title = options[:title] || name.to_s.titleize
46
- attr.sortable = options[:sortable].nil? || !(options[:sortable] === false)
47
- attr.editable = options[:editable] === true
48
- attr.mode = options[:mode]
49
- attr.sort_key = (options[:sort_key] || name).to_s
44
+ attr[:kind] = :attribute
45
+ attr[:attribute] = name.to_sym
46
+ attr[:options] = options
47
+ attr[:data] = block
48
+ attr[:title] = options[:title] || name.to_s.titleize
49
+ attr[:sortable] = options[:sortable].nil? || !(options[:sortable] === false)
50
+ attr[:editable] = options[:editable] === true
51
+ attr[:mode] = options[:mode]
52
+ attr[:sort_key] = (options[:sort_key] || name).to_s
50
53
  attr
51
54
  end
52
55
 
@@ -55,12 +58,12 @@ module SimpleAdmin
55
58
  # This is only used when displaying a form.
56
59
  #
57
60
  def content(options={}, &block)
58
- cont = OpenStruct.new
61
+ cont = {}
59
62
  @attributes << cont
60
- cont.kind = :content
61
- cont.options = options
62
- cont.data = block
63
- cont.mode = options[:mode]
63
+ cont[:kind] = :content
64
+ cont[:options] = options
65
+ cont[:data] = block
66
+ cont[:mode] = options[:mode]
64
67
  cont
65
68
  end
66
69
 
@@ -80,14 +83,14 @@ module SimpleAdmin
80
83
  # end
81
84
  # end
82
85
  def section(options={}, &block)
83
- sect = OpenStruct.new
86
+ sect = {}
84
87
  @attributes << sect
85
- sect.kind = options.delete(:kind) || :section
86
- sect.options = options
87
- sect.mode = options[:mode]
88
- sect.attributes = []
88
+ sect[:kind] = options.delete(:kind) || :section
89
+ sect[:options] = options
90
+ sect[:mode] = options[:mode]
91
+ sect[:attributes] = []
89
92
  save_attributes = @attributes
90
- @attributes = sect.attributes
93
+ @attributes = sect[:attributes]
91
94
  instance_eval(&block) if block_given?
92
95
  @attributes = save_attributes
93
96
  sect
@@ -106,6 +109,7 @@ module SimpleAdmin
106
109
  #
107
110
  def defaults(options={})
108
111
  clear
112
+ return @cols if defined?(@cols)
109
113
  if @section.section == :form
110
114
  reflections = @interface.constant.reflections rescue []
111
115
  association_columns = reflections.map do |name, ref|
@@ -115,16 +119,17 @@ module SimpleAdmin
115
119
  end.compact
116
120
 
117
121
  content_columns = @interface.constant.content_columns rescue []
118
- cols = content_columns.map {|col| col.name.to_sym }
119
- cols += association_columns
120
- cols -= SKIPPED_COLUMNS
121
- cols.compact!
122
+ @cols = content_columns.map {|col| col.name.to_sym }
123
+ @cols += association_columns
124
+ @cols -= SKIPPED_COLUMNS
125
+ @cols.compact!
122
126
  else
123
- cols = @interface.constant.columns.map{|col| col.name.to_sym } rescue []
127
+ @cols = @interface.constant.columns.map{|col| col.name.to_sym } rescue []
124
128
  end
125
- cols -= options[:except] if options[:except]
126
- cols &= options[:only] if options[:only]
127
- cols.each {|col| attribute(col.to_s) }
129
+ @cols -= options[:except] if options[:except]
130
+ @cols &= options[:only] if options[:only]
131
+ @cols.sort_by! {|col| options[:only].index(col.to_sym) } if options[:only]
132
+ @cols.each {|col| attribute(col.to_s) }
128
133
  end
129
134
  end
130
135
  end
File without changes
@@ -8,7 +8,9 @@ module SimpleAdmin
8
8
  end
9
9
 
10
10
  def section(sym, options={}, &block)
11
+ start = Time.now
11
12
  @interface.sections[sym] = SimpleAdmin::Section.new(@interface, sym, options, &block)
13
+ Rails.logger.info("[#{Time.now}] *** Built section #{sym} for #{interface.collection} (elapsed #{Time.now - start})")
12
14
  end
13
15
 
14
16
  def index(options={}, &block)
@@ -28,7 +30,7 @@ module SimpleAdmin
28
30
  options[:actions] = options[:actions] || [:index, :show, :edit, :new, :destroy, :create, :update]
29
31
  options[:actions] -= options[:except] if options[:except]
30
32
  options[:actions] &= options[:only] if options[:only]
31
- @interface.before << options
33
+ @interface.before_filters << options
32
34
  end
33
35
 
34
36
  # Comfort the masses
File without changes
File without changes
@@ -2,7 +2,7 @@ require 'ostruct'
2
2
 
3
3
  module SimpleAdmin
4
4
  class Interface
5
- attr_reader :collection, :member, :constant, :options, :before, :sections
5
+ attr_reader :collection, :member, :constant, :options, :sections, :before_filters
6
6
 
7
7
  def initialize(resource, options={}, &block)
8
8
  if resource.is_a?(Class)
@@ -17,7 +17,7 @@ module SimpleAdmin
17
17
  @options = options
18
18
  @sections = {}
19
19
  @block = block
20
- @before = []
20
+ @before_filters = []
21
21
  self
22
22
  end
23
23
 
@@ -26,15 +26,19 @@ module SimpleAdmin
26
26
  end
27
27
 
28
28
  def filters_for(sym)
29
- options_for(sym)[:filters].attributes
29
+ @filters ||= options_for(sym)[:filters]
30
+ @filters ||= section(sym).filters
31
+ @filters.attributes
30
32
  end
31
33
 
32
34
  def attributes_for(sym, mode=nil)
33
- options_for(sym)[:attributes].attributes.select{|a| a.mode == mode}
35
+ @attributes ||= options_for(sym)[:attributes]
36
+ @attributes ||= section(sym).attributes
37
+ @attributes.attributes.select{|a| a[:mode] == mode}
34
38
  end
35
39
 
36
40
  def sidebars_for(sym)
37
- options_for(sym)[:sidebars] || []
41
+ @sidebars ||= options_for(sym)[:sidebars] || []
38
42
  end
39
43
 
40
44
  def options_for(sym)
@@ -49,6 +53,11 @@ module SimpleAdmin
49
53
  arr
50
54
  end
51
55
 
56
+ def before
57
+ @builder ||= SimpleAdmin::Builder.new(self, &@block)
58
+ @before_filters
59
+ end
60
+
52
61
  private
53
62
 
54
63
  def section(sym)
@@ -1,25 +1,25 @@
1
1
  module SimpleAdmin
2
2
  class Section
3
- attr_accessor :options, :section
3
+ attr_accessor :options, :section, :allow_filters
4
4
 
5
5
  def initialize(interface, section, options={}, &block)
6
6
  @interface = interface
7
7
  @section = section
8
8
  @options = options
9
9
  @allow_filters = (section == :index)
10
- attributes
11
- filters if @allow_filters
10
+ # attributes
11
+ # filters if @allow_filters
12
12
  instance_eval(&block) if block_given?
13
13
  self
14
14
  end
15
15
 
16
16
  def attributes(attr_options={}, &block)
17
- self.options[:attributes] = SimpleAdmin::Attributes.new(@interface, self, attr_options, &block)
17
+ self.options[:attributes] ||= SimpleAdmin::Attributes.new(@interface, self, attr_options, &block)
18
18
  end
19
19
 
20
20
  def filters(filter_options={}, &block)
21
21
  raise "Filters cannot be specified for this section" unless @allow_filters
22
- self.options[:filters] = SimpleAdmin::Filters.new(@interface, self, filter_options, &block)
22
+ self.options[:filters] ||= SimpleAdmin::Filters.new(@interface, self, filter_options, &block)
23
23
  end
24
24
 
25
25
  def sidebar(sidebar_options={}, &block)
@@ -1,3 +1,3 @@
1
1
  module SimpleAdmin
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.1"
3
3
  end
data/lib/simple_admin.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module SimpleAdmin
2
- require 'simple_admin/engine' if defined?(Rails) && Rails::VERSION::MAJOR == 3
2
+ require 'simple_admin/engine' if defined?(Rails)
3
3
  require 'simple_admin/interface'
4
4
  require 'simple_admin/builder'
5
5
  require 'simple_admin/section'
File without changes
data/simple_admin.gemspec CHANGED
File without changes
File without changes
data/spec/factories.rb CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
data/spec/spec_helper.rb CHANGED
File without changes
metadata CHANGED
@@ -1,167 +1,149 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: simple_admin
3
- version: !ruby/object:Gem::Version
4
- hash: 7
5
- prerelease:
6
- segments:
7
- - 0
8
- - 6
9
- - 0
10
- version: 0.6.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.7.1
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Jeff Rafter
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2012-03-16 00:00:00 -07:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
11
+ date: 2013-12-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
22
14
  name: rails
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 3
32
- - 1
33
- - 0
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
34
19
  version: 3.1.0
35
20
  type: :runtime
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: kaminari
39
21
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- hash: 3
46
- segments:
47
- - 0
48
- version: "0"
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 3.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: kaminari
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
49
34
  type: :runtime
50
- version_requirements: *id002
51
- - !ruby/object:Gem::Dependency
52
- name: rspec
53
35
  prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
55
- none: false
56
- requirements:
57
- - - ">="
58
- - !ruby/object:Gem::Version
59
- hash: 23
60
- segments:
61
- - 2
62
- - 6
63
- - 0
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
64
47
  version: 2.6.0
65
48
  type: :development
66
- version_requirements: *id003
67
- - !ruby/object:Gem::Dependency
68
- name: rspec-rails
69
49
  prerelease: false
70
- requirement: &id004 !ruby/object:Gem::Requirement
71
- none: false
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- hash: 23
76
- segments:
77
- - 2
78
- - 6
79
- - 0
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 2.6.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
80
61
  version: 2.6.0
81
62
  type: :development
82
- version_requirements: *id004
83
- - !ruby/object:Gem::Dependency
84
- name: shoulda
85
63
  prerelease: false
86
- requirement: &id005 !ruby/object:Gem::Requirement
87
- none: false
88
- requirements:
89
- - - ">="
90
- - !ruby/object:Gem::Version
91
- hash: 3
92
- segments:
93
- - 0
94
- version: "0"
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: 2.6.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: shoulda
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
95
76
  type: :development
96
- version_requirements: *id005
97
- - !ruby/object:Gem::Dependency
98
- name: factory_girl
99
77
  prerelease: false
100
- requirement: &id006 !ruby/object:Gem::Requirement
101
- none: false
102
- requirements:
103
- - - ">="
104
- - !ruby/object:Gem::Version
105
- hash: 3
106
- segments:
107
- - 0
108
- version: "0"
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: factory_girl
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
109
90
  type: :development
110
- version_requirements: *id006
111
- - !ruby/object:Gem::Dependency
112
- name: mocha
113
91
  prerelease: false
114
- requirement: &id007 !ruby/object:Gem::Requirement
115
- none: false
116
- requirements:
117
- - - ">"
118
- - !ruby/object:Gem::Version
119
- hash: 3
120
- segments:
121
- - 0
122
- version: "0"
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: mocha
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>'
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
123
104
  type: :development
124
- version_requirements: *id007
125
- - !ruby/object:Gem::Dependency
126
- name: capybara
127
105
  prerelease: false
128
- requirement: &id008 !ruby/object:Gem::Requirement
129
- none: false
130
- requirements:
131
- - - ">="
132
- - !ruby/object:Gem::Version
133
- hash: 15
134
- segments:
135
- - 0
136
- - 4
137
- - 0
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>'
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: capybara
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
138
117
  version: 0.4.0
139
118
  type: :development
140
- version_requirements: *id008
141
- - !ruby/object:Gem::Dependency
142
- name: sqlite3-ruby
143
119
  prerelease: false
144
- requirement: &id009 !ruby/object:Gem::Requirement
145
- none: false
146
- requirements:
147
- - - ">="
148
- - !ruby/object:Gem::Version
149
- hash: 3
150
- segments:
151
- - 0
152
- version: "0"
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: 0.4.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: sqlite3-ruby
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
153
132
  type: :development
154
- version_requirements: *id009
155
- description: Use SimpleAdmin to build out filtering, searchable, editable interfaces for your models
156
- email:
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: Use SimpleAdmin to build out filtering, searchable, editable interfaces
140
+ for your models
141
+ email:
157
142
  - jeffrafter@gmail.com
158
143
  executables: []
159
-
160
144
  extensions: []
161
-
162
145
  extra_rdoc_files: []
163
-
164
- files:
146
+ files:
165
147
  - .gitignore
166
148
  - .rspec
167
149
  - Gemfile
@@ -209,7 +191,6 @@ files:
209
191
  - lib/simple_admin/section.rb
210
192
  - lib/simple_admin/version.rb
211
193
  - lib/tasks/routes.rake
212
- - rails/init.rb
213
194
  - simple_admin.gemspec
214
195
  - spec/acceptance/admin_thing_spec.rb
215
196
  - spec/controllers/simple_admin/admin_controller_spec.rb
@@ -223,41 +204,30 @@ files:
223
204
  - spec/simple_admin/section_spec.rb
224
205
  - spec/simple_admin/simple_admin_spec.rb
225
206
  - spec/spec_helper.rb
226
- has_rdoc: true
227
207
  homepage: http://github.com/jeffrafter/simple_admin
228
208
  licenses: []
229
-
209
+ metadata: {}
230
210
  post_install_message:
231
211
  rdoc_options: []
232
-
233
- require_paths:
212
+ require_paths:
234
213
  - lib
235
- required_ruby_version: !ruby/object:Gem::Requirement
236
- none: false
237
- requirements:
238
- - - ">="
239
- - !ruby/object:Gem::Version
240
- hash: 3
241
- segments:
242
- - 0
243
- version: "0"
244
- required_rubygems_version: !ruby/object:Gem::Requirement
245
- none: false
246
- requirements:
247
- - - ">="
248
- - !ruby/object:Gem::Version
249
- hash: 3
250
- segments:
251
- - 0
252
- version: "0"
214
+ required_ruby_version: !ruby/object:Gem::Requirement
215
+ requirements:
216
+ - - '>='
217
+ - !ruby/object:Gem::Version
218
+ version: '0'
219
+ required_rubygems_version: !ruby/object:Gem::Requirement
220
+ requirements:
221
+ - - '>='
222
+ - !ruby/object:Gem::Version
223
+ version: '0'
253
224
  requirements: []
254
-
255
225
  rubyforge_project: simple_admin
256
- rubygems_version: 1.3.9.2
226
+ rubygems_version: 2.0.3
257
227
  signing_key:
258
- specification_version: 3
228
+ specification_version: 4
259
229
  summary: Simple administrative interfaces for data in your rails application
260
- test_files:
230
+ test_files:
261
231
  - spec/acceptance/admin_thing_spec.rb
262
232
  - spec/controllers/simple_admin/admin_controller_spec.rb
263
233
  - spec/factories.rb
data/rails/init.rb DELETED
@@ -1,2 +0,0 @@
1
- # This is here so that this can be treated like a plugin instead of a gem
2
- require 'simple_admin'