adminpanel 2.4.3 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -0
  3. data/README.md +16 -16
  4. data/adminpanel.gemspec +9 -8
  5. data/app/assets/javascripts/adminpanel/application.js +4 -0
  6. data/app/assets/javascripts/adminpanel/bootstrap-wysihtml5.js +2 -4
  7. data/app/assets/javascripts/adminpanel/sortable.js.coffee +27 -0
  8. data/app/assets/stylesheets/adminpanel/application.css +1 -0
  9. data/app/assets/stylesheets/adminpanel/sortable.css.scss.erb +13 -0
  10. data/app/controllers/adminpanel/application_controller.rb +0 -1
  11. data/app/controllers/adminpanel/sessions_controller.rb +5 -2
  12. data/app/controllers/concerns/adminpanel/rest_actions.rb +24 -22
  13. data/app/controllers/concerns/adminpanel/sortable_actions.rb +3 -20
  14. data/app/helpers/adminpanel/breadcrumbs_helper.rb +6 -5
  15. data/app/helpers/adminpanel/router_helper.rb +9 -3
  16. data/app/helpers/adminpanel/shared_pages_helper.rb +1 -1
  17. data/app/models/concerns/adminpanel/base.rb +34 -11
  18. data/app/models/concerns/adminpanel/sitemap.rb +0 -1
  19. data/app/models/concerns/adminpanel/sortable.rb +33 -30
  20. data/app/models/concerns/adminpanel/sortable_gallery.rb +90 -0
  21. data/app/views/adminpanel/form/_adminpanel_file_field.html.erb +1 -1
  22. data/app/views/adminpanel/templates/index.html.erb +41 -13
  23. data/app/views/adminpanel/templates/show.html.erb +33 -13
  24. data/config/initializers/adminpanel/carrierwave_mini_magick_quality.rb +11 -0
  25. data/config/locales/en.yml +3 -7
  26. data/config/locales/es.yml +1 -8
  27. data/config/routes.rb +6 -8
  28. data/lib/adminpanel.rb +9 -8
  29. data/lib/adminpanel/version.rb +1 -1
  30. data/lib/generators/adminpanel/custom_errors/custom_errors_generator.rb +37 -0
  31. data/lib/generators/adminpanel/custom_errors/templates/errors_controller.rb +14 -0
  32. data/lib/generators/adminpanel/custom_errors/templates/show.html.erb +1 -0
  33. data/lib/generators/adminpanel/gallery/templates/gallery_template.rb +8 -3
  34. data/lib/generators/adminpanel/gallery/templates/uploader.rb +4 -1
  35. data/lib/generators/adminpanel/initialize/initialize_generator.rb +0 -12
  36. data/lib/generators/adminpanel/initialize/templates/adminpanel_setup.rb +1 -2
  37. data/lib/generators/adminpanel/resource/resource_generator.rb +29 -8
  38. data/lib/generators/adminpanel/resource/resource_generator_helper.rb +34 -7
  39. data/lib/generators/adminpanel/resource/templates/adminpanel_resource_template.rb +7 -2
  40. data/lib/tasks/adminpanel/adminpanel.rake +19 -61
  41. data/test/dummy/app/models/adminpanel/file_resourcefile.rb +1 -1
  42. data/test/dummy/app/models/adminpanel/gallery.rb +9 -4
  43. data/test/dummy/app/models/adminpanel/galleryfile.rb +2 -2
  44. data/test/dummy/app/models/adminpanel/photo.rb +1 -1
  45. data/test/dummy/app/models/adminpanel/product.rb +0 -4
  46. data/test/dummy/config/initializers/adminpanel_setup.rb +1 -1
  47. data/test/dummy/test/fixtures/adminpanel/galleryfiles.yml +24 -0
  48. data/test/features/shared/concerns/sortable_gallery_ui_test.rb +25 -0
  49. data/test/features/shared/concerns/sortable_test.rb +4 -4
  50. data/test/features/shared/form/{belongs_to_non_category_modal_test.rb → belongs_to_remote_test.rb} +1 -1
  51. data/test/features/shared/form/{has_many_through_non_category_modal_test.rb → has_many_through_remote_test.rb} +1 -1
  52. data/test/generators/dump_generator_test.rb +1 -13
  53. data/test/generators/gallery_generator_test.rb +1 -1
  54. data/test/generators/initialize_generator_test.rb +1 -9
  55. data/test/generators/resource_generator_test.rb +21 -1
  56. data/test/helpers/router_helper_test.rb +0 -4
  57. data/test/models/adminpanel/sortable_gallery_unit_test.rb +118 -0
  58. data/test/models/adminpanel/sortable_unit_test.rb +75 -0
  59. data/test/tasks/adminpanel_rake_test.rb +1 -1
  60. metadata +86 -85
  61. data/app/assets/images/adminpanel/loguito.png +0 -0
  62. data/app/controllers/adminpanel/categories_controller.rb +0 -52
  63. data/app/controllers/concerns/adminpanel/galleryzable_actions.rb +0 -34
  64. data/app/models/concerns/adminpanel/galleryzation.rb +0 -78
  65. data/app/views/adminpanel/categories/_categories_table.html.erb +0 -48
  66. data/app/views/adminpanel/categories/_category_form.html.erb +0 -33
  67. data/app/views/adminpanel/categories/create.js.erb +0 -6
  68. data/app/views/adminpanel/categories/index.html.erb +0 -63
  69. data/app/views/adminpanel/categories/new.js.erb +0 -5
  70. data/app/views/adminpanel/icons/_move_to_better.html.erb +0 -17
  71. data/app/views/adminpanel/icons/_move_to_worst.html.erb +0 -18
  72. data/app/views/adminpanel/shared/_gallery_entries.html.erb +0 -11
  73. data/app/views/adminpanel/shared/_index_records.html.erb +0 -32
  74. data/app/views/adminpanel/templates/gallery_entries.js.erb +0 -1
  75. data/app/views/adminpanel/templates/index_records.js.erb +0 -1
  76. data/lib/generators/adminpanel/initialize/templates/category_template.rb +0 -45
  77. data/lib/generators/adminpanel/initialize/templates/create_adminpanel_categories_table.rb +0 -11
  78. data/test/features/categories/categories_index_test.rb +0 -31
  79. data/test/features/shared/concerns/galleryzable_test.rb +0 -22
  80. data/test/features/shared/form/belongs_to_category_modal_test.rb +0 -35
  81. data/test/features/shared/form/has_many_through_category_modal_test.rb +0 -35
  82. data/test/models/adminpanel/galleryzable_test.rb +0 -28
@@ -1,52 +0,0 @@
1
- module Adminpanel
2
- class CategoriesController < Adminpanel::ApplicationController
3
- skip_before_action :set_resource_collection
4
-
5
- def index
6
- @categories = Category.all
7
- end
8
-
9
- def new
10
- @resource_instance = @model.new
11
- respond_to do |format|
12
- format.html { render 'adminpanel/templates/new' }
13
- format.js { render }
14
- end
15
- end
16
-
17
- def create
18
- merge_params
19
- @resource_instance = @model.new(send(whitelisted_params))
20
- respond_to do |format|
21
- if @resource_instance.save
22
- format.html { redirect_to categories_path, flash: { success: I18n.t('action.save_success') } }
23
- format.js do
24
- if params[:currentcontroller].to_s == 'adminpanel/categories'
25
- # we are in categories controller
26
- render 'create', locals: { category: @resource_instance }
27
- elsif params[:belongs_request].present?
28
- # we are in other controller as a belongs_to, add option to select
29
- render 'adminpanel/templates/create_belongs_to', locals: { resource: @resource_instance }
30
- else
31
- # we are in other controller as a has_many, add checkbox
32
- render 'adminpanel/templates/create_has_many', locals: { resource: @resource_instance }
33
- end
34
- end
35
- else
36
- format.html { render 'adminpanel/templates/new' }
37
- format.js { render 'new' }
38
- end
39
- end
40
- end
41
-
42
- def destroy
43
- @resource_instance.destroy
44
- redirect_to categories_path
45
- end
46
-
47
- private
48
- def category_params
49
- params.require(:category).permit(:name, :model)
50
- end
51
- end
52
- end
@@ -1,34 +0,0 @@
1
- module Adminpanel
2
- module GalleryzableActions
3
- extend ActiveSupport::Concern
4
-
5
- included do
6
- skip_authorize_resource :move_gallery_better, :move_gallery_worst
7
- end
8
-
9
- def move_gallery_better
10
- @resource_instance = @model.find(params[:id])
11
- @resource_instance.move_to_better_position
12
- respond
13
- end
14
-
15
- def move_gallery_worst
16
- @resource_instance = @model.find(params[:id])
17
- @resource_instance.move_to_worst_position
18
- respond
19
- end
20
-
21
- private
22
- def respond
23
- respond_to do |format|
24
- format.js do
25
- render 'adminpanel/templates/gallery_entries', locals: {
26
- collection: @model.ordered.where(
27
- @model.relation_field.to_sym => @resource_instance.send(@model.relation_field)
28
- )
29
- }
30
- end
31
- end
32
- end
33
- end
34
- end
@@ -1,78 +0,0 @@
1
- module Adminpanel
2
- module Galleryzation
3
- extend ActiveSupport::Concern
4
-
5
- included do
6
- before_create :set_position
7
- before_destroy :rearrange_positions
8
-
9
- scope :ordered, -> do
10
- order('position ASC')
11
- end
12
-
13
- end
14
-
15
- def move_to_better_position
16
- if self.position > 1
17
- conflicting_gallery = get_conflicting_gallery(position - 1)
18
-
19
- self.update_attribute(:position, self.position - 1)
20
-
21
- conflicting_gallery.update_attribute(
22
- :position, conflicting_gallery.position + 1
23
- )
24
- true
25
- else
26
- false
27
- end
28
- end
29
-
30
- def move_to_worst_position
31
- records = self.class.count
32
- if self.position < records
33
- conflicting_gallery = get_conflicting_gallery(position + 1)
34
-
35
- update_attribute(:position, self.position + 1)
36
-
37
- conflicting_gallery.update_attribute(
38
- :position, conflicting_gallery.position - 1
39
- )
40
- true
41
- else
42
- false
43
- end
44
- end
45
-
46
- protected
47
- def get_conflicting_gallery(conflicting_position)
48
- self.class.where(
49
- self.class.relation_field => self.send(self.class.relation_field)
50
- ).find_by_position(conflicting_position)
51
- end
52
-
53
- def rearrange_positions
54
- unarranged_galleries = self.class.where(
55
- self.class.relation_field => self.send(
56
- self.class.relation_field
57
- )
58
- ).where('position > ?', self.position)
59
- unarranged_galleries.each do |gallery|
60
- gallery.update_attribute(:position, gallery.position - 1)
61
- end
62
-
63
- end
64
-
65
- def set_position
66
- last_record = self.class.where(
67
- self.class.relation_field => self.send(
68
- self.class.relation_field
69
- )
70
- ).last
71
- if last_record.nil?
72
- self.position = 1
73
- else
74
- self.position = last_record.position + 1
75
- end
76
- end
77
- end
78
- end
@@ -1,48 +0,0 @@
1
- <div class="row-fluid">
2
- <%=
3
- link_to(
4
- content_tag(:div,
5
- content_tag(
6
- :i,
7
- nil,
8
- :class => 'fa fa-plus-circle fa-2x') +
9
- content_tag(
10
- :span,
11
- I18n.t("action.create", resource: @model.display_name) + " para #{model}",
12
- nil
13
- ),
14
- :class => "btn btn-box span2"),
15
- {
16
- :controller => params[:controller],
17
- :action => "new",
18
- :"model" => model,
19
- :currentcontroller => params[:controller]
20
- },
21
- :"data-target" => '#new-category',
22
- :"data-toggle" => 'modal',
23
- :remote => true
24
- )
25
- %>
26
- </div>
27
-
28
- <br/>
29
-
30
- <table id="<%= model %>-table" class="table table-striped table-bordered">
31
- <tr>
32
- <th><%= t("category.name") %></th>
33
- <th><%= t("actions") %></th>
34
- </tr>
35
- <% categories.each do |category| %>
36
- <tr>
37
- <td><%= link_to category.name, category_path(category) %></td>
38
- <td>
39
- <%= render 'adminpanel/icons/show', resource: category %>
40
-
41
- <%= render 'adminpanel/icons/edit', resource: category %>
42
-
43
- <%= render 'adminpanel/icons/delete', resource: category %>
44
- </td>
45
- </tr>
46
- <% end %>
47
-
48
- </table>
@@ -1,33 +0,0 @@
1
- <%= adminpanel_form_for(
2
- resource,
3
- url: {
4
- action: :create,
5
- model: params[:model],
6
- model_name: params[:model_name],
7
- currentcontroller: params[:currentcontroller],
8
- belongs_request: params[:belongs_request]
9
- },
10
- remote: true,
11
- html: {
12
- class: "form-horizontal",
13
- id: "new-category-form"
14
- }
15
- ) do |f| %>
16
- <div class="row-fluid">
17
- <div class="modal-body">
18
- <%= render 'adminpanel/shared/error_messages', object: resource %>
19
- <%= render 'adminpanel/shared/form_fields', f: f %>
20
- <%= f.hidden_field :model, value: params[:model] %>
21
- </div>
22
- </div>
23
- <div class="modal-footer">
24
- <button id="modal-button" class="btn" data-dismiss="modal" aria-hidden="true"><%= I18n.t('action.close') %></button>
25
- <%= f.submit(
26
- t("action.add", resource: @model.display_name),
27
- data: {
28
- disable_with: t("action.submitting")
29
- },
30
- id: "new-#{@model.name.demodulize}-button"
31
- ) %>
32
- </div>
33
- <% end %>
@@ -1,6 +0,0 @@
1
- $('#new-category').modal('toggle');
2
- row = "<tr><td><%= escape_javascript link_to @resource_instance.name, category_path(@resource_instance) %></td>";
3
- row = row + "<td><%= escape_javascript link_to content_tag(:i, nil, class: 'fa fa-pencil'), edit_category_path(@resource_instance), title: 'Editar' %> ";
4
- row = row + "<%= escape_javascript link_to content_tag(:i, nil, class: 'fa fa-remove'),[@resource_instance], title: 'Editar', method: :delete %></td>";
5
- row = row + "</tr>";
6
- $("#<%= @resource_instance.model %>-table").append(row);
@@ -1,63 +0,0 @@
1
- <%= provide(:page_title, I18n.t('model.Categories')) %>
2
-
3
- <div class="row-fluid">
4
- <div class="widget widget-padding span12">
5
- <div class="widget-header">
6
- <ul class="nav nav-tabs">
7
- <% current_page = "no-page" %>
8
- <% @categories.each_with_index do |category, index| %>
9
- <% if current_page != category.model %>
10
- <li class = "<%= active_tab(index) %>">
11
- <%=
12
- link_to(
13
- (category.model.capitalize.pluralize(I18n.default_locale)),
14
- "#tab#{index}",
15
- "data-toggle" => "tab"
16
- )
17
- %>
18
- </li>
19
- <% current_page = category.model %>
20
- <% end %>
21
- <% end %>
22
- </ul>
23
- </div>
24
-
25
- <div class="widget-body">
26
- <div class="tab-content">
27
- <% current_page = 'no-page' %>
28
- <% @categories.each_with_index do |category, index| %>
29
-
30
- <% if current_page != category.model %>
31
- <% if index == 0 %>
32
- <div class="tab-pane active" id="tab<%= index %>">
33
- <% else %>
34
- <div class="tab-pane" id="tab<%= index %>">
35
- <% end %>
36
- <% current_cateogory_records = @categories.select {|c| c.model == category.model } %>
37
- <%=
38
- render(
39
- 'categories_table',
40
- categories: current_cateogory_records,
41
- model: category.model
42
- ) %>
43
- </div>
44
- <% current_page = category.model %>
45
- <% end %>
46
- <% end %>
47
- </div>
48
-
49
- </div>
50
- </div>
51
- </div>
52
-
53
- <!-- modal -->
54
- <%= render(
55
- 'adminpanel/shared/modal',
56
- id: 'new-category',
57
- title: (
58
- I18n.t(
59
- 'action.create',
60
- resource: I18n.t('model.Category')
61
- )
62
- )
63
- ) %>
@@ -1,5 +0,0 @@
1
- $("#modal-title").html('Agregar <%= @model.display_name %>');
2
- $("#modal-container").html('<%= escape_javascript(render "category_form", :resource => @resource_instance) %>');
3
- setTimeout(function() {
4
- $("#remote-form-modal input[type='text']:first").focus();
5
- }, 500);
@@ -1,17 +0,0 @@
1
- <% if @model.has_route?(:edit) && can?(:update, @model) %>
2
- <% if ! defined? path %>
3
- <!-- if defined we're called from gallery sort -->
4
- <% path = [:move_to_better, member] %>
5
- <% end %>
6
- <%= link_to(
7
- content_tag(
8
- :i,
9
- nil,
10
- class: 'fa fa-chevron-up'
11
- ),
12
- path,
13
- title: I18n.t('action.move_to_better', resource: member.name),
14
- method: :put,
15
- remote: true
16
- ) %>
17
- <% end %>
@@ -1,18 +0,0 @@
1
- <% if @model.has_route?(:edit) && can?(:update, @model) %>
2
- <% if ! defined? path %>
3
- <!-- if defined we're called for gallery sort -->
4
- <% path = [:move_to_worst, member] %>
5
- <% end %>
6
-
7
- <%= link_to(
8
- content_tag(
9
- :i,
10
- nil,
11
- class: 'fa fa-chevron-down'
12
- ),
13
- path,
14
- title: I18n.t('action.move_to_worst', resource: member.name),
15
- method: :put,
16
- remote: true
17
- ) %>
18
- <% end %>
@@ -1,11 +0,0 @@
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
- <%= render 'adminpanel/icons/move_to_better', path: [:move_gallery_to_better, image] %>
7
- <%= render 'adminpanel/icons/move_to_worst', path: [:move_gallery_to_worst, image] %>
8
- </li>
9
- </ul>
10
- </li>
11
- <% end %>
@@ -1,32 +0,0 @@
1
- <% collection.each do |member| %>
2
- <% cache ["#{member.class}-member", member] do %>
3
- <tr>
4
- <% @model.display_attributes('index').each do |fields| %>
5
- <% fields.each do |attribute, properties| %>
6
- <td>
7
- <%= field_value(properties, attribute, member) %>
8
- </td>
9
- <% end %>
10
- <% end %>
11
- <% if @model.is_sortable? %>
12
- <!-- if has included the orderable concern -->
13
- <td>
14
- <%= render 'adminpanel/icons/move_to_better', member: member %>
15
-
16
- <%= render 'adminpanel/icons/move_to_worst', member: member %>
17
- </td>
18
- <% end %>
19
- <td>
20
- <%= render 'adminpanel/icons/show', resource: member %>
21
-
22
- <%= render 'adminpanel/icons/edit', resource: member %>
23
-
24
- <%= render 'adminpanel/icons/delete', resource: member %>
25
-
26
- <%= render 'adminpanel/icons/facebook', resource: member %>
27
-
28
- <%= render 'adminpanel/icons/twitter', resource: member %>
29
- </td>
30
- </tr>
31
- <% end %>
32
- <% end %>
@@ -1 +0,0 @@
1
- $('#gallery-entries').html("<%= escape_javascript(render 'adminpanel/shared/gallery_entries', :images => collection) %>")
@@ -1 +0,0 @@
1
- $("#body-content").html("<%= escape_javascript(render 'adminpanel/shared/index_records', collection: collection ) %>");
@@ -1,45 +0,0 @@
1
- module Adminpanel
2
- class Category < ActiveRecord::Base
3
- include Adminpanel::Base
4
-
5
- validates_presence_of :model
6
- validates_presence_of :name
7
- validates_uniqueness_of :name
8
-
9
-
10
- # has_many :categorizations
11
- # has_many :products, :through => :categorizations, :dependent => :destroy
12
-
13
-
14
- def self.form_attributes
15
- [
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
- },
31
- ]
32
- end
33
-
34
- def self.display_name
35
- "Categoria" #singular
36
- end
37
-
38
- def self.icon
39
- "bookmark" #fa-{icon}
40
- end
41
-
42
- default_scope { order("model ASC")}
43
- scope :of_model, lambda{|model| where(:model => model)}
44
- end
45
- end