adminpanel 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +3 -2
  3. data/Gemfile +24 -24
  4. data/README.md +8 -2
  5. data/adminpanel.gemspec +39 -39
  6. data/app/assets/javascripts/adminpanel/realm.js +0 -3
  7. data/app/controllers/adminpanel/galleries_controller.rb +38 -2
  8. data/app/models/adminpanel/gallery.rb +51 -0
  9. data/app/models/adminpanel/section.rb +6 -1
  10. data/app/views/adminpanel/galleries/_galleries_table.html.erb +15 -0
  11. data/app/views/adminpanel/galleries/index.html.erb +6 -15
  12. data/app/views/adminpanel/galleries/move_better.js.erb +1 -0
  13. data/app/views/adminpanel/galleries/move_worst.js.erb +1 -0
  14. data/app/views/adminpanel/sections/_sections_table.html.erb +17 -0
  15. data/app/views/adminpanel/sections/index.html.erb +36 -30
  16. data/app/views/layouts/admin.html.erb +2 -3
  17. data/config/locales/es.yml +10 -0
  18. data/config/routes.rb +6 -1
  19. data/lib/adminpanel.rb +7 -7
  20. data/lib/adminpanel/version.rb +3 -3
  21. data/lib/generators/adminpanel/install/templates/migrations/create_adminpanel_tables.rb +17 -0
  22. data/spec/dummy/db/schema.rb +1 -51
  23. data/spec/features/galleries_pages_spec.rb +69 -1
  24. data/spec/features/section_pages_spec.rb +1 -1
  25. data/spec/models/gallery_spec.rb +4 -0
  26. data/spec/models/section_spec.rb +27 -15
  27. data/spec/spec_helper.rb +2 -0
  28. data/spec/support/define_factory_models.rb +1 -0
  29. data/spec/support/{active_record.rb → test_database.rb} +2 -3
  30. data/spec/uploaders/gallery_uploader_spec.rb +1 -1
  31. data/spec/uploaders/image_uploader_spec.rb +0 -1
  32. metadata +8 -12
  33. data/spec/dummy/public/uploads/image/file/1/hipster.jpg +0 -0
  34. data/spec/dummy/public/uploads/image/file/1/portfolio_hipster.jpg +0 -0
  35. data/spec/dummy/public/uploads/image/file/1/thumb_hipster.jpg +0 -0
  36. data/spec/support/schema.rb +0 -64
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA512:
3
- metadata.gz: 6d8f123e3a3faf4e15d9314743b74780780988363dcb070d23b4cea17671beb6fc807be8ac42f392cdee3949c4dea68ceb824bfe8226f311d465475f5e39a8d7
4
- data.tar.gz: 819a1638157388e34921f75d3fe4f707fd8f6a6cc7e102da078ce0761ad3aa4d474b1e1d6b2d61df54beeca2b9f7ae7851fc2515b7af3d53f5668e07f8e3cd74
5
2
  SHA1:
6
- metadata.gz: 6b1cb78b89c6b70303680facd5f010f5ac177828
7
- data.tar.gz: 459579d0e5a2168f0a4cc4d31a4dc83912cd2612
3
+ metadata.gz: 435b2e9a0b1762665f46f09b0139867b12b4309e
4
+ data.tar.gz: 2ada99e5776704ba5872ffa3345673fb7d2b6626
5
+ SHA512:
6
+ metadata.gz: c956d64b07c304bdf6f650bc78b0ad4c455f59d4195219985c6ae8c344fa059c2e46cd8c2949cf8eaa5955e7ceba8a11d910f311be29bcb41a911aed775c0475
7
+ data.tar.gz: cdfe59993943b62d09aed0dca24177d10cce055041b8a47e0b640b495eaf2c107f9c256dd538f820f34833c21baf32c5cb7005b03d42403e73a20ab67c2e65a1
data/.travis.yml CHANGED
@@ -1,6 +1,7 @@
1
1
  language: ruby
2
- notifications:
3
- email: false
2
+ before_install:
3
+ - gem update --system 2.1.11
4
+ - gem --version
4
5
  rvm:
5
6
  - "1.8.7"
6
7
  env:
data/Gemfile CHANGED
@@ -1,24 +1,24 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in adminpanel.gemspec
4
- # gemspec
5
-
6
- gem "rails", "~> 3.2.12"
7
- gem "carrierwave", "~> 0.9.0"
8
- gem "rmagick", "~> 2.13.2"
9
- gem "jquery-rails", "~> 3.0.4"
10
- gem "bcrypt-ruby", "~> 3.0.0"
11
- gem "rails-i18n", "~> 3.0.0"
12
-
13
- group :test do
14
- gem "bundler", "~> 1.3"
15
- gem "activerecord", "3.2.12"
16
- gem "rspec", "2.14.0"
17
- gem "rspec-rails"
18
- gem "sqlite3", :platform => [:ruby, :mswin, :mingw]
19
- gem "rake"
20
- gem "factory_girl", "2.6.4"
21
- gem "capybara", "1.1.4"
22
- gem "nokogiri", "1.5.9"
23
- gem "rubyzip", "0.9.9"
24
- end
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in adminpanel.gemspec
4
+ # gemspec
5
+
6
+ gem "rails", "~> 3.2.12"
7
+ gem "carrierwave", "~> 0.9.0"
8
+ gem "rmagick", "~> 2.13.2"
9
+ gem "jquery-rails", "~> 3.0.4"
10
+ gem "bcrypt-ruby", "~> 3.0.0"
11
+ gem "rails-i18n", "~> 3.0.0"
12
+
13
+ group :test do
14
+ gem "bundler", "~> 1.3"
15
+ gem "activerecord", "3.2.12"
16
+ gem "rspec", "2.14.0"
17
+ gem "rspec-rails"
18
+ gem "sqlite3", :platform => [:ruby, :mswin, :mingw]
19
+ gem "rake"
20
+ gem "factory_girl", "2.6.4"
21
+ gem "capybara", "1.1.4"
22
+ gem "nokogiri", "1.5.9"
23
+ gem "rubyzip", "0.9.9"
24
+ end
data/README.md CHANGED
@@ -29,13 +29,16 @@ Then run:
29
29
 
30
30
  rails g adminpanel:install create_migrations
31
31
  rake db:migrate
32
- to create the database that the adminpanel it's expecting.
32
+ to create the database that the adminpanel it's expecting, this will also seed the database with the default user.
33
33
 
34
34
  Then, mount the gem wherever you like!
35
35
 
36
36
  mount Adminpanel::Engine => "/admin"
37
37
 
38
- Any doubts or errors feel free to ask me!
38
+ Also make sure to include adminpanel assets in your application.rb if you need to precompile them:
39
+
40
+ config.assets.precompile += ['application-admin.js', 'application-admin.css']
41
+ The version 0.1.0 is the first stable version, feel free to use it, any doubts or errors feel free to ask me!.
39
42
 
40
43
  ## Contributing
41
44
 
@@ -49,3 +52,6 @@ Any doubts or errors feel free to ask me!
49
52
 
50
53
  1. Add english support
51
54
  2. Add the medium editor to the custom builder so it inits itself
55
+ 3. Get a section generator or some kind of it
56
+ 4. Add test to section edit(the only tests remaining)
57
+ 5. Add a generator that let you create scaffolded model/controller/view in way that you can change them in the main app.
data/adminpanel.gemspec CHANGED
@@ -1,39 +1,39 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'adminpanel/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "adminpanel"
8
- spec.version = Adminpanel::VERSION
9
- spec.authors = ["Jose Ramon Camacho", "Victor Camacho"]
10
- spec.email = ["joserracamacho@gmail.com"]
11
- spec.description = %q{Gem that makes the admin panel for a site a breeze!}
12
- spec.summary = %q{Developed with love for ruby 1.8.7}
13
- spec.homepage = "https://github.com/joseramonc/adminpanel"
14
- spec.license = "MIT"
15
-
16
- spec.files = `git ls-files`.split($/)
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib", "app/assets"]
20
-
21
-
22
- spec.add_dependency "rails", "~> 3.2.12"
23
- spec.add_dependency "carrierwave", "~> 0.9.0"
24
- spec.add_dependency "rmagick", "~> 2.13.2"
25
- spec.add_dependency "jquery-rails", "~> 3.0.4"
26
- spec.add_dependency "bcrypt-ruby", "~> 3.0.0"
27
- spec.add_dependency "rails-i18n", "~> 3.0.0"
28
-
29
- spec.add_development_dependency "bundler", "~> 1.3"
30
- spec.add_development_dependency "activerecord", "~> 3.2.12"
31
- spec.add_development_dependency "rake"
32
- spec.add_development_dependency "sqlite3"
33
- spec.add_development_dependency "factory_girl_rails", "2.6.4"
34
- spec.add_development_dependency "rspec", "~> 2.14.0"
35
- spec.add_development_dependency "rspec-rails", "~> 2.14.0"
36
- spec.add_development_dependency "capybara", "1.1.4"
37
- spec.add_development_dependency "nokogiri", "1.5.9"
38
- spec.add_development_dependency "rubyzip", "0.9.9"
39
- end
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'adminpanel/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "adminpanel"
8
+ spec.version = Adminpanel::VERSION
9
+ spec.authors = ["Jose Ramon Camacho", "Victor Camacho"]
10
+ spec.email = ["joserracamacho@gmail.com"]
11
+ spec.description = %q{Gem that makes the admin panel for a site a breeze!}
12
+ spec.summary = %q{Developed with love for ruby 1.8.7}
13
+ spec.homepage = "https://github.com/joseramonc/adminpanel"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib", "app/assets"]
20
+
21
+
22
+ spec.add_dependency "rails", "~> 3.2.12"
23
+ spec.add_dependency "carrierwave", "~> 0.9.0"
24
+ spec.add_dependency "rmagick", "~> 2.13.2"
25
+ spec.add_dependency "jquery-rails", "~> 3.0.4"
26
+ spec.add_dependency "bcrypt-ruby", "~> 3.0.0"
27
+ spec.add_dependency "rails-i18n", "~> 3.0.0"
28
+
29
+ spec.add_development_dependency "bundler", "~> 1.3"
30
+ spec.add_development_dependency "activerecord", "~> 3.2.12"
31
+ spec.add_development_dependency "rake"
32
+ spec.add_development_dependency "sqlite3"
33
+ spec.add_development_dependency "factory_girl_rails", "2.6.4"
34
+ spec.add_development_dependency "rspec", "~> 2.14.0"
35
+ spec.add_development_dependency "rspec-rails", "~> 2.14.0"
36
+ spec.add_development_dependency "capybara", "1.1.4"
37
+ spec.add_development_dependency "nokogiri", "1.5.9"
38
+ spec.add_development_dependency "rubyzip", "0.9.9"
39
+ end
@@ -60,9 +60,6 @@ $(function() {
60
60
  }); // end document reday
61
61
 
62
62
 
63
-
64
-
65
-
66
63
  //----- Side menu functions -----//
67
64
 
68
65
  // slide menu out of view
@@ -1,7 +1,7 @@
1
1
  module Adminpanel
2
2
  class GalleriesController < Adminpanel::ApplicationController
3
3
  def index
4
- @galleries = Gallery.all
4
+ @galleries = Gallery.find(:all)
5
5
  end
6
6
 
7
7
  def show
@@ -22,11 +22,47 @@ module Adminpanel
22
22
  end
23
23
  end
24
24
 
25
+ def move_better
26
+ @gallery = Gallery.find(params[:id])
27
+ if @gallery.move_to_better_position
28
+ flash[:success] = t("gallery.moved")
29
+ else
30
+ flash[:warning] = t("gallery.not-moved")
31
+ end
32
+ respond_to do |format|
33
+ format.html do
34
+ redirect_to galleries_path
35
+ end
36
+ format.js do
37
+ @galleries = Gallery.all
38
+ render :locals => { :galleries => @galleries }
39
+ end
40
+ end
41
+ end
42
+
43
+ def move_worst
44
+ @gallery = Gallery.find(params[:id])
45
+ if @gallery.move_to_worst_position
46
+ flash[:success] = t("gallery.moved")
47
+ else
48
+ flash[:warning] = t("gallery.not-moved")
49
+ end
50
+ respond_to do |format|
51
+ format.html do
52
+ redirect_to galleries_path
53
+ end
54
+ format.js do
55
+ @galleries = Gallery.all
56
+ render :locals => { :galleries => @galleries }
57
+ end
58
+ end
59
+ end
60
+
25
61
  def destroy
26
62
  @gallery = Gallery.find(params[:id])
27
63
  @gallery.destroy
28
64
 
29
- redirect_to galleries_path, :notice => "La imagen ha sido eliminada"
65
+ redirect_to galleries_path, :notice => t("gallery.deleted")
30
66
  end
31
67
 
32
68
  def update
@@ -6,5 +6,56 @@ module Adminpanel
6
6
 
7
7
  mount_uploader :file, Adminpanel::GalleryUploader
8
8
  validates_presence_of :file
9
+ before_create :set_position
10
+ before_destroy :rearrange_positions
11
+
12
+
13
+ default_scope { order("position ASC")}
14
+
15
+
16
+ def move_to_better_position
17
+ if position > 1
18
+ conflicting_gallery = Gallery.find_by_position(position - 1)
19
+ update_attribute(:position, position - 1)
20
+ conflicting_gallery.update_attribute(
21
+ :position, conflicting_gallery.position + 1
22
+ )
23
+ true
24
+ else
25
+ false
26
+ end
27
+ end
28
+
29
+ def move_to_worst_position
30
+ records = Gallery.count
31
+ if position < records
32
+ conflicting_gallery = Gallery.find_by_position(position + 1)
33
+ update_attribute(:position, position + 1)
34
+ conflicting_gallery.update_attribute(
35
+ :position, conflicting_gallery.position - 1
36
+ )
37
+ true
38
+ else
39
+ false
40
+ end
41
+ end
42
+
43
+ private
44
+ def rearrange_positions
45
+ unarranged_galleries = Gallery.where("position > ?", position)
46
+ unarranged_galleries.each do |gallery|
47
+ gallery.update_attribute(:position, gallery.position - 1)
48
+ end
49
+
50
+ end
51
+
52
+ def set_position
53
+ last_record = Gallery.last
54
+ if last_record.nil?
55
+ self.position = 1
56
+ else
57
+ self.position = last_record.position + 1
58
+ end
59
+ end
9
60
  end
10
61
  end
@@ -2,7 +2,7 @@ require 'carrierwave'
2
2
  require 'carrierwave/orm/activerecord'
3
3
  module Adminpanel
4
4
  class Section < ActiveRecord::Base
5
- attr_accessible :description, :has_image, :key, :name, :has_description, :images_attributes
5
+ attr_accessible :description, :has_image, :key, :page, :name, :has_description, :images_attributes
6
6
  has_many :images, :foreign_key => "foreign_key", :conditions => { :model => "Section" }
7
7
  accepts_nested_attributes_for :images, :allow_destroy => true
8
8
  validates_length_of :description, :minimum => 10, :maximum => 10, :on => :update, :if => lambda{|section| section.key == "telephone"}
@@ -10,6 +10,11 @@ module Adminpanel
10
10
  validates :description, :numericality => { :only_integer => true }, :on => :update, :if => lambda{|section| section.key == "telephone"}
11
11
  validates_presence_of :key
12
12
  validates_presence_of :name
13
+ validates_presence_of :page
14
+
15
+ default_scope { order("page ASC")}
16
+
17
+ scope :of_page, lambda{|page| where(:page => page)}
13
18
 
14
19
  def simple_name
15
20
  "Section"
@@ -0,0 +1,15 @@
1
+ <% @galleries.each do |gallery| %>
2
+ <tr>
3
+ <td><%= link_to image_tag(gallery.file_url(:thumb)), gallery_path(gallery) %></td>
4
+ <td>
5
+ <%= link_to content_tag(:i, nil, :class => "icon-chevron-up"), move_to_better_gallery_path(gallery), :method => :put, :remote => true %>
6
+ <%= link_to content_tag(:i, nil, :class => "icon-chevron-down"), move_to_worst_gallery_path(gallery), :method => :put, :remote => true %>
7
+ </td>
8
+ <td>
9
+ <%= link_to content_tag(:i, nil, :class => 'icon-pencil'), edit_gallery_path(gallery), :title => t("action.edit") %>
10
+ <%= link_to content_tag(:i, nil, :class => 'icon-remove'), gallery_path(gallery), :title => t("action.delete"), :method => :delete,
11
+ :data => { :confirm => t("action.delete confirmation") }
12
+ %>
13
+ </td>
14
+ </tr>
15
+ <% end %>
@@ -29,25 +29,16 @@
29
29
  </div>
30
30
  <div class="widget-body">
31
31
  <div class="dataTables_wrapper form-inline">
32
- <table id="information-table" class="table table-striped table-bordered dataTable">
32
+ <table class="table table-striped table-bordered dataTable">
33
33
  <thead>
34
34
  <tr>
35
- <th>Imagen</th>
36
- <th>Acción</th>
35
+ <th><%= t("gallery.image") %></th>
36
+ <th><%= t("gallery.position") %></th>
37
+ <th><%= t("gallery.action") %></th>
37
38
  </tr>
38
39
  </thead>
39
- <tbody>
40
- <% @galleries.each do |gallery| %>
41
- <tr>
42
- <td><%= link_to image_tag(gallery.file_url(:thumb)), gallery_path(gallery) %></td>
43
- <td>
44
- <%= link_to content_tag(:i, nil, :class => 'icon-pencil'), edit_gallery_path(gallery), :title => t("action.edit") %>
45
- <%= link_to content_tag(:i, nil, :class => 'icon-remove'), gallery_path(gallery), :title => t("action.delete"), :method => :delete,
46
- :data => { :confirm => t("action.delete confirmation") }
47
- %>
48
- </td>
49
- </tr>
50
- <% end %>
40
+ <tbody id = "galleries-content">
41
+ <%= render 'galleries_table', :galleries => @galleries %>
51
42
  </tbody>
52
43
  </table>
53
44
  <div class="row-fluid">
@@ -0,0 +1 @@
1
+ $("#galleries-content").html("<%= escape_javascript(render 'galleries_table', :locals => { :galleries => @galleries } ) %>");
@@ -0,0 +1 @@
1
+ $("#galleries-content").html("<%= escape_javascript(render 'galleries_table', :locals => { :galleries => @galleries } ) %>");
@@ -0,0 +1,17 @@
1
+ <table class="table table-striped table-bordered">
2
+ <tr>
3
+ <th><%= t("section.name") %></th>
4
+ <th><%= t("section.description") %></th>
5
+ <th><%= t("actions") %></th>
6
+ </tr>
7
+ <% sections.each do |section| %>
8
+ <tr>
9
+ <td><%= link_to section.name, section_path(section) %></td>
10
+ <td><%= strip_tags section.description %></td>
11
+ <td>
12
+ <%= link_to content_tag(:i, nil, :class => 'icon-pencil'), edit_section_path(section), :title => "Editar" %>
13
+ </td>
14
+ </tr>
15
+ <% end %>
16
+
17
+ </table>
@@ -1,38 +1,44 @@
1
1
  <%= provide(:page_title, "Secciones") %>
2
2
 
3
3
  <div class="row-fluid">
4
- <div class="widget widget-padding span12">
4
+ <div class="widget widget-padding span12" id="wizard">
5
5
  <div class="widget-header">
6
- <i class="icon-tasks"></i>
7
- <h5>Secciones</h5>
8
- </div>
6
+ <ul class="nav nav-tabs">
7
+ <% current_page = "no-page" %>
8
+ <% @sections.each_with_index do |section, index| %>
9
+ <% if current_page != section.page %>
10
+ <% if index == 0 %>
11
+ <li class = "active">
12
+ <% else %>
13
+ <li>
14
+ <% end %>
15
+ <%= link_to (section.page.capitalize), "#tab#{index}", "data-toggle" => "tab" %></li>
16
+ <% current_page = section.page %>
17
+ <% end %>
18
+ <% end %>
19
+ </ul>
20
+ </div>
21
+
9
22
  <div class="widget-body">
10
- <div class="dataTables_wrapper form-inline">
11
- <table id="information-table" class="table table-striped table-bordered dataTable">
12
- <thead>
13
- <tr>
14
- <th>Nombre</th>
15
- <th>Descripción</th>
16
- <th>Acción</th>
17
- </tr>
18
- </thead>
19
- <tbody>
20
- <% @sections.each do |section| %>
21
- <tr>
22
- <td><%= link_to section.name, section_path(section) %></td>
23
- <td><%= strip_tags section.description %></td>
24
- <td>
25
- <%= link_to content_tag(:i, nil, :class => 'icon-pencil'), edit_section_path(section), :title => "Editar" %>
26
- </td>
27
- </tr>
28
- <% end %>
29
- </tbody>
30
- </table>
31
- <div class="row-fluid">
32
- <div class="span6"></div>
33
- <div class="span6"></div>
34
- </div>
35
- </div>
23
+ <div class="tab-content">
24
+ <% current_page = "no-page" %>
25
+ <% @sections.each_with_index do |section, index| %>
26
+ <% if current_page != section.page %>
27
+ <% if index == 0 %>
28
+ <div class="tab-pane active" id="tab<%= index %>">
29
+ <% else %>
30
+ <div class="tab-pane" id="tab<%= index %>">
31
+ <% end %>
32
+ <% section_pages = Adminpanel::Section.of_page section.page %>
33
+ <%= render "sections_table", :sections => section_pages %>
34
+ </div>
35
+ <% current_page = section.page %>
36
+ <% end %>
37
+ <% end %>
38
+ </div>
39
+
36
40
  </div>
37
41
  </div>
38
42
  </div>
43
+
44
+
@@ -4,13 +4,12 @@
4
4
  <meta charset="utf-8">
5
5
  <title><%= full_title(yield(:page_title)) %></title>
6
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
- <meta name="author" content="Bluth Company">
8
7
  <%= stylesheet_link_tag "application-admin", :media => "all" %>
9
8
  <%= javascript_include_tag "application-admin" %>
10
9
  <%= csrf_meta_tags %>
11
- <link rel="shortcut icon" href="favicon.ico">
10
+ <%= favicon_link_tag "favicon.ico" %>
12
11
  <link href="http://fonts.googleapis.com/css?family=Open+Sans:400,700" rel="stylesheet" type="text/css">
13
- <link rel="Favicon Icon" href="favicon.ico">
12
+
14
13
  <%= render 'layouts/shim' %>
15
14
  </head>
16
15
 
@@ -89,6 +89,7 @@ es:
89
89
  Write description here: "Escriba la descripción aquí"
90
90
  Panel title: "Panel Administrativo"
91
91
  New: "Nuevo"
92
+ actions: "Acciones"
92
93
  action:
93
94
  submiting: "Enviando..."
94
95
  save: "Guardar"
@@ -108,11 +109,20 @@ es:
108
109
  gallery:
109
110
  new: "Agregar Imagen"
110
111
  success: "La imagen ha sido guardada"
112
+ deleted: "La imagen ha sido eliminada"
113
+ moved : "Se ha actualizado la posición de la galería"
114
+ not-moved: "No se pudo mover la Imagen"
115
+ image: "Imagen"
116
+ position: "Posición"
117
+ action: "Acción"
111
118
  user:
112
119
  new: "Agregar Usuario"
113
120
  success: "El usuario ha sido guardado"
114
121
  section:
122
+ name: "Nombre"
123
+ description: "Descripción"
115
124
  edit: "Editar Sección"
125
+ default: "Sin Sección"
116
126
  session:
117
127
  password: "Contraseña"
118
128
  email: "Correo electrónico"
data/config/routes.rb CHANGED
@@ -1,7 +1,12 @@
1
1
  Adminpanel::Engine.routes.draw do
2
2
  resources :sections, :except => [:new]
3
3
  resources :users
4
- resources :galleries
4
+ resources :galleries do
5
+ member do
6
+ put :move_better, :as => "move_to_better"
7
+ put :move_worst, :as => "move_to_worst"
8
+ end
9
+ end
5
10
  resources :sessions, :only => [:new, :create, :destroy]
6
11
  resources :products
7
12
  resources :categories
data/lib/adminpanel.rb CHANGED
@@ -1,7 +1,7 @@
1
- require "adminpanel/version"
2
- require "adminpanel/engine"
3
-
4
- module Adminpanel
5
- class AccessDenied < StandardError
6
- end
7
- end
1
+ require "adminpanel/version"
2
+ require "adminpanel/engine"
3
+
4
+ module Adminpanel
5
+ class AccessDenied < StandardError
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
- module Adminpanel
2
- VERSION = "0.1.0"
3
- end
1
+ module Adminpanel
2
+ VERSION = "0.1.1"
3
+ end
@@ -1,4 +1,12 @@
1
1
  class CreateAdminpanelTables < ActiveRecord::Migration
2
+ def migrate(direction)
3
+ super
4
+ # Create a default user
5
+ if direction == :up
6
+ Adminpanel::User.new(:email => 'admin@admin.com', :name => "Admin", :password => 'password', :password_confirmation => 'password').save
7
+ end
8
+ end
9
+
2
10
  def change
3
11
  create_table :adminpanel_products do |t|
4
12
  t.integer :category_id
@@ -20,6 +28,7 @@ class CreateAdminpanelTables < ActiveRecord::Migration
20
28
 
21
29
  create_table :adminpanel_galleries do |t|
22
30
  t.string :file
31
+ t.integer :position
23
32
  t.timestamps
24
33
  end
25
34
 
@@ -35,9 +44,17 @@ class CreateAdminpanelTables < ActiveRecord::Migration
35
44
  t.boolean :has_description
36
45
  t.text :description
37
46
  t.string :key
47
+ t.string :page
38
48
  t.boolean :has_image
39
49
  t.timestamps
40
50
  end
51
+
52
+ create_table :adminpanel_clients do |t|
53
+ t.string :name
54
+ t.string :logo
55
+ t.timestamps
56
+ end
57
+
41
58
  add_index :adminpanel_sections, [:key]
42
59
 
43
60
  create_table :adminpanel_categories do |t|
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  # This file is auto-generated from the current state of the database. Instead
3
2
  # of editing this file, please use the migrations feature of Active Record to
4
3
  # incrementally modify your database, and then regenerate this schema definition.
@@ -11,55 +10,6 @@
11
10
  #
12
11
  # It's strongly recommended to check this file into your version control system.
13
12
 
14
- ActiveRecord::Schema.define(:version => 20131120070259) do
15
-
16
- create_table "adminpanel_users", :force => true do |t|
17
- t.string "name"
18
- t.string "email"
19
- t.string "password_digest"
20
- t.string "remember_token"
21
- t.datetime "created_at", :null => false
22
- t.datetime "updated_at", :null => false
23
- end
24
-
25
- create_table "adminpanel_categories", :force => true do |t|
26
- t.string "name"
27
- t.datetime "created_at", :null => false
28
- t.datetime "updated_at", :null => false
29
- end
30
-
31
- create_table "adminpanel_galleries", :force => true do |t|
32
- t.string "file"
33
- t.datetime "created_at", :null => false
34
- t.datetime "updated_at", :null => false
35
- end
36
-
37
- create_table "adminpanel_images", :force => true do |t|
38
- t.string "file"
39
- t.integer "foreign_key"
40
- t.datetime "created_at", :null => false
41
- t.datetime "updated_at", :null => false
42
- t.string "model"
43
- end
44
-
45
- create_table "adminpanel_products", :force => true do |t|
46
- t.string "name"
47
- t.text "description"
48
- t.datetime "created_at", :null => false
49
- t.datetime "updated_at", :null => false
50
- t.integer "category_id"
51
- t.string "brief"
52
- end
53
-
54
- create_table "adminpanel_sections", :force => true do |t|
55
- t.string "name"
56
- t.text "description"
57
- t.string "key"
58
- t.boolean "has_image"
59
- t.string "file"
60
- t.datetime "created_at", :null => false
61
- t.datetime "updated_at", :null => false
62
- t.boolean "has_description"
63
- end
13
+ ActiveRecord::Schema.define(:version => 0) do
64
14
 
65
15
  end
@@ -11,7 +11,7 @@ describe "Gallery pages" do
11
11
  end
12
12
 
13
13
  describe "galleries" do
14
- let(:gallery) { Factory(:gallery) }
14
+ let(:gallery) { Factory(:gallery) }
15
15
  before do
16
16
  visit adminpanel.galleries_path
17
17
  end
@@ -19,6 +19,74 @@ describe "Gallery pages" do
19
19
  it { should have_link(I18n.t("gallery.new"), adminpanel.new_gallery_path)}
20
20
  it { should have_link("i", adminpanel.gallery_path(gallery)) }
21
21
  it { should have_link("i", adminpanel.edit_gallery_path(gallery)) }
22
+ it { should have_link("i", adminpanel.move_to_better_gallery_path(gallery)) }
23
+ it { should have_link("i", adminpanel.move_to_worst_gallery_path(gallery)) }
24
+ end
25
+
26
+ describe "when creating" do
27
+ describe "a single image" do
28
+ let(:gallery) { Factory(:gallery)}
29
+ it { gallery.position.should eq 1 }
30
+ end
31
+
32
+ describe "3 images" do
33
+ let!(:gallery_1) { Factory(:gallery) }
34
+ let!(:gallery_2) { Factory(:gallery) }
35
+ let!(:gallery_3) { Factory(:gallery) }
36
+
37
+ it { gallery_2.position.should eq 2 }
38
+ it { gallery_3.position.should eq 3 }
39
+ describe "when moving down the image in position 1" do
40
+ before do
41
+ gallery_1.move_to_worst_position
42
+ gallery_2.reload
43
+ gallery_3.reload
44
+ end
45
+
46
+ it { gallery_1.move_to_worst_position.should eq true}
47
+ it { gallery_3.move_to_worst_position.should eq false}
48
+ it { gallery_1.position.should eq 2}
49
+ it { gallery_2.position.should eq 1}
50
+ it { gallery_3.position.should eq 3}
51
+
52
+ after do
53
+ gallery_1.position = 1
54
+ gallery_2.position = 2
55
+ gallery_3.position = 3
56
+ end
57
+ end
58
+
59
+ describe "when moving up the image in position 2" do
60
+ before do
61
+ gallery_2.move_to_better_position
62
+ gallery_1.reload
63
+ gallery_3.reload
64
+ end
65
+
66
+ it { gallery_1.move_to_better_position.should eq true}
67
+ it { gallery_2.move_to_better_position.should eq false}
68
+ it { gallery_1.position.should eq 2}
69
+ it { gallery_2.position.should eq 1}
70
+ it { gallery_3.position.should eq 3}
71
+
72
+ after do
73
+ gallery_1.position = 1
74
+ gallery_2.position = 2
75
+ gallery_3.position = 3
76
+ end
77
+ end
78
+
79
+ describe "when deleting the image in position 1" do
80
+ before do
81
+ gallery_1.destroy
82
+ gallery_2.reload
83
+ gallery_3.reload
84
+ end
85
+
86
+ it { gallery_2.position.should eq 1}
87
+ it { gallery_3.position.should eq 2}
88
+ end
89
+ end
22
90
  end
23
91
 
24
92
  describe "new" do
@@ -28,7 +28,7 @@ describe "Section pages" do
28
28
 
29
29
  before do
30
30
  visit adminpanel.section_path(section)
31
- image.file = image.file
31
+ end
32
32
 
33
33
  it { should have_title(section.name.humanize) }
34
34
  it { should have_content(section.description) }
@@ -15,4 +15,8 @@ describe Adminpanel::Gallery do
15
15
  before {@gallery.file = " "}
16
16
  it {should_not be_valid}
17
17
  end
18
+
19
+ describe "default scope" do
20
+ it { expect(Adminpanel::Gallery.scoped.to_sql).to eq Adminpanel::Gallery.reorder('').order('position ASC').to_sql}
21
+ end
18
22
  end
@@ -3,10 +3,12 @@ require 'spec_helper'
3
3
  describe Adminpanel::Section do
4
4
  before do
5
5
  @section = Adminpanel::Section.new(
6
- :description => "Test description for product",
6
+ :name => "Section name",
7
+ :description => "Test description for index",
7
8
  :has_image => true,
8
9
  :key => "example_key",
9
- :has_description => true
10
+ :has_description => true,
11
+ :page => "index"
10
12
  )
11
13
  end
12
14
 
@@ -17,39 +19,49 @@ describe Adminpanel::Section do
17
19
  it { should respond_to(:key) }
18
20
  it { should respond_to(:name) }
19
21
  it { should respond_to(:has_description) }
22
+ it { should respond_to(:page) }
20
23
 
21
24
  describe "when key is telephone and has less than 10 chars" do
22
- before {@section.key = "telephone"}
23
- before {@section.description = "1" * 9}
24
- it {should_not be_valid}
25
+ before do
26
+ @section.key = "telephone"
27
+ @section.description = "1" * 9
28
+ end
29
+ it { @section.valid? eq false}
25
30
  end
26
31
 
27
32
  describe "when key is telephone and has more than 10 chars" do
28
- before {@section.key = "telephone"}
29
- before {@section.description = "1" * 11}
30
- it {should_not be_valid}
33
+ before do
34
+ @section.key = "telephone"
35
+ @section.description = "1" * 11
36
+ end
37
+ it { @section.valid? eq false}
31
38
  end
32
39
 
33
40
  describe "when key is telephone and has 10 chars" do
34
- before {
41
+ before do
35
42
  @section.key = "telephone"
36
43
  @section.description = "1" * 10
37
- }
38
- it {@section.description.length.should eql(10)}
44
+ end
45
+ it { @section.valid? eq true}
46
+
39
47
  end
40
48
 
41
49
  describe "when key is blank" do
42
50
  before {@section.key = " "}
43
- it {should_not be_valid}
51
+ it { @section.valid? eq false}
44
52
  end
45
53
 
46
54
  describe "when name is blank" do
47
55
  before {@section.name = " "}
48
- it {should_not be_valid}
56
+ it { @section.valid? eq false}
49
57
  end
50
58
 
51
59
  describe "when description is blank" do
52
60
  before {@section.description = " "}
53
- it {should_not be_valid}
54
- end
61
+ it { @section.valid? eq false}
62
+ end
63
+
64
+ describe "default scope" do
65
+ it { expect(Adminpanel::Section.scoped.to_sql).to eq Adminpanel::Section.reorder('').order('page ASC').to_sql}
66
+ end
55
67
  end
data/spec/spec_helper.rb CHANGED
@@ -9,6 +9,8 @@ ENV["RAILS_ENV"] ||= 'test'
9
9
  require File.expand_path("../dummy/config/environment", __FILE__)
10
10
  require "rspec/rails"
11
11
  require "factory_girl"
12
+ require "carrierwave/test/matchers"
13
+ require "active_record"
12
14
 
13
15
  Dir["./spec/support/**/*.rb"].sort.each {|f| require f}
14
16
 
@@ -33,4 +33,5 @@ Factory.define :section_with_gallery, :class => Adminpanel::Section do |section|
33
33
  section.has_image true
34
34
  section.has_description false
35
35
  section.name "section_name"
36
+ section.page "index"
36
37
  end
@@ -1,5 +1,3 @@
1
- require "active_record"
2
-
3
1
  ActiveRecord::Migration.create_table :adminpanel_users do |t|
4
2
  t.string :name
5
3
  t.string :email
@@ -15,6 +13,7 @@ ActiveRecord::Migration.create_table :adminpanel_categories do |t|
15
13
  end
16
14
  ActiveRecord::Migration.create_table :adminpanel_galleries do |t|
17
15
  t.string :file
16
+ t.integer :position
18
17
  t.datetime :created_at, :null => false
19
18
  t.datetime :updated_at, :null => false
20
19
  end
@@ -38,7 +37,7 @@ ActiveRecord::Migration.create_table :adminpanel_sections do |t|
38
37
  t.text :description
39
38
  t.string :key
40
39
  t.boolean :has_image
41
- t.string :file
40
+ t.string :page
42
41
  t.datetime :created_at, :null => false
43
42
  t.datetime :updated_at, :null => false
44
43
  t.boolean :has_description
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- require 'support/active_record'
2
+ require 'support/test_database'
3
3
  require 'carrierwave/test/matchers'
4
4
 
5
5
  describe Adminpanel::GalleryUploader do
@@ -1,5 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'support/active_record'
3
2
  require 'carrierwave/test/matchers'
4
3
 
5
4
  describe Adminpanel::ImageUploader do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adminpanel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jose Ramon Camacho
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2013-12-11 00:00:00 Z
13
+ date: 2014-01-11 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -282,10 +282,13 @@ files:
282
282
  - app/views/adminpanel/categories/index.html.erb
283
283
  - app/views/adminpanel/categories/new.html.erb
284
284
  - app/views/adminpanel/categories/show.html.erb
285
+ - app/views/adminpanel/galleries/_galleries_table.html.erb
285
286
  - app/views/adminpanel/galleries/create.html.erb
286
287
  - app/views/adminpanel/galleries/delete.html.erb
287
288
  - app/views/adminpanel/galleries/edit.html.erb
288
289
  - app/views/adminpanel/galleries/index.html.erb
290
+ - app/views/adminpanel/galleries/move_better.js.erb
291
+ - app/views/adminpanel/galleries/move_worst.js.erb
289
292
  - app/views/adminpanel/galleries/new.html.erb
290
293
  - app/views/adminpanel/galleries/show.html.erb
291
294
  - app/views/adminpanel/galleries/update.html.erb
@@ -297,6 +300,7 @@ files:
297
300
  - app/views/adminpanel/products/new.html.erb
298
301
  - app/views/adminpanel/products/show.html.erb
299
302
  - app/views/adminpanel/sections/_image_fields.html.erb
303
+ - app/views/adminpanel/sections/_sections_table.html.erb
300
304
  - app/views/adminpanel/sections/create.html.erb
301
305
  - app/views/adminpanel/sections/destroy.html.erb
302
306
  - app/views/adminpanel/sections/edit.html.erb
@@ -364,9 +368,6 @@ files:
364
368
  - spec/dummy/public/favicon.ico
365
369
  - spec/dummy/public/uploads/gallery/file/1/hipster.jpg
366
370
  - spec/dummy/public/uploads/gallery/file/1/thumb_hipster.jpg
367
- - spec/dummy/public/uploads/image/file/1/hipster.jpg
368
- - spec/dummy/public/uploads/image/file/1/portfolio_hipster.jpg
369
- - spec/dummy/public/uploads/image/file/1/thumb_hipster.jpg
370
371
  - spec/dummy/script/rails
371
372
  - spec/features/authentication_pages_spec.rb
372
373
  - spec/features/categories_pages_spec.rb
@@ -380,11 +381,10 @@ files:
380
381
  - spec/models/section_spec.rb
381
382
  - spec/models/user_spec.rb
382
383
  - spec/spec_helper.rb
383
- - spec/support/active_record.rb
384
384
  - spec/support/define_factory_models.rb
385
385
  - spec/support/helper_methods.rb
386
- - spec/support/schema.rb
387
386
  - spec/support/submit_forms_without_button.rb
387
+ - spec/support/test_database.rb
388
388
  - spec/uploaders/gallery_uploader_spec.rb
389
389
  - spec/uploaders/image_uploader_spec.rb
390
390
  homepage: https://github.com/joseramonc/adminpanel
@@ -450,9 +450,6 @@ test_files:
450
450
  - spec/dummy/public/favicon.ico
451
451
  - spec/dummy/public/uploads/gallery/file/1/hipster.jpg
452
452
  - spec/dummy/public/uploads/gallery/file/1/thumb_hipster.jpg
453
- - spec/dummy/public/uploads/image/file/1/hipster.jpg
454
- - spec/dummy/public/uploads/image/file/1/portfolio_hipster.jpg
455
- - spec/dummy/public/uploads/image/file/1/thumb_hipster.jpg
456
453
  - spec/dummy/script/rails
457
454
  - spec/features/authentication_pages_spec.rb
458
455
  - spec/features/categories_pages_spec.rb
@@ -466,10 +463,9 @@ test_files:
466
463
  - spec/models/section_spec.rb
467
464
  - spec/models/user_spec.rb
468
465
  - spec/spec_helper.rb
469
- - spec/support/active_record.rb
470
466
  - spec/support/define_factory_models.rb
471
467
  - spec/support/helper_methods.rb
472
- - spec/support/schema.rb
473
468
  - spec/support/submit_forms_without_button.rb
469
+ - spec/support/test_database.rb
474
470
  - spec/uploaders/gallery_uploader_spec.rb
475
471
  - spec/uploaders/image_uploader_spec.rb
@@ -1,64 +0,0 @@
1
- # encoding: UTF-8
2
- # This file is auto-generated from the current state of the database. Instead
3
- # of editing this file, please use the migrations feature of Active Record to
4
- # incrementally modify your database, and then regenerate this schema definition.
5
- #
6
- # Note that this schema.rb definition is the authoritative source for your
7
- # database schema. If you need to create the application database on another
8
- # system, you should be using db:schema:load, not running all the migrations
9
- # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
- # you'll amass, the slower it'll run and the greater likelihood for issues).
11
- #
12
- # It's strongly recommended to check this file into your version control system.
13
-
14
- ActiveRecord::Schema.define(:version => 20131120070259) do
15
-
16
- create_table "adminpanel_users", :force => true do |t|
17
- t.string "name"
18
- t.string "email"
19
- t.string "password_digest"
20
- t.string "remember_token"
21
- t.datetime "created_at", :null => false
22
- t.datetime "updated_at", :null => false
23
- end
24
-
25
- create_table "adminpanel_categories", :force => true do |t|
26
- t.string "name"
27
- t.datetime "created_at", :null => false
28
- t.datetime "updated_at", :null => false
29
- end
30
-
31
- create_table "adminpanel_galleries", :force => true do |t|
32
- t.string "file"
33
- t.datetime "created_at", :null => false
34
- t.datetime "updated_at", :null => false
35
- end
36
-
37
- create_table "adminpanel_images", :force => true do |t|
38
- t.string "file"
39
- t.integer "foreign_key"
40
- t.datetime "created_at", :null => false
41
- t.datetime "updated_at", :null => false
42
- t.string "model"
43
- end
44
-
45
- create_table "adminpanel_products", :force => true do |t|
46
- t.string "name"
47
- t.text "description"
48
- t.datetime "created_at", :null => false
49
- t.datetime "updated_at", :null => false
50
- t.integer "category_id"
51
- t.string "brief"
52
- end
53
-
54
- create_table "adminpanel_sections", :force => true do |t|
55
- t.string "name"
56
- t.text "description"
57
- t.string "key"
58
- t.boolean "has_image"
59
- t.datetime "created_at", :null => false
60
- t.datetime "updated_at", :null => false
61
- t.boolean "has_description"
62
- end
63
-
64
- end