adminpanel 1.2.5 → 1.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/.travis.yml +0 -1
  2. data/README.md +9 -6
  3. data/Rakefile +1 -1
  4. data/app/helpers/adminpanel/application_helper.rb +2 -2
  5. data/app/helpers/adminpanel/custom_form_builder.rb +45 -9
  6. data/app/helpers/adminpanel/shared_pages_helper.rb +10 -3
  7. data/app/models/adminpanel/gallery.rb +6 -0
  8. data/app/models/adminpanel/image.rb +3 -8
  9. data/app/models/adminpanel/section.rb +16 -6
  10. data/app/uploaders/adminpanel/image_uploader.rb +2 -2
  11. data/app/views/adminpanel/categories/_categories_table.html.erb +1 -1
  12. data/app/views/adminpanel/categories/index.html.erb +9 -8
  13. data/app/views/adminpanel/galleries/edit.html.erb +3 -10
  14. data/app/views/adminpanel/galleries/index.html.erb +2 -2
  15. data/app/views/adminpanel/galleries/new.html.erb +3 -3
  16. data/app/views/adminpanel/sections/edit.html.erb +11 -15
  17. data/app/views/shared/_form_fields.html.erb +16 -9
  18. data/app/views/shared/_image_fields.html.erb +2 -23
  19. data/app/views/shared/_init_editor.html.erb +12 -12
  20. data/app/views/shared/show.html.erb +4 -3
  21. data/config/locales/es.yml +3 -0
  22. data/lib/adminpanel.rb +1 -1
  23. data/lib/adminpanel/active_record/adminpanel_extension.rb +142 -0
  24. data/lib/adminpanel/version.rb +1 -1
  25. data/lib/generators/adminpanel/gallery/gallery_generator.rb +41 -0
  26. data/lib/generators/adminpanel/gallery/templates/gallery_migration.rb +11 -0
  27. data/lib/generators/adminpanel/gallery/templates/gallery_template.rb +8 -0
  28. data/lib/generators/adminpanel/gallery/templates/uploader.rb +86 -0
  29. data/lib/generators/adminpanel/initialize/initialize_generator.rb +22 -12
  30. data/lib/generators/adminpanel/initialize/templates/create_adminpanel_categories_table.rb +1 -1
  31. data/lib/generators/adminpanel/initialize/templates/create_adminpanel_tables.rb +3 -4
  32. data/lib/generators/adminpanel/initialize/templates/section_uploader.rb +86 -0
  33. data/lib/generators/adminpanel/resource/resource_generator.rb +72 -22
  34. data/lib/tasks/adminpanel/adminpanel.rake +1 -1
  35. data/spec/dummy/.gitignore +2 -1
  36. data/spec/dummy/app/controllers/adminpanel/categories_controller.rb +2 -2
  37. data/spec/dummy/app/controllers/adminpanel/products_controller.rb +3 -3
  38. data/spec/dummy/app/models/adminpanel/categorization.rb +17 -17
  39. data/spec/dummy/app/models/adminpanel/photo.rb +8 -0
  40. data/spec/dummy/app/models/adminpanel/product.rb +49 -26
  41. data/spec/dummy/app/uploader/adminpanel/photo_uploader.rb +86 -0
  42. data/spec/dummy/app/uploader/adminpanel/section_uploader.rb +86 -0
  43. data/spec/features/section_pages_spec.rb +4 -4
  44. data/spec/features/shared_pages_spec.rb +15 -15
  45. data/spec/generators/gallery_generator_spec.rb +53 -0
  46. data/spec/generators/initialize_generator_spec.rb +19 -12
  47. data/spec/generators/resource_generator_spec.rb +44 -37
  48. data/spec/support/define_factory_models.rb +3 -5
  49. data/spec/support/test_database.rb +8 -3
  50. data/spec/tasks/adminpanel_rake_spec.rb +5 -5
  51. metadata +18 -7
  52. data/app/helpers/adminpanel/class_definitions_helper.rb +0 -10
  53. data/app/views/adminpanel/sections/_image_fields.html.erb +0 -24
  54. data/lib/adminpanel/active_record_extension.rb +0 -123
@@ -1,24 +1,3 @@
1
1
  <div class="product-image">
2
- <% unless f.object.new_record? %>
3
- <div class="control-group">
4
- <div class="controls">
5
- <%= image_tag f.object.file_url(:thumb) %>
6
- </div>
7
- </div>
8
- <% end %>
9
- <div class="control-group">
10
- <%= f.label t("model.Adminpanel::Image"), :class => "control-label" %>
11
- <div class="controls">
12
- <%= f.file_field :file %>
13
- <%= f.hidden_field :model, :value => model_name %>
14
- <%= f.hidden_field :_destroy %>
15
- <%=
16
- content_tag(
17
- :button,
18
- t("action.delete"),
19
- :class => "btn btn-danger remove_fields"
20
- )
21
- %>
22
- </div>
23
- </div>
24
- </div>
2
+ <%= f.gallery_field :file %>
3
+ </div>
@@ -1,24 +1,24 @@
1
1
  var elements = document.querySelectorAll('#<%= field_var %>'),
2
2
  <%= field_var %> = new MediumEditor(elements,{
3
- buttons: [
4
- 'bold',
5
- 'italic',
6
- 'underline',
7
- 'anchor',
8
- 'header1',
9
- 'header2',
10
- 'quote',
11
- 'unorderedlist'
12
- ]
3
+ buttons: [
4
+ 'bold',
5
+ 'italic',
6
+ 'underline',
7
+ 'anchor',
8
+ 'header1',
9
+ 'header2',
10
+ 'quote',
11
+ 'unorderedlist'
12
+ ]
13
13
  });
14
14
 
15
15
  $(document).ready(function(){
16
16
  $("#<%= field_var %>").on("focusout", function(){
17
-
17
+
18
18
 
19
19
  //alert(document.getElementById("<%= field_var %>-field").value);
20
20
  //.value = <%= field_var %>.serialize()["editable"]["value"];
21
21
  //$("#<%= field_var %>-field").value = <%= field_var %>.serialize()["editable"]["value"];
22
22
  document.getElementById("<%= field_var %>-field").value = <%= field_var %>.serialize()["<%= field_var %>"]["value"];
23
23
  });
24
- });
24
+ });
@@ -1,6 +1,6 @@
1
1
  <% provide(:page_title, t("action.view") + " #{@model.display_name.capitalize}") -%>
2
2
  <% breadcrumb_add(
3
- @model.display_name.capitalize.pluralize,
3
+ @model.display_name.capitalize.pluralize,
4
4
  {
5
5
  :controller => params[:controller],
6
6
  :action => "index"
@@ -59,13 +59,14 @@
59
59
  <div class="widget-body row-fluid">
60
60
  <div id="gallery-container" class="js-masonry"
61
61
  data-masonry-options='{ "columnWidth": 3, "itemSelector": ".gallery-item" }'>
62
- <% resource.images.each do |image|%>
62
+ <% resource.send(@model.get_image_relationship).each do |image|%>
63
63
  <div class="gallery-item">
64
64
  <%= link_to (image_tag image.file_url(:thumb)), image.file.to_s, :rel => "group", :name => @model.display_name %>
65
+ <%#= link_to (image_tag image.file_url(:thumb)), image.file.to_s, :rel => "group", :name => @model.display_name %>
65
66
  </div>
66
67
  <% end %>
67
68
  </div>
68
69
  </div>
69
70
  </div>
70
71
  <% end %>
71
- </div>
72
+ </div>
@@ -74,9 +74,12 @@ es:
74
74
  description: "Descripción"
75
75
  edit: "Editar Sección"
76
76
  default: "Sin Sección"
77
+ image: "Imagen"
77
78
  session:
78
79
  password: "Contraseña"
79
80
  email: "Correo electrónico"
80
81
  other:
81
82
  choose: "Selecciona %{model} pertenecientes"
82
83
  no description: "No tiene descripción aún"
84
+ key:
85
+ telephone: 'Teléfono'
data/lib/adminpanel.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require "adminpanel/version"
2
2
  require "adminpanel/engine"
3
3
  require "inherited_resources"
4
- require "adminpanel/active_record_extension"
4
+ require "adminpanel/active_record/adminpanel_extension"
5
5
  require "carrierwave"
6
6
  require "carrierwave/orm/activerecord"
7
7
  require "google/api_client"
@@ -0,0 +1,142 @@
1
+ module ActiveRecord
2
+ module AdminpanelExtension
3
+ extend ActiveSupport::Concern
4
+ #instance methods
5
+ # def foo
6
+
7
+ # end
8
+
9
+ # static(class) methods
10
+ module ClassMethods
11
+
12
+ def mount_images(relation)
13
+ has_many relation, :dependent => :destroy
14
+ accepts_nested_attributes_for relation, :allow_destroy => true
15
+ end
16
+
17
+ def form_attributes
18
+ [{
19
+ "name" => {
20
+ "type" => "text_field",
21
+ "name" => "name"
22
+ }
23
+ }]
24
+ end
25
+
26
+ def display_name
27
+ "display_name"
28
+ end
29
+
30
+ def get_attribute_name(field)
31
+ form_attributes.each do |attribute|
32
+ attribute.each do |name, properties|
33
+ if name == field
34
+ return properties["name"]
35
+ end
36
+ end
37
+ end
38
+ return ":("
39
+ end
40
+
41
+
42
+ def get_attribute_name(field)
43
+ form_attributes.each do |attribute|
44
+ attribute.each do |name, properties|
45
+ if name == field
46
+ return properties["name"]
47
+ end
48
+ end
49
+ end
50
+ return ":("
51
+ end
52
+
53
+ def get_attribute_label(field)
54
+ form_attributes.each do |attribute|
55
+ attribute.each do |name, properties|
56
+ if name == field
57
+ return properties["label"]
58
+ end
59
+ end
60
+ end
61
+ return ":("
62
+ end
63
+
64
+ def get_attribute_placeholder(field)
65
+ form_attributes.each do |attribute|
66
+ attribute.each do |name, properties|
67
+ if name == field
68
+ return properties["placeholder"]
69
+ end
70
+ end
71
+ end
72
+ return ":("
73
+ end
74
+
75
+ def display_attributes
76
+ display_attributes = []
77
+ form_attributes.each do |attribute|
78
+ attribute.each do |name, properties|
79
+ if properties["show"].nil? || properties["show"] == "true"
80
+ display_attributes << attribute
81
+ end
82
+ end
83
+ end
84
+
85
+ return display_attributes
86
+ end
87
+
88
+ def has_images?
89
+ form_attributes.each do |fields|
90
+ fields.each do |attribute, properties|
91
+ if properties["type"] == "adminpanel_file_field"
92
+ return true
93
+ end
94
+ end
95
+ end
96
+ return false
97
+ end
98
+
99
+ def get_image_relationship
100
+ form_attributes.each do |fields|
101
+ fields.each do |attribute, properties|
102
+ if properties["type"] == "adminpanel_file_field"
103
+ return attribute
104
+ end
105
+ end
106
+ end
107
+ return false
108
+ end
109
+
110
+ def belongs_to_relationships
111
+ belongs_to_classes = []
112
+ form_attributes.each do |fields|
113
+ fields.each do |attribute, properties|
114
+ if properties["type"] == "belongs_to"
115
+ belongs_to_classes << properties["model"].classify.constantize
116
+ end
117
+ end
118
+ end
119
+ return belongs_to_classes
120
+ end
121
+
122
+ def has_many_relationships
123
+ has_many_classes = []
124
+ form_attributes.each do |fields|
125
+ fields.each do |attribute, properties|
126
+ if properties["type"] == "has_many"
127
+ has_many_classes << properties["model"].classify.constantize
128
+ end
129
+ end
130
+ end
131
+ return has_many_classes
132
+ end
133
+
134
+ def icon
135
+ "icon-truck"
136
+ end
137
+ end
138
+ end
139
+
140
+ # include the extension
141
+ ActiveRecord::Base.send(:include, AdminpanelExtension)
142
+ end
@@ -1,3 +1,3 @@
1
1
  module Adminpanel
2
- VERSION = "1.2.5"
2
+ VERSION = "1.2.6"
3
3
  end
@@ -0,0 +1,41 @@
1
+ require 'rails/generators/active_record'
2
+ module Adminpanel
3
+ module Generators
4
+ class GalleryGenerator < ActiveRecord::Generators::Base
5
+ source_root File.expand_path("../templates", __FILE__)
6
+ desc "Generate the resource files necessary to use a model"
7
+
8
+ # argument :reference_model,
9
+ # :aliases => "-m",
10
+ # :type => :string,
11
+ # :require => true,
12
+ # :desc => 'Choose the model that you want the uploader to belong_to'
13
+
14
+ def create_model
15
+ template 'gallery_template.rb', "app/models/adminpanel/#{lower_name}.rb"
16
+ end
17
+
18
+ def create_uploader
19
+ template 'uploader.rb', "app/uploader/adminpanel/#{lower_name}_uploader.rb"
20
+ end
21
+
22
+ def create_migration
23
+ migration_template 'gallery_migration.rb', "db/migrate/create_adminpanel_#{lower_name.pluralize}_table.rb"
24
+ puts "don't forget to add the form_field, the relationship and #{lower_name}s_attributes it to attr_accessible"
25
+ end
26
+
27
+ private
28
+ def reference_name
29
+ name.singularize.downcase
30
+ end
31
+
32
+ def class_name
33
+ "#{lower_name.capitalize}"
34
+ end
35
+
36
+ def lower_name
37
+ "#{name.singularize.downcase}file"
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,11 @@
1
+ class CreateAdminpanel<%= class_name.pluralize %>Table < ActiveRecord::Migration
2
+ def change
3
+ create_table :adminpanel_<%= lower_name.pluralize %> do |t|
4
+
5
+ t.integer :<%= reference_name %>_id
6
+ t.string :file
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,8 @@
1
+ module Adminpanel
2
+ class <%= class_name %> < ActiveRecord::Base
3
+ attr_accessible :<%= reference_name %>_id, :file
4
+
5
+ mount_uploader :file, <%= class_name %>Uploader
6
+
7
+ end
8
+ end
@@ -0,0 +1,86 @@
1
+ module Adminpanel
2
+ class <%= class_name %>Uploader < CarrierWave::Uploader::Base
3
+ include CarrierWave::RMagick
4
+
5
+ storage :file
6
+
7
+ def root
8
+ Rails.root.join 'public/'
9
+ end
10
+
11
+ def store_dir
12
+ "uploads/image/#{mounted_as}/#{model.id}"
13
+ end
14
+
15
+ # Process files as they are uploaded:
16
+ # process :resize_to_fill => [1366, 768]
17
+
18
+ # THE THUMB VERSION IS NECESSARY!!!!
19
+ version :thumb do
20
+ process :resize_to_limit => [220, 220]
21
+ end
22
+
23
+ # however, you can create your own versions:
24
+ # version :awesome do
25
+ # process :reside_and_pad => [120, 900]
26
+ # end
27
+
28
+ # resize_and_pad(width, height, background=:transparent, gravity=::Magick::CenterGravity)
29
+ #
30
+ # Resize the image to fit within the specified dimensions while retaining
31
+ # the original aspect ratio. If necessary, will pad the remaining area with
32
+ # the given color, which defaults to transparent (for gif and png, white for jpeg).
33
+ #
34
+ # width (Integer)
35
+ # the width to scale the image to
36
+ # height (Integer)
37
+ # the height to scale the image to
38
+ # background (String, :transparent)
39
+ # the color of the background as a hexcode, like “ff45de“
40
+ # gravity (Magick::GravityType)
41
+ # how to position the image
42
+
43
+ # resize_to_fill(width, height)
44
+ #
45
+ # From the RMagick documentation: “Resize the image to fit within the
46
+ # specified dimensions while retaining the aspect ratio of the original image.
47
+ # If necessary, crop the image in the larger dimension.“
48
+ #
49
+ # See even www.imagemagick.org/RMagick/doc/image3.html#resize_to_fill
50
+ #
51
+ # width (Integer)
52
+ # the width to scale the image to
53
+ # height (Integer)
54
+ # the height to scale the image to
55
+
56
+ # resize_to_fit(width, height)
57
+ #
58
+ # From the RMagick documentation: “Resize the image to fit within the
59
+ # specified dimensions while retaining the original aspect ratio. The image
60
+ # may be shorter or narrower than specified in the smaller dimension but
61
+ # will not be larger than the specified values.“
62
+ #
63
+ # See even www.imagemagick.org/RMagick/doc/image3.html#resize_to_fit
64
+ #
65
+ # width (Integer)
66
+ # the width to scale the image to
67
+ # height (Integer)
68
+ # the height to scale the image to
69
+
70
+ # resize_to_limit(width, height)
71
+ #
72
+ # Resize the image to fit within the specified dimensions while retaining
73
+ # the original aspect ratio. Will only resize the image if it is larger than
74
+ # the specified dimensions. The resulting image may be shorter or narrower
75
+ # than specified in the smaller dimension but will not be larger than the
76
+ # specified values.
77
+ #
78
+ # width (Integer)
79
+ # the width to scale the image to
80
+ # height (Integer)
81
+ # the height to scale the image to
82
+ def extension_white_list
83
+ %w(jpg jpeg png)
84
+ end
85
+ end
86
+ end
@@ -1,29 +1,39 @@
1
- include Rails::Generators::Migration
1
+ require 'rails/generators/active_record'
2
2
  module Adminpanel
3
3
  module Generators
4
- class InitializeGenerator < Rails::Generators::Base
4
+ class InitializeGenerator < ActiveRecord::Generators::Base
5
5
  desc "Generate the migrations necessary to start the gem"
6
6
  source_root File.expand_path("../templates", __FILE__)
7
- class_option :include_category, :type => :boolean, :aliases => "-c", :default => true, :desc => "Include category skeleton and migration for it"
8
-
9
- def self.next_migration_number(path)
10
- Time.now.utc.strftime("%Y%m%d%H%M%S")
11
- end
7
+ argument :name, :type => :string, :default => "default", :require => false
8
+ class_option :'skip-category', :type => :boolean, :aliases => "-c", :default => false, :desc => "Include category skeleton and migration for it"
9
+ class_option :'skip-uploader', :type => :boolean, :aliases => "-u", :default => false
10
+ class_option :'skip-migration', :type => :boolean, :aliases => "-m", :default => false
11
+ class_option :'skip-setup', :type => :boolean, :aliases => "-s", :default => false
12
12
 
13
13
  def create_initializers
14
- copy_file 'adminpanel_setup.rb', 'config/initializers/adminpanel_setup.rb'
14
+ if !options[:'skip-setup']
15
+ copy_file 'adminpanel_setup.rb', 'config/initializers/adminpanel_setup.rb'
16
+ end
15
17
  end
16
18
 
17
19
  def create_categories
18
- if options[:include_category]
19
- puts "including category files"
20
+ if !options[:'skip-category']
21
+ # puts "including category files"
20
22
  copy_file "category_template.rb", 'app/models/adminpanel/category.rb'
21
- migration_template 'create_adminpanel_categories_table.rb', 'db/migrate/create_adminpanel_categories_tables.rb'
23
+ migration_template 'create_adminpanel_categories_table.rb', 'db/migrate/create_adminpanel_categories_table.rb'
24
+ end
25
+ end
26
+
27
+ def create_section_uploader
28
+ if !options[:'skip-uploader']
29
+ copy_file "section_uploader.rb", 'app/uploader/adminpanel/section_uploader.rb'
22
30
  end
23
31
  end
24
32
 
25
33
  def create_migration
26
- migration_template 'create_adminpanel_tables.rb', 'db/migrate/create_adminpanel_tables.rb'
34
+ if !options[:'skip-migration']
35
+ migration_template 'create_adminpanel_tables.rb', 'db/migrate/create_adminpanel_tables.rb'
36
+ end
27
37
  end
28
38
 
29
39
  end