databrowser 0.8 → 0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/data_browser/data_browser.rb +9 -0
- data/lib/data_browser/data_browser_controller.rb +29 -31
- data/lib/data_browser/routing.rb +15 -5
- data/lib/data_browser/views/data_browser/data_browser/_form.html.erb +1 -1
- data/lib/data_browser/views/data_browser/data_browser/_obj.rhtml +2 -2
- data/lib/data_browser/views/data_browser/data_browser/about.html.erb +2 -2
- data/lib/data_browser/views/data_browser/data_browser/browse.html.erb +2 -2
- data/lib/data_browser/views/data_browser/data_browser/index.html.erb +3 -3
- data/lib/data_browser/views/data_browser/data_browser/new.html.erb +1 -1
- data/lib/data_browser/views/layouts/data_browser.html.erb +7 -7
- metadata +2 -2
@@ -4,6 +4,7 @@ require 'digest/sha1'
|
|
4
4
|
module DataBrowser
|
5
5
|
@@user_digest = nil
|
6
6
|
@@models = []
|
7
|
+
@@tables = []
|
7
8
|
|
8
9
|
class << self
|
9
10
|
def should_auth
|
@@ -36,5 +37,13 @@ module DataBrowser
|
|
36
37
|
def models=(models)
|
37
38
|
@@models = models if models.is_a?(Array)
|
38
39
|
end
|
40
|
+
|
41
|
+
def tables
|
42
|
+
@@tables
|
43
|
+
end
|
44
|
+
|
45
|
+
def tables=(tables)
|
46
|
+
@@tables = tables if tables.is_a?(Array)
|
47
|
+
end
|
39
48
|
end
|
40
49
|
end
|
@@ -3,16 +3,15 @@ module DataBrowser
|
|
3
3
|
layout "data_browser"
|
4
4
|
protect_from_forgery :secret => Time.now.to_i.to_s
|
5
5
|
before_filter :load_models, :authenticate
|
6
|
-
before_filter :load_current_model, :except => [:index]
|
7
6
|
|
8
|
-
|
9
|
-
|
7
|
+
helper_method :current_model, :current_model_id
|
8
|
+
|
10
9
|
# all the work here is being done by :load_models
|
11
10
|
def index; end
|
12
11
|
|
13
12
|
def browse
|
14
|
-
params[:select] ||=
|
15
|
-
@objects =
|
13
|
+
params[:select] ||= current_model.column_names
|
14
|
+
@objects = current_model.find(:all,
|
16
15
|
:conditions => params[:conditions],
|
17
16
|
:select => params[:select] ? params[:select].join(", ") : nil
|
18
17
|
)
|
@@ -24,64 +23,55 @@ module DataBrowser
|
|
24
23
|
end
|
25
24
|
|
26
25
|
def empty
|
27
|
-
|
28
|
-
flash[:notice] = "#{
|
26
|
+
current_model.delete_all
|
27
|
+
flash[:notice] = "#{current_model.table_name} model was emptied"
|
29
28
|
redirect_to :action => "index"
|
30
29
|
end
|
31
30
|
|
32
31
|
def new
|
33
|
-
@obj =
|
32
|
+
@obj = current_model.new
|
34
33
|
end
|
35
34
|
|
36
35
|
def edit
|
37
|
-
@obj =
|
36
|
+
@obj = current_model.find(params[:id])
|
38
37
|
end
|
39
38
|
|
40
39
|
def destroy
|
41
|
-
@obj =
|
40
|
+
@obj = current_model.find(params[:id])
|
42
41
|
@obj.destroy()
|
43
|
-
flash[:notice] = "#{
|
44
|
-
redirect_to :action => "browse", :model =>
|
42
|
+
flash[:notice] = "#{current_model.table_name} #{@obj.to_param} successfuly deleted!"
|
43
|
+
redirect_to :action => "browse", :model => current_model_id
|
45
44
|
end
|
46
45
|
|
47
46
|
def update
|
48
|
-
@obj =
|
49
|
-
@obj.
|
47
|
+
@obj = current_model.find(params[:id])
|
48
|
+
@obj.update_attributes(params[current_model.to_s.underscore])
|
50
49
|
|
51
|
-
@obj.
|
52
|
-
|
53
|
-
redirect_to :action => "browse", :model => @model.to_s
|
50
|
+
flash[:notice] = "#{current_model.table_name} #{@obj.to_param} successfuly saved!"
|
51
|
+
redirect_to :action => "browse", :model => current_model_id
|
54
52
|
end
|
55
53
|
|
56
54
|
def create
|
57
|
-
@obj =
|
55
|
+
@obj = current_model.new(params[current_model.to_s.underscore])
|
58
56
|
|
59
57
|
@obj.save(false)
|
60
|
-
flash[:notice] = "#{
|
61
|
-
redirect_to :action => "browse", :model =>
|
58
|
+
flash[:notice] = "#{current_model.table_name} #{@obj.to_param} successfuly saved!"
|
59
|
+
redirect_to :action => "browse", :model => current_model_id
|
62
60
|
end
|
63
61
|
|
64
62
|
protected
|
65
63
|
|
66
64
|
def load_models
|
67
|
-
# this will make that the models won't be fetched in every request
|
68
65
|
if DataBrowser.models.size == 0
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
c = Kernel.const_get(c)
|
73
|
-
c if c < ActiveRecord::Base
|
66
|
+
(DataBrowser.tables.empty?? ActiveRecord::Base.connection.tables : DataBrowser.tables).each do |table|
|
67
|
+
model_name = "DataBrowser::#{table.classify}"
|
68
|
+
eval("#{model_name} = Class.new(ActiveRecord::Base); DataBrowser.models.push(#{model_name})")
|
74
69
|
end
|
75
|
-
DataBrowser.models = models.compact.sort { |a, b| a.to_s <=> b.to_s }
|
76
70
|
end
|
77
71
|
|
78
72
|
@models = DataBrowser.models
|
79
73
|
end
|
80
74
|
|
81
|
-
def load_current_model
|
82
|
-
@model = Kernel.const_get(params[:model]) if params[:model]
|
83
|
-
end
|
84
|
-
|
85
75
|
def authenticate
|
86
76
|
if DataBrowser::should_auth && !DataBrowser::check_digest(session[:databrowser])
|
87
77
|
authenticate_or_request_with_http_basic("DataBrowser") do |user, pass|
|
@@ -89,5 +79,13 @@ module DataBrowser
|
|
89
79
|
end
|
90
80
|
end
|
91
81
|
end
|
82
|
+
|
83
|
+
def current_model
|
84
|
+
@model ||= DataBrowser.models[current_model_id] if current_model_id
|
85
|
+
end
|
86
|
+
|
87
|
+
def current_model_id
|
88
|
+
params[:model].to_i if params[:model]
|
89
|
+
end
|
92
90
|
end
|
93
91
|
end
|
data/lib/data_browser/routing.rb
CHANGED
@@ -3,11 +3,21 @@ module DataBrowser
|
|
3
3
|
def databrowser(opts={})
|
4
4
|
root = opts[:root] || "databrowser"
|
5
5
|
with_options :controller => "data_browser/data_browser" do |db|
|
6
|
-
|
7
|
-
db.
|
8
|
-
db.
|
9
|
-
|
10
|
-
db.
|
6
|
+
# Databrowser pages
|
7
|
+
db.data_browser_home "/#{root}", :action => "index"
|
8
|
+
db.data_browser_about "/#{root}/about", :action => "about"
|
9
|
+
# Model manipulation
|
10
|
+
db.with_options :model => /\d+/ do |model|
|
11
|
+
model.data_browser_model "/#{root}/:model", :action => "browse", :conditions => {:method => :get}
|
12
|
+
model.data_browser_new "/#{root}/:model/new", :action => "new", :conditions => {:method => :get}
|
13
|
+
model.data_browser_object "/#{root}/:model/:id", :action => "show", :conditions => {:method => :get}
|
14
|
+
model.data_browser_edit "/#{root}/:model/:id/edit", :action => "edit", :conditions => {:method => :get}
|
15
|
+
|
16
|
+
model.connect "/#{root}/:model", :action => "empty", :conditions => {:method => :delete}
|
17
|
+
model.connect "/#{root}/:model/:id", :action => "update", :conditions => {:method => :put}
|
18
|
+
model.connect "/#{root}/:model/:id", :action => "destroy", :conditions => {:method => :delete}
|
19
|
+
model.connect "/#{root}/:model", :action => "create", :conditions => {:method => :post}
|
20
|
+
end
|
11
21
|
end
|
12
22
|
end
|
13
23
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<tr class="<%= cycle("odd", "") %>">
|
2
|
-
<td><%= link_to("Edit", :
|
3
|
-
<td><%= link_to("Delete", :
|
2
|
+
<td><%= link_to("Edit", data_browser_edit_path(:id => obj.to_param, :model => current_model_id)) unless obj.to_param.nil? %></td>
|
3
|
+
<td><%= link_to("Delete", data_browser_object_path(:id => obj.to_param, :model => current_model_id), :method => :delete, :confirm => "Are you sure?") unless obj.to_param.nil? %></td>
|
4
4
|
<% for column in params[:select] %>
|
5
5
|
<td><%= obj.attributes[column] %></td>
|
6
6
|
<% end %>
|
@@ -2,6 +2,6 @@
|
|
2
2
|
|
3
3
|
<p>Rails DataBrowser is a data browser based on the idea of <a href="http://www.djangoproject.com/documentation/databrowse/">Django's Databrowser</a>.</p>
|
4
4
|
<p>Using Rails DataBrowser you can browse, view, edit, crate and delete data through your model classes. It's not a replacement to your DBMS or to your CMS, it's just a helper for developers and WebMasters to manage data without.</p>
|
5
|
-
<p>If you find a bug, please report it <a href="http://
|
5
|
+
<p>If you find a bug, please report it <a href="http://redmine.milk-it.net/projects/databrowser/issues/new">here</a></p>
|
6
6
|
<p />
|
7
|
-
<p>Rails DataBrowser plugin is sponsored by <a href="http://milk-it.net">Milk-it
|
7
|
+
<p>Rails DataBrowser plugin is sponsored by <a href="http://milk-it.net">Milk-it Software House</a> and maintained by <%= mail_to "carlos@milk-it.net", "Carlos Júnior", :encode => "hex", :replace_at => " at ", :replace_dot => "dot" %>.</p>
|
@@ -1,8 +1,8 @@
|
|
1
|
-
<% form_tag(
|
1
|
+
<% form_tag(data_browser_model_path(:model => current_model_id), {:id => "search_form"}) do %>
|
2
2
|
<div id="search-box" style="display:none">
|
3
3
|
<p>
|
4
4
|
<label>Select</label><br />
|
5
|
-
<% for column in
|
5
|
+
<% for column in current_model.column_names %>
|
6
6
|
<label><%= check_box_tag("select[]", column, params[:select].include?(column)) %><%= column %></label>
|
7
7
|
<% end %>
|
8
8
|
</p>
|
@@ -1,8 +1,8 @@
|
|
1
1
|
<ul>
|
2
|
-
<% @models.
|
2
|
+
<% @models.each_with_index do |model, i| %>
|
3
3
|
<li>
|
4
|
-
<%= link_to(model.
|
5
|
-
<%= link_to("empty",
|
4
|
+
<%= link_to(model.table_name, data_browser_model_path(:model => i)) %> (<%= model.count %> records)
|
5
|
+
<%= link_to("empty", data_browser_model_path(:model => i), :confirm => "Are you sure?", :method => :delete) %>
|
6
6
|
</li>
|
7
7
|
<% end %>
|
8
8
|
</ul>
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<% form_for(@obj, :url =>
|
1
|
+
<% form_for(@obj, :url => data_browser_model_path(:model => current_model_id), :method => :post) do |f| %>
|
2
2
|
<%= render :partial => "form", :locals => {:form => f} %>
|
3
3
|
<div class="button">
|
4
4
|
<%= submit_tag("Create") %> or <%= link_to("cancel", :action => "browse", :model => @model.to_s) %>
|
@@ -209,15 +209,15 @@ document.getElementById("show-search").style.display = "none";
|
|
209
209
|
</script>
|
210
210
|
</head>
|
211
211
|
<body id="home">
|
212
|
-
<h1><%= link_to("<b>Rails</b>DataBrowser",
|
212
|
+
<h1><%= link_to("<b>Rails</b>DataBrowser", data_browser_home_path()) %></h1>
|
213
213
|
<ul id="models">
|
214
|
-
<%
|
215
|
-
<li><%= link_to(model.
|
214
|
+
<% @models.each_with_index do |model, i| %>
|
215
|
+
<li><%= link_to(model.table_name, data_browser_model_path(:model => i)) %></li>
|
216
216
|
<% end %>
|
217
217
|
</ul>
|
218
218
|
<div id="content">
|
219
|
-
<% if
|
220
|
-
<h2><%=
|
219
|
+
<% if current_model %>
|
220
|
+
<h2><%= current_model.table_name %> <%= link_to("new", data_browser_new_path(:model => current_model_id)) %></h2>
|
221
221
|
<% end %>
|
222
222
|
<%= content_tag(:h3, flash[:notice], :class => "notice") if flash[:notice] %>
|
223
223
|
<%= yield %>
|
@@ -225,12 +225,12 @@ document.getElementById("show-search").style.display = "none";
|
|
225
225
|
<div style="clear:both"> </div>
|
226
226
|
<div id="footer">
|
227
227
|
<p class="left">
|
228
|
-
Powered by <%= link_to
|
228
|
+
Powered by <%= link_to("DataBrowser", data_browser_about_path()) %><br />
|
229
229
|
by <a href="http://milk-it.net">Milk-it</a>
|
230
230
|
</p>
|
231
231
|
<p class="right">
|
232
232
|
Visit Rails DataBrowser Official WebSite.<br />
|
233
|
-
<a href="http://
|
233
|
+
<a href="http://redmine.milk-it.net/projects/show/databrowser">redmine.milk-it.net/projects</a>
|
234
234
|
</p>
|
235
235
|
</div>
|
236
236
|
</body>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: databrowser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: "0.
|
4
|
+
version: "0.9"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carlos Junior
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-08-05 00:00:00 -03:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|