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
@@ -6,23 +6,16 @@ module RademadeAdmin
6
6
 
7
7
  attr_reader :params
8
8
 
9
- def initialize(params, origin_fields)
9
+ # @param params [Hash]
10
+ # @param data_items [RademadeAdmin::Model::Info::DataItems]
11
+ #
12
+ def initialize(params, data_items)
10
13
  @params = params
11
- @origin_fields = origin_fields
14
+ @data_items = data_items
12
15
  end
13
16
 
14
17
  def conditions
15
- @conditions ||= init_conditions
16
- end
17
-
18
- def base_condition(model)
19
- model.unscoped
20
- end
21
-
22
- protected
23
-
24
- def init_conditions
25
- {
18
+ @conditions ||= {
26
19
  :where => where,
27
20
  :order => order,
28
21
  :page => page,
@@ -31,12 +24,20 @@ module RademadeAdmin
31
24
  }
32
25
  end
33
26
 
27
+ def base_condition(model)
28
+ # todo. deleted at?
29
+ # We can't use default scope. It can be patched
30
+ model.unscoped
31
+ end
32
+
33
+ protected
34
+
34
35
  def where
35
36
  nil
36
37
  end
37
38
 
38
39
  def order
39
- {}
40
+ nil
40
41
  end
41
42
 
42
43
  def page
@@ -6,17 +6,13 @@ module RademadeAdmin
6
6
  module Conditions
7
7
  class Autocomplete < Abstract
8
8
 
9
- def initialize(params, origin_fields, filter_fields)
10
- super(params, origin_fields)
11
- @filter_fields = filter_fields
12
- end
13
-
14
9
  protected
15
10
 
16
11
  def where
17
- @where_conditions = Where.new(:and)
12
+ @where_conditions = RademadeAdmin::Search::Part::Where.new(:and)
18
13
  append_query_condition
19
14
  append_search_params
15
+ append_ids_params
20
16
  @where_conditions
21
17
  end
22
18
 
@@ -28,8 +24,8 @@ module RademadeAdmin
28
24
 
29
25
  def append_query_condition
30
26
  if @params[:q].present?
31
- query_where = Where.new(:or)
32
- @filter_fields.each do |field|
27
+ query_where = RademadeAdmin::Search::Part::Where.new(:or)
28
+ @data_items.filter_fields.each do |field|
33
29
  query_where.add(field, /#{@params[:q]}/i)
34
30
  end
35
31
  @where_conditions.sub_add(query_where)
@@ -39,11 +35,17 @@ module RademadeAdmin
39
35
  def append_search_params
40
36
  if @params[:search].present?
41
37
  @params[:search].each do |key, value|
42
- @where_conditions.add(key.to_sym, value) if @origin_fields.include? key.to_s
38
+ @where_conditions.add(key.to_sym, value) if @data_items.origin_fields.include? key.to_s
43
39
  end
44
40
  end
45
41
  end
46
42
 
43
+ def append_ids_params
44
+ if @params[:ids].present?
45
+ @where_conditions.add(@data_items.primary_field.name, @params[:ids])
46
+ end
47
+ end
48
+
47
49
  end
48
50
  end
49
51
  end
@@ -9,17 +9,18 @@ module RademadeAdmin
9
9
  protected
10
10
 
11
11
  def where
12
- where_conditions = Where.new(:and)
13
- @params.slice(*@origin_fields).each do |field, value|
12
+ where_conditions = RademadeAdmin::Search::Part::Where.new(:and)
13
+ @params.slice(*@data_items.origin_fields).each do |field, value|
14
14
  where_conditions.add(field, value)
15
15
  end
16
16
  where_conditions
17
17
  end
18
18
 
19
19
  def order
20
+ order_conditions = RademadeAdmin::Search::Part::Order.new
20
21
  field = @params[:sort] || default_order_field
21
- direction = @params[:direction] || :asc
22
- [{field => direction}]
22
+ order_conditions.add(field, @params[:direction])
23
+ order_conditions
23
24
  end
24
25
 
25
26
  def page
@@ -33,7 +34,7 @@ module RademadeAdmin
33
34
  private
34
35
 
35
36
  def default_order_field
36
- @origin_fields.include?('position') ? :position : :id
37
+ @data_items.has_field?(:position) ? :position : :id
37
38
  end
38
39
 
39
40
  end
@@ -6,24 +6,29 @@ module RademadeAdmin
6
6
  module Conditions
7
7
  class RelatedList < Abstract
8
8
 
9
- def base_condition(model)
10
- model_related_name = model.to_s.tableize.gsub('/', '_').to_sym
11
- @params[:parent].constantize.find(@params[:parent_id]).send(model_related_name)
12
- end
9
+ attr_reader :item
13
10
 
14
11
  protected
15
12
 
13
+ def initialize(item, params, data_items)
14
+ @item = item
15
+ super(params, data_items)
16
+ end
17
+
16
18
  def where
17
- where_conditions = Where.new(:and)
18
- @params.slice(*@origin_fields).each do |field, value|
19
+ where_conditions = RademadeAdmin::Search::Part::Where.new(:and)
20
+ where_conditions.add(:id, related_item_ids)
21
+ @params.slice(*@data_items.origin_fields).each do |field, value|
19
22
  where_conditions.add(field, value)
20
23
  end
21
24
  where_conditions
22
25
  end
23
26
 
24
27
  def order
28
+ order_conditions = RademadeAdmin::Search::Part::Order.new
25
29
  field = @params[:sort] || default_order_field
26
- [{field => direction}]
30
+ order_conditions.add(field, @params[:direction])
31
+ order_conditions
27
32
  end
28
33
 
29
34
  def page
@@ -37,14 +42,13 @@ module RademadeAdmin
37
42
  private
38
43
 
39
44
  def default_order_field
40
- @origin_fields.include?('position') ? :position : :id
45
+ @data_items.has_field?(:position) ? :position : :id
41
46
  end
42
47
 
43
- def direction
44
- if @params[:direction].present?
45
- @params[:direction].to_sym
46
- else
47
- :asc
48
+ def related_item_ids
49
+ related_items = @item.send(params[:relation])
50
+ related_items.map do |related_item|
51
+ related_item.id.to_s
48
52
  end
49
53
  end
50
54
 
@@ -1,13 +1,11 @@
1
- # -*- encoding : utf-8 -*-
2
1
  module RademadeAdmin
3
2
  module Search
4
- module Conditions
5
- class Where
3
+ module Part
4
+ class Abstract
6
5
 
7
- attr_reader :type, :parts
6
+ attr_reader :parts
8
7
 
9
- def initialize(type)
10
- @type = type
8
+ def initialize
11
9
  @parts = []
12
10
  end
13
11
 
@@ -18,11 +16,11 @@ module RademadeAdmin
18
16
  }
19
17
  end
20
18
 
21
- def sub_add(where)
22
- @parts << where
19
+ def sub_add(part)
20
+ @parts << part
23
21
  end
24
22
 
25
23
  end
26
24
  end
27
25
  end
28
- end
26
+ end
@@ -0,0 +1,17 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'search/part/abstract'
3
+
4
+ module RademadeAdmin
5
+ module Search
6
+ module Part
7
+ class Order < Abstract
8
+
9
+ def add(field, value)
10
+ value ||= :asc
11
+ super(field, value.to_sym)
12
+ end
13
+
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'search/part/abstract'
3
+
4
+ module RademadeAdmin
5
+ module Search
6
+ module Part
7
+ class Where < Abstract
8
+
9
+ attr_reader :type
10
+
11
+ def initialize(type)
12
+ super()
13
+ @type = type
14
+ end
15
+
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,38 +1,38 @@
1
1
  # -*- encoding : utf-8 -*-
2
- class RademadeAdmin::SortableService
2
+ module RademadeAdmin
3
+ class SortableService
3
4
 
4
- def initialize(model_info, params)
5
- @model_info = model_info
6
- @params = params
7
- end
5
+ def initialize(model_info, params)
6
+ @model_info = model_info
7
+ @params = params
8
+ end
8
9
 
9
- def re_sort_items
10
- min = @params[:minimum].to_i
11
- @params[:sorted].each do |k, v|
12
- item = @model_info.model.find(v[0])
13
- item.position = k.to_i + 1 + min
14
- item.save
10
+ def sort_items
11
+ @params[:sorted].each do |_, sorted_data|
12
+ item = @model_info.query_adapter.find(sorted_data[:id])
13
+ item.position = sorted_data[:position].to_i
14
+ item.save
15
+ end
15
16
  end
16
- end
17
17
 
18
- def can_reset?
19
- @params[:sort].present?
20
- end
18
+ def can_reset?
19
+ @params[:sort].present?
20
+ end
21
21
 
22
- def sorting_sign(name)
23
- if name.to_s == @params[:sort]
24
- case @params[:direction]
25
- when 'asc'
26
- return '⬇'
27
- when 'desc'
28
- return '⬆'
22
+ #
23
+ # @return [RademadeAdmin::Model::Info::DataItem]
24
+ #
25
+ def sorting_sign(field)
26
+ if field.name.to_s == @params[:sort]
27
+ return '' if @params[:direction] == 'asc'
28
+ return '⬆' if @params[:direction] == 'desc'
29
29
  end
30
+ ''
30
31
  end
31
- ''
32
- end
33
32
 
34
- def has_position?
35
- @model_info.has_field? 'position'
36
- end
33
+ def has_position?
34
+ @model_info.data_items.has_field? :position
35
+ end
37
36
 
37
+ end
38
38
  end
@@ -0,0 +1,68 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module RademadeAdmin
3
+ class TemplateService
4
+
5
+ def initialize(root_dir)
6
+ @root_dir = root_dir
7
+ end
8
+
9
+ def template_path(*directories)
10
+ "#{@root_dir}/#{directories.join('/')}"
11
+ end
12
+
13
+ def inner_layout
14
+ layout_path 'inner'
15
+ end
16
+
17
+ def inner_form_layout
18
+ layout_path 'inner/form'
19
+ end
20
+
21
+ def form_control_block
22
+ block_path 'form/control'
23
+ end
24
+
25
+ def form_lang_panel
26
+ block_path 'form/lang_panel'
27
+ end
28
+
29
+ def pagination_block
30
+ block_path 'pagination'
31
+ end
32
+
33
+ def on_page_select_block
34
+ block_path 'on_page_select'
35
+ end
36
+
37
+ def header_block
38
+ block_path 'header'
39
+ end
40
+
41
+ def menu_block
42
+ block_path 'menu'
43
+ end
44
+
45
+ def sub_menu_block
46
+ block_path 'sub_menu'
47
+ end
48
+
49
+ def sub_menu_link_block
50
+ block_path 'sub_menu/link'
51
+ end
52
+
53
+ def table_head_block
54
+ block_path 'table/head'
55
+ end
56
+
57
+ private
58
+
59
+ def layout_path(layout)
60
+ template_path '_layouts', layout
61
+ end
62
+
63
+ def block_path(block)
64
+ template_path '_blocks', block
65
+ end
66
+
67
+ end
68
+ end
@@ -0,0 +1,86 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module RademadeAdmin
3
+ module Upload
4
+ class PreviewService
5
+
6
+ include ActionView::Helpers::TagHelper
7
+ include ActionView::Context
8
+
9
+ def initialize(uploader)
10
+ @uploader = uploader
11
+ end
12
+
13
+ def preview_html
14
+ content_tag(:div, :class => ['preview-wrapper', preview_style_class].join(' ')) do
15
+ if @uploader.blank?
16
+ empty_file_html
17
+ else
18
+ uploaded_file_html
19
+ end
20
+ end
21
+ end
22
+
23
+ def uploaded_file_html
24
+ if is_image?
25
+ uploaded_image_preview
26
+ elsif is_video?
27
+ uploaded_video_preview
28
+ else
29
+ uploaded_file_default_preview
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def empty_file_html
36
+ content_tag(:span, I18n.t('rademade_admin.file_not_chosen'), {
37
+ :class => 'no-file'
38
+ })
39
+ end
40
+
41
+ def preview_style_class
42
+ if is_image?
43
+ 'image-preview-wrapper'
44
+ elsif is_video?
45
+ 'video-preview-wrapper'
46
+ else
47
+ 'file-preview-wrapper'
48
+ end
49
+ end
50
+
51
+ def is_image?
52
+ @uploader.class.ancestors.include? RademadeAdmin::Uploader::Photo
53
+ end
54
+
55
+ def is_video?
56
+ @uploader.class.ancestors.include? RademadeAdmin::Uploader::Video
57
+ end
58
+
59
+ def uploaded_image_preview
60
+ content_tag(:img, '', {
61
+ :src => @uploader.resize(230, 130),
62
+ :class => 'image-preview',
63
+ :width => 230,
64
+ :height => 130
65
+ })
66
+ end
67
+
68
+ def uploaded_video_preview
69
+ content_tag(:img, '', {
70
+ :src => @uploader.thumb_path,
71
+ :class => 'video-preview',
72
+ :width => 300
73
+ })
74
+ end
75
+
76
+ def uploaded_file_default_preview
77
+ file_path = @uploader.file.file
78
+ text = "#{File.basename(file_path)}, #{RademadeAdmin::FileInfoFormatter.format_size(File.size(file_path))}"
79
+ content_tag(:span, text, {
80
+ :class => 'file-uploaded'
81
+ })
82
+ end
83
+
84
+ end
85
+ end
86
+ end