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
@@ -1,19 +1,19 @@
|
|
1
|
-
module Kadmin
|
2
|
-
class DashController < Kadmin::ApplicationController
|
3
|
-
# @!group Endpoints
|
4
|
-
|
5
|
-
# GET /
|
6
|
-
def index
|
7
|
-
end
|
8
|
-
|
9
|
-
# @!endgroup
|
10
|
-
|
11
|
-
# @!group Helpers
|
12
|
-
|
13
|
-
def set_navbar_links
|
14
|
-
@layout_navbar_links = Kadmin.config.navbar_links
|
15
|
-
end
|
16
|
-
|
17
|
-
# @!endgroup
|
18
|
-
end
|
19
|
-
end
|
1
|
+
module Kadmin
|
2
|
+
class DashController < Kadmin::ApplicationController
|
3
|
+
# @!group Endpoints
|
4
|
+
|
5
|
+
# GET /
|
6
|
+
def index
|
7
|
+
end
|
8
|
+
|
9
|
+
# @!endgroup
|
10
|
+
|
11
|
+
# @!group Helpers
|
12
|
+
|
13
|
+
def set_navbar_links
|
14
|
+
@layout_navbar_links = Kadmin.config.navbar_links
|
15
|
+
end
|
16
|
+
|
17
|
+
# @!endgroup
|
18
|
+
end
|
19
|
+
end
|
@@ -1,50 +1,50 @@
|
|
1
|
-
module Kadmin
|
2
|
-
class FinderDecorator
|
3
|
-
# @return [Kadmin::Finder] underlying finder model
|
4
|
-
attr_reader :finder
|
5
|
-
|
6
|
-
delegate :filters, :scope, :results, to: :finder
|
7
|
-
|
8
|
-
def initialize(finder)
|
9
|
-
@finder = finder
|
10
|
-
end
|
11
|
-
|
12
|
-
# @return [Boolean] true if no results, false otherwise
|
13
|
-
def empty?
|
14
|
-
return finder.results.count.zero?
|
15
|
-
end
|
16
|
-
|
17
|
-
# @return [String] how many resources are being displayed (along with indices)
|
18
|
-
def currently_showing
|
19
|
-
resource = resource_name.downcase
|
20
|
-
displayed = empty? ? 0 : pager.displayed_items
|
21
|
-
|
22
|
-
currently_showing_phrase = "#{displayed} #{resource}"
|
23
|
-
currently_showing_phrase = "#{currently_showing_phrase} (#{pager.page_start} - #{pager.page_end})" if finder.results.count > 1
|
24
|
-
|
25
|
-
return currently_showing_phrase
|
26
|
-
end
|
27
|
-
|
28
|
-
# @return [String] human readable, singular/plural form of the finder's model
|
29
|
-
def resource_name
|
30
|
-
return @finder.scope.model_name.human(count: pager.displayed_items)
|
31
|
-
end
|
32
|
-
|
33
|
-
# @return [String] a description of the current applied filters
|
34
|
-
def applied_filters
|
35
|
-
applied_filters = ''
|
36
|
-
filters = @finder.filters.reduce([]) do |acc, (name, filter)|
|
37
|
-
next(acc) if filter.value.blank?
|
38
|
-
acc << %(<strong>#{filter.value}</strong> on <em>#{name}</em>)
|
39
|
-
end
|
40
|
-
applied_filters = "(filtering: #{filters.join('; ')})" unless filters.empty?
|
41
|
-
|
42
|
-
return applied_filters.html_safe
|
43
|
-
end
|
44
|
-
|
45
|
-
# @return [Kadmin::PagerDecorator] decorated pager of the underlying finder
|
46
|
-
def pager
|
47
|
-
return @pager ||= Kadmin::PagerDecorator.new(@finder.pager)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
1
|
+
module Kadmin
|
2
|
+
class FinderDecorator
|
3
|
+
# @return [Kadmin::Finder] underlying finder model
|
4
|
+
attr_reader :finder
|
5
|
+
|
6
|
+
delegate :filters, :scope, :results, to: :finder
|
7
|
+
|
8
|
+
def initialize(finder)
|
9
|
+
@finder = finder
|
10
|
+
end
|
11
|
+
|
12
|
+
# @return [Boolean] true if no results, false otherwise
|
13
|
+
def empty?
|
14
|
+
return finder.results.count.zero?
|
15
|
+
end
|
16
|
+
|
17
|
+
# @return [String] how many resources are being displayed (along with indices)
|
18
|
+
def currently_showing
|
19
|
+
resource = resource_name.downcase
|
20
|
+
displayed = empty? ? 0 : pager.displayed_items
|
21
|
+
|
22
|
+
currently_showing_phrase = "#{displayed} #{resource}"
|
23
|
+
currently_showing_phrase = "#{currently_showing_phrase} (#{pager.page_start} - #{pager.page_end})" if finder.results.count > 1
|
24
|
+
|
25
|
+
return currently_showing_phrase
|
26
|
+
end
|
27
|
+
|
28
|
+
# @return [String] human readable, singular/plural form of the finder's model
|
29
|
+
def resource_name
|
30
|
+
return @finder.scope.model_name.human(count: pager.displayed_items)
|
31
|
+
end
|
32
|
+
|
33
|
+
# @return [String] a description of the current applied filters
|
34
|
+
def applied_filters
|
35
|
+
applied_filters = ''
|
36
|
+
filters = @finder.filters.reduce([]) do |acc, (name, filter)|
|
37
|
+
next(acc) if filter.value.blank?
|
38
|
+
acc << %(<strong>#{filter.value}</strong> on <em>#{name}</em>)
|
39
|
+
end
|
40
|
+
applied_filters = "(filtering: #{filters.join('; ')})" unless filters.empty?
|
41
|
+
|
42
|
+
return applied_filters.html_safe
|
43
|
+
end
|
44
|
+
|
45
|
+
# @return [Kadmin::PagerDecorator] decorated pager of the underlying finder
|
46
|
+
def pager
|
47
|
+
return @pager ||= Kadmin::PagerDecorator.new(@finder.pager)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -1,33 +1,33 @@
|
|
1
|
-
module Kadmin
|
2
|
-
class PagerDecorator
|
3
|
-
# @return [Kadmin::Pager] underlying pager model
|
4
|
-
attr_reader :pager
|
5
|
-
|
6
|
-
delegate :total, :size, :offset, :pages, :current_page, :contains?, :next_page?,
|
7
|
-
:previous_page?, :offset_at, :current_page?,
|
8
|
-
to: :pager
|
9
|
-
|
10
|
-
def initialize(pager)
|
11
|
-
@pager = pager
|
12
|
-
end
|
13
|
-
|
14
|
-
# @return [Integer] the current number of items displayed for this page
|
15
|
-
def displayed_items
|
16
|
-
return page_end - offset
|
17
|
-
end
|
18
|
-
|
19
|
-
# @return [Integer] the index number of the last item for this page
|
20
|
-
def page_end
|
21
|
-
return [next_page_offset, total].min
|
22
|
-
end
|
23
|
-
|
24
|
-
# @return [Integer] the index number of the start item for this page
|
25
|
-
def page_start
|
26
|
-
return offset + 1
|
27
|
-
end
|
28
|
-
|
29
|
-
def next_page_offset
|
30
|
-
return @pager.offset_at(current_page + 1)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
1
|
+
module Kadmin
|
2
|
+
class PagerDecorator
|
3
|
+
# @return [Kadmin::Pager] underlying pager model
|
4
|
+
attr_reader :pager
|
5
|
+
|
6
|
+
delegate :total, :size, :offset, :pages, :current_page, :contains?, :next_page?,
|
7
|
+
:previous_page?, :offset_at, :current_page?,
|
8
|
+
to: :pager
|
9
|
+
|
10
|
+
def initialize(pager)
|
11
|
+
@pager = pager
|
12
|
+
end
|
13
|
+
|
14
|
+
# @return [Integer] the current number of items displayed for this page
|
15
|
+
def displayed_items
|
16
|
+
return page_end - offset
|
17
|
+
end
|
18
|
+
|
19
|
+
# @return [Integer] the index number of the last item for this page
|
20
|
+
def page_end
|
21
|
+
return [next_page_offset, total].min
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [Integer] the index number of the start item for this page
|
25
|
+
def page_start
|
26
|
+
return offset + 1
|
27
|
+
end
|
28
|
+
|
29
|
+
def next_page_offset
|
30
|
+
return @pager.offset_at(current_page + 1)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -1,59 +1,59 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
module Kadmin
|
3
|
-
# Provide helpers for displaying alerts, as well as matching those alerts to
|
4
|
-
# different flash keys.
|
5
|
-
module AlertHelper
|
6
|
-
# Generates HTML for a bootstrap alert message, optionally closable.
|
7
|
-
# @param [String] type the type of the alert: danger, success, info, warning, or any alert-<TYPE> defined in your CSS
|
8
|
-
# @param [Hash] options options to customize the alert
|
9
|
-
# @option options [String] content ('') text to show if you're not going to pass a block
|
10
|
-
# @option options [Boolean] dismissible (true) if true, adds a close button to the alert. Requires JS enabled
|
11
|
-
# @param [Proc] block optional block to pass if you want add more complex HTML inside
|
12
|
-
def alert(type, options = {}, &block)
|
13
|
-
dismissible = options.fetch(:dismissible, true)
|
14
|
-
text_content = options.fetch(:content, '')
|
15
|
-
|
16
|
-
css_classes = %W(alert alert-#{type})
|
17
|
-
css_classes << 'alert-dismissible' if options.fetch(:dismissible, true)
|
18
|
-
block_content = capture(&block) if block_given?
|
19
|
-
|
20
|
-
return content_tag(:div, '', class: css_classes.join(' '), role: 'alert') do
|
21
|
-
content = text_content.html_safe
|
22
|
-
|
23
|
-
if dismissible
|
24
|
-
button = button_tag(type: 'button', class: 'close', 'data-dismiss': 'alert') do
|
25
|
-
content_tag(:span, '×', {}, false)
|
26
|
-
end
|
27
|
-
content.concat(button)
|
28
|
-
end
|
29
|
-
|
30
|
-
content.concat(block_content.html_safe) unless block_content.blank?
|
31
|
-
content
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
Type = Struct.new(:flash_keys, :css_class, :glyphicon)
|
36
|
-
TYPES = [
|
37
|
-
Type.new(['danger', 'alert'], 'danger', 'exclamation-sign'),
|
38
|
-
Type.new(['success'], 'success', 'ok-sign'),
|
39
|
-
Type.new(['notice', 'info'], 'info', 'info-sign'),
|
40
|
-
Type.new(['warn', 'warning'], 'warning', 'question-sign')
|
41
|
-
].freeze
|
42
|
-
def render_flash_alerts
|
43
|
-
alerts = AlertHelper::TYPES.map do |type|
|
44
|
-
next unless type.flash_keys.any? { |key| flash[key].present? }
|
45
|
-
render_flash_alert(type)
|
46
|
-
end.compact
|
47
|
-
|
48
|
-
return safe_join(alerts)
|
49
|
-
end
|
50
|
-
|
51
|
-
def render_flash_alert(type, &block)
|
52
|
-
messages = type.flash_keys.map { |key| Array.wrap(flash[key]).compact }.flatten
|
53
|
-
return '' if messages.blank?
|
54
|
-
|
55
|
-
wrapped = messages.map { |message| content_tag(:p, glyphicon(type.glyphicon) + " #{message}") }.join('')
|
56
|
-
return alert(type.css_class, content: wrapped)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Kadmin
|
3
|
+
# Provide helpers for displaying alerts, as well as matching those alerts to
|
4
|
+
# different flash keys.
|
5
|
+
module AlertHelper
|
6
|
+
# Generates HTML for a bootstrap alert message, optionally closable.
|
7
|
+
# @param [String] type the type of the alert: danger, success, info, warning, or any alert-<TYPE> defined in your CSS
|
8
|
+
# @param [Hash] options options to customize the alert
|
9
|
+
# @option options [String] content ('') text to show if you're not going to pass a block
|
10
|
+
# @option options [Boolean] dismissible (true) if true, adds a close button to the alert. Requires JS enabled
|
11
|
+
# @param [Proc] block optional block to pass if you want add more complex HTML inside
|
12
|
+
def alert(type, options = {}, &block)
|
13
|
+
dismissible = options.fetch(:dismissible, true)
|
14
|
+
text_content = options.fetch(:content, '')
|
15
|
+
|
16
|
+
css_classes = %W(alert alert-#{type})
|
17
|
+
css_classes << 'alert-dismissible' if options.fetch(:dismissible, true)
|
18
|
+
block_content = capture(&block) if block_given?
|
19
|
+
|
20
|
+
return content_tag(:div, '', class: css_classes.join(' '), role: 'alert') do
|
21
|
+
content = text_content.html_safe
|
22
|
+
|
23
|
+
if dismissible
|
24
|
+
button = button_tag(type: 'button', class: 'close', 'data-dismiss': 'alert') do
|
25
|
+
content_tag(:span, '×', {}, false)
|
26
|
+
end
|
27
|
+
content.concat(button)
|
28
|
+
end
|
29
|
+
|
30
|
+
content.concat(block_content.html_safe) unless block_content.blank?
|
31
|
+
content
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
Type = Struct.new(:flash_keys, :css_class, :glyphicon)
|
36
|
+
TYPES = [
|
37
|
+
Type.new(['danger', 'alert'], 'danger', 'exclamation-sign'),
|
38
|
+
Type.new(['success'], 'success', 'ok-sign'),
|
39
|
+
Type.new(['notice', 'info'], 'info', 'info-sign'),
|
40
|
+
Type.new(['warn', 'warning'], 'warning', 'question-sign')
|
41
|
+
].freeze
|
42
|
+
def render_flash_alerts
|
43
|
+
alerts = AlertHelper::TYPES.map do |type|
|
44
|
+
next unless type.flash_keys.any? { |key| flash[key].present? }
|
45
|
+
render_flash_alert(type)
|
46
|
+
end.compact
|
47
|
+
|
48
|
+
return safe_join(alerts)
|
49
|
+
end
|
50
|
+
|
51
|
+
def render_flash_alert(type, &block)
|
52
|
+
messages = type.flash_keys.map { |key| Array.wrap(flash[key]).compact }.flatten
|
53
|
+
return '' if messages.blank?
|
54
|
+
|
55
|
+
wrapped = messages.map { |message| content_tag(:p, glyphicon(type.glyphicon) + " #{message}") }.join('')
|
56
|
+
return alert(type.css_class, content: wrapped)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module Kadmin
|
2
|
-
module ApplicationHelper
|
3
|
-
end
|
4
|
-
end
|
1
|
+
module Kadmin
|
2
|
+
module ApplicationHelper
|
3
|
+
end
|
4
|
+
end
|
@@ -1,23 +1,23 @@
|
|
1
|
-
module Kadmin
|
2
|
-
# Collection of Bootstrap helpers
|
3
|
-
module BootstrapHelper
|
4
|
-
# @see http://getbootstrap.com/components/#glyphicons-glyphs
|
5
|
-
# @param [String] icon the part after glyphicon-
|
6
|
-
def glyphicon(icon)
|
7
|
-
return content_tag(:span, ' ', class: "glyphicon glyphicon-#{icon}", 'aria-hidden': 'true')
|
8
|
-
end
|
9
|
-
|
10
|
-
# @param [Boolean] condition condition of evaluate
|
11
|
-
# @param [String] icon_true the glyphicon to use if true
|
12
|
-
# @param [String] icon_false the glyphicon to use if false
|
13
|
-
def glyphicon_if_else(condition, icon_true, icon_false)
|
14
|
-
return condition ? glyphicon(icon_true) : glyphicon(icon_false)
|
15
|
-
end
|
16
|
-
|
17
|
-
# @param [Hash, String] url_options anything accepted by link_to and image_tag
|
18
|
-
# @param [Integer] max_height maximum height of the thumbnail
|
19
|
-
def thumbnail_link(url_options, max_height)
|
20
|
-
return link_to(image_tag(url_options), url_options, class: 'thumbnail', style: "max-height: #{max_height}px", target: 'new')
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
1
|
+
module Kadmin
|
2
|
+
# Collection of Bootstrap helpers
|
3
|
+
module BootstrapHelper
|
4
|
+
# @see http://getbootstrap.com/components/#glyphicons-glyphs
|
5
|
+
# @param [String] icon the part after glyphicon-
|
6
|
+
def glyphicon(icon)
|
7
|
+
return content_tag(:span, ' ', class: "glyphicon glyphicon-#{icon}", 'aria-hidden': 'true')
|
8
|
+
end
|
9
|
+
|
10
|
+
# @param [Boolean] condition condition of evaluate
|
11
|
+
# @param [String] icon_true the glyphicon to use if true
|
12
|
+
# @param [String] icon_false the glyphicon to use if false
|
13
|
+
def glyphicon_if_else(condition, icon_true, icon_false)
|
14
|
+
return condition ? glyphicon(icon_true) : glyphicon(icon_false)
|
15
|
+
end
|
16
|
+
|
17
|
+
# @param [Hash, String] url_options anything accepted by link_to and image_tag
|
18
|
+
# @param [Integer] max_height maximum height of the thumbnail
|
19
|
+
def thumbnail_link(url_options, max_height)
|
20
|
+
return link_to(image_tag(url_options), url_options, class: 'thumbnail', style: "max-height: #{max_height}px", target: 'new')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
module Kadmin
|
2
|
-
class FormBuilder < ActionView::Helpers::FormBuilder
|
3
|
-
# Creates a checkbox where the value is 0 when checked, 1 when unchecked.
|
4
|
-
# @see Kadmin::Forms::InvertedCheckBox
|
5
|
-
def inverted_check_box(method, options = {})
|
6
|
-
Kadmin::Forms::InvertedCheckBox.new(@object_name, method, @template, '0', '1', objectify_options(options)).render
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
1
|
+
module Kadmin
|
2
|
+
class FormBuilder < ActionView::Helpers::FormBuilder
|
3
|
+
# Creates a checkbox where the value is 0 when checked, 1 when unchecked.
|
4
|
+
# @see Kadmin::Forms::InvertedCheckBox
|
5
|
+
def inverted_check_box(method, options = {})
|
6
|
+
Kadmin::Forms::InvertedCheckBox.new(@object_name, method, @template, '0', '1', objectify_options(options)).render
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
module Kadmin
|
2
|
-
module Forms
|
3
|
-
class InvertedCheckBox < ActionView::Helpers::Tags::CheckBox
|
4
|
-
# Overload how it gets the value and return the invert
|
5
|
-
def value(*args)
|
6
|
-
return !super
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
1
|
+
module Kadmin
|
2
|
+
module Forms
|
3
|
+
class InvertedCheckBox < ActionView::Helpers::Tags::CheckBox
|
4
|
+
# Overload how it gets the value and return the invert
|
5
|
+
def value(*args)
|
6
|
+
return !super
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -1,28 +1,28 @@
|
|
1
|
-
module Kadmin
|
2
|
-
module NavigationHelper
|
3
|
-
# Generates HTML for a bootstrap navigation link
|
4
|
-
# @param [String] title the navigation text
|
5
|
-
# @param [Hash, String] path the path for the link
|
6
|
-
# @param [Proc] block optional block to include content within the link
|
7
|
-
def nav_link_to(title, path, &block)
|
8
|
-
css_classes = []
|
9
|
-
css_classes << 'active' if request.path.starts_with?(path)
|
10
|
-
return content_tag(:li, link_to(title, path, &block), class: css_classes.join(' '))
|
11
|
-
end
|
12
|
-
|
13
|
-
# Generates a navigation drop down for bootstrap
|
14
|
-
# @param [String] prompt dropdown prompt
|
15
|
-
# @param [Array<Hash,String>] links list of links to add within the dropdown
|
16
|
-
def dropdown(prompt, links = [])
|
17
|
-
button_content = content_tag(:span, '', class: 'caret').prepend(prompt)
|
18
|
-
button = button_tag(button_content, type: 'button', data: { toggle: 'dropdown' }, class: 'btn btn-
|
19
|
-
list = content_tag(:ul, '', class: 'dropdown-menu') do
|
20
|
-
links.reduce(ActiveSupport::SafeBuffer.new) do |buffer, link|
|
21
|
-
buffer + content_tag(:li, link)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
return content_tag(:div, button + list, class: 'dropdown', style: 'display: inline-block;')
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
1
|
+
module Kadmin
|
2
|
+
module NavigationHelper
|
3
|
+
# Generates HTML for a bootstrap navigation link
|
4
|
+
# @param [String] title the navigation text
|
5
|
+
# @param [Hash, String] path the path for the link
|
6
|
+
# @param [Proc] block optional block to include content within the link
|
7
|
+
def nav_link_to(title, path, &block)
|
8
|
+
css_classes = []
|
9
|
+
css_classes << 'active' if request.path.starts_with?(path)
|
10
|
+
return content_tag(:li, link_to(title, path, &block), class: css_classes.join(' '))
|
11
|
+
end
|
12
|
+
|
13
|
+
# Generates a navigation drop down for bootstrap
|
14
|
+
# @param [String] prompt dropdown prompt
|
15
|
+
# @param [Array<Hash,String>] links list of links to add within the dropdown
|
16
|
+
def dropdown(prompt, links = [])
|
17
|
+
button_content = content_tag(:span, '', class: 'caret').prepend(prompt)
|
18
|
+
button = button_tag(button_content, type: 'button', data: { toggle: 'dropdown' }, class: 'btn btn-sm')
|
19
|
+
list = content_tag(:ul, '', class: 'dropdown-menu') do
|
20
|
+
links.reduce(ActiveSupport::SafeBuffer.new) do |buffer, link|
|
21
|
+
buffer + content_tag(:li, link)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
return content_tag(:div, button + list, class: 'dropdown', style: 'display: inline-block;')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|