kadmin 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +44 -44
- data/Rakefile +146 -146
- data/app/assets/javascripts/modular/app.js +1388 -1388
- data/app/assets/javascripts/modular/application.js +3 -3
- data/app/assets/javascripts/modular/vendor.js +57671 -57671
- data/app/assets/stylesheets/kadmin/typeahead-select.scss +2 -0
- data/app/assets/stylesheets/modular/app-blue.css +2795 -2795
- data/app/assets/stylesheets/modular/app-custom.css +2795 -2795
- data/app/assets/stylesheets/modular/app-green.css +2795 -2795
- data/app/assets/stylesheets/modular/app-orange.css +2795 -2795
- data/app/assets/stylesheets/modular/app-purple.css +2795 -2795
- data/app/assets/stylesheets/modular/app-red.css +2795 -2795
- data/app/assets/stylesheets/modular/app-seagreen.css +2795 -2795
- data/app/assets/stylesheets/modular/app.css +2795 -2795
- data/app/assets/stylesheets/modular/custom.css +51 -19
- data/app/assets/stylesheets/modular/vendor.css +12999 -12999
- data/app/controllers/kadmin/application_controller.rb +64 -64
- data/app/controllers/kadmin/auth_controller.rb +98 -98
- data/app/controllers/kadmin/concerns/authorized_user.rb +67 -67
- data/app/controllers/kadmin/dash_controller.rb +19 -19
- data/app/decorators/kadmin/finder_decorator.rb +50 -50
- data/app/decorators/kadmin/pager_decorator.rb +33 -33
- data/app/helpers/kadmin/alert_helper.rb +59 -59
- data/app/helpers/kadmin/application_helper.rb +4 -4
- data/app/helpers/kadmin/bootstrap_helper.rb +23 -23
- data/app/helpers/kadmin/form_builder.rb +9 -9
- data/app/helpers/kadmin/forms/inverted_check_box.rb +10 -10
- data/app/helpers/kadmin/navigation_helper.rb +28 -28
- data/app/helpers/kadmin/pagination_helper.rb +95 -95
- data/app/views/kadmin/auth/login.html.erb +4 -4
- data/app/views/kadmin/components/_finder.html.erb +14 -18
- data/app/views/kadmin/components/finder/_empty.html.erb +3 -3
- data/app/views/kadmin/components/finder/_form.erb +10 -10
- data/app/views/kadmin/components/finder/_header.html.erb +14 -11
- data/app/views/kadmin/dash/index.html.erb +5 -5
- data/app/views/kadmin/error.html.erb +5 -5
- data/app/views/kadmin/helpers/_alerts.html.erb +4 -4
- data/app/views/kadmin/helpers/_form_errors.html.erb +10 -10
- data/app/views/layouts/modular/application.html.erb +134 -132
- data/config/initializers/action_view.rb +2 -2
- data/config/initializers/assets.rb +5 -5
- data/config/locales/de.yml +25 -25
- data/config/locales/en.yml +24 -24
- data/config/routes.rb +12 -12
- data/lib/kadmin.rb +22 -22
- data/lib/kadmin/auth.rb +31 -31
- data/lib/kadmin/auth/configuration.rb +66 -66
- data/lib/kadmin/auth/unauthorized_error.rb +14 -14
- data/lib/kadmin/auth/user.rb +15 -15
- data/lib/kadmin/auth/user_store.rb +21 -21
- data/lib/kadmin/configuration.rb +18 -18
- data/lib/kadmin/engine.rb +15 -15
- data/lib/kadmin/error.rb +7 -7
- data/lib/kadmin/errors/authorization.rb +15 -15
- data/lib/kadmin/finder.rb +66 -66
- data/lib/kadmin/form.rb +179 -179
- data/lib/kadmin/pager.rb +93 -93
- data/lib/kadmin/version.rb +3 -3
- data/test/dummy/README.rdoc +28 -28
- data/test/dummy/Rakefile +6 -6
- data/test/dummy/app/assets/javascripts/application.js +13 -13
- data/test/dummy/app/assets/stylesheets/application.css +15 -15
- data/test/dummy/app/controllers/admin/application_controller.rb +11 -11
- data/test/dummy/app/controllers/admin/people_controller.rb +89 -89
- data/test/dummy/app/controllers/admin_controller.rb +4 -4
- data/test/dummy/app/controllers/application_controller.rb +5 -5
- data/test/dummy/app/controllers/authorized_controller.rb +8 -8
- data/test/dummy/app/helpers/application_helper.rb +2 -2
- data/test/dummy/app/models/group.rb +8 -8
- data/test/dummy/app/models/group_person.rb +6 -6
- data/test/dummy/app/models/person.rb +20 -20
- data/test/dummy/app/views/admin/index.html.erb +1 -1
- data/test/dummy/app/views/admin/people/_form.html.erb +34 -34
- data/test/dummy/app/views/admin/people/_table.html.erb +33 -33
- data/test/dummy/app/views/admin/people/edit.html.erb +4 -4
- data/test/dummy/app/views/admin/people/index.html.erb +3 -3
- data/test/dummy/app/views/admin/people/new.html.erb +5 -5
- data/test/dummy/app/views/admin/people/show.html.erb +3 -3
- data/test/dummy/app/views/authorized/index.html.erb +1 -1
- data/test/dummy/app/views/layouts/application.html.erb +14 -14
- data/test/dummy/bin/bundle +3 -3
- data/test/dummy/bin/rails +4 -4
- data/test/dummy/bin/rake +4 -4
- data/test/dummy/bin/setup +29 -29
- data/test/dummy/config.ru +4 -4
- data/test/dummy/config/application.rb +39 -39
- data/test/dummy/config/boot.rb +5 -5
- data/test/dummy/config/database.yml +22 -22
- data/test/dummy/config/environment.rb +5 -5
- data/test/dummy/config/environments/development.rb +41 -41
- data/test/dummy/config/environments/production.rb +79 -79
- data/test/dummy/config/environments/test.rb +42 -42
- data/test/dummy/config/initializers/assets.rb +10 -10
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -7
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -3
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -4
- data/test/dummy/config/initializers/inflections.rb +16 -16
- data/test/dummy/config/initializers/kadmin.rb +24 -24
- data/test/dummy/config/initializers/mime_types.rb +4 -4
- data/test/dummy/config/initializers/session_store.rb +3 -3
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -14
- data/test/dummy/config/locales/en.yml +17 -17
- data/test/dummy/config/routes.rb +13 -13
- data/test/dummy/config/secrets.yml +22 -22
- data/test/dummy/db/migrate/20161006114509_create_people.rb +11 -11
- data/test/dummy/db/migrate/20161006134459_create_groups.rb +11 -11
- data/test/dummy/db/migrate/20161006134746_create_group_people.rb +11 -11
- data/test/dummy/db/schema.rb +43 -43
- data/test/dummy/lib/forms/group_form.rb +16 -16
- data/test/dummy/lib/forms/person_form.rb +19 -19
- data/test/dummy/public/404.html +67 -67
- data/test/dummy/public/422.html +67 -67
- data/test/dummy/public/500.html +66 -66
- data/test/dummy/test/fixtures/children.yml +11 -11
- data/test/dummy/test/fixtures/group_people.yml +11 -11
- data/test/dummy/test/fixtures/groups.yml +11 -11
- data/test/dummy/test/fixtures/people.yml +11 -11
- data/test/dummy/test/models/group_person_test.rb +7 -7
- data/test/dummy/test/models/group_test.rb +7 -7
- data/test/kadmin/form_test.rb +6 -6
- data/test/test_helper.rb +32 -32
- metadata +54 -53
data/lib/kadmin/pager.rb
CHANGED
@@ -1,93 +1,93 @@
|
|
1
|
-
module Kadmin
|
2
|
-
# Simple Pager structure, used to paginate collections
|
3
|
-
class Pager
|
4
|
-
# @return [Integer] number of items per page
|
5
|
-
attr_reader :size
|
6
|
-
|
7
|
-
# @return [Integer] current index offset (determines current page)
|
8
|
-
attr_reader :offset
|
9
|
-
|
10
|
-
# @return [Integer] total number of pages
|
11
|
-
attr_reader :pages
|
12
|
-
|
13
|
-
# @return [Integer] the current page
|
14
|
-
attr_reader :current_page
|
15
|
-
|
16
|
-
# @return [Integer] total number of items in the collection
|
17
|
-
attr_reader :total
|
18
|
-
|
19
|
-
# @param [Integer] size size of a page
|
20
|
-
# @param [Integer] offset offset/index for the current page
|
21
|
-
def initialize(size:, offset:)
|
22
|
-
@size = size
|
23
|
-
@offset = offset
|
24
|
-
|
25
|
-
raise(Kadmin::Error, 'Page size must be greater than 0!') unless @size.positive?
|
26
|
-
raise(Kadmin::Error, 'Offset must be at least 0!') unless @offset >= 0
|
27
|
-
|
28
|
-
@current_page = (@offset / @size.to_f).floor
|
29
|
-
self.total = @size # assume page size is maximum initially
|
30
|
-
end
|
31
|
-
|
32
|
-
# @param [ActiveRecord::Relation] collection relation to paginate
|
33
|
-
# @return [ActiveRecord::Relation] paginated collection
|
34
|
-
def page(collection)
|
35
|
-
self.total = collection.count
|
36
|
-
|
37
|
-
collection = collection.offset(@offset)
|
38
|
-
collection = collection.limit(@size)
|
39
|
-
|
40
|
-
return collection
|
41
|
-
end
|
42
|
-
|
43
|
-
# @param [Integer] page the page to get the offset for; if not given, uses the current page
|
44
|
-
# @return [Integer] start offset for the given page
|
45
|
-
def offset_at(page = nil)
|
46
|
-
page ||= @current_page
|
47
|
-
return @size * page.to_i
|
48
|
-
end
|
49
|
-
|
50
|
-
# @param [Integer] page the page to check for
|
51
|
-
# @return [Boolean] true if `page` is the current page
|
52
|
-
def current_page?(page)
|
53
|
-
return page == @current_page
|
54
|
-
end
|
55
|
-
|
56
|
-
# @param [Integer] page the page to check for
|
57
|
-
# @return [Boolean] true if `page` exists (i.e. would have any data)
|
58
|
-
def contains?(page)
|
59
|
-
page.in?(0...@pages)
|
60
|
-
end
|
61
|
-
|
62
|
-
# @param [Integer] total sets the number of total collection items (not total loaded)
|
63
|
-
def total=(total)
|
64
|
-
@total = total
|
65
|
-
@pages = (@total / @size.to_f).ceil
|
66
|
-
end
|
67
|
-
|
68
|
-
# @param [Integer] page optional; if not given, uses the current page
|
69
|
-
# @return [Integer] the number of items that are on this page
|
70
|
-
def page_size(page = nil)
|
71
|
-
page ||= @current_page
|
72
|
-
page_start = offset_at(page)
|
73
|
-
page_end = [offset_at(page.to_i + 1), @total].min
|
74
|
-
|
75
|
-
return page_end - page_start
|
76
|
-
end
|
77
|
-
|
78
|
-
# @param [Integer] page optional; if given, checks if the page after would have any data, otherwise checks based on the current page
|
79
|
-
# @return [Boolean] true if there is a next page
|
80
|
-
def next_page?(page = nil)
|
81
|
-
page ||= @current_page
|
82
|
-
return offset_at(page.to_i + 1) < @total
|
83
|
-
end
|
84
|
-
|
85
|
-
# @param [Integer] page optional; if given, checks if the page after would have any data, otherwise checks based on the current page
|
86
|
-
# @return [Boolean] true if there is a previous page
|
87
|
-
def previous_page?(page = nil)
|
88
|
-
page ||= @current_page
|
89
|
-
|
90
|
-
return page.to_i.positive?
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
1
|
+
module Kadmin
|
2
|
+
# Simple Pager structure, used to paginate collections
|
3
|
+
class Pager
|
4
|
+
# @return [Integer] number of items per page
|
5
|
+
attr_reader :size
|
6
|
+
|
7
|
+
# @return [Integer] current index offset (determines current page)
|
8
|
+
attr_reader :offset
|
9
|
+
|
10
|
+
# @return [Integer] total number of pages
|
11
|
+
attr_reader :pages
|
12
|
+
|
13
|
+
# @return [Integer] the current page
|
14
|
+
attr_reader :current_page
|
15
|
+
|
16
|
+
# @return [Integer] total number of items in the collection
|
17
|
+
attr_reader :total
|
18
|
+
|
19
|
+
# @param [Integer] size size of a page
|
20
|
+
# @param [Integer] offset offset/index for the current page
|
21
|
+
def initialize(size:, offset:)
|
22
|
+
@size = size
|
23
|
+
@offset = offset
|
24
|
+
|
25
|
+
raise(Kadmin::Error, 'Page size must be greater than 0!') unless @size.positive?
|
26
|
+
raise(Kadmin::Error, 'Offset must be at least 0!') unless @offset >= 0
|
27
|
+
|
28
|
+
@current_page = (@offset / @size.to_f).floor
|
29
|
+
self.total = @size # assume page size is maximum initially
|
30
|
+
end
|
31
|
+
|
32
|
+
# @param [ActiveRecord::Relation] collection relation to paginate
|
33
|
+
# @return [ActiveRecord::Relation] paginated collection
|
34
|
+
def page(collection)
|
35
|
+
self.total = collection.count
|
36
|
+
|
37
|
+
collection = collection.offset(@offset)
|
38
|
+
collection = collection.limit(@size)
|
39
|
+
|
40
|
+
return collection
|
41
|
+
end
|
42
|
+
|
43
|
+
# @param [Integer] page the page to get the offset for; if not given, uses the current page
|
44
|
+
# @return [Integer] start offset for the given page
|
45
|
+
def offset_at(page = nil)
|
46
|
+
page ||= @current_page
|
47
|
+
return @size * page.to_i
|
48
|
+
end
|
49
|
+
|
50
|
+
# @param [Integer] page the page to check for
|
51
|
+
# @return [Boolean] true if `page` is the current page
|
52
|
+
def current_page?(page)
|
53
|
+
return page == @current_page
|
54
|
+
end
|
55
|
+
|
56
|
+
# @param [Integer] page the page to check for
|
57
|
+
# @return [Boolean] true if `page` exists (i.e. would have any data)
|
58
|
+
def contains?(page)
|
59
|
+
page.in?(0...@pages)
|
60
|
+
end
|
61
|
+
|
62
|
+
# @param [Integer] total sets the number of total collection items (not total loaded)
|
63
|
+
def total=(total)
|
64
|
+
@total = total
|
65
|
+
@pages = (@total / @size.to_f).ceil
|
66
|
+
end
|
67
|
+
|
68
|
+
# @param [Integer] page optional; if not given, uses the current page
|
69
|
+
# @return [Integer] the number of items that are on this page
|
70
|
+
def page_size(page = nil)
|
71
|
+
page ||= @current_page
|
72
|
+
page_start = offset_at(page)
|
73
|
+
page_end = [offset_at(page.to_i + 1), @total].min
|
74
|
+
|
75
|
+
return page_end - page_start
|
76
|
+
end
|
77
|
+
|
78
|
+
# @param [Integer] page optional; if given, checks if the page after would have any data, otherwise checks based on the current page
|
79
|
+
# @return [Boolean] true if there is a next page
|
80
|
+
def next_page?(page = nil)
|
81
|
+
page ||= @current_page
|
82
|
+
return offset_at(page.to_i + 1) < @total
|
83
|
+
end
|
84
|
+
|
85
|
+
# @param [Integer] page optional; if given, checks if the page after would have any data, otherwise checks based on the current page
|
86
|
+
# @return [Boolean] true if there is a previous page
|
87
|
+
def previous_page?(page = nil)
|
88
|
+
page ||= @current_page
|
89
|
+
|
90
|
+
return page.to_i.positive?
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
data/lib/kadmin/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module Kadmin
|
2
|
-
VERSION = '0.3.
|
3
|
-
end
|
1
|
+
module Kadmin
|
2
|
+
VERSION = '0.3.2'.freeze
|
3
|
+
end
|
data/test/dummy/README.rdoc
CHANGED
@@ -1,28 +1,28 @@
|
|
1
|
-
== README
|
2
|
-
|
3
|
-
This README would normally document whatever steps are necessary to get the
|
4
|
-
application up and running.
|
5
|
-
|
6
|
-
Things you may want to cover:
|
7
|
-
|
8
|
-
* Ruby version
|
9
|
-
|
10
|
-
* System dependencies
|
11
|
-
|
12
|
-
* Configuration
|
13
|
-
|
14
|
-
* Database creation
|
15
|
-
|
16
|
-
* Database initialization
|
17
|
-
|
18
|
-
* How to run the test suite
|
19
|
-
|
20
|
-
* Services (job queues, cache servers, search engines, etc.)
|
21
|
-
|
22
|
-
* Deployment instructions
|
23
|
-
|
24
|
-
* ...
|
25
|
-
|
26
|
-
|
27
|
-
Please feel free to use a different markup language if you do not plan to run
|
28
|
-
<tt>rake doc:app</tt>.
|
1
|
+
== README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
25
|
+
|
26
|
+
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
28
|
+
<tt>rake doc:app</tt>.
|
data/test/dummy/Rakefile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
2
|
-
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
3
|
-
|
4
|
-
require File.expand_path('../config/application', __FILE__)
|
5
|
-
|
6
|
-
Rails.application.load_tasks
|
1
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
2
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
3
|
+
|
4
|
+
require File.expand_path('../config/application', __FILE__)
|
5
|
+
|
6
|
+
Rails.application.load_tasks
|
@@ -1,13 +1,13 @@
|
|
1
|
-
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
-
// listed below.
|
3
|
-
//
|
4
|
-
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
-
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
-
//
|
7
|
-
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
-
// compiled file.
|
9
|
-
//
|
10
|
-
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
|
-
// about supported directives.
|
12
|
-
//
|
13
|
-
//= require_tree .
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -1,15 +1,15 @@
|
|
1
|
-
/*
|
2
|
-
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
-
* listed below.
|
4
|
-
*
|
5
|
-
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
-
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
-
*
|
8
|
-
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
-
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
-
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
-
* file per style scope.
|
12
|
-
*
|
13
|
-
*= require_tree .
|
14
|
-
*= require_self
|
15
|
-
*/
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
+
* file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -1,11 +1,11 @@
|
|
1
|
-
module Admin
|
2
|
-
class ApplicationController < Kadmin::ApplicationController
|
3
|
-
def set_navbar_links
|
4
|
-
super
|
5
|
-
@layout_navbar_links += [
|
6
|
-
{ title: 'People', path: admin_people_path },
|
7
|
-
{ title: 'Groups', path: admin_groups_path }
|
8
|
-
]
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
1
|
+
module Admin
|
2
|
+
class ApplicationController < Kadmin::ApplicationController
|
3
|
+
def set_navbar_links
|
4
|
+
super
|
5
|
+
@layout_navbar_links += [
|
6
|
+
{ title: 'People', path: admin_people_path },
|
7
|
+
{ title: 'Groups', path: admin_groups_path }
|
8
|
+
]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -1,89 +1,89 @@
|
|
1
|
-
module Admin
|
2
|
-
class PeopleController < Admin::ApplicationController
|
3
|
-
MAX_PAGE_SIZE = 200
|
4
|
-
|
5
|
-
# GET /admin/people
|
6
|
-
def index
|
7
|
-
params.permit(:page_size, :page_offset, :filter_name, :format)
|
8
|
-
|
9
|
-
page_size = [params.fetch(:page_size, 15).to_i, MAX_PAGE_SIZE].min # fix 200 as maximum size
|
10
|
-
|
11
|
-
finder = Kadmin::Finder.new(Person.includes(:groups, :owned_groups).order(created_at: :desc))
|
12
|
-
.filter(name: :name, column: [:first_name, :last_name], value: params[:filter_name])
|
13
|
-
.paginate(size: page_size, offset: params.fetch(:page_offset, 0))
|
14
|
-
finder.find!
|
15
|
-
@finder = Kadmin::FinderDecorator.new(finder)
|
16
|
-
end
|
17
|
-
|
18
|
-
# GET /admin/people/:id
|
19
|
-
def show
|
20
|
-
@person = load_person
|
21
|
-
end
|
22
|
-
|
23
|
-
# GET /admin/people/edit/:id
|
24
|
-
def edit
|
25
|
-
@person ||= load_person
|
26
|
-
@person_form ||= person_form
|
27
|
-
end
|
28
|
-
|
29
|
-
# PUT /admin/people/:id
|
30
|
-
# PATCH /admin/people/:id
|
31
|
-
def update
|
32
|
-
@person = load_person
|
33
|
-
@person_form = person_form
|
34
|
-
|
35
|
-
if @person_form.valid? && @person_form.save
|
36
|
-
redirect_to(admin_person_path(@person_form.id))
|
37
|
-
else
|
38
|
-
render :edit
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
# GET /admin/people/new
|
43
|
-
def new
|
44
|
-
@person ||= Person.new
|
45
|
-
@person_form ||= person_form
|
46
|
-
end
|
47
|
-
|
48
|
-
# POST /admin/people
|
49
|
-
def create
|
50
|
-
@person = Person.new
|
51
|
-
@person_form = person_form
|
52
|
-
|
53
|
-
if @person_form.valid? && @person_form.save
|
54
|
-
redirect_to(admin_person_path(@person_form.id))
|
55
|
-
else
|
56
|
-
render :new
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
# DELETE /admin/people/:id
|
61
|
-
def destroy
|
62
|
-
@person = Person.new
|
63
|
-
name = [@person.last_name, @person.first_name].join(', ')
|
64
|
-
|
65
|
-
@person.destroy # only fails when it raises an exception
|
66
|
-
flash[:success] = "Successfully deleted #{name}"
|
67
|
-
|
68
|
-
redirect_to admin_people_path
|
69
|
-
end
|
70
|
-
|
71
|
-
# @!group Helpers
|
72
|
-
|
73
|
-
def load_person
|
74
|
-
params.require(:id)
|
75
|
-
id = params[:id].to_i
|
76
|
-
return Person.includes(:groups, :owned_groups).find(id)
|
77
|
-
end
|
78
|
-
private :load_person
|
79
|
-
|
80
|
-
def person_form
|
81
|
-
form = Forms::PersonForm.new(@person)
|
82
|
-
form.assign_attributes(params.fetch(:person, {}).except(:id))
|
83
|
-
return form
|
84
|
-
end
|
85
|
-
private :person_form
|
86
|
-
|
87
|
-
# @!endgroup
|
88
|
-
end
|
89
|
-
end
|
1
|
+
module Admin
|
2
|
+
class PeopleController < Admin::ApplicationController
|
3
|
+
MAX_PAGE_SIZE = 200
|
4
|
+
|
5
|
+
# GET /admin/people
|
6
|
+
def index
|
7
|
+
params.permit(:page_size, :page_offset, :filter_name, :format)
|
8
|
+
|
9
|
+
page_size = [params.fetch(:page_size, 15).to_i, MAX_PAGE_SIZE].min # fix 200 as maximum size
|
10
|
+
|
11
|
+
finder = Kadmin::Finder.new(Person.includes(:groups, :owned_groups).order(created_at: :desc))
|
12
|
+
.filter(name: :name, column: [:first_name, :last_name], value: params[:filter_name])
|
13
|
+
.paginate(size: page_size, offset: params.fetch(:page_offset, 0))
|
14
|
+
finder.find!
|
15
|
+
@finder = Kadmin::FinderDecorator.new(finder)
|
16
|
+
end
|
17
|
+
|
18
|
+
# GET /admin/people/:id
|
19
|
+
def show
|
20
|
+
@person = load_person
|
21
|
+
end
|
22
|
+
|
23
|
+
# GET /admin/people/edit/:id
|
24
|
+
def edit
|
25
|
+
@person ||= load_person
|
26
|
+
@person_form ||= person_form
|
27
|
+
end
|
28
|
+
|
29
|
+
# PUT /admin/people/:id
|
30
|
+
# PATCH /admin/people/:id
|
31
|
+
def update
|
32
|
+
@person = load_person
|
33
|
+
@person_form = person_form
|
34
|
+
|
35
|
+
if @person_form.valid? && @person_form.save
|
36
|
+
redirect_to(admin_person_path(@person_form.id))
|
37
|
+
else
|
38
|
+
render :edit
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# GET /admin/people/new
|
43
|
+
def new
|
44
|
+
@person ||= Person.new
|
45
|
+
@person_form ||= person_form
|
46
|
+
end
|
47
|
+
|
48
|
+
# POST /admin/people
|
49
|
+
def create
|
50
|
+
@person = Person.new
|
51
|
+
@person_form = person_form
|
52
|
+
|
53
|
+
if @person_form.valid? && @person_form.save
|
54
|
+
redirect_to(admin_person_path(@person_form.id))
|
55
|
+
else
|
56
|
+
render :new
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# DELETE /admin/people/:id
|
61
|
+
def destroy
|
62
|
+
@person = Person.new
|
63
|
+
name = [@person.last_name, @person.first_name].join(', ')
|
64
|
+
|
65
|
+
@person.destroy # only fails when it raises an exception
|
66
|
+
flash[:success] = "Successfully deleted #{name}"
|
67
|
+
|
68
|
+
redirect_to admin_people_path
|
69
|
+
end
|
70
|
+
|
71
|
+
# @!group Helpers
|
72
|
+
|
73
|
+
def load_person
|
74
|
+
params.require(:id)
|
75
|
+
id = params[:id].to_i
|
76
|
+
return Person.includes(:groups, :owned_groups).find(id)
|
77
|
+
end
|
78
|
+
private :load_person
|
79
|
+
|
80
|
+
def person_form
|
81
|
+
form = Forms::PersonForm.new(@person)
|
82
|
+
form.assign_attributes(params.fetch(:person, {}).except(:id))
|
83
|
+
return form
|
84
|
+
end
|
85
|
+
private :person_form
|
86
|
+
|
87
|
+
# @!endgroup
|
88
|
+
end
|
89
|
+
end
|