rademade_admin 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/rademade_admin/app/common/location.coffee.erb +5 -1
  3. data/app/assets/javascripts/rademade_admin/app/common/status-toggler.coffee +25 -0
  4. data/app/assets/javascripts/rademade_admin/app/common/turboform.coffee +8 -0
  5. data/app/assets/javascripts/rademade_admin/app/form-popup/view.coffee +3 -3
  6. data/app/assets/javascripts/rademade_admin/app/gallery/image/collection-view.coffee +35 -0
  7. data/app/assets/javascripts/rademade_admin/app/gallery/image/collection.coffee +19 -0
  8. data/app/assets/javascripts/rademade_admin/app/gallery/image/model.coffee +25 -0
  9. data/app/assets/javascripts/rademade_admin/app/gallery/image/view.coffee +58 -0
  10. data/app/assets/javascripts/rademade_admin/app/gallery/view.coffee +40 -0
  11. data/app/assets/javascripts/rademade_admin/app/select2/related/view.coffee +1 -1
  12. data/app/assets/javascripts/rademade_admin/app/select2/view.coffee +11 -2
  13. data/app/assets/javascripts/rademade_admin/app/templates/crop.jst.ejs +2 -2
  14. data/app/assets/javascripts/rademade_admin/app/templates/related-item.jst.ejs +2 -2
  15. data/app/assets/javascripts/rademade_admin/form/form.coffee +4 -1
  16. data/app/assets/stylesheets/rademade_admin.sass.erb +2 -1
  17. data/app/assets/stylesheets/rademade_admin/blocks/form/input.sass +56 -27
  18. data/app/assets/stylesheets/rademade_admin/blocks/gallery/_main.sass +67 -0
  19. data/app/assets/stylesheets/rademade_admin/modules/pagination/main.sass +19 -2
  20. data/app/cells/menu/item.slim +2 -0
  21. data/app/cells/menu_cell.rb +8 -2
  22. data/app/controllers/rademade_admin/abstract_controller.rb +6 -2
  23. data/app/controllers/rademade_admin/dashboard_controller.rb +1 -1
  24. data/app/controllers/rademade_admin/file_controller.rb +14 -5
  25. data/app/controllers/rademade_admin/gallery_controller.rb +48 -0
  26. data/app/controllers/rademade_admin/model_controller.rb +37 -29
  27. data/app/controllers/rademade_admin/sessions_controller.rb +7 -6
  28. data/app/controllers/rademade_admin/status_controller.rb +16 -0
  29. data/app/helpers/rademade_admin/field_helper.rb +3 -4
  30. data/app/helpers/rademade_admin/form_helper.rb +35 -25
  31. data/app/helpers/rademade_admin/uri_helper.rb +6 -14
  32. data/app/inputs/rademade_admin/file_input.rb +24 -8
  33. data/app/inputs/rademade_admin/gallery_input.rb +77 -0
  34. data/app/inputs/rademade_admin/related_select_input.rb +13 -4
  35. data/app/serializers/autocomplete/base_serializer.rb +1 -1
  36. data/app/services/gallery/manager.rb +81 -0
  37. data/app/services/login.rb +3 -3
  38. data/app/services/menu_service.rb +1 -1
  39. data/app/services/menu_service/menu_item.rb +4 -0
  40. data/app/services/model_controller/model_options.rb +1 -0
  41. data/app/services/model_controller/notifier.rb +24 -10
  42. data/app/services/search/conditions/autocomplete.rb +4 -11
  43. data/app/services/search/conditions/list.rb +22 -10
  44. data/app/services/search/conditions/related_list.rb +8 -4
  45. data/app/services/search/where.rb +20 -0
  46. data/app/services/sortable_service.rb +1 -4
  47. data/app/services/status/toggler.rb +27 -0
  48. data/app/services/template_service.rb +33 -1
  49. data/app/services/upload/gallery_preview_service.rb +64 -0
  50. data/app/views/layouts/rademade_admin.html.erb +1 -22
  51. data/app/views/rademade_admin/_blocks/_form.html.erb +10 -0
  52. data/app/views/rademade_admin/_blocks/_header.html.erb +0 -12
  53. data/app/views/rademade_admin/_blocks/_search.html.erb +11 -0
  54. data/app/views/rademade_admin/_blocks/_sort_reset.html.erb +5 -0
  55. data/app/views/rademade_admin/_blocks/button/_cancel.html.erb +7 -0
  56. data/app/views/rademade_admin/_blocks/button/_destroy.html.erb +12 -0
  57. data/app/views/rademade_admin/_blocks/button/_edit.html.erb +4 -2
  58. data/app/views/rademade_admin/_blocks/button/_hide.html.erb +13 -0
  59. data/app/views/rademade_admin/_blocks/button/_preview.html.erb +3 -0
  60. data/app/views/rademade_admin/_blocks/form/_control.html.erb +9 -3
  61. data/app/views/rademade_admin/_blocks/form/_separator.html.erb +1 -0
  62. data/app/views/rademade_admin/_blocks/table/_head.html.erb +8 -2
  63. data/app/views/rademade_admin/_layouts/inner/index_table.html.erb +1 -3
  64. data/app/views/rademade_admin/_layouts/main.html.erb +26 -0
  65. data/app/views/rademade_admin/abstract/_form.html.erb +1 -7
  66. data/app/views/rademade_admin/abstract/index.html.erb +7 -13
  67. data/config/locales/rademade_admin.en.yml +16 -1
  68. data/config/locales/rademade_admin.ru.yml +22 -2
  69. data/config/routes.rb +9 -1
  70. data/lib/rademade_admin.rb +5 -0
  71. data/lib/rademade_admin/configuration.rb +6 -1
  72. data/lib/rademade_admin/engine.rb +4 -0
  73. data/lib/rademade_admin/gallery.rb +13 -0
  74. data/lib/rademade_admin/hideable.rb +37 -0
  75. data/lib/rademade_admin/input/related_select_input/related_list.rb +2 -2
  76. data/lib/rademade_admin/model/adapter/data.rb +8 -0
  77. data/lib/rademade_admin/model/adapter/data/active_record.rb +12 -2
  78. data/lib/rademade_admin/model/adapter/data/mongoid.rb +10 -8
  79. data/lib/rademade_admin/model/adapter/query/active_record.rb +8 -3
  80. data/lib/rademade_admin/model/configuration.rb +10 -8
  81. data/lib/rademade_admin/model/info.rb +13 -2
  82. data/lib/rademade_admin/model/info/data_item.rb +8 -3
  83. data/lib/rademade_admin/model/info/fields.rb +12 -2
  84. data/lib/rademade_admin/model/info/relation.rb +5 -0
  85. data/lib/rademade_admin/model/info/relation/gallery.rb +12 -0
  86. data/lib/rademade_admin/model/reflection.rb +4 -0
  87. data/lib/rademade_admin/routing/mapper.rb +1 -1
  88. data/lib/rademade_admin/routing/resource.rb +4 -0
  89. data/lib/rademade_admin/uploader/crop_photo.rb +3 -2
  90. data/lib/rademade_admin/version.rb +1 -1
  91. metadata +83 -8
@@ -20,7 +20,7 @@ module RademadeAdmin::FieldHelper
20
20
  elsif data_item.has_uploader?
21
21
  RademadeAdmin::Upload::PreviewService.new(value).uploaded_file_html
22
22
  else
23
- value.to_s
23
+ value.to_s.html_safe
24
24
  end
25
25
  end
26
26
 
@@ -29,10 +29,9 @@ module RademadeAdmin::FieldHelper
29
29
  hash_params.delete(:page)
30
30
  hash_params[name.to_sym] = number
31
31
 
32
- options = '?' + hash_params.map { |k, v| "#{k.to_s}=#{v}" }.join('&')
33
32
  selected = number == request.query_parameters[name.to_sym].to_i
34
-
35
- content_tag(:option, number.to_s, :selected => selected, :value => request.path + options)
33
+ url_params = request.path_parameters.merge(hash_params)
34
+ content_tag(:option, number.to_s, :selected => selected, :value => admin_url_for(url_params, true))
36
35
  end
37
36
 
38
37
  def input_attr(attrs = {})
@@ -17,19 +17,21 @@ module RademadeAdmin::FormHelper
17
17
  )
18
18
  end
19
19
 
20
- def admin_field(form, form_field, model_info)
21
- name = form_field.name
22
- attrs = admin_default_params(name, model_info)
23
- .merge(field_params(form_field))
24
- .merge(input_params(name))
25
- concat form.input(name, input_attr(attrs))
20
+ def admin_field(form, data_item, model_info)
21
+ if can_read_relation data_item
22
+ name = data_item.name
23
+ attrs = admin_default_params(name, model_info)
24
+ .merge(field_params(data_item))
25
+ .merge(input_params(name))
26
+ concat form.input(name, input_attr(attrs))
27
+ end
26
28
  end
27
29
 
28
- def admin_localized_field(form, form_field, model_info, locale)
29
- name = "#{form_field.getter}][#{locale}"
30
- attrs = admin_default_params(form_field.name, model_info)
31
- .merge(field_params(form_field))
32
- .merge(localized_field_params(form_field, locale))
30
+ def admin_localized_field(form, data_item, model_info, locale)
31
+ name = "#{data_item.getter}][#{locale}"
32
+ attrs = admin_default_params(data_item.name, model_info)
33
+ .merge(field_params(data_item))
34
+ .merge(localized_field_params(data_item, locale))
33
35
  concat form.input(name, input_attr(attrs))
34
36
  end
35
37
 
@@ -39,9 +41,9 @@ module RademadeAdmin::FormHelper
39
41
  { :label => model_info.label_for(name) }
40
42
  end
41
43
 
42
- def field_params(form_field)
43
- field_params = form_field.form_params
44
- field_params[:as] = default_field_type(form_field) unless field_params[:as].present?
44
+ def field_params(data_item)
45
+ field_params = data_item.form_params
46
+ field_params[:as] = default_field_type(data_item) unless field_params[:as].present?
45
47
  field_params
46
48
  end
47
49
 
@@ -53,24 +55,28 @@ module RademadeAdmin::FormHelper
53
55
  }
54
56
  end
55
57
 
56
- def localized_field_params(form_field, locale)
58
+ def localized_field_params(data_item, locale)
57
59
  {
58
60
  :input_html => {
59
- :id => "#{form_field.getter}_#{locale}_#{@item.id}",
60
- :value => localized_value(form_field.getter, locale)
61
+ :id => "#{data_item.getter}_#{locale}_#{@item.id}",
62
+ :value => localized_value(data_item.getter, locale)
61
63
  }
62
64
  }
63
65
  end
64
66
 
65
- def default_field_type(form_field)
66
- if form_field.has_relation?
67
- :'rademade_admin/related_select'
68
- elsif form_field.has_uploader?
69
- :'rademade_admin/file'
70
- elsif form_field.date_time?
71
- :'rademade_admin/date_time'
67
+ def default_field_type(data_item)
68
+ if data_item.has_relation?
69
+ if data_item.gallery_relation?
70
+ :'rademade_admin/gallery'
71
+ else
72
+ :'rademade_admin/related_select'
73
+ end
74
+ elsif data_item.has_uploader?
75
+ :'rademade_admin/file'
76
+ elsif data_item.date_time?
77
+ :'rademade_admin/date_time'
72
78
  else
73
- nil
79
+ nil
74
80
  end
75
81
  end
76
82
 
@@ -84,4 +90,8 @@ module RademadeAdmin::FormHelper
84
90
  item_value
85
91
  end
86
92
 
93
+ def can_read_relation(data_item)
94
+ !data_item.has_relation? || can?(:read, data_item.relation.to)
95
+ end
96
+
87
97
  end
@@ -79,20 +79,12 @@ module RademadeAdmin::UriHelper
79
79
  }))
80
80
  end
81
81
 
82
- def admin_url_for(opts)
83
- opts = opts.merge({
84
- :controller => "rademade_admin/#{opts[:controller]}",
85
- :only_path => true
86
- })
87
- begin
88
- Rails.application.routes.url_helpers.url_for(opts)
89
- rescue
90
- begin
91
- RademadeAdmin::Engine.routes.url_helpers.url_for(opts)
92
- rescue
93
- nil
94
- end
95
- end
82
+ def admin_url_for(opts, is_admin_controller = false)
83
+ opts[:only_path] = true
84
+ opts[:controller] = "rademade_admin/#{opts[:controller]}" unless is_admin_controller
85
+ Rails.application.routes.url_helpers.url_for(opts)
86
+ rescue
87
+ RademadeAdmin::Engine.routes.url_helpers.url_for(opts) rescue nil
96
88
  end
97
89
 
98
90
  private
@@ -7,7 +7,7 @@ module RademadeAdmin
7
7
  def input(wrapper_options = {})
8
8
  template.content_tag(
9
9
  :div,
10
- HtmlBuffer.new([file_html]),
10
+ HtmlBuffer.new([file_html, download_button_html]),
11
11
  { :class => 'uploader-block' }
12
12
  )
13
13
  end
@@ -35,19 +35,16 @@ module RademadeAdmin
35
35
  :class => 'btn yellow-btn uploader-input-file',
36
36
  :name => uploader.mounted_as,
37
37
  :data => {
38
- :column => uploader.mounted_as,
39
- :id => object.id.to_s,
40
38
  :saved => object.new_record? ? 0 : 1,
41
- :model => object.class.to_s,
42
- :uploader => uploader.class.to_s,
43
39
  :url => admin_url_for(:controller => 'file', :action => 'upload')
44
- }
40
+ }.merge(uploader_params)
45
41
  })
46
42
  end
47
43
 
48
44
  def input_hidden_html
49
45
  @builder.hidden_field(attribute_name, {
50
- :class => 'uploader-input-hidden hidden'
46
+ :class => 'uploader-input-hidden hidden',
47
+ :value => uploader.url
51
48
  }.merge(input_html_options))
52
49
  end
53
50
 
@@ -67,6 +64,16 @@ module RademadeAdmin
67
64
  })
68
65
  end
69
66
 
67
+ def download_button_html
68
+ template.content_tag(:a, I18n.t('rademade_admin.download_file'), {
69
+ :class => 'btn blue-btn download-btn',
70
+ :href => admin_url_for({
71
+ :controller => 'file',
72
+ :action => 'download'
73
+ }.merge(uploader_params))
74
+ }) unless uploader.file.nil?
75
+ end
76
+
70
77
  def crop_button_html
71
78
  template.content_tag(:span, I18n.t('rademade_admin.crop'), {
72
79
  :class => 'btn red-btn upload-btn',
@@ -74,7 +81,7 @@ module RademadeAdmin
74
81
  :crop => true,
75
82
  :url => admin_url_for(:controller => 'file', :action => 'crop')
76
83
  }
77
- }) if photo_uploader?
84
+ })
78
85
  end
79
86
 
80
87
  def upload_preview_service
@@ -89,5 +96,14 @@ module RademadeAdmin
89
96
  uploader.class.ancestors.include? RademadeAdmin::Uploader::Photo
90
97
  end
91
98
 
99
+ def uploader_params
100
+ {
101
+ :id => object.id.to_s,
102
+ :model => object.class.to_s,
103
+ :uploader => uploader.class.to_s,
104
+ :column => uploader.mounted_as
105
+ }
106
+ end
107
+
92
108
  end
93
109
  end
@@ -0,0 +1,77 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module RademadeAdmin
3
+ class GalleryInput < SimpleForm::Inputs::Base
4
+
5
+ include UriHelper
6
+
7
+ def input(wrapper_options = {})
8
+ template.content_tag(
9
+ :div,
10
+ HtmlBuffer.new([upload_button_html, gallery_images_html, gallery_hidden_html]),
11
+ { :class => 'gallery' }
12
+ )
13
+ end
14
+
15
+ private
16
+
17
+ def upload_button_html
18
+ template.content_tag(:input, '', {
19
+ :class => 'btn gallery-image-upload',
20
+ :type => 'file',
21
+ :multiple => true,
22
+ :data => {
23
+ :url => admin_url_for(:controller => 'gallery', :action => 'upload'),
24
+ :class_name => gallery_class.to_s
25
+ }
26
+ })
27
+ end
28
+
29
+ def gallery_images_html
30
+ is_sortable = gallery_image_info.sortable_relation?
31
+ template.content_tag(:div, HtmlBuffer.new([images_html]), {
32
+ :class => 'gallery-images-container',
33
+ :data => {
34
+ :sortable_url => is_sortable ? admin_url_for(:controller => 'gallery', :action => 'sort') : ''
35
+ }
36
+ })
37
+ end
38
+
39
+ def gallery_hidden_html
40
+ template.content_tag(:input, '', {
41
+ :type => 'hidden',
42
+ :name => "data[#{gallery_info.getter}]",
43
+ :value => gallery.id.to_s
44
+ })
45
+ end
46
+
47
+ def images_html
48
+ html = ''
49
+ preview_service = RademadeAdmin::Upload::GalleryPreviewService.new
50
+ gallery.images.each do |gallery_image|
51
+ html += preview_service.preview_html(gallery_image.image)
52
+ end
53
+ html
54
+ end
55
+
56
+ def gallery
57
+ @gallery ||= object.send(attribute_name) || gallery_class.create
58
+ end
59
+
60
+ def gallery_info
61
+ @gallery_relation ||= model_info(object.class.to_s, attribute_name)
62
+ end
63
+
64
+ def gallery_image_info
65
+ @gallery_image_info ||= model_info(gallery_class, :images)
66
+ end
67
+
68
+ def gallery_class
69
+ @gallery_class ||= gallery_info.relation.to
70
+ end
71
+
72
+ def model_info(class_name, data_item_name)
73
+ RademadeAdmin::Model::Graph.instance.model_info(class_name).data_items.data_item(data_item_name)
74
+ end
75
+
76
+ end
77
+ end
@@ -27,7 +27,7 @@ module RademadeAdmin
27
27
  if multiple?
28
28
  related_list_html
29
29
  else
30
- related_item_html
30
+ RademadeAdmin::HtmlBuffer.new([related_item_html, edit_button_html])
31
31
  end
32
32
  end
33
33
 
@@ -55,11 +55,13 @@ module RademadeAdmin
55
55
  end
56
56
 
57
57
  def reflection_data
58
- {
58
+ search_url = admin_autocomplete_uri(related_to, :format => :json)
59
+ data = {
59
60
  :'rel-multiple' => multiple?,
60
- :'rel-class' => related_to.to_s,
61
- :'search-url' => admin_autocomplete_uri(related_to, :format => :json)
61
+ :'rel-class' => related_to.to_s
62
62
  }
63
+ data[:'search-url'] = search_url unless search_url.nil?
64
+ data
63
65
  end
64
66
 
65
67
  def related_item_html
@@ -74,5 +76,12 @@ module RademadeAdmin
74
76
  end
75
77
  end
76
78
 
79
+ def edit_button_html
80
+ template.content_tag(:button, I18n.t('rademade_admin.edit_related_item'), {
81
+ :class => 'btn blue-btn',
82
+ :'data-edit-relation' => true
83
+ })
84
+ end
85
+
77
86
  end
78
87
  end
@@ -35,7 +35,7 @@ module Autocomplete
35
35
  {
36
36
  :id => item.id.to_s,
37
37
  :text => (item.respond_to?(:to_autocomplete) ? item.to_autocomplete : item.to_s),
38
- :edit_url => admin_edit_form_uri(item)
38
+ :editurl => admin_edit_form_uri(item)
39
39
  }
40
40
  end
41
41
 
@@ -0,0 +1,81 @@
1
+ module RademadeAdmin
2
+ module Gallery
3
+ class Manager
4
+
5
+ attr_reader :gallery_images_html
6
+
7
+ def initialize(class_name)
8
+ @class_name = class_name
9
+ init_gallery_models
10
+ end
11
+
12
+ def upload_images(gallery_id, files)
13
+ find_gallery gallery_id
14
+ upload_gallery_images files
15
+ @gallery.save
16
+ end
17
+
18
+ def crop_image(image_id, crop_data)
19
+ gallery_image = @gallery_image_relation.to.find(image_id)
20
+ uploader = gallery_image.image
21
+ image = uploader.crop_image(crop_data)
22
+ uploader.store!(image)
23
+ gallery_image.save
24
+ uploader
25
+ end
26
+
27
+ def remove_image(image_id)
28
+ @gallery_image_relation.to.find(image_id).destroy
29
+ end
30
+
31
+ def sort_images(images)
32
+ sort_gallery_images images
33
+ end
34
+
35
+ private
36
+
37
+ def init_gallery_models
38
+ gallery_info = RademadeAdmin::Model::Graph.instance.model_info(@class_name)
39
+ @gallery_model = gallery_info.model
40
+ @gallery_image_relation = gallery_info.data_items.data_item(:images).relation
41
+ end
42
+
43
+ def find_gallery(gallery_id)
44
+ @gallery = @gallery_model.find(gallery_id)
45
+ end
46
+
47
+ def upload_gallery_images(images)
48
+ preview_service = RademadeAdmin::Upload::GalleryPreviewService.new
49
+ @gallery_images_html = []
50
+ images.each do |image|
51
+ gallery_image = @gallery_image_relation.to.create
52
+ gallery_image.image.store! image
53
+ update_gallery_image_position(gallery_image)
54
+ @gallery.images << gallery_image
55
+ @gallery_images_html << preview_service.preview_html(gallery_image.image)
56
+ end
57
+ end
58
+
59
+ def sort_gallery_images(images)
60
+ images.each_with_index do |image_id, index|
61
+ gallery_image = @gallery_image_relation.to.find(image_id)
62
+ set_gallery_image_position(gallery_image, index)
63
+ gallery_image.save
64
+ end
65
+ end
66
+
67
+ def update_gallery_image_position(gallery_image)
68
+ if @gallery_image_relation.sortable?
69
+ last_image = @gallery.images.last
70
+ previous_position = last_image.nil? ? 0 : last_image.send(:"#{@gallery_image_relation.sortable_field}")
71
+ set_gallery_image_position(gallery_image, previous_position + 1)
72
+ end
73
+ end
74
+
75
+ def set_gallery_image_position(gallery_image, position)
76
+ gallery_image.send(:"#{@gallery_image_relation.sortable_field}=", position)
77
+ end
78
+
79
+ end
80
+ end
81
+ end
@@ -6,9 +6,9 @@ module RademadeAdmin
6
6
  params.require(:data).permit([:email, :password])
7
7
  user = RademadeAdmin.user_class.get_by_email(params[:data][:email])
8
8
 
9
- error('There is no users with such email', :email) unless user.is_a? RademadeAdmin.user_class
10
- error('Incorrect password', :password) unless user.valid_password? params[:data][:password]
11
- error('Access denied', :email) unless user.admin?
9
+ error(I18n.t('rademade_admin.login_email_not_found'), :email) unless user.is_a? RademadeAdmin.user_class
10
+ error(I18n.t('rademade_admin.login_incorrect_password'), :password) unless user.valid_password? params[:data][:password]
11
+ error(I18n.t('rademade_admin.login_access_denied'), :email) unless user.admin?
12
12
 
13
13
  user
14
14
  end
@@ -16,7 +16,7 @@ module RademadeAdmin
16
16
  def collect_children(parent_model = nil)
17
17
  menu_items = []
18
18
  @model_infos.each do |model_info|
19
- if model_info.parent_model == parent_model && model_info.display_in_menu?
19
+ if model_info.parent_model == parent_model
20
20
  menu_items << RademadeAdmin::MenuService::MenuItem.new(model_info, collect_children(model_info.model))
21
21
  end
22
22
  end