databrowser 0.9 → 1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/data_browser/data_browser_controller.rb +15 -27
- data/lib/data_browser/routing.rb +10 -8
- data/lib/data_browser/views/data_browser/data_browser/_obj.rhtml +2 -2
- data/lib/data_browser/views/data_browser/data_browser/edit.html.erb +2 -2
- data/lib/data_browser/views/data_browser/data_browser/new.html.erb +2 -2
- metadata +2 -2
@@ -4,10 +4,12 @@ module DataBrowser
|
|
4
4
|
protect_from_forgery :secret => Time.now.to_i.to_s
|
5
5
|
before_filter :load_models, :authenticate
|
6
6
|
|
7
|
-
|
7
|
+
include DataBrowser::Helpers
|
8
8
|
|
9
9
|
# all the work here is being done by :load_models
|
10
10
|
def index; end
|
11
|
+
def new; end
|
12
|
+
def edit; end
|
11
13
|
|
12
14
|
def browse
|
13
15
|
params[:select] ||= current_model.column_names
|
@@ -25,38 +27,25 @@ module DataBrowser
|
|
25
27
|
def empty
|
26
28
|
current_model.delete_all
|
27
29
|
flash[:notice] = "#{current_model.table_name} model was emptied"
|
28
|
-
redirect_to
|
29
|
-
end
|
30
|
-
|
31
|
-
def new
|
32
|
-
@obj = current_model.new
|
33
|
-
end
|
34
|
-
|
35
|
-
def edit
|
36
|
-
@obj = current_model.find(params[:id])
|
30
|
+
redirect_to data_browser_home_url()
|
37
31
|
end
|
38
32
|
|
39
33
|
def destroy
|
40
|
-
|
41
|
-
@obj.destroy()
|
34
|
+
current_object.delete_all(current_object.attributes)
|
42
35
|
flash[:notice] = "#{current_model.table_name} #{@obj.to_param} successfuly deleted!"
|
43
|
-
redirect_to :
|
36
|
+
redirect_to data_browser_model_url(:model => current_model_id)
|
44
37
|
end
|
45
38
|
|
46
39
|
def update
|
47
|
-
|
48
|
-
@obj.update_attributes(params[current_model.to_s.underscore])
|
49
|
-
|
40
|
+
current_model.update_all(data_from_params, current_object.attributes)
|
50
41
|
flash[:notice] = "#{current_model.table_name} #{@obj.to_param} successfuly saved!"
|
51
|
-
redirect_to :
|
42
|
+
redirect_to data_browser_model_url(:model => current_model_id)
|
52
43
|
end
|
53
44
|
|
54
45
|
def create
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
flash[:notice] = "#{current_model.table_name} #{@obj.to_param} successfuly saved!"
|
59
|
-
redirect_to :action => "browse", :model => current_model_id
|
46
|
+
current_model.create(data_from_params)
|
47
|
+
flash[:notice] = "#{current_model.table_name} #{current_object.to_param || "record"} successfuly saved!"
|
48
|
+
redirect_to data_browser_model_url(:model => current_model_id)
|
60
49
|
end
|
61
50
|
|
62
51
|
protected
|
@@ -80,12 +69,11 @@ module DataBrowser
|
|
80
69
|
end
|
81
70
|
end
|
82
71
|
|
83
|
-
|
84
|
-
@model ||= DataBrowser.models[current_model_id] if current_model_id
|
85
|
-
end
|
72
|
+
private
|
86
73
|
|
87
|
-
def
|
88
|
-
|
74
|
+
def data_from_params
|
75
|
+
pos = ActionController::RecordIdentifier.singular_class_name(current_model)
|
76
|
+
current_model.new(params[pos]).attributes # Hum... well, you know..
|
89
77
|
end
|
90
78
|
end
|
91
79
|
end
|
data/lib/data_browser/routing.rb
CHANGED
@@ -1,22 +1,24 @@
|
|
1
1
|
module DataBrowser
|
2
2
|
module Routing
|
3
|
-
def databrowser(
|
4
|
-
root = opts[:root] || "databrowser"
|
3
|
+
def databrowser(root="databrowser")
|
5
4
|
with_options :controller => "data_browser/data_browser" do |db|
|
6
5
|
# Databrowser pages
|
7
6
|
db.data_browser_home "/#{root}", :action => "index"
|
8
7
|
db.data_browser_about "/#{root}/about", :action => "about"
|
9
8
|
# Model manipulation
|
10
9
|
db.with_options :model => /\d+/ do |model|
|
11
|
-
model.data_browser_model "/#{root}/:model",
|
12
|
-
model.data_browser_new "/#{root}/:model/new",
|
13
|
-
|
14
|
-
model.
|
10
|
+
model.data_browser_model "/#{root}/:model", :action => "browse", :conditions => {:method => :get}
|
11
|
+
model.data_browser_new "/#{root}/:model/new", :action => "new", :conditions => {:method => :get}
|
12
|
+
|
13
|
+
model.connect "/#{root}/:model", :action => "empty", :conditions => {:method => :delete}
|
14
|
+
model.connect "/#{root}/:model", :action => "create", :conditions => {:method => :post}
|
15
|
+
|
16
|
+
# Object manipulation
|
17
|
+
model.data_browser_object "/#{root}/:model/:id/", :action => "show", :conditions => {:method => :get}
|
18
|
+
model.data_browser_edit "/#{root}/:model/:id/edit", :action => "edit", :conditions => {:method => :get}
|
15
19
|
|
16
|
-
model.connect "/#{root}/:model", :action => "empty", :conditions => {:method => :delete}
|
17
20
|
model.connect "/#{root}/:model/:id", :action => "update", :conditions => {:method => :put}
|
18
21
|
model.connect "/#{root}/:model/:id", :action => "destroy", :conditions => {:method => :delete}
|
19
|
-
model.connect "/#{root}/:model", :action => "create", :conditions => {:method => :post}
|
20
22
|
end
|
21
23
|
end
|
22
24
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<tr class="<%= cycle("odd", "") %>">
|
2
|
-
<td><%= link_to("Edit", data_browser_edit_path(
|
3
|
-
<td><%= link_to("Delete", data_browser_object_path(
|
2
|
+
<td><%= link_to("Edit", data_browser_edit_path(object_params(obj))) %></td>
|
3
|
+
<td><%= link_to("Delete", data_browser_object_path(object_params(obj)), :method => :delete, :confirm => "Are you sure?") %></td>
|
4
4
|
<% for column in params[:select] %>
|
5
5
|
<td><%= obj.attributes[column] %></td>
|
6
6
|
<% end %>
|
@@ -1,5 +1,5 @@
|
|
1
|
-
<% form_for(
|
2
|
-
<%= render :partial => "form", :
|
1
|
+
<% form_for(current_object, :url => data_browser_object_path(object_params(current_object)), :method => :put) do |f| %>
|
2
|
+
<%= render :partial => "form", :object => f %>
|
3
3
|
<div class="button">
|
4
4
|
<%= submit_tag("Save") %> or <%= link_to("cancel", :action => "browse", :model => @model.to_s) %>
|
5
5
|
</div>
|
@@ -1,5 +1,5 @@
|
|
1
|
-
<% form_for(
|
2
|
-
<%= render :partial => "form", :
|
1
|
+
<% form_for(current_object, :url => data_browser_model_path(:model => current_model_id), :method => :post) do |f| %>
|
2
|
+
<%= render :partial => "form", :object => f %>
|
3
3
|
<div class="button">
|
4
4
|
<%= submit_tag("Create") %> or <%= link_to("cancel", :action => "browse", :model => @model.to_s) %>
|
5
5
|
</div>
|
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: "1.0"
|
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-08-
|
12
|
+
date: 2008-08-06 00:00:00 -03:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|