manage 1.2.0 → 1.3.0
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.
- checksums.yaml +7 -0
- data/Rakefile +7 -10
- data/app/assets/javascripts/manage/application.js +1 -2
- data/app/assets/stylesheets/manage/application.css.scss +1 -1
- data/app/controllers/manage/admin_users_controller.rb +12 -0
- data/app/controllers/manage/application_controller.rb +4 -10
- data/app/controllers/manage/resource_controller.rb +74 -0
- data/app/controllers/manage/sessions_controller.rb +8 -3
- data/app/helpers/manage/form_helper.rb +1 -1
- data/app/helpers/manage/resource_helper.rb +56 -0
- data/app/models/admin_user.rb +4 -0
- data/app/views/layouts/manage/_main_menu.html.slim +1 -5
- data/app/views/layouts/manage/sign_in.html.slim +13 -13
- data/app/views/manage/resource/_form.html.slim +3 -3
- data/app/views/manage/resource/index/_count.html.slim +6 -0
- data/app/views/manage/resource/index/_filters.html.slim +18 -7
- data/app/views/manage/resource/index/_table.html.slim +7 -5
- data/app/views/manage/resource/index.html.slim +3 -2
- data/app/views/{sessions → manage/sessions}/new.html.slim +2 -3
- data/config/initializers/devise.rb +247 -0
- data/config/initializers/session_store.rb +3 -0
- data/config/initializers/simple_form_foundation.rb +2 -0
- data/config/locales/devise.en.yml +59 -0
- data/config/routes.rb +6 -4
- data/db/migrate/20131204142720_create_admin_users.rb +24 -0
- data/lib/manage/engine.rb +16 -5
- data/lib/manage/fields/reader.rb +57 -0
- data/lib/manage/fields/searcher.rb +48 -0
- data/lib/manage/fields.rb +6 -0
- data/lib/manage/version.rb +1 -1
- data/lib/manage.rb +2 -0
- data/lib/tasks/manage_tasks.rake +11 -0
- data/lib/templates/erb/scaffold/_form.html.erb +1 -1
- data/spec/controllers/manage/resource_controller_spec.rb +29 -0
- data/spec/dummy/app/controllers/manage/posts_controller.rb +4 -0
- data/spec/dummy/app/models/post.rb +3 -0
- data/spec/dummy/app/models/user.rb +5 -0
- data/{test → spec}/dummy/config/application.rb +1 -0
- data/{test → spec}/dummy/config/database.yml +1 -1
- data/spec/dummy/config/routes.rb +10 -0
- data/spec/dummy/db/migrate/20130716083410_init_migration.rb +21 -0
- data/spec/dummy/db/schema.rb +53 -0
- data/spec/fields/reader_spec.rb +79 -0
- data/spec/spec_helper.rb +24 -0
- metadata +163 -104
- data/test/controllers/manage/resource_controller_test.rb +0 -9
- data/test/dummy/config/routes.rb +0 -4
- data/test/helpers/manage/resource_helper_test.rb +0 -6
- data/test/integration/navigation_test.rb +0 -10
- data/test/manage_test.rb +0 -7
- data/test/test_helper.rb +0 -15
- /data/{test → spec}/dummy/README.rdoc +0 -0
- /data/{test → spec}/dummy/Rakefile +0 -0
- /data/{test → spec}/dummy/app/assets/javascripts/application.js +0 -0
- /data/{test → spec}/dummy/app/assets/stylesheets/application.css +0 -0
- /data/{test → spec}/dummy/app/controllers/application_controller.rb +0 -0
- /data/{test → spec}/dummy/app/helpers/application_helper.rb +0 -0
- /data/{test → spec}/dummy/app/views/layouts/application.html.erb +0 -0
- /data/{test → spec}/dummy/bin/bundle +0 -0
- /data/{test → spec}/dummy/bin/rails +0 -0
- /data/{test → spec}/dummy/bin/rake +0 -0
- /data/{test → spec}/dummy/config/boot.rb +0 -0
- /data/{test → spec}/dummy/config/environment.rb +0 -0
- /data/{test → spec}/dummy/config/environments/development.rb +0 -0
- /data/{test → spec}/dummy/config/environments/production.rb +0 -0
- /data/{test → spec}/dummy/config/environments/test.rb +0 -0
- /data/{test → spec}/dummy/config/initializers/backtrace_silencers.rb +0 -0
- /data/{test → spec}/dummy/config/initializers/filter_parameter_logging.rb +0 -0
- /data/{test → spec}/dummy/config/initializers/inflections.rb +0 -0
- /data/{test → spec}/dummy/config/initializers/mime_types.rb +0 -0
- /data/{test → spec}/dummy/config/initializers/secret_token.rb +0 -0
- /data/{test → spec}/dummy/config/initializers/session_store.rb +0 -0
- /data/{test → spec}/dummy/config/initializers/wrap_parameters.rb +0 -0
- /data/{test → spec}/dummy/config/locales/en.yml +0 -0
- /data/{test → spec}/dummy/config.ru +0 -0
- /data/{test → spec}/dummy/public/404.html +0 -0
- /data/{test → spec}/dummy/public/422.html +0 -0
- /data/{test → spec}/dummy/public/500.html +0 -0
- /data/{test → spec}/dummy/public/favicon.ico +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b46432d4fd1f5036e85a8a0187d609e413bdc0d4
|
4
|
+
data.tar.gz: bb3c8fcb086a0c47ea700940da85e721df96e31a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a07c1505b5592327ca8e7229de3f4601a245c1eaec0fe8e63f319e74456f91800b741e4b3f182a024e7aeb1f6273bc03ae1f3dacfe582c3e9e30d5bf8544aff5
|
7
|
+
data.tar.gz: 89c6e920b1dd516e29cca17a7246b334f6ef4129d81d2f3989c7efe52ba66cb6da3b131953cde16ba1e187ca62800eb42a3393d2abfc7c66e1a25d246c6f7c1c
|
data/Rakefile
CHANGED
@@ -14,21 +14,18 @@ RDoc::Task.new(:rdoc) do |rdoc|
|
|
14
14
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
15
|
end
|
16
16
|
|
17
|
-
APP_RAKEFILE = File.expand_path("../
|
17
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
18
18
|
load 'rails/tasks/engine.rake'
|
19
19
|
|
20
20
|
|
21
|
-
|
22
21
|
Bundler::GemHelper.install_tasks
|
23
22
|
|
24
|
-
|
23
|
+
Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each {|f| load f }
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
t.libs << 'test'
|
29
|
-
t.pattern = 'test/**/*_test.rb'
|
30
|
-
t.verbose = false
|
31
|
-
end
|
25
|
+
require 'rspec/core'
|
26
|
+
require 'rspec/core/rake_task'
|
32
27
|
|
28
|
+
desc "Run all specs in spec directory (excluding plugin specs)"
|
29
|
+
RSpec::Core::RakeTask.new(:spec => 'app:db:test:prepare')
|
33
30
|
|
34
|
-
task default: :
|
31
|
+
task default: :spec
|
@@ -1,2 +1,2 @@
|
|
1
1
|
@import "foundation";
|
2
|
-
@import "manage/layout";
|
2
|
+
@import "manage/layout.css.scss";
|
@@ -1,3 +1,15 @@
|
|
1
1
|
class Manage::AdminUsersController < Manage::ResourceController
|
2
|
+
index_fields :email, :sign_in_count, :current_sign_in_ip, :last_sign_in_ip
|
3
|
+
search_fields :email, :sign_in_count, :current_sign_in_ip, :last_sign_in_ip
|
4
|
+
|
5
|
+
def show
|
6
|
+
if params[:id] == 'sign_out'
|
7
|
+
signed_out = (Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name))
|
8
|
+
redirect_to '/manage/admin_users/sign_in'
|
9
|
+
return
|
10
|
+
end
|
11
|
+
|
12
|
+
super
|
13
|
+
end
|
2
14
|
|
3
15
|
end
|
@@ -1,19 +1,13 @@
|
|
1
1
|
class Manage::ApplicationController < ActionController::Base
|
2
|
-
|
3
|
-
before_filter :authenticate_admin
|
2
|
+
before_filter :auth_user!
|
4
3
|
|
5
|
-
def
|
6
|
-
|
7
|
-
@current_user = AdminUser.where(email: username).first
|
8
|
-
return request_http_basic_authentication if @current_user.blank?
|
9
|
-
return request_http_basic_authentication unless @current_user.valid_password?(password)
|
10
|
-
@current_user
|
11
|
-
end
|
4
|
+
def auth_user!
|
5
|
+
redirect_to new_admin_user_session_path unless admin_user_signed_in?
|
12
6
|
end
|
13
7
|
|
14
8
|
helper_method :current_user
|
15
9
|
def current_user
|
16
|
-
|
10
|
+
current_admin_user
|
17
11
|
end
|
18
12
|
|
19
13
|
end
|
@@ -12,6 +12,19 @@ class Manage::ResourceController < Manage::ApplicationController
|
|
12
12
|
|
13
13
|
respond_to :html
|
14
14
|
|
15
|
+
helper_method :list_index_fields, :list_edit_fields, :list_search_fields, :list_action_links
|
16
|
+
|
17
|
+
def end_of_association_chain
|
18
|
+
if self.resources_configuration[:self][:search_fields].blank?
|
19
|
+
self.class.search_fields :all
|
20
|
+
end
|
21
|
+
|
22
|
+
config = self.resources_configuration[:self]
|
23
|
+
@search = config[:search].new(params[:f])
|
24
|
+
|
25
|
+
@search.results
|
26
|
+
end
|
27
|
+
|
15
28
|
protected
|
16
29
|
def collection
|
17
30
|
assocation = end_of_association_chain.page(params[:page] || 1)
|
@@ -22,4 +35,65 @@ class Manage::ResourceController < Manage::ApplicationController
|
|
22
35
|
params.permit!
|
23
36
|
end
|
24
37
|
|
38
|
+
def self.index_fields(*fields)
|
39
|
+
setup_fields(:index_fields, *fields)
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.edit_fields(*fields)
|
43
|
+
setup_fields(:edit_fields, *fields)
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.search_fields(*fields)
|
47
|
+
setup_fields(:search_fields, *fields)
|
48
|
+
|
49
|
+
config = self.resources_configuration[:self]
|
50
|
+
config[:search] = Manage::Fields::Searcher.generate_search_object(resource_class, config[:search_fields])
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.action_links(*fields)
|
54
|
+
setup_fields(:action_links, *fields)
|
55
|
+
end
|
56
|
+
|
57
|
+
def list_index_fields
|
58
|
+
list_fields(:index_fields)
|
59
|
+
end
|
60
|
+
|
61
|
+
def list_edit_fields
|
62
|
+
list_fields(:edit_fields)
|
63
|
+
end
|
64
|
+
|
65
|
+
def list_search_fields
|
66
|
+
list_fields(:search_fields)
|
67
|
+
end
|
68
|
+
|
69
|
+
def list_action_links
|
70
|
+
if self.resources_configuration[:self][:action_links].blank?
|
71
|
+
[]
|
72
|
+
else
|
73
|
+
self.resources_configuration[:self][:action_links]
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
def self.setup_fields(key, *fields)
|
79
|
+
# :all means all the fields - default
|
80
|
+
if not fields.first.is_a?(Hash) and fields.first.to_sym == :all
|
81
|
+
options = fields.extract_options!
|
82
|
+
options[:except] ||= []
|
83
|
+
options[:include] ||= []
|
84
|
+
|
85
|
+
self.resources_configuration[:self][key] = (resource_class.attribute_names + Array(options[:include])) - Array(options[:except]).map(&:to_s)
|
86
|
+
else
|
87
|
+
self.resources_configuration[:self][key] = fields
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def list_fields(key)
|
92
|
+
if self.resources_configuration[:self][key].blank?
|
93
|
+
resource_class.attribute_names - %w(id created_at updated_at)
|
94
|
+
else
|
95
|
+
self.resources_configuration[:self][key]
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
25
99
|
end
|
@@ -1,6 +1,11 @@
|
|
1
|
-
|
2
|
-
class
|
3
|
-
|
1
|
+
module Manage
|
2
|
+
class SessionsController < ::Devise::SessionsController
|
3
|
+
layout "manage/sign_in"
|
4
4
|
|
5
|
+
def destroy
|
6
|
+
p 'what?'
|
7
|
+
super
|
8
|
+
end
|
9
|
+
end
|
5
10
|
end
|
6
11
|
|
@@ -1,7 +1,63 @@
|
|
1
1
|
module Manage
|
2
2
|
module ResourceHelper
|
3
|
+
def index_fields
|
4
|
+
list_index_fields
|
5
|
+
end
|
6
|
+
|
7
|
+
def edit_fields
|
8
|
+
list_edit_fields
|
9
|
+
end
|
10
|
+
|
3
11
|
def attributes
|
4
12
|
resource_class.attribute_names - %w(id created_at updated_at)
|
5
13
|
end
|
14
|
+
|
15
|
+
def field_value(scope, field_data)
|
16
|
+
Fields::Reader.field_value(scope, field_data).to_s
|
17
|
+
end
|
18
|
+
|
19
|
+
def field_title(resource_class, field_data)
|
20
|
+
Fields::Reader.field_title(resource_class, field_data)
|
21
|
+
end
|
22
|
+
|
23
|
+
def action_link(scope, link_data)
|
24
|
+
value = nil
|
25
|
+
|
26
|
+
if link_data.is_a? (Hash)
|
27
|
+
relation = link_data.keys.first
|
28
|
+
entity = Fields::Reader.field_value(scope, relation)
|
29
|
+
unless entity.present?
|
30
|
+
return ''
|
31
|
+
end
|
32
|
+
if link_data[relation][:label_field].present?
|
33
|
+
value = field_value(scope, link_data[relation][:label_field])
|
34
|
+
elsif link_data[relation][:label].present?
|
35
|
+
value = link_data[relation][:label]
|
36
|
+
end
|
37
|
+
|
38
|
+
path = entity.class.name.dasherize.pluralize.downcase
|
39
|
+
return link_to value, [scope.public_send(relation)]
|
40
|
+
end
|
41
|
+
|
42
|
+
if link_data.is_a? (Symbol) or link_data.is_a?(String)
|
43
|
+
relation = link_data.to_s
|
44
|
+
if scope.class.reflect_on_association(link_data.to_sym).options[:class_name].present?
|
45
|
+
rel_name = scope.class.reflect_on_association(link_data.to_sym).options[:class_name]
|
46
|
+
relation = rel_name.downcase.dasherize.pluralize
|
47
|
+
end
|
48
|
+
if scope.class.reflect_on_association(link_data.to_sym).options[:as].present?
|
49
|
+
key = scope.class.reflect_on_association(link_data.to_sym).options[:as].to_s + '_id'
|
50
|
+
else
|
51
|
+
key = scope.class.name.downcase.dasherize + '_id'
|
52
|
+
end
|
53
|
+
return "<a href=\"#{relation}?f%5B#{key}%5D=#{scope.id}\">#{resource_class.human_attribute_name(link_data.to_s)}</a>".html_safe
|
54
|
+
end
|
55
|
+
|
56
|
+
unless value
|
57
|
+
raise 'Unsupported link data'
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
6
62
|
end
|
7
63
|
end
|
@@ -4,14 +4,10 @@ ul.right
|
|
4
4
|
li.divider.hide-for-small
|
5
5
|
li = link_to current_user.email, current_user
|
6
6
|
li.divider.hide-for-small
|
7
|
-
li = link_to City.model_name.human(count: 2), manage.cities_path
|
8
|
-
li.divider.hide-for-small
|
9
7
|
li = link_to 'users', users_path
|
10
8
|
li.divider.hide-for-small
|
11
9
|
li = link_to AdminUser.model_name.human(count:2), admin_users_path
|
12
10
|
li.divider.hide-for-small
|
13
|
-
li = link_to 'terms', main_app.about_us_pages_path
|
14
|
-
li.divider.hide-for-small
|
15
11
|
li.has-dropdown
|
16
12
|
a href="#" Main Item 1
|
17
13
|
ul.dropdown
|
@@ -53,4 +49,4 @@ ul.right
|
|
53
49
|
li
|
54
50
|
a href="#" Dropdown Level 1f
|
55
51
|
li.has-form
|
56
|
-
a.button href="http://foundation.zurb.com/docs" Sample button
|
52
|
+
a.button href="http://foundation.zurb.com/docs" Sample button
|
@@ -5,23 +5,23 @@ html
|
|
5
5
|
title Manage
|
6
6
|
= stylesheet_link_tag "manage/application", media: "all"
|
7
7
|
= javascript_include_tag "vendor/custom.modernizr"
|
8
|
-
= javascript_include_tag "manage/application"
|
9
8
|
= csrf_meta_tags
|
10
9
|
|
11
|
-
body class="
|
12
|
-
|
10
|
+
body class="simple" data-locale=I18n.locale
|
11
|
+
section.main
|
13
12
|
#flash
|
14
13
|
- flash.each do |key, value|
|
15
14
|
- key = 'info' if key == :notice
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
.clearfix
|
15
|
+
- key = 'alert' if key == :error
|
16
|
+
div data-alert="" class="alert-box #{key}"
|
17
|
+
- if value.is_a?(Array)
|
18
|
+
- value.each do |element|
|
19
|
+
p #{element.html_safe}
|
20
|
+
- elsif value.is_a?(String)
|
21
|
+
p #{value.html_safe}
|
22
|
+
a.close href="#" ×
|
25
23
|
|
24
|
+
= yield
|
25
|
+
|
26
|
+
= javascript_include_tag "manage/application"
|
26
27
|
|
27
|
-
= yield
|
@@ -1,4 +1,4 @@
|
|
1
1
|
= manage_form_for [ resource ] do |f|
|
2
|
-
-
|
3
|
-
= f.input
|
4
|
-
= f.submit class: 'button small'
|
2
|
+
- edit_fields.each do |field|
|
3
|
+
= f.input field
|
4
|
+
= f.submit class: 'button small'
|
@@ -1,11 +1,22 @@
|
|
1
|
-
form
|
1
|
+
= manage_form_for @search, as: :f, method: :get, url: "#{resource_class.name.underscore.pluralize}", html: {id: 'search-form'} do |f|
|
2
2
|
fieldset
|
3
3
|
legend Filter
|
4
|
+
- list_search_fields.each do |field|
|
5
|
+
.row
|
6
|
+
.columns.large-12
|
7
|
+
- label_text = resource_class.human_attribute_name(field)
|
8
|
+
- if resource_class.columns_hash[field.to_s].blank?
|
9
|
+
label #{label_text}
|
10
|
+
= f.search_field field.to_sym, placeholder: label_text
|
11
|
+
- elsif resource_class.columns_hash[field.to_s].type == :datetime
|
12
|
+
label #{label_text}
|
13
|
+
= f.date_field field.to_sym, placeholder: label_text
|
14
|
+
- elsif resource_class.columns_hash[field.to_s].type == :integer
|
15
|
+
label #{label_text}
|
16
|
+
= f.number_field field.to_sym, placeholder: label_text
|
17
|
+
- else
|
18
|
+
label #{label_text}
|
19
|
+
= f.search_field field.to_sym, placeholder: label_text
|
4
20
|
.row
|
5
21
|
.columns.large-12
|
6
|
-
|
7
|
-
input type="text" placeholder="Name"
|
8
|
-
.row
|
9
|
-
.columns.large-12
|
10
|
-
label City
|
11
|
-
input type="text" placeholder="City"
|
22
|
+
= f.submit 'Search', class: 'button small'
|
@@ -1,16 +1,18 @@
|
|
1
1
|
table
|
2
2
|
thead
|
3
3
|
tr
|
4
|
-
-
|
5
|
-
th= resource_class
|
4
|
+
- index_fields.each do |field_data|
|
5
|
+
th = field_title(resource_class, field_data)
|
6
6
|
th = t('.actions')
|
7
7
|
tbody
|
8
8
|
- collection.each do |resource|
|
9
9
|
tr
|
10
|
-
-
|
11
|
-
td = resource
|
10
|
+
- index_fields.each do |field_data|
|
11
|
+
td = field_value(resource, field_data)
|
12
12
|
td
|
13
13
|
ul.inline-list
|
14
14
|
li = link_to t('manage.actions.show'), [resource]
|
15
15
|
li = link_to t('manage.actions.edit'), [:edit, resource]
|
16
|
-
li = link_to t('manage.actions.destroy'), [resource], method: :delete, data: { confirm: t('manage.confirmations.Are you sure')}
|
16
|
+
li = link_to t('manage.actions.destroy'), [resource], method: :delete, data: { confirm: t('manage.confirmations.Are you sure')}
|
17
|
+
- list_action_links.each do |link_data|
|
18
|
+
li = action_link(resource, link_data)
|
@@ -5,8 +5,9 @@ nav
|
|
5
5
|
|
6
6
|
.row
|
7
7
|
.columns.large-9
|
8
|
-
= render "manage/resource/index/table",
|
8
|
+
= render "manage/resource/index/table", index_fields: index_fields
|
9
9
|
.columns.large-3
|
10
10
|
= render "manage/resource/index/filters"
|
11
11
|
|
12
|
-
= paginate collection
|
12
|
+
= paginate collection
|
13
|
+
= render "manage/resource/index/count"
|
@@ -1,11 +1,10 @@
|
|
1
1
|
h2 = t('.sign_in')
|
2
2
|
|
3
|
-
= simple_form_for(resource, :as => resource_name, :url =>
|
3
|
+
= simple_form_for(resource, :as => resource_name, :url => admin_user_session_path) do |f|
|
4
4
|
.form-inputs
|
5
5
|
= f.input :email, :required => false, :autofocus => true
|
6
6
|
= f.input :password, :required => false
|
7
7
|
= f.input :remember_me, :as => :boolean if devise_mapping.rememberable?
|
8
8
|
.form-actions
|
9
|
-
= f.
|
9
|
+
= f.submit t('devise.users.registrations.login')
|
10
10
|
|
11
|
-
= render "devise/users/shared/links"
|