obitum-rails_admin 0.0.4 → 0.0.5
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.
- data/app/helpers/rails_admin/application_helper.rb +2 -2
- data/app/views/layouts/rails_admin/application.html.haml +1 -1
- data/app/views/rails_admin/main/_form_nested_many.html.haml +4 -2
- data/config/initializers/mongoid_extensions.rb +1 -0
- data/lib/rails_admin/adapters/active_record.rb +8 -0
- data/lib/rails_admin/adapters/mongoid.rb +13 -1
- data/lib/rails_admin/adapters/mongoid/extension.rb +21 -0
- data/lib/rails_admin/config.rb +1 -1
- data/lib/rails_admin/config/fields/association.rb +1 -1
- data/lib/rails_admin/support/csv_converter.rb +1 -1
- data/lib/rails_admin/version.rb +1 -1
- data/spec/dummy_app/app/models/article.rb +3 -0
- data/spec/dummy_app/app/models/note.rb +7 -0
- data/spec/integration/basic/export/rails_admin_mongoid_export_spec.rb +23 -0
- data/spec/integration/config/edit/rails_admin_config_edit_spec.rb +10 -0
- metadata +9 -5
@@ -79,7 +79,7 @@ module RailsAdmin
|
|
79
79
|
o = a.send(:eval, 'bindings[:object]')
|
80
80
|
content_tag(:li, :class => "#{"active" if current_action?(a, am, o)}") do
|
81
81
|
if a.http_methods.include?(:get)
|
82
|
-
link_to wording_for(:breadcrumb, a, am, o), { :action => a.action_name, :controller => 'rails_admin/main', :model_name => am.try(:to_param), :id => o.try(:id) }
|
82
|
+
link_to wording_for(:breadcrumb, a, am, o), { :action => a.action_name, :controller => 'rails_admin/main', :model_name => am.try(:to_param), :id => (o.try(:persisted?) && o.try(:id) || nil) }
|
83
83
|
else
|
84
84
|
content_tag(:span, wording_for(:breadcrumb, a, am, o))
|
85
85
|
end
|
@@ -95,7 +95,7 @@ module RailsAdmin
|
|
95
95
|
wording = wording_for(:menu, action)
|
96
96
|
%{
|
97
97
|
<li data-original-title="#{wording}" rel="#{'tooltip' if only_icon}" class="icon #{action.key}_#{parent}_link #{'active' if current_action?(action)}">
|
98
|
-
<a href="#{url_for({ :action => action.action_name, :controller => 'rails_admin/main', :model_name => abstract_model.try(:to_param), :id => object.try(:id) })}">
|
98
|
+
<a href="#{url_for({ :action => action.action_name, :controller => 'rails_admin/main', :model_name => abstract_model.try(:to_param), :id => (object.try(:persisted?) && object.try(:id) || nil) })}">
|
99
99
|
<i class="#{action.link_icon}"></i>
|
100
100
|
<span#{only_icon ? " style='display:none'" : ""}>#{wording}</span>
|
101
101
|
</a>
|
@@ -32,7 +32,7 @@
|
|
32
32
|
= value
|
33
33
|
= breadcrumb
|
34
34
|
%ul.nav.nav-tabs
|
35
|
-
= menu_for((@abstract_model ? (@object.try(:
|
35
|
+
= menu_for((@abstract_model ? (@object.try(:persisted?) ? :member : :collection) : :root), @abstract_model, @object)
|
36
36
|
= content_for :contextual_tabs
|
37
37
|
= yield
|
38
38
|
%footer
|
@@ -2,13 +2,15 @@
|
|
2
2
|
.btn-group
|
3
3
|
%a.btn.btn-info.toggler{:'data-toggle' => "button", :'data-target' => "#{form.jquery_namespace(field)} > .tab-content, #{form.jquery_namespace(field)} > .controls > .nav", :class => (field.active? ? 'active' : '')}
|
4
4
|
%i.icon-white
|
5
|
-
|
5
|
+
- unless field.nested_form[:update_only]
|
6
|
+
= form.link_to_add "<i class=\"icon-plus icon-white\"></i> #{wording_for(:link, :new, field.associated_model_config.abstract_model)}".html_safe, field.name, { :class => 'btn btn-info' }
|
6
7
|
= form.errors_for(field)
|
7
8
|
= form.help_for(field)
|
8
9
|
%ul.nav.nav-tabs{ :style => 'margin-top:5px' }
|
9
10
|
.tab-content
|
10
11
|
= form.fields_for field.name do |nested_form|
|
11
|
-
|
12
|
+
- if field.nested_form[:allow_destroy]
|
13
|
+
= nested_form.link_to_remove '<span class="btn btn-small btn-danger"><i class="icon-trash icon-white"></i></span>'.html_safe
|
12
14
|
= nested_form.generate({:action => :nested, :model_config => field.associated_model_config, :nested_in => field.name })
|
13
15
|
|
14
16
|
= form.javascript_for(field) do
|
@@ -1,4 +1,5 @@
|
|
1
1
|
if defined?(::Mongoid::Document)
|
2
2
|
require 'rails_admin/adapters/mongoid/extension'
|
3
3
|
Mongoid::Document.send(:include, RailsAdmin::Adapters::Mongoid::Extension)
|
4
|
+
Mongoid::NestedAttributes::ClassMethods.send(:include, RailsAdmin::Adapters::Mongoid::NestedAttributesExtension)
|
4
5
|
end
|
@@ -93,6 +93,14 @@ module RailsAdmin
|
|
93
93
|
model.serialized_attributes.keys
|
94
94
|
end
|
95
95
|
|
96
|
+
def encoding
|
97
|
+
Rails.configuration.database_configuration[Rails.env]['encoding']
|
98
|
+
end
|
99
|
+
|
100
|
+
def embedded?
|
101
|
+
false
|
102
|
+
end
|
103
|
+
|
96
104
|
private
|
97
105
|
|
98
106
|
def query_conditions(query, fields = config.list.fields.select(&:queryable?))
|
@@ -70,7 +70,7 @@ module RailsAdmin
|
|
70
70
|
:polymorphic => association_polymorphic_lookup(association),
|
71
71
|
:inverse_of => association_inverse_of_lookup(association),
|
72
72
|
:read_only => nil,
|
73
|
-
:nested_form =>
|
73
|
+
:nested_form => association_nested_attributes_options_lookup(association)
|
74
74
|
}
|
75
75
|
end
|
76
76
|
end
|
@@ -124,6 +124,14 @@ module RailsAdmin
|
|
124
124
|
[]
|
125
125
|
end
|
126
126
|
|
127
|
+
def encoding
|
128
|
+
'UTF-8'
|
129
|
+
end
|
130
|
+
|
131
|
+
def embedded?
|
132
|
+
@embedded ||= !!model.associations.values.find{|a| a.macro.to_sym == :embedded_in }
|
133
|
+
end
|
134
|
+
|
127
135
|
private
|
128
136
|
|
129
137
|
def query_conditions(query, fields = config.list.fields.select(&:queryable?))
|
@@ -256,6 +264,10 @@ module RailsAdmin
|
|
256
264
|
end
|
257
265
|
end
|
258
266
|
|
267
|
+
def association_nested_attributes_options_lookup(association)
|
268
|
+
model.nested_attributes_options.try { |o| o[association.name.to_sym] }
|
269
|
+
end
|
270
|
+
|
259
271
|
def association_as_lookup(association)
|
260
272
|
association.as.try :to_sym
|
261
273
|
end
|
@@ -22,6 +22,27 @@ module RailsAdmin
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
25
|
+
|
26
|
+
module NestedAttributesExtension
|
27
|
+
extend ActiveSupport::Concern
|
28
|
+
|
29
|
+
included do
|
30
|
+
attr_reader :nested_attributes_options
|
31
|
+
alias_method_chain :accepts_nested_attributes_for, :rails_admin
|
32
|
+
end
|
33
|
+
|
34
|
+
# Mongoid accepts_nested_attributes_for does not store options in accessible scope,
|
35
|
+
# so we intercept the call and store it in instance variable which can be accessed from outside
|
36
|
+
def accepts_nested_attributes_for_with_rails_admin(*args)
|
37
|
+
@nested_attributes_options = {}
|
38
|
+
options = args.extract_options!
|
39
|
+
args.each do |arg|
|
40
|
+
@nested_attributes_options[arg.to_sym] = options.reverse_merge(:allow_destroy=>false, :update_only=>false)
|
41
|
+
end
|
42
|
+
args << options
|
43
|
+
accepts_nested_attributes_for_without_rails_admin(*args)
|
44
|
+
end
|
45
|
+
end
|
25
46
|
end
|
26
47
|
end
|
27
48
|
end
|
data/lib/rails_admin/config.rb
CHANGED
@@ -304,7 +304,7 @@ module RailsAdmin
|
|
304
304
|
# @see RailsAdmin::Config::Hideable
|
305
305
|
|
306
306
|
def visible_models(bindings)
|
307
|
-
models.map{|m| m.with(bindings) }.select{|m| m.visible? && bindings[:controller].authorized?(:index, m.abstract_model)}.sort do |a, b|
|
307
|
+
models.map{|m| m.with(bindings) }.select{|m| m.visible? && bindings[:controller].authorized?(:index, m.abstract_model) && !m.abstract_model.embedded?}.sort do |a, b|
|
308
308
|
(weight_order = a.weight <=> b.weight) == 0 ? a.label.downcase <=> b.label.downcase : weight_order
|
309
309
|
end
|
310
310
|
end
|
@@ -21,7 +21,7 @@ module RailsAdmin
|
|
21
21
|
amc = polymorphic? ? RailsAdmin::Config.model(associated) : associated_model_config # perf optimization for non-polymorphic associations
|
22
22
|
am = amc.abstract_model
|
23
23
|
wording = associated.send(amc.object_label_method)
|
24
|
-
can_see = v.authorized?(:show, am, associated)
|
24
|
+
can_see = v.authorized?(:show, am, associated) && !am.embedded?
|
25
25
|
can_see = can_see && (show_action = RailsAdmin::Config::Actions.find(:show, { :controller => v.controller, :abstract_model => am, :object => associated }))
|
26
26
|
can_see ? v.link_to(wording, v.url_for(:action => show_action.action_name, :model_name => am.to_param, :id => associated.id)) : wording
|
27
27
|
end.to_sentence.html_safe
|
@@ -42,7 +42,7 @@ module RailsAdmin
|
|
42
42
|
return '' if @objects.blank?
|
43
43
|
|
44
44
|
# encoding shenanigans first
|
45
|
-
@encoding_from = if [nil, '', 'utf8', 'utf-8', 'UTF8', 'UTF-8'].include?(encoding =
|
45
|
+
@encoding_from = if [nil, '', 'utf8', 'utf-8', 'UTF8', 'UTF-8'].include?(encoding = @abstract_model.encoding)
|
46
46
|
'UTF-8'
|
47
47
|
else
|
48
48
|
encoding
|
data/lib/rails_admin/version.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "RailsAdmin Mongoid Export" do
|
4
|
+
|
5
|
+
subject { page }
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@authors = 3.times.map { FactoryGirl.create :author }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "POST /admin/author/export (prompt)" do
|
12
|
+
|
13
|
+
it "should allow to export to CSV" do
|
14
|
+
visit export_path(:model_name => 'author')
|
15
|
+
should have_content 'Select fields to export'
|
16
|
+
Rails.configuration.should_not_receive(:database_configuration)
|
17
|
+
click_button 'Export to csv'
|
18
|
+
should have_content "Name"
|
19
|
+
should have_content @authors[0].name
|
20
|
+
should have_content @authors[2].name
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -814,6 +814,16 @@ describe "RailsAdmin Config DSL Edit Section" do
|
|
814
814
|
visit new_path(:model_name => "field_test")
|
815
815
|
should have_no_selector('.add_nested_fields')
|
816
816
|
end
|
817
|
+
|
818
|
+
it 'should work with Mongoid' do
|
819
|
+
RailsAdmin::Config.excluded_models = [RelTest]
|
820
|
+
@record = Article.create :notes => [{:subject => 'nested'}]
|
821
|
+
visit edit_path(:model_name => "article", :id => @record.id)
|
822
|
+
fill_in "article_notes_attributes_0_subject", :with => 'note subject 1 edited'
|
823
|
+
click_button "Save"
|
824
|
+
@record.reload
|
825
|
+
@record.notes[0].subject.should == 'note subject 1 edited'
|
826
|
+
end
|
817
827
|
end
|
818
828
|
|
819
829
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: obitum-rails_admin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 5
|
10
|
+
version: 0.0.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Erik Michaels-Ober
|
@@ -18,7 +18,7 @@ autorequire:
|
|
18
18
|
bindir: bin
|
19
19
|
cert_chain: []
|
20
20
|
|
21
|
-
date: 2012-03-
|
21
|
+
date: 2012-03-17 00:00:00 Z
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
24
24
|
name: bbenezech-nested_form
|
@@ -619,6 +619,7 @@ files:
|
|
619
619
|
- spec/dummy_app/app/models/league.rb
|
620
620
|
- spec/dummy_app/app/models/mongoid_field_test.rb
|
621
621
|
- spec/dummy_app/app/models/nested_field_test.rb
|
622
|
+
- spec/dummy_app/app/models/note.rb
|
622
623
|
- spec/dummy_app/app/models/player.rb
|
623
624
|
- spec/dummy_app/app/models/rel_test.rb
|
624
625
|
- spec/dummy_app/app/models/tag.rb
|
@@ -717,6 +718,7 @@ files:
|
|
717
718
|
- spec/integration/basic/destroy/rails_admin_basic_destroy_spec.rb
|
718
719
|
- spec/integration/basic/edit/rails_admin_basic_edit_spec.rb
|
719
720
|
- spec/integration/basic/export/rails_admin_basic_export_spec.rb
|
721
|
+
- spec/integration/basic/export/rails_admin_mongoid_export_spec.rb
|
720
722
|
- spec/integration/basic/list/rails_admin_basic_list_spec.rb
|
721
723
|
- spec/integration/basic/new/rails_admin_basic_new_spec.rb
|
722
724
|
- spec/integration/basic/new/rails_admin_namespaced_model_new_spec.rb
|
@@ -770,7 +772,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
770
772
|
requirements: []
|
771
773
|
|
772
774
|
rubyforge_project:
|
773
|
-
rubygems_version: 1.8.
|
775
|
+
rubygems_version: 1.8.16
|
774
776
|
signing_key:
|
775
777
|
specification_version: 3
|
776
778
|
summary: Admin for Rails
|
@@ -803,6 +805,7 @@ test_files:
|
|
803
805
|
- spec/dummy_app/app/models/league.rb
|
804
806
|
- spec/dummy_app/app/models/mongoid_field_test.rb
|
805
807
|
- spec/dummy_app/app/models/nested_field_test.rb
|
808
|
+
- spec/dummy_app/app/models/note.rb
|
806
809
|
- spec/dummy_app/app/models/player.rb
|
807
810
|
- spec/dummy_app/app/models/rel_test.rb
|
808
811
|
- spec/dummy_app/app/models/tag.rb
|
@@ -901,6 +904,7 @@ test_files:
|
|
901
904
|
- spec/integration/basic/destroy/rails_admin_basic_destroy_spec.rb
|
902
905
|
- spec/integration/basic/edit/rails_admin_basic_edit_spec.rb
|
903
906
|
- spec/integration/basic/export/rails_admin_basic_export_spec.rb
|
907
|
+
- spec/integration/basic/export/rails_admin_mongoid_export_spec.rb
|
904
908
|
- spec/integration/basic/list/rails_admin_basic_list_spec.rb
|
905
909
|
- spec/integration/basic/new/rails_admin_basic_new_spec.rb
|
906
910
|
- spec/integration/basic/new/rails_admin_namespaced_model_new_spec.rb
|