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.
Files changed (223) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/fonts/glyphicons-halflings-regular.eot +0 -0
  3. data/app/assets/fonts/glyphicons-halflings-regular.svg +229 -0
  4. data/app/assets/fonts/glyphicons-halflings-regular.ttf +0 -0
  5. data/app/assets/fonts/glyphicons-halflings-regular.woff +0 -0
  6. data/app/assets/images/rademade_admin/ico/btn-attach.png +0 -0
  7. data/app/assets/images/rademade_admin/logos/logo.png +0 -0
  8. data/app/assets/javascripts/rademade_admin.coffee +8 -4
  9. data/app/assets/javascripts/rademade_admin/app/app.coffee +2 -1
  10. data/app/assets/javascripts/rademade_admin/app/common/datetime-picker.coffee +7 -0
  11. data/app/assets/javascripts/rademade_admin/app/common/dnd-sort.coffee +23 -32
  12. data/app/assets/javascripts/rademade_admin/app/common/droplist.coffee +8 -0
  13. data/app/assets/javascripts/rademade_admin/app/common/lang-panel.coffee +6 -0
  14. data/app/assets/javascripts/rademade_admin/app/common/related-index.coffee +6 -9
  15. data/app/assets/javascripts/rademade_admin/app/common/sort-list.coffee +10 -14
  16. data/app/assets/javascripts/rademade_admin/app/common/uploader.coffee +3 -3
  17. data/app/assets/javascripts/rademade_admin/app/form-popup/initializer.coffee +24 -37
  18. data/app/assets/javascripts/rademade_admin/app/form-popup/view.coffee +32 -18
  19. data/app/assets/javascripts/rademade_admin/app/forms/remove.coffee +4 -3
  20. data/app/assets/javascripts/rademade_admin/app/select2/model.coffee +7 -0
  21. data/app/assets/javascripts/rademade_admin/app/select2/related/collection-view.coffee +35 -0
  22. data/app/assets/javascripts/rademade_admin/app/select2/related/collection.coffee +28 -0
  23. data/app/assets/javascripts/rademade_admin/app/select2/related/model.coffee +15 -0
  24. data/app/assets/javascripts/rademade_admin/app/select2/related/view.coffee +40 -0
  25. data/app/assets/javascripts/rademade_admin/app/select2/view.coffee +78 -0
  26. data/app/assets/javascripts/rademade_admin/form/form-ajax.coffee +48 -0
  27. data/app/assets/javascripts/rademade_admin/form/form-initializater.coffee +45 -0
  28. data/app/assets/javascripts/rademade_admin/form/form-validation.coffee +42 -0
  29. data/app/assets/javascripts/rademade_admin/form/form.coffee +62 -0
  30. data/app/assets/javascripts/rademade_admin/library/ckeditor/config.js +14 -12
  31. data/app/assets/stylesheets/{rademade_admin/bootstrap → old/-bootstrap}/bootstrap-overrides.css.erb +0 -0
  32. data/app/assets/stylesheets/{rademade_admin/bootstrap → old/-bootstrap}/main.scss.erb +0 -0
  33. data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/chart-showcase.scss.erb +0 -0
  34. data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/datatables.scss.erb +0 -0
  35. data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/elements.scss.erb +0 -0
  36. data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/error.scss.erb +0 -0
  37. data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/form-showcase.scss.erb +0 -0
  38. data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/form-wizard.scss.erb +0 -0
  39. data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/gallery.scss.erb +0 -0
  40. data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/grids.scss.erb +0 -0
  41. data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/icons.scss.erb +0 -0
  42. data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/index.scss.erb +0 -0
  43. data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/layout.scss.erb +0 -0
  44. data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/new-user.scss.erb +0 -0
  45. data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/personal-info.scss.erb +0 -0
  46. data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/popup.scss.erb +0 -0
  47. data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/signin.scss.erb +0 -0
  48. data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/tables.scss.erb +0 -0
  49. data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/ui-elements.scss.erb +0 -0
  50. data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/user-list.scss.erb +0 -0
  51. data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/user-profile.scss.erb +0 -0
  52. data/app/assets/stylesheets/{rademade_admin/detail_admin → old/-detail_admin}/web-app-icons.scss.erb +0 -0
  53. data/app/assets/stylesheets/{rademade_admin/lib → old/-lib}/bootstrap.datepicker.css.erb +0 -0
  54. data/app/assets/stylesheets/{rademade_admin/lib → old/-lib}/morris.css.erb +0 -0
  55. data/app/assets/stylesheets/{rademade_admin → old}/base.scss.erb +0 -0
  56. data/app/assets/stylesheets/{rademade_admin → old}/edit.css +0 -0
  57. data/app/assets/stylesheets/{rademade_admin → old}/file-upload.scss.erb +0 -0
  58. data/app/assets/stylesheets/{rademade_admin → old}/notifier.custom.css.erb +0 -0
  59. data/app/assets/stylesheets/{rademade_admin → old}/scaffolds.scss.erb +0 -0
  60. data/app/assets/stylesheets/rademade_admin.sass.erb +96 -0
  61. data/app/assets/stylesheets/rademade_admin/base/main.sass +71 -0
  62. data/app/assets/stylesheets/rademade_admin/blocks/buttons/main.sass +81 -0
  63. data/app/assets/stylesheets/rademade_admin/blocks/form/input.sass +29 -0
  64. data/app/assets/stylesheets/rademade_admin/blocks/form/label.sass +31 -0
  65. data/app/assets/stylesheets/rademade_admin/blocks/form/select.sass +26 -0
  66. data/app/assets/stylesheets/rademade_admin/blocks/form/select2.sass +67 -0
  67. data/app/assets/stylesheets/rademade_admin/blocks/form/table.sass +42 -0
  68. data/app/assets/stylesheets/rademade_admin/blocks/form/texarea.sass +20 -0
  69. data/app/assets/stylesheets/rademade_admin/blocks/header/_logo.sass +7 -0
  70. data/app/assets/stylesheets/rademade_admin/blocks/header/_menu.sass +80 -0
  71. data/app/assets/stylesheets/rademade_admin/blocks/header/_search.sass +37 -0
  72. data/app/assets/stylesheets/rademade_admin/blocks/page/content/_main.sass +11 -0
  73. data/app/assets/stylesheets/rademade_admin/blocks/page/headline/main.sass +44 -0
  74. data/app/assets/stylesheets/rademade_admin/blocks/page/menu/_main.sass +31 -0
  75. data/app/assets/stylesheets/rademade_admin/lib/datepicker.sass +373 -0
  76. data/app/assets/stylesheets/rademade_admin/lib/glyphicon.sass.erb +618 -0
  77. data/app/assets/stylesheets/rademade_admin/lib/notifier.css.erb +661 -0
  78. data/app/assets/stylesheets/rademade_admin/lib/uploader.sass +66 -0
  79. data/app/assets/stylesheets/rademade_admin/mixins/clear.sass +5 -0
  80. data/app/assets/stylesheets/rademade_admin/mixins/fonts.sass +8 -0
  81. data/app/assets/stylesheets/rademade_admin/mixins/sprite.sass +7 -0
  82. data/app/assets/stylesheets/rademade_admin/mixins/text-overflow.sass +6 -0
  83. data/app/assets/stylesheets/rademade_admin/mixins/user-select.sass +5 -0
  84. data/app/assets/stylesheets/rademade_admin/modules/breadcrumbs/main.sass +30 -0
  85. data/app/assets/stylesheets/rademade_admin/modules/errors/error.sass.erb +19 -0
  86. data/app/assets/stylesheets/rademade_admin/modules/form/main.sass +15 -0
  87. data/app/assets/stylesheets/rademade_admin/modules/header/main.sass +6 -0
  88. data/app/assets/stylesheets/rademade_admin/modules/login/_main.sass +79 -0
  89. data/app/assets/stylesheets/rademade_admin/modules/main-menu/main.sass +0 -0
  90. data/app/assets/stylesheets/rademade_admin/modules/page/main.sass +16 -0
  91. data/app/assets/stylesheets/rademade_admin/modules/pagination/main.sass +51 -0
  92. data/app/assets/stylesheets/rademade_admin/modules/popup/new.sass +18 -0
  93. data/app/assets/stylesheets/rademade_admin/var/colors.sass +0 -0
  94. data/app/assets/stylesheets/rademade_admin/var/images.sass +2 -0
  95. data/app/assets/stylesheets/rademade_admin/var/width.sass +13 -0
  96. data/app/controllers/rademade_admin/abstract_controller.rb +18 -2
  97. data/app/controllers/rademade_admin/application_controller.rb +1 -1
  98. data/app/controllers/rademade_admin/dashboard_controller.rb +1 -1
  99. data/app/controllers/rademade_admin/file_controller.rb +25 -0
  100. data/app/controllers/rademade_admin/model_controller.rb +66 -47
  101. data/app/controllers/rademade_admin/sessions_controller.rb +3 -3
  102. data/app/helpers/rademade_admin/field_helper.rb +21 -32
  103. data/app/helpers/rademade_admin/form_helper.rb +57 -27
  104. data/app/helpers/rademade_admin/menu_helper.rb +12 -5
  105. data/app/helpers/rademade_admin/uri_helper.rb +50 -62
  106. data/app/inputs/rademade_admin/date_time_input.rb +13 -0
  107. data/app/inputs/rademade_admin/file_input.rb +72 -0
  108. data/app/inputs/rademade_admin/related_select_input.rb +78 -0
  109. data/app/serializers/autocomplete/link_serializer.rb +6 -4
  110. data/app/services/linker.rb +8 -14
  111. data/app/services/login.rb +5 -3
  112. data/app/services/model_controller/breadcrumbs.rb +36 -0
  113. data/app/services/model_controller/instance_options.rb +7 -5
  114. data/app/services/model_controller/model_options.rb +10 -7
  115. data/app/services/model_controller/notifier.rb +10 -6
  116. data/app/services/model_controller/templates.rb +4 -3
  117. data/app/services/relation_service.rb +11 -0
  118. data/app/services/saver.rb +59 -24
  119. data/app/services/search/conditions/abstract.rb +15 -14
  120. data/app/services/search/conditions/autocomplete.rb +11 -9
  121. data/app/services/search/conditions/list.rb +6 -5
  122. data/app/services/search/conditions/related_list.rb +17 -13
  123. data/app/services/search/{conditions/part/where.rb → part/abstract.rb} +7 -9
  124. data/app/services/search/part/order.rb +17 -0
  125. data/app/services/search/part/where.rb +19 -0
  126. data/app/services/sortable_service.rb +27 -27
  127. data/app/services/template_service.rb +68 -0
  128. data/app/services/upload/preview_service.rb +86 -0
  129. data/app/views/layouts/rademade_admin.html.erb +13 -4
  130. data/app/views/rademade_admin/_blocks/_header.html.erb +35 -28
  131. data/app/views/rademade_admin/_blocks/_menu.html.erb +20 -23
  132. data/app/views/rademade_admin/_blocks/_on_page_select.html.erb +15 -0
  133. data/app/views/rademade_admin/_blocks/_pagination.html.erb +1 -18
  134. data/app/views/rademade_admin/_blocks/_sub_menu.html.erb +3 -3
  135. data/app/views/rademade_admin/_blocks/form/_control.html.erb +3 -0
  136. data/app/views/rademade_admin/_blocks/form/_lang_panel.html.erb +19 -0
  137. data/app/views/rademade_admin/_blocks/sub_menu/_link.html.erb +6 -5
  138. data/app/views/rademade_admin/_blocks/table/_head.html.erb +13 -0
  139. data/app/views/rademade_admin/_layouts/inner.html.erb +21 -33
  140. data/app/views/rademade_admin/_layouts/inner/form.html.erb +6 -13
  141. data/app/views/rademade_admin/_layouts/inner/index_table.html.erb +31 -55
  142. data/app/views/rademade_admin/_layouts/inner/related_index_table.html.erb +26 -54
  143. data/app/views/rademade_admin/abstract/_form.html.erb +6 -9
  144. data/app/views/rademade_admin/abstract/edit.html.erb +3 -8
  145. data/app/views/rademade_admin/abstract/index.html.erb +38 -67
  146. data/app/views/rademade_admin/abstract/new.html.erb +3 -8
  147. data/app/views/rademade_admin/abstract/related.html.erb +48 -0
  148. data/app/views/rademade_admin/dashboard/index.html.erb +4 -5
  149. data/app/views/rademade_admin/dashboard/login.html.erb +19 -30
  150. data/config/initializers/carrier_wave/mongoid.rb +48 -0
  151. data/config/initializers/ckeditor.rb +3 -0
  152. data/config/initializers/kaminari_route_proxy.rb +16 -0
  153. data/config/initializers/simple_form.rb +147 -0
  154. data/config/initializers/simple_form/rademade_component.rb +9 -0
  155. data/config/initializers/simple_form/wrappers.rb +28 -0
  156. data/config/locales/rademade_admin.en.yml +28 -0
  157. data/config/locales/simple_form.en.yml +26 -0
  158. data/config/routes.rb +1 -2
  159. data/lib/rademade_admin.rb +7 -5
  160. data/lib/rademade_admin/bower/performer.rb +1 -1
  161. data/lib/rademade_admin/breadcrumbs/render/rademade.rb +31 -0
  162. data/lib/rademade_admin/engine.rb +2 -2
  163. data/lib/rademade_admin/input/related_select_input/model_data.rb +40 -0
  164. data/lib/rademade_admin/input/related_select_input/related_list.rb +60 -0
  165. data/lib/rademade_admin/model/adapter/data.rb +119 -0
  166. data/lib/rademade_admin/model/adapter/data/active_record.rb +109 -0
  167. data/lib/rademade_admin/model/adapter/data/mongoid.rb +77 -0
  168. data/{app/services/search/query_adapter/abstract.rb → lib/rademade_admin/model/adapter/query.rb} +15 -5
  169. data/lib/rademade_admin/model/adapter/query/active_record.rb +50 -0
  170. data/lib/rademade_admin/model/adapter/query/mongoid.rb +57 -0
  171. data/lib/rademade_admin/model/configuration.rb +43 -16
  172. data/lib/rademade_admin/model/configuration/field_label.rb +16 -0
  173. data/lib/rademade_admin/model/configuration/fields.rb +47 -21
  174. data/lib/rademade_admin/model/configuration/fields_labels.rb +31 -0
  175. data/lib/rademade_admin/model/configuration/form_field.rb +27 -0
  176. data/lib/rademade_admin/model/configuration/form_fields.rb +18 -0
  177. data/lib/rademade_admin/model/configuration/list_field.rb +21 -0
  178. data/lib/rademade_admin/model/configuration/list_fields.rb +18 -0
  179. data/lib/rademade_admin/model/graph.rb +9 -9
  180. data/lib/rademade_admin/model/info.rb +53 -68
  181. data/lib/rademade_admin/model/info/data_item.rb +130 -0
  182. data/lib/rademade_admin/model/info/data_items.rb +130 -0
  183. data/lib/rademade_admin/model/info/field.rb +39 -0
  184. data/lib/rademade_admin/model/info/fields.rb +87 -0
  185. data/lib/rademade_admin/model/info/relation.rb +49 -0
  186. data/lib/rademade_admin/model/info/relations.rb +40 -0
  187. data/lib/rademade_admin/model/info/uploader.rb +16 -0
  188. data/lib/rademade_admin/model/info/uploaders.rb +35 -0
  189. data/lib/rademade_admin/model/reflection.rb +38 -9
  190. data/lib/rademade_admin/routing/mapper.rb +9 -5
  191. data/lib/rademade_admin/search/searcher.rb +22 -0
  192. data/lib/rademade_admin/sortable.rb +1 -0
  193. data/lib/rademade_admin/uploader/photo.rb +1 -0
  194. data/lib/rademade_admin/user.rb +7 -6
  195. data/lib/rademade_admin/version.rb +1 -1
  196. data/lib/tasks/rademade_bower_install.rake +10 -2
  197. data/lib/templates/erb/scaffold/_form.html.erb +13 -0
  198. metadata +195 -109
  199. data/app/assets/javascripts/rademade_admin/app/common/relation-list.coffee +0 -109
  200. data/app/assets/javascripts/rademade_admin/app/form-popup/collection.coffee +0 -20
  201. data/app/assets/javascripts/rademade_admin/app/form-popup/model.coffee +0 -4
  202. data/app/assets/javascripts/rademade_admin/detail_admin/theme.js +0 -56
  203. data/app/assets/javascripts/rademade_admin/form/form-ajax-submit.coffee +0 -157
  204. data/app/assets/stylesheets/rademade_admin.scss.erb +0 -19
  205. data/app/helpers/rademade_admin/name_helper.rb +0 -18
  206. data/app/helpers/rademade_admin/upload_preview_helper.rb +0 -60
  207. data/app/inputs/rademade_admin/admin_file_input.rb +0 -71
  208. data/app/inputs/rademade_admin/admin_select_input.rb +0 -82
  209. data/app/inputs/rademade_admin/admin_textarea_input.rb +0 -6
  210. data/app/inputs/rademade_admin/boolean_input.rb +0 -14
  211. data/app/services/form_builder.rb +0 -4
  212. data/app/services/search/query_adapter/active_record.rb +0 -45
  213. data/app/services/search/query_adapter/mongoid.rb +0 -51
  214. data/app/services/search/searcher.rb +0 -20
  215. data/app/views/rademade_admin/_blocks/_form_control.html.erb +0 -5
  216. data/app/views/rademade_admin/abstract/related_index.html.erb +0 -85
  217. data/config/initializers/devise.rb +0 -251
  218. data/config/initializers/formtastic.rb +0 -13
  219. data/lib/rademade_admin/model/data_adapter.rb +0 -64
  220. data/lib/rademade_admin/model/data_adapter/active_record.rb +0 -59
  221. data/lib/rademade_admin/model/data_adapter/mongoid.rb +0 -54
  222. data/lib/rademade_admin/model/reflection/data.rb +0 -48
  223. 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
@@ -1,19 +1,29 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module RademadeAdmin
3
- module Search
4
- module QueryAdapter
5
- class Abstract
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 apply_conditions(search_conditions)
12
- @params = search_conditions.params
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 :parent_menu_item, :list_fields, :form_fields
6
+ attr_reader :controller, :parent_menu_item, :model_name
7
7
 
8
- def initialize(controller_name)
9
- @controller_name = controller_name
8
+ def initialize(controller)
9
+ @controller = controller
10
10
  end
11
11
 
12
- def model_name
13
- @model_name ||= @controller_name.classify
12
+ def item_name
13
+ @item_name ||= singular_name.pluralize
14
14
  end
15
15
 
16
- def item_name
17
- @item_name ||= model_name.underscore.gsub('/', '_').humanize
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
- private
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
- def item(item_name)
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 list(*field_options, &block)
39
- @list_fields = fields(*field_options, &block)
66
+ def labels(*field_options, &block)
67
+ field_labels.configure(*field_options, &block)
40
68
  end
41
69
 
42
- def form(*field_options, &block)
43
- @form_fields = fields(*field_options, &block)
70
+ def list(*field_options, &block)
71
+ list_fields.configure(*field_options, &block)
44
72
  end
45
73
 
46
- def fields(*field_options, &block)
47
- model_fields = block_given? ? Fields.init_from_block(&block) : Fields.init_from_options(field_options)
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
@@ -0,0 +1,16 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module RademadeAdmin
3
+ module Model
4
+ class Configuration
5
+ class FieldLabel
6
+
7
+ attr_accessor :name, :label
8
+
9
+ def initialize(name, label)
10
+ @name, @label = name, label
11
+ end
12
+
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,34 +1,60 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module RademadeAdmin
3
3
  module Model
4
- class Fields
4
+ class Configuration
5
+ class Fields
5
6
 
6
- attr_reader :fields
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
- def self.init_from_block(&block)
9
- model_fields = self.new
10
- model_fields.instance_eval(&block)
11
- model_fields
12
- end
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
- def self.init_from_options(field_options)
15
- model_fields = self.new(field_options)
16
- model_fields
17
- end
28
+ def all
29
+ @fields
30
+ end
18
31
 
19
- def initialize(fields = [])
20
- @fields = fields
21
- end
32
+ def method_missing(name, *arguments)
33
+ @fields << field_class.new(name.to_sym, *arguments)
34
+ end
22
35
 
23
- def method_missing(name, *arguments)
24
- if arguments.empty?
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