matestack-ui-bootstrap 1.4.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +17 -5
  3. data/README.md +53 -19
  4. data/lib/matestack/ui/bootstrap.rb +97 -17
  5. data/{app/concepts → lib}/matestack/ui/bootstrap/apps/admin_template.rb +14 -7
  6. data/lib/matestack/ui/bootstrap/base_component.rb +13 -0
  7. data/lib/matestack/ui/bootstrap/base_vue_js_component.rb +13 -0
  8. data/lib/matestack/ui/bootstrap/components/accordion.rb +58 -0
  9. data/{app/concepts → lib}/matestack/ui/bootstrap/components/alert.js +12 -9
  10. data/lib/matestack/ui/bootstrap/components/alert.rb +43 -0
  11. data/lib/matestack/ui/bootstrap/components/avatar.rb +27 -0
  12. data/lib/matestack/ui/bootstrap/components/badge.rb +32 -0
  13. data/lib/matestack/ui/bootstrap/components/breadcrumb.rb +50 -0
  14. data/lib/matestack/ui/bootstrap/components/button.rb +71 -0
  15. data/lib/matestack/ui/bootstrap/components/button_group.rb +36 -0
  16. data/lib/matestack/ui/bootstrap/components/card.rb +105 -0
  17. data/{app/concepts → lib}/matestack/ui/bootstrap/components/carousel.js +21 -18
  18. data/lib/matestack/ui/bootstrap/components/carousel.rb +103 -0
  19. data/{app/concepts → lib}/matestack/ui/bootstrap/components/close.rb +10 -9
  20. data/{app/concepts → lib}/matestack/ui/bootstrap/components/collapse.js +20 -17
  21. data/lib/matestack/ui/bootstrap/components/collapse.rb +54 -0
  22. data/{app/concepts → lib}/matestack/ui/bootstrap/components/dropdown.js +5 -2
  23. data/{app/concepts → lib}/matestack/ui/bootstrap/components/dropdown.rb +31 -26
  24. data/lib/matestack/ui/bootstrap/components/icon.rb +21 -0
  25. data/lib/matestack/ui/bootstrap/components/list_group.rb +148 -0
  26. data/{app/concepts → lib}/matestack/ui/bootstrap/components/modal.js +24 -21
  27. data/lib/matestack/ui/bootstrap/components/modal.rb +121 -0
  28. data/lib/matestack/ui/bootstrap/components/navbar.rb +163 -0
  29. data/{app/concepts → lib}/matestack/ui/bootstrap/components/page_heading.rb +7 -5
  30. data/{app/concepts → lib}/matestack/ui/bootstrap/components/pagination.rb +15 -13
  31. data/{app/concepts → lib}/matestack/ui/bootstrap/components/popover.js +4 -1
  32. data/{app/concepts → lib}/matestack/ui/bootstrap/components/popover.rb +26 -22
  33. data/{app/concepts → lib}/matestack/ui/bootstrap/components/progress.rb +24 -24
  34. data/lib/matestack/ui/bootstrap/components/scrollspy.rb +50 -0
  35. data/lib/matestack/ui/bootstrap/components/section_card.rb +33 -0
  36. data/lib/matestack/ui/bootstrap/components/spinner.rb +35 -0
  37. data/lib/matestack/ui/bootstrap/components/tab_nav.rb +79 -0
  38. data/lib/matestack/ui/bootstrap/components/tab_nav_content.rb +35 -0
  39. data/{app/concepts → lib}/matestack/ui/bootstrap/components/toast.js +27 -18
  40. data/lib/matestack/ui/bootstrap/components/toast.rb +113 -0
  41. data/{app/concepts → lib}/matestack/ui/bootstrap/components/tooltip.js +4 -1
  42. data/lib/matestack/ui/bootstrap/components/tooltip.rb +66 -0
  43. data/{app/concepts → lib}/matestack/ui/bootstrap/content/figure.rb +4 -2
  44. data/lib/matestack/ui/bootstrap/content/smart_collection/collection.rb +120 -0
  45. data/{app/concepts/matestack/ui/bootstrap/content/collection → lib/matestack/ui/bootstrap/content/smart_collection}/collection.scss +0 -0
  46. data/lib/matestack/ui/bootstrap/content/smart_collection/content.rb +118 -0
  47. data/{app/concepts/matestack/ui/bootstrap/content/collection → lib/matestack/ui/bootstrap/content/smart_collection}/filter.rb +7 -3
  48. data/{app/concepts/matestack/ui/bootstrap/content/collection → lib/matestack/ui/bootstrap/content/smart_collection}/paginate.rb +19 -14
  49. data/lib/matestack/ui/bootstrap/form/checkbox.rb +90 -0
  50. data/lib/matestack/ui/bootstrap/form/input.rb +118 -0
  51. data/lib/matestack/ui/bootstrap/form/radio.rb +57 -0
  52. data/lib/matestack/ui/bootstrap/form/select.rb +63 -0
  53. data/lib/matestack/ui/bootstrap/form/submit.rb +20 -0
  54. data/lib/matestack/ui/bootstrap/form/switch.rb +32 -0
  55. data/lib/matestack/ui/bootstrap/form/textarea.rb +49 -0
  56. data/lib/matestack/ui/bootstrap/index.js +24 -0
  57. data/lib/matestack/ui/bootstrap/layout/column.rb +49 -0
  58. data/{app/concepts → lib}/matestack/ui/bootstrap/layout/container.rb +12 -9
  59. data/lib/matestack/ui/bootstrap/layout/row.rb +25 -0
  60. data/{app/concepts → lib}/matestack/ui/bootstrap/layout/sidebar.js +5 -2
  61. data/{app/concepts → lib}/matestack/ui/bootstrap/layout/sidebar.rb +10 -10
  62. data/{app/concepts → lib}/matestack/ui/bootstrap/layout/sidebar.scss +0 -0
  63. data/lib/matestack/ui/bootstrap/registry.rb +173 -0
  64. data/{app/javascript/matestack-ui-bootstrap → lib/matestack/ui/bootstrap}/stylesheets/matestack-ui-bootstrap.scss +0 -0
  65. data/lib/matestack/ui/bootstrap/version.rb +1 -1
  66. data/lib/tasks/matestack/ui/bootstrap_tasks.rake +25 -25
  67. metadata +68 -76
  68. data/app/assets/images/avatar-placeholder.png +0 -0
  69. data/app/assets/images/icons/bootstrap-icons.svg +0 -1
  70. data/app/concepts/matestack/ui/bootstrap/components/accordion.rb +0 -53
  71. data/app/concepts/matestack/ui/bootstrap/components/alert.rb +0 -34
  72. data/app/concepts/matestack/ui/bootstrap/components/avatar.rb +0 -27
  73. data/app/concepts/matestack/ui/bootstrap/components/badge.rb +0 -30
  74. data/app/concepts/matestack/ui/bootstrap/components/breadcrumb.rb +0 -46
  75. data/app/concepts/matestack/ui/bootstrap/components/button.rb +0 -54
  76. data/app/concepts/matestack/ui/bootstrap/components/button_group.rb +0 -36
  77. data/app/concepts/matestack/ui/bootstrap/components/card.rb +0 -100
  78. data/app/concepts/matestack/ui/bootstrap/components/carousel.rb +0 -85
  79. data/app/concepts/matestack/ui/bootstrap/components/chart.js +0 -232
  80. data/app/concepts/matestack/ui/bootstrap/components/chart.rb +0 -71
  81. data/app/concepts/matestack/ui/bootstrap/components/collapse.rb +0 -43
  82. data/app/concepts/matestack/ui/bootstrap/components/icon.rb +0 -19
  83. data/app/concepts/matestack/ui/bootstrap/components/list_group.rb +0 -83
  84. data/app/concepts/matestack/ui/bootstrap/components/modal.rb +0 -106
  85. data/app/concepts/matestack/ui/bootstrap/components/navbar.rb +0 -120
  86. data/app/concepts/matestack/ui/bootstrap/components/scrollspy.rb +0 -33
  87. data/app/concepts/matestack/ui/bootstrap/components/section_card.rb +0 -31
  88. data/app/concepts/matestack/ui/bootstrap/components/spinner.rb +0 -31
  89. data/app/concepts/matestack/ui/bootstrap/components/tab_nav.rb +0 -81
  90. data/app/concepts/matestack/ui/bootstrap/components/tab_nav_content.rb +0 -32
  91. data/app/concepts/matestack/ui/bootstrap/components/toast.rb +0 -99
  92. data/app/concepts/matestack/ui/bootstrap/components/tooltip.rb +0 -82
  93. data/app/concepts/matestack/ui/bootstrap/content/collection/collection.rb +0 -112
  94. data/app/concepts/matestack/ui/bootstrap/content/collection/content.rb +0 -101
  95. data/app/concepts/matestack/ui/bootstrap/form/checkbox.rb +0 -90
  96. data/app/concepts/matestack/ui/bootstrap/form/date.js +0 -38
  97. data/app/concepts/matestack/ui/bootstrap/form/date.rb +0 -98
  98. data/app/concepts/matestack/ui/bootstrap/form/input.rb +0 -123
  99. data/app/concepts/matestack/ui/bootstrap/form/radio.rb +0 -65
  100. data/app/concepts/matestack/ui/bootstrap/form/select.haml +0 -11
  101. data/app/concepts/matestack/ui/bootstrap/form/select.rb +0 -74
  102. data/app/concepts/matestack/ui/bootstrap/form/submit.rb +0 -20
  103. data/app/concepts/matestack/ui/bootstrap/form/switch.rb +0 -90
  104. data/app/concepts/matestack/ui/bootstrap/layout/column.rb +0 -47
  105. data/app/concepts/matestack/ui/bootstrap/layout/row.rb +0 -15
  106. data/app/concepts/matestack/ui/bootstrap/pages/devise/sign_in.rb +0 -40
  107. data/app/concepts/matestack/ui/bootstrap/registry.rb +0 -63
  108. data/app/helpers/matestack/ui/bootstrap/application_helper.rb +0 -13
  109. data/app/javascript/matestack-ui-bootstrap/index.js +0 -26
  110. data/app/javascript/packs/matestack-ui-bootstrap.js +0 -2
  111. data/config/routes.rb +0 -2
  112. data/lib/matestack/ui/bootstrap/engine.rb +0 -26
@@ -1,33 +0,0 @@
1
- class Matestack::Ui::Bootstrap::Components::Scrollspy < Matestack::Ui::Component
2
-
3
- optional :offset # pixel to offset from top, by default 10
4
- optional method: { as: :bs_method} # find which section, by default auto
5
- optional :target # scroll target id
6
- optional class: { as: :bs_class} # adding custom class to scrollspy
7
-
8
- def response
9
- div scrollspy_attributes do
10
- yield_components
11
- end
12
- end
13
-
14
- protected
15
-
16
- def scrollspy_attributes
17
- attributes = {}.tap do |hash|
18
- hash[:class] = scrollspy_classes
19
- hash[:data] = { "bs-spy": "scroll", "bs-target": "#{target}" }
20
- hash[:data].merge!("bs-offset": offset) if offset.present?
21
- hash[:data].merge!("bs-method": :"#{bs_method}") if bs_method.present?
22
- end
23
- html_attributes.merge(
24
- attributes
25
- )
26
- end
27
-
28
- def scrollspy_classes
29
- [].tap do |classes|
30
- classes << bs_class
31
- end.join(' ').strip
32
- end
33
- end
@@ -1,31 +0,0 @@
1
- class Matestack::Ui::Bootstrap::Components::SectionCard < Matestack::Ui::Component
2
-
3
- optional :id, :title, :subtitle, :icon, :slots, :content_padding
4
-
5
- def response
6
- section id: :id, class: "section-card rounded shadow-sm mb-4 bg-white" do
7
- div class: "d-flex flex-row justify-content-between" do
8
- if title.present? || subtitle.present?
9
- div class: "section-card-heading p-4" do
10
- heading size: 5, class: "mb-0" do
11
- bs_icon name: icon, size: "35" if icon.present?
12
- plain title
13
- end
14
- small class: "text-muted" do
15
- plain subtitle
16
- end
17
- end
18
- end
19
- if slots.present? && slots[:actions].present?
20
- div class: "section-card-actions p-4" do
21
- slot slots[:actions]
22
- end
23
- end
24
- end
25
- div class: "section-card-content #{'p-4' unless content_padding == false} #{'pt-1' if title || subtitle}" do
26
- yield_components
27
- end
28
- end
29
- end
30
-
31
- end
@@ -1,31 +0,0 @@
1
- class Matestack::Ui::Bootstrap::Components::Spinner < Matestack::Ui::Component
2
-
3
- optional class: { as: :bs_class }
4
- optional :kind, :variant, :size, :sr_only
5
-
6
- def response
7
- div spinner_attributes do
8
- span class: "sr-only", text: sr_only
9
- end
10
- end
11
-
12
- protected
13
-
14
- def spinner_attributes
15
- html_attributes.merge(
16
- class: spinner_class,
17
- attributes: { 'role': "status" }
18
- )
19
- end
20
-
21
- def spinner_class
22
- [].tap do |classes|
23
- spinner_kind = kind || :border
24
- classes << "spinner-#{spinner_kind}"
25
- classes << "text-#{variant || 'primary'}"
26
- classes << "spinner-#{spinner_kind}-sm" if size
27
- #optional classes
28
- classes << bs_class
29
- end.join(' ').strip
30
- end
31
- end
@@ -1,81 +0,0 @@
1
- class Matestack::Ui::Bootstrap::Components::TabNav < Matestack::Ui::Component
2
-
3
- requires :id
4
-
5
- optional :items, :variant, :fill, :justified, :vertical, :vertical_up_to_sm,
6
- :vertical_up_to_md, :vertical_up_to_xl, :horizontal,
7
- class: { as: :bs_class }, attributes: { as: :bs_attrs}
8
-
9
- def response
10
- ul nav_attributes do
11
- nav_items_partial if items.present?
12
- end
13
- div class: "tab-content", id: "#{id}Content" do
14
- yield_components
15
- end
16
- end
17
-
18
- protected
19
-
20
- def nav_items_partial
21
- items.each do |item|
22
- li class: "nav-item", attributes: { role: "presentation" } do
23
- # '<a class="nav-link active" id="pills-home-tab" data-toggle="pill" href="#pills-home" role="tab" aria-controls="pills-home" aria-selected="true">Home</a>'
24
- link class: "nav-link #{'active' if item[:active]}",
25
- id: "tab-#{item[:id]}",
26
- path: "#tab-#{item[:id]}-content",
27
- attributes: {
28
- role: "tab",
29
- "aria-controls": "tab-#{item[:id]}",
30
- "aria-selected": "#{'true' if item[:active]}",
31
- "data-bs-toggle": "tab"
32
- } do
33
- bs_icon name: item[:icon], size: 20 if item[:icon]
34
- span class: "#{'ps-3' if item[:icon]}", text: item[:text] if item[:text]
35
- end
36
- end
37
- end
38
- end
39
-
40
- def link_attrs path, active, disabled, delay=nil
41
- {}.tap do |hash|
42
- hash[:class] = "nav-link #{'active' if path == request.fullpath } #{'disabled' if disabled}"
43
-
44
- hash[:attributes] = {}.tap do |hash|
45
- hash[:'aria-selected'] = path == request.fullpath ? 'true' : 'false'
46
- hash[:'aria-current'] = 'page' if active == true
47
- hash[:'aria-disabled'] = 'true' if disabled
48
- hash[:role] = "tab" if toggle.present?
49
- hash[:'aria-controls'] = "#{path.gsub('#','')}" if toggle.present?
50
- end
51
-
52
- hash[:data] = { "bs-toggle": "pill" } if pills
53
- hash[:data] = { "bs-toggle": "tab" } if tabs
54
- hash[:path] = path
55
- end
56
- end
57
-
58
- def nav_attributes
59
- html_attributes.merge(
60
- id: id,
61
- class: nav_classes,
62
- attributes: { role: "tablist"}
63
- )
64
- end
65
-
66
- def nav_classes
67
- [].tap do |classes|
68
- classes << 'nav'
69
- classes << 'nav-tabs' if variant == :tabs || variant.nil?
70
- classes << 'nav-pills' if variant == :pills
71
- classes << 'nav-fill' if fill
72
- classes << 'nav-justified' if justified
73
- classes << 'flex-column' if vertical
74
- classes << 'flex-column flex-sm-column flex-md-row' if vertical_up_to_sm
75
- classes << 'flex-column flex-sm-column flex-md-column flex-lg-row' if vertical_up_to_md
76
- classes << 'flex-column flex-sm-column flex-md-column flex-lg-column flex-xl-row' if vertical_up_to_xl
77
- classes << "justify-content-#{horizontal}" if horizontal.present?
78
- classes << bs_class
79
- end.join(' ').strip
80
- end
81
- end
@@ -1,32 +0,0 @@
1
- class Matestack::Ui::Bootstrap::Components::TabNavContent < Matestack::Ui::Component
2
-
3
- requires :id
4
-
5
- optional :tabs, :pills, :active, class: { as: :bs_class }, attributes: { as: :bs_attrs}
6
-
7
- def response
8
- div tab_content_attributes do
9
- yield_components
10
- end
11
- end
12
-
13
- protected
14
-
15
- def tab_content_attributes
16
- html_attributes.merge(
17
- id: "tab-#{id}-content",
18
- class: tab_content_classes,
19
- attributes: { role: "tabpanel", "aria-labelledby": "tab-#{id}" }
20
- )
21
- end
22
-
23
- def tab_content_classes
24
- [].tap do |classes|
25
- classes << 'tab-pane'
26
- classes << 'fade'
27
- classes << 'show ' if active
28
- classes << 'active' if active
29
- classes << bs_class
30
- end.join(' ').strip
31
- end
32
- end
@@ -1,99 +0,0 @@
1
- class Matestack::Ui::Bootstrap::Components::Toast < Matestack::Ui::VueJsComponent
2
- vue_js_component_name "matestack-ui-bootstrap-toast"
3
-
4
- # header attributes, expects a hash or string
5
- # possible keys `:icon_class, :icon, :title, :subtitle`
6
- optional :header
7
- # body expects a string as message inside toast
8
- optional :body
9
- # placement attributes, expects a hash wiht possible keys: position, min-height
10
- optional :placement # for adding custom css style
11
- optional :important, :delay, :autohide, :animation
12
- optional class: { as: :bs_class }, attributes: { as: :bs_attrs }, data: { as: :bs_data }
13
- optional :slots
14
-
15
- def response
16
- standard_placement_partial
17
- # standard_placement_partial unless placement.present?
18
- # custom_placement_partial if placement.present?
19
- end
20
-
21
- protected
22
-
23
- def custom_placement_partial
24
- div attributes: placement_attrs do
25
- standard_placement_partial
26
- end
27
- end
28
-
29
- def standard_placement_partial
30
- div toast_attributes do
31
- header_partial if header || slots && slots[:header]
32
- body_partial
33
- end
34
- end
35
-
36
- def header_partial
37
- header = self.header.is_a?(Hash) ? self.header : { title: self.header }
38
- div class: "toast-header" do
39
- img class: "#{'rounded me-2' || header[:icon_class]}", path: header[:icon] if header[:icon].present?
40
- strong class: "me-auto", text: header[:title] if header[:title].present?
41
- small text: header[:subtitle] if header[:subtitle].present?
42
-
43
- slot slots[:header] if slots && slots[:header]
44
- bs_close dismiss: 'toast', class: "ms-2 mb-1", attributes: { "@click": "hide()"}
45
- end
46
-
47
- end
48
-
49
- def body_partial
50
- div class: "toast-body" do
51
- plain body if body
52
- end
53
- unless header || slots && slots[:header]
54
- bs_close dismiss: 'toast', class: "ms-auto me-2 btn-close-white", attributes: { "@click": "hide()"}
55
- end
56
- end
57
-
58
- def toast_attributes
59
- html_attributes.merge(
60
- class: toast_classes,
61
- attributes: toast_attrs,
62
- data: toast_data
63
- )
64
- end
65
-
66
- def toast_data
67
- (bs_data || {}).tap do |hash|
68
- hash["bs-delay"] = delay.nil? ? 5000 : delay
69
- hash["bs-autohide"] = autohide.nil? ? "true" : "#{autohide}"
70
- hash["bs-animation"] = animation.nil? ? "true" : "#{animation}"
71
- end
72
- end
73
-
74
- def toast_attrs
75
- (bs_attrs || {}).tap do |hash|
76
- hash[:role] = (important == false ? 'status' : 'alert')
77
- hash[:'aria-live'] = (important ? 'assertive' : 'polite') if important.present? && !placement.present?
78
- hash[:'aria-live'] = 'assertive' unless important.present?
79
- hash[:'aria-atomic'] = 'true' unless placement.present?
80
- hash[:style] = "z-index: 10000; position: fixed; #{placement[:position] || 'top: 0; right: 0;' }" if placement.present?
81
- hash["v-bind:class"] = "{'show' : showing }"
82
- end
83
- end
84
-
85
- def toast_classes
86
- [].tap do |classes|
87
- classes << 'toast p-0 fade d-flex align-items-center border-0'
88
- classes << bs_class
89
- end.join(' ').strip
90
- end
91
-
92
- def placement_attrs
93
- {}.tap do |hash|
94
- hash[:'aria-live'] = (important ? 'assertive' : 'polite') if important.present?
95
- hash[:'aria-atomic'] = 'true'
96
- hash[:style] = "position: relative; min-height: #{placement[:height]};"
97
- end
98
- end
99
- end
@@ -1,82 +0,0 @@
1
- class Matestack::Ui::Bootstrap::Components::Tooltip < Matestack::Ui::VueJsComponent
2
- vue_js_component_name "matestack-ui-bootstrap-tooltip"
3
-
4
- DATA_ALIAS_ATTRIBUTES = %i[container delay selector html template fallback_placement]
5
-
6
- DATA_ALIAS_ATTRIBUTES.each do |attribute|
7
- optional "#{attribute}": { as: :"bs_#{attribute}"}
8
- end
9
-
10
- # TODO:
11
- # for security reasons the sanitize, sanitizeFn and whiteList options cannot be supplied using data attributes.
12
- # sanitize sanitize_fn white_list
13
- # optional :content
14
- optional :tag
15
- optional class: { as: :bs_class }
16
- optional id: { as: :bs_id }
17
- DATA_ATTRIBUTES = %i[title text variant animation placement tabindex trigger boundary offset popper_config]
18
- optional *DATA_ATTRIBUTES
19
-
20
- def response
21
- case tag
22
- when :div
23
- div tooltip_attributes do
24
- element_partial
25
- end
26
- when :span
27
- span tooltip_attributes do
28
- element_partial
29
- end
30
- when :link
31
- link tooltip_attributes
32
- else
33
- bs_btn tooltip_attributes
34
- end
35
- end
36
-
37
- protected
38
-
39
- def element_partial
40
- if options[:slots] && options[:slots][:element]
41
- slot options[:slots][:element]
42
- else
43
- bs_btn variant: variant, attributes: { 'style': "pointer-events: none;" }, text: text
44
- end
45
- end
46
-
47
- def tooltip_attributes
48
- attributes = {}.tap do |hash|
49
- hash[:class] = tooltip_classes
50
- hash[:style] = variant if (tag == :button or !tag.present?)
51
-
52
- hash[:attributes] = { role: "button", title: "#{title}", tabindex: "#{tabindex}" } if (tag == :link or tag == :a)
53
-
54
- hash[:text] = text if text.present?
55
-
56
- hash[:data] = {}.tap do |hash|
57
- DATA_ALIAS_ATTRIBUTES.each do |attribute|
58
- hash["bs-#{attribute}"] = self.send(:"bs_#{attribute}") if self.send(:"bs_#{attribute}")
59
- end
60
- DATA_ATTRIBUTES.each do |attribute|
61
- hash["bs-#{attribute}"] = self.send(:"#{attribute}") if self.send(:"#{attribute}")
62
- end
63
- hash["bs-toggle"] = "tooltip"
64
- hash["bs-type"] = tag
65
- # hash[:'original-title'] = content
66
- end
67
- end
68
- html_attributes.merge(
69
- attributes
70
- )
71
- end
72
-
73
- def tooltip_classes
74
- [].tap do |classes|
75
- classes << "d-inline-block" if (tag == :span or tag == :div)
76
- classes << "btn btn-#{variant || 'link'}" if (tag == :link or !tag.present?)
77
-
78
- classes << bs_class
79
- end.join(' ').strip
80
- end
81
-
82
- end
@@ -1,112 +0,0 @@
1
- class Matestack::Ui::Bootstrap::Content::Collection::Collection < Matestack::Ui::Component
2
- include Matestack::Ui::Core::Collection::Helper
3
- include Matestack::Ui::Bootstrap::Content::Collection::Content
4
- include Matestack::Ui::Bootstrap::Content::Collection::Filter
5
- include Matestack::Ui::Bootstrap::Content::Collection::Paginate
6
-
7
- # html attributes
8
- optional id: { as: :bs_id }
9
-
10
- # table configuration
11
- optional :items
12
- optional :columns
13
- optional :filters
14
- optional :footer
15
- optional :paginate
16
- optional :rerender_on
17
- optional :item_actions_proc
18
- optional :collection_rendering_proc
19
- optional :slots
20
-
21
- # bootstrap settings
22
- optional :responsive
23
- optional :variant
24
- optional :striped
25
- optional :hoverable
26
- optional :border_variant
27
- optional :borderless
28
-
29
- attr_accessor :processed_filters
30
-
31
- def response
32
- div class: "smart-collection" do
33
- filter_partial
34
- content
35
- end
36
- end
37
-
38
-
39
- private
40
-
41
- def collection
42
- return @collection if @collection
43
- settings = {}.tap do |h|
44
- h[:id] = bs_id || "smartcollection"
45
- h[:data] = filtered_query
46
- h[:base_count] = items.count
47
- h[:init_limit] = paginate if paginate
48
- h[:filtered_count] = filtered_query.count if paginate
49
- end
50
- @collection = set_collection(settings)
51
- end
52
-
53
- def collection_id
54
- collection.config[:id]
55
- end
56
-
57
- def filtered_query
58
- return @filtered_query if @filtered_query
59
- @filtered_query = items
60
- filters.select { |key, value| '.'.in? key.to_s }.each do |key, value|
61
- associated_name = key.to_s.split(".").first
62
- @filtered_query = @filtered_query.joins(associated_name.to_sym).all
63
- if value.is_a?(Hash)
64
- processed_filters[key] = value
65
- @filtered_query = add_query_filter(@filtered_query, associated_name, key, value)
66
- end
67
- end
68
- filters.reject { |key, value| '.'.in? key.to_s }.each do |key, value|
69
- if value.is_a?(Hash)
70
- processed_filters[key] = value
71
- @filtered_query = add_query_filter(@filtered_query, nil, key, value)
72
- end
73
- end
74
- @filtered_query
75
- end
76
-
77
- def add_query_filter(query, associated_name, key, filter_config)
78
- value = get_collection_filter(collection_id)[key.to_sym]
79
- if value.present?
80
- if associated_name.present?
81
- table_name = items.klass.reflections[associated_name].table_name
82
- key = key.to_s.gsub(associated_name, table_name)
83
- else
84
- table_name = items.klass.table_name
85
- key = key.to_s
86
- end
87
- case filter_config[:match]
88
- when :equals
89
- query = query.where("#{key}": value)
90
- when :starts_with
91
- query = query.where("lower(#{key}) LIKE ?", "#{value.downcase}%")
92
- when :ends_with
93
- query = query.where("lower(#{key}) LIKE ?", "%#{value.downcase}")
94
- when :like
95
- query = query.where("lower(#{key}) LIKE ?", "%#{value.downcase}%")
96
- else
97
- query = query.where("#{key}": value)
98
- end
99
- end
100
- query
101
- end
102
-
103
- def head_columns
104
- columns.map { |key, value| value.is_a?(Hash) ? value[:heading] : value }
105
- end
106
-
107
- def processed_filters
108
- @filters ||= {}
109
- end
110
-
111
-
112
- end