flexible_datatables 1.0.1 → 1.0.2
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 +20 -13
- data/CHANGELOG.md +20 -13
- data/README.rdoc +1 -1
- data/lib/flexible_datatables.rb +1 -0
- data/lib/flexible_datatables/configurator.rb +2 -1
- data/lib/flexible_datatables/datatable.rb +8 -10
- data/lib/flexible_datatables/sorters.rb +3 -0
- data/lib/flexible_datatables/sorters/active_record_sorter.rb +12 -0
- data/lib/flexible_datatables/sorters/enumerable_sorter.rb +16 -0
- data/lib/flexible_datatables/sorters/proxy_sorter.rb +18 -0
- data/lib/flexible_datatables/version.rb +1 -1
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 954ecfb0dc491d590399d366e0d1ab7b102aefef
|
4
|
+
data.tar.gz: 28e89d97b8f83f54549099197d8a14141e198f93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1afe923adbb6c6236ac6604de583fb9a9c62a72aac794e61a65933a973a7ef6f3e86a62d216dfcba8fdfae35558cdd2817d41bbd1e95cd421dc36d6b949e2c8d
|
7
|
+
data.tar.gz: 6301cd5f284f6ace86ea407a7a239c8a1b02156f10039087d25daa3c6c49ac642871905a33b5182efac38ecad8fc7bec109e62a31822e74a02d6b8d7fe767eeb
|
data/CHANGELOG
CHANGED
@@ -1,20 +1,27 @@
|
|
1
|
-
Change Log
|
2
|
-
==========
|
1
|
+
# Change Log
|
3
2
|
|
4
3
|
All notable changes to the project are documented in this file.
|
5
4
|
|
6
|
-
[
|
7
|
-
--------------------
|
5
|
+
## [Unreleased][unreleased]
|
8
6
|
|
9
|
-
|
10
|
-
e621434 refer to the default DummyPaginator using the full namespace
|
11
|
-
4bb3085 Instantiate a Settings object when Configurator is defined, so default settings are available without needing to call Configurator.configuration first
|
12
|
-
513db65 pull in paginators and configurator definitions first
|
13
|
-
95d38a5 tweak file list
|
14
|
-
2308215 use rdoc for the README
|
7
|
+
## [v1.0.2] - 2015-02-16
|
15
8
|
|
16
|
-
|
17
|
-
|
9
|
+
### Changed
|
10
|
+
* Refactored sorting code into separate modules
|
18
11
|
|
19
|
-
|
12
|
+
### Fixed
|
13
|
+
* When sorting, if we do not have a collection of ActiveRecord::Relation objects, assume the collection responds to the Enumerable#sort
|
20
14
|
|
15
|
+
## [v1.0.1] - 2015-02-15
|
16
|
+
|
17
|
+
### Fixed
|
18
|
+
* Don't use 'blank?', which is an enhancement to Ruby from Rails, because obviously the code won't work outside of Rails
|
19
|
+
* refer to the default DummyPaginator using the full namespace
|
20
|
+
* Instantiate a Settings object when Configurator is defined, so default settings are available without needing to call Configurator.configuration first
|
21
|
+
* pull in paginators and configurator definitions first
|
22
|
+
|
23
|
+
## v1.0.0 - 2015-02-14
|
24
|
+
|
25
|
+
[unreleased]: https://github.com/davecorning/flexible_datatables/compare/v1.0.2...HEAD
|
26
|
+
[v1.0.2]: https://github.com/davecorning/flexible_datatables/compare/v1.0.1...v1.0.2
|
27
|
+
[v1.0.1]: https://github.com/davecorning/flexible_datatables/compare/v1.0.0...v1.0.1
|
data/CHANGELOG.md
CHANGED
@@ -1,20 +1,27 @@
|
|
1
|
-
Change Log
|
2
|
-
==========
|
1
|
+
# Change Log
|
3
2
|
|
4
3
|
All notable changes to the project are documented in this file.
|
5
4
|
|
6
|
-
[
|
7
|
-
--------------------
|
5
|
+
## [Unreleased][unreleased]
|
8
6
|
|
9
|
-
|
10
|
-
e621434 refer to the default DummyPaginator using the full namespace
|
11
|
-
4bb3085 Instantiate a Settings object when Configurator is defined, so default settings are available without needing to call Configurator.configuration first
|
12
|
-
513db65 pull in paginators and configurator definitions first
|
13
|
-
95d38a5 tweak file list
|
14
|
-
2308215 use rdoc for the README
|
7
|
+
## [v1.0.2] - 2015-02-16
|
15
8
|
|
16
|
-
|
17
|
-
|
9
|
+
### Changed
|
10
|
+
* Refactored sorting code into separate modules
|
18
11
|
|
19
|
-
|
12
|
+
### Fixed
|
13
|
+
* When sorting, if we do not have a collection of ActiveRecord::Relation objects, assume the collection responds to the Enumerable#sort
|
20
14
|
|
15
|
+
## [v1.0.1] - 2015-02-15
|
16
|
+
|
17
|
+
### Fixed
|
18
|
+
* Don't use 'blank?', which is an enhancement to Ruby from Rails, because obviously the code won't work outside of Rails
|
19
|
+
* refer to the default DummyPaginator using the full namespace
|
20
|
+
* Instantiate a Settings object when Configurator is defined, so default settings are available without needing to call Configurator.configuration first
|
21
|
+
* pull in paginators and configurator definitions first
|
22
|
+
|
23
|
+
## v1.0.0 - 2015-02-14
|
24
|
+
|
25
|
+
[unreleased]: https://github.com/davecorning/flexible_datatables/compare/v1.0.2...HEAD
|
26
|
+
[v1.0.2]: https://github.com/davecorning/flexible_datatables/compare/v1.0.1...v1.0.2
|
27
|
+
[v1.0.1]: https://github.com/davecorning/flexible_datatables/compare/v1.0.0...v1.0.1
|
data/README.rdoc
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
= Flexible Datatables
|
1
|
+
= Flexible Datatables {<img src="https://badge.fury.io/rb/flexible_datatables.svg" alt="Gem Version" />}[http://badge.fury.io/rb/flexible_datatables]
|
2
2
|
Easily integrate {JQuery Datatables}[https://www.datatables.net] (with Ajax) into your Ruby / Rails web applications.
|
3
3
|
|
4
4
|
== Introduction
|
data/lib/flexible_datatables.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
module FlexibleDatatables
|
2
2
|
module Configurator
|
3
3
|
class Settings
|
4
|
-
attr_accessor :items_per_page, :paginator
|
4
|
+
attr_accessor :items_per_page, :paginator, :sorter
|
5
5
|
|
6
6
|
def initialize
|
7
7
|
@items_per_page = 10
|
8
8
|
@paginator = ::FlexibleDatatables::DummyPaginator
|
9
|
+
@sorter = ::FlexibleDatatables::ProxySorter
|
9
10
|
end
|
10
11
|
end
|
11
12
|
|
@@ -9,6 +9,7 @@ module FlexibleDatatables
|
|
9
9
|
@length = args.fetch(:length, Configurator.settings.items_per_page).to_i
|
10
10
|
@order = args.fetch(:order, {})
|
11
11
|
@paginator = args.fetch(:paginator, Configurator.settings.paginator)
|
12
|
+
@sorter = Configurator.settings.sorter
|
12
13
|
@start = args.fetch(:start, 0).to_i
|
13
14
|
end
|
14
15
|
|
@@ -23,7 +24,7 @@ module FlexibleDatatables
|
|
23
24
|
|
24
25
|
def format_grid(cols = [])
|
25
26
|
@columns = cols unless cols.empty?
|
26
|
-
records =
|
27
|
+
records = sort(records)
|
27
28
|
@grid = paginate(records).map { |record| yield(record) }
|
28
29
|
end
|
29
30
|
|
@@ -32,18 +33,15 @@ module FlexibleDatatables
|
|
32
33
|
:length,
|
33
34
|
:order,
|
34
35
|
:paginator,
|
35
|
-
:start
|
36
|
-
|
37
|
-
def sort_column
|
38
|
-
@columns[order["0"].fetch(:column).to_i]
|
39
|
-
end
|
40
|
-
|
41
|
-
def sort_direction
|
42
|
-
order["0"].fetch(:dir) == "desc" ? "desc" : "asc"
|
43
|
-
end
|
36
|
+
:start,
|
37
|
+
:sorter
|
44
38
|
|
45
39
|
def paginate(records)
|
46
40
|
paginator.paginate(start: start, length: length, records: records)
|
47
41
|
end
|
42
|
+
|
43
|
+
def sort(records)
|
44
|
+
sorter.sort(columns: @columns, records: collection, order: order)
|
45
|
+
end
|
48
46
|
end
|
49
47
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module FlexibleDatatables
|
2
|
+
module ActiveRecordSorter
|
3
|
+
def self.sort(opts = {})
|
4
|
+
columns = opts.fetch(:columns)
|
5
|
+
records = opts.fetch(:records, [])
|
6
|
+
order_opts = opts.fetch(:order)
|
7
|
+
sort_col = columns[order_opts['0'].fetch(:column).to_i]
|
8
|
+
sort_dir = order_opts['0'].fetch(:dir) == 'desc' ? 'desc' : 'asc'
|
9
|
+
records.order("#{sort_col} #{sort_dir}")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module FlexibleDatatables
|
2
|
+
module EnumerableSorter
|
3
|
+
def self.sort(opts = {})
|
4
|
+
order = opts.fetch(:order)
|
5
|
+
sort_dir = order['0'].fetch(:dir) == 'desc' ? 'desc' : 'asc'
|
6
|
+
sort_col = order['0'].fetch(:column).to_i
|
7
|
+
records = opts.fetch(:records, [])
|
8
|
+
|
9
|
+
sorted_records = records.sort_by do |row|
|
10
|
+
row[sort_col]
|
11
|
+
end
|
12
|
+
sorted_records.reverse if sort_dir == 'desc'
|
13
|
+
sorted_records
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module FlexibleDatatables
|
2
|
+
module ProxySorter
|
3
|
+
def self.sort(opts = {})
|
4
|
+
columns = opts.fetch(:columns)
|
5
|
+
records = opts.fetch(:records, [])
|
6
|
+
order_opts = opts.fetch(:order)
|
7
|
+
sorted_records = []
|
8
|
+
begin
|
9
|
+
sorted_records =
|
10
|
+
ActiveRecordSorter.sort(records: records, columns: columns, order: order_opts)
|
11
|
+
rescue NoMethodError
|
12
|
+
sorted_records =
|
13
|
+
EnumerableSorter.sort(records: records, order: order_opts)
|
14
|
+
end
|
15
|
+
sorted_records
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flexible_datatables
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dave Corning
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Flexible Datatables wraps array-like objects (ActiveRecord::Relation
|
14
14
|
collections, etc) that JQuery Datatables can read (via ajax) from your Ruby / Rails
|
@@ -28,6 +28,10 @@ files:
|
|
28
28
|
- lib/flexible_datatables/paginators/dummy_paginator.rb
|
29
29
|
- lib/flexible_datatables/paginators/kaminari_paginator.rb
|
30
30
|
- lib/flexible_datatables/paginators/simple_paginator.rb
|
31
|
+
- lib/flexible_datatables/sorters.rb
|
32
|
+
- lib/flexible_datatables/sorters/active_record_sorter.rb
|
33
|
+
- lib/flexible_datatables/sorters/enumerable_sorter.rb
|
34
|
+
- lib/flexible_datatables/sorters/proxy_sorter.rb
|
31
35
|
- lib/flexible_datatables/version.rb
|
32
36
|
homepage: https://github.com/davecorning/flexible_datatables
|
33
37
|
licenses:
|
@@ -41,7 +45,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
41
45
|
requirements:
|
42
46
|
- - ">="
|
43
47
|
- !ruby/object:Gem::Version
|
44
|
-
version:
|
48
|
+
version: 1.9.3
|
45
49
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
50
|
requirements:
|
47
51
|
- - ">="
|