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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 63027ccb0c6c51b72acd15c9589005d146e5e7a6d75c300d5ccbf37de508da2c
4
- data.tar.gz: 6651f729c5cdddc7d41857b3c85db1ddce3794fca964492b86bd493fc6d26caf
3
+ metadata.gz: c18ace7510d52747446fe800cbacbfd54a7a70f2cc27064df3b3ad3e854fd96f
4
+ data.tar.gz: edd3e8d33421b2b68963f3ce32c35d90caff279ee5add09a795326f59048e855
5
5
  SHA512:
6
- metadata.gz: a691e48ea16f98d17b5449a8966ad2af7467c66a0e719820283b0bfbecf47c2168b5ad5feabbcab3e194993cda4f1d05c1067d37d3f9803d1dd7ad14f3b4a738
7
- data.tar.gz: 6350e19c8f8f22d05b03925160906a757bb7d6ade6ee09cf52c0a0158cc632f98bd24114b51306ff2c7bbf68bd98cc414e12fffd4895b9cec4b46dc2fa0a74fc
6
+ metadata.gz: 4c9468645b4c07fcb171c4fbf61b31fa8f00c53fdc21463f685ea9598239d23f8525e7a8894d1d41d9c983f970cf79e7ac2b5afcaa2e71615be7c22e5926c79d
7
+ data.tar.gz: fbdd9fe4b730a9fe85c831615788b72096d65cc5d8d2b4cb0f7f0478386fba6aeef1c4d20c872a8ae308916af9c01bf7ed4e79c8cace1e2421550e35ba7449d7
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
@@ -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] %>
@@ -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
- attr_value = if attribute.is_a?(Symbol) || attribute.is_a?(String)
32
- element.send(attribute)
33
- else
34
- element.send(*attribute.keys).send(*attribute.values)
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("#{model.model_name.i18n_key}.#{attribute.to_s.pluralize}.#{attr_value}")
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}, {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.2"
2
+ VERSION = "4.0.0"
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.2
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: 2019-02-02 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:
@@ -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
- rubyforge_project:
133
- rubygems_version: 2.7.7
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.
@@ -1,4 +0,0 @@
1
- var tableName = "<%= params[:table] %>";
2
- var snaptable = $(".snaptable." + tableName);
3
- snaptable.replaceWith('<%= j content %>');
4
- snapifyTable($(".snaptable." + tableName));