katalyst-tables 1.0.0 → 1.1.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 +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/katalyst/tables/backend/sort_form.rb +12 -41
- data/lib/katalyst/tables/backend.rb +1 -2
- data/lib/katalyst/tables/frontend/builder/base.rb +1 -0
- data/lib/katalyst/tables/frontend/builder/header_cell.rb +1 -1
- data/lib/katalyst/tables/frontend/helper.rb +16 -0
- data/lib/katalyst/tables/frontend.rb +1 -1
- data/lib/katalyst/tables/version.rb +1 -1
- metadata +7 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5482118f21175e8c1dbff1a397fa7b5ff68480783a2c47da2a92c0436c66e739
|
4
|
+
data.tar.gz: 99e70f74ef353cce895305e5ad39a98dc690efd7f0c68d4305867fbcdc23c941
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 219380d0ccb99e001c9604594d0aa68a58925bbd745d87898af359316192e61727d3549c4ab64198c31656c663ec00809d93ddc8034921143f8169fcb49f7769
|
7
|
+
data.tar.gz: b9d8a9e03604f9b39389d218bfceb4d354343bd0d1da4ff3bd7ca55f66446ba8f5fbc8430b9d5b22974f1210eed344ce0d579bccb209e29a0d35ca59982d4c63
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [1.1.0] - 2023-07-18
|
4
|
+
|
5
|
+
- Replaces `param_key` with `i18n_key` for attribute lookup in locale file
|
6
|
+
- Remove controller and url helpers from backend
|
7
|
+
- No changes required to existing code unless you were using the internal
|
8
|
+
classes directly
|
9
|
+
|
3
10
|
## [1.0.0] - 2022-03-23
|
4
11
|
|
5
12
|
- Initial release
|
@@ -10,11 +10,9 @@ module Katalyst
|
|
10
10
|
|
11
11
|
attr_accessor :column, :direction
|
12
12
|
|
13
|
-
def initialize(
|
13
|
+
def initialize(column: nil, direction: nil)
|
14
14
|
self.column = column
|
15
15
|
self.direction = direction
|
16
|
-
|
17
|
-
@controller = controller
|
18
16
|
end
|
19
17
|
|
20
18
|
# Returns true if the given collection supports sorting on the given
|
@@ -38,35 +36,19 @@ module Katalyst
|
|
38
36
|
direction if column.to_s == self.column
|
39
37
|
end
|
40
38
|
|
41
|
-
#
|
39
|
+
# Calculates the sort parameter to apply when the given column is toggled.
|
42
40
|
#
|
43
|
-
# @param column [String, Symbol]
|
44
|
-
# @return [String]
|
45
|
-
def
|
46
|
-
#
|
47
|
-
|
48
|
-
request = @controller.request
|
49
|
-
|
50
|
-
# Preserve any existing GET parameters
|
51
|
-
# CAUTION: these parameters are not sanitised
|
52
|
-
params = request.GET.merge("sort" => "#{column} #{toggle_direction(column)}").except("page")
|
53
|
-
query_string = params.empty? ? "" : "?#{Rack::Utils.build_nested_query(params)}"
|
54
|
-
|
55
|
-
"#{request.path}#{query_string}"
|
56
|
-
end
|
57
|
-
|
58
|
-
# Generates a url for the current page without any sorting parameters.
|
59
|
-
#
|
60
|
-
# @return [String] URL for use as a link in a column header
|
61
|
-
def unsorted_url
|
62
|
-
request = @controller.request
|
63
|
-
|
64
|
-
# Preserve any existing GET parameters but remove sort.
|
65
|
-
# CAUTION: these parameters are not sanitised
|
66
|
-
params = request.GET.except("sort", "page")
|
67
|
-
query_string = params.empty? ? "" : "?#{Rack::Utils.build_nested_query(params)}"
|
41
|
+
# @param column [String, Symbol]
|
42
|
+
# @return [String]
|
43
|
+
def toggle(column)
|
44
|
+
return "#{column} asc" unless column.to_s == self.column
|
68
45
|
|
69
|
-
|
46
|
+
case direction
|
47
|
+
when "asc"
|
48
|
+
"#{column} desc"
|
49
|
+
when "desc"
|
50
|
+
"#{column} asc"
|
51
|
+
end
|
70
52
|
end
|
71
53
|
|
72
54
|
# Apply the constructed sort ordering to the collection.
|
@@ -92,17 +74,6 @@ module Katalyst
|
|
92
74
|
def clear!
|
93
75
|
self.column = self.direction = nil
|
94
76
|
end
|
95
|
-
|
96
|
-
def toggle_direction(column)
|
97
|
-
return "asc" unless column.to_s == self.column
|
98
|
-
|
99
|
-
case direction
|
100
|
-
when "asc"
|
101
|
-
"desc"
|
102
|
-
when "desc"
|
103
|
-
"asc"
|
104
|
-
end
|
105
|
-
end
|
106
77
|
end
|
107
78
|
end
|
108
79
|
end
|
@@ -22,8 +22,7 @@ module Katalyst
|
|
22
22
|
column, direction = params[:sort]&.split(" ")
|
23
23
|
direction = "asc" unless SortForm::DIRECTIONS.include?(direction)
|
24
24
|
|
25
|
-
SortForm.new(
|
26
|
-
column: column,
|
25
|
+
SortForm.new(column: column,
|
27
26
|
direction: direction)
|
28
27
|
.apply(collection)
|
29
28
|
end
|
@@ -4,6 +4,22 @@ module Katalyst
|
|
4
4
|
module Tables
|
5
5
|
module Frontend
|
6
6
|
module Helper # :nodoc:
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
# Generates a url for applying/toggling sort for the given column.
|
10
|
+
#
|
11
|
+
# @param sort [String, nil] sort parameter to apply, or nil to remove sorting
|
12
|
+
# @return [String] URL for toggling column sorting
|
13
|
+
def sort_url_for(sort: nil)
|
14
|
+
# Implementation inspired by pagy's `pagy_url_for` helper.
|
15
|
+
# Preserve any existing GET parameters
|
16
|
+
# CAUTION: these parameters are not sanitised
|
17
|
+
params = request.GET.merge("sort" => sort).except("page")
|
18
|
+
query_string = params.empty? ? "" : "?#{Rack::Utils.build_nested_query(params)}"
|
19
|
+
|
20
|
+
"#{request.path}#{query_string}"
|
21
|
+
end
|
22
|
+
|
7
23
|
private
|
8
24
|
|
9
25
|
def html_options_for_table_with(html: {}, **options)
|
@@ -17,7 +17,7 @@ module Katalyst
|
|
17
17
|
def table_with(collection:, **options, &block)
|
18
18
|
table_options = options.slice(:header, :object_name, :sort)
|
19
19
|
|
20
|
-
table_options[:object_name] ||= collection.try(:model_name)&.
|
20
|
+
table_options[:object_name] ||= collection.try(:model_name)&.i18n_key
|
21
21
|
|
22
22
|
html_options = html_options_for_table_with(**options)
|
23
23
|
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: katalyst-tables
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Katalyst Interactive
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: rspec
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '3.2'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '3.2'
|
11
|
+
date: 2023-07-18 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
27
13
|
description: Builder-style HTML table generator for building tabular index views.
|
28
14
|
Supports sorting by columns.
|
29
15
|
email:
|
@@ -56,7 +42,7 @@ metadata:
|
|
56
42
|
homepage_uri: https://github.com/katalyst/katalyst-tables
|
57
43
|
source_code_uri: https://github.com/katalyst/katalyst-tables
|
58
44
|
changelog_uri: https://github.com/katalyst/katalyst-tables/blobs/main/CHANGELOG.md
|
59
|
-
post_install_message:
|
45
|
+
post_install_message:
|
60
46
|
rdoc_options: []
|
61
47
|
require_paths:
|
62
48
|
- lib
|
@@ -71,8 +57,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
57
|
- !ruby/object:Gem::Version
|
72
58
|
version: '0'
|
73
59
|
requirements: []
|
74
|
-
rubygems_version: 3.
|
75
|
-
signing_key:
|
60
|
+
rubygems_version: 3.4.12
|
61
|
+
signing_key:
|
76
62
|
specification_version: 4
|
77
63
|
summary: HTML table generator for Rails views
|
78
64
|
test_files: []
|