rademade_admin 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/fonts/glyphicons-halflings-regular.eot +0 -0
- data/app/assets/fonts/glyphicons-halflings-regular.svg +229 -0
- data/app/assets/fonts/glyphicons-halflings-regular.ttf +0 -0
- data/app/assets/fonts/glyphicons-halflings-regular.woff +0 -0
- data/app/assets/images/rademade_admin/ico/btn-attach.png +0 -0
- data/app/assets/images/rademade_admin/logos/logo.png +0 -0
- data/app/assets/javascripts/rademade_admin.coffee +8 -4
- data/app/assets/javascripts/rademade_admin/app/app.coffee +2 -1
- data/app/assets/javascripts/rademade_admin/app/common/datetime-picker.coffee +7 -0
- data/app/assets/javascripts/rademade_admin/app/common/dnd-sort.coffee +23 -32
- data/app/assets/javascripts/rademade_admin/app/common/droplist.coffee +8 -0
- data/app/assets/javascripts/rademade_admin/app/common/lang-panel.coffee +6 -0
- data/app/assets/javascripts/rademade_admin/app/common/related-index.coffee +6 -9
- data/app/assets/javascripts/rademade_admin/app/common/sort-list.coffee +10 -14
- data/app/assets/javascripts/rademade_admin/app/common/uploader.coffee +3 -3
- data/app/assets/javascripts/rademade_admin/app/form-popup/initializer.coffee +24 -37
- data/app/assets/javascripts/rademade_admin/app/form-popup/view.coffee +32 -18
- data/app/assets/javascripts/rademade_admin/app/forms/remove.coffee +4 -3
- data/app/assets/javascripts/rademade_admin/app/select2/model.coffee +7 -0
- data/app/assets/javascripts/rademade_admin/app/select2/related/collection-view.coffee +35 -0
- data/app/assets/javascripts/rademade_admin/app/select2/related/collection.coffee +28 -0
- data/app/assets/javascripts/rademade_admin/app/select2/related/model.coffee +15 -0
- data/app/assets/javascripts/rademade_admin/app/select2/related/view.coffee +40 -0
- data/app/assets/javascripts/rademade_admin/app/select2/view.coffee +78 -0
- data/app/assets/javascripts/rademade_admin/form/form-ajax.coffee +48 -0
- data/app/assets/javascripts/rademade_admin/form/form-initializater.coffee +45 -0
- data/app/assets/javascripts/rademade_admin/form/form-validation.coffee +42 -0
- data/app/assets/javascripts/rademade_admin/form/form.coffee +62 -0
- data/app/assets/javascripts/rademade_admin/library/ckeditor/config.js +14 -12
- data/app/assets/stylesheets/{rademade_admin/bootstrap → old/-bootstrap}/bootstrap-overrides.css.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin/bootstrap → old/-bootstrap}/main.scss.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/chart-showcase.scss.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/datatables.scss.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/elements.scss.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/error.scss.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/form-showcase.scss.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/form-wizard.scss.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/gallery.scss.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/grids.scss.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/icons.scss.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/index.scss.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/layout.scss.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/new-user.scss.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/personal-info.scss.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/popup.scss.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/signin.scss.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/tables.scss.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/ui-elements.scss.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/user-list.scss.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/user-profile.scss.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/web-app-icons.scss.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin/lib → old/-lib}/bootstrap.datepicker.css.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin/lib → old/-lib}/morris.css.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin → old}/base.scss.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin → old}/edit.css +0 -0
- data/app/assets/stylesheets/{rademade_admin → old}/file-upload.scss.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin → old}/notifier.custom.css.erb +0 -0
- data/app/assets/stylesheets/{rademade_admin → old}/scaffolds.scss.erb +0 -0
- data/app/assets/stylesheets/rademade_admin.sass.erb +96 -0
- data/app/assets/stylesheets/rademade_admin/base/main.sass +71 -0
- data/app/assets/stylesheets/rademade_admin/blocks/buttons/main.sass +81 -0
- data/app/assets/stylesheets/rademade_admin/blocks/form/input.sass +29 -0
- data/app/assets/stylesheets/rademade_admin/blocks/form/label.sass +31 -0
- data/app/assets/stylesheets/rademade_admin/blocks/form/select.sass +26 -0
- data/app/assets/stylesheets/rademade_admin/blocks/form/select2.sass +67 -0
- data/app/assets/stylesheets/rademade_admin/blocks/form/table.sass +42 -0
- data/app/assets/stylesheets/rademade_admin/blocks/form/texarea.sass +20 -0
- data/app/assets/stylesheets/rademade_admin/blocks/header/_logo.sass +7 -0
- data/app/assets/stylesheets/rademade_admin/blocks/header/_menu.sass +80 -0
- data/app/assets/stylesheets/rademade_admin/blocks/header/_search.sass +37 -0
- data/app/assets/stylesheets/rademade_admin/blocks/page/content/_main.sass +11 -0
- data/app/assets/stylesheets/rademade_admin/blocks/page/headline/main.sass +44 -0
- data/app/assets/stylesheets/rademade_admin/blocks/page/menu/_main.sass +31 -0
- data/app/assets/stylesheets/rademade_admin/lib/datepicker.sass +373 -0
- data/app/assets/stylesheets/rademade_admin/lib/glyphicon.sass.erb +618 -0
- data/app/assets/stylesheets/rademade_admin/lib/notifier.css.erb +661 -0
- data/app/assets/stylesheets/rademade_admin/lib/uploader.sass +66 -0
- data/app/assets/stylesheets/rademade_admin/mixins/clear.sass +5 -0
- data/app/assets/stylesheets/rademade_admin/mixins/fonts.sass +8 -0
- data/app/assets/stylesheets/rademade_admin/mixins/sprite.sass +7 -0
- data/app/assets/stylesheets/rademade_admin/mixins/text-overflow.sass +6 -0
- data/app/assets/stylesheets/rademade_admin/mixins/user-select.sass +5 -0
- data/app/assets/stylesheets/rademade_admin/modules/breadcrumbs/main.sass +30 -0
- data/app/assets/stylesheets/rademade_admin/modules/errors/error.sass.erb +19 -0
- data/app/assets/stylesheets/rademade_admin/modules/form/main.sass +15 -0
- data/app/assets/stylesheets/rademade_admin/modules/header/main.sass +6 -0
- data/app/assets/stylesheets/rademade_admin/modules/login/_main.sass +79 -0
- data/app/assets/stylesheets/rademade_admin/modules/main-menu/main.sass +0 -0
- data/app/assets/stylesheets/rademade_admin/modules/page/main.sass +16 -0
- data/app/assets/stylesheets/rademade_admin/modules/pagination/main.sass +51 -0
- data/app/assets/stylesheets/rademade_admin/modules/popup/new.sass +18 -0
- data/app/assets/stylesheets/rademade_admin/var/colors.sass +0 -0
- data/app/assets/stylesheets/rademade_admin/var/images.sass +2 -0
- data/app/assets/stylesheets/rademade_admin/var/width.sass +13 -0
- data/app/controllers/rademade_admin/abstract_controller.rb +18 -2
- data/app/controllers/rademade_admin/application_controller.rb +1 -1
- data/app/controllers/rademade_admin/dashboard_controller.rb +1 -1
- data/app/controllers/rademade_admin/file_controller.rb +25 -0
- data/app/controllers/rademade_admin/model_controller.rb +66 -47
- data/app/controllers/rademade_admin/sessions_controller.rb +3 -3
- data/app/helpers/rademade_admin/field_helper.rb +21 -32
- data/app/helpers/rademade_admin/form_helper.rb +57 -27
- data/app/helpers/rademade_admin/menu_helper.rb +12 -5
- data/app/helpers/rademade_admin/uri_helper.rb +50 -62
- data/app/inputs/rademade_admin/date_time_input.rb +13 -0
- data/app/inputs/rademade_admin/file_input.rb +72 -0
- data/app/inputs/rademade_admin/related_select_input.rb +78 -0
- data/app/serializers/autocomplete/link_serializer.rb +6 -4
- data/app/services/linker.rb +8 -14
- data/app/services/login.rb +5 -3
- data/app/services/model_controller/breadcrumbs.rb +36 -0
- data/app/services/model_controller/instance_options.rb +7 -5
- data/app/services/model_controller/model_options.rb +10 -7
- data/app/services/model_controller/notifier.rb +10 -6
- data/app/services/model_controller/templates.rb +4 -3
- data/app/services/relation_service.rb +11 -0
- data/app/services/saver.rb +59 -24
- data/app/services/search/conditions/abstract.rb +15 -14
- data/app/services/search/conditions/autocomplete.rb +11 -9
- data/app/services/search/conditions/list.rb +6 -5
- data/app/services/search/conditions/related_list.rb +17 -13
- data/app/services/search/{conditions/part/where.rb → part/abstract.rb} +7 -9
- data/app/services/search/part/order.rb +17 -0
- data/app/services/search/part/where.rb +19 -0
- data/app/services/sortable_service.rb +27 -27
- data/app/services/template_service.rb +68 -0
- data/app/services/upload/preview_service.rb +86 -0
- data/app/views/layouts/rademade_admin.html.erb +13 -4
- data/app/views/rademade_admin/_blocks/_header.html.erb +35 -28
- data/app/views/rademade_admin/_blocks/_menu.html.erb +20 -23
- data/app/views/rademade_admin/_blocks/_on_page_select.html.erb +15 -0
- data/app/views/rademade_admin/_blocks/_pagination.html.erb +1 -18
- data/app/views/rademade_admin/_blocks/_sub_menu.html.erb +3 -3
- data/app/views/rademade_admin/_blocks/form/_control.html.erb +3 -0
- data/app/views/rademade_admin/_blocks/form/_lang_panel.html.erb +19 -0
- data/app/views/rademade_admin/_blocks/sub_menu/_link.html.erb +6 -5
- data/app/views/rademade_admin/_blocks/table/_head.html.erb +13 -0
- data/app/views/rademade_admin/_layouts/inner.html.erb +21 -33
- data/app/views/rademade_admin/_layouts/inner/form.html.erb +6 -13
- data/app/views/rademade_admin/_layouts/inner/index_table.html.erb +31 -55
- data/app/views/rademade_admin/_layouts/inner/related_index_table.html.erb +26 -54
- data/app/views/rademade_admin/abstract/_form.html.erb +6 -9
- data/app/views/rademade_admin/abstract/edit.html.erb +3 -8
- data/app/views/rademade_admin/abstract/index.html.erb +38 -67
- data/app/views/rademade_admin/abstract/new.html.erb +3 -8
- data/app/views/rademade_admin/abstract/related.html.erb +48 -0
- data/app/views/rademade_admin/dashboard/index.html.erb +4 -5
- data/app/views/rademade_admin/dashboard/login.html.erb +19 -30
- data/config/initializers/carrier_wave/mongoid.rb +48 -0
- data/config/initializers/ckeditor.rb +3 -0
- data/config/initializers/kaminari_route_proxy.rb +16 -0
- data/config/initializers/simple_form.rb +147 -0
- data/config/initializers/simple_form/rademade_component.rb +9 -0
- data/config/initializers/simple_form/wrappers.rb +28 -0
- data/config/locales/rademade_admin.en.yml +28 -0
- data/config/locales/simple_form.en.yml +26 -0
- data/config/routes.rb +1 -2
- data/lib/rademade_admin.rb +7 -5
- data/lib/rademade_admin/bower/performer.rb +1 -1
- data/lib/rademade_admin/breadcrumbs/render/rademade.rb +31 -0
- data/lib/rademade_admin/engine.rb +2 -2
- data/lib/rademade_admin/input/related_select_input/model_data.rb +40 -0
- data/lib/rademade_admin/input/related_select_input/related_list.rb +60 -0
- data/lib/rademade_admin/model/adapter/data.rb +119 -0
- data/lib/rademade_admin/model/adapter/data/active_record.rb +109 -0
- data/lib/rademade_admin/model/adapter/data/mongoid.rb +77 -0
- data/{app/services/search/query_adapter/abstract.rb → lib/rademade_admin/model/adapter/query.rb} +15 -5
- data/lib/rademade_admin/model/adapter/query/active_record.rb +50 -0
- data/lib/rademade_admin/model/adapter/query/mongoid.rb +57 -0
- data/lib/rademade_admin/model/configuration.rb +43 -16
- data/lib/rademade_admin/model/configuration/field_label.rb +16 -0
- data/lib/rademade_admin/model/configuration/fields.rb +47 -21
- data/lib/rademade_admin/model/configuration/fields_labels.rb +31 -0
- data/lib/rademade_admin/model/configuration/form_field.rb +27 -0
- data/lib/rademade_admin/model/configuration/form_fields.rb +18 -0
- data/lib/rademade_admin/model/configuration/list_field.rb +21 -0
- data/lib/rademade_admin/model/configuration/list_fields.rb +18 -0
- data/lib/rademade_admin/model/graph.rb +9 -9
- data/lib/rademade_admin/model/info.rb +53 -68
- data/lib/rademade_admin/model/info/data_item.rb +130 -0
- data/lib/rademade_admin/model/info/data_items.rb +130 -0
- data/lib/rademade_admin/model/info/field.rb +39 -0
- data/lib/rademade_admin/model/info/fields.rb +87 -0
- data/lib/rademade_admin/model/info/relation.rb +49 -0
- data/lib/rademade_admin/model/info/relations.rb +40 -0
- data/lib/rademade_admin/model/info/uploader.rb +16 -0
- data/lib/rademade_admin/model/info/uploaders.rb +35 -0
- data/lib/rademade_admin/model/reflection.rb +38 -9
- data/lib/rademade_admin/routing/mapper.rb +9 -5
- data/lib/rademade_admin/search/searcher.rb +22 -0
- data/lib/rademade_admin/sortable.rb +1 -0
- data/lib/rademade_admin/uploader/photo.rb +1 -0
- data/lib/rademade_admin/user.rb +7 -6
- data/lib/rademade_admin/version.rb +1 -1
- data/lib/tasks/rademade_bower_install.rake +10 -2
- data/lib/templates/erb/scaffold/_form.html.erb +13 -0
- metadata +195 -109
- data/app/assets/javascripts/rademade_admin/app/common/relation-list.coffee +0 -109
- data/app/assets/javascripts/rademade_admin/app/form-popup/collection.coffee +0 -20
- data/app/assets/javascripts/rademade_admin/app/form-popup/model.coffee +0 -4
- data/app/assets/javascripts/rademade_admin/detail_admin/theme.js +0 -56
- data/app/assets/javascripts/rademade_admin/form/form-ajax-submit.coffee +0 -157
- data/app/assets/stylesheets/rademade_admin.scss.erb +0 -19
- data/app/helpers/rademade_admin/name_helper.rb +0 -18
- data/app/helpers/rademade_admin/upload_preview_helper.rb +0 -60
- data/app/inputs/rademade_admin/admin_file_input.rb +0 -71
- data/app/inputs/rademade_admin/admin_select_input.rb +0 -82
- data/app/inputs/rademade_admin/admin_textarea_input.rb +0 -6
- data/app/inputs/rademade_admin/boolean_input.rb +0 -14
- data/app/services/form_builder.rb +0 -4
- data/app/services/search/query_adapter/active_record.rb +0 -45
- data/app/services/search/query_adapter/mongoid.rb +0 -51
- data/app/services/search/searcher.rb +0 -20
- data/app/views/rademade_admin/_blocks/_form_control.html.erb +0 -5
- data/app/views/rademade_admin/abstract/related_index.html.erb +0 -85
- data/config/initializers/devise.rb +0 -251
- data/config/initializers/formtastic.rb +0 -13
- data/lib/rademade_admin/model/data_adapter.rb +0 -64
- data/lib/rademade_admin/model/data_adapter/active_record.rb +0 -59
- data/lib/rademade_admin/model/data_adapter/mongoid.rb +0 -54
- data/lib/rademade_admin/model/reflection/data.rb +0 -48
- data/lib/rademade_admin/model/reflection/uploader.rb +0 -18
@@ -0,0 +1,77 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module RademadeAdmin
|
3
|
+
module Model
|
4
|
+
module Adapter
|
5
|
+
class Data
|
6
|
+
|
7
|
+
#
|
8
|
+
# Data adapter for Mongoid
|
9
|
+
#
|
10
|
+
class Mongoid < RademadeAdmin::Model::Adapter::Data
|
11
|
+
|
12
|
+
protected
|
13
|
+
|
14
|
+
def has_many_relations
|
15
|
+
[:embeds_many, :has_many, :has_and_belongs_to_many]
|
16
|
+
end
|
17
|
+
|
18
|
+
def has_one_relations
|
19
|
+
[:has_one, :embeds_one, :belongs_to]
|
20
|
+
end
|
21
|
+
|
22
|
+
def _map_fields
|
23
|
+
fields = {}
|
24
|
+
@model.fields.each do |name, field_data|
|
25
|
+
name = name.to_sym
|
26
|
+
getter = name.to_s
|
27
|
+
fields[name] = RademadeAdmin::Model::Info::Field.new({
|
28
|
+
:name => name,
|
29
|
+
:primary => name == :_id,
|
30
|
+
:getter => getter,
|
31
|
+
:setter => getter + '=',
|
32
|
+
:type => field_data.type,
|
33
|
+
:is_date_time => field_data.type == DateTime,
|
34
|
+
:localizable => field_data.localized?,
|
35
|
+
:relation_name => field_data.options[:metadata].try(:name)
|
36
|
+
})
|
37
|
+
end
|
38
|
+
fields
|
39
|
+
end
|
40
|
+
|
41
|
+
def _map_relations
|
42
|
+
relations = {}
|
43
|
+
@model.relations.each do |name, relation_info|
|
44
|
+
name = name.to_sym
|
45
|
+
type = relation_info.relation.macro
|
46
|
+
is_sortable = relation_info.sortable?
|
47
|
+
relations[name] = ::RademadeAdmin::Model::Info::Relation.new({
|
48
|
+
:name => name,
|
49
|
+
:from => @model,
|
50
|
+
:to => to_class(relation_info),
|
51
|
+
:getter => name.to_s,
|
52
|
+
:setter => relation_info.setter,
|
53
|
+
:type => type,
|
54
|
+
:many => type == :has_many,
|
55
|
+
:has_many => has_many_relations.include?(type),
|
56
|
+
:sortable => is_sortable,
|
57
|
+
:sortable_field => is_sortable ? relation_info.sortable_field : nil,
|
58
|
+
:foreign_key => relation_info.foreign_key.to_sym
|
59
|
+
})
|
60
|
+
end
|
61
|
+
relations
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def to_class(relation_info)
|
67
|
+
RademadeAdmin::LoaderService.const_get(relation_info.class_name)
|
68
|
+
rescue
|
69
|
+
nil
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
data/{app/services/search/query_adapter/abstract.rb → lib/rademade_admin/model/adapter/query.rb}
RENAMED
@@ -1,19 +1,29 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
module RademadeAdmin
|
3
|
-
module
|
4
|
-
module
|
5
|
-
class
|
3
|
+
module Model
|
4
|
+
module Adapter
|
5
|
+
class Query
|
6
6
|
|
7
7
|
def initialize(model)
|
8
8
|
@model = model
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
12
|
-
@
|
11
|
+
def find(ids)
|
12
|
+
@model.find(ids)
|
13
|
+
end
|
14
|
+
|
15
|
+
#
|
16
|
+
# @param search_conditions [RademadeAdmin::Search::Conditions::Abstract]
|
17
|
+
#
|
18
|
+
def exec_query(search_conditions)
|
13
19
|
@result = search_conditions.base_condition(@model)
|
20
|
+
|
21
|
+
return nil if @result.nil?
|
22
|
+
|
14
23
|
search_conditions.conditions.each do |query_part, values|
|
15
24
|
@result = self.send(query_part, values) unless values.nil?
|
16
25
|
end
|
26
|
+
|
17
27
|
@result
|
18
28
|
end
|
19
29
|
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module RademadeAdmin
|
3
|
+
module Model
|
4
|
+
module Adapter
|
5
|
+
class Query
|
6
|
+
|
7
|
+
class ActiveRecord < RademadeAdmin::Model::Adapter::Query
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
def where(where_conditions)
|
12
|
+
@values = []
|
13
|
+
condition = collect_where_conditions(where_conditions)
|
14
|
+
@result.where([condition, *@values])
|
15
|
+
end
|
16
|
+
|
17
|
+
def order(order_conditions)
|
18
|
+
order_conditions.parts.each do |part|
|
19
|
+
if part.is_a? RademadeAdmin::Search::Part::Order
|
20
|
+
# todo
|
21
|
+
else
|
22
|
+
@result = @result.order(part[:field] => part[:value])
|
23
|
+
end
|
24
|
+
end
|
25
|
+
@result
|
26
|
+
end
|
27
|
+
|
28
|
+
def collect_where_conditions(where_conditions)
|
29
|
+
condition = ''
|
30
|
+
where_conditions.parts.each do |part|
|
31
|
+
condition += " #{where_conditions.type.to_s.capitalize} " unless condition.empty?
|
32
|
+
if part.is_a? RademadeAdmin::Search::Part::Where
|
33
|
+
condition += "(#{collect_where_conditions(part)})"
|
34
|
+
else
|
35
|
+
if part[:value].is_a? Array
|
36
|
+
condition += "#{part[:field]} IN (?)"
|
37
|
+
else
|
38
|
+
condition += "#{part[:field]} = ?"
|
39
|
+
end
|
40
|
+
@values << part[:value]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
condition
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module RademadeAdmin
|
3
|
+
module Model
|
4
|
+
module Adapter
|
5
|
+
class Query
|
6
|
+
|
7
|
+
class Mongoid < RademadeAdmin::Model::Adapter::Query
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
WHERE_METHOD_MAP = { :or => :or, :and => :where }.freeze
|
12
|
+
|
13
|
+
def where(where_conditions)
|
14
|
+
if defined?(::Mongoid::Paranoia) and @model.ancestors.include? ::Mongoid::Paranoia
|
15
|
+
where_condition = RademadeAdmin::Search::Part::Where.new(:and)
|
16
|
+
where_condition.add(:deleted_at, nil)
|
17
|
+
where_condition.sub_add(where_conditions) if where_conditions
|
18
|
+
where_conditions = where_condition
|
19
|
+
end
|
20
|
+
collect_where_condition(where_conditions, @result)
|
21
|
+
end
|
22
|
+
|
23
|
+
def order(order_conditions)
|
24
|
+
order_conditions.parts.each do |part|
|
25
|
+
if part.is_a? RademadeAdmin::Search::Part::Order
|
26
|
+
# todo
|
27
|
+
else
|
28
|
+
@result = @result.order_by(part[:field] => part[:value])
|
29
|
+
end
|
30
|
+
end
|
31
|
+
@result
|
32
|
+
end
|
33
|
+
|
34
|
+
def collect_where_condition(where_conditions, result)
|
35
|
+
where_method = WHERE_METHOD_MAP[where_conditions.type]
|
36
|
+
where_conditions.parts.each do |part|
|
37
|
+
if part.is_a? RademadeAdmin::Search::Part::Where
|
38
|
+
result = result.send(where_method, where_sub_condition(part))
|
39
|
+
else
|
40
|
+
field = part[:field]
|
41
|
+
field = field.in if part[:value].is_a? Array
|
42
|
+
result = result.send(where_method, field => part[:value])
|
43
|
+
end
|
44
|
+
end
|
45
|
+
result
|
46
|
+
end
|
47
|
+
|
48
|
+
def where_sub_condition(where_sub_conditions)
|
49
|
+
collect_where_condition(where_sub_conditions, @model.all).selector
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -3,31 +3,59 @@ module RademadeAdmin
|
|
3
3
|
module Model
|
4
4
|
class Configuration
|
5
5
|
|
6
|
-
attr_reader :
|
6
|
+
attr_reader :controller, :parent_menu_item, :model_name
|
7
7
|
|
8
|
-
def initialize(
|
9
|
-
@
|
8
|
+
def initialize(controller)
|
9
|
+
@controller = controller
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
13
|
-
@
|
12
|
+
def item_name
|
13
|
+
@item_name ||= singular_name.pluralize
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
17
|
-
@
|
16
|
+
def singular_name
|
17
|
+
@singular_name ||= model_name.underscore.gsub('/', '_').humanize
|
18
18
|
end
|
19
19
|
|
20
20
|
def model_class
|
21
21
|
@model_class ||= RademadeAdmin::LoaderService.const_get(model_name)
|
22
22
|
end
|
23
23
|
|
24
|
-
|
24
|
+
# Return configured list info
|
25
|
+
#
|
26
|
+
# @return [RademadeAdmin::Model::Configuration::ListFields]
|
27
|
+
#
|
28
|
+
def list_fields
|
29
|
+
@list_fields ||= RademadeAdmin::Model::Configuration::ListFields.new
|
30
|
+
end
|
31
|
+
|
32
|
+
# Return configured fields info
|
33
|
+
#
|
34
|
+
# @return [RademadeAdmin::Model::Configuration::FormFields]
|
35
|
+
#
|
36
|
+
def form_fields
|
37
|
+
@form_fields ||= RademadeAdmin::Model::Configuration::FormFields.new
|
38
|
+
end
|
39
|
+
|
40
|
+
# Return configured fields info
|
41
|
+
#
|
42
|
+
# @return [RademadeAdmin::Model::Configuration::FieldsLabels]
|
43
|
+
#
|
44
|
+
def field_labels
|
45
|
+
@field_labels ||= RademadeAdmin::Model::Configuration::FieldsLabels.new
|
46
|
+
end
|
47
|
+
|
48
|
+
def all_field_names
|
49
|
+
@all_field_names ||= Set.new(list_fields.all.map(&:name) + form_fields.all.map(&:name))
|
50
|
+
end
|
25
51
|
|
26
52
|
def model(model_name)
|
27
53
|
@model_name = model_name
|
28
54
|
end
|
29
55
|
|
30
|
-
|
56
|
+
private
|
57
|
+
|
58
|
+
def name(item_name)
|
31
59
|
@item_name = item_name
|
32
60
|
end
|
33
61
|
|
@@ -35,17 +63,16 @@ module RademadeAdmin
|
|
35
63
|
@parent_menu_item = parent_menu_item
|
36
64
|
end
|
37
65
|
|
38
|
-
def
|
39
|
-
|
66
|
+
def labels(*field_options, &block)
|
67
|
+
field_labels.configure(*field_options, &block)
|
40
68
|
end
|
41
69
|
|
42
|
-
def
|
43
|
-
|
70
|
+
def list(*field_options, &block)
|
71
|
+
list_fields.configure(*field_options, &block)
|
44
72
|
end
|
45
73
|
|
46
|
-
def
|
47
|
-
|
48
|
-
model_fields.fields
|
74
|
+
def form(*field_options, &block)
|
75
|
+
form_fields.configure(*field_options, &block)
|
49
76
|
end
|
50
77
|
|
51
78
|
end
|
@@ -1,34 +1,60 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
module RademadeAdmin
|
3
3
|
module Model
|
4
|
-
class
|
4
|
+
class Configuration
|
5
|
+
class Fields
|
5
6
|
|
6
|
-
|
7
|
+
def find(name)
|
8
|
+
name = name.to_sym
|
9
|
+
field = @fields.select { |field| field.name == name }.first
|
10
|
+
return nil if field.nil?
|
11
|
+
yield(field) if block_given?
|
12
|
+
field
|
13
|
+
end
|
7
14
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
15
|
+
def find_with_index(name)
|
16
|
+
found_field, found_index = nil, nil
|
17
|
+
@fields.each_with_index do |field, index|
|
18
|
+
if field.name == name
|
19
|
+
found_field, found_index = field, index
|
20
|
+
break
|
21
|
+
end
|
22
|
+
end
|
23
|
+
return nil if found_field.nil?
|
24
|
+
yield(found_field, found_index) if block_given?
|
25
|
+
{ :field => found_field, :index => found_index }
|
26
|
+
end
|
13
27
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
28
|
+
def all
|
29
|
+
@fields
|
30
|
+
end
|
18
31
|
|
19
|
-
|
20
|
-
|
21
|
-
|
32
|
+
def method_missing(name, *arguments)
|
33
|
+
@fields << field_class.new(name.to_sym, *arguments)
|
34
|
+
end
|
22
35
|
|
23
|
-
|
24
|
-
|
25
|
-
field = name.to_sym
|
26
|
-
else
|
27
|
-
field = { name.to_sym => arguments.first }
|
36
|
+
def configure(*options, &block)
|
37
|
+
block_given? ? instance_eval(&block) : _init_from_options(*options)
|
28
38
|
end
|
29
|
-
@fields << field
|
30
|
-
end
|
31
39
|
|
40
|
+
protected
|
41
|
+
|
42
|
+
def initialize
|
43
|
+
@fields = []
|
44
|
+
end
|
45
|
+
|
46
|
+
def field_class
|
47
|
+
raise NotImplementedError, 'Field class for {CLASS} fields not defined'
|
48
|
+
end
|
49
|
+
|
50
|
+
def _init_from_options(*options)
|
51
|
+
options.each do |option|
|
52
|
+
#todo add validation
|
53
|
+
@fields << field_class.new(option.to_sym)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
32
58
|
end
|
33
59
|
end
|
34
60
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'rademade_admin/model/configuration/fields'
|
3
|
+
|
4
|
+
module RademadeAdmin
|
5
|
+
module Model
|
6
|
+
class Configuration
|
7
|
+
class FieldsLabels < Fields
|
8
|
+
|
9
|
+
def label_for(name)
|
10
|
+
field = find(name)
|
11
|
+
if field.nil?
|
12
|
+
name.to_s.humanize
|
13
|
+
else
|
14
|
+
field.label
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
protected
|
19
|
+
|
20
|
+
def field_class
|
21
|
+
RademadeAdmin::Model::Configuration::FieldLabel
|
22
|
+
end
|
23
|
+
|
24
|
+
def _init_from_options(*options)
|
25
|
+
raise "Can't init labels from options"
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module RademadeAdmin
|
3
|
+
module Model
|
4
|
+
class Configuration
|
5
|
+
class FormField
|
6
|
+
|
7
|
+
attr_accessor :name, :params
|
8
|
+
|
9
|
+
def initialize(name, params = {})
|
10
|
+
@name = name
|
11
|
+
init_params(params)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def init_params(params)
|
17
|
+
if params.is_a? Hash
|
18
|
+
@params = params
|
19
|
+
else
|
20
|
+
@params = { :as => params }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|