simple-datatable 0.0.1 → 0.0.6

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
  SHA256:
3
- metadata.gz: 5f568f1a7e3f5f96f01d92ee18a26ae60a6e6ea7d2f59f472f683199160a58b8
4
- data.tar.gz: 23577023127b68cbaf1ec89b78a0290f6fcd524f03fa44ec8ae6904d60e7a467
3
+ metadata.gz: 6546720f990be32ef557c2db9e4d4b311a85c31a3afe7c3053d5673ad180ee36
4
+ data.tar.gz: a8d92d1c1da51150d823313c8ac93f2f78e84f96ac5c822d7c90cec52094ebb1
5
5
  SHA512:
6
- metadata.gz: 8721b06b947fa709765e2937b65105174fd5652ff1c70c8bb499f2aab1ce9e27a55d31b531455af6a6abe8eb170d474c130b7e35f9cd09a112244ac78045d10f
7
- data.tar.gz: 3f46b454fbad88cf7550fe72e9d28a249f13b43559de74a53d9d65701eb68764a528e983ed8c2f27c5a85717b222a2e827920bd71749f42983013c83a17adecc
6
+ metadata.gz: fca861d0c1fc1e2dec43980bdf5baae3b708ce7104b81d3477e4870a6eb05226aa533fe048d96842d8ff55e5192db82d62fcc0cc7d03fabe8bb969cfcbc10818
7
+ data.tar.gz: df26f00ff3eb2730d94e054167dd111f627c849599023e04b39574767288ce47a7d86bf28e57705ad58ccf168ac220f35a8355cbb128220ba39c109fde9afa1a
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in simple-datatable.gemspec
4
+
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Datatable
1
+ # Simple Datatable
2
2
  [![GitHub version](https://badge.fury.io/gh/apptec-cl%2Fdatatable.svg)](https://badge.fury.io/gh/apptec-cl%2Fdatatable)
3
3
 
4
4
  ## Description
@@ -50,20 +50,83 @@ in your file ```application.js```
50
50
  add gem
51
51
 
52
52
  ```
53
- gem 'datatable', :git => 'git@github.com:apptec-cl/datatable.git'
53
+ gem 'simple-datatable'
54
54
 
55
55
  ```
56
56
 
57
- Generate model with structure datatables, open your terminal and write:
57
+ It also depends on:
58
+
58
59
 
59
60
  ```
60
- $ datatable g model_name
61
+ gem 'will_paginate', '~> 3.1.0'
62
+
61
63
  ```
62
64
 
63
65
  Automatically we are created a folder with the structure of the tables ```app/datatables```.
64
66
 
65
67
  ## Usage
66
68
 
69
+
70
+ Generate model with structure datatables, open your terminal and write:
71
+
72
+ ```
73
+ $ datatable g model_name
74
+ ```
75
+
76
+
77
+ Example Controller:
78
+
79
+ ```
80
+ # Query with data
81
+ @clients = Client.all
82
+
83
+ # Format table
84
+ data = %w[clients.id clients.name clients.lastname clients.address]
85
+ respond_to do |format|
86
+ format.html
87
+ format.json { render json: ClientsDatatable.new(view_context, @clients, data) }
88
+ end
89
+
90
+ ```
91
+
92
+ View:
93
+
94
+ ```
95
+ <table id="datatable" class="table datatable_table table-hover" role="grid" data-source="<%= clients_path(format: :json) %>" cellspacing="0">
96
+ <thead>
97
+ <tr>
98
+ <th>ID</th>
99
+ <th>Name</th>
100
+ <th>Last Name</th>
101
+ <th>Address</th>
102
+ </tr>
103
+ </thead>
104
+
105
+ <tbody>
106
+ <!-- leave blank -->
107
+ </tbody>
108
+ </table>
109
+ ```
110
+
111
+ Folder datatable:
112
+
113
+ ```
114
+ class ClientsDatatable < ApplicationDatatable
115
+ private
116
+ def data
117
+ dimension.map do |dimension|
118
+ [
119
+ # Add your attributes
120
+ dimension.id,
121
+ dimension.name,
122
+ dimension.lastname,
123
+ dimension.address,
124
+ ]
125
+ end
126
+ end
127
+ end
128
+ ```
129
+
67
130
  ### Quickstart
68
131
 
69
132
 
@@ -73,4 +136,4 @@ Automatically we are created a folder with the structure of the tables ```app/d
73
136
  2. Create your feature branch (`git checkout -b my-new-feature`)
74
137
  3. Commit your changes (`git commit -am 'Add some feature'`)
75
138
  4. Push to the branch (`git push origin my-new-feature`)
76
- 5. Create a new Pull Request
139
+ 5. Create a new Pull Request
@@ -4,6 +4,8 @@ module Datatable
4
4
  include Rails.application.routes.url_helpers
5
5
  include ActionView::Helpers::TagHelper
6
6
  include ActionView::Helpers::NumberHelper
7
+ include ActionView::Helpers::SanitizeHelper
8
+
7
9
  delegate :params, :h, :link_to, :image_tag, :current_user, to: :@view
8
10
 
9
11
  def initialize(view, model, items, order_items=nil, pre_filter=false, filter='')
@@ -22,7 +24,7 @@ module Datatable
22
24
  sEcho: params[:draw].to_i,
23
25
  iTotalRecords: @model.count,
24
26
  iTotalDisplayRecords: dimension.total_entries,
25
- aaData: data
27
+ aaData: sanitize_data(data)
26
28
  }
27
29
  end
28
30
 
@@ -95,5 +97,15 @@ module Datatable
95
97
  asset = asset.get_asset
96
98
  end
97
99
 
100
+ def sanitize_data data
101
+ # sanitize data, when the persistent (or stored) Cross-site scripting vulnerability
102
+ data.each do |row|
103
+ row.each_with_index do |attribute, index|
104
+ row[index] = sanitize(row[index]) if row[index].is_a? String
105
+ end
106
+ end
107
+ data
108
+ end
109
+
98
110
  end
99
111
  end
@@ -4,7 +4,7 @@ module Datatable
4
4
 
5
5
  def initialize(name)
6
6
  @name = name
7
- @dirname = 'datatables'
7
+ @dirname = 'app/datatables'
8
8
  end
9
9
 
10
10
  def up
@@ -12,6 +12,7 @@ module Datatable
12
12
  create_folder
13
13
  create_principal
14
14
  create_file
15
+ copy_datatable_js
15
16
  end
16
17
 
17
18
  def templates
@@ -25,21 +26,33 @@ module Datatable
25
26
  end
26
27
 
27
28
  def create_principal
29
+ return if File.exist?("#{@dirname}/application_datatable.rb")
28
30
  result = generate_template('application_datatable.erb')
29
31
  puts result
30
- File.open("datatables/application_datatable.rb", 'w') { |file| file.write(result) }
32
+ File.open("#{@dirname}/application_datatable.rb", 'w') { |file| file.write(result) }
31
33
  puts "Created principal class application_datatable.rb"
32
34
  end
33
35
 
34
36
  def create_file
37
+ if File.exist?("#{@dirname}/#{@name.downcase}_datatable.rb")
38
+ puts "Ya existe el archivo: #{@dirname}/#{@name.downcase}_datatable.rb, intenta con otro nombre"
39
+ return
40
+ end
35
41
  result = generate_template('template_datatable.erb')
36
42
  puts result
37
- File.open("datatables/#{@name.downcase}_datatable.rb", 'w') { |file| file.write(result) }
43
+ File.open("#{@dirname}/#{@name.downcase}_datatable.rb", 'w') { |file| file.write(result) }
38
44
  puts "Created new file #{@name}_datatable.rb in folder datatables"
39
45
  end
40
46
 
47
+ def copy_datatable_js
48
+ result = generate_template('datatable.coffee')
49
+ puts result
50
+ File.open("app/assets/javascripts/datatable.coffee", 'w') { |file| file.write(result) }
51
+ puts "Created new file datatable.coffee in folder :app/assets/stylesheets/"
52
+ end
53
+
41
54
  def generate_template name_template
42
55
  ERB.new(File.read("#{templates}/#{name_template}"), nil, '-').result(binding)
43
56
  end
44
57
  end
45
- end
58
+ end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = %q{simple-datatable}
3
- spec.version = "0.0.1"
3
+ spec.version = "0.0.6"
4
4
  spec.date = %q{2019-11-24}
5
5
  spec.summary = %q{awesome_gem is the best datatable Rails Gem}
6
6
  spec.authors = ["DevTeam AppTec"]
@@ -9,10 +9,11 @@ Gem::Specification.new do |spec|
9
9
  spec.homepage = "https://github.com/apptec-cl/simple-datatable"
10
10
  spec.license = "MIT"
11
11
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
12
- spec.bindir = "exe"
12
+ spec.bindir = 'exe'
13
13
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
14
- spec.require_paths = ["lib", "templates"]
15
- spec.add_development_dependency "bundler", "~> 1.7"
16
- spec.add_development_dependency "rake", "~> 10.0"
14
+ spec.require_paths = ['lib', 'templates']
15
+ spec.add_development_dependency 'bundler', '~> 1.7'
16
+ spec.add_development_dependency 'rake', '~> 10.0'
17
17
  spec.add_development_dependency 'rspec'
18
+ spec.add_development_dependency 'will_paginate', '~> 3.1.0'
18
19
  end
@@ -1,2 +1,5 @@
1
+ require 'datatable'
2
+ require 'datatable/application'
3
+
1
4
  class ApplicationDatatable < Datatable::Application
2
5
  end
@@ -0,0 +1,79 @@
1
+ document.addEventListener 'turbolinks:load', ->
2
+ $('.filter-datatable-tabs').on 'click', ->
3
+ filter = $(this).data('id')
4
+ table = $(this).closest('.datatable-container').find('.datatable_table')
5
+ if table.find('.status_cell').length > 0
6
+ position = table.find('.status_cell').prop('cellIndex')
7
+ #table.DataTable().ajax.reload
8
+ table.DataTable().column( position ).search( filter ).draw()
9
+ if table.find('.fee_status').length > 0
10
+ #table.DataTable().ajax.reload
11
+ table.DataTable().column(0).search( filter ).draw()
12
+ if $('.datatable_table').length > 0
13
+ $('.datatable_table').each () ->
14
+ if !$.fn.DataTable.isDataTable( "#"+$(this).prop("id") )
15
+ set_datatable($(this))
16
+ set_datatable = (data)->
17
+ if !$.fn.DataTable.isDataTable( "#"+data.prop("id") )
18
+ table = $("#"+data.prop("id"))
19
+ datatable_table = table.DataTable({
20
+ pagingType: "full_numbers"
21
+ processing: true
22
+ stateSave: true
23
+ serverSide: true
24
+ responsive: true
25
+ ajax:
26
+ url: table.data('source')
27
+ type: 'GET'
28
+ language:
29
+ 'sProcessing': 'Procesando...'
30
+ 'sLengthMenu': 'Mostrar _MENU_ registros'
31
+ 'sZeroRecords': 'No se encontraron resultados'
32
+ 'sEmptyTable': 'Ningún dato disponible en esta tabla'
33
+ 'sInfo': 'Mostrando registros del _START_ al _END_ de un total de _TOTAL_ registros'
34
+ 'sInfoEmpty': 'Mostrando registros del 0 al 0 de un total de 0 registros'
35
+ 'sInfoFiltered': ''
36
+ 'sInfoPostFix': ''
37
+ 'sSearch': 'Buscar:'
38
+ 'sUrl': ''
39
+ 'sInfoThousands': ','
40
+ 'sLoadingRecords': 'Cargando...'
41
+ 'oPaginate':
42
+ 'sFirst': 'Primero'
43
+ 'sLast': 'Último'
44
+ 'sNext': 'Siguiente'
45
+ 'sPrevious': 'Anterior'
46
+ 'oAria':
47
+ 'sSortAscending': ': Activar para ordenar la columna de manera ascendente'
48
+ 'sSortDescending': ': Activar para ordenar la columna de manera descendente'
49
+ })
50
+ switch(data.prop("id"))
51
+ when "customer_datatable"
52
+ yadcf.init(datatable_table, [
53
+ {
54
+ column_number: 0
55
+ filter_type: "text"
56
+ filter_default_label: "Escribir Nombre"
57
+ filter_container_id: "filter_1"
58
+ }
59
+ {
60
+ column_number: 1
61
+ filter_type: "text"
62
+ filter_default_label: "Escribir RUT"
63
+ filter_container_id: "filter_2"
64
+ }
65
+ {
66
+ column_number: 2
67
+ filter_type: "none"
68
+ filter_container_id: "filter_3"
69
+ }
70
+ ])
71
+ filter = table.closest('.datatable-container').find('.filter-datatable-tabs').first().data('id')
72
+ position = table.find('.status_cell').prop('cellIndex')
73
+ if filter
74
+ datatable_table.column( position ).search( filter ).draw()
75
+ document.addEventListener "turbolinks:before-cache", ->
76
+ if $('.datatable_table').length > 0
77
+ $('.datatable_table').each () ->
78
+ datatable = $("#"+$(this).prop("id")).DataTable()
79
+ datatable.destroy()
@@ -1,4 +1,4 @@
1
- class <%= @name.capitalize %>_Datatable < ApplicationDatatable
1
+ class <%= @name.capitalize %>Datatable < ApplicationDatatable
2
2
  private
3
3
  def data
4
4
  dimension.map do |dimension|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple-datatable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - DevTeam AppTec
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: will_paginate
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 3.1.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 3.1.0
55
69
  description:
56
70
  email:
57
71
  - soporte@apptec.cl
@@ -60,6 +74,7 @@ executables:
60
74
  extensions: []
61
75
  extra_rdoc_files: []
62
76
  files:
77
+ - Gemfile
63
78
  - README.md
64
79
  - exe/datatable
65
80
  - lib/datatable.rb
@@ -68,6 +83,7 @@ files:
68
83
  - lib/datatable/runner.rb
69
84
  - simple-datatable.gemspec
70
85
  - templates/application_datatable.erb
86
+ - templates/datatable.coffee
71
87
  - templates/template_datatable.erb
72
88
  homepage: https://github.com/apptec-cl/simple-datatable
73
89
  licenses: