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
@@ -29,8 +29,12 @@ module Adminpanel
29
29
 
30
30
  end
31
31
 
32
- def simple_name
33
- "Section"
32
+ def self.icon
33
+ "icon-tasks"
34
34
  end
35
+
36
+ def self.display_name
37
+ 'Secciones'
38
+ end
35
39
  end
36
40
  end
@@ -42,6 +42,10 @@ module Adminpanel
42
42
 
43
43
  end
44
44
 
45
+ def self.icon
46
+ 'icon-user'
47
+ end
48
+
45
49
  private
46
50
  def create_remember_token
47
51
  self.remember_token = SecureRandom.base64.tr("+/", "-_")
@@ -23,4 +23,4 @@
23
23
  <%= f.submit "Iniciar Sesión", :class => "btn pull-right", :id => "signin-button" %>
24
24
  <% end %>
25
25
  </div>
26
- </div>
26
+ </div>
@@ -12,42 +12,8 @@
12
12
  %>
13
13
  </div>
14
14
  <div class="accordion" id="accordion2">
15
-
16
- <% if !Adminpanel.unincluded_modules.include?(:analytics) %>
17
- <div class="accordion-group">
18
- <div class="accordion-heading">
19
- <%=
20
- link_to(
21
- content_tag(
22
- :i,
23
- nil,
24
- :class => 'icon-dashboard') +
25
- content_tag(:span," #{I18n.t('model.Analytics')}"),
26
- pages_path,
27
- :class => "accordion-toggle b_D1B2D1 #{is_current_section?('pages')}"
28
- )
29
- %>
30
- </div>
31
- </div>
32
- <% end %>
33
-
34
- <div class="accordion-group">
35
- <div class="accordion-heading">
36
- <%=
37
- link_to(
38
- content_tag(
39
- :i,
40
- nil,
41
- :class => 'icon-user') +
42
- content_tag(:span,' Usuarios'),
43
- users_path,
44
- :class => "accordion-toggle b_9FDDF6 #{is_current_section?('users')}"
45
- )
46
- %>
47
- </div>
48
- </div>
49
-
50
- <% if !Adminpanel.unincluded_modules.include?(:gallery) %>
15
+ <% Adminpanel.displayable_resources.each do |resource| %>
16
+ <% resource_class = symbol_class(resource) %>
51
17
  <div class="accordion-group">
52
18
  <div class="accordion-heading">
53
19
  <%=
@@ -55,65 +21,17 @@
55
21
  content_tag(
56
22
  :i,
57
23
  nil,
58
- :class => 'icon-picture') +
59
- content_tag(:span, " #{t('model.Gallery')}"),
60
- galleries_path,
61
- :class => "accordion-toggle b_C3F7A7 #{is_current_section?('galleries')}"
62
- )
63
- %>
64
- </div>
65
- </div>
66
- <% end %>
67
-
68
- <% if !Adminpanel.unincluded_modules.include?(:sections) %>
69
- <div class="accordion-group">
70
- <div class="accordion-heading">
71
- <%=
72
- link_to(
73
- content_tag(:i, nil, :class => 'icon-tasks') +
74
- content_tag(:span, ' Secciones'),
75
- sections_path,
76
- :class => "accordion-toggle b_F6F1A2 #{is_current_section?('sections')}"
77
- )
78
- %>
79
- </div>
80
- </div>
81
- <% end %>
82
-
83
- <% if !Adminpanel.unincluded_modules.include?(:categories) %>
84
- <div class="accordion-group">
85
- <div class="accordion-heading">
86
- <%=
87
- link_to(
88
- content_tag(:i, nil, :class => 'icon-bookmark') +
89
- content_tag(:span, " #{t('model.Categories')}"),
90
- categories_path,
91
- :class => "accordion-toggle b_99FFCC #{is_current_section?('categories')}"
24
+ :class => resource_class.icon) +
25
+ content_tag(:span," #{resource_class.display_name}"),
26
+ [route_symbol(resource.to_s)],
27
+ :class => "accordion-toggle b_99FFCC
28
+ #{is_current_section?(resource_class.display_name)}"
92
29
  )
93
30
  %>
94
31
  </div>
95
32
  </div>
96
33
  <% end %>
97
34
 
98
-
99
- <% @menu_items.each do |menu| %>
100
- <div class="accordion-group">
101
- <div class="accordion-heading">
102
- <%=
103
- link_to content_tag(
104
- :i,
105
- nil,
106
- :class => "Adminpanel::#{menu}".constantize.icon
107
- ) + content_tag(
108
- :span,
109
- " " + pluralize_es("Adminpanel::#{menu}".constantize.display_name)
110
- ),
111
- [route_symbol(menu)],
112
- :class => "accordion-toggle b_F5C294 #{is_current_section?(menu)}"
113
- %>
114
- </div>
115
- </div>
116
- <% end %>
117
35
  </div>
118
36
  </div>
119
37
  <!-- /Side menu -->
@@ -0,0 +1,11 @@
1
+ <% images.each do |image| %>
2
+ <li>
3
+ <%= link_to (image_tag image.file_url(:thumb)), image.file.to_s, :rel => "group", :name => @model.display_name %>
4
+ <ul class="rightboxes">
5
+ <li>
6
+ <%= link_to content_tag(:i, nil, :class => "icon-chevron-up"), [:move_to_better, image], :method => :put, :remote => true %>
7
+ <%= link_to content_tag(:i, nil, :class => "icon-chevron-down"), [:move_to_worst, image], :method => :put, :remote => true %>
8
+ </li>
9
+ </ul>
10
+ </li>
11
+ <% end %>
@@ -0,0 +1 @@
1
+ $('#gallery-entries').html("<%= escape_javascript(render 'shared/gallery_entries', :images => collection) %>")
@@ -18,7 +18,7 @@
18
18
  <div class="widget-body">
19
19
  <div class="widget-tickets widget-tickets-large clearfix"><ul>
20
20
  <% @model.display_attributes.each do |fields| %>
21
- <% fields.each do |attribute, properties| %>
21
+ <% fields.each do |attribute, properties| %>
22
22
  <% if properties["type"] != "adminpanel_file_field" %>
23
23
  <li class="priority-high">
24
24
  <div class="span3">
@@ -36,6 +36,10 @@
36
36
  <li class="priority-low"><%= member.name %></li>
37
37
  <% end %>
38
38
  </ul>
39
+ <% elsif properties['type'] == 'file_field' %>
40
+ <ul>
41
+ <%= image_tag(resource.send("#{attribute}_url", :thumb)) %>
42
+ </ul>
39
43
  <% else %>
40
44
  <%= resource.send(attribute) -%>
41
45
  <% end %>
@@ -56,16 +60,24 @@
56
60
  <%= link_to content_tag(:i, nil, :class => 'icon-pencil'), [:edit, resource], :title => t("action.update") + " #{@model.display_name}" %>
57
61
  </h5>
58
62
  </div>
59
- <div class="widget-body row-fluid">
60
- <div id="gallery-container" class="js-masonry"
61
- data-masonry-options='{ "columnWidth": 3, "itemSelector": ".gallery-item" }'>
62
- <% resource.send(@model.get_image_relationship).each do |image|%>
63
- <div class="gallery-item">
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 %>
63
+ <% if @model.act_as_a_gallery?.nil? %>
64
+ <div class="widget-body row-fluid">
65
+ <div id="gallery-container" class="js-masonry"
66
+ data-masonry-options='{ "columnWidth": 3, "itemSelector": ".gallery-item" }'>
67
+ <% resource.send(@model.get_image_relationship).each do |image|%>
68
+ <div class="gallery-item">
69
+ <%= link_to (image_tag image.file_url(:thumb)), image.file_url(:thumb).to_s, :rel => "group", :name => @model.display_name %>
70
+ </div>
71
+ <% end %>
72
+ </div>
66
73
  </div>
67
- <% end %>
74
+ <% else %>
75
+ <div class="widget-body widget-tasks-assigned clearfix">
76
+ <ul id="gallery-entries">
77
+ <%= render 'shared/gallery_entries', :images => resource.send(@model.get_image_relationship) %>
78
+ </ul>
68
79
  </div>
80
+ <% end %>
69
81
  </div>
70
82
  </div>
71
83
  <% end %>
data/config/routes.rb CHANGED
@@ -2,34 +2,40 @@ include Adminpanel::RouterHelper
2
2
 
3
3
  Adminpanel::Engine.routes.draw do
4
4
 
5
- adminpanel_resources.each do |file|
6
- if file
7
- resources file.to_sym
8
- end
9
- end
10
-
11
- resources :sections, :except => [:new, :create, :destroy]
12
- match '/signout', :to => 'sessions#destroy', :via => :delete, :as => "signout"
13
- match '/signin', :to => 'sessions#new', :as => "signin"
14
- resources :users
15
- if !Adminpanel.unincluded_modules.include?(:categories)
16
- resources :categories
17
- end
18
-
19
- if !Adminpanel.unincluded_modules.include?(:gallery)
5
+ Adminpanel.displayable_resources.each do |resource|
6
+ case resource
7
+ when :sections
8
+ resources :sections, :except => [:new, :create, :destroy]
9
+ when :users
10
+ resources :users
11
+ when :galleries
20
12
  resources :galleries do
21
13
  member do
22
14
  put :move_better, :as => "move_to_better"
23
15
  put :move_worst, :as => "move_to_worst"
24
16
  end
25
17
  end
26
- end
27
- resources :sessions, :only => [:new, :create, :destroy]
28
-
29
- if !Adminpanel.unincluded_modules.include?(:analytics)
30
- resources :pages, :path => 'analytics', :only => [:index]
31
- root :to => 'pages#index'
18
+ when :categories
19
+ resources :categories
20
+ when :analytics
21
+ resources :analytics, :only => [:index]
32
22
  else
33
- root :to => 'users#index'
23
+ if !acts_as_a_gallery?(resource).nil?
24
+ resources resource
25
+ resources acts_as_a_gallery?(resource).to_sym, :only => [:index] do
26
+ member do
27
+ put :move_better, :as => 'move_to_better'
28
+ put :move_worst, :as => 'move_to_worst'
29
+ end
30
+ end
31
+ else
32
+ resources resource
33
+ end
34
34
  end
35
+ end
36
+
37
+ root :to => "#{Adminpanel.displayable_resources.first}#index"
38
+ resources :sessions, :only => [:new, :create, :destroy]
39
+ match '/signout', :to => 'sessions#destroy', :via => :delete, :as => "signout"
40
+ match '/signin', :to => 'sessions#new', :as => "signin"
35
41
  end
@@ -2,18 +2,51 @@ module ActiveRecord
2
2
  module AdminpanelExtension
3
3
  extend ActiveSupport::Concern
4
4
  #instance methods
5
- # def foo
5
+ def move_to_better_position
6
+ if self.position > 1
7
+ conflicting_gallery = self.class.where(self.class.relation_field => self.send(self.class.relation_field)).find_by_position(position - 1)
8
+ self.update_attribute(:position, self.position - 1)
9
+ conflicting_gallery.update_attribute(
10
+ :position, conflicting_gallery.position + 1
11
+ )
12
+ true
13
+ else
14
+ false
15
+ end
16
+ end
6
17
 
7
- # end
18
+ def move_to_worst_position
19
+ records = self.class.count
20
+ if self.position < records
21
+ conflicting_gallery = self.class.where(self.class.relation_field => self.send(self.class.relation_field)).find_by_position(position + 1)
22
+ update_attribute(:position, self.position + 1)
23
+ conflicting_gallery.update_attribute(
24
+ :position, conflicting_gallery.position - 1
25
+ )
26
+ true
27
+ else
28
+ false
29
+ end
30
+ end
8
31
 
9
32
  # static(class) methods
10
33
  module ClassMethods
11
-
12
34
  def mount_images(relation)
13
35
  has_many relation, :dependent => :destroy
14
36
  accepts_nested_attributes_for relation, :allow_destroy => true
15
37
  end
16
38
 
39
+ def act_as_a_gallery
40
+ before_create :set_position
41
+ before_destroy :rearrange_positions
42
+
43
+ default_scope { order("position ASC")}
44
+ end
45
+
46
+ # def self.of_parent(field, id)
47
+ # where(field.to_sym => id)
48
+ # end
49
+
17
50
  def form_attributes
18
51
  [{
19
52
  "name" => {
@@ -122,9 +155,35 @@ module ActiveRecord
122
155
  def icon
123
156
  "icon-truck"
124
157
  end
158
+
159
+ def act_as_a_gallery?
160
+ nil
161
+ end
162
+
163
+ def self.relation_field
164
+ 'undefined_relation_field'
165
+ end
125
166
  end
126
- end
127
167
 
168
+ private
169
+ def rearrange_positions
170
+ unarranged_galleries = self.class.where(self.class.relation_field => self.send(self.class.relation_field)).where("position > ?", self.position)
171
+ unarranged_galleries.each do |gallery|
172
+ gallery.update_attribute(:position, gallery.position - 1)
173
+ end
174
+
175
+ end
176
+
177
+ def set_position
178
+ last_record = self.class.where(self.class.relation_field => self.send(self.class.relation_field)).last
179
+ if last_record.nil?
180
+ self.position = 1
181
+ else
182
+ self.position = last_record.position + 1
183
+ end
184
+ end
185
+
186
+ end
128
187
  # include the extension
129
188
  ActiveRecord::Base.send(:include, AdminpanelExtension)
130
189
  end
@@ -5,11 +5,16 @@ module Adminpanel
5
5
 
6
6
  class << self
7
7
  mattr_accessor :analytics_profile_id, :analytics_key_path, :analytics_key_filename,
8
- :unincluded_modules
8
+ :displayable_resources
9
9
  self.analytics_profile_id = nil
10
10
  self.analytics_key_path = "config/analytics"
11
11
  self.analytics_key_filename = nil
12
- self.unincluded_modules = []
12
+ self.displayable_resources = [
13
+ :analytics,
14
+ :users,
15
+ :galleries,
16
+ :sections
17
+ ]
13
18
  end
14
19
 
15
20
  def self.setup(&block)
@@ -1,3 +1,3 @@
1
1
  module Adminpanel
2
- VERSION = "1.2.8"
2
+ VERSION = "1.2.9"
3
3
  end
@@ -16,7 +16,7 @@ module Adminpanel
16
16
  end
17
17
 
18
18
  def create_uploader
19
- template 'uploader.rb', "app/uploader/adminpanel/#{lower_name}_uploader.rb"
19
+ template 'uploader.rb', "app/uploaders/adminpanel/#{lower_name}_uploader.rb"
20
20
  end
21
21
 
22
22
  def create_migration
@@ -4,5 +4,11 @@ module Adminpanel
4
4
 
5
5
  mount_uploader :file, <%= class_name %>Uploader
6
6
 
7
+ # act_as_a_gallery
8
+
9
+ # def self.relation_field
10
+ # 'something_id'
11
+ # end
12
+
7
13
  end
8
14
  end
@@ -17,7 +17,7 @@ module Adminpanel
17
17
 
18
18
  # THE THUMB VERSION IS NECESSARY!!!!
19
19
  version :thumb do
20
- process :resize_to_limit => [220, 220]
20
+ process :resize_to_limit => [80, 80]
21
21
  end
22
22
 
23
23
  # however, you can create your own versions:
@@ -70,7 +70,7 @@ module Adminpanel
70
70
  # resize_to_limit(width, height)
71
71
  #
72
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
73
+ # the original aspect ratio. Will only resize the image if it is larger than
74
74
  # the specified dimensions. The resulting image may be shorter or narrower
75
75
  # than specified in the smaller dimension but will not be larger than the
76
76
  # specified values.
@@ -5,10 +5,26 @@ module Adminpanel
5
5
  desc "Generate the migrations necessary to start the gem"
6
6
  source_root File.expand_path("../templates", __FILE__)
7
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
8
+ class_option :'skip-category',
9
+ :type => :boolean,
10
+ :aliases => '-c',
11
+ :default => false,
12
+ :desc => "Skip category skeleton and migration for it if true"
13
+ class_option :'skip-section-uploader',
14
+ :type => :boolean,
15
+ :aliases => '-u',
16
+ :default => false,
17
+ :desc => 'Skip section uploader if true'
18
+ class_option :'skip-migration',
19
+ :type => :boolean,
20
+ :aliases => '-m',
21
+ :default => false,
22
+ :desc => 'Skip initial migrations if true'
23
+ class_option :'skip-setup',
24
+ :type => :boolean,
25
+ :aliases => '-p',
26
+ :default => false,
27
+ :desc => 'Skip setup if true'
12
28
 
13
29
  def create_initializers
14
30
  if !options[:'skip-setup']
@@ -25,12 +41,12 @@ module Adminpanel
25
41
  end
26
42
 
27
43
  def create_section_uploader
28
- if !options[:'skip-uploader']
29
- copy_file "section_uploader.rb", 'app/uploader/adminpanel/section_uploader.rb'
44
+ if !options[:'skip-section-uploader']
45
+ copy_file "section_uploader.rb", 'app/uploaders/adminpanel/section_uploader.rb'
30
46
  end
31
47
  end
32
48
 
33
- def create_migration
49
+ def create_adminpanel_migration
34
50
  if !options[:'skip-migration']
35
51
  migration_template 'create_adminpanel_tables.rb', 'db/migrate/create_adminpanel_tables.rb'
36
52
  end