snaptable 2.2.3 → 4.0.1
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/config/manifest.js +2 -0
- 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/collection.rb +1 -1
- data/lib/snaptable/constructor/renderer.rb +9 -4
- data/lib/snaptable/constructor/sortable.rb +1 -1
- data/lib/snaptable/engine.rb +0 -1
- data/lib/snaptable/version.rb +1 -1
- metadata +24 -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: 2ab8263939c5acf6d90d8147b964917911ef93316c5c98f19a9a6430072ec3c6
|
4
|
+
data.tar.gz: ac8ea9902f36f5f17b5b655d6435ad9407f47982334cc65173678ae314becf5e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc252e82f88e2137fde7af3a0f4b28518b1ea5f1853d1375368d8eded48a7843c48d60c8391673b275bc2c4980c30d412dd09c84df3c9f8bcc2c856d85ba7d8a
|
7
|
+
data.tar.gz: 119bde82a218caa16fe97b1ef60769c53f1fe65a5a6e6515ce7b9500a8080d5874f9cc6fdd98b5b4a334d93bb350da036e39c249a9ce54d7df92975a42bbbc0f
|
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
|
|
@@ -32,7 +29,7 @@ module Snaptable
|
|
32
29
|
attr_value = element.send(attribute)
|
33
30
|
else # a hash { model: :attribute }
|
34
31
|
attr_value = element.send(attribute.keys[0]).send(attribute.values[0])
|
35
|
-
attr_model = attribute.keys[0].to_s
|
32
|
+
attr_model = string_to_class(attribute.keys[0].to_s)
|
36
33
|
attribute = attribute.values[0]
|
37
34
|
end
|
38
35
|
format(attribute, attr_value, attr_model)
|
@@ -55,6 +52,14 @@ module Snaptable
|
|
55
52
|
model.defined_enums.keys
|
56
53
|
end
|
57
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
|
+
|
58
63
|
end
|
59
64
|
end
|
60
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.1
|
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:
|
@@ -91,6 +77,7 @@ files:
|
|
91
77
|
- MIT-LICENSE
|
92
78
|
- README.md
|
93
79
|
- Rakefile
|
80
|
+
- app/assets/config/manifest.js
|
94
81
|
- app/assets/javascripts/snaptable.js
|
95
82
|
- app/assets/javascripts/snaptable/table.js
|
96
83
|
- app/assets/stylesheets/snaptable.css
|
@@ -98,7 +85,6 @@ files:
|
|
98
85
|
- app/views/snaptable/_buttons.html.erb
|
99
86
|
- app/views/snaptable/_search_field.html.erb
|
100
87
|
- app/views/snaptable/base.html.erb
|
101
|
-
- app/views/snaptable/sort.js.erb
|
102
88
|
- config/locales/en.yml
|
103
89
|
- config/locales/fr.yml
|
104
90
|
- lib/snaptable.rb
|
@@ -114,7 +100,7 @@ homepage: http://github.com/khcr/snaptable
|
|
114
100
|
licenses:
|
115
101
|
- MIT
|
116
102
|
metadata: {}
|
117
|
-
post_install_message:
|
103
|
+
post_install_message:
|
118
104
|
rdoc_options: []
|
119
105
|
require_paths:
|
120
106
|
- lib
|
@@ -129,9 +115,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
115
|
- !ruby/object:Gem::Version
|
130
116
|
version: '0'
|
131
117
|
requirements: []
|
132
|
-
|
133
|
-
|
134
|
-
signing_key:
|
118
|
+
rubygems_version: 3.1.2
|
119
|
+
signing_key:
|
135
120
|
specification_version: 4
|
136
121
|
summary: A gem that generate HTML tables from your models in order to display them
|
137
122
|
in your admin views.
|