greedo 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8c37eaa9ca950940e9c87f9ed42e5954d03d06e4
4
- data.tar.gz: e5c83b75858b499a110a9ac15aef2ff973c0083e
3
+ metadata.gz: 48c3028f4ecf306b0c59c53b9bede17f851103cd
4
+ data.tar.gz: 7ef547c2576e93017b31013cccfee5b367772e7e
5
5
  SHA512:
6
- metadata.gz: 68a84e842d0191ad79765e733ee98d2283b8ec1e71055437e881de2b57a770d1a66b0638737f3bc0aba681e4d4ff95c6289ae1a41ed722c661b9f87e34bf32d7
7
- data.tar.gz: 6a4d333a874b4228d1955e55568c6b4a652c7c64b65a976dfa8998801dd365181a33961d1ed0a06261ac2a60341eaed0d8028797c9d6df8d3db5081e53b7dabb
6
+ metadata.gz: 96eb11d4a5dcd6f38904289d3e3e8d8fac085fbe8c6a81aaa176f0f3cd1270dcec7c6719ca10d193a567304f6a33207c6436527b170a03cce3fba23ba167e1d9
7
+ data.tar.gz: 557a57d5eb4c230c044fc0132e79d00555de86c06ac73766b264a4a64d2fb3cfec5838612de033bc5d8e84db0693fe50c9d1cb8e386a8ca25b88f950f162b1a8
@@ -23,4 +23,6 @@
23
23
  = column.value
24
24
 
25
25
  - if grid.show_pagination?
26
- = will_paginate grid.paginator.records, param_name: param_name, renderer: BootstrapPagination::Rails
26
+ = will_paginate grid.paginator.records, param_name: param_name,
27
+ params: path_params,
28
+ renderer: BootstrapPagination::Rails
@@ -3,9 +3,9 @@ module Greedo
3
3
  class Grid
4
4
  attr_accessor :paginator
5
5
  attr_reader :view_context, :fields, :presenter, :empty_message_text,
6
- :order, :order_by
6
+ :order, :order_by, :path_params
7
7
 
8
- def initialize(view_context:, order: nil, order_by: nil)
8
+ def initialize(view_context:, order: nil, order_by: nil, path_params: nil)
9
9
  @view_context = view_context
10
10
  @row_id = ->(record) { default_row_id(record) }
11
11
  @fields = []
@@ -13,6 +13,7 @@ module Greedo
13
13
  @empty_message_text = "No data to show."
14
14
  @order = order
15
15
  @order_by = order_by
16
+ @path_params = path_params
16
17
  end
17
18
 
18
19
  def configure
@@ -43,7 +44,7 @@ module Greedo
43
44
  renderer = ->(record) { present(record).public_send(name) }
44
45
  end
45
46
 
46
- fields << Field.new(name, label, renderer, order, order_by, view_context, sort)
47
+ fields << Field.new(name, label, renderer, order, order_by, view_context, sort, path_params)
47
48
  nil
48
49
  end
49
50
 
@@ -102,7 +103,8 @@ module Greedo
102
103
  end
103
104
  end
104
105
 
105
- Field = Struct.new(:name, :label, :renderer, :order, :order_by, :view_context, :sort) do
106
+ Field = Struct.new(:name, :label, :renderer, :order, :order_by,
107
+ :view_context, :sort, :path_params) do
106
108
  def value(record)
107
109
  renderer.call(record)
108
110
  end
@@ -115,19 +117,23 @@ module Greedo
115
117
  order_by == name.to_s && %w(asc desc).include?(order)
116
118
  end
117
119
 
120
+ def params
121
+ view_context.params.merge(path_params)
122
+ end
123
+
118
124
  def order_desc_path
119
125
  if ordered_by? && order == "desc"
120
- view_context.url_for(view_context.params)
126
+ view_context.url_for(params.merge(order: nil, order_by: nil))
121
127
  else
122
- view_context.url_for(view_context.params.merge(order: :desc, order_by: name))
128
+ view_context.url_for(params.merge(order: :desc, order_by: name))
123
129
  end
124
130
  end
125
131
 
126
132
  def order_asc_path
127
133
  if ordered_by? && order == "asc"
128
- view_context.url_for(view_context.params)
134
+ view_context.url_for(params.merge(order: nil, order_by: nil))
129
135
  else
130
- view_context.url_for(view_context.params.merge(order: :asc, order_by: name))
136
+ view_context.url_for(params.merge(order: :asc, order_by: name))
131
137
  end
132
138
  end
133
139
 
@@ -153,16 +159,22 @@ module Greedo
153
159
  param_name: :page,
154
160
  page: params.fetch(param_name) { 1 }.to_i,
155
161
  per_page: 20,
162
+ path_params: {},
156
163
  order: params[:order],
157
164
  order_by: params[:order_by],
158
165
  &block)
159
- grid = Grid.new(view_context: self, order: order, order_by: order_by)
166
+ grid = Grid.new(view_context: self,
167
+ order: order,
168
+ order_by: order_by,
169
+ path_params: path_params)
160
170
  grid.configure(&block)
161
171
  grid.paginator = Paginator.build(scope,
162
172
  page: page,
163
173
  per_page: per_page,
164
174
  order_by: grid.ordered_by)
165
- render partial: "greedo/grid", locals: {grid: grid, param_name: param_name}
175
+ render partial: "greedo/grid", locals: {grid: grid,
176
+ param_name: param_name,
177
+ path_params: path_params}
166
178
  end
167
179
  end
168
180
  end
@@ -1,3 +1,3 @@
1
1
  module Greedo
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: greedo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Pohorecki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-17 00:00:00.000000000 Z
11
+ date: 2018-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler