mongoid_document_editor 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +40 -17
- data/app/controllers/mongoid/document_editor/application_controller.rb +3 -0
- data/app/controllers/mongoid/document_editor/documents_controller.rb +22 -6
- data/app/helpers/mongoid/document_editor/documents_helper.rb +13 -1
- data/app/views/mongoid/document_editor/documents/all.html.erb +3 -0
- data/app/views/mongoid/document_editor/documents/edit.html.erb +15 -5
- data/app/views/mongoid/document_editor/documents/index.html.erb +30 -1
- data/app/views/mongoid/document_editor/documents/show.html.erb +25 -0
- data/app/views/mongoid/document_editor/layouts/application.html.erb +6 -1
- data/config/routes.rb +4 -1
- data/lib/mongoid/document_editor/engine.rb +5 -1
- data/lib/mongoid/document_editor/version.rb +1 -1
- data/lib/mongoid/document_editor.rb +13 -1
- data/mongoid_document_editor.gemspec +1 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a560b84e3fe4da5adc33097334815fc355440e8
|
4
|
+
data.tar.gz: 5701273de9024ce00b415615a6635060b94322ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e8d01079e509c85715309554cb80d31f09fe5af7b3e3ed198d0b584f084bbad1afa4c18dae1c194caf0db5eaad4070dcd03473e2efc84b98d55a7eb4c5bfa49
|
7
|
+
data.tar.gz: 1ed9e7db517aec84842567ceeb27150c76d0f72667f396e683e4a063ec4a1b81504365d222b7594ad11b65a45eec41e641ae334ad36f4b3743c7b665435b0fe0
|
data/README.md
CHANGED
@@ -1,29 +1,52 @@
|
|
1
|
-
#
|
1
|
+
# Mongoid Document Editor
|
2
2
|
|
3
|
-
Mongoid
|
3
|
+
Mongoid Document Editor is Rails Engine that provides a DSL for setting up simple admin interfaces to edit MongoDB documents. No configuration is required in order to get a basic form, however you can override any form you want to provide a more custom and usable interface.
|
4
4
|
|
5
|
-
|
5
|
+
### Configuration
|
6
|
+
Create an initializer and configure your admin interface.
|
6
7
|
|
7
|
-
|
8
|
+
```ruby
|
9
|
+
Mongoid::DocumentEditor.configure do
|
8
10
|
|
9
|
-
|
11
|
+
authenticate_with :admin_required
|
12
|
+
|
13
|
+
mount_at "/admin/documents"
|
10
14
|
|
11
|
-
|
15
|
+
form_configuration_for User do
|
16
|
+
field :first_name
|
17
|
+
field :last_name
|
18
|
+
field :favorite_color, values: User::COLORS
|
19
|
+
field :email, type: :email
|
20
|
+
field :home_city_id, values: -> { City.all }, label: :name, value: :id
|
21
|
+
field :visitied_city_ids: values: ->(user) { user.visited_cities }, label: :name, value: :id
|
22
|
+
end
|
12
23
|
|
13
|
-
|
24
|
+
index_configuration_for User do
|
25
|
+
column :first_name
|
26
|
+
column :last_Name
|
27
|
+
column :email
|
28
|
+
column :city, value: ->(user) { user.city.name }
|
29
|
+
end
|
14
30
|
|
15
|
-
|
31
|
+
end
|
32
|
+
```
|
16
33
|
|
17
|
-
|
34
|
+
### Usage
|
35
|
+
In your application visit: **/documents**
|
18
36
|
|
19
|
-
|
37
|
+
### Options
|
38
|
+
`authenticate_with`: Provide a controller filter for granting / denying access
|
39
|
+
`form_configuration_for Class`: Allows you to specify the fields that you want on the form for the specified class
|
40
|
+
`index_configuration_for Class`: Allows you to specify the columns that are displayed on the index page
|
41
|
+
`mount_at`: Endpoint where editor is mounted (default is **/documents**)
|
20
42
|
|
21
|
-
|
43
|
+
### Notes
|
44
|
+
In development mode set `preload_models: true`
|
22
45
|
|
23
|
-
|
46
|
+
### TODO
|
24
47
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
48
|
+
* Rails generator
|
49
|
+
* Remove simple_form dependency
|
50
|
+
|
51
|
+
|
52
|
+
Styled using [Base](http://matthewhartman.github.io/base/docs/index.html)
|
@@ -1,34 +1,50 @@
|
|
1
1
|
module Mongoid
|
2
2
|
module DocumentEditor
|
3
3
|
class DocumentsController < ApplicationController
|
4
|
-
include DocumentsHelper
|
5
4
|
|
6
5
|
layout "mongoid/document_editor/layouts/application"
|
7
6
|
|
8
|
-
before_filter
|
7
|
+
before_filter :setup_klass, except: [:all]
|
8
|
+
|
9
|
+
def all
|
10
|
+
end
|
9
11
|
|
10
12
|
def index
|
13
|
+
@documents = @klass.all
|
11
14
|
end
|
12
15
|
|
13
16
|
def edit
|
14
|
-
@klass = params[:type].classify.constantize
|
15
17
|
@document = @klass.find(params[:id])
|
16
18
|
end
|
17
19
|
|
18
20
|
def update
|
19
|
-
@klass = params[:type].classify.constantize
|
20
21
|
@document = @klass.find(params[:id])
|
21
22
|
@document.update_attributes(document_params)
|
22
23
|
|
23
|
-
redirect_to
|
24
|
+
redirect_to document_path(params[:type], @document.id)
|
25
|
+
end
|
26
|
+
|
27
|
+
def show
|
28
|
+
@document = @klass.find(params[:id])
|
24
29
|
end
|
25
30
|
|
26
|
-
|
31
|
+
def destroy
|
32
|
+
@document = @klass.find(params[:id])
|
33
|
+
@document.destroy
|
34
|
+
|
35
|
+
redirect_to documents_path(params[:type])
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
27
39
|
|
28
40
|
def document_params
|
29
41
|
params.require(params[:type].to_sym).permit!
|
30
42
|
end
|
31
43
|
|
44
|
+
def setup_klass
|
45
|
+
@klass = params[:type].classify.constantize
|
46
|
+
end
|
47
|
+
|
32
48
|
end
|
33
49
|
end
|
34
50
|
end
|
@@ -31,7 +31,19 @@ module Mongoid
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
|
34
|
+
def cell_value(document, header, config)
|
35
|
+
if config[:value] && config[:value].respond_to?(:call)
|
36
|
+
config[:value].call(document)
|
37
|
+
else
|
38
|
+
document.send(header)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def model_param(model)
|
43
|
+
model.to_s.underscore.downcase
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
35
47
|
|
36
48
|
def private_field?(name)
|
37
49
|
return true if name.start_with?("_")
|
@@ -1,6 +1,16 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
<
|
4
|
-
|
5
|
-
|
1
|
+
<div class="section header">
|
2
|
+
<div class="container clear">
|
3
|
+
<h1 class='logo'>Editing: <%= @document.id %></h1>
|
4
|
+
</div>
|
5
|
+
</div>
|
6
|
+
|
7
|
+
<%= simple_form_for @document, url: update_document_path(model_param(@klass), @document) do |f| %>
|
8
|
+
<fieldset class='row'>
|
9
|
+
<% Mongoid::DocumentEditor.fields_for(@klass).each_pair do |name, config| %>
|
10
|
+
<p><%= document_edit_field(f, @klass, @document, name, config) %></p>
|
11
|
+
<% end %>
|
12
|
+
<%= link_to "Cancel", document_path(model_param(@klass), @document), class: "button orange-button mobile-full" %>
|
13
|
+
<%= f.submit class: "button orange-button mobile-full" %>
|
14
|
+
</fieldset>
|
6
15
|
<% end %>
|
16
|
+
|
@@ -1 +1,30 @@
|
|
1
|
-
<
|
1
|
+
<div class="section header">
|
2
|
+
<div class="container clear">
|
3
|
+
<h1 class='logo'><%= @klass.name.pluralize %></h1>
|
4
|
+
</div>
|
5
|
+
</div>
|
6
|
+
|
7
|
+
<table>
|
8
|
+
<thead>
|
9
|
+
<tr>
|
10
|
+
<% Mongoid::DocumentEditor.index_for(@klass).each_pair do |header, config| %>
|
11
|
+
<th><%= header.to_s.humanize %></th>
|
12
|
+
<% end %>
|
13
|
+
<th>Actions</th>
|
14
|
+
</tr>
|
15
|
+
</thead>
|
16
|
+
<tbody>
|
17
|
+
<% @documents.each do |document| %>
|
18
|
+
<tr>
|
19
|
+
<% Mongoid::DocumentEditor.index_for(@klass).each_pair do |header, config| %>
|
20
|
+
<td><%= cell_value(document, header, config) %></td>
|
21
|
+
<% end %>
|
22
|
+
<td>
|
23
|
+
<%= link_to "View", document_path(model_param(@klass), document) %> |
|
24
|
+
<%= link_to "Edit", edit_document_path(model_param(@klass), document) %> |
|
25
|
+
<%= link_to "Destroy", destroy_document_path(model_param(@klass), document), method: :delete, data: {confirm: "Are you sure you want to destroy this record?"} %>
|
26
|
+
</td>
|
27
|
+
</tr>
|
28
|
+
<% end %>
|
29
|
+
</tbody>
|
30
|
+
</table>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<div class="section header">
|
2
|
+
<div class="container clear">
|
3
|
+
<h1 class='logo'>Viewing: <%= @document.id %></h1>
|
4
|
+
</div>
|
5
|
+
</div>
|
6
|
+
<h3><%= link_to "Edit", edit_document_path(model_param(@klass), @document.id) %></h3>
|
7
|
+
|
8
|
+
<% @klass.fields.each do |key, value| %>
|
9
|
+
<p><b><%= key %>:</b> <%= @document.send(key) %></p>
|
10
|
+
<% end %>
|
11
|
+
|
12
|
+
<hr>
|
13
|
+
<h2>Relations:</h2>
|
14
|
+
<% @klass.relations.each do |key, value| %>
|
15
|
+
<h3><%= key %></h3>
|
16
|
+
<% if [:has_many, :has_and_belongs_to_many].include?(@document.relations[key].macro) %>
|
17
|
+
<% @document.send(key).each do |relation| %>
|
18
|
+
<p><%= link_to relation.send(:id), document_path(model_param(value.class_name), relation.send(:id)) %></p>
|
19
|
+
<% end %>
|
20
|
+
<% elsif [:has_one, :belongs_to].include?(@document.relations[key].macro) %>
|
21
|
+
<% if relation = @document.send(key) %>
|
22
|
+
<p><%= link_to relation.send(:id), document_path(model_param(value.class_name), relation.send(:id)) %></p>
|
23
|
+
<% end %>
|
24
|
+
<% end %>
|
25
|
+
<% end %>
|
@@ -2,8 +2,13 @@
|
|
2
2
|
<html>
|
3
3
|
<head>
|
4
4
|
<%= csrf_meta_tags %>
|
5
|
+
<%= stylesheet_link_tag "base/style", "base/doc" %>
|
5
6
|
</head>
|
6
7
|
<body>
|
7
|
-
|
8
|
+
<div class="container content-inner">
|
9
|
+
<%= link_to "All Documents", document_listing_path %>
|
10
|
+
<%= yield %>
|
11
|
+
</div>
|
12
|
+
<%= javascript_include_tag "jquery", "jquery_ujs" %>
|
8
13
|
</body>
|
9
14
|
</html>
|
data/config/routes.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
Mongoid::DocumentEditor::Engine.routes.draw do
|
2
2
|
|
3
|
+
get "/", to: "documents#all", as: :document_listing
|
3
4
|
get "/:type/:id/edit", to: "documents#edit", as: :edit_document
|
5
|
+
get "/:type/:id", to: "documents#show", as: :document
|
4
6
|
put "/:type/:id/edit", to: "documents#update", as: :update_document
|
5
|
-
|
7
|
+
get "/:type", to: "documents#index", as: :documents
|
8
|
+
delete "/:type/:id", to: "documents#destroy", as: :destroy_document
|
6
9
|
|
7
10
|
end
|
@@ -3,9 +3,13 @@ module Mongoid
|
|
3
3
|
class Engine < ::Rails::Engine
|
4
4
|
isolate_namespace Mongoid::DocumentEditor
|
5
5
|
|
6
|
+
initializer "mongoid-document-editor.assets.precompile" do |app|
|
7
|
+
app.config.assets.precompile += ["base/style.css", "base/doc.css", "jquery.js", "jquery_ujs.js"]
|
8
|
+
end
|
9
|
+
|
6
10
|
config.after_initialize do |app|
|
7
11
|
app.routes.prepend do
|
8
|
-
mount Mongoid::DocumentEditor::Engine =>
|
12
|
+
mount Mongoid::DocumentEditor::Engine => Mongoid::DocumentEditor.endpoint
|
9
13
|
end
|
10
14
|
end
|
11
15
|
|
@@ -17,6 +17,9 @@ module Mongoid
|
|
17
17
|
mattr_accessor :authentication_filter
|
18
18
|
@@authentication_filter = nil
|
19
19
|
|
20
|
+
mattr_accessor :endpoint
|
21
|
+
@@endpoint = "/documents"
|
22
|
+
|
20
23
|
def self.configure(&block)
|
21
24
|
instance_eval(&block)
|
22
25
|
end
|
@@ -30,7 +33,12 @@ module Mongoid
|
|
30
33
|
end
|
31
34
|
|
32
35
|
def self.index_for(klass)
|
33
|
-
|
36
|
+
default_fields = {}
|
37
|
+
klass.fields.each_pair do |name, options|
|
38
|
+
next if name.start_with?("_")
|
39
|
+
default_fields[name.to_s] = {}
|
40
|
+
end
|
41
|
+
@@index_configuration.fetch(klass, default_fields)
|
34
42
|
end
|
35
43
|
|
36
44
|
def self.form_configuration_for(document_class, &block)
|
@@ -49,5 +57,9 @@ module Mongoid
|
|
49
57
|
@@authentication_filter = filter
|
50
58
|
end
|
51
59
|
|
60
|
+
def self.mount_at(endpoint)
|
61
|
+
@@endpoint = endpoint
|
62
|
+
end
|
63
|
+
|
52
64
|
end
|
53
65
|
end
|
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_dependency "simple_form", "~> 2.1.0"
|
26
26
|
spec.add_dependency "mongoid", "~> 3.1.0"
|
27
27
|
spec.add_dependency "strong_parameters"
|
28
|
+
spec.add_dependency "jquery-rails"
|
28
29
|
|
29
30
|
spec.add_development_dependency "bundler", "~> 1.3"
|
30
31
|
spec.add_development_dependency "rake"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid_document_editor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick DeSteffen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: jquery-rails
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: bundler
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -111,8 +125,10 @@ files:
|
|
111
125
|
- app/controllers/mongoid/document_editor/application_controller.rb
|
112
126
|
- app/controllers/mongoid/document_editor/documents_controller.rb
|
113
127
|
- app/helpers/mongoid/document_editor/documents_helper.rb
|
128
|
+
- app/views/mongoid/document_editor/documents/all.html.erb
|
114
129
|
- app/views/mongoid/document_editor/documents/edit.html.erb
|
115
130
|
- app/views/mongoid/document_editor/documents/index.html.erb
|
131
|
+
- app/views/mongoid/document_editor/documents/show.html.erb
|
116
132
|
- app/views/mongoid/document_editor/layouts/application.html.erb
|
117
133
|
- config/routes.rb
|
118
134
|
- README.md
|