snaptable 2.2.2 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/app/assets/javascripts/snaptable/table.js +35 -31
- data/app/assets/javascripts/snaptable.js +0 -2
- data/app/views/snaptable/_search_field.html.erb +1 -1
- data/lib/snaptable/constructor/renderer.rb +20 -12
- data/lib/snaptable/constructor/sortable.rb +1 -1
- data/lib/snaptable/engine.rb +0 -1
- data/lib/snaptable/version.rb +1 -1
- metadata +23 -39
- data/app/views/snaptable/sort.js.erb +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c18ace7510d52747446fe800cbacbfd54a7a70f2cc27064df3b3ad3e854fd96f
|
4
|
+
data.tar.gz: edd3e8d33421b2b68963f3ce32c35d90caff279ee5add09a795326f59048e855
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c9468645b4c07fcb171c4fbf61b31fa8f00c53fdc21463f685ea9598239d23f8525e7a8894d1d41d9c983f970cf79e7ac2b5afcaa2e71615be7c22e5926c79d
|
7
|
+
data.tar.gz: fbdd9fe4b730a9fe85c831615788b72096d65cc5d8d2b4cb0f7f0478386fba6aeef1c4d20c872a8ae308916af9c01bf7ed4e79c8cace1e2421550e35ba7449d7
|
data/README.md
CHANGED
@@ -5,41 +5,49 @@
|
|
5
5
|
|
6
6
|
function snapifyTable(snaptable) {
|
7
7
|
|
8
|
-
var tableButtons = snaptable.
|
9
|
-
editButton = tableButtons.
|
10
|
-
deleteButton = tableButtons.
|
11
|
-
showButton = tableButtons.
|
8
|
+
var tableButtons = snaptable.querySelector(".table_buttons"),
|
9
|
+
editButton = tableButtons.querySelector("a.edit"),
|
10
|
+
deleteButton = tableButtons.querySelector("a.delete"),
|
11
|
+
showButton = tableButtons.querySelector("a.show"),
|
12
12
|
path = window.location.pathname + "/",
|
13
13
|
urlParams = new URLSearchParams(location.search),
|
14
14
|
token = urlParams.get('token');
|
15
15
|
|
16
16
|
var paramsStr = (token ? ("?token=" + token) : "")
|
17
17
|
|
18
|
-
// add ajax to the pagination
|
19
|
-
snaptable.on("click", ".pagination a", function() {
|
20
|
-
$.getScript(this.href);
|
21
|
-
return false;
|
22
|
-
});
|
23
|
-
|
24
18
|
// line clickable
|
25
|
-
snaptable.
|
26
|
-
var
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
19
|
+
snaptable.querySelector("tbody").addEventListener("click", function(e) {
|
20
|
+
var target = e.target.parentElement; // td is clicked, tr is the direct parent
|
21
|
+
var id = target.dataset.url;
|
22
|
+
if (typeof id !== "undefined" && !target.classList.contains("selected")) {
|
23
|
+
// change selected row
|
24
|
+
var selected = snaptable.querySelector("tr.selected");
|
25
|
+
if (selected) {
|
26
|
+
snaptable.querySelector("tr.selected").classList.remove("selected");
|
27
|
+
}
|
28
|
+
target.classList.add("selected");
|
29
|
+
// update the buttons
|
30
|
+
if (showButton) {
|
31
|
+
showButton.classList.add("on");
|
32
|
+
showButton.setAttribute("href", path + id + paramsStr);
|
33
|
+
}
|
34
|
+
if (editButton) {
|
35
|
+
editButton.classList.add("on");
|
36
|
+
editButton.setAttribute("href", path + id + "/edit" + paramsStr);
|
37
|
+
}
|
38
|
+
if (deleteButton) {
|
39
|
+
deleteButton.classList.add("on");
|
40
|
+
deleteButton.setAttribute("href", path + id + paramsStr);
|
41
|
+
}
|
34
42
|
}
|
35
43
|
});
|
36
44
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
var id =
|
45
|
+
if(editButton) {
|
46
|
+
snaptable.querySelector("tbody").addEventListener("dblclick", function(e) {
|
47
|
+
var target = e.target.parentElement; // td is clicked, tr is the direct parent
|
48
|
+
var id = target.dataset.url;
|
41
49
|
if ( typeof id !== "undefined" ) {
|
42
|
-
window.location = path + id + "/edit";
|
50
|
+
window.location = path + id + "/edit" + paramsStr;
|
43
51
|
}
|
44
52
|
});
|
45
53
|
}
|
@@ -48,14 +56,10 @@ function snapifyTable(snaptable) {
|
|
48
56
|
|
49
57
|
function snapifyTables() {
|
50
58
|
|
51
|
-
|
52
|
-
snapifyTable(
|
59
|
+
document.querySelectorAll(".snaptable").forEach(function(table) {
|
60
|
+
snapifyTable(table);
|
53
61
|
})
|
54
62
|
|
55
63
|
}
|
56
64
|
|
57
|
-
|
58
|
-
|
59
|
-
snapifyTables();
|
60
|
-
|
61
|
-
});
|
65
|
+
document.addEventListener("DOMContentLoaded", snapifyTables);
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<div class="search">
|
2
2
|
<p><%= t("table.search.title") %></p>
|
3
|
-
<%= form_tag request.fullpath, method: :get
|
3
|
+
<%= form_tag request.fullpath, method: :get do %>
|
4
4
|
<%= hidden_field_tag :table, presenter.table_name %>
|
5
5
|
<%= hidden_field_tag :buttons, presenter.instance_variable_get(:@buttons) %>
|
6
6
|
<%= search_field_tag :query, params[:query] %>
|
@@ -10,9 +10,6 @@ module Snaptable
|
|
10
10
|
def respond
|
11
11
|
respond_to do |format|
|
12
12
|
format.html
|
13
|
-
format.js do
|
14
|
-
render '/snaptable/sort', locals: { content: self.present(buttons: params[:buttons]) }
|
15
|
-
end
|
16
13
|
end
|
17
14
|
end
|
18
15
|
|
@@ -28,30 +25,41 @@ module Snaptable
|
|
28
25
|
|
29
26
|
def values(element)
|
30
27
|
attributes.map do |attribute|
|
31
|
-
|
32
|
-
element.send(attribute)
|
33
|
-
else
|
34
|
-
element.send(
|
28
|
+
if attribute.is_a?(Symbol) || attribute.is_a?(String)
|
29
|
+
attr_value = element.send(attribute)
|
30
|
+
else # a hash { model: :attribute }
|
31
|
+
attr_value = element.send(attribute.keys[0]).send(attribute.values[0])
|
32
|
+
attr_model = string_to_class(attribute.keys[0].to_s)
|
33
|
+
attribute = attribute.values[0]
|
35
34
|
end
|
36
|
-
format(attribute, attr_value)
|
35
|
+
format(attribute, attr_value, attr_model)
|
37
36
|
end
|
38
37
|
end
|
39
38
|
|
40
|
-
def format(attribute, attr_value)
|
39
|
+
def format(attribute, attr_value, attr_model)
|
40
|
+
attr_model ||= model
|
41
41
|
if attr_value.is_a?(Date) || attr_value.is_a?(Time) || attr_value.is_a?(DateTime)
|
42
42
|
attr_value = l(attr_value, format: :snaptable)
|
43
|
-
elsif !attr_value.nil? && attribute.to_s.in?(enums)
|
44
|
-
attr_value = t("#{
|
43
|
+
elsif !attr_value.nil? && attribute.to_s.in?(enums(attr_model))
|
44
|
+
attr_value = t("#{attr_model.model_name.i18n_key}.#{attribute.to_s.pluralize}.#{attr_value}")
|
45
45
|
end
|
46
46
|
attr_value = view_context.strip_tags(attr_value.to_s)
|
47
47
|
attr_value = view_context.truncate(attr_value, length: 40) unless options[:truncate] == false
|
48
48
|
return attr_value
|
49
49
|
end
|
50
50
|
|
51
|
-
def enums
|
51
|
+
def enums(model)
|
52
52
|
model.defined_enums.keys
|
53
53
|
end
|
54
54
|
|
55
|
+
def string_to_class(string)
|
56
|
+
begin
|
57
|
+
return string.classify.constantize
|
58
|
+
rescue NameError
|
59
|
+
return nil
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
55
63
|
end
|
56
64
|
end
|
57
65
|
end
|
@@ -4,7 +4,7 @@ module Snaptable
|
|
4
4
|
|
5
5
|
def sortable(column)
|
6
6
|
if model.reflect_on_association(column.gsub /_id/, '').nil?
|
7
|
-
view_context.link_to({sort: column, direction: direction(column), query: params[:query], paginate_key => page, table: table_name, buttons: @buttons}, {
|
7
|
+
view_context.link_to({sort: column, direction: direction(column), query: params[:query], paginate_key => page, table: table_name, buttons: @buttons}, {class: css_class(column)}) do
|
8
8
|
model.human_attribute_name(column)
|
9
9
|
end
|
10
10
|
else
|
data/lib/snaptable/engine.rb
CHANGED
data/lib/snaptable/version.rb
CHANGED
metadata
CHANGED
@@ -1,85 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: snaptable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- khcr
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '6.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '6.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: will_paginate
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '3.3'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '3.3'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: sassc-rails
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '2.1'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: jquery-rails
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
54
|
+
version: '2.1'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: sqlite3
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
72
58
|
requirements:
|
73
|
-
- - "
|
59
|
+
- - "~>"
|
74
60
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
61
|
+
version: '1.4'
|
76
62
|
type: :development
|
77
63
|
prerelease: false
|
78
64
|
version_requirements: !ruby/object:Gem::Requirement
|
79
65
|
requirements:
|
80
|
-
- - "
|
66
|
+
- - "~>"
|
81
67
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
68
|
+
version: '1.4'
|
83
69
|
description: A gem that generate HTML tables from your models in order to display
|
84
70
|
them in your admin views.
|
85
71
|
email:
|
@@ -98,7 +84,6 @@ files:
|
|
98
84
|
- app/views/snaptable/_buttons.html.erb
|
99
85
|
- app/views/snaptable/_search_field.html.erb
|
100
86
|
- app/views/snaptable/base.html.erb
|
101
|
-
- app/views/snaptable/sort.js.erb
|
102
87
|
- config/locales/en.yml
|
103
88
|
- config/locales/fr.yml
|
104
89
|
- lib/snaptable.rb
|
@@ -114,7 +99,7 @@ homepage: http://github.com/khcr/snaptable
|
|
114
99
|
licenses:
|
115
100
|
- MIT
|
116
101
|
metadata: {}
|
117
|
-
post_install_message:
|
102
|
+
post_install_message:
|
118
103
|
rdoc_options: []
|
119
104
|
require_paths:
|
120
105
|
- lib
|
@@ -129,9 +114,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
114
|
- !ruby/object:Gem::Version
|
130
115
|
version: '0'
|
131
116
|
requirements: []
|
132
|
-
|
133
|
-
|
134
|
-
signing_key:
|
117
|
+
rubygems_version: 3.1.2
|
118
|
+
signing_key:
|
135
119
|
specification_version: 4
|
136
120
|
summary: A gem that generate HTML tables from your models in order to display them
|
137
121
|
in your admin views.
|