adminpanel 1.2.8 → 1.2.9

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 (44) hide show
  1. data/Gemfile +1 -1
  2. data/adminpanel.gemspec +2 -2
  3. data/app/controllers/adminpanel/{pages_controller.rb → analytics_controller.rb} +11 -6
  4. data/app/controllers/adminpanel/application_controller.rb +5 -6
  5. data/app/controllers/adminpanel/galleries_controller.rb +23 -23
  6. data/app/controllers/adminpanel/sections_controller.rb +5 -1
  7. data/app/controllers/adminpanel/sessions_controller.rb +7 -3
  8. data/app/helpers/adminpanel/application_helper.rb +7 -3
  9. data/app/helpers/adminpanel/rest_actions_helper.rb +20 -0
  10. data/app/helpers/adminpanel/router_helper.rb +2 -32
  11. data/app/helpers/adminpanel/shared_pages_helper.rb +8 -8
  12. data/app/models/adminpanel/analytic.rb +12 -0
  13. data/app/models/adminpanel/gallery.rb +48 -43
  14. data/app/models/adminpanel/section.rb +6 -2
  15. data/app/models/adminpanel/user.rb +4 -0
  16. data/app/views/adminpanel/{pages → analytics}/index.html.erb +0 -0
  17. data/app/views/adminpanel/sessions/new.html.erb +1 -1
  18. data/app/views/layouts/_side_menu.html.erb +7 -89
  19. data/app/views/shared/_gallery_entries.html.erb +11 -0
  20. data/app/views/shared/gallery_entries.js.erb +1 -0
  21. data/app/views/shared/show.html.erb +21 -9
  22. data/config/routes.rb +28 -22
  23. data/lib/adminpanel/active_record/adminpanel_extension.rb +63 -4
  24. data/lib/adminpanel/engine.rb +7 -2
  25. data/lib/adminpanel/version.rb +1 -1
  26. data/lib/generators/adminpanel/gallery/gallery_generator.rb +1 -1
  27. data/lib/generators/adminpanel/gallery/templates/gallery_template.rb +6 -0
  28. data/lib/generators/adminpanel/gallery/templates/uploader.rb +2 -2
  29. data/lib/generators/adminpanel/initialize/initialize_generator.rb +23 -7
  30. data/lib/generators/adminpanel/initialize/templates/adminpanel_setup.rb +8 -3
  31. data/lib/generators/adminpanel/initialize/templates/category_template.rb +22 -9
  32. data/lib/generators/adminpanel/resource/resource_generator.rb +8 -4
  33. data/lib/tasks/adminpanel/adminpanel.rake +9 -23
  34. data/spec/dummy/.gitignore +1 -0
  35. data/spec/dummy/app/models/adminpanel/category.rb +3 -3
  36. data/spec/dummy/app/models/adminpanel/product.rb +3 -3
  37. data/spec/dummy/config/initializers/adminpanel_setup.rb +22 -0
  38. data/spec/features/galleries_pages_spec.rb +3 -28
  39. data/spec/generators/gallery_generator_spec.rb +40 -44
  40. data/spec/generators/initialize_generator_spec.rb +46 -19
  41. data/spec/generators/resource_generator_spec.rb +101 -129
  42. data/spec/spec_helper.rb +1 -2
  43. data/spec/tasks/adminpanel_rake_spec.rb +4 -4
  44. metadata +21 -14
@@ -10,7 +10,12 @@ Adminpanel.setup do |config|
10
10
  # # Path to the key file, defaults to config/analytics
11
11
  # config.analytics_key_path = "config/analytics"
12
12
 
13
- # # Configure the default modules that you don't need
14
- # # the supported options are :categories, :gallery, :sections and :categories
15
- # config.unincluded_modules = [:categories, :gallery, :sections, :categories]
13
+ # # This are the modules that are going to be displayed and order that are going to be displayed
14
+ # config.displayable_resources = [
15
+ # :analytics,
16
+ # :users,
17
+ # :galleries,
18
+ # :sections,
19
+ # :categories
20
+ # ]
16
21
  end
@@ -1,30 +1,43 @@
1
1
  module Adminpanel
2
2
  class Category < ActiveRecord::Base
3
- attr_accessible :name, :model
3
+ attr_accessible :name, :model #, :product_ids
4
4
 
5
5
  validates_presence_of :model
6
6
  validates_presence_of :name
7
7
  validates_uniqueness_of :name
8
8
 
9
9
 
10
- has_many :categorizations
11
- has_many :products, :through => :categorizations, :dependent => :destroy
10
+ # has_many :categorizations
11
+ # has_many :products, :through => :categorizations, :dependent => :destroy
12
12
 
13
13
 
14
14
  def self.form_attributes
15
15
  [
16
- {"product_ids" => {"type" => "has_many", "model" => "Adminpanel::Product", "name" => "product_ids"}},
17
- {"name" => {"type" => "text_field", "name" => "name", "label" => "name", "placeholder" => "name"}},
16
+ # {
17
+ # 'product_ids' => {
18
+ # 'type' => 'has_many',
19
+ # 'model' => 'Adminpanel::Product',
20
+ # 'name' => 'product_ids'
21
+ # }
22
+ # },
23
+ {
24
+ 'name' => {
25
+ 'type' => 'text_field',
26
+ 'name' => 'name',
27
+ 'label' => 'name',
28
+ 'placeholder' => 'name'
29
+ }
30
+ },
18
31
  ]
19
32
  end
20
33
 
21
34
  def self.display_name
22
- "Categoría"
35
+ "Categorías"
23
36
  end
24
37
 
25
- # def self.icon
26
- # "icon-truck"
27
- # end
38
+ def self.icon
39
+ "icon-bookmark"
40
+ end
28
41
 
29
42
  default_scope { order("model ASC")}
30
43
  scope :of_model, lambda{|model| where(:model => model)}
@@ -34,6 +34,10 @@ module Adminpanel
34
34
  false
35
35
  end
36
36
 
37
+ def gallery_name
38
+ "#{lower_name}file"
39
+ end
40
+
37
41
  def lower_name
38
42
  name.singularize.downcase
39
43
  end
@@ -83,7 +87,7 @@ module Adminpanel
83
87
  assign_attributes_variables(attribute)
84
88
 
85
89
  if @attr_type == "images"
86
- attr_string = attr_string + ":#{@attr_field.pluralize.downcase}_attributes, "
90
+ attr_string = attr_string + ":#{gallery_name.pluralize}_attributes, "
87
91
  elsif @attr_type == "belongs_to"
88
92
  attr_string = "#{attr_string}:#{belongs_to_field(@attr_field)}, "
89
93
  elsif @attr_type == "has_many" || @attr_type == "has_many_through"
@@ -142,7 +146,7 @@ module Adminpanel
142
146
  end
143
147
 
144
148
  def file_field_hash
145
- "#{starting_hash(@attr_field.downcase.pluralize)} => {#{form_type('adminpanel_file_field')}," +
149
+ "#{starting_hash(gallery_name.pluralize)} => {#{form_type('adminpanel_file_field')}," +
146
150
  "#{label_type}," +
147
151
  "#{placeholder_type}}\n\t\t\t},"
148
152
  end
@@ -246,11 +250,11 @@ module Adminpanel
246
250
 
247
251
  def image_association
248
252
  generate_gallery
249
- return "\n\t\tmount_images :#{@attr_field.pluralize.downcase}\n"
253
+ return "\n\t\tmount_images :#{gallery_name.pluralize}\n"
250
254
  end
251
255
 
252
256
  def generate_gallery
253
- Rails::Generators.invoke("adminpanel:gallery", lower_name)
257
+ generate "adminpanel:gallery", lower_name
254
258
  end
255
259
 
256
260
  end
@@ -84,7 +84,6 @@ namespace :adminpanel do
84
84
  end
85
85
 
86
86
  task :populate, [:times, :model, :attributes] => :environment do |t, args|
87
-
88
87
  puts "Generating #{args[:times]} records of #{args[:model]}"
89
88
 
90
89
  @model = "adminpanel/#{args[:model]}".classify.constantize
@@ -107,26 +106,27 @@ namespace :adminpanel do
107
106
  when "category" || "category_name" #generate a category name
108
107
  value = @things.sample.pluralize
109
108
 
110
- when "lorem_name" || 'small_lorem' || "sentence"
109
+ when 'lorem_short'
111
110
  value = generate_lorem_name #lorem random short sentence
112
111
 
113
- when "description" || "lorem" #large paragraph.
112
+ when "lorem" || "description" #large paragraph.
114
113
  value = generate_lorem
115
114
 
116
115
  when "number" #generate a number
117
116
  value = [*1..5000].sample
118
117
 
119
118
  when "id" #assign field_id it to a random instance of Adminpanel::field
120
- value = "adminpanel/#{field}".classify.constantize.order("RAND()").first.id
121
- field = "#{field}_id"
119
+ field = field.downcase.singularize
120
+ if field != 'category'
121
+ value = "adminpanel/#{field}".classify.constantize.order("RAND()").first.id
122
+ else
123
+ value = "adminpanel/#{field}".classify.constantize.of_model(@model.display_name).order("RAND()").first.id
124
+ end
125
+ field = "#{field}_id"
122
126
 
123
127
  when "email" #generates a random email
124
128
  value = generate_email
125
129
 
126
- when "image" #force an image...
127
- has_image = true
128
- @file_url = "http://placehold.it/#{field}"
129
-
130
130
  else #no type
131
131
  value = "#{time + 1} Lorem ipsum dolor sit amec"
132
132
 
@@ -141,10 +141,6 @@ namespace :adminpanel do
141
141
 
142
142
  change_dates(instance)
143
143
 
144
- if(has_image) #forcing the image into the db
145
- create_image_of(instance.id)
146
- end
147
-
148
144
  end
149
145
 
150
146
  end
@@ -170,16 +166,6 @@ private
170
166
  ").save\n"
171
167
  end
172
168
 
173
- def create_image_of(model_id)
174
- image_instance = Adminpanel::Image.new(
175
- :model => @model.display_name,
176
- :foreign_key => model_id
177
- )
178
- image_instance.save(:validate => false)
179
- image_instance.update_column(:file, @file_url)
180
- change_dates(image_instance)
181
- end
182
-
183
169
  def generate_lorem
184
170
  value = "#{@lorem.sample}"
185
171
  [*60..80].sample.times do
@@ -2,6 +2,7 @@
2
2
  capybara-*.html
3
3
  .rspec
4
4
  /log
5
+ /tmp
5
6
  /tmp/test.log
6
7
  /tmp/development.log
7
8
  /db/*.sqlite3
@@ -17,8 +17,8 @@ module Adminpanel
17
17
  "Category"
18
18
  end
19
19
 
20
- # def self.icon
21
- # "icon-truck"
22
- # end
20
+ def self.icon
21
+ "icon-truck"
22
+ end
23
23
  end
24
24
  end
@@ -49,8 +49,8 @@ module Adminpanel
49
49
  "Product"
50
50
  end
51
51
 
52
- # def self.icon
53
- # "icon-truck"
54
- # end
52
+ def self.icon
53
+ "icon-truck"
54
+ end
55
55
  end
56
56
  end
@@ -0,0 +1,22 @@
1
+ Adminpanel.setup do |config|
2
+ # # You get this from the Google Analytics Dashboard, this configuration is required.
3
+ # config.analytics_profile_id = '12341234'
4
+
5
+ # # The next configuration is the file used to establish server to server authentication/authorization
6
+ # # you need to download this file from the Google Developers Console
7
+ # # and place it inside your application, this configuration is required.
8
+ # config.analytics_key_filename = '12345ABCDE.p12'
9
+
10
+ # # Path to the key file, defaults to config/analytics
11
+ # config.analytics_key_path = "config/analytics"
12
+
13
+ # # This are the modules that are going to be displayed and order that are going to be displayed
14
+ config.displayable_resources = [
15
+ :analytics,
16
+ :galleries,
17
+ :sections,
18
+ :categories,
19
+ :products,
20
+ :users
21
+ ]
22
+ end
@@ -4,12 +4,12 @@ describe "Gallery pages" do
4
4
  subject {page}
5
5
 
6
6
  let(:user) { Factory(:user) }
7
- before do
7
+ before do
8
8
  visit adminpanel.signin_path
9
9
  valid_signin(user)
10
10
  clean_uploads_folder
11
11
  end
12
-
12
+
13
13
  describe "galleries" do
14
14
  let(:gallery) { Factory(:gallery) }
15
15
  before do
@@ -89,31 +89,6 @@ describe "Gallery pages" do
89
89
  end
90
90
  end
91
91
 
92
- describe "new" do
93
- before do
94
- visit adminpanel.new_gallery_path
95
- end
96
-
97
- it { should have_title(I18n.t("gallery.new")) }
98
-
99
- describe "with invalid information" do
100
- before { find("form#new_gallery").submit_form! }
101
-
102
- it { should have_title(I18n.t("gallery.new")) }
103
- it { should have_selector("div#alerts") }
104
- end
105
-
106
- describe "with valid information" do
107
- before do
108
- attach_file('gallery_file', File.join(Rails.root, '/app/assets/images/hipster.jpg'))
109
- find("form#new_gallery").submit_form!
110
- end
111
-
112
- it { should have_content(I18n.t("gallery.success"))}
113
- it { File.exists? File.join(Rails.root, '/public/uploads/gallery/file/1/thumb_hipster.jpg') }
114
- end
115
- end
116
-
117
92
  describe "show" do
118
93
  let(:gallery) { Factory(:gallery) }
119
94
  before do
@@ -122,4 +97,4 @@ describe "Gallery pages" do
122
97
 
123
98
  it { page.should have_selector("img", :src => gallery.file_url) }
124
99
  end
125
- end
100
+ end
@@ -1,53 +1,49 @@
1
1
  require 'spec_helper'
2
+ require 'generators/adminpanel/gallery/gallery_generator'
2
3
 
3
- describe "adminpanel:gallery" do
4
+ describe Adminpanel::Generators::GalleryGenerator do
5
+ destination File.expand_path("../../dummy/tmp", __FILE__)
4
6
 
5
- with_args :Product do
6
- it 'should generate the model' do
7
- subject.should generate('app/models/adminpanel/productfile.rb'){ |content|
8
- content.should =~ /attr_accessible :product_id, :file/ &&
9
- content.should =~ /mount_uploader :file, ProductfileUploader/
10
- }
7
+ before do
8
+ Rails::Generators.options[:rails][:orm] = :active_record
9
+ end
10
+
11
+ # after do
12
+ # prepare_destination
13
+ # end
14
+
15
+ describe 'with "product" as argument' do
16
+ before do
17
+ prepare_destination
18
+ run_generator %w(Product)
11
19
  end
12
20
 
13
- it 'should generate the uploader' do
14
- subject.should generate('app/uploader/adminpanel/productfile_uploader.rb')
21
+ it 'should generate the productfile migration' do
22
+ migration_file('db/migrate/create_adminpanel_productfiles_table.rb').should
23
+ be_a_migration
15
24
  end
16
25
 
17
- # it 'should generate the migration' do
18
- # subject.should generate("db/migrate/#{Time.now.utc.strftime("%Y%m%d%H%M%S")}_create_adminpanel_productfields_table.rb"){|content|
19
- # content.should =~ /t.integer :product_id/
20
- # }
21
- #
22
- # end
23
- #
24
- # it "should generate the default category model" do
25
- # subject.should generate("app/models/adminpanel/category.rb")
26
- # end
27
- #
28
- # it 'should generate the categories migration' do
29
- # subject.should generate("db/migrate/#{Time.now.utc.strftime("%Y%m%d%H%M%S")}_create_adminpanel_categories_table.rb")
30
- # end
31
- # end
32
- #
33
- # with_args :'-c', :false do
34
- # it "shouldn't generate the default category model" do
35
- # subject.should_not generate("app/models/adminpanel/category.rb")
36
- # end
37
- #
38
- # it "shouldn't generate the categories migration" do
39
- # subject.should_not generate("db/migrate/#{Time.now.utc.strftime("%Y%m%d%H%M%S")}_create_adminpanel_categories_table.rb")
40
- # end
41
- #
42
- # it "should generate the initialization migration" do
43
- # subject.should generate("db/migrate/#{Time.now.utc.strftime("%Y%m%d%H%M%S")}_create_adminpanel_tables.rb")
44
- # end
45
- #
46
- # end
47
- #
48
- # it 'should generate the configuration initializer' do
49
- # subject.should generate('config/initializers/adminpanel_setup.rb'){ |content|
50
- # content.should =~ /Adminpanel.setup do |config|/
51
- # }
26
+
27
+ it 'should migrate the correct fields' do
28
+ migration_file('db/migrate/create_adminpanel_productfiles_table.rb').should(
29
+ contain(/t.integer :product_id/) &&
30
+ contain(/create_table :adminpanel_productfiles/)
31
+ )
32
+ end
33
+
34
+ it 'should generate the productfile model with uploader and attr_accessible' do
35
+ file('app/models/adminpanel/productfile.rb').should(
36
+ contain(/attr_accessible :product_id, :file/) &&
37
+ contain(/mount_uploader :file, ProductfileUploader/)
38
+ )
39
+ end
40
+
41
+ it 'should generate the productfile model with uploader and attr_accessible' do
42
+ file('app/models/adminpanel/productfile.rb').should exist
43
+ end
44
+
45
+ it 'should the produfile uploader' do
46
+ file('app/uploaders/adminpanel/productfile_uploader.rb').should exist
47
+ end
52
48
  end
53
49
  end
@@ -1,41 +1,68 @@
1
1
  require 'spec_helper'
2
+ require 'generators/adminpanel/initialize/initialize_generator'
2
3
 
3
- describe "adminpanel:initialize" do
4
+ describe Adminpanel::Generators::InitializeGenerator do
5
+ destination File.expand_path("../../dummy/tmp", __FILE__)
4
6
 
5
- context "with no arguments or options" do
6
- it "should generate the initialization migration" do
7
- subject.should generate("db/migrate/#{Time.now.utc.strftime("%Y%m%d%H%M%S").to_i + 1}_create_adminpanel_tables.rb")
7
+ before do
8
+ Rails::Generators.options[:rails][:orm] = :active_record
9
+ end
10
+
11
+ after do
12
+ prepare_destination
13
+ end
14
+
15
+ describe 'with no arguments' do
16
+ before do
17
+ prepare_destination
18
+ run_generator
8
19
  end
9
20
 
10
- it "should generate the default category model" do
11
- subject.should generate("app/models/adminpanel/category.rb")
21
+ it 'should generate the initial migration' do
22
+ migration_file('db/migrate/create_adminpanel_tables.rb').should be_a_migration
23
+ end
24
+
25
+ it 'should generate the adminpanel_setup file' do
26
+ file('config/initializers/adminpanel_setup.rb').should exist
12
27
  end
13
28
 
14
29
  it 'should generate the categories migration' do
15
- subject.should generate("db/migrate/#{Time.now.utc.strftime("%Y%m%d%H%M%S")}_create_adminpanel_categories_table.rb")
30
+ migration_file('db/migrate/create_adminpanel_categories_table.rb').should be_a_migration
16
31
  end
17
32
 
18
- it 'should generate the configuration initializer' do
19
- subject.should generate('config/initializers/adminpanel_setup.rb'){ |content|
20
- content.should =~ /Adminpanel.setup do |config|/
21
- }
33
+ it 'should generate the category file' do
34
+ file('app/models/adminpanel/category.rb').should exist
35
+ end
36
+
37
+ it 'should generate the section uploader' do
38
+ file('app/uploaders/adminpanel/section_uploader.rb').should exist
22
39
  end
23
40
  end
24
41
 
25
- with_args :'-c', :true, :'-u', :true, :'-m', :true do
42
+ describe 'with arguments -c true -u true -m true -p true' do
43
+ before do
44
+ prepare_destination
45
+ run_generator %w(-c true -u true -m true -p true)
46
+ end
26
47
 
27
- it "shouldn't generate the default category model" do
28
- subject.should_not generate("app/models/adminpanel/category.rb")
48
+ it 'should\'t generate the adminpanel_setup' do
49
+ file('config/initializers/adminpanel_setup.rb').should_not exist
29
50
  end
30
51
 
31
- it "shouldn't generate the categories migration" do
32
- subject.should_not generate("db/migrate/#{Time.now.utc.strftime("%Y%m%d%H%M%S")}_create_adminpanel_categories_table.rb")
52
+ it 'should\'t generate the initial migration' do
53
+ migration_file('db/migrate/create_adminpanel_categories_table.rb').should_not exist
33
54
  end
34
55
 
35
- it "shouldn't generate the initialization migration" do
36
- subject.should_not generate("db/migrate/#{Time.now.utc.strftime("%Y%m%d%H%M%S").to_i + 1}_create_adminpanel_tables.rb")
56
+ it 'should\'t genearte the section uploader' do
57
+ file('app/uploaders/adminpanel/section_uploader.rb').should_not exist
37
58
  end
38
59
 
39
- end
60
+ it 'should\'t generate the categories migration' do
61
+ migration_file('db/migrate/create_adminpanel_categories_table.rb').should_not exist
62
+ end
40
63
 
64
+ it 'should\'t generate the category file' do
65
+ file('app/models/adminpanel/category.rb').should_not exist
66
+ end
67
+ end
41
68
  end