zuora_connect 1.1.0 → 1.1.1
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/lib/generators/datatable_generator.rb +91 -0
- data/lib/zuora_connect/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d535c9cd41021000e90b81f1c061941f17125d2
|
4
|
+
data.tar.gz: cc4702738a1b9e007011076393afbd855d1fbeae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b1fd7147209f29d4bc413797c9796e2053fea0f167e2f9d5146ae98c076c6a7b0805fd8fe01ec8779274cd369aa7eadbf3454260ce1cc0413da498a189ab7e1
|
7
|
+
data.tar.gz: b75f6f660fe9f1ace17e18e90816c06e481878c34430f28de08b2810c209faf1a96f9706891972f461cf0d1a236c35a37b5ac5d9461ce3465141965ce4bcb029
|
@@ -0,0 +1,91 @@
|
|
1
|
+
class DatatableGenerator < Rails::Generators::Base
|
2
|
+
def create_datatable_file
|
3
|
+
|
4
|
+
|
5
|
+
columns = Object.const_defined?("#{class_name}") ? "#{class_name}".constantize.send("column_names") : []
|
6
|
+
column_string = ""
|
7
|
+
columns.each do |col|
|
8
|
+
column_string << "\"#{plural_name}\" => #{plural_name.singularize}.#{col},"
|
9
|
+
end
|
10
|
+
|
11
|
+
create_file "app/datatables/#{file_name}_datatable.rb", <<-FILE
|
12
|
+
class #{class_name}Datatable
|
13
|
+
delegate :controller, :url_for, :render, :params, :image_tag, :h, :link_to, :api_call_path, :number_to_currency, to: :@view
|
14
|
+
|
15
|
+
def initialize(view)
|
16
|
+
@view = view
|
17
|
+
@total_#{plural_name} = #{class_name}.count(:all)
|
18
|
+
@#{plural_name} = #{class_name}.select(select_string).where(search_string, search: "%#{params[:sSearch].to_s.downcase}%").order("#{sort_column} #{sort_direction}")
|
19
|
+
@filtered_total = @#{plural_name}.size
|
20
|
+
@#{plural_name} = @#{plural_name}.page(page).per_page(per_page)
|
21
|
+
end
|
22
|
+
|
23
|
+
def as_json(options = {})
|
24
|
+
{
|
25
|
+
sEcho: params[:sEcho].to_i,
|
26
|
+
iTotalDisplayRecords: @filtered_total,
|
27
|
+
aaData: data,
|
28
|
+
iTotalRecords: @total_#{plural_name},
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
def data
|
34
|
+
@#{plural_name}.map do |#{plural_name.singularize}|
|
35
|
+
{
|
36
|
+
DT_RowId: product.id.to_s,
|
37
|
+
DT_RowClass: nil,
|
38
|
+
DT_RowAttr: { },
|
39
|
+
#{column_string}
|
40
|
+
#{plural_name}_actions: actions(#{plural_name.singularize}),
|
41
|
+
}
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def actions(#{plural_name.singularize})
|
46
|
+
render(:partial=>"#{plural_name}/actions.html.erb", locals: { #{plural_name.singularize}: #{plural_name.singularize}} , :formats => [:html]) if params[:table_view_mode] == 'table'
|
47
|
+
end
|
48
|
+
|
49
|
+
def display_time(time)
|
50
|
+
return !time.to_s.blank? ? Time.parse(time.to_s).strftime("%m/%d/%y %I:%M:%S %p") : ''
|
51
|
+
end
|
52
|
+
|
53
|
+
def page
|
54
|
+
params[:iDisplayStart].to_i/per_page + 1
|
55
|
+
end
|
56
|
+
|
57
|
+
def per_page
|
58
|
+
params[:iDisplayLength].to_i > 0 ? params[:iDisplayLength].to_i : 10
|
59
|
+
end
|
60
|
+
|
61
|
+
def sort_column
|
62
|
+
col = [*0..params[:iColumns].to_i-1].map{|i| params["mDataProp_#{i}"].gsub("__", ".") if params["bSortable_#{i}"] != 'false' }[params[:iSortCol_0].to_i]
|
63
|
+
if !col.blank?
|
64
|
+
object, field = col.split('.')
|
65
|
+
if !field.blank? && !object.blank?
|
66
|
+
map = {"#{class_name}" => #{class_name}}
|
67
|
+
field_type = map[object.classify].column_for_attribute(field).type
|
68
|
+
return [:string, :text].include?(field_type) ? "lower(#{col})" : col
|
69
|
+
else
|
70
|
+
return col
|
71
|
+
end
|
72
|
+
else
|
73
|
+
return "#{plural_name}.id"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def sort_direction
|
78
|
+
params[:sSortDir_0] == "asc" ? "asc" : "desc"
|
79
|
+
end
|
80
|
+
|
81
|
+
def search_string
|
82
|
+
"to_char(#{plural_name}.id, '999999999')"
|
83
|
+
end
|
84
|
+
|
85
|
+
def select_string
|
86
|
+
"#{plural_name}.*"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
FILE
|
90
|
+
end
|
91
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zuora_connect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Connect Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02-
|
11
|
+
date: 2017-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord-session_store
|
@@ -144,6 +144,7 @@ files:
|
|
144
144
|
- db/migrate/20161024162319_add_tokens_to_app_instance.rb
|
145
145
|
- db/migrate/20161024220705_add_token_to_app_instance.rb
|
146
146
|
- db/migrate/20170131211919_add_sessions_table.rb
|
147
|
+
- lib/generators/datatable_generator.rb
|
147
148
|
- lib/tasks/zuora_connect_tasks.rake
|
148
149
|
- lib/zuora_connect.rb
|
149
150
|
- lib/zuora_connect/configuration.rb
|