tabulatr2 0.9.3 → 0.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f6cc8ca903e127f8312818a5a85faf7a01fb7b85
4
- data.tar.gz: 90df54794f6c5699ac87809a3513ed5845fa34f5
3
+ metadata.gz: 0b11a5d5bda9718541550adc016fca03765e3e06
4
+ data.tar.gz: 5281e726afe6e44bec05af2a31d72e3546201180
5
5
  SHA512:
6
- metadata.gz: 6c4ce4dfcb2f5caf2e57a9c89b0a380989cc73112a074dceb6055837844817fb1271f0b10f4cab36c89d9f8e80d282a94d401b0d7b14785f061f3b352423b047
7
- data.tar.gz: 66121f0ea6dc15b810fbaa31bc86385afd96f5a9632889a0a5ffe44f288a0a02981d48f4e6dccf45b1d524b6ec4eb483a78e83b717775a0c77646a5ebfce567b
6
+ metadata.gz: 1cb47ebf2433da0db9280acb652d833fd4311629d111b03b175ff94ca3e695249222ce841dc7ba94e9e881ac935ebdb095aa1eaf2884670e93ce6284d95596e7
7
+ data.tar.gz: 231823bbb5a39e6f95c0991d3debab968f978d9a8ae8fe07203b9266eacb5f9ff729fa8ce9da26fcffd04ecfa7b93f2f5b5d828369c60e63ba8105d50586e5bb
data/CHANGELOG.md CHANGED
@@ -1,4 +1,11 @@
1
+ ## 0.9.4
2
+
3
+ * Fixed date filters
4
+
5
+ * Added missing translations to the install generator.
6
+
1
7
  ## 0.9.3
8
+
2
9
  * Tabulatr is now stopped from retrieving data in endless pagination mode when all data
3
10
  is already on the client.
4
11
 
@@ -29,35 +29,36 @@ form.form.form-horizontal.tabulatr_filter_form data-table=table_id data-remote=
29
29
  - iname = "#{formatted_name}_filter[#{name}]"
30
30
  - filter_name = "tabulatr_form_#{name}"
31
31
 
32
- label.control-label.col-md-3 for=filter_name
32
+ label.control-label.col-sm-3.col-xs-12 for=filter_name
33
33
  = column.human_name
34
34
 
35
- .controls.col-md-9.row
35
+ .controls.col-sm-9.col-xs-12.row
36
36
  - if column.filter.is_a?(Hash) || column.filter.is_a?(Array) || column.filter.is_a?(String)
37
- select.form-control id=name name=iname
38
- - if column.filter.class.is_a?(String)
39
- = column.filter
40
- - else
41
- option
42
- = options_for_select(column.filter)
37
+ .col-sm-11
38
+ select.form-control id=name name=iname
39
+ - if column.filter.class.is_a?(String)
40
+ = column.filter
41
+ - else
42
+ option
43
+ = options_for_select(column.filter)
43
44
  - elsif column.filter == :range
44
- .col-md-5
45
+ .col-sm-5
45
46
  input.tabulatr_filter.form-control type="text" id="#{name}_from" data-tabulatr-attribute="#{name}_from" name="#{iname}[from]"
46
- span.col-md-1.text-center —
47
- .col-md-5
47
+ span.col-sm-1.text-center —
48
+ .col-sm-5
48
49
  input.tabulatr_filter.form-control type="text" id="#{name}_to" data-tabulatr-attribute="#{name}_to" name="#{iname}[to]"
49
50
  - elsif column.filter == :checkbox
50
- .col-md-11
51
+ .col-sm-11
51
52
  = select_tag(iname, options_for_select([ \
52
53
  [t('tabulatr.boolean_filter.both'), ""],
53
54
  [t('tabulatr.boolean_filter.no'), "false"],
54
55
  [t('tabulatr.boolean_filter.yes'), "true"]] \
55
56
  ), class: 'form-control')
56
57
  - elsif column.filter == :exact
57
- .col-md-11
58
+ .col-sm-11
58
59
  input.tabulatr_filter.form-control type="text" id="#{name}_exact" data-tabulatr-attribute="#{name}" name="#{iname}"
59
60
  - elsif column.filter == :date
60
- .col-md-3
61
+ .col-sm-3
61
62
  select.form-control name="#{iname}[date][simple]" data-tabulatr-date-filter="#{formatted_name}_#{name}_filter"
62
63
  option= I18n.t("tabulatr.date_filter.none")
63
64
  option value="today"= I18n.t("tabulatr.date_filter.today")
@@ -67,18 +68,18 @@ form.form.form-horizontal.tabulatr_filter_form data-table=table_id data-remote=
67
68
  option value="this_month"= I18n.t("tabulatr.date_filter.this_month")
68
69
  option value="last_30_days"= I18n.t("tabulatr.date_filter.last_30_days")
69
70
  option value="from_to"= I18n.t("tabulatr.date_filter.from_to")
70
- .col-md-1
71
- .col-md-3
71
+ .col-sm-1
72
+ .col-sm-3
72
73
  input.tabulatr_filter.form-control.date-picker.hidden.from_to type="text" id="#{formatted_name}_#{name}_filter_from" name="#{iname}[date][from]"
73
- .col-md-1.text-center
74
+ .col-sm-1.text-center
74
75
  .span.from_to.hidden
75
76
  |—
76
- .col-md-3
77
+ .col-sm-3
77
78
  input.tabulatr_filter.form-control.date-picker.from_to.hidden type="text" id="#{formatted_name}_#{name}_filter_to" name="#{iname}[date][to]"
78
79
  - else
79
- .col-md-11
80
+ .col-sm-11
80
81
  input.tabulatr_filter.form-control type="text" id="#{name}_like" data-tabulatr-attribute="#{name}" name="#{iname}[like]"
81
- .col-md-1
82
+ .col-sm-1
82
83
  = link_to "✕", '#', 'data-hide-table-filter' => name, class: 'form-control btn btn-danger btn-mini'
83
84
 
84
85
  .control-group.form-group data-filter-column-name="_submit"
@@ -78,17 +78,30 @@ module Tabulatr::Data::Filtering
78
78
  today = Date.today
79
79
  case cond[:simple]
80
80
  when 'none' then return
81
- when 'today' then since = today
82
- when 'yesterday' then since = today - 1.day
83
- when 'this_week' then since = today.at_beginning_of_week
84
- when 'last_7_days' then since = today - 7.day
85
- when 'this_month' then since = today.at_beginning_of_month
86
- when 'last_30_days' then since = today - 30.day
81
+ when 'today'
82
+ since = today
83
+ to = today.at_end_of_day
84
+ when 'yesterday'
85
+ since = today - 1.day
86
+ to = since.at_end_of_day
87
+ when 'this_week'
88
+ since = today.at_beginning_of_week.beginning_of_day
89
+ to = today.at_end_of_week.end_of_day
90
+ when 'last_7_days'
91
+ since = (today - 6.day).beginning_of_day
92
+ to = today.at_end_of_day
93
+ when 'this_month'
94
+ since = today.at_beginning_of_month.beginning_of_day
95
+ to = today.at_end_of_month.end_of_day
96
+ when 'last_30_days'
97
+ since = (today - 29.day).beginning_of_day
98
+ to = today.at_end_of_day
87
99
  when 'from_to'
88
100
  since = Date.parse(cond[:from]) if cond[:from].present?
89
- @relation = @relation.where("#{n} <= ?", Date.parse(cond[:to])) if cond[:to].present?
101
+ to = Date.parse(cond[:to]) if cond[:to].present?
90
102
  end
91
103
  @relation = @relation.where("#{n} >= ?", since) if since.present?
104
+ @relation = @relation.where("#{n} <= ?", to) if to.present?
92
105
  end
93
106
 
94
107
  def apply_string_condition(replacement_string, value)
@@ -6,6 +6,20 @@ en:
6
6
  count: 'Showing: %{current} of total %{total}. %{per_page} items per page.'
7
7
  apply_filters: 'Apply'
8
8
  search: 'Search'
9
+ date_filter:
10
+ none: ''
11
+ today: "Today"
12
+ yesterday: Yesterday
13
+ this_week: This Week
14
+ last_7_days: Last 7 Days
15
+ this_month: This Month
16
+ last_30_days: Last 30 Days
17
+ from_to: From - To
18
+ boolean_filter:
19
+ both: All
20
+ yes: Yes
21
+ no: No
22
+
9
23
  de:
10
24
  tabulatr:
11
25
  rows_per_page: 'Ergebnisse pro Seite'
@@ -14,3 +28,16 @@ de:
14
28
  count: 'Zeige %{current} von insgesamt %{total}. %{per_page} pro Seite.'
15
29
  apply_filters: 'Anwenden'
16
30
  search: 'Suche'
31
+ date_filter:
32
+ none: ''
33
+ today: "Heute"
34
+ yesterday: Gestern
35
+ this_week: Diese Woche
36
+ last_7_days: Letzte 7 Tage
37
+ this_month: Dieser Monat
38
+ last_30_days: Letzte 30 Tage
39
+ from_to: Von - Bis
40
+ boolean_filter:
41
+ both: Alle
42
+ yes: Ja
43
+ no: Nein
@@ -22,5 +22,5 @@
22
22
  #++
23
23
 
24
24
  module Tabulatr
25
- VERSION = "0.9.3"
25
+ VERSION = "0.9.4"
26
26
  end
@@ -0,0 +1,5 @@
1
+ class AddPublishAtToProducts < ActiveRecord::Migration
2
+ def change
3
+ add_column :products, :publish_at, :datetime
4
+ end
5
+ end
@@ -11,7 +11,7 @@
11
11
  #
12
12
  # It's strongly recommended that you check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(version: 20130730132348) do
14
+ ActiveRecord::Schema.define(version: 20140128140114) do
15
15
 
16
16
  create_table "products", force: true do |t|
17
17
  t.integer "vendor_id"
@@ -20,6 +20,7 @@ ActiveRecord::Schema.define(version: 20130730132348) do
20
20
  t.boolean "active"
21
21
  t.datetime "created_at"
22
22
  t.datetime "updated_at"
23
+ t.datetime "publish_at"
23
24
  end
24
25
 
25
26
  add_index "products", ["vendor_id"], name: "index_products_on_vendor_id"
@@ -0,0 +1,72 @@
1
+ require 'spec_helper'
2
+
3
+ describe Tabulatr::Data::Filtering do
4
+ class DummySpecClass
5
+ include Tabulatr::Data::Filtering
6
+ end
7
+
8
+ before(:each) do
9
+ @dummy = DummySpecClass.new
10
+ @dummy.instance_variable_set('@relation', Product.all)
11
+ @yesterday = Product.create!(publish_at: DateTime.new(2013, 12, 31, 0, 0))
12
+ @today = Product.create!(publish_at: DateTime.new(2014, 1, 1, 15, 0))
13
+ @week_one = Product.create!(publish_at: DateTime.new(2013, 12, 30, 0, 0))
14
+ @week_two = Product.create!(publish_at: DateTime.new(2014, 1, 5, 8, 0))
15
+ @last_seven_days = Product.create!(publish_at: DateTime.new(2013, 12, 26, 0, 0))
16
+ @last_thirty_days = Product.create!(publish_at: DateTime.new(2013, 12, 3, 0, 0))
17
+ @outside_last_thirty_days = Product.create!(publish_at: DateTime.new(2013, 12, 2, 23, 59))
18
+ @this_month = Product.create!(publish_at: DateTime.new(2014, 1, 15, 0, 0))
19
+ @next_year = Product.create!(publish_at: DateTime.new(2015, 1, 1, 12, 0))
20
+ Date.stub(:today).and_return(Date.new(2014,1,1))
21
+ end
22
+ describe '.apply_date_condition' do
23
+ it "filters for 'today'" do
24
+ @dummy.apply_date_condition('publish_at', {simple: 'today'})
25
+ result = @dummy.instance_variable_get('@relation')
26
+ expect(result.count).to be 1
27
+ expect(result[0].id).to be @today.id
28
+ end
29
+
30
+ it "filters for 'yesterday'" do
31
+ @dummy.apply_date_condition('publish_at', {simple: 'yesterday'})
32
+ result = @dummy.instance_variable_get('@relation')
33
+ expect(result.count).to be 1
34
+ expect(result[0].id).to be @yesterday.id
35
+ end
36
+
37
+ it "filters for 'this week'" do
38
+ @dummy.apply_date_condition('publish_at', {simple: 'this_week'})
39
+ result = @dummy.instance_variable_get('@relation')
40
+ expect(result.count).to be 4
41
+ expect(result.map(&:id).sort).to eq [@yesterday.id, @today.id, @week_one.id, @week_two.id].sort
42
+ end
43
+
44
+ it "filters for 'last 7 days'" do
45
+ @dummy.apply_date_condition('publish_at', {simple: 'last_7_days'})
46
+ result = @dummy.instance_variable_get('@relation')
47
+ expect(result.map(&:id).sort).to eq ([@last_seven_days.id, @yesterday.id, @today.id, @week_one.id].sort)
48
+ end
49
+
50
+ it "filters for 'this month'" do
51
+ @dummy.apply_date_condition('publish_at', {simple: 'this_month'})
52
+ result = @dummy.instance_variable_get('@relation')
53
+ expect(result.map(&:id).sort).to eq ([@today.id, @week_two.id, @this_month.id])
54
+ end
55
+
56
+ it "filters for 'last 30 days'" do
57
+ @dummy.apply_date_condition('publish_at', {simple: 'last_30_days'})
58
+ result = @dummy.instance_variable_get('@relation')
59
+ expect(result.map(&:id).sort).to eq ([
60
+ @last_thirty_days.id, @yesterday.id, @last_seven_days.id, @today.id,
61
+ @week_one.id].sort)
62
+ end
63
+
64
+ it "filters from 'start_date' to 'end_date'" do
65
+ @dummy.apply_date_condition('publish_at', {
66
+ simple: 'from_to', from: '31.12.2013 15:00',
67
+ to: '15.01.2014 00:00'})
68
+ result = @dummy.instance_variable_get('@relation')
69
+ expect(result.map(&:id)).to eq ([@yesterday.id, @today.id, @week_two.id].sort)
70
+ end
71
+ end
72
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tabulatr2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Horn
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-01-27 00:00:00.000000000 Z
13
+ date: 2014-01-29 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -171,6 +171,7 @@ files:
171
171
  - spec/dummy/db/migrate/20130730132101_create_vendors.rb
172
172
  - spec/dummy/db/migrate/20130730132321_create_products.rb
173
173
  - spec/dummy/db/migrate/20130730132348_create_tags.rb
174
+ - spec/dummy/db/migrate/20140128140114_add_publish_at_to_products.rb
174
175
  - spec/dummy/db/schema.rb
175
176
  - spec/dummy/lib/assets/.keep
176
177
  - spec/dummy/log/.keep
@@ -180,6 +181,7 @@ files:
180
181
  - spec/dummy/public/favicon.ico
181
182
  - spec/features/tabulatrs_spec.rb
182
183
  - spec/lib/tabulatr/data/data_spec.rb
184
+ - spec/lib/tabulatr/data/filtering_spec.rb
183
185
  - spec/lib/tabulatr/data/pagination_spec.rb
184
186
  - spec/lib/tabulatr/json_builder_spec.rb
185
187
  - spec/lib/tabulatr/renderer/renderer_spec.rb
@@ -263,6 +265,7 @@ test_files:
263
265
  - spec/dummy/db/migrate/20130730132101_create_vendors.rb
264
266
  - spec/dummy/db/migrate/20130730132321_create_products.rb
265
267
  - spec/dummy/db/migrate/20130730132348_create_tags.rb
268
+ - spec/dummy/db/migrate/20140128140114_add_publish_at_to_products.rb
266
269
  - spec/dummy/db/schema.rb
267
270
  - spec/dummy/lib/assets/.keep
268
271
  - spec/dummy/log/.keep
@@ -272,6 +275,7 @@ test_files:
272
275
  - spec/dummy/public/favicon.ico
273
276
  - spec/features/tabulatrs_spec.rb
274
277
  - spec/lib/tabulatr/data/data_spec.rb
278
+ - spec/lib/tabulatr/data/filtering_spec.rb
275
279
  - spec/lib/tabulatr/data/pagination_spec.rb
276
280
  - spec/lib/tabulatr/json_builder_spec.rb
277
281
  - spec/lib/tabulatr/renderer/renderer_spec.rb