simple-datatable 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +76 -0
- data/exe/datatable +10 -0
- data/lib/datatable.rb +15 -0
- data/lib/datatable/application.rb +99 -0
- data/lib/datatable/generator.rb +45 -0
- data/lib/datatable/runner.rb +41 -0
- data/simple-datatable.gemspec +18 -0
- data/templates/application_datatable.erb +2 -0
- data/templates/template_datatable.erb +10 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5f568f1a7e3f5f96f01d92ee18a26ae60a6e6ea7d2f59f472f683199160a58b8
|
4
|
+
data.tar.gz: 23577023127b68cbaf1ec89b78a0290f6fcd524f03fa44ec8ae6904d60e7a467
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8721b06b947fa709765e2937b65105174fd5652ff1c70c8bb499f2aab1ce9e27a55d31b531455af6a6abe8eb170d474c130b7e35f9cd09a112244ac78045d10f
|
7
|
+
data.tar.gz: 3f46b454fbad88cf7550fe72e9d28a249f13b43559de74a53d9d65701eb68764a528e983ed8c2f27c5a85717b222a2e827920bd71749f42983013c83a17adecc
|
data/README.md
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
# 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
|
data/exe/datatable
ADDED
data/lib/datatable.rb
ADDED
@@ -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,45 @@
|
|
1
|
+
module Datatable
|
2
|
+
class Generator
|
3
|
+
attr_accessor :name
|
4
|
+
|
5
|
+
def initialize(name)
|
6
|
+
@name = name
|
7
|
+
@dirname = '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("datatables/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("datatables/#{@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 generate_template name_template
|
42
|
+
ERB.new(File.read("#{templates}/#{name_template}"), nil, '-').result(binding)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
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,18 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = %q{simple-datatable}
|
3
|
+
spec.version = "0.0.1"
|
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
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple-datatable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
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
|
+
description:
|
56
|
+
email:
|
57
|
+
- soporte@apptec.cl
|
58
|
+
executables:
|
59
|
+
- datatable
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- README.md
|
64
|
+
- exe/datatable
|
65
|
+
- lib/datatable.rb
|
66
|
+
- lib/datatable/application.rb
|
67
|
+
- lib/datatable/generator.rb
|
68
|
+
- lib/datatable/runner.rb
|
69
|
+
- simple-datatable.gemspec
|
70
|
+
- templates/application_datatable.erb
|
71
|
+
- templates/template_datatable.erb
|
72
|
+
homepage: https://github.com/apptec-cl/simple-datatable
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
- templates
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubygems_version: 3.0.4
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Datatable Ruby gem for Rails.
|
96
|
+
test_files: []
|