lolita 3.1.18 → 3.2.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +5 -2
- data/History.rdoc +24 -0
- data/README.md +113 -0
- data/VERSION +1 -1
- data/{public → app/assets}/images/lolita/plus.png +0 -0
- data/{public → app/assets}/javascripts/lolita/application.js +0 -0
- data/{public → app/assets}/javascripts/lolita/base64.js +0 -0
- data/{public → app/assets}/javascripts/lolita/main.js +1 -0
- data/{public → app/assets}/javascripts/lolita/tab.js +0 -0
- data/{public → app/assets}/stylesheets/lolita/PIE-custom.htc +0 -0
- data/{public → app/assets}/stylesheets/lolita/PIE.htc +0 -0
- data/{public → app/assets}/stylesheets/lolita/default.css +0 -0
- data/{public → app/assets}/stylesheets/lolita/style.css +0 -21
- data/app/controllers/lolita/info_controller.rb +1 -12
- data/app/controllers/lolita/rest_controller.rb +2 -7
- data/app/helpers/lolita_helper.rb +1 -12
- data/app/views/components/lolita/configuration/column/_header.html.erb +1 -1
- data/app/views/components/lolita/configuration/column/_sort.html.erb +4 -7
- data/app/views/components/lolita/configuration/field/array/habtm/_display.html.haml +1 -1
- data/app/views/components/lolita/configuration/field/array/select/_display.html.erb +1 -1
- data/app/views/components/lolita/configuration/field/string/disabled/_display.html.erb +1 -1
- data/app/views/components/lolita/configuration/field/string/text/_display.html.erb +1 -1
- data/app/views/components/lolita/configuration/list/_paginator.html.erb +1 -1
- data/app/views/components/lolita/configuration/list/_title.html.erb +1 -6
- data/app/views/components/lolita/configuration/nested_form/_display.html.erb +6 -8
- data/app/views/components/lolita/navigation/_tree.html.erb +25 -18
- data/app/views/components/lolita/shared/_header.html.erb +1 -1
- data/app/views/components/lolita/shared/_right_sidebar.html.erb +6 -1
- data/app/views/layouts/lolita/application.html.erb +3 -3
- data/config/locales/en.yml +24 -1
- data/config/locales/lv.yml +0 -1
- data/config/routes.rb +1 -3
- data/lib/generators/lolita/install_generator.rb +1 -5
- data/lib/lolita.rb +23 -38
- data/lib/lolita/adapter/abstract_adapter.rb +0 -1
- data/lib/lolita/adapter/active_record.rb +4 -42
- data/lib/lolita/adapter/mongoid.rb +4 -76
- data/lib/lolita/configuration/base.rb +2 -15
- data/lib/lolita/configuration/column.rb +2 -25
- data/lib/lolita/configuration/factory/field.rb +2 -10
- data/lib/lolita/configuration/field.rb +1 -6
- data/lib/lolita/configuration/field/array.rb +31 -124
- data/lib/lolita/configuration/field/integer.rb +1 -0
- data/lib/lolita/configuration/list.rb +2 -23
- data/lib/lolita/configuration/tabs.rb +0 -6
- data/lib/lolita/controllers/component_helpers.rb +1 -1
- data/lib/lolita/controllers/internal_helpers.rb +4 -18
- data/lib/lolita/controllers/user_helpers.rb +11 -23
- data/lib/lolita/hooks.rb +120 -163
- data/lib/lolita/lazy_loader.rb +0 -3
- data/lib/lolita/mapping.rb +0 -23
- data/lib/lolita/modules/rest.rb +1 -1
- data/lib/lolita/navigation/branch.rb +1 -52
- data/lib/lolita/navigation/tree.rb +0 -10
- data/lib/lolita/rails.rb +2 -1
- data/lib/lolita/rails/routes.rb +5 -4
- data/lib/lolita/system_configuration/application.rb +1 -7
- data/lolita.gemspec +83 -100
- data/spec/configuration/field_spec.rb +1 -1
- data/spec/configuration/list_spec.rb +14 -19
- data/spec/rails_app/app/mongoid/post.rb +0 -4
- data/spec/rails_app/config/application.rb +1 -12
- data/spec/rails_app/config/environments/development.rb +2 -6
- data/spec/rails_app/config/environments/production.rb +1 -5
- data/spec/rails_app/config/environments/test.rb +1 -5
- data/vendor/assets/javascripts/jquery-1.6.2.min.js +18 -0
- data/{public → vendor/assets}/javascripts/jquery-ui-1.8.13.min.js +0 -0
- data/{public → vendor/assets}/javascripts/modernizr-1.7.min.js +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/jquery.tinymce.js +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/langs/en.js +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/license.txt +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/themes/advanced/about.htm +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/themes/advanced/anchor.htm +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/themes/advanced/charmap.htm +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/themes/advanced/color_picker.htm +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/themes/advanced/editor_template.js +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/themes/advanced/editor_template_src.js +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/themes/advanced/image.htm +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/themes/advanced/img/colorpicker.jpg +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/themes/advanced/img/flash.gif +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/themes/advanced/img/icons.gif +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/themes/advanced/img/iframe.gif +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/themes/advanced/img/pagebreak.gif +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/themes/advanced/img/quicktime.gif +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/themes/advanced/img/realmedia.gif +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/themes/advanced/img/shockwave.gif +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/themes/advanced/img/trans.gif +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/themes/advanced/img/video.gif +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/themes/advanced/img/windowsmedia.gif +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/themes/advanced/js/about.js +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/themes/advanced/js/anchor.js +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/themes/advanced/js/charmap.js +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/themes/advanced/js/color_picker.js +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/themes/advanced/js/image.js +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/themes/advanced/js/link.js +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/themes/advanced/js/source_editor.js +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/themes/advanced/langs/en.js +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/themes/advanced/langs/en_dlg.js +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/themes/advanced/link.htm +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/themes/advanced/shortcuts.htm +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/themes/advanced/skins/cirkuit/content.css +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/themes/advanced/skins/cirkuit/dialog.css +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/themes/advanced/skins/cirkuit/img/butt2.png +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/themes/advanced/skins/cirkuit/img/button-bg.png +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/themes/advanced/skins/cirkuit/img/buttons.png +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/themes/advanced/skins/cirkuit/img/down_arrow.gif +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/themes/advanced/skins/cirkuit/img/fade-butt.png +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/themes/advanced/skins/cirkuit/img/icons.png +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/themes/advanced/skins/cirkuit/img/items.gif +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/themes/advanced/skins/cirkuit/img/menu-arrow.png +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/themes/advanced/skins/cirkuit/img/menu-check.png +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/themes/advanced/skins/cirkuit/img/progress.gif +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/themes/advanced/skins/cirkuit/img/tabs.gif +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/themes/advanced/skins/cirkuit/img/toolbarbg.png +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/themes/advanced/skins/cirkuit/ui.css +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/themes/advanced/source_editor.htm +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/tiny_mce.js +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/tiny_mce_popup.js +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/utils/editable_selects.js +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/utils/form_utils.js +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/utils/mctabs.js +0 -0
- data/{public → vendor/assets}/javascripts/tinymce/utils/validate.js +0 -0
- data/{public → vendor/assets}/javascripts/tinymce_config.js +1 -1
- metadata +121 -127
- data/README.rdoc +0 -100
- data/app/controllers/lolita/field_data_controller.rb +0 -36
- data/app/views/components/lolita/configuration/field/array/autocomplete/_display.html.haml +0 -11
- data/app/views/components/lolita/configuration/field/array/checkbox/_display.html.haml +0 -8
- data/app/views/components/lolita/configuration/field/array/polymorphic/_display.html.haml +0 -6
- data/app/views/components/lolita/configuration/field/array/polymorphic/_options_for_select.html.haml +0 -1
- data/app/views/components/lolita/configuration/search/_display.html.haml +0 -2
- data/app/views/components/lolita/shared/_save_button.html.erb +0 -6
- data/lib/generators/lolita/assets_generator.rb +0 -19
- data/lib/lolita/configuration/factory.rb +0 -56
- data/lib/lolita/configuration/helper.rb +0 -24
- data/lib/lolita/configuration/page.rb +0 -126
- data/lib/lolita/configuration/search.rb +0 -91
- data/lib/lolita/controller_additions.rb +0 -15
- data/lib/lolita/controllers/authorization_helpers.rb +0 -56
- data/lib/lolita/search/simple.rb +0 -76
- data/public/javascripts/jquery-1.6.min.js +0 -16
- data/public/javascripts/rails.js +0 -137
- data/spec/configuration/search_spec.rb +0 -44
- data/spec/search/simple_spec.rb +0 -48
@@ -3,7 +3,7 @@
|
|
3
3
|
<% if lolita_current_user %>
|
4
4
|
<nav>
|
5
5
|
<a href="<%=send(:"edit_#{lolita_current_user.class.to_s.downcase}_password_path")%>" class="username"><%=lolita_current_user.email%></a>
|
6
|
-
|
6
|
+
<a href="<%=send(:"destroy_#{lolita_current_user.class.to_s.downcase}_session_path")%>" class="button grey"><%=::I18n.t("lolita.shared.log_out")%></a>
|
7
7
|
</nav>
|
8
8
|
<% end %>
|
9
9
|
</header>
|
@@ -4,6 +4,11 @@
|
|
4
4
|
<h1><%= t "lolita.tabs.save" %></h1>
|
5
5
|
<div class="arrow"></div>
|
6
6
|
</div>
|
7
|
-
|
7
|
+
<div class="save black">
|
8
|
+
<div class="last-save">
|
9
|
+
<%= resource.updated_at.strftime("#{t("lolita.tabs.last_save")}: %m/%d/%Y %H:%M ") if resource.respond_to?(:updated_at) && resource.updated_at %>
|
10
|
+
</div>
|
11
|
+
<button class="save-all"><%=::I18n.t("lolita.tabs.save")%></button>
|
12
|
+
</div>
|
8
13
|
</div>
|
9
14
|
</div>
|
@@ -15,16 +15,16 @@
|
|
15
15
|
<%= stylesheet_link_tag "lolita/default","lolita/style" %>
|
16
16
|
<%= yield :style %>
|
17
17
|
|
18
|
-
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"></script>
|
18
|
+
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
|
19
19
|
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/jquery-ui.min.js"></script>
|
20
20
|
<script>
|
21
21
|
if(!window.jQuery){
|
22
|
-
document.write('<script src="/javascripts/jquery-1.6.min.js">\x3C/script>');
|
22
|
+
document.write('<script src="/javascripts/jquery-1.6.2.min.js">\x3C/script>');
|
23
23
|
document.write('<script src="/javascripts/jquery-ui-1.8.13.min.js">\x3C/script>');
|
24
24
|
}
|
25
25
|
</script>
|
26
26
|
<%= javascript_include_tag "modernizr-1.7.min" %>
|
27
|
-
<%= javascript_include_tag "
|
27
|
+
<%= javascript_include_tag "lolita/tab","lolita/main","lolita/application", "lolita/base64" %>
|
28
28
|
<%= yield :script %>
|
29
29
|
<%= raw csrf_meta_tag %>
|
30
30
|
</head>
|
data/config/locales/en.yml
CHANGED
@@ -23,7 +23,30 @@ en:
|
|
23
23
|
filter:
|
24
24
|
apply_button: Apply
|
25
25
|
include_blank_by_title: " -- Filter by %{title} -- "
|
26
|
-
|
26
|
+
lolita:
|
27
|
+
shared:
|
28
|
+
save_notice: Successfully saved.
|
29
|
+
save_alert: Save did not succeed.
|
30
|
+
log_out: Sign out
|
31
|
+
edit: Edit
|
32
|
+
delete: Delete
|
33
|
+
and: and
|
34
|
+
powered: Powered Lolita (2010-%{year})
|
35
|
+
nested_form:
|
36
|
+
add: "Add %{resource_name}"
|
37
|
+
tabs:
|
38
|
+
last_save: Last save
|
39
|
+
save: Save
|
40
|
+
save_all: Save all
|
41
|
+
titles:
|
42
|
+
default: "Default"
|
43
|
+
content: "Content"
|
44
|
+
list:
|
45
|
+
add_new: Add new %{name}
|
46
|
+
confirm: "Are you sure you want to delete record?"
|
47
|
+
filter:
|
48
|
+
apply_button: Apply
|
49
|
+
include_blank_by_title: " -- Filter by %{title} -- "
|
27
50
|
views:
|
28
51
|
pagination:
|
29
52
|
previous: "« Previous"
|
data/config/locales/lv.yml
CHANGED
data/config/routes.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
Rails.application.routes.draw do
|
2
2
|
match '/lolita' => "lolita/info#index"
|
3
3
|
match '/lolita/info/properties' => "lolita/info#properties"
|
4
|
-
|
5
|
-
match "/lolita/autocomplete_field/:field_class/:field_name" => "lolita/field_data#autocomplete_field", :as => "autocomplete_field"
|
6
|
-
end
|
4
|
+
end
|
@@ -5,17 +5,13 @@ module Lolita
|
|
5
5
|
class InstallGenerator < Rails::Generators::Base
|
6
6
|
include Lolita::Generators::FileHelper
|
7
7
|
source_root File.expand_path("../../templates", __FILE__)
|
8
|
-
desc "Create lolita initializer.
|
8
|
+
desc "Create lolita initializer."
|
9
9
|
|
10
10
|
|
11
11
|
def copy_initializer
|
12
12
|
template "lolita.rb", "config/initializers/lolita.rb" unless file_exists?("config/initializers/lolita.rb")
|
13
13
|
end
|
14
14
|
|
15
|
-
def copy_assets
|
16
|
-
generate("lolita:assets")
|
17
|
-
end
|
18
|
-
|
19
15
|
def install_modules
|
20
16
|
Lolita.modules.each do |module_name|
|
21
17
|
|
data/lib/lolita.rb
CHANGED
@@ -1,23 +1,30 @@
|
|
1
1
|
|
2
2
|
$:<<File.dirname(__FILE__) unless $:.include?(File.dirname(__FILE__))
|
3
3
|
LOLITA_VERSION=File.read(File.expand_path("../../VERSION",__FILE__)).gsub(/[^.\w]/,"")
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
puts "=> Lolita #{LOLITA_VERSION} starting#{defined?(Rails) ? " with Rails" : ""}"
|
5
|
+
|
6
|
+
# TODO should allow run lolita seperated
|
7
|
+
# unless (["-d","--debug"] & ARGV).empty?
|
8
|
+
# require "ruby-debug"
|
9
|
+
# Debugger.settings[:autoeval]=true
|
10
|
+
# else
|
11
|
+
# unless self.respond_to?(:debugger)
|
12
|
+
# def debugger
|
13
|
+
# warn "Debugger called at #{caller.first} was ignored, run lolita with -d to attatch debugger."
|
14
|
+
# end
|
15
|
+
# end
|
16
|
+
# end
|
9
17
|
require "rubygems"
|
10
18
|
require 'abstract'
|
11
|
-
|
12
|
-
require '
|
13
|
-
|
14
|
-
require 'active_support/core_ext/
|
15
|
-
require 'active_support/
|
16
|
-
require 'active_support/
|
17
|
-
require 'active_support/
|
18
|
-
require 'active_support/
|
19
|
-
|
20
|
-
|
19
|
+
require "base64"
|
20
|
+
require 'kaminari'
|
21
|
+
unless defined?(ActiveSupport)
|
22
|
+
require 'active_support/core_ext/numeric/time'
|
23
|
+
require 'active_support/core_ext/date_time/conversions'
|
24
|
+
require 'active_support/concern'
|
25
|
+
require 'active_support/callbacks'
|
26
|
+
require 'active_support/dependencies'
|
27
|
+
end
|
21
28
|
require 'lolita/errors'
|
22
29
|
require "lolita/hooks"
|
23
30
|
# Require all ruby extensions
|
@@ -33,7 +40,6 @@ module Lolita
|
|
33
40
|
autoload(:VERSION,'lolita/version')
|
34
41
|
autoload(:ObservedArray,'lolita/observed_array')
|
35
42
|
autoload(:Builder,'lolita/builder')
|
36
|
-
autoload(:ControllerAdditions,'lolita/controller_additions')
|
37
43
|
module Builder
|
38
44
|
autoload(:Custom, 'lolita/builder')
|
39
45
|
end
|
@@ -60,7 +66,6 @@ module Lolita
|
|
60
66
|
|
61
67
|
# Keep all configuration classes and modules, that is used to configure classes with lolita.
|
62
68
|
module Configuration
|
63
|
-
|
64
69
|
autoload :Base, 'lolita/configuration/base'
|
65
70
|
autoload :Column, 'lolita/configuration/column'
|
66
71
|
autoload :Columns, 'lolita/configuration/columns'
|
@@ -70,7 +75,6 @@ module Lolita
|
|
70
75
|
autoload :Tabs, 'lolita/configuration/tabs'
|
71
76
|
autoload :Filter, 'lolita/configuration/filter'
|
72
77
|
autoload :NestedForm, 'lolita/configuration/nested_form'
|
73
|
-
autoload :Search, 'lolita/configuration/search'
|
74
78
|
|
75
79
|
# Module contains classes that is used to create specific type class based on given arguments.
|
76
80
|
module Factory
|
@@ -99,9 +103,6 @@ module Lolita
|
|
99
103
|
|
100
104
|
def self.included(base)
|
101
105
|
base.class_eval do
|
102
|
-
include Lolita::Hooks
|
103
|
-
add_hook :after_lolita_loaded
|
104
|
-
|
105
106
|
extend ClassMethods
|
106
107
|
def lolita
|
107
108
|
self.class.lolita
|
@@ -113,7 +114,6 @@ module Lolita
|
|
113
114
|
def lolita(&block)
|
114
115
|
Lolita::LazyLoader.lazy_load(self,:@lolita,Lolita::Configuration::Base,self,&block)
|
115
116
|
end
|
116
|
-
|
117
117
|
def lolita=(value)
|
118
118
|
if value.is_a?(Lolita::Configuration::Base)
|
119
119
|
@lolita=value
|
@@ -133,7 +133,7 @@ module Lolita
|
|
133
133
|
autoload :UserHelpers, 'lolita/controllers/user_helpers'
|
134
134
|
autoload :UrlHelpers, 'lolita/controllers/url_helpers'
|
135
135
|
autoload :ComponentHelpers, 'lolita/controllers/component_helpers'
|
136
|
-
autoload :
|
136
|
+
autoload :ViewUserHelpers, 'lolita/controllers/view_user_helpers'
|
137
137
|
end
|
138
138
|
|
139
139
|
module Navigation
|
@@ -148,10 +148,6 @@ module Lolita
|
|
148
148
|
end
|
149
149
|
end
|
150
150
|
|
151
|
-
module Search
|
152
|
-
autoload :Simple, 'lolita/search/simple'
|
153
|
-
end
|
154
|
-
|
155
151
|
@@scopes={}
|
156
152
|
|
157
153
|
def self.scope name=nil
|
@@ -179,13 +175,6 @@ module Lolita
|
|
179
175
|
end
|
180
176
|
|
181
177
|
def self.method_missing method_name, *args, &block
|
182
|
-
self.class_eval <<-LOLITA_SETUP,__FILE__,__LINE__+1
|
183
|
-
class << self
|
184
|
-
def #{method_name}(*args,&block)
|
185
|
-
scope.send(:#{method_name},*args,&block)
|
186
|
-
end
|
187
|
-
end
|
188
|
-
LOLITA_SETUP
|
189
178
|
scope.send(method_name,*args,&block)
|
190
179
|
end
|
191
180
|
|
@@ -200,9 +189,5 @@ module Lolita
|
|
200
189
|
end
|
201
190
|
|
202
191
|
if Lolita.rails3?
|
203
|
-
require "base64"
|
204
|
-
require 'kaminari'
|
205
|
-
# require 'tinymce-rails'
|
206
|
-
# require 'jquery-rails'
|
207
192
|
require 'lolita/rails/all'
|
208
193
|
end
|
@@ -8,7 +8,6 @@ module Lolita
|
|
8
8
|
abstract_method 'method_name,page,per,options', :pagination_scope_from_klass
|
9
9
|
abstract_method 'name',:reflect_on_association,:field_by_name,:field_by_association
|
10
10
|
abstract_method 'id',:find_by_id
|
11
|
-
abstract_method 'query', :search
|
12
11
|
end
|
13
12
|
end
|
14
13
|
end
|
@@ -24,26 +24,15 @@ module Lolita
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def key
|
27
|
-
|
28
|
-
@association.primary_key_name
|
29
|
-
else
|
30
|
-
@association.association_foreign_key
|
31
|
-
end
|
27
|
+
@association.association_foreign_key
|
32
28
|
end
|
33
29
|
|
34
30
|
def polymorphic?
|
35
31
|
@association.options[:polymorphic]
|
36
32
|
end
|
37
33
|
|
38
|
-
def native_macro
|
39
|
-
@association.macro
|
40
|
-
end
|
41
|
-
|
42
34
|
def macro
|
43
|
-
convertator = {
|
44
|
-
:has_many => :many, :has_one => :one, :belongs_to => :one,
|
45
|
-
:has_and_belongs_to_many => :many_to_many
|
46
|
-
}
|
35
|
+
convertator = {:has_many => :many, :has_one => :one, :belongs_to => :one, :has_and_belongs_to_many => :many}
|
47
36
|
convertator[@association.macro]
|
48
37
|
end
|
49
38
|
end
|
@@ -88,15 +77,11 @@ module Lolita
|
|
88
77
|
end
|
89
78
|
|
90
79
|
def association
|
91
|
-
|
80
|
+
unless @association
|
92
81
|
possible_association = @adapter.associations.detect{|name,association|
|
93
82
|
[association.key.to_s].include?(@name.to_s)
|
94
83
|
}
|
95
|
-
@association = if possible_association
|
96
|
-
possible_association.last
|
97
|
-
else
|
98
|
-
false
|
99
|
-
end
|
84
|
+
@association = possible_association.last if possible_association
|
100
85
|
end
|
101
86
|
@association
|
102
87
|
end
|
@@ -200,29 +185,6 @@ module Lolita
|
|
200
185
|
end
|
201
186
|
end
|
202
187
|
|
203
|
-
def search(query, options = {})
|
204
|
-
#TODO raise error or warn when there are lot of records and no index on field
|
205
|
-
unless query.blank?
|
206
|
-
resources = self.klass.arel_table
|
207
|
-
content_fields = @dbi.fields.map{|field| field.type!="string" ? nil : field.name.to_sym}.compact
|
208
|
-
if options[:fields] && options[:fields].any?
|
209
|
-
content_fields = content_fields & options[:fields]
|
210
|
-
end
|
211
|
-
scope = nil
|
212
|
-
content_fields.each_with_index do |field,index|
|
213
|
-
new_scope = resources[field].matches("%#{query}%")
|
214
|
-
unless index == 0
|
215
|
-
scope = scope.or(new_scope)
|
216
|
-
else
|
217
|
-
scope = new_scope
|
218
|
-
end
|
219
|
-
end
|
220
|
-
self.klass.where(scope)
|
221
|
-
else
|
222
|
-
self.klass.where(nil)
|
223
|
-
end
|
224
|
-
end
|
225
|
-
|
226
188
|
def db
|
227
189
|
self.klass.connection
|
228
190
|
end
|
@@ -24,17 +24,13 @@ module Lolita
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def key
|
27
|
-
@association.
|
28
|
-
end
|
29
|
-
|
30
|
-
def native_macro
|
31
|
-
@association.macro
|
27
|
+
@association.key
|
32
28
|
end
|
33
29
|
|
34
30
|
def macro
|
35
31
|
convertator = {
|
36
32
|
:references_many => :many, :references_one => :one, :referenced_in => :one,
|
37
|
-
:references_and_referenced_in_many => :
|
33
|
+
:references_and_referenced_in_many => :many, :embeds_one => :one, :embeds_many => :many
|
38
34
|
}
|
39
35
|
convertator[@association.macro]
|
40
36
|
end
|
@@ -80,15 +76,11 @@ module Lolita
|
|
80
76
|
end
|
81
77
|
|
82
78
|
def association
|
83
|
-
|
79
|
+
unless @association
|
84
80
|
possible_association = @adapter.associations.detect{|name,association|
|
85
81
|
[association.key.to_s].include?(@name.to_s)
|
86
82
|
}
|
87
|
-
@association = if possible_association
|
88
|
-
possible_association.last
|
89
|
-
else
|
90
|
-
false
|
91
|
-
end
|
83
|
+
@association = possible_association.last if possible_association
|
92
84
|
end
|
93
85
|
@association
|
94
86
|
end
|
@@ -184,70 +176,6 @@ module Lolita
|
|
184
176
|
end
|
185
177
|
end
|
186
178
|
|
187
|
-
def search(query, options = {})
|
188
|
-
unless query.blank?
|
189
|
-
content_fields = @dbi.fields.map{|field|
|
190
|
-
if field.type!="string" || field.name.match(/^_/)
|
191
|
-
nil
|
192
|
-
else
|
193
|
-
field.name.to_sym
|
194
|
-
end
|
195
|
-
}.compact
|
196
|
-
if options[:fields] && options[:fields].any?
|
197
|
-
content_fields = content_fields & options[:fields]
|
198
|
-
end
|
199
|
-
content_fields = content_fields.slice(0..3)
|
200
|
-
#result = self.map_reduce_search(content_fields,query)
|
201
|
-
#debugger
|
202
|
-
#result
|
203
|
-
where_hash = {}
|
204
|
-
content_fields.each do |field|
|
205
|
-
where_hash[field] = /#{Regexp.escape(query.to_s)}/
|
206
|
-
end
|
207
|
-
klass.where(where_hash)
|
208
|
-
else
|
209
|
-
klass.where(nil)
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
#FIXME
|
214
|
-
def map_reduce_search(content_fields,query)
|
215
|
-
keys = "[" + @dbi.fields.map{|f|
|
216
|
-
f.primary? || f.name.to_s.match(/^_/) ? nil : "'#{f.name}'"
|
217
|
-
}.compact.join(",").to_s + "]"
|
218
|
-
content_keys = "[" + content_fields.map{|f| "'#{f.name}'"}.join(",").to_s + "]"
|
219
|
-
result_obj = @dbi.fields.map{|f|
|
220
|
-
f.name.to_s.match(/^_/) ? nil : "'#{f.name}': false"
|
221
|
-
}.compact.join(",")
|
222
|
-
result_obj = "{#{result_obj}}"
|
223
|
-
map = %^
|
224
|
-
function(){
|
225
|
-
var doc = #{result_obj};
|
226
|
-
var do_emit = false;
|
227
|
-
for(var k in #{content_keys}){
|
228
|
-
var c_val = this[k];
|
229
|
-
if(c_val && c_val.match(/#{Regexp.escape(query)}/i)){
|
230
|
-
do_emit = true;
|
231
|
-
break;
|
232
|
-
};
|
233
|
-
};
|
234
|
-
if(true){
|
235
|
-
#{keys}.forEach(function(k){
|
236
|
-
doc[k] = this.name;
|
237
|
-
})
|
238
|
-
emit(this.id,doc);
|
239
|
-
};
|
240
|
-
};
|
241
|
-
^
|
242
|
-
reduce = %^
|
243
|
-
function(key,values){
|
244
|
-
|
245
|
-
return values[values.length-1];
|
246
|
-
};
|
247
|
-
^
|
248
|
-
self.collection.map_reduce(map,reduce, {:out => "custom_mr", :query => {}})
|
249
|
-
end
|
250
|
-
|
251
179
|
def db
|
252
180
|
self.klass.db
|
253
181
|
end
|
@@ -15,11 +15,9 @@ module Lolita
|
|
15
15
|
|
16
16
|
attr_reader :dbi,:klass
|
17
17
|
@@generators=[:tabs,:list]
|
18
|
-
|
19
18
|
class << self
|
20
|
-
|
21
19
|
def add_generator(method)
|
22
|
-
@@generators<<method.to_sym
|
20
|
+
@@generators<<method.to_sym
|
23
21
|
end
|
24
22
|
end
|
25
23
|
# When configuration is defined in class than you don't need to worry about
|
@@ -40,7 +38,6 @@ module Lolita
|
|
40
38
|
# Person.lolita=Lolita::Configuration::Base.new(Person)
|
41
39
|
# Person.lolita.klass #=> Person
|
42
40
|
def initialize(orm_class,&block)
|
43
|
-
@in_callback_mode = false
|
44
41
|
@klass=orm_class
|
45
42
|
@dbi=Lolita::DBI::Base.create(orm_class)
|
46
43
|
block_given? ? self.instance_eval(&block) : self.generate!
|
@@ -53,10 +50,6 @@ module Lolita
|
|
53
50
|
Lolita::LazyLoader.lazy_load(self,:@list,Lolita::Configuration::List,@dbi,&block)
|
54
51
|
end
|
55
52
|
|
56
|
-
def list=(new_list)
|
57
|
-
@list = new_list if new_list.is_a?(Lolita::Configuration::List)
|
58
|
-
end
|
59
|
-
|
60
53
|
# Create collection of Lolita::Configuration::Tab, loading lazy.
|
61
54
|
# See Lolita::Configuration::Tabs for details.
|
62
55
|
def tabs &block
|
@@ -76,13 +69,7 @@ module Lolita
|
|
76
69
|
self.send(generator)
|
77
70
|
}
|
78
71
|
end
|
79
|
-
|
80
|
-
private
|
81
|
-
|
82
|
-
def after_initialize
|
83
|
-
@dbi.klass.run(:after_lolita_loaded, :once => self)
|
84
|
-
end
|
85
|
-
|
72
|
+
|
86
73
|
end
|
87
74
|
end
|
88
75
|
end
|