katalyst-tables 3.0.0.beta1 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -2
  3. data/README.md +65 -187
  4. data/app/assets/builds/katalyst/tables.esm.js +17 -47
  5. data/app/assets/builds/katalyst/tables.js +17 -47
  6. data/app/assets/builds/katalyst/tables.min.js +1 -1
  7. data/app/assets/builds/katalyst/tables.min.js.map +1 -1
  8. data/app/assets/stylesheets/katalyst/tables/_index.scss +1 -0
  9. data/app/assets/stylesheets/katalyst/tables/_summary.scss +14 -0
  10. data/app/assets/stylesheets/katalyst/tables/typed-columns/_boolean.scss +1 -1
  11. data/app/assets/stylesheets/katalyst/tables/typed-columns/_currency.scss +3 -0
  12. data/app/assets/stylesheets/katalyst/tables/typed-columns/_date.scss +1 -1
  13. data/app/assets/stylesheets/katalyst/tables/typed-columns/_datetime.scss +1 -1
  14. data/app/assets/stylesheets/katalyst/tables/typed-columns/_number.scss +3 -0
  15. data/app/components/concerns/katalyst/tables/has_table_content.rb +19 -10
  16. data/app/components/concerns/katalyst/tables/identifiable.rb +51 -0
  17. data/app/components/concerns/katalyst/tables/orderable.rb +35 -105
  18. data/app/components/concerns/katalyst/tables/row_renderer.rb +1 -1
  19. data/app/components/concerns/katalyst/tables/selectable.rb +18 -75
  20. data/app/components/concerns/katalyst/tables/sortable.rb +51 -17
  21. data/app/components/katalyst/summary_table_component.html.erb +15 -0
  22. data/app/components/katalyst/summary_table_component.rb +44 -0
  23. data/app/components/katalyst/table_component.html.erb +4 -4
  24. data/app/components/katalyst/table_component.rb +271 -53
  25. data/app/components/katalyst/tables/body_row_component.html.erb +5 -0
  26. data/app/components/katalyst/tables/body_row_component.rb +4 -31
  27. data/app/components/katalyst/tables/cell_component.rb +85 -0
  28. data/app/components/katalyst/tables/{body → cells}/boolean_component.rb +8 -2
  29. data/app/components/katalyst/tables/{body → cells}/currency_component.rb +7 -7
  30. data/app/components/katalyst/tables/{body → cells}/date_component.rb +12 -9
  31. data/app/components/katalyst/tables/{body → cells}/date_time_component.rb +13 -10
  32. data/app/components/katalyst/tables/{body → cells}/number_component.rb +5 -5
  33. data/app/components/katalyst/tables/cells/ordinal_component.rb +44 -0
  34. data/app/components/katalyst/tables/{body → cells}/rich_text_component.rb +8 -5
  35. data/app/components/katalyst/tables/cells/select_component.rb +39 -0
  36. data/app/components/katalyst/tables/data.rb +30 -0
  37. data/app/components/katalyst/tables/header_row_component.html.erb +5 -0
  38. data/app/components/katalyst/tables/header_row_component.rb +4 -25
  39. data/app/components/katalyst/tables/label.rb +37 -0
  40. data/app/components/katalyst/tables/orderable/form_component.rb +38 -0
  41. data/app/components/katalyst/tables/selectable/form_component.html.erb +3 -3
  42. data/app/components/katalyst/tables/selectable/form_component.rb +8 -11
  43. data/app/components/katalyst/tables/summary/body_component.html.erb +3 -0
  44. data/app/components/katalyst/tables/summary/body_component.rb +10 -0
  45. data/app/components/katalyst/tables/summary/header_component.html.erb +3 -0
  46. data/app/components/katalyst/tables/summary/header_component.rb +10 -0
  47. data/app/components/katalyst/tables/summary/row_component.html.erb +4 -0
  48. data/app/components/katalyst/tables/summary/row_component.rb +12 -0
  49. data/app/controllers/concerns/katalyst/tables/backend.rb +17 -28
  50. data/app/helpers/katalyst/tables/frontend.rb +67 -2
  51. data/app/javascript/tables/application.js +0 -5
  52. data/app/javascript/tables/orderable/form_controller.js +8 -6
  53. data/app/javascript/tables/orderable/item_controller.js +9 -0
  54. data/app/models/concerns/katalyst/tables/collection/core.rb +6 -1
  55. data/app/models/concerns/katalyst/tables/collection/pagination.rb +2 -2
  56. data/app/models/concerns/katalyst/tables/collection/sorting.rb +86 -18
  57. data/app/models/katalyst/tables/collection/array.rb +38 -0
  58. data/app/models/katalyst/tables/collection/base.rb +4 -0
  59. data/app/models/katalyst/tables/collection/filter.rb +2 -2
  60. data/config/importmap.rb +1 -0
  61. data/config/locales/tables.en.yml +0 -6
  62. data/lib/katalyst/tables/config.rb +23 -0
  63. data/lib/katalyst/tables.rb +9 -0
  64. metadata +32 -30
  65. data/app/components/concerns/katalyst/tables/body/typed_columns.rb +0 -132
  66. data/app/components/concerns/katalyst/tables/configurable_component.rb +0 -52
  67. data/app/components/concerns/katalyst/tables/header/typed_columns.rb +0 -179
  68. data/app/components/katalyst/tables/body/attachment_component.rb +0 -58
  69. data/app/components/katalyst/tables/body/link_component.rb +0 -40
  70. data/app/components/katalyst/tables/body_cell_component.rb +0 -55
  71. data/app/components/katalyst/tables/header/attachment_component.rb +0 -15
  72. data/app/components/katalyst/tables/header/boolean_component.rb +0 -15
  73. data/app/components/katalyst/tables/header/currency_component.rb +0 -15
  74. data/app/components/katalyst/tables/header/date_component.rb +0 -15
  75. data/app/components/katalyst/tables/header/date_time_component.rb +0 -15
  76. data/app/components/katalyst/tables/header/link_component.rb +0 -15
  77. data/app/components/katalyst/tables/header/number_component.rb +0 -15
  78. data/app/components/katalyst/tables/header/rich_text_component.rb +0 -15
  79. data/app/components/katalyst/tables/header_cell_component.rb +0 -97
  80. data/app/helpers/katalyst/tables/frontend/helper.rb +0 -31
  81. data/app/javascript/tables/turbo/collection_controller.js +0 -38
  82. data/app/models/katalyst/tables/collection/sort_form.rb +0 -120
@@ -1,120 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Katalyst
4
- module Tables
5
- module Collection
6
- # A FormObject (model) representing the sort state of controller for a given
7
- # collection/parameter.
8
- class SortForm
9
- DIRECTIONS = %w[asc desc].freeze
10
-
11
- attr_accessor :column, :direction, :default
12
-
13
- def self.normalize(param)
14
- new(param:).to_param
15
- end
16
-
17
- def self.parse(param, **args)
18
- new(param:, **args)
19
- end
20
-
21
- def initialize(param: nil, column: nil, direction: nil, default: nil)
22
- if param.present?
23
- column, direction = param.to_s.split
24
- direction = "asc" unless DIRECTIONS.include?(direction)
25
- end
26
-
27
- self.column = column
28
- self.direction = direction
29
- self.default = SortForm.normalize(default) if default
30
- end
31
-
32
- def to_param
33
- "#{column} #{direction}"
34
- end
35
-
36
- def default?
37
- to_param == default.to_param
38
- end
39
-
40
- def hash
41
- to_param.hash
42
- end
43
-
44
- def eql?(other)
45
- to_param == other.to_param
46
- end
47
-
48
- alias to_s to_param
49
-
50
- # Returns true if the given collection supports sorting on the given
51
- # column. A column supports sorting if it is a database column or if
52
- # the collection responds to `order_by_#{column}(direction)`.
53
- #
54
- # @param collection [ActiveRecord::Relation]
55
- # @param column [String, Symbol]
56
- # @return [true, false]
57
- def supports?(collection, column)
58
- scope_for(collection).respond_to?(:"order_by_#{column}") ||
59
- model_for(collection).has_attribute?(column.to_s)
60
- end
61
-
62
- # Returns the current sort behaviour of the given column, for use as a
63
- # column heading class in the table view.
64
- #
65
- # @param column [String, Symbol] the table column as defined in table_with
66
- # @return [String] the current sort behaviour of the given column
67
- def status(column)
68
- direction if column.to_s == self.column
69
- end
70
-
71
- # Calculates the sort parameter to apply when the given column is toggled.
72
- #
73
- # @param column [String, Symbol]
74
- # @return [String]
75
- def toggle(column)
76
- return "#{column} asc" unless column.to_s == self.column
77
-
78
- case direction
79
- when "asc"
80
- "#{column} desc"
81
- when "desc"
82
- "#{column} asc"
83
- end
84
- end
85
-
86
- # Apply the constructed sort ordering to the collection.
87
- #
88
- # @param collection [ActiveRecord::Relation]
89
- # @return [Array(SortForm, ActiveRecord::Relation)]
90
- def apply(collection)
91
- return [self, collection] if column.nil?
92
-
93
- if collection.respond_to?(:"order_by_#{column}")
94
- collection = collection.reorder(nil).public_send(:"order_by_#{column}", direction.to_sym)
95
- elsif collection.model.has_attribute?(column)
96
- collection = collection.reorder(column => direction)
97
- else
98
- clear!
99
- end
100
-
101
- [self, collection]
102
- end
103
-
104
- private
105
-
106
- def clear!
107
- self.column = self.direction = nil
108
- end
109
-
110
- def scope_for(collection)
111
- collection.is_a?(Core) ? collection.items : collection
112
- end
113
-
114
- def model_for(collection)
115
- scope_for(collection).model
116
- end
117
- end
118
- end
119
- end
120
- end