rademade_admin 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/rademade_admin.coffee +1 -0
  3. data/app/assets/javascripts/rademade_admin/app/common/cropper.coffee +0 -4
  4. data/app/assets/javascripts/rademade_admin/app/common/image-preview.coffee +33 -0
  5. data/app/assets/javascripts/rademade_admin/app/templates/image-preview-popup.jst.ejs +3 -0
  6. data/app/assets/javascripts/rademade_admin/app/templates/related-item.jst.ejs +2 -2
  7. data/app/assets/javascripts/rademade_admin/library/ckeditor/config.js +1 -0
  8. data/app/assets/stylesheets/edit.css +15 -0
  9. data/app/assets/stylesheets/rademade_admin/base/main.sass +45 -39
  10. data/app/assets/stylesheets/rademade_admin/blocks/buttons/main.sass +6 -1
  11. data/app/assets/stylesheets/rademade_admin/blocks/form/select2.sass +85 -60
  12. data/app/controllers/rademade_admin/model_controller.rb +3 -0
  13. data/app/helpers/rademade_admin/field_helper.rb +25 -13
  14. data/app/helpers/rademade_admin/form_helper.rb +4 -6
  15. data/app/helpers/rademade_admin/uri_helper.rb +3 -3
  16. data/app/services/csv_service.rb +38 -0
  17. data/app/services/linker.rb +3 -1
  18. data/app/services/model_controller/instance_options.rb +7 -2
  19. data/app/services/model_controller/notifier.rb +15 -19
  20. data/app/services/model_controller/templates.rb +1 -0
  21. data/app/services/saver.rb +6 -1
  22. data/app/services/template_service.rb +38 -19
  23. data/app/services/upload/preview_service.rb +2 -1
  24. data/app/views/rademade_admin/_blocks/_form.html.erb +6 -5
  25. data/app/views/rademade_admin/_blocks/button/_hide.html.erb +2 -2
  26. data/app/views/rademade_admin/_layouts/main.html.erb +3 -6
  27. data/app/views/rademade_admin/abstract/index.html.erb +4 -2
  28. data/config/locales/rademade_admin.en.yml +2 -1
  29. data/config/locales/rademade_admin.ru.yml +2 -1
  30. data/lib/rademade_admin/{hrml_buffer.rb → html_buffer.rb} +0 -0
  31. data/lib/rademade_admin/input/related_select_input/related_list.rb +8 -5
  32. data/lib/rademade_admin/model/adapter/data/mongoid.rb +1 -1
  33. data/lib/rademade_admin/model/adapter/query/active_record.rb +1 -1
  34. data/lib/rademade_admin/model/configuration.rb +17 -1
  35. data/lib/rademade_admin/model/configuration/csv_fields.rb +12 -0
  36. data/lib/rademade_admin/model/configuration/list_field.rb +5 -1
  37. data/lib/rademade_admin/model/info.rb +10 -1
  38. data/lib/rademade_admin/model/info/data_item.rb +31 -13
  39. data/lib/rademade_admin/model/info/data_item/initializer.rb +37 -0
  40. data/lib/rademade_admin/model/info/data_items.rb +11 -1
  41. data/lib/rademade_admin/model/info/fields.rb +39 -26
  42. data/lib/rademade_admin/version.rb +1 -1
  43. metadata +22 -4
  44. data/app/assets/javascripts/rademade_admin/library/jquery/jquery.tablednd.js +0 -1
@@ -61,7 +61,7 @@ module RademadeAdmin
61
61
  :has_many => has_many_relations.include?(type),
62
62
  :sortable => is_sortable,
63
63
  :sortable_field => is_sortable ? relation_info.sortable_field : nil,
64
- :foreign_key => relation_info.foreign_key.to_sym
64
+ :foreign_key => relation_info.foreign_key ? relation_info.foreign_key.to_sym : nil
65
65
  })
66
66
  end
67
67
  relations
@@ -35,7 +35,7 @@ module RademadeAdmin
35
35
  field = "`#{part[:field]}`"
36
36
  if part[:value].is_a? Regexp
37
37
  # hack temporary fix
38
- condition += "#{field} REGEXP ?"
38
+ condition += "LOWER(#{field}) REGEXP ?"
39
39
  part[:value] = part[:value].source
40
40
  elsif part[:value].is_a? Array
41
41
  condition += "#{field} IN (?)"
@@ -29,6 +29,14 @@ module RademadeAdmin
29
29
  @list_fields ||= RademadeAdmin::Model::Configuration::ListFields.new
30
30
  end
31
31
 
32
+ # Return configured csv info
33
+ #
34
+ # @return [RademadeAdmin::Model::Configuration::CsvFields]
35
+ #
36
+ def csv_fields
37
+ @csv_fields ||= RademadeAdmin::Model::Configuration::CsvFields.new
38
+ end
39
+
32
40
  # Return configured fields info
33
41
  #
34
42
  # @return [RademadeAdmin::Model::Configuration::FormFields]
@@ -46,7 +54,11 @@ module RademadeAdmin
46
54
  end
47
55
 
48
56
  def all_field_names
49
- @all_field_names ||= Set.new(list_fields.all.map(&:name) + form_fields.all.map(&:name))
57
+ @all_field_names ||= Set.new([
58
+ list_fields.all.map(&:name),
59
+ form_fields.all.map(&:name),
60
+ csv_fields.all.map(&:name)
61
+ ].flatten(1))
50
62
  end
51
63
 
52
64
  def model(model_name)
@@ -79,6 +91,10 @@ module RademadeAdmin
79
91
  list_fields.configure(*field_options, &block)
80
92
  end
81
93
 
94
+ def csv(*field_options, &block)
95
+ csv_fields.configure(*field_options, &block)
96
+ end
97
+
82
98
  def form(*field_options, &block)
83
99
  form_fields.configure(*field_options, &block)
84
100
  end
@@ -0,0 +1,12 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'rademade_admin/model/configuration/list_fields'
3
+
4
+ module RademadeAdmin
5
+ module Model
6
+ class Configuration
7
+ class CsvFields < ListFields
8
+
9
+ end
10
+ end
11
+ end
12
+ end
@@ -12,7 +12,11 @@ module RademadeAdmin
12
12
  end
13
13
 
14
14
  def preview_accessor
15
- @opts.has_key?(:method) ? @opts[:method] : nil
15
+ @opts[:method]
16
+ end
17
+
18
+ def preview_handler
19
+ @opts[:handler]
16
20
  end
17
21
 
18
22
  end
@@ -57,17 +57,25 @@ module RademadeAdmin
57
57
  @model_configuration.menu_count_block.try(:call)
58
58
  end
59
59
 
60
+ # TODO it's not Model::Info logic. Move method
60
61
  def preview_url(item)
61
62
  unless @model_configuration.preview_url_block.nil?
62
63
  # calls within url helpers context
63
64
  Rails.application.routes.url_helpers.instance_exec(item, &@model_configuration.preview_url_block)
64
65
  end
66
+ rescue
67
+ nil
65
68
  end
66
69
 
67
70
  def data_items
68
71
  fields.data_items
69
72
  end
70
73
 
74
+ # TODO it's not Model::Info logic. Move method
75
+ def has_csv?
76
+ not data_items.csv_fields.empty?
77
+ end
78
+
71
79
  # Fields data class
72
80
  #
73
81
  # @return [RademadeAdmin::Model::Info::Fields]
@@ -95,6 +103,8 @@ module RademadeAdmin
95
103
  model_reflection.data_adapter
96
104
  end
97
105
 
106
+ # TODO add galleries component
107
+
98
108
  # @return [RademadeAdmin::Model::Info::Relations]
99
109
  def relations
100
110
  @model_relations ||= RademadeAdmin::Model::Info::Relations.new(_data_adapter)
@@ -104,7 +114,6 @@ module RademadeAdmin
104
114
  def uploaders
105
115
  @model_uploaders ||= RademadeAdmin::Model::Info::Uploaders.new(_data_adapter)
106
116
  end
107
-
108
117
  end
109
118
  end
110
119
  end
@@ -4,36 +4,44 @@ module RademadeAdmin
4
4
  class Info
5
5
  class DataItem
6
6
 
7
+ # TODO extract sub classes
8
+
7
9
  attr_accessor :name,
8
10
  :field,
9
11
  :relation,
10
12
  :label,
13
+ :has_uploader,
14
+ :order_column,
15
+ :form_params,
16
+
11
17
  :form_position,
12
18
  :list_position,
13
- :has_uploader,
14
- :order_column
19
+ :csv_position,
20
+
21
+ :in_form,
22
+ :in_list,
23
+ :in_csv,
15
24
 
16
- attr_writer :in_form,
17
- :form_params,
18
- :in_list,
19
- :preview_accessor
25
+ :list_preview_accessor,
26
+ :list_preview_handler,
27
+ :csv_preview_accessor,
28
+ :csv_preview_handler
20
29
 
21
30
  #
22
31
  # @param name [Symbol]
23
32
  # @param field [RademadeAdmin::Model::Info::Field]
24
33
  # @param relation [RademadeAdmin::Model::Info::Relation]
25
- # @param has_uploader [Boolean]
34
+ # @param order_column [String]
26
35
  #
27
- def initialize(name, field = nil, relation = nil, has_uploader = false, order_column = nil)
36
+ def initialize(name, field = nil, relation = nil, order_column = nil)
28
37
  @name = name
29
38
  @field = field
30
39
  @relation = relation
31
- @has_uploader = has_uploader
32
40
  @order_column = order_column
41
+ @has_uploader = false
33
42
  @in_list = false
34
43
  @in_form = false
35
- @form_params = nil
36
- @preview_accessor = nil
44
+ @in_csv = false
37
45
  end
38
46
 
39
47
  def has_name?(name)
@@ -81,14 +89,24 @@ module RademadeAdmin
81
89
  @setter ||= :"#{getter}="
82
90
  end
83
91
 
84
- def preview_accessor
85
- @preview_accessor.nil? ? getter : @preview_accessor
92
+ def list_preview_accessor
93
+ return @list_preview_accessor if @list_preview_accessor
94
+ getter
95
+ end
96
+
97
+ def csv_preview_accessor
98
+ return @csv_preview_accessor if @csv_preview_accessor
99
+ getter
86
100
  end
87
101
 
88
102
  def in_list?
89
103
  @in_list
90
104
  end
91
105
 
106
+ def in_csv?
107
+ @in_csv
108
+ end
109
+
92
110
  def in_form?
93
111
  @in_form
94
112
  end
@@ -0,0 +1,37 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module RademadeAdmin
3
+ module Model
4
+ class Info
5
+ class DataItem
6
+ class Initializer
7
+
8
+ def auto
9
+ return from_relation if @relation
10
+ return form_field if @field
11
+ raise 'No relation and field given for DateItem initialization' # TODO custom exception
12
+ end
13
+
14
+ def from_relation
15
+ build(@relation.name, @relation.foreign_key)
16
+ end
17
+
18
+ def form_field
19
+ name = @field.name
20
+ build(name, name)
21
+ end
22
+
23
+ def build(name, order_column)
24
+ RademadeAdmin::Model::Info::DataItem.new(name, @field, @relation, order_column)
25
+ end
26
+
27
+ protected
28
+
29
+ def initialize(field, relation)
30
+ @field, @relation = field, relation
31
+ end
32
+
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -4,6 +4,7 @@ module RademadeAdmin
4
4
  class Info
5
5
  class DataItems
6
6
  include ::Enumerable
7
+
7
8
  # rm_todo extract mixins
8
9
 
9
10
  UNINFORMATIVE_FIELDS = [:_id, :deleted_at, :position]
@@ -17,7 +18,7 @@ module RademadeAdmin
17
18
  end
18
19
 
19
20
  def each(&block)
20
- items.each(&block)
21
+ items.values.each(&block)
21
22
  end
22
23
 
23
24
  # @param data_item [RademadeAdmin::Model::Info::DataItem]
@@ -57,6 +58,10 @@ module RademadeAdmin
57
58
  @list_fields ||= collect_list_fields
58
59
  end
59
60
 
61
+ def csv_fields
62
+ @csv_fields ||= collect_csv_fields
63
+ end
64
+
60
65
  def filter_fields
61
66
  @autocomplete_fields ||= collect_field_names { |data_item| data_item.string_field? }
62
67
  end
@@ -95,6 +100,11 @@ module RademadeAdmin
95
100
  fields.empty? ? _default_fields.values : fields.values.sort_by(&:list_position)
96
101
  end
97
102
 
103
+ def collect_csv_fields
104
+ fields = items.select { |_, data_item| data_item.in_csv? }
105
+ fields.empty? ? [] : fields.values.sort_by(&:csv_position)
106
+ end
107
+
98
108
  def collect_form_fields
99
109
  fields = items.select { |_, data_item| data_item.in_form? }
100
110
  fields.empty? ? _default_fields : fields
@@ -24,56 +24,59 @@ module RademadeAdmin
24
24
  end
25
25
 
26
26
  def data_items
27
- @data_items ||= init_data_items
27
+ @data_items ||= build_items
28
28
  end
29
29
 
30
- private
30
+ protected
31
31
 
32
- def init_data_items
32
+ def item_initializer
33
+ RademadeAdmin::Model::Info::DataItem::Initializer
34
+ end
35
+
36
+ def build_items
33
37
  data_items = RademadeAdmin::Model::Info::DataItems.new
34
38
  used_relations = []
35
39
 
40
+ # TODO extract sub - methods
36
41
  @data_adapter.fields.each do |_, field|
37
42
  relation = field.relation_name.nil? ? nil : @data_adapter.relation(field.relation_name)
38
43
  used_relations << field.relation_name if relation
39
- data_items.add_data_item(init_data_item(field, relation))
44
+ data_item = item_initializer.new(field, relation).auto
45
+ data_items.add_data_item( data_item )
40
46
  end
41
47
 
42
48
  @data_adapter.relations.each do |_, relation|
43
49
  unless used_relations.include? relation.name
44
- data_items.add_data_item(init_data_item(nil, relation))
50
+ data_items.add_data_item( item_initializer.new(nil, relation).from_relation )
45
51
  end
46
52
  end
47
53
 
48
54
  @model_configuration.all_field_names.each do |field_name|
49
55
  unless data_items.has_field?(field_name)
50
- data_item = RademadeAdmin::Model::Info::DataItem.new(field_name)
51
- add_configuration_data(data_item, field_name)
52
- data_items.add_data_item(data_item)
56
+ data_items.add_data_item( item_initializer.new(nil, nil).build(field_name, nil) )
53
57
  end
54
58
  end
55
59
 
60
+ configure_items(data_items)
61
+
56
62
  data_items
57
63
  end
58
64
 
59
- def init_data_item(field, relation)
60
- if relation.nil?
61
- name = field.name
62
- order_column = name
63
- else
64
- name = relation.name
65
- order_column = relation.foreign_key
66
- end
67
- data_item = RademadeAdmin::Model::Info::DataItem.new(
68
- name, field, relation,
69
- @uploaders.has_uploader?(name),
70
- @data_adapter.columns.include?(order_column) ? order_column : nil
71
- )
72
- add_configuration_data(data_item, name)
73
- data_item
65
+ def configure_items(data_items)
66
+ data_items.each { |item| configure_item(item) }
67
+
74
68
  end
75
69
 
76
- def add_configuration_data(data_item, name)
70
+ # @param [RademadeAdmin::Model::Info::DataItem]
71
+ def configure_item(data_item)
72
+
73
+ # TODO extract sub methods
74
+
75
+ name = data_item.name
76
+
77
+ data_item.has_uploader = @uploaders.has_uploader?(name)
78
+ data_item.order_column = nil unless @data_adapter.columns.include?(data_item.order_column)
79
+
77
80
  @model_configuration.field_labels.find(name) do |label_data|
78
81
  data_item.label = label_data.label
79
82
  end
@@ -84,11 +87,21 @@ module RademadeAdmin
84
87
  data_item.form_position = index
85
88
  end
86
89
 
87
- @model_configuration.list_fields.find_with_index(name) do |list_field_data, index|
90
+ @model_configuration.list_fields.find_with_index(name) do |data, index|
88
91
  data_item.in_list = true
89
- data_item.preview_accessor = list_field_data.preview_accessor
92
+ data_item.list_preview_accessor = data.preview_accessor
93
+ data_item.list_preview_handler = data.preview_handler
90
94
  data_item.list_position = index
91
95
  end
96
+
97
+ @model_configuration.csv_fields.find_with_index(name) do |data, index|
98
+ data_item.in_csv = true
99
+ data_item.csv_preview_accessor = data.preview_accessor
100
+ data_item.csv_preview_handler = data.preview_handler
101
+ data_item.csv_position = index
102
+ end
103
+
104
+ data_item
92
105
  end
93
106
 
94
107
  end
@@ -1,4 +1,4 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module RademadeAdmin
3
- VERSION = "0.1.5"
3
+ VERSION = "0.1.6"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rademade_admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladislav Melanitskiy
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-02-27 00:00:00.000000000 Z
13
+ date: 2015-06-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -142,6 +142,20 @@ dependencies:
142
142
  - - '='
143
143
  - !ruby/object:Gem::Version
144
144
  version: 2.11.0
145
+ - !ruby/object:Gem::Dependency
146
+ name: sass
147
+ requirement: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - "~>"
150
+ - !ruby/object:Gem::Version
151
+ version: '3.1'
152
+ type: :runtime
153
+ prerelease: false
154
+ version_requirements: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - "~>"
157
+ - !ruby/object:Gem::Version
158
+ version: '3.1'
145
159
  - !ruby/object:Gem::Dependency
146
160
  name: sass-rails
147
161
  requirement: !ruby/object:Gem::Requirement
@@ -408,6 +422,7 @@ files:
408
422
  - app/assets/javascripts/rademade_admin/app/common/datetime-picker.coffee
409
423
  - app/assets/javascripts/rademade_admin/app/common/dnd-sort.coffee
410
424
  - app/assets/javascripts/rademade_admin/app/common/droplist.coffee
425
+ - app/assets/javascripts/rademade_admin/app/common/image-preview.coffee
411
426
  - app/assets/javascripts/rademade_admin/app/common/lang-panel.coffee
412
427
  - app/assets/javascripts/rademade_admin/app/common/location.coffee.erb
413
428
  - app/assets/javascripts/rademade_admin/app/common/pagination.coffee
@@ -434,13 +449,13 @@ files:
434
449
  - app/assets/javascripts/rademade_admin/app/select2/related/view.coffee
435
450
  - app/assets/javascripts/rademade_admin/app/select2/view.coffee
436
451
  - app/assets/javascripts/rademade_admin/app/templates/crop.jst.ejs
452
+ - app/assets/javascripts/rademade_admin/app/templates/image-preview-popup.jst.ejs
437
453
  - app/assets/javascripts/rademade_admin/app/templates/related-item.jst.ejs
438
454
  - app/assets/javascripts/rademade_admin/form/form-ajax.coffee
439
455
  - app/assets/javascripts/rademade_admin/form/form-initializater.coffee
440
456
  - app/assets/javascripts/rademade_admin/form/form-validation.coffee
441
457
  - app/assets/javascripts/rademade_admin/form/form.coffee
442
458
  - app/assets/javascripts/rademade_admin/library/ckeditor/config.js
443
- - app/assets/javascripts/rademade_admin/library/jquery/jquery.tablednd.js
444
459
  - app/assets/javascripts/rademade_admin/library/notifier.custom.min.js
445
460
  - app/assets/javascripts/rademade_admin/settings/ajax-csrf.coffee
446
461
  - app/assets/stylesheets/edit.css
@@ -510,6 +525,7 @@ files:
510
525
  - app/models/rademade_admin/ability.rb
511
526
  - app/serializers/autocomplete/base_serializer.rb
512
527
  - app/serializers/autocomplete/link_serializer.rb
528
+ - app/services/csv_service.rb
513
529
  - app/services/gallery/manager.rb
514
530
  - app/services/linker.rb
515
531
  - app/services/loader_service.rb
@@ -589,7 +605,7 @@ files:
589
605
  - lib/rademade_admin/file_info_formatter.rb
590
606
  - lib/rademade_admin/gallery.rb
591
607
  - lib/rademade_admin/hideable.rb
592
- - lib/rademade_admin/hrml_buffer.rb
608
+ - lib/rademade_admin/html_buffer.rb
593
609
  - lib/rademade_admin/input/related_select_input/model_data.rb
594
610
  - lib/rademade_admin/input/related_select_input/related_list.rb
595
611
  - lib/rademade_admin/model/adapter/data.rb
@@ -599,6 +615,7 @@ files:
599
615
  - lib/rademade_admin/model/adapter/query/active_record.rb
600
616
  - lib/rademade_admin/model/adapter/query/mongoid.rb
601
617
  - lib/rademade_admin/model/configuration.rb
618
+ - lib/rademade_admin/model/configuration/csv_fields.rb
602
619
  - lib/rademade_admin/model/configuration/field_label.rb
603
620
  - lib/rademade_admin/model/configuration/fields.rb
604
621
  - lib/rademade_admin/model/configuration/fields_labels.rb
@@ -609,6 +626,7 @@ files:
609
626
  - lib/rademade_admin/model/graph.rb
610
627
  - lib/rademade_admin/model/info.rb
611
628
  - lib/rademade_admin/model/info/data_item.rb
629
+ - lib/rademade_admin/model/info/data_item/initializer.rb
612
630
  - lib/rademade_admin/model/info/data_items.rb
613
631
  - lib/rademade_admin/model/info/field.rb
614
632
  - lib/rademade_admin/model/info/fields.rb