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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b0203c800bc07e68796bd21371315d3ad87d083f0431d2c9aa42b7b856dde471
4
- data.tar.gz: 5c33e463f36a732c9091f379ced36caf3d2e105cb5c080cdff1879cd022c6506
3
+ metadata.gz: 2ab8263939c5acf6d90d8147b964917911ef93316c5c98f19a9a6430072ec3c6
4
+ data.tar.gz: ac8ea9902f36f5f17b5b655d6435ad9407f47982334cc65173678ae314becf5e
5
5
  SHA512:
6
- metadata.gz: c76e95b4382399619cbe008fe107ee9f2c3ecb1c0e519d5afce71993e932c0f9c717afaf405d1b897ba1a633ee9dae8da53a371ac60d40417037486b20c8466b
7
- data.tar.gz: 28736105c9c34676597409ab2e32b1c042d77be09cdbab4c354dd062085dfca9acd97482ab177887ac920b9caccbe370a551ff10094cc9bcfcccbbf96eb3b540
6
+ metadata.gz: fc252e82f88e2137fde7af3a0f4b28518b1ea5f1853d1375368d8eded48a7843c48d60c8391673b275bc2c4980c30d412dd09c84df3c9f8bcc2c856d85ba7d8a
7
+ data.tar.gz: 119bde82a218caa16fe97b1ef60769c53f1fe65a5a6e6515ce7b9500a8080d5874f9cc6fdd98b5b4a334d93bb350da036e39c249a9ce54d7df92975a42bbbc0f
data/README.md CHANGED
@@ -171,7 +171,7 @@ class ArticleTable < BaseTable
171
171
  end
172
172
 
173
173
  def self.fields
174
- { articles: [:title, :content], user: [:name, :email], category: [:name] }
174
+ { articles: [:title, :content], users: [:name, :email], categories: [:name] }
175
175
  end
176
176
 
177
177
  end
@@ -0,0 +1,2 @@
1
+ //= link_directory ../stylesheets .css
2
+ //= linl_directory ../javascripts .js
@@ -5,41 +5,49 @@
5
5
 
6
6
  function snapifyTable(snaptable) {
7
7
 
8
- var tableButtons = snaptable.find(".table_buttons"),
9
- editButton = tableButtons.find("a[class='edit']"),
10
- deleteButton = tableButtons.find("a[class='delete']"),
11
- showButton = tableButtons.find("a[class='show']"),
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.on("click", "tbody tr", function(e) {
26
- var id = $(this).data("url");
27
- if ( typeof id !== "undefined" && !$(this).hasClass("selected") ) {
28
- snaptable.find("tr.selected").removeClass("selected");
29
- $(this).addClass("selected");
30
- deleteButton.add(editButton).add(showButton).addClass("on");
31
- editButton.attr("href", path + id + "/edit" + paramsStr);
32
- deleteButton.attr("href", path + id + paramsStr);
33
- showButton.attr("href", path + id + paramsStr);
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
- // Double click
38
- if(editButton.length) {
39
- snaptable.on("dblclick", "tbody tr", function() {
40
- var id = $(this).data("url");
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
- $(".snaptable").each(function() {
52
- snapifyTable($(this));
59
+ document.querySelectorAll(".snaptable").forEach(function(table) {
60
+ snapifyTable(table);
53
61
  })
54
62
 
55
63
  }
56
64
 
57
- $(document).on("ready turbolinks:load", function() {
58
-
59
- snapifyTables();
60
-
61
- });
65
+ document.addEventListener("DOMContentLoaded", snapifyTables);
@@ -10,6 +10,4 @@
10
10
  // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
11
  // about supported directives.
12
12
  //
13
- //= require jquery
14
- //= require jquery_ujs
15
13
  //= require_tree ./snaptable
@@ -1,6 +1,6 @@
1
1
  <div class="search">
2
2
  <p><%= t("table.search.title") %></p>
3
- <%= form_tag request.fullpath, method: :get, remote: true do %>
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] %>
@@ -41,7 +41,7 @@ module Snaptable
41
41
  end
42
42
 
43
43
  def belongs_to_associations
44
- model.reflect_on_all_associations(:belongs_to).map{ |a| a.name }
44
+ model.reflect_on_all_associations(:belongs_to).reject {|a| a.options[:polymorphic]}.map {|a| a.name}
45
45
  end
46
46
 
47
47
  end
@@ -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.capitalize.constantize
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}, {remote: true, class: css_class(column)}) do
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
@@ -4,7 +4,6 @@ require 'snaptable/helpers/buttons_helper'
4
4
  module Snaptable
5
5
  class Engine < ::Rails::Engine
6
6
  require 'will_paginate'
7
- require 'jquery-rails'
8
7
 
9
8
  initializer 'Snaptable.tables' do
10
9
  ActionController::Base.send :include, Helpers::TableHelper
@@ -1,3 +1,3 @@
1
1
  module Snaptable
2
- VERSION = "2.2.3"
2
+ VERSION = "4.0.1"
3
3
  end
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: 2.2.3
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: 2019-02-06 00:00:00.000000000 Z
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: 5.0.0
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: 5.0.0
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: '0'
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: '0'
40
+ version: '3.3'
41
41
  - !ruby/object:Gem::Dependency
42
- name: sass-rails
42
+ name: sassc-rails
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
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: '0'
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: '0'
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: '0'
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
- rubyforge_project:
133
- rubygems_version: 2.7.7
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.
@@ -1,4 +0,0 @@
1
- var tableName = "<%= params[:table] %>";
2
- var snaptable = $(".snaptable." + tableName);
3
- snaptable.replaceWith('<%= j content %>');
4
- snapifyTable($(".snaptable." + tableName));