sferik-merb-admin 0.2.8 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +1 -1
- data/Rakefile +1 -1
- data/app/controllers/main.rb +3 -3
- data/app/views/main/_belongs_to.html.erb +23 -0
- data/app/views/main/edit.html.erb +7 -2
- data/app/views/main/new.html.erb +7 -2
- data/lib/abstract_model.rb +4 -5
- data/lib/merb-admin.rb +1 -1
- metadata +2 -1
data/README.markdown
CHANGED
@@ -14,7 +14,7 @@ At the command prompt, type:
|
|
14
14
|
|
15
15
|
In your app, add the following dependency to `config/dependencies.rb`:
|
16
16
|
|
17
|
-
dependency "sferik-merb-admin", "0.
|
17
|
+
dependency "sferik-merb-admin", "0.3.0", :require_as => "merb-admin"
|
18
18
|
dependency "dm-is-paginated", "0.0.1" # if you want pagination support
|
19
19
|
|
20
20
|
Add the following route to `config/router.rb`:
|
data/Rakefile
CHANGED
@@ -12,7 +12,7 @@ AUTHOR = "Erik Michaels-Ober"
|
|
12
12
|
EMAIL = "sferik@gmail.com"
|
13
13
|
HOMEPAGE = "http://twitter.com/sferik"
|
14
14
|
SUMMARY = "MerbAdmin is a Merb plugin that provides an easy-to-use interface for managing your data."
|
15
|
-
GEM_VERSION = "0.
|
15
|
+
GEM_VERSION = "0.3.0"
|
16
16
|
|
17
17
|
spec = Gem::Specification.new do |s|
|
18
18
|
s.rubyforge_project = "merb"
|
data/app/controllers/main.rb
CHANGED
@@ -54,7 +54,7 @@ class MerbAdmin::Main < MerbAdmin::Application
|
|
54
54
|
object = params[@abstract_model.singular_name] || {}
|
55
55
|
# Delete fields that are blank
|
56
56
|
object.each do |key, value|
|
57
|
-
object
|
57
|
+
object[key] = nil if value.blank?
|
58
58
|
end
|
59
59
|
associations = @abstract_model.has_many_associations.map{|association| [association, (params[:associations] || {}).delete(association[:name])]}
|
60
60
|
@object = @abstract_model.new(object)
|
@@ -76,7 +76,7 @@ class MerbAdmin::Main < MerbAdmin::Application
|
|
76
76
|
object = params[@abstract_model.singular_name] || {}
|
77
77
|
# Delete fields that are blank
|
78
78
|
object.each do |key, value|
|
79
|
-
object
|
79
|
+
object[key] = nil if value.blank?
|
80
80
|
end
|
81
81
|
associations = @abstract_model.has_many_associations.map{|association| [association, (params[:associations] || {}).delete(association[:name])]}
|
82
82
|
if @object.update_attributes(object) && associations.each{|association, ids| update_has_many_association(association, ids)}
|
@@ -146,7 +146,7 @@ class MerbAdmin::Main < MerbAdmin::Application
|
|
146
146
|
conditions = []
|
147
147
|
@properties.each do |property|
|
148
148
|
next unless property[:type] == :string
|
149
|
-
condition_statement << "#{property[:
|
149
|
+
condition_statement << "#{property[:name]} LIKE ?"
|
150
150
|
conditions << "%#{params[:query]}%"
|
151
151
|
end
|
152
152
|
conditions.unshift(condition_statement.join(" OR "))
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<fieldset class="module aligned">
|
2
|
+
<h2><%= association[:pretty_name].capitalize %></h2>
|
3
|
+
<div class="<%= @object.errors[association[:child_key].first] ? "form-row errors" : "form-row"%>">
|
4
|
+
<% if @object.errors[association[:child_key].first] %>
|
5
|
+
<ul class="errorlist">
|
6
|
+
<% @object.errors[association[:child_key].first].each do |error| %>
|
7
|
+
<li><%= error %></li>
|
8
|
+
<% end %>
|
9
|
+
</ul>
|
10
|
+
<% end %>
|
11
|
+
<div>
|
12
|
+
<%= select(association[:child_key].first, :collection => MerbAdmin::AbstractModel.new(association[:parent_model]).find_all.map{|o| [o.id, object_title(o)]}.sort_by{|o| o[1]}, :include_blank => true, :selected => @object.send(association[:child_key].first).to_s, :label => association[:pretty_name].capitalize) %>
|
13
|
+
<p class="help">
|
14
|
+
<% required = false %>
|
15
|
+
<% @properties.each do |property| %>
|
16
|
+
<% next unless property[:name] == association[:child_key].first %>
|
17
|
+
<% required = true unless property[:nullable?] %>
|
18
|
+
<% end %>
|
19
|
+
<%= required ? "Required." : "Optional." %>
|
20
|
+
</p>
|
21
|
+
</div>
|
22
|
+
</div>
|
23
|
+
</fieldset>
|
@@ -7,8 +7,10 @@
|
|
7
7
|
<%= form_for(@object, :action => slice_url(:admin_update, :model_name => @abstract_model.singular_name, :id => @object.id)) do %>
|
8
8
|
<div>
|
9
9
|
<fieldset class="module aligned">
|
10
|
+
<% belongs_to_keys = @abstract_model.belongs_to_associations.map{|b| b[:child_key].first} %>
|
10
11
|
<% @properties.each do |property| %>
|
11
|
-
<% next if [:id, :created_at, :created_on, :updated_at, :updated_on].include?(property[:name]) %>
|
12
|
+
<% next if [:id, :created_at, :created_on, :deleted_at, :updated_at, :updated_on, :deleted_on].include?(property[:name]) %>
|
13
|
+
<% next if belongs_to_keys.include?(property[:name]) %>
|
12
14
|
<div class="<%= @object.errors[property[:name]] ? "form-row errors" : "form-row"%>">
|
13
15
|
<% if @object.errors[property[:name]] %>
|
14
16
|
<ul class="errorlist">
|
@@ -21,8 +23,11 @@
|
|
21
23
|
</div>
|
22
24
|
<% end %>
|
23
25
|
</fieldset>
|
26
|
+
<% @abstract_model.belongs_to_associations.each do |association| %>
|
27
|
+
<%= partial('belongs_to', :association => association) -%>
|
28
|
+
<% end %>
|
24
29
|
<% @abstract_model.has_many_associations.each do |association| %>
|
25
|
-
<%= partial('has_many', :association => association)
|
30
|
+
<%= partial('has_many', :association => association) -%>
|
26
31
|
<% end %>
|
27
32
|
<div class="submit-row" >
|
28
33
|
<%= submit "Save", :class => "default", :name => "_save" %>
|
data/app/views/main/new.html.erb
CHANGED
@@ -2,8 +2,10 @@
|
|
2
2
|
<%= form_for(@object, :action => slice_url(:admin_create, :model_name => @abstract_model.singular_name)) do %>
|
3
3
|
<div>
|
4
4
|
<fieldset class="module aligned">
|
5
|
+
<% belongs_to_keys = @abstract_model.belongs_to_associations.map{|b| b[:child_key].first} %>
|
5
6
|
<% @properties.each do |property| %>
|
6
|
-
|
7
|
+
<% next if [:id, :created_at, :created_on, :deleted_at, :updated_at, :updated_on, :deleted_on].include?(property[:name]) %>
|
8
|
+
<% next if belongs_to_keys.include?(property[:name]) %>
|
7
9
|
<div class="<%= @object.errors[property[:name]] ? "form-row errors" : "form-row"%>">
|
8
10
|
<% if @object.errors[property[:name]] %>
|
9
11
|
<ul class="errorlist">
|
@@ -16,8 +18,11 @@
|
|
16
18
|
</div>
|
17
19
|
<% end %>
|
18
20
|
</fieldset>
|
21
|
+
<% @abstract_model.belongs_to_associations.each do |association| %>
|
22
|
+
<%= partial('belongs_to', :association => association) -%>
|
23
|
+
<% end %>
|
19
24
|
<% @abstract_model.has_many_associations.each do |association| %>
|
20
|
-
<%= partial('has_many', :association => association)
|
25
|
+
<%= partial('has_many', :association => association) -%>
|
21
26
|
<% end %>
|
22
27
|
<div class="submit-row" >
|
23
28
|
<%= submit "Save", :class => "default", :name => "_save" %>
|
data/lib/abstract_model.rb
CHANGED
@@ -97,9 +97,9 @@ module MerbAdmin
|
|
97
97
|
:pretty_name => name.to_s.gsub('_', ' '),
|
98
98
|
:type => association_type_lookup(relationship),
|
99
99
|
:parent_model => relationship.parent_model,
|
100
|
-
:parent_key => relationship.parent_key.map{|
|
100
|
+
:parent_key => relationship.parent_key.map{|r| r.name},
|
101
101
|
:child_model => relationship.child_model,
|
102
|
-
:child_key => relationship.child_key.map{|
|
102
|
+
:child_key => relationship.child_key.map{|r| r.name},
|
103
103
|
:remote_relationship => relationship.options[:remote_relationship_name],
|
104
104
|
:near_relationship => relationship.options[:near_relationship_name],
|
105
105
|
}
|
@@ -117,12 +117,11 @@ module MerbAdmin
|
|
117
117
|
{
|
118
118
|
:name => property.name,
|
119
119
|
:pretty_name => property.field.gsub('_', ' '),
|
120
|
+
:type => type_lookup(property),
|
121
|
+
:length => property.length,
|
120
122
|
:nullable? => property.nullable?,
|
121
123
|
:serial? => property.serial?,
|
122
124
|
:key? => property.key?,
|
123
|
-
:field => property.field,
|
124
|
-
:length => property.length,
|
125
|
-
:type => type_lookup(property),
|
126
125
|
:flag_map => property.type.respond_to?(:flag_map) ? property.type.flag_map : nil,
|
127
126
|
}
|
128
127
|
end
|
data/lib/merb-admin.rb
CHANGED
@@ -23,7 +23,7 @@ if defined?(Merb::Plugins)
|
|
23
23
|
|
24
24
|
# Slice metadata
|
25
25
|
self.description = "MerbAdmin is a Merb plugin that provides an easy-to-use interface for managing your data."
|
26
|
-
self.version = "0.
|
26
|
+
self.version = "0.3.0"
|
27
27
|
self.author = "Erik Michaels-Ober"
|
28
28
|
|
29
29
|
# Stub classes loaded hook - runs before LoadClasses BootLoader
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sferik-merb-admin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Erik Michaels-Ober
|
@@ -86,6 +86,7 @@ files:
|
|
86
86
|
- app/views/layout/form.html.erb
|
87
87
|
- app/views/layout/list.html.erb
|
88
88
|
- app/views/main
|
89
|
+
- app/views/main/_belongs_to.html.erb
|
89
90
|
- app/views/main/_big_decimal.html.erb
|
90
91
|
- app/views/main/_boolean.html.erb
|
91
92
|
- app/views/main/_date.html.erb
|