merb-admin 0.4.4 → 0.4.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +3 -1
- data/Rakefile +1 -1
- data/app/controllers/main.rb +14 -0
- data/app/views/main/list.html.erb +14 -0
- data/lib/merb-admin.rb +1 -1
- data/spec/requests/main_spec.rb +20 -0
- metadata +1 -1
data/README.markdown
CHANGED
@@ -4,6 +4,8 @@
|
|
4
4
|
|
5
5
|
It currently offers the features listed [here](http://sferik.tadalist.com/lists/1352791/public).
|
6
6
|
|
7
|
+
The status of the current build can be seen [here](http://runcoderun.com/sferik/merb-admin).
|
8
|
+
|
7
9
|
## Get it
|
8
10
|
|
9
11
|
At the command prompt, type:
|
@@ -14,7 +16,7 @@ At the command prompt, type:
|
|
14
16
|
|
15
17
|
In your app, add the following dependency to `config/dependencies.rb`:
|
16
18
|
|
17
|
-
dependency "merb-admin", "0.4.
|
19
|
+
dependency "merb-admin", "0.4.5"
|
18
20
|
|
19
21
|
Add the following route to `config/router.rb`:
|
20
22
|
|
data/Rakefile
CHANGED
@@ -9,7 +9,7 @@ AUTHOR = "Erik Michaels-Ober"
|
|
9
9
|
EMAIL = "sferik@gmail.com"
|
10
10
|
HOMEPAGE = "http://twitter.com/sferik"
|
11
11
|
SUMMARY = "MerbAdmin is a Merb plugin that provides an easy-to-use interface for managing your data."
|
12
|
-
GEM_VERSION = "0.4.
|
12
|
+
GEM_VERSION = "0.4.5"
|
13
13
|
|
14
14
|
spec = Gem::Specification.new do |s|
|
15
15
|
s.rubyforge_project = "merb"
|
data/app/controllers/main.rb
CHANGED
@@ -13,6 +13,7 @@ class MerbAdmin::Main < MerbAdmin::Application
|
|
13
13
|
|
14
14
|
def list
|
15
15
|
options = {}
|
16
|
+
merge_query!(options)
|
16
17
|
merge_sort!(options)
|
17
18
|
merge_sort_reverse!(options)
|
18
19
|
|
@@ -125,6 +126,19 @@ class MerbAdmin::Main < MerbAdmin::Application
|
|
125
126
|
raise NotFound unless @object
|
126
127
|
end
|
127
128
|
|
129
|
+
def merge_query!(options)
|
130
|
+
return unless params[:query]
|
131
|
+
condition_statement = []
|
132
|
+
conditions = []
|
133
|
+
@properties.each do |property|
|
134
|
+
next unless property[:type] == :string
|
135
|
+
condition_statement << "#{property[:name]} LIKE ?"
|
136
|
+
conditions << "%#{params[:query]}%"
|
137
|
+
end
|
138
|
+
conditions.unshift(condition_statement.join(' OR '))
|
139
|
+
options.merge!(:conditions => conditions) unless conditions == ['']
|
140
|
+
end
|
141
|
+
|
128
142
|
def merge_sort!(options)
|
129
143
|
return unless params[:sort]
|
130
144
|
sort = params[:sort] || "id"
|
@@ -1,5 +1,6 @@
|
|
1
1
|
<%
|
2
2
|
params = request.params.except(:action, :controller, :model_name)
|
3
|
+
query = params[:query]
|
3
4
|
sort = params[:sort]
|
4
5
|
sort_reverse = params[:sort_reverse]
|
5
6
|
%>
|
@@ -10,6 +11,19 @@
|
|
10
11
|
</li>
|
11
12
|
</ul>
|
12
13
|
<div class="module" id="changelist">
|
14
|
+
<div id="toolbar">
|
15
|
+
<form id="changelist-search" action="" method="get">
|
16
|
+
<div>
|
17
|
+
<label for="searchbar"><img src="<%= image_path("icon_searchbox.png") %>" alt="Search" /></label>
|
18
|
+
<input type="text" size="40" name="query" value="" id="searchbar" />
|
19
|
+
<input type="submit" value="Search" />
|
20
|
+
<% if query %>
|
21
|
+
<span class="small quiet"><%= @record_count %> <%= @record_count == 1 ? "result" : "results" %> (<a href="?"><%= @abstract_model.count %> total</a>)</span>
|
22
|
+
<% end %>
|
23
|
+
</div>
|
24
|
+
</form>
|
25
|
+
</div>
|
26
|
+
<script type="text/javascript">document.getElementById("searchbar").focus();</script>
|
13
27
|
<table cellspacing="0">
|
14
28
|
<thead>
|
15
29
|
<tr>
|
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.4.
|
26
|
+
self.version = "0.4.5"
|
27
27
|
self.author = "Erik Michaels-Ober"
|
28
28
|
|
29
29
|
# Stub classes loaded hook - runs before LoadClasses BootLoader
|
data/spec/requests/main_spec.rb
CHANGED
@@ -89,6 +89,26 @@ describe "MerbAdmin" do
|
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
|
+
describe "list with query" do
|
93
|
+
before(:each) do
|
94
|
+
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 42, :name => "Jackie Robinson", :sex => :male, :position => :second)
|
95
|
+
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 32, :name => "Sandy Koufax", :sex => :male, :position => :pitcher)
|
96
|
+
@response = request(url(:admin_list, :model_name => "player"), :params => {:query => "Jackie Robinson"})
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should respond sucessfully" do
|
100
|
+
@response.should be_successful
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should contain a correct result" do
|
104
|
+
@response.body.should contain("Jackie Robinson")
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should not contain an incorrect result" do
|
108
|
+
@response.body.should_not contain("Sandy Koufax")
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
92
112
|
describe "list with sort" do
|
93
113
|
before(:each) do
|
94
114
|
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 42, :name => "Jackie Robinson", :sex => :male, :position => :second)
|