adminpanel 2.2.2 → 2.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: efc38f8b1f2d0b9edd74586cf882831058760307
4
- data.tar.gz: ab6a27f69e79bf15a3e03d57c70d1206832c7b9f
3
+ metadata.gz: 1507bc64df02e756c6142e0222e98ebe33b1bf09
4
+ data.tar.gz: 32e379878e099ac52116affe5515589d39f83e91
5
5
  SHA512:
6
- metadata.gz: 0abbee803b58820f03963b53cb607cb30ba35b62a75a97a74142e34f5e86fe084e885a416afe18c708056192d5eb24cf9d9ae57f43095ec06ba08fbacd4f100f
7
- data.tar.gz: 44d14aaa1e658615d1ecb98b66237f16815be4b4e0ab0499c83a2f3dbec11e2e38e9f429007296b443e4ef989c1a3145161da48a8364263d648f3287b7f6b802
6
+ metadata.gz: 621fed57774947e6ab5aefbde93243d572bde6bb5fc26112e4c75ef0ca37a1e33ca7098ed5990e27c26d9d47f160f9f0437fb4d2871ba6514cb7a87b923d4dd1
7
+ data.tar.gz: e71a1faf210481f8c792ffbf137ca4d70d6481119d6911b9f9f4b93f31c41998cbcb20ebcff0404c989c62e114835a003aef8becd8c173ca91cce3a1296f90c4
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
- # Adminpanel
1
+ # [![CoDN](http://cl.ly/image/130Q0E153d2G/codn180.png)](http://www.codn.mx "CoDN") Adminpanel
2
2
 
3
3
  CMS for Rails 4, for rails 3.x check the corresponding branch.
4
4
 
5
5
  [![Gem Version](https://badge.fury.io/rb/adminpanel.svg)](http://badge.fury.io/rb/adminpanel)
6
6
  [![Build Status](https://travis-ci.org/joseramonc/adminpanel.svg?branch=master)](https://travis-ci.org/joseramonc/adminpanel)
7
- [![Code Climate](https://codeclimate.com/github/joseramonc/adminpanel.png)](https://codeclimate.com/github/joseramonc/adminpanel)
7
+ [![Code Climate](https://codeclimate.com/github/joseramonc/adminpanel/badges/gpa.svg)](https://codeclimate.com/github/joseramonc/adminpanel)
8
8
  <!-- [![Dependency Status](https://gemnasium.com/joseramonc/adminpanel.svg)](https://gemnasium.com/joseramonc/adminpanel) -->
9
9
  ## Installation
10
10
 
@@ -83,49 +83,46 @@ module Adminpanel
83
83
  def fb
84
84
  authorize! :read, Adminpanel::Analytic
85
85
  auth = Adminpanel::Auth.find_by_key('facebook')
86
- if !auth.nil? && auth.value != '' # not nil & not void
87
- if params[:insight].present?
88
- period = params[:insight]
89
- else
90
- period = 'day' #default period
91
- end
92
- page_graph = Koala::Facebook::API.new(auth.value)
93
- @impressions,
94
- @impressions_unique,
86
+ redirect_via_turbolinks_to analytics_path if !auth.nil? && auth.value != '' # not nil & not void
87
+ if params[:insight].present?
88
+ period = params[:insight]
89
+ else
90
+ period = 'day' #default period
91
+ end
92
+ page_graph = Koala::Facebook::API.new(auth.value)
93
+ @impressions,
94
+ @impressions_unique,
95
95
 
96
- @new_likes,
97
- @total_likes,
96
+ @new_likes,
97
+ @total_likes,
98
98
 
99
- @hidden,
100
- @hidden_unique,
99
+ @hidden,
100
+ @hidden_unique,
101
101
 
102
- @consumptions,
103
- @consumptions_unique,
102
+ @consumptions,
103
+ @consumptions_unique,
104
104
 
105
- @views,
106
- @views_unique,
105
+ @views,
106
+ @views_unique,
107
107
 
108
- @stories = page_graph.batch do |api|
109
- #all information on same request
110
- api.get_connections('me', 'insights', metric: 'page_impressions', period: period) #eye
111
- api.get_connections('me', 'insights', metric: 'page_impressions_unique', period: period) #eye
108
+ @stories = page_graph.batch do |api|
109
+ #all information on same request
110
+ api.get_connections('me', 'insights', metric: 'page_impressions', period: period) #eye
111
+ api.get_connections('me', 'insights', metric: 'page_impressions_unique', period: period) #eye
112
112
 
113
- api.get_connections('me', 'insights', metric: 'page_fan_adds') #fb-thumb
114
- api.get_connections('me', 'insights', metric: 'page_fans') #fb-thumb
113
+ api.get_connections('me', 'insights', metric: 'page_fan_adds') #fb-thumb
114
+ api.get_connections('me', 'insights', metric: 'page_fans') #fb-thumb
115
115
 
116
- api.get_connections('me', 'insights', metric: 'page_negative_feedback', period: period)
117
- api.get_connections('me', 'insights', metric: 'page_negative_feedback_unique', period: period)
116
+ api.get_connections('me', 'insights', metric: 'page_negative_feedback', period: period)
117
+ api.get_connections('me', 'insights', metric: 'page_negative_feedback_unique', period: period)
118
118
 
119
- api.get_connections('me', 'insights', metric: 'page_consumptions', period: period)
120
- api.get_connections('me', 'insights', metric: 'page_consumptions_unique', period: period)
119
+ api.get_connections('me', 'insights', metric: 'page_consumptions', period: period)
120
+ api.get_connections('me', 'insights', metric: 'page_consumptions_unique', period: period)
121
121
 
122
- api.get_connections('me', 'insights', metric: 'page_views')
123
- api.get_connections('me', 'insights', metric: 'page_views_unique')
122
+ api.get_connections('me', 'insights', metric: 'page_views')
123
+ api.get_connections('me', 'insights', metric: 'page_views_unique')
124
124
 
125
- api.get_connections('me', 'insights', metric: 'page_stories', period: period)
126
- end
127
- else
128
- redirect_to analytics_path
125
+ api.get_connections('me', 'insights', metric: 'page_stories', period: period)
129
126
  end
130
127
  end
131
128
 
@@ -14,8 +14,8 @@ module Adminpanel
14
14
  include Adminpanel::FacebookActions
15
15
  include Adminpanel::TwitterActions
16
16
  include Adminpanel::SitemapActions
17
- private
18
17
 
18
+ private
19
19
  def strong_params_for_cancan
20
20
  resource = controller_name.singularize.to_sym
21
21
  method = "#{resource}_params"
@@ -47,7 +47,7 @@ module Adminpanel
47
47
  :page,
48
48
  :name,
49
49
  :has_image,
50
- images_attributes: [:id, :file]
50
+ { images_attributes: [:id, :file, :_destroy] }
51
51
  )
52
52
  end
53
53
  end
@@ -1,6 +1,8 @@
1
1
  module Adminpanel
2
2
  class SessionsController < ActionController::Base
3
3
  include SessionsHelper
4
+ include ApplicationHelper
5
+
4
6
  protect_from_forgery
5
7
  layout 'admin-login'
6
8
  before_action :configure_instagram, only:[:instagram_login, :instagram_callback]
@@ -13,7 +15,12 @@ module Adminpanel
13
15
  if user && user.authenticate(params[:session][:password])
14
16
  sign_in user
15
17
  flash[:success] = I18n.t('authentication.signin_success')
16
- redirect_to root_url
18
+ permission = user.rol.permissions.first
19
+ if permission.nil?
20
+ redirect_to root_url
21
+ else
22
+ redirect_to [route_symbol(permission.resource)]
23
+ end
17
24
  else
18
25
  flash.now[:error] = I18n.t('authentication.signin_error')
19
26
  render 'new'
@@ -72,11 +72,13 @@ module Adminpanel
72
72
  end
73
73
 
74
74
  def enum_field name, *args
75
- select name, self.object.class.actions.map{|action, value| [I18n.t("enum.#{action}"), action]}, *args
75
+ select name, self.object.class.actions.map{|action, value| [I18n.t("#{self.object.class.name.demodulize.downcase}.#{action}"), action]}, *args
76
76
  end
77
77
 
78
78
  def resource_select name, *args
79
79
  select name, Adminpanel.displayable_resources.map{|resource| [symbol_class(resource).display_name, resource.to_s]}, *args
80
+ # select name, Adminpanel.displayable_resources.map{|resource| ['resource', 'resource']}, *args
81
+
80
82
  end
81
83
 
82
84
  def select(name, select_options, *args)
@@ -23,11 +23,7 @@ module Adminpanel
23
23
  def is_current_section?(display_name)
24
24
  display_name == params[:controller].classify.constantize.display_name ? 'active' : nil
25
25
  end
26
-
27
- def section_is_login(section_name)
28
- section_name.downcase == 'login'
29
- end
30
-
26
+
31
27
  def link_to_add_fields(name, f, association)
32
28
  new_object = f.object.send(association).klass.new
33
29
  id = new_object.object_id
@@ -16,6 +16,14 @@ module Adminpanel
16
16
  resource_class(resource).twitter_share?
17
17
  end
18
18
 
19
+ def member_routes(resource)
20
+ resource_class(resource).member_routes
21
+ end
22
+
23
+ def collection_routes(resource)
24
+ resource_class(resource).collection_routes
25
+ end
26
+
19
27
  def rest_path_names
20
28
  {
21
29
  path_names: {
@@ -9,9 +9,19 @@ module Adminpanel
9
9
  belongs_to :rol
10
10
 
11
11
  def name
12
- "#{I18n.t('enum.' + action.to_s)} #{symbol_class(self.resource).display_name}"
12
+ "#{action} #{symbol_class(self['resource']).display_name}"
13
13
  end
14
14
 
15
+ # def action
16
+ # Permission.actions.each do |key, value|
17
+ # return I18n.t("permission.#{key}") if value == self['action']
18
+ # end
19
+ # end
20
+
21
+ # def resource
22
+ # symbol_class(self['resource']).display_name.to_s.pluralize(I18n.default_locale)
23
+ # end
24
+
15
25
  def self.form_attributes
16
26
  [
17
27
  {
@@ -34,7 +44,6 @@ module Adminpanel
34
44
  'label' => I18n.t('permission.resource'),
35
45
  }
36
46
  },
37
-
38
47
  ]
39
48
  end
40
49
 
@@ -42,7 +42,6 @@ module Adminpanel
42
42
  {'key' => {'name' => 'key', 'label' => 'Llave'}},
43
43
  {'page' => {'name' => 'page'}},
44
44
  ]
45
-
46
45
  end
47
46
 
48
47
  def self.icon
@@ -12,12 +12,12 @@ module Adminpanel
12
12
  validates_length_of :name, :maximum => 25
13
13
 
14
14
  #password validations
15
- validates_confirmation_of :password
16
- validates_presence_of :password
17
- validates_length_of :password, :minimum => 6
15
+ validates_confirmation_of :password, :on => :create
16
+ validates_presence_of :password, :on => :create
17
+ validates_length_of :password, :minimum => 6, :on => :create
18
18
 
19
19
  #password_confirmation validations
20
- validates_presence_of :password_confirmation
20
+ validates_presence_of :password_confirmation, :on => :create
21
21
 
22
22
  #email validations
23
23
  validates_presence_of :email
@@ -76,6 +76,10 @@ module Adminpanel
76
76
  ]
77
77
  end
78
78
 
79
+ def root_url
80
+ self.rol.permissions.first
81
+ end
82
+
79
83
  def self.display_name
80
84
  'Usuario'
81
85
  end
@@ -86,10 +86,7 @@ module Adminpanel
86
86
  end
87
87
 
88
88
  def routes_options
89
- { path: ActiveSupport::Inflector.transliterate(
90
- display_name.pluralize(I18n.default_locale).downcase
91
- ).tr(' ', '-')
92
- }
89
+ { path: display_name.pluralize(I18n.default_locale).parameterize }
93
90
  end
94
91
 
95
92
  def has_route?(route)
@@ -108,6 +105,14 @@ module Adminpanel
108
105
  false
109
106
  end
110
107
 
108
+ def member_routes
109
+ []
110
+ end
111
+
112
+ def collection_routes
113
+ []
114
+ end
115
+
111
116
  private
112
117
  def exlude?(route)
113
118
  if routes_options[:except].nil?
@@ -25,9 +25,9 @@
25
25
  <div class="row-fluid">
26
26
  <div class="widget widget-padding span12">
27
27
  <div class="widget-header">
28
- <%= content_tag :i, nil, class: "fa fa-#{@model.icon}" %>
29
- <h5><%= @model.display_name.pluralize(I18n.default_locale) %></h5>
30
- </div>
28
+ <%= content_tag :i, nil, class: "fa fa-#{@model.icon}" %>
29
+ <h5><%= @model.display_name.pluralize(I18n.default_locale) %></h5>
30
+ </div>
31
31
  <div class="widget-body">
32
32
  <div class="dataTables_wrapper form-inline">
33
33
  <table class="table table-striped table-bordered dataTable">
@@ -1 +1 @@
1
- $("#galleries-content").html("<%= escape_javascript(render 'galleries_table', :locals => { :galleries => @galleries } ) %>");
1
+ $("#galleries-content").html("<%= escape_javascript(render 'services_table', :locals => { :galleries => @galleries } ) %>");
@@ -7,6 +7,7 @@
7
7
  class: 'fa fa-search-plus'
8
8
  ),
9
9
  [resource],
10
+ class: 'spinner-link',
10
11
  title: t('action.show'),
11
12
  id: 'show-resource-icon'
12
13
  )
@@ -42,6 +42,18 @@ es:
42
42
  description: 'Escriba la descripción aquí'
43
43
  Panel title: 'Panel Administrativo'
44
44
  permission:
45
+ 0: 'Ver'
46
+ to_read: 'Ver'
47
+ 1: 'Publicar en Redes Sociales'
48
+ to_publish: 'Publicar en Redes Sociales'
49
+ 2: 'Crear'
50
+ to_create: 'Crear'
51
+ 3: 'Actualizar'
52
+ to_update: 'Actualizar'
53
+ 4: 'Borrar'
54
+ to_destroy: 'Borrar'
55
+ 5: 'Administrar'
56
+ to_manage: 'Administrar'
45
57
  rol: 'Rol'
46
58
  action: 'Acción permitida'
47
59
  resource: 'Módulo'
@@ -157,10 +169,3 @@ es:
157
169
  page_select: 'Selecciona una cuenta para la publicación'
158
170
  message: 'Mensaje de la publicación'
159
171
  saved_token: 'Log in con Twitter exitoso, ya puedes publicar con la cuenta de Twitter'
160
- enum:
161
- to_read: 'Ver'
162
- to_publish: 'Publicar en Redes Sociales'
163
- to_create: 'Crear'
164
- to_update: 'Actualizar'
165
- to_destroy: 'Borrar'
166
- to_manage: 'Ver, crear, actualizar y borrar'
data/config/routes.rb CHANGED
@@ -41,13 +41,16 @@ Adminpanel::Engine.routes.draw do
41
41
  end
42
42
  end
43
43
 
44
- # normal resource
45
- resources resource, resources_parameters(resource).merge(rest_path_names)
46
-
47
- # if resource is going to be shared on facebook
48
44
  resources resource, resources_parameters(resource).merge(rest_path_names) do
49
45
  member do
46
+ # adds custom member routes of the resource
47
+ member_routes(resource).each do |route|
48
+ route.each do |request_type, args|
49
+ send(request_type, args['path'].to_sym, args['args'])
50
+ end
51
+ end
50
52
  if has_fb_share?(resource)
53
+ # if resource is going to be shared on facebook
51
54
  get :fb_choose_page, as: 'fb_choose_page', path: 'publicar-a-pagina-en-fb'
52
55
  post :fb_save_token, as: 'fb_save_token', path: 'guardar-token-fb'
53
56
  post :fb_publish, to: "#{resource}#fb_publish", as: 'fb_publish', path: 'publicar-a-facebook'
@@ -56,6 +59,14 @@ Adminpanel::Engine.routes.draw do
56
59
  post :twitter_publish, to: "#{resource}#twitter_publish", as: 'twitter_publish', path: 'publicar-a-twitter'
57
60
  end
58
61
  end
62
+ collection do
63
+ # add custom collection routes of the resource
64
+ collection_routes(resource).each do |route|
65
+ route.each do |request_type, args|
66
+ send(request_type, args['path'].to_sym, args['args'])
67
+ end
68
+ end
69
+ end
59
70
  end
60
71
  end
61
72
  end
@@ -1,3 +1,3 @@
1
1
  module Adminpanel
2
- VERSION = "2.2.2"
2
+ VERSION = "2.2.3"
3
3
  end
@@ -24,7 +24,14 @@ module Adminpanel
24
24
 
25
25
  def generate_migration
26
26
  parameters = fields
27
- parameters.delete_if{ |pair| pair.split(':').second == 'has_many' }
27
+ parameters.delete_if do |pair|
28
+ if pair.split(':').second == 'has_many'
29
+ puts "migrations aren't supported yet, sorry :(, but you can do a pull request"
30
+ true
31
+ else
32
+ false
33
+ end
34
+ end
28
35
  invoke :migration, [migration_name, parameters]
29
36
  end
30
37
 
@@ -6,11 +6,10 @@ module Adminpanel
6
6
  include ResourceGeneratorHelper
7
7
  source_root File.expand_path('../templates', __FILE__)
8
8
  desc 'Generate the resource files necessary to use a model'
9
- class_option :'gallery',
9
+ class_option :'skip-gallery',
10
10
  :type => :boolean,
11
- :aliases => '-g',
12
11
  :default => true,
13
- :desc => 'Creates the gallery for this resource'
12
+ :desc => 'Choose if we shoud create the gallery for this resource, default: true (skip gallery )'
14
13
 
15
14
  argument :fields, :type => :array, :default => [], :banner => 'field[:type][:index] field[:type][:index]'
16
15
 
@@ -40,7 +40,7 @@ module Adminpanel
40
40
  end
41
41
 
42
42
  def has_gallery?
43
- options[:'gallery']
43
+ !options[:'skip-gallery']
44
44
  end
45
45
 
46
46
  def resource_name
@@ -51,8 +51,8 @@ module Adminpanel
51
51
  "#{resource_name}file" #ex: postfile
52
52
  end
53
53
 
54
- def capitalized_resource
55
- resource_name.capitalize
54
+ def camelized_resource
55
+ resource_name.camelize
56
56
  end
57
57
 
58
58
  def pluralized_name
@@ -1,5 +1,5 @@
1
1
  module Adminpanel
2
- class <%= capitalized_resource %> < ActiveRecord::Base
2
+ class <%= camelized_resource %> < ActiveRecord::Base
3
3
  include Adminpanel::Base
4
4
 
5
5
  <%= associations if has_associations? -%>
@@ -13,7 +13,7 @@ module Adminpanel
13
13
  end
14
14
 
15
15
  def self.display_name
16
- '<%= capitalized_resource %>' #singular
16
+ '<%= camelized_resource %>' #singular
17
17
  end
18
18
 
19
19
  # def self.icon
@@ -6,16 +6,27 @@ class ResourceGeneratorTest < Rails::Generators::TestCase
6
6
  destination Rails.root.join('tmp/generators')
7
7
  setup :prepare_destination
8
8
 
9
- def test_not_generation_of_gallery
9
+ def test_default_not_generation_of_gallery
10
10
  run_generator %w(
11
11
  post
12
12
  name
13
13
  description:wysiwyg
14
14
  number:float
15
- --no-gallery
16
15
  )
17
16
  assert_no_file 'app/models/adminpanel/postfile.rb'
18
- assert_no_migration('db/migrate/create_adminpanel_productfiles.rb')
17
+ assert_no_migration 'db/migrate/create_adminpanel_postfiles.rb'
18
+ end
19
+
20
+ def test_generation_of_gallery
21
+ run_generator %w(
22
+ post
23
+ name
24
+ description:wysiwyg
25
+ number:float
26
+ --no-skip-gallery
27
+ )
28
+ assert_file 'app/models/adminpanel/postfile.rb'
29
+ assert_migration 'db/migrate/create_adminpanel_postfiles.rb'
19
30
  end
20
31
 
21
32
  # def test_initializer_update
@@ -32,30 +43,6 @@ class ResourceGeneratorTest < Rails::Generators::TestCase
32
43
  # )
33
44
  # end
34
45
 
35
- def test_correct_migration_attributes
36
- generator = Adminpanel::ResourceGenerator.new %w(
37
- post
38
- name
39
- description:wysiwyg
40
- number:float
41
- flag:boolean
42
- quantity:integer
43
- date:datepicker
44
- )
45
-
46
- # puts generator.generate_migration
47
-
48
- # assert_migration(
49
- # 'db/migrate/create_adminpanel_posts.rb',
50
- # /t.string :name/,
51
- # /t.float :number/,
52
- # /t.boolean :flag/,
53
- # /t.integer :quantity/,
54
- # /t.string :date/,
55
- # /t.text :description/
56
- # )
57
- end
58
-
59
46
  def test_controller_generation
60
47
  run_generator %w(
61
48
  post
@@ -65,6 +52,7 @@ class ResourceGeneratorTest < Rails::Generators::TestCase
65
52
  flag:boolean
66
53
  quantity:integer
67
54
  date:datepicker
55
+ --no-skip-gallery
68
56
  )
69
57
  assert_file(
70
58
  'app/controllers/adminpanel/posts_controller.rb',
@@ -81,7 +69,7 @@ class ResourceGeneratorTest < Rails::Generators::TestCase
81
69
 
82
70
  def test_model_generation
83
71
  run_generator %w(
84
- post
72
+ admin_post
85
73
  name
86
74
  description:wysiwyg
87
75
  number:float
@@ -89,11 +77,13 @@ class ResourceGeneratorTest < Rails::Generators::TestCase
89
77
  quantity:integer
90
78
  date:datepicker
91
79
  categories:has_many
80
+ --no-skip-gallery
92
81
  )
93
82
  assert_file(
94
- 'app/models/adminpanel/post.rb',
83
+ 'app/models/adminpanel/admin_post.rb',
84
+ /class AdminPost </,
95
85
  /include Adminpanel::Base/,
96
- /mount_images :postfiles/,
86
+ /mount_images :admin_postfiles/,
97
87
  # form_fields generated correctly
98
88
  /'description' => {/,
99
89
  /'type' => 'wysiwyg_field',/,
@@ -107,7 +97,7 @@ class ResourceGeneratorTest < Rails::Generators::TestCase
107
97
  /'type' => 'number_field',/,
108
98
  /'date' => {/,
109
99
  /'type' => 'datepicker',/,
110
- /'postfiles' => {/,
100
+ /'admin_postfiles' => {/,
111
101
  /'type' => 'adminpanel_file_field',/,
112
102
  /'category_ids' => {/,
113
103
  /'type' => 'has_many'/,
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: 2.2.2
4
+ version: 2.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jose Ramon Camacho
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-07-24 00:00:00.000000000 Z
12
+ date: 2014-08-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails