tabulatr2 0.9.32 → 0.9.33

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: 8925e114b7d2dc500bb27471320b8c81ad86773c
4
- data.tar.gz: ca9a67f02bd9d69763d502fd9c5fd1ecaa321ae9
3
+ metadata.gz: 62d761945606d57007db863163a4674d08d41bb6
4
+ data.tar.gz: d4ab3323e85d5b46cb5595d1d712b3fadb1b672e
5
5
  SHA512:
6
- metadata.gz: 96a7faf7a4ad05a24433a3e67355775fa0340919c6d7a325bc82fea6a155c5514aeb0f7cbe4523506cb28a332b0cf2b1daecbf6ec867f0cbfb08c0f7c0795d16
7
- data.tar.gz: 53c823ee7b120e983cd9281245b9b4118953c9aa595c0a4807e960c4b0014a655613abb6a170779e8e51598ba1a12bbdd9c2a13d2050ae68d5aab26670d5fce5
6
+ metadata.gz: 13ec315f26b5ca9f02b904ae5ddbcb25acd4a96043a3354135f4b37e43fff755714701f3b1fbaff91973c0decfe8ecee4718ada6a85c1c5eddb48c4d76aaa806
7
+ data.tar.gz: 3a2f82c463b13993a5e6de5fbec54a83164dde8d9a698ab457d7745d952de7e7d9a11422b3a999b87cd54480b4f1e9cec6d7b825c4110c23a056b60c400cd8ef
data/CHANGELOG.md CHANGED
@@ -1,4 +1,12 @@
1
- ## UNRELEASED
1
+ ## 0.9.33
2
+
3
+ * allow batch actions to return files, data or redirects
4
+
5
+ ## 0.9.32
6
+
7
+ * define default order by giving `default_order: '<sql order>'` option to `tabulatr_for`
8
+
9
+ ## 0.9.21?
2
10
  * Rename `filter` option of `table_for` to `filters` to not conceal the
3
11
  `table_option` also named `filter`.
4
12
 
@@ -26,9 +26,16 @@
26
26
  i.icon-cog.glyphicon.glyphicon-cog.fa.fa-cog>
27
27
  i.icon-caret-down.glyphicon.glyphicon-chevron-down.fa.fa-caret-down
28
28
  ul.dropdown-menu role="menu" aria-labelledby="dLabel" data-confirm-text=t('tabulatr.batch_confirm_text')
29
- - table_options[:batch_actions].each do |key, label|
29
+ - table_options[:batch_actions].each do |key, data|
30
+ - if data.is_a?(String)
31
+ - label = data
32
+ - download = false
33
+ - else
34
+ - label = data[:text]
35
+ - download = !!data[:download]
30
36
  li
31
37
  = link_to label, '#', class: "batch-action-inputs", data: { \
32
38
  "do-batch-action-name" => iname, \
33
39
  "do-batch-action" => key, \
34
- "table-id" => table_id }
40
+ "table-id" => table_id, \
41
+ "download" => download }
@@ -55,7 +55,8 @@ class Tabulatr::Data
55
55
  apply_sorting(sort_params params)
56
56
  join_required_tables(params)
57
57
 
58
- execute_batch_actions(batch_params(params), check_params(params))
58
+ batch_result = execute_batch_actions(batch_params(params), check_params(params))
59
+ return batch_result if batch_result.is_a? Tabulatr::Responses::DirectResponse
59
60
 
60
61
  pagination = compute_pagination(params[:page], params[:pagesize])
61
62
  apply_pagination(pagination.slice(:offset, :pagesize))
@@ -25,11 +25,21 @@ class Tabulatr::Data::Invoker
25
25
  def initialize(batch_action, ids)
26
26
  @batch_action = batch_action.to_sym
27
27
  @ids = ids
28
+ @result = nil
28
29
  end
29
30
 
30
31
  def method_missing(name, *args, &block)
31
- if @batch_action == name
32
- yield(@ids)
32
+ @result ||= if @batch_action == name
33
+ s = yield(@ids)
34
+ if s.is_a?(Hash) && s[:data]
35
+ Tabulatr::Responses::RawResponse.new(s[:data])
36
+ elsif s.is_a?(Hash) && s[:file]
37
+ Tabulatr::Responses::FileResponse.new(s[:file], filename: s[:filename])
38
+ elsif s.is_a?(Hash) && s[:url]
39
+ Tabulatr::Responses::RedirectResponse.new(s[:url], ids: @ids)
40
+ else
41
+ s
42
+ end
33
43
  end
34
44
  end
35
45
  end
@@ -28,17 +28,33 @@ class ActionController::Base
28
28
 
29
29
  def tabulatr_for(relation, tabulatr_data_class: nil, serializer: nil, render_action: nil, default_order: nil, locals: {}, &block)
30
30
  klass = relation.respond_to?(:klass) ? relation.klass : relation
31
+ locals[:current_user] ||= current_user if respond_to?(:current_user)
32
+ if batch_params(klass, params).present?
33
+ response = klass.tabulatr(relation, tabulatr_data_class).data_for_table(params, locals: locals, controller: self, &block)
34
+ case response
35
+ when Tabulatr::Responses::RawResponse
36
+ return send_data response.data, response.options
37
+ when Tabulatr::Responses::FileResponse
38
+ return send_file response.file, response.options
39
+ when Tabulatr::Responses::RedirectResponse
40
+ return redirect_to response.url, ids: response.ids
41
+ else records = response
42
+ end
43
+ end
44
+
31
45
  respond_to do |format|
32
46
  format.json {
33
- locals[:current_user] ||= current_user if respond_to?(:current_user)
34
- records = klass.tabulatr(relation, tabulatr_data_class).data_for_table(params, locals: locals, controller: self, default_order: default_order, &block)
47
+ records ||= klass.tabulatr(relation, tabulatr_data_class).data_for_table(params, locals: locals, controller: self, &block)
35
48
  render json: records.to_tabulatr_json(serializer)
36
- records
37
49
  }
38
50
  format.html {
39
51
  render action: render_action || action_name
40
- nil
41
52
  }
42
53
  end
43
54
  end
55
+
56
+ def batch_params(klass, params)
57
+ params["#{Tabulatr::Utility.formatted_name(klass.name)}_batch"]
58
+ end
59
+
44
60
  end
@@ -0,0 +1,2 @@
1
+ class Tabulatr::Responses::DirectResponse
2
+ end
@@ -0,0 +1,8 @@
1
+ class Tabulatr::Responses::FileResponse < Tabulatr::Responses::DirectResponse
2
+ attr_accessor :file, :options
3
+
4
+ def initialize(file, options={})
5
+ @file = file
6
+ @options = options
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ class Tabulatr::Responses::RawResponse < Tabulatr::Responses::DirectResponse
2
+ attr_accessor :data, :options
3
+
4
+ def initialize(data, options={})
5
+ @data = data
6
+ @options = options
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ class Tabulatr::Responses::RedirectResponse < Tabulatr::Responses::DirectResponse
2
+ attr_accessor :url, :ids
3
+
4
+ def initialize(url, ids: nil)
5
+ @url = url
6
+ @ids = ids
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ module Tabulatr::Responses
2
+ end
3
+
4
+ require_relative './direct_response'
5
+ require_relative './file_response'
6
+ require_relative './raw_response'
7
+ require_relative './redirect_response'
@@ -22,5 +22,5 @@
22
22
  #++
23
23
 
24
24
  module Tabulatr
25
- VERSION = "0.9.32"
25
+ VERSION = "0.9.33"
26
26
  end
data/lib/tabulatr.rb CHANGED
@@ -55,6 +55,7 @@ require 'tabulatr/data/data'
55
55
  require 'tabulatr/json_builder'
56
56
  require 'tabulatr/params_builder'
57
57
  require 'tabulatr/generators/railtie' if defined?(Rails)
58
+ require 'tabulatr/responses/responses'
58
59
 
59
60
  #--
60
61
  # Mainly Monkey Patching...
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tabulatr2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.32
4
+ version: 0.9.33
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Horn
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-10-26 00:00:00.000000000 Z
13
+ date: 2017-11-03 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -165,6 +165,11 @@ files:
165
165
  - lib/tabulatr/renderer/columns_from_block.rb
166
166
  - lib/tabulatr/renderer/filter.rb
167
167
  - lib/tabulatr/renderer/renderer.rb
168
+ - lib/tabulatr/responses/direct_response.rb
169
+ - lib/tabulatr/responses/file_response.rb
170
+ - lib/tabulatr/responses/raw_response.rb
171
+ - lib/tabulatr/responses/redirect_response.rb
172
+ - lib/tabulatr/responses/responses.rb
168
173
  - lib/tabulatr/utility/request_data_not_included_error.rb
169
174
  - lib/tabulatr/utility/unexpected_search_result_error.rb
170
175
  - lib/tabulatr/utility/utility.rb