adminpanel 2.1.2 → 2.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/adminpanel.gemspec +20 -18
  3. data/app/assets/javascripts/adminpanel/jquery.knob.js +652 -0
  4. data/app/assets/javascripts/adminpanel/realm.js +20 -18
  5. data/app/assets/javascripts/adminpanel/spinner.js.coffee +3 -3
  6. data/app/controllers/adminpanel/analytics_controller.rb +99 -53
  7. data/app/controllers/adminpanel/auths_controller.rb +1 -1
  8. data/app/controllers/adminpanel/sessions_controller.rb +26 -26
  9. data/app/controllers/concerns/adminpanel/facebook_actions.rb +2 -2
  10. data/app/helpers/adminpanel/adminpanel_form_builder.rb +257 -298
  11. data/app/helpers/adminpanel/analytics_helper.rb +46 -0
  12. data/app/helpers/adminpanel/application_helper.rb +57 -57
  13. data/app/helpers/adminpanel/breadcrumbs_helper.rb +13 -13
  14. data/app/helpers/adminpanel/sessions_helper.rb +20 -20
  15. data/app/helpers/adminpanel/shared_pages_helper.rb +41 -41
  16. data/app/models/adminpanel/gallery.rb +65 -63
  17. data/app/models/adminpanel/image.rb +5 -5
  18. data/app/models/adminpanel/section.rb +61 -53
  19. data/app/models/adminpanel/user.rb +1 -6
  20. data/app/models/concerns/adminpanel/facebook.rb +1 -1
  21. data/app/uploaders/adminpanel/gallery_uploader.rb +1 -1
  22. data/app/views/adminpanel/analytics/_widget_task_statistics.html.erb +63 -0
  23. data/app/views/adminpanel/analytics/fb.html.erb +98 -0
  24. data/app/views/adminpanel/analytics/index.html.erb +8 -8
  25. data/app/views/adminpanel/galleries/_galleries_table.html.erb +12 -12
  26. data/app/views/adminpanel/galleries/move_better.js.erb +1 -1
  27. data/app/views/adminpanel/galleries/move_worst.js.erb +1 -1
  28. data/app/views/adminpanel/sections/_sections_table.html.erb +7 -7
  29. data/app/views/adminpanel/sections/show.html.erb +25 -25
  30. data/app/views/adminpanel/sessions/new.html.erb +22 -22
  31. data/app/views/layouts/_shim.html.erb +1 -1
  32. data/app/views/layouts/_side_menu.html.erb +35 -35
  33. data/app/views/layouts/admin-login.html.erb +22 -22
  34. data/app/views/layouts/admin.html.erb +35 -35
  35. data/app/views/shared/_breadcrumb.html.erb +4 -4
  36. data/app/views/shared/_error_messages.html.erb +15 -15
  37. data/app/views/shared/_form_fields.html.erb +48 -47
  38. data/app/views/shared/_image_fields.html.erb +1 -1
  39. data/config/initializers/pluralization_es.rb +1 -1
  40. data/config/locales/es.yml +38 -2
  41. data/config/routes.rb +5 -4
  42. data/lib/adminpanel/version.rb +1 -1
  43. data/lib/generators/adminpanel/gallery/templates/gallery_migration.rb +5 -5
  44. data/lib/generators/adminpanel/gallery/templates/uploader.rb +1 -1
  45. data/lib/generators/adminpanel/initialize/initialize_generator.rb +54 -54
  46. data/lib/generators/adminpanel/initialize/templates/category_template.rb +1 -1
  47. data/lib/generators/adminpanel/initialize/templates/create_adminpanel_categories_table.rb +5 -5
  48. data/lib/generators/adminpanel/initialize/templates/create_adminpanel_tables.rb +57 -57
  49. data/lib/generators/adminpanel/initialize/templates/section_uploader.rb +1 -1
  50. data/lib/generators/adminpanel/migration/migration_generator.rb +44 -0
  51. data/lib/generators/adminpanel/migration/migration_generator_helper.rb +19 -0
  52. data/lib/generators/adminpanel/resource/resource_generator.rb +60 -245
  53. data/lib/generators/adminpanel/resource/resource_generator_helper.rb +189 -0
  54. data/lib/generators/adminpanel/resource/templates/{controller.rb → adminpanel_controller_template.rb} +2 -2
  55. data/lib/generators/adminpanel/resource/templates/{resource.rb → adminpanel_resource_template.rb} +0 -0
  56. data/test/dummy/app/models/adminpanel/categorization.rb +2 -2
  57. data/test/dummy/app/models/adminpanel/category.rb +3 -3
  58. data/test/dummy/app/models/adminpanel/department.rb +2 -2
  59. data/test/dummy/app/models/adminpanel/item.rb +3 -3
  60. data/test/dummy/app/models/adminpanel/mug.rb +14 -14
  61. data/test/dummy/app/models/adminpanel/product.rb +19 -19
  62. data/test/dummy/app/models/adminpanel/salesman.rb +15 -15
  63. data/test/dummy/app/uploader/adminpanel/photo_uploader.rb +1 -1
  64. data/test/dummy/app/views/layouts/application.html.erb +9 -9
  65. data/test/dummy/config/boot.rb +1 -1
  66. data/test/features/shared/{belongs_to_category_modal_test.rb → form/belongs_to_category_modal_test.rb} +0 -0
  67. data/test/features/shared/{belongs_to_non_category_modal_test.rb → form/belongs_to_non_category_modal_test.rb} +0 -0
  68. data/test/features/shared/{has_many_through_category_modal_test.rb → form/has_many_through_category_modal_test.rb} +0 -0
  69. data/test/features/shared/{has_many_through_non_category_modal_test.rb → form/has_many_through_non_category_modal_test.rb} +0 -0
  70. data/test/features/shared/{edit_test.rb → resource/edit_test.rb} +0 -0
  71. data/test/features/shared/{index_test.rb → resource/index_test.rb} +0 -0
  72. data/test/features/shared/{new_test.rb → resource/new_test.rb} +0 -0
  73. data/test/features/shared/{show_test.rb → resource/show_test.rb} +0 -0
  74. data/test/features/shared/{action_exclution_test.rb → ui/action_exclution_test.rb} +0 -0
  75. data/test/test_helper.rb +1 -1
  76. metadata +44 -32
  77. data/test/dummy/app/controllers/adminpanel/.gitkeep +0 -0
  78. data/test/dummy/app/models/.gitkeep +0 -0
@@ -0,0 +1,19 @@
1
+ module Adminpanel
2
+ module MigrationGeneratorHelper
3
+
4
+ def migration_name
5
+ migration_name_parts = name.underscore.split('_')
6
+ prefix_table = migration_name_parts[(migration_name_parts.size - 2)] # to get 'adminpanel' if exists
7
+ if prefix_table != 'adminpanel'
8
+ table_name = migration_name_parts.pop
9
+ migration_name_parts << 'adminpanel' << table_name
10
+ end
11
+ return migration_name_parts.join('_')
12
+ end
13
+
14
+ def resource_migrating
15
+ resource_name = name.underscore.split('_').pop.singularize
16
+ end
17
+
18
+ end
19
+ end
@@ -1,248 +1,63 @@
1
1
  require 'rails/generators/active_record'
2
- module Adminpanel
3
- class ResourceGenerator < ActiveRecord::Generators::Base
4
- source_root File.expand_path("../templates", __FILE__)
5
- desc "Generate the resource files necessary to use a model"
6
- class_option :'gallery',
7
- :type => :boolean,
8
- :aliases => '-g',
9
- :default => true,
10
- :desc => 'Creates the gallery for this resource'
11
-
12
- argument :fields, :type => :array, :default => [], :banner => "field[:type][:index] field[:type][:index]"
13
-
14
- def change_fields_aliases
15
- fields.each do |attribute|
16
- type = attribute.split(':').second
17
- case type
18
- when 'wysiwyg'
19
- fields.delete(attribute)
20
- fields << attribute.split(':').first + ':' + 'text'
21
- end
22
- end
23
- end
24
-
25
- def generate_model
26
- template 'resource.rb', "app/models/adminpanel/#{lower_singularized_name}.rb"
27
- end
28
-
29
- def generate_controller
30
- if is_a_resource?
31
- template "controller.rb", "app/controllers/adminpanel/#{pluralized_name}_controller.rb"
32
- end
33
- end
34
-
35
- def generate_migration
36
- parameters = fields
37
- parameters.delete_if{ |pair| pair.split(':').second == 'has_many' }
38
- invoke :migration, ["create_adminpanel_#{pluralized_name}", parameters]
39
- puts parameters if ENV['RAILS_ENV']
40
- end
41
-
42
- def generate_gallery
43
- if has_gallery? && is_a_resource?
44
- invoke 'adminpanel:gallery', [lower_singularized_name]
45
- end
46
- end
47
-
48
- def add_resource_to_config
49
- if setup_is_found? && is_a_resource?
50
- inject_into_file 'config/initializers/adminpanel_setup.rb',
51
- after: 'config.displayable_resources = [' do
52
- indent "\n:#{pluralized_name},", 4
53
- end
54
- end
55
- end
56
-
57
- def print_messages
58
- puts "don't forget to restart your server"
59
- end
60
-
61
- private
62
- def setup_is_found?
63
- if Dir.exists?('config') && Dir.exists?('config/initializers') && File.exists?('config/initializers/adminpanel_setup.rb')
64
- true
65
- else
66
- false
67
- end
68
- end
69
-
70
- def is_a_resource?
71
- fields.each do |attribute|
72
- assign_attributes_variables(attribute)
73
- if @attr_type != 'belongs_to'
74
- return true
75
- end
76
- end
77
- false
78
- end
79
-
80
- def has_gallery?
81
- options[:'gallery']
82
- end
83
-
84
- def gallery_name
85
- "#{lower_singularized_name}file"
86
- end
87
-
88
- def lower_singularized_name
89
- name.singularize.downcase
90
- end
91
-
92
- def capitalized_resource
93
- lower_singularized_name.capitalize
94
- end
95
-
96
- def pluralized_name
97
- "#{lower_singularized_name.pluralize}"
98
- end
99
-
100
- def belongs_to_field(resource)
101
- "#{resource.singularize.downcase}_id"
102
- end
103
-
104
- def has_many_field(resource)
105
- "#{resource.singularize.downcase}_ids"
106
- end
107
-
108
- def resource_class_name(resource)
109
- "#{resource.singularize.capitalize}"
110
- end
111
-
112
- def assign_attributes_variables(attribute)
113
- @attr_field = attribute.split(":").first
114
- if attribute.split(":").second.nil?
115
- @attr_type = "string"
116
- else
117
- @attr_type = attribute.split(":").second
118
- end
119
- end
120
-
121
- def symbolized_attributes
122
- fields.map do |attribute|
123
- assign_attributes_variables(attribute)
124
- case @attr_type
125
- when 'belongs_to'
126
- ':' + belongs_to_field(@attr_field)
127
- when 'has_many'
128
- ':' + has_many_field(@attr_field)
129
- else
130
- ":#{attribute.split(':').first}"
131
- end
132
- end.join(",\n")
133
- end
134
-
135
- def get_attribute_hash
136
- fields.map do |attribute|
137
- assign_attributes_variables(attribute)
138
- send(@attr_type + '_form_hash')
139
- end.join(", \n")
140
- end
2
+ require 'generators/adminpanel/resource/resource_generator_helper'
141
3
 
142
- def string_form_hash
143
- attribute_hash(@attr_field, 'text_field')
144
- end
145
-
146
- def float_form_hash
147
- attribute_hash(@attr_field, 'text_field')
148
- end
149
-
150
- def text_form_hash
151
- attribute_hash(@attr_field ,'wysiwyg_field')
152
- end
153
-
154
- def integer_form_hash
155
- attribute_hash(@attr_field, 'number_field')
156
- end
157
-
158
- def boolean_form_hash
159
- attribute_hash(@attr_field, 'boolean')
160
- end
161
-
162
- def datepicker_form_hash
163
- attribute_hash(@attr_field, 'datepicker')
164
- end
165
-
166
- def file_field_form_hash
167
- attribute_hash(gallery_name.pluralize, 'adminpanel_file_field')
168
- end
169
-
170
- def belongs_to_form_hash
171
- attribute_hash(belongs_to_field(@attr_field), 'belongs_to', resource_class_name(@attr_field))
172
- end
173
-
174
- def has_many_form_hash
175
- attribute_hash(has_many_field(resource_class_name(@attr_field)), 'has_many', 'has_many model')
176
- end
177
-
178
- def attribute_hash(name, type, model = '')
179
- if model != ''
180
- model = model_type(model) + ",\n"
181
- end
182
- "{\n" +
183
- indent("'#{name}'" + " => {\n", 2) +
184
- indent(form_type(type), 4) + ",\n" +
185
- indent(label_type, 4) + ",\n" +
186
- indent(placeholder_type, 4) + ",\n" +
187
- indent(model, 4) +
188
- indent("}\n", 2) +
189
- '}'
190
- end
191
-
192
- def form_type(type)
193
- "'type' => '#{type}'"
194
- end
195
-
196
- def label_type
197
- "'label' => '#{@attr_field}'"
198
- end
199
-
200
- def placeholder_type
201
- "'placeholder' => '#{@attr_field}'"
202
- end
203
-
204
- def model_type(type)
205
- "'model' => 'Adminpanel::#{type}'"
206
- end
207
-
208
- def has_associations?
209
- fields.each do |attribute|
210
- assign_attributes_variables(attribute)
211
- if @attr_type == "images" || @attr_type == "belongs_to" || @attr_type == "has_many" || @attr_type == "has_many_through"
212
- return true
213
- end
214
- end
215
- return false
216
- end
217
-
218
- def associations
219
- association = ""
220
- fields.each do |attribute|
221
- assign_attributes_variables(attribute)
222
- if @attr_type == "belongs_to"
223
- association = "#{association}#{belongs_to_association(@attr_field)}"
224
- elsif @attr_type == "has_many" || @attr_type == "has_many_through"
225
- association = "#{association}#{has_many_association(@attr_field)}"
226
- end
227
-
228
- end
229
- association
230
- end
231
-
232
- def belongs_to_association(field)
233
- "belongs_to :#{field.singularize.downcase}\n\t\t"
234
- end
235
-
236
- def has_many_association(field)
237
- return "# has_many :categorizations\n\t\t" +
238
- "# has_many :#{@attr_field}, " +
239
- ":through => :categorizations, " +
240
- ":dependent => :destroy\n\t\t"
241
- end
242
-
243
- def get_gallery
244
- return "\n\t\tmount_images :#{gallery_name.pluralize}\n"
245
- end
246
-
247
- end
4
+ module Adminpanel
5
+ class ResourceGenerator < ActiveRecord::Generators::Base
6
+ include ResourceGeneratorHelper
7
+ source_root File.expand_path('../templates', __FILE__)
8
+ desc 'Generate the resource files necessary to use a model'
9
+ class_option :'gallery',
10
+ :type => :boolean,
11
+ :aliases => '-g',
12
+ :default => true,
13
+ :desc => 'Creates the gallery for this resource'
14
+
15
+ argument :fields, :type => :array, :default => [], :banner => 'field[:type][:index] field[:type][:index]'
16
+
17
+ def change_fields_aliases
18
+ fields.each do |attribute|
19
+ type = attribute.split(':').second
20
+ case type
21
+ when 'wysiwyg'
22
+ fields.delete(attribute)
23
+ fields << attribute.split(':').first + ':' + 'text'
24
+ end
25
+ end
26
+ end
27
+
28
+ def generate_model
29
+ template 'adminpanel_resource_template.rb', "app/models/adminpanel/#{resource_name}.rb"
30
+ end
31
+
32
+ def generate_controller
33
+ if is_a_resource?
34
+ template 'adminpanel_controller_template.rb', "app/controllers/adminpanel/#{pluralized_name}_controller.rb"
35
+ end
36
+ end
37
+
38
+ def generate_migration
39
+ parameters = fields
40
+ parameters.delete_if{ |pair| pair.split(':').second == 'has_many' }
41
+ invoke :migration, ["create_adminpanel_#{pluralized_name}", parameters]
42
+ end
43
+
44
+ def generate_gallery
45
+ if has_gallery? && is_a_resource?
46
+ invoke 'adminpanel:gallery', [resource_name]
47
+ end
48
+ end
49
+
50
+ def add_resource_to_config
51
+ if setup_is_found? && is_a_resource?
52
+ inject_into_file 'config/initializers/adminpanel_setup.rb',
53
+ after: 'config.displayable_resources = [' do
54
+ indent "\n:#{pluralized_name},", 4
55
+ end
56
+ end
57
+ end
58
+
59
+ def print_messages
60
+ puts "don't forget to restart your server and migrate db"
61
+ end
62
+ end
248
63
  end
@@ -0,0 +1,189 @@
1
+ module Adminpanel
2
+ module ResourceGeneratorHelper
3
+ def setup_is_found?
4
+ if Dir.exists?('config') && Dir.exists?('config/initializers') && File.exists?('config/initializers/adminpanel_setup.rb')
5
+ true
6
+ else
7
+ false
8
+ end
9
+ end
10
+
11
+ def belongs_to_field(resource)
12
+ "#{resource.singularize.downcase}_id"
13
+ end
14
+
15
+ def has_many_field(resource)
16
+ "#{resource.singularize.downcase}_ids"
17
+ end
18
+
19
+ def resource_class_name(resource)
20
+ "#{resource.singularize.capitalize}"
21
+ end
22
+
23
+ def assign_attributes_variables(attribute)
24
+ @attr_field = attribute.split(":").first
25
+ if attribute.split(":").second.nil?
26
+ @attr_type = "string"
27
+ else
28
+ @attr_type = attribute.split(":").second
29
+ end
30
+ end
31
+
32
+ def is_a_resource?
33
+ fields.each do |attribute|
34
+ assign_attributes_variables(attribute)
35
+ if @attr_type != 'belongs_to'
36
+ return true
37
+ end
38
+ end
39
+ false
40
+ end
41
+
42
+ def has_gallery?
43
+ options[:'gallery']
44
+ end
45
+
46
+ def resource_name
47
+ name.singularize.downcase #normalize name to downcase and singular
48
+ end
49
+
50
+ def gallery_name
51
+ "#{resource_name}file" #ex: postfile
52
+ end
53
+
54
+ def capitalized_resource
55
+ resource_name.capitalize
56
+ end
57
+
58
+ def pluralized_name
59
+ "#{resource_name.pluralize}"
60
+ end
61
+
62
+ def symbolized_attributes
63
+ fields.map do |attribute|
64
+ assign_attributes_variables(attribute)
65
+ case @attr_type
66
+ when 'belongs_to'
67
+ ':' + belongs_to_field(@attr_field)
68
+ when 'has_many'
69
+ ':' + has_many_field(@attr_field)
70
+ else
71
+ ":#{attribute.split(':').first}"
72
+ end
73
+ end.join(",\n")
74
+ end
75
+
76
+ def get_attribute_hash
77
+ fields.map do |attribute|
78
+ assign_attributes_variables(attribute)
79
+ send(@attr_type + '_form_hash')
80
+ end.join(", \n")
81
+ end
82
+
83
+ def string_form_hash
84
+ attribute_hash(@attr_field, 'text_field')
85
+ end
86
+
87
+ def float_form_hash
88
+ attribute_hash(@attr_field, 'text_field')
89
+ end
90
+
91
+ def text_form_hash
92
+ attribute_hash(@attr_field ,'wysiwyg_field')
93
+ end
94
+
95
+ def integer_form_hash
96
+ attribute_hash(@attr_field, 'number_field')
97
+ end
98
+
99
+ def boolean_form_hash
100
+ attribute_hash(@attr_field, 'boolean')
101
+ end
102
+
103
+ def datepicker_form_hash
104
+ attribute_hash(@attr_field, 'datepicker')
105
+ end
106
+
107
+ def file_field_form_hash
108
+ attribute_hash(gallery_name.pluralize, 'adminpanel_file_field')
109
+ end
110
+
111
+ def belongs_to_form_hash
112
+ attribute_hash(belongs_to_field(@attr_field), 'belongs_to', resource_class_name(@attr_field))
113
+ end
114
+
115
+ def has_many_form_hash
116
+ attribute_hash(has_many_field(resource_class_name(@attr_field)), 'has_many', 'has_many model')
117
+ end
118
+
119
+ def attribute_hash(name, type, model = '')
120
+ if model != ''
121
+ model = model_type(model) + ",\n"
122
+ end
123
+ "{\n" +
124
+ indent("'#{name}'" + " => {\n", 2) +
125
+ indent(form_type(type), 4) + ",\n" +
126
+ indent(label_type, 4) + ",\n" +
127
+ indent(placeholder_type, 4) + ",\n" +
128
+ indent(model, 4) +
129
+ indent("}\n", 2) +
130
+ '}'
131
+ end
132
+
133
+ def form_type(type)
134
+ "'type' => '#{type}'"
135
+ end
136
+
137
+ def label_type
138
+ "'label' => '#{@attr_field}'"
139
+ end
140
+
141
+ def placeholder_type
142
+ "'placeholder' => '#{@attr_field}'"
143
+ end
144
+
145
+ def model_type(type)
146
+ "'model' => 'Adminpanel::#{type}'"
147
+ end
148
+
149
+ def has_associations?
150
+ fields.each do |attribute|
151
+ assign_attributes_variables(attribute)
152
+ if @attr_type == "images" || @attr_type == "belongs_to" || @attr_type == "has_many" || @attr_type == "has_many_through"
153
+ return true
154
+ end
155
+ end
156
+ return false
157
+ end
158
+
159
+ def associations
160
+ association = ""
161
+ fields.each do |attribute|
162
+ assign_attributes_variables(attribute)
163
+ if @attr_type == "belongs_to"
164
+ association = "#{association}#{belongs_to_association(@attr_field)}"
165
+ elsif @attr_type == "has_many" || @attr_type == "has_many_through"
166
+ association = "#{association}#{has_many_association(@attr_field)}"
167
+ end
168
+
169
+ end
170
+ association
171
+ end
172
+
173
+ def belongs_to_association(field)
174
+ "belongs_to :#{field.singularize.downcase}\n\t\t"
175
+ end
176
+
177
+ def has_many_association(field)
178
+ return "# has_many :categorizations\n\t\t" +
179
+ "# has_many :#{@attr_field}, " +
180
+ ":through => :categorizations, " +
181
+ ":dependent => :destroy\n\t\t"
182
+ end
183
+
184
+ def get_gallery
185
+ return "\n\t\tmount_images :#{gallery_name.pluralize}\n"
186
+ end
187
+
188
+ end
189
+ end