sortable_by 1.0 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Rakefile +1 -1
- data/app/helpers/sortable_by/table_helper.rb +3 -3
- data/lib/sortable_by/configuration.rb +1 -1
- data/lib/sortable_by/engine.rb +1 -1
- data/{app/controllers/concerns → lib}/sortable_by/params.rb +9 -9
- data/lib/sortable_by/table_header.rb +8 -2
- data/lib/sortable_by/version.rb +1 -1
- data/lib/sortable_by.rb +1 -0
- metadata +17 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 57aec93c545980e73c92b7135b14d161981ea29d0760ee3aab3317bd6ada0bdd
|
4
|
+
data.tar.gz: 632442d5cc37d21280d95da6a09a66966ca7d8329a73ba8dce4790c01dd1f444
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df35102a578b4b0331642f68f06c07940b746a159d51a3af851142ae2b5f6aa5b77bd3b88e9ebdf783c4c9af75ee1cf04e4e72817a059b9f9535d2bdc1262f6f
|
7
|
+
data.tar.gz: bd1d63ab89b77020d5c376bc6ea78d6cd674477731ec0866bc7d624e60bb428c6983e1f6659e2c371339b3adf89b3c73185b60df7ccadf94cb5a50090360bd6f
|
data/Rakefile
CHANGED
@@ -14,7 +14,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
|
|
14
14
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
15
|
end
|
16
16
|
|
17
|
-
APP_RAKEFILE = File.expand_path('
|
17
|
+
APP_RAKEFILE = File.expand_path('spec/dummy/Rakefile', __dir__)
|
18
18
|
load 'rails/tasks/engine.rake'
|
19
19
|
|
20
20
|
load 'rails/tasks/statistics.rake'
|
@@ -25,11 +25,11 @@ module SortableBy
|
|
25
25
|
#
|
26
26
|
def sortable_table_header(path_helper, model: nil, permit: [], icon: SortableBy.icon_strategy, &block)
|
27
27
|
header = SortableBy::TableHeader.new(
|
28
|
-
path_helper
|
29
|
-
model
|
28
|
+
path_helper:,
|
29
|
+
model:,
|
30
30
|
params: params.permit(permit.concat(SortableBy.params_list)),
|
31
31
|
context: self,
|
32
|
-
icon:
|
32
|
+
icon:)
|
33
33
|
header.capture(block) if block
|
34
34
|
header.to_html
|
35
35
|
end
|
data/lib/sortable_by/engine.rb
CHANGED
@@ -3,9 +3,7 @@ module SortableBy
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
module ClassMethods
|
6
|
-
attr_accessor :default_sort_attribute
|
7
|
-
attr_accessor :default_sort_dir
|
8
|
-
attr_accessor :sortable_mapping
|
6
|
+
attr_accessor :default_sort_attribute, :default_sort_dir, :sortable_mapping
|
9
7
|
|
10
8
|
# Define attributes you wish to sort by
|
11
9
|
#
|
@@ -27,7 +25,7 @@ module SortableBy
|
|
27
25
|
def sortable_by(*attributes, **options)
|
28
26
|
@default_sort_attribute = options.delete(:default)
|
29
27
|
@default_sort_dir = options.delete(:direction) || :asc
|
30
|
-
@sortable_mapping = options.merge(attributes.
|
28
|
+
@sortable_mapping = options.merge(attributes.to_h { |att| [att, att] })
|
31
29
|
end
|
32
30
|
end
|
33
31
|
|
@@ -56,6 +54,7 @@ module SortableBy
|
|
56
54
|
#
|
57
55
|
def sortable_query
|
58
56
|
return unless sort_attribute
|
57
|
+
|
59
58
|
normalize_sort_value(
|
60
59
|
sort_attribute,
|
61
60
|
sort_direction
|
@@ -66,13 +65,14 @@ module SortableBy
|
|
66
65
|
#
|
67
66
|
def normalize_sort_value(sort_by, direction)
|
68
67
|
mapping = self.class.sortable_mapping[sort_by]
|
69
|
-
|
68
|
+
case mapping
|
69
|
+
when Symbol
|
70
70
|
{ mapping => sort_direction }
|
71
|
-
|
71
|
+
when String
|
72
72
|
mapping.gsub(':dir', sort_direction.to_s)
|
73
|
-
|
74
|
-
mapping.
|
75
|
-
|
73
|
+
when Array
|
74
|
+
mapping.index_with { |_att| direction }
|
75
|
+
when Proc
|
76
76
|
mapping.call(direction)
|
77
77
|
else
|
78
78
|
logger.debug("WARNING: Sort attribute '#{sort_by}' is not recognized. Did you mean to pass it to sortable_by?")
|
@@ -8,7 +8,7 @@ module SortableBy
|
|
8
8
|
# Forward view helper methods to the view context
|
9
9
|
delegate :concat, :content_tag, :link_to, to: :context
|
10
10
|
|
11
|
-
def initialize(path_helper:, model: nil, params: {}
|
11
|
+
def initialize(path_helper:, context:, icon:, model: nil, params: {})
|
12
12
|
@path_helper = path_helper
|
13
13
|
@model = model
|
14
14
|
@params = params
|
@@ -39,7 +39,7 @@ module SortableBy
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def to_html
|
42
|
-
content_tag :thead, to_row, class: '
|
42
|
+
content_tag :thead, to_row, class: 'sortable-table-header'
|
43
43
|
end
|
44
44
|
|
45
45
|
private
|
@@ -88,6 +88,7 @@ module SortableBy
|
|
88
88
|
|
89
89
|
def sort_arrow_for_attribute(attribute)
|
90
90
|
return '' unless @params[:sort] == attribute.to_s
|
91
|
+
|
91
92
|
IconStrategy.send(@icon, context, current_direction) if IconStrategy.respond_to?(@icon)
|
92
93
|
end
|
93
94
|
end
|
@@ -103,5 +104,10 @@ module SortableBy
|
|
103
104
|
icon_class = dir == 'asc' ? 'up' : 'down'
|
104
105
|
context.content_tag(:span, '', class: "glyphicon glyphicon-arrow-#{icon_class}")
|
105
106
|
end
|
107
|
+
|
108
|
+
def self.basic(context, dir)
|
109
|
+
text = dir == 'desc' ? '▼' : '▲'
|
110
|
+
context.content_tag(:span, text, class: 'sortable-direction')
|
111
|
+
end
|
106
112
|
end
|
107
113
|
end
|
data/lib/sortable_by/version.rb
CHANGED
data/lib/sortable_by.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sortable_by
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Greg Woods
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-09-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '5.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: database_cleaner
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: pg
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: rspec-rails
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: rubocop
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
@@ -81,7 +81,7 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name: rubocop
|
84
|
+
name: rubocop-rails
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
@@ -94,8 +94,8 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
-
description:
|
98
|
-
|
97
|
+
description: Adds capabilities to create sortable table headers and connect them to
|
98
|
+
an ActiveRecord query
|
99
99
|
email:
|
100
100
|
- greg.woods@moserit.com
|
101
101
|
executables: []
|
@@ -105,19 +105,20 @@ files:
|
|
105
105
|
- MIT-LICENSE
|
106
106
|
- README.md
|
107
107
|
- Rakefile
|
108
|
-
- app/controllers/concerns/sortable_by/params.rb
|
109
108
|
- app/helpers/sortable_by/table_helper.rb
|
110
109
|
- lib/sortable_by.rb
|
111
110
|
- lib/sortable_by/configuration.rb
|
112
111
|
- lib/sortable_by/engine.rb
|
112
|
+
- lib/sortable_by/params.rb
|
113
113
|
- lib/sortable_by/table_header.rb
|
114
114
|
- lib/sortable_by/version.rb
|
115
115
|
- lib/tasks/sortable_by_tasks.rake
|
116
116
|
homepage: https://github.com/moser-inc/sortable_by
|
117
117
|
licenses:
|
118
118
|
- MIT
|
119
|
-
metadata:
|
120
|
-
|
119
|
+
metadata:
|
120
|
+
rubygems_mfa_required: 'true'
|
121
|
+
post_install_message:
|
121
122
|
rdoc_options: []
|
122
123
|
require_paths:
|
123
124
|
- lib
|
@@ -125,16 +126,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
125
126
|
requirements:
|
126
127
|
- - ">="
|
127
128
|
- !ruby/object:Gem::Version
|
128
|
-
version: '
|
129
|
+
version: '3.1'
|
129
130
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
131
|
requirements:
|
131
132
|
- - ">="
|
132
133
|
- !ruby/object:Gem::Version
|
133
134
|
version: '0'
|
134
135
|
requirements: []
|
135
|
-
|
136
|
-
|
137
|
-
signing_key:
|
136
|
+
rubygems_version: 3.3.22
|
137
|
+
signing_key:
|
138
138
|
specification_version: 4
|
139
139
|
summary: Simple tool for sorting tables of data in rails
|
140
140
|
test_files: []
|