table_on_steroids 0.1.1.11 → 0.1.1.13

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1378468bf399d1096d6d742f411713b663d79b17e8ce51acde40c1e17ca9083b
4
- data.tar.gz: f5fa42544357f2ee09879351e98960b8c05d276bf8a372e3f0b66aa27c7d0be4
3
+ metadata.gz: 2f24d4f105e27626f6ac9038284f6ddff75784239fd7004fa5146cbb57c0c134
4
+ data.tar.gz: e1b9627cf54ffc485856845972d776b2614663a21cd812cf7c8030a8a510ee03
5
5
  SHA512:
6
- metadata.gz: 51fb1cedc9bc4d726094e024b7b51a4ce0ac91cb35103838a0e9a50cae1c6c2e4ab3c5f939f543e6a813edad82f218e6eb9e45700b50832a86a30eaa32d3335e
7
- data.tar.gz: e44da86c8988df5c3385925aa35249a5a9509d438fb6d3ddd4734ab9b883e0347b11d18f132db541e25f28217732e6f57966cef8f67afdbd7e94852ee3d7f671
6
+ metadata.gz: 3f506dea75e687c7240cdb61d10806a504cca35f311ce1213e6c51b514ac259024ecd644e9a1120c10d167755c6c470e16c9021ddb8bb00d7973ebd09dc77835
7
+ data.tar.gz: 5fb0e6809e49d51a9cce6a65cc8c4d5f8fddd38558b510e0feb0f03029197e1f6f286f6ee02479b735c318f45ea2cc9931b72580a63e25a49c4756a3b752caa2
data/README.md CHANGED
@@ -123,6 +123,14 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
123
123
 
124
124
  Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/table_on_steroids. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
125
125
 
126
+ ## Build and deploy a new version
127
+
128
+ 1. Upgrade the version number
129
+ 2. `gem build table_on_steroids` it will create a .gem file
130
+ 3. `gem push table_on_steroids-[newversion].gem`
131
+
132
+ Adding an owner `gem owner --add {{email}} {{gem}}` (the person must have a https://rubygems.org/ account)
133
+
126
134
  ## License
127
135
 
128
136
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -39,7 +39,10 @@ module TableOnSteroids
39
39
  OBJECTS_PER_PAGE = 50
40
40
  end
41
41
 
42
- def filter_and_order(objects, columns_on_steroid, global_search = nil, include_counts = false, all_pages = false, table_on_steroids = nil)
42
+ def filter_and_order(objects, columns_on_steroid, global_search = nil, include_counts = false, all_pages = false, table_on_steroids = nil, rows_to_display = nil)
43
+
44
+ limit = rows_to_display || OBJECTS_PER_PAGE
45
+
43
46
  # execute the global search if you have one
44
47
  if params[:search].present?
45
48
  objects = global_search.call(objects, params[:search]) if global_search
@@ -50,18 +53,16 @@ module TableOnSteroids
50
53
  # column search
51
54
  objects = objects_where(objects, columns_on_steroid, t)
52
55
 
53
- # apply filters
54
- if params[:filters].present?
55
- params[:filters].each_pair do |k, v|
56
- filter = columns_on_steroid[k]
57
- next unless filter.present? && filter[t].present?
58
-
59
- objects = filter[t][:filter_lambda].call(objects, v)
56
+ filter_columns = columns_on_steroid.map{|k,v| k if v.dig(t,:filter_lambda) }.compact
57
+ filter_columns.each do |k|
58
+ filter_value = (params[:filters] && params[:filters][k]) || params[k]
59
+ if(!filter_value.blank?)
60
+ objects = columns_on_steroid[k][t][:filter_lambda].call(objects, filter_value)
60
61
  end
61
62
  end
62
63
 
63
64
  #order
64
- if params&.dig(:knowledge,:order) && (object_order = columns_on_steroid[params[:knowledge][:order]]).present?
65
+ if params&.dig(:knowledge,:order) && (object_order = columns_on_steroid[params[:knowledge][:order]]).present?
65
66
  if(object_order[t] && object_order[t][:order_lambda])
66
67
  direction = (params&.dig(:knowledge,:ascending).to_s == 'true') ? 'asc' : 'desc'
67
68
  objects = objects.reorder(nil) if(objects.is_a?(ActiveRecord::Base) || objects.is_a?(ActiveRecord::Relation))
@@ -87,14 +88,14 @@ module TableOnSteroids
87
88
  return (include_counts ? [objects, 1, objects.count] : objects) if all_pages
88
89
 
89
90
  # GO to specific object page
90
- page = get_page(objects, params, table_on_steroids)
91
+ page = get_page(objects, params, table_on_steroids, limit)
91
92
 
92
93
  if objects.is_a?(ActiveRecord::Base) || objects.is_a?(ActiveRecord::Relation)
93
- objects = objects.page(page).per(OBJECTS_PER_PAGE)
94
+ objects = objects.page(page).per(limit)
94
95
  total_pages = objects.total_pages
95
96
  total_count = objects.total_count
96
97
  else
97
- objects = Kaminari.paginate_array(objects).page(page).per(OBJECTS_PER_PAGE)
98
+ objects = Kaminari.paginate_array(objects).page(page).per(limit)
98
99
  total_pages = objects.total_pages
99
100
  total_count = objects.total_count
100
101
  end
@@ -221,7 +222,7 @@ module TableOnSteroids
221
222
  objects
222
223
  end
223
224
 
224
- def get_page(objects, params, table_on_steroids)
225
+ def get_page(objects, params, table_on_steroids, limit)
225
226
  active_record_object_fetch_opts = table_on_steroids&.dig(:active_record_object_fetch_opts)
226
227
  key_lambda = table_on_steroids&.dig(:key_lambda)
227
228
  return params[:page] unless active_record_object_fetch_opts && key_lambda
@@ -230,7 +231,7 @@ module TableOnSteroids
230
231
  return params[:page] unless object
231
232
 
232
233
  index = objects.index { |o| key_lambda.call(o) == key_lambda.call(object) }
233
- index ? index / OBJECTS_PER_PAGE + 1 : params[:page]
234
+ index ? index / limit + 1 : params[:page]
234
235
  end
235
236
  end
236
237
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TableOnSteroids
4
- VERSION = '0.1.1.11'
4
+ VERSION = '0.1.1.13'
5
5
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: table_on_steroids
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1.11
4
+ version: 0.1.1.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marieke Gueye
8
8
  - Matt Hiatt
9
- autorequire:
9
+ autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2019-11-09 00:00:00.000000000 Z
12
+ date: 2024-06-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bootstrap-datepicker-rails
@@ -136,7 +136,7 @@ homepage: http://www.github.com/mariekou
136
136
  licenses:
137
137
  - MIT
138
138
  metadata: {}
139
- post_install_message:
139
+ post_install_message:
140
140
  rdoc_options: []
141
141
  require_paths:
142
142
  - lib
@@ -151,9 +151,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
153
  requirements: []
154
- rubyforge_project:
154
+ rubyforge_project:
155
155
  rubygems_version: 2.7.7
156
- signing_key:
156
+ signing_key:
157
157
  specification_version: 4
158
158
  summary: Create awesome tables for rails
159
159
  test_files: []