simple-datatable 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ac0671db4d33ba215dc786dfcf3041729065a45e2960a5fb1c348640f512230b
4
+ data.tar.gz: 3f9a4d3f7ed75a0449205ff59bef8060cd6d6446c32a42dfb181a2f7a6a0ac67
5
+ SHA512:
6
+ metadata.gz: 7ae9fb46c1f3b21ab8d099db4927056ad659bd2ad1fcd7ea92c3d9219416cac4092a86ea9dafb97982374b8608283a845616ed1a7290d0e06ce5d524748230ae
7
+ data.tar.gz: a0a4ea2292663121f72417012fe320a02cf5d71b5a4bb0215d922469761dc245ec90938b6c1498bd53ddf12d65717afe6fe71815ce4918bbaa25679fbf290f51
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in simple-datatable.gemspec
4
+
@@ -0,0 +1,76 @@
1
+ # Simple Datatable
2
+ [![GitHub version](https://badge.fury.io/gh/apptec-cl%2Fdatatable.svg)](https://badge.fury.io/gh/apptec-cl%2Fdatatable)
3
+
4
+ ## Description
5
+
6
+ Datatables development to Apptec, we add advanced interaction controls to your HTML tables the free & easy way in ruby on rails, this gem gives you a good starting with datatables.
7
+
8
+ ```
9
+ ___ ___ ___ ___ ___
10
+ / /\ / /\ / /\ ___ / /\ / /\
11
+ / /::\ / /::\ / /::\ / /\ / /:/_ / /:/
12
+ / /:/\:\ / /:/\:\ / /:/\:\ / /:/ / /:/ /\ / /:/
13
+ / /:/~/::\ / /:/~/:/ / /:/~/:/ / /:/ / /:/ /:/_ / /:/ ___
14
+ /__/:/ /:/\:\ /__/:/ /:/ /__/:/ /:/ / /::\ /__/:/ /:/ /\ /__/:/ / /\
15
+ \ \:\/:/__\/ \ \:\/:/ \ \:\/:/ /__/:/\:\ \ \:\/:/ /:/ \ \:\ / /:/
16
+ \ \::/ \ \::/ \ \::/ \__\/ \:\ \ \::/ /:/ \ \:\ /:/
17
+ \ \:\ \ \:\ \ \:\ \ \:\ \ \:\/:/ \ \:\/:/
18
+ \ \:\ \ \:\ \ \:\ \__\/ \ \::/ \ \::/
19
+ \__\/ \__\/ \__\/ \__\/ \__\/
20
+
21
+ ```
22
+
23
+
24
+ ## Requirements
25
+
26
+ - Ruby
27
+ - Rails
28
+ - datatables
29
+ - Human
30
+
31
+ ## Installation
32
+
33
+ It is necessary to install lib datatable from:
34
+
35
+ [https://datatables.net/download/index](https://datatables.net/download/index)
36
+
37
+ in your file ```application.js```
38
+
39
+
40
+ ```
41
+
42
+ //= require dataTables/jquery.dataTables
43
+ //= require dataTables/jquery.dataTables.yadcf
44
+ //= require dataTables/dataTables.bootstrap4
45
+ //= require dataTables/dataTables.responsive
46
+ //= require dataTables/responsive.bootstrap4
47
+
48
+ ```
49
+
50
+ add gem
51
+
52
+ ```
53
+ gem 'datatable', :git => 'git@github.com:apptec-cl/datatable.git'
54
+
55
+ ```
56
+
57
+ Generate model with structure datatables, open your terminal and write:
58
+
59
+ ```
60
+ $ datatable g model_name
61
+ ```
62
+
63
+ Automatically we are created a folder with the structure of the tables ```app/datatables```.
64
+
65
+ ## Usage
66
+
67
+ ### Quickstart
68
+
69
+
70
+ ## Contributing
71
+
72
+ 1. Fork it ( https://github.com/apptec-cl/datatable/fork )
73
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
74
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
75
+ 4. Push to the branch (`git push origin my-new-feature`)
76
+ 5. Create a new Pull Request
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "datatable"
4
+
5
+ begin
6
+ Datatable::Runner.new(ARGV).execute
7
+ rescue Exception => e
8
+ puts e.message
9
+ exit 0
10
+ end
@@ -0,0 +1,15 @@
1
+ # require "datatable/application"
2
+ require "datatable/generator"
3
+ require "datatable/runner"
4
+ require 'erb'
5
+ require 'fileutils'
6
+
7
+ module Datatable
8
+ def self.root
9
+ File.dirname __dir__
10
+ end
11
+
12
+ def self.templates
13
+ File.join root, 'templates'
14
+ end
15
+ end
@@ -0,0 +1,99 @@
1
+ module Datatable
2
+ class Application
3
+ include AbstractController::Rendering
4
+ include Rails.application.routes.url_helpers
5
+ include ActionView::Helpers::TagHelper
6
+ include ActionView::Helpers::NumberHelper
7
+ delegate :params, :h, :link_to, :image_tag, :current_user, to: :@view
8
+
9
+ def initialize(view, model, items, order_items=nil, pre_filter=false, filter='')
10
+ @view = view
11
+ if pre_filter
12
+ @model= model.where(filter)
13
+ else
14
+ @model = model
15
+ end
16
+ @items = items
17
+ @order = order_items.blank? ? items : order_items
18
+ end
19
+
20
+ def as_json(options = {})
21
+ {
22
+ sEcho: params[:draw].to_i,
23
+ iTotalRecords: @model.count,
24
+ iTotalDisplayRecords: dimension.total_entries,
25
+ aaData: data
26
+ }
27
+ end
28
+
29
+ def set_datatable_button dimension, partial_path
30
+ ApplicationController.new.render_to_string(partial: partial_path, locals: { dimension: dimension })
31
+ end
32
+
33
+ private
34
+
35
+ def dimension
36
+ @dimension ||= fetch_dimension
37
+ end
38
+
39
+ def fetch_dimension
40
+ dimension = @model
41
+ search = ''
42
+
43
+ @items.each_with_index do |val, key|
44
+ search << (key == 0 ? val+' LIKE :search ' : 'OR ' + val + ' LIKE :search ')
45
+ end
46
+
47
+ if params[:order]
48
+ params[:order].each do |key, val|
49
+ column_for_order = val[:column].to_i
50
+ dimension = dimension.order("#{@order[column_for_order]} #{val[:dir]}")
51
+ end
52
+ end
53
+
54
+ if !params[:search][:value].blank?
55
+ dimension = dimension.where(search, search: "%#{params[:search][:value]}%")
56
+ end
57
+
58
+ params[:columns].each do |key,column|
59
+ if !column[:search][:value].blank?
60
+ dimension = dimension.where(@items[column[:data].to_i] + ' LIKE :search ', search: "%#{column[:search][:value]}%")
61
+ end
62
+ end
63
+ dimension = dimension.page(page).per_page(per_page)
64
+ dimension
65
+ end
66
+
67
+ def page
68
+ params[:start].to_i / per_page + 1
69
+ end
70
+
71
+ def per_page
72
+ params[:length].to_i > 0 ? params[:length].to_i : 10
73
+ end
74
+
75
+ def imagen_data value, url, default
76
+ if value.url(:thumb) == url
77
+ image_tag default, class: "img-circle", size: "60", style: "border: 5px solid #FFF;"
78
+ else
79
+ image_tag value.url(:thumb), class: "img-circle", size: "60", style: "border: 5px solid #FFF;"
80
+ end
81
+ end
82
+
83
+ def miles value
84
+ number_with_delimiter(value, delimiter: ".")
85
+ end
86
+
87
+ def rut_format value
88
+ spliter = value.split("-")
89
+ formated = number_with_delimiter(spliter[0], delimiter: ".")
90
+ formated.to_s+"-"+spliter[1].to_s
91
+ end
92
+
93
+ def get_asset id
94
+ asset = AssetConsumer.new current_user.customer_id, id
95
+ asset = asset.get_asset
96
+ end
97
+
98
+ end
99
+ end
@@ -0,0 +1,52 @@
1
+ module Datatable
2
+ class Generator
3
+ attr_accessor :name
4
+
5
+ def initialize(name)
6
+ @name = name
7
+ @dirname = 'app/datatables'
8
+ end
9
+
10
+ def up
11
+ # The first is to create folder in case it does not exist.
12
+ create_folder
13
+ create_principal
14
+ create_file
15
+ end
16
+
17
+ def templates
18
+ Datatable.templates
19
+ end
20
+
21
+ private
22
+
23
+ def create_folder
24
+ FileUtils.mkdir_p(@dirname) unless File.directory?(@dirname)
25
+ end
26
+
27
+ def create_principal
28
+ result = generate_template('application_datatable.erb')
29
+ puts result
30
+ File.open("#{@dirname}/application_datatable.rb", 'w') { |file| file.write(result) }
31
+ puts "Created principal class application_datatable.rb"
32
+ end
33
+
34
+ def create_file
35
+ result = generate_template('template_datatable.erb')
36
+ puts result
37
+ File.open("#{@dirname}/#{@name.downcase}_datatable.rb", 'w') { |file| file.write(result) }
38
+ puts "Created new file #{@name}_datatable.rb in folder datatables"
39
+ end
40
+
41
+ def copy_datatable_js
42
+ result = generate_template('datatable.coffee')
43
+ puts result
44
+ File.open("app/assets/stylesheets/datatable.coffee", 'w') { |file| file.write(result) }
45
+ puts "Created new file datatable.coffee in folder :app/assets/stylesheets/"
46
+ end
47
+
48
+ def generate_template name_template
49
+ ERB.new(File.read("#{templates}/#{name_template}"), nil, '-').result(binding)
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,41 @@
1
+ module Datatable
2
+ class Runner
3
+
4
+ MESSAGE = " ___ ___ ___ ___ ___
5
+ / /\ / /\ / /\ ___ / /\ / /\
6
+ / /::\ / /::\ / /::\ / /\ / /:/_ / /:/
7
+ / /:/\:\ / /:/\:\ / /:/\:\ / /:/ / /:/ /\ / /:/
8
+ / /:/~/::\ / /:/~/:/ / /:/~/:/ / /:/ / /:/ /:/_ / /:/ ___
9
+ /__/:/ /:/\:\ /__/:/ /:/ /__/:/ /:/ / /::\ /__/:/ /:/ /\ /__/:/ / /\
10
+ \ \:\/:/__\/ \ \:\/:/ \ \:\/:/ /__/:/\:\ \ \:\/:/ /:/ \ \:\ / /:/
11
+ \ \::/ \ \::/ \ \::/ \__\/ \:\ \ \::/ /:/ \ \:\ /:/
12
+ \ \:\ \ \:\ \ \:\ \ \:\ \ \:\/:/ \ \:\/:/
13
+ \ \:\ \ \:\ \ \:\ \__\/ \ \::/ \ \::/
14
+ \__\/ \__\/ \__\/ \__\/ \__\/
15
+
16
+
17
+ https://datatables.net/
18
+ Add advanced interaction controls to your HTML tables the free & easy way \n
19
+ \n
20
+ \n
21
+ Example: \n
22
+ datatable g model_name"
23
+ ERROR_MESSAGE = 'USAGE: datatable up APP_NAME'
24
+
25
+ def initialize(options)
26
+ @options = options
27
+ end
28
+
29
+ def execute
30
+ raise MESSAGE if @options[0] == 'h'
31
+ raise ERROR_MESSAGE unless valid?
32
+ Datatable::Generator.new(@options[1]).up
33
+ end
34
+
35
+ def valid?
36
+ # first option should always be up
37
+ return false if @options[0] != 'g'
38
+ true
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,19 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = %q{simple-datatable}
3
+ spec.version = "0.0.2"
4
+ spec.date = %q{2019-11-24}
5
+ spec.summary = %q{awesome_gem is the best datatable Rails Gem}
6
+ spec.authors = ["DevTeam AppTec"]
7
+ spec.email = ["soporte@apptec.cl"]
8
+ spec.summary = %q{Datatable Ruby gem for Rails.}
9
+ spec.homepage = "https://github.com/apptec-cl/simple-datatable"
10
+ spec.license = "MIT"
11
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
12
+ spec.bindir = 'exe'
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'
17
+ spec.add_development_dependency 'rspec'
18
+ spec.add_development_dependency 'will_paginate', '~> 3.1.0'
19
+ end
@@ -0,0 +1,5 @@
1
+ require 'datatable'
2
+ require 'datatable/application'
3
+
4
+ class ApplicationDatatable < Datatable::Application
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()
@@ -0,0 +1,10 @@
1
+ class <%= @name.capitalize %>Datatable < ApplicationDatatable
2
+ private
3
+ def data
4
+ dimension.map do |dimension|
5
+ [
6
+ # Add your attributes
7
+ ]
8
+ end
9
+ end
10
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple-datatable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - DevTeam AppTec
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-11-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
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
69
+ description:
70
+ email:
71
+ - soporte@apptec.cl
72
+ executables:
73
+ - datatable
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - Gemfile
78
+ - README.md
79
+ - exe/datatable
80
+ - lib/datatable.rb
81
+ - lib/datatable/application.rb
82
+ - lib/datatable/generator.rb
83
+ - lib/datatable/runner.rb
84
+ - simple-datatable.gemspec
85
+ - templates/application_datatable.erb
86
+ - templates/datatable.coffee
87
+ - templates/template_datatable.erb
88
+ homepage: https://github.com/apptec-cl/simple-datatable
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ - templates
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubygems_version: 3.0.4
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Datatable Ruby gem for Rails.
112
+ test_files: []