datagrid 1.5.3 → 1.5.4

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
  SHA1:
3
- metadata.gz: 73197170df7e4ea6b273acbf39a305d2fda2e43f
4
- data.tar.gz: d5b443380915e544d250a887eed816f87872eaf3
3
+ metadata.gz: 2e27c90403d5aa7a2c924c000961747a6f8aad08
4
+ data.tar.gz: dc805468469c8c967b06f69b33e875038d606ae2
5
5
  SHA512:
6
- metadata.gz: 20eab0fc5d58eadb673fc1f0a4c0a3a844bf04b0a3511e9f20365f9b73462b343a58e393492819705910571782a57802e36108fae67486a443bdd7e314cfe37d
7
- data.tar.gz: 90de90dc86bbbed3887c637b6d8d4c1da92a6467da19ab8248c84ec9280311c510750ccf8c38e7b5bf90dbc0d244b840164e155477f94ad6d008634d50bcc116
6
+ metadata.gz: 033dd01f968f8af3360e92623c2921d6b08cc5032eac39d46e948bc9fc14b6f5d988c21e9c3aea4493aebfb59c30f986770b2cee35beb2a1aa0423fd51f91004
7
+ data.tar.gz: 609622339821f30c85f9d8abcb603ee592763ac0a57c78f0d0e0e00d9691292d224ab443d369ef4672336debb5bab9cf2392e0c83ce2854d2019c4affbb2bcb4
@@ -3,7 +3,7 @@ language: ruby
3
3
  rvm:
4
4
  - 2.2.2
5
5
  - 2.3.0
6
- - 2.4.0
6
+ - 2.4.1
7
7
  #- jruby
8
8
  #- jruby-head
9
9
  #env: JRUBY_OPTS="--server -J-Xms512m -J-Xmx1024m"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.5.3
1
+ 1.5.4
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: datagrid 1.5.3 ruby lib
5
+ # stub: datagrid 1.5.4 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "datagrid".freeze
9
- s.version = "1.5.3"
9
+ s.version = "1.5.4"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["Bogdan Gusiev".freeze]
14
- s.date = "2017-03-06"
14
+ s.date = "2017-06-16"
15
15
  s.description = "This allows you to easily build datagrid aka data tables with sortable columns and filters".freeze
16
16
  s.email = "agresso@gmail.com".freeze
17
17
  s.extra_rdoc_files = [
@@ -4,7 +4,7 @@ module Datagrid
4
4
  # Required to be ActiveModel compatible
5
5
  # @private
6
6
  module ActiveModel #:nodoc:
7
-
7
+
8
8
  def self.included(base)
9
9
  base.extend ClassMethods
10
10
  base.class_eval do
@@ -13,21 +13,23 @@ module Datagrid
13
13
  extend ::ActiveModel::Naming
14
14
  rescue LoadError
15
15
  end
16
+ begin
17
+ require 'active_model/attributes_assignment'
18
+ extend ::ActiveModel::AttributesAssignment
19
+ rescue LoadError
20
+ end
21
+
16
22
  end
17
23
  base.send :include, InstanceMethods
18
24
  end # self.included
19
-
25
+
20
26
  module ClassMethods
21
-
22
27
  def param_name
23
28
  self.to_s.underscore.tr('/', '_')
24
29
  end
25
-
26
-
27
30
  end # ClassMethods
28
-
31
+
29
32
  module InstanceMethods
30
-
31
33
  def param_name
32
34
  self.class.param_name
33
35
  end
@@ -52,8 +54,5 @@ module Datagrid
52
54
  self.param_name
53
55
  end
54
56
  end # InstanceMethods
55
-
56
57
  end
57
-
58
-
59
58
  end
@@ -103,14 +103,18 @@ module Datagrid
103
103
 
104
104
 
105
105
  # Updates datagrid attributes with a passed hash argument
106
- def assign_attributes(attributes)
107
- attributes.each do |name, value|
108
- self[name] = value
106
+ def attributes=(attributes)
107
+ if respond_to?(:assign_attributes)
108
+ assign_attributes(attributes)
109
+ else
110
+ attributes.each do |name, value|
111
+ self[name] = value
112
+ end
113
+ self
109
114
  end
110
- self
111
115
  end
112
- alias attributes= assign_attributes
113
116
 
117
+ # Returns serializable query arguments skipping all nil values
114
118
  def as_query
115
119
  attributes = self.attributes.clone
116
120
  attributes.each do |key, value|
@@ -13,7 +13,7 @@ module Datagrid
13
13
 
14
14
  def to_scope(scope)
15
15
  return scope if scope.is_a?(::Sequel::Dataset)
16
- scope.where
16
+ scope.where({})
17
17
  end
18
18
 
19
19
  def append_column_queries(assets, columns)
@@ -41,11 +41,11 @@ module Datagrid
41
41
  end
42
42
 
43
43
  def greater_equal(scope, field, value)
44
- scope.where(["#{prefix_table_name(scope, field)} >= ?", value])
44
+ scope.where(::Sequel.lit("#{prefix_table_name(scope, field)} >= ?", value))
45
45
  end
46
46
 
47
47
  def less_equal(scope, field, value)
48
- scope.where(["#{prefix_table_name(scope, field)} <= ?", value])
48
+ scope.where(::Sequel.lit("#{prefix_table_name(scope, field)} <= ?", value))
49
49
  end
50
50
 
51
51
  def has_column?(scope, column_name)
@@ -103,7 +103,7 @@ module Datagrid
103
103
  input_name = "#{object_name}[#{filter.name.to_s}][]"
104
104
  field, operation, value = object.filter_value(filter)
105
105
  options = options.merge(:name => input_name)
106
- field_input = select(
106
+ field_input = dynamic_filter_select(
107
107
  filter.name,
108
108
  object.select_options(filter) || [],
109
109
  {
@@ -114,7 +114,7 @@ module Datagrid
114
114
  },
115
115
  add_html_classes(options, "field")
116
116
  )
117
- operation_input = select(
117
+ operation_input = dynamic_filter_select(
118
118
  filter.name, filter.operations_select,
119
119
  {:include_blank => false, :include_hidden => false, :prompt => false, :selected => operation },
120
120
  add_html_classes(options, "operation")
@@ -123,6 +123,18 @@ module Datagrid
123
123
  [field_input, operation_input, value_input].join("\n").html_safe
124
124
  end
125
125
 
126
+ def dynamic_filter_select(name, variants, select_options, html_options)
127
+ if variants.size <= 1
128
+ value = variants.first
129
+ # select options format may vary
130
+ value = value.last if value.is_a?(Array)
131
+ # don't render any visible input when there is nothing to choose from
132
+ hidden_field(name, html_options.merge(value: value))
133
+ else
134
+ select(name, variants, select_options, html_options)
135
+ end
136
+ end
137
+
126
138
  def datagrid_range_filter(type, attribute_or_filter, options = {})
127
139
  filter = datagrid_get_filter(attribute_or_filter)
128
140
  if filter.range?
@@ -13,17 +13,18 @@ module Datagrid
13
13
  end
14
14
 
15
15
  def translate_from_namespace(namespace, grid_class, key)
16
- deprecated_key = :"datagrid.#{grid_class.param_name}.#{namespace}.#{key}"
17
- live_key = :"datagrid.#{grid_class.model_name.i18n_key}.#{namespace}.#{key}"
18
- i18n_key = grid_class.model_name.i18n_key.to_s
19
-
20
- if grid_class.param_name != i18n_key && I18n.exists?(deprecated_key)
21
- Datagrid::Utils.warn_once(
22
- "Deprecated translation namespace 'datagrid.#{grid_class.param_name}' for #{grid_class}. Use 'datagrid.#{i18n_key}' instead."
23
- )
24
- return I18n.t(deprecated_key)
16
+
17
+ lookups = []
18
+ namespaced_key = "#{namespace}.#{key}"
19
+
20
+ grid_class.ancestors.each do |ancestor|
21
+ if ancestor.respond_to?(:model_name)
22
+ lookups << :"datagrid.#{ancestor.model_name.i18n_key}.#{namespaced_key}"
23
+ end
25
24
  end
26
- I18n.t(live_key, default: key.to_s.humanize).presence
25
+ lookups << :"datagrid.defaults.#{namespaced_key}"
26
+ lookups << key.to_s.humanize
27
+ I18n.t(lookups.shift, default: lookups).presence
27
28
  end
28
29
 
29
30
  def warn_once(message, delay = 5)
@@ -63,30 +63,36 @@ describe Datagrid::Columns do
63
63
  column(:name)
64
64
  end
65
65
  end
66
- it "translates column with deprecated namespace" do
67
- silence_warnings do
68
- store_translations(:en, datagrid: {ns45_translated_report: {columns: {name: "Navn"}}}) do
69
- expect(Ns45::TranslatedReport.new.header.first).to eq("Navn")
70
- end
71
- end
72
- end
73
-
74
- it "translates column with namespace" do
66
+ it "translates column-header with namespace" do
75
67
  store_translations(:en, datagrid: {:"ns45/translated_report" => {columns: {name: "Navn"}}}) do
76
68
  expect(Ns45::TranslatedReport.new.header.first).to eq("Navn")
77
69
  end
78
70
  end
79
71
 
80
- it "translates column without namespace" do
72
+ it "translates column-header without namespace" do
81
73
  class Report27
82
74
  include Datagrid
83
75
  scope {Entry}
84
76
  column(:name)
85
77
  end
78
+
86
79
  store_translations(:en, datagrid: {:"report27" => {columns: {name: "Nombre"}}}) do
87
80
  expect(Report27.new.header.first).to eq("Nombre")
88
81
  end
89
82
  end
83
+
84
+ it "translates column-header in using defaults namespace" do
85
+ class Report27
86
+ include Datagrid
87
+ scope {Entry}
88
+ column(:name)
89
+ end
90
+
91
+ store_translations(:en, datagrid: {defaults: {columns: {name: "Nombre"}}}) do
92
+ expect(Report27.new.header.first).to eq("Nombre")
93
+ end
94
+ end
95
+
90
96
  end
91
97
 
92
98
  it "should return html_columns" do
@@ -207,13 +207,8 @@ describe Datagrid::Filters do
207
207
  scope { Entry }
208
208
  filter(:name)
209
209
  end
210
- end
211
- it "translates filter with deprecated namespace" do
212
- grid = Ns46::TranslatedReport.new
213
- silence_warnings do
214
- store_translations(:en, datagrid: {ns46_translated_report: {filters: {name: "Navn"}}}) do
215
- expect(grid.filters.map(&:header)).to eq(["Navn"])
216
- end
210
+
211
+ class InheritedReport < TranslatedReport
217
212
  end
218
213
  end
219
214
 
@@ -224,6 +219,19 @@ describe Datagrid::Filters do
224
219
  end
225
220
  end
226
221
 
222
+ it "translates filter using defaults namespace" do
223
+ grid = Ns46::TranslatedReport.new
224
+ store_translations(:en, datagrid: {defaults: {filters: {name: "Navn"}}}) do
225
+ expect(grid.filters.map(&:header)).to eq(["Navn"])
226
+ end
227
+ end
228
+
229
+ it "translates filter using parent report" do
230
+ grid = Ns46::InheritedReport.new
231
+ store_translations(:en, datagrid: {:"ns46/translated_report" => {filters: {name: "Navn"}}}) do
232
+ expect(grid.filters.map(&:header)).to eq(["Navn"])
233
+ end
234
+ end
227
235
  end
228
236
 
229
237
 
@@ -567,35 +567,44 @@ DOM
567
567
  it {should equal_to_dom(expected_html)}
568
568
 
569
569
  end
570
- context "when select option passed" do
570
+
571
+ context "when operations and options are defined" do
571
572
  let(:filter_options) do
572
- {:select => [:id, :name]}
573
+ {:operations => %w(>= <=), :select => [:id, :name]}
573
574
  end
574
575
  let(:expected_html) do
575
576
  <<-HTML
576
- <select class="condition dynamic_filter field" name="report[condition][]" id="report_condition"><option value="id">id</option>
577
- <option value="name">name</option></select><select class="condition dynamic_filter operation" name="report[condition][]" id="report_condition"><option value="=">=</option>
578
- <option value="=~">&asymp;</option>
579
- <option value="&gt;=">&ge;</option>
580
- <option value="&lt;=">&le;</option></select><input class="condition dynamic_filter value" name="report[condition][]" type="text" id="report_condition">
577
+ <select class="condition dynamic_filter field" name="report[condition][]" id="report_condition"><option value="id">id</option><option value="name">name</option></select><select class="condition dynamic_filter operation" name="report[condition][]" id="report_condition"><option value="&gt;=">≥</option>
578
+ <option value="&lt;=">≤</option></select><input class="condition dynamic_filter value" name="report[condition][]" type="text" id="report_condition">
581
579
  HTML
582
580
  end
583
581
  it {should equal_to_dom(expected_html)}
584
-
585
582
  end
586
583
 
587
- context "when operation options passed" do
584
+ context "when the field is predefined" do
588
585
  let(:filter_options) do
589
586
  {:operations => %w(>= <=), :select => [:id]}
590
587
  end
591
588
  let(:expected_html) do
592
589
  <<-HTML
593
- <select class="condition dynamic_filter field" name="report[condition][]" id="report_condition"><option value="id">id</option></select><select class="condition dynamic_filter operation" name="report[condition][]" id="report_condition"><option value="&gt;=">≥</option>
590
+ <input class="condition dynamic_filter field" name="report[condition][]" value="id" type="hidden" id="report_condition"><select class="condition dynamic_filter operation" name="report[condition][]" id="report_condition"><option value="&gt;=">≥</option>
594
591
  <option value="&lt;=">≤</option></select><input class="condition dynamic_filter value" name="report[condition][]" type="text" id="report_condition">
595
592
  HTML
596
593
  end
597
594
  it {should equal_to_dom(expected_html)}
598
595
  end
596
+ context "when operation is predefined" do
597
+ let(:filter_options) do
598
+ {:operations => %w(=), :select => [:id, :name]}
599
+ end
600
+ let(:expected_html) do
601
+ <<-HTML
602
+ <select class="condition dynamic_filter field" name="report[condition][]" id="report_condition"><option value="id">id</option><option value="name">name</option></select><input class="condition dynamic_filter operation" name="report[condition][]" value="=" type="hidden" id="report_condition"><input class="condition dynamic_filter value" name="report[condition][]" type="text" id="report_condition">
603
+ HTML
604
+ end
605
+ it {should equal_to_dom(expected_html)}
606
+ end
607
+
599
608
  end
600
609
  end
601
610
 
@@ -86,7 +86,7 @@ RSpec.configure do |config|
86
86
  #TODO better database truncation
87
87
  Group.delete_all
88
88
  Entry.delete_all
89
- SequelEntry.where.delete
89
+ SequelEntry.where({}).delete
90
90
  unless NO_MONGO
91
91
  MongoidEntry.delete_all
92
92
  MongoMapperEntry.delete_all if defined?(MongoMapperEntry)
@@ -3,5 +3,4 @@ def store_translations(locale, translations, &block)
3
3
  yield
4
4
  ensure
5
5
  I18n.reload!
6
- I18n.backend.send :init_translations
7
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datagrid
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.3
4
+ version: 1.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bogdan Gusiev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-06 00:00:00.000000000 Z
11
+ date: 2017-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails