tabulatr2 0.9.7 → 0.9.10

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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/README.md +30 -0
  4. data/app/assets/stylesheets/tabulatr/application.css.scss +1 -1
  5. data/app/views/tabulatr/_tabulatr_actual_table.html.slim +3 -3
  6. data/app/views/tabulatr/_tabulatr_batch_actions_menu.html.slim +2 -2
  7. data/app/views/tabulatr/_tabulatr_buttons.html.slim +19 -0
  8. data/app/views/tabulatr/_tabulatr_filter_dialog.html.slim +1 -1
  9. data/app/views/tabulatr/_tabulatr_filter_menu.html.slim +2 -2
  10. data/app/views/tabulatr/_tabulatr_fuzzy_search_field.html.slim +1 -1
  11. data/app/views/tabulatr/_tabulatr_info_string.html.slim +1 -1
  12. data/app/views/tabulatr/_tabulatr_paginator.html.slim +1 -1
  13. data/app/views/tabulatr/_tabulatr_static_table.html.slim +3 -3
  14. data/app/views/tabulatr/_tabulatr_table.html.slim +1 -1
  15. data/lib/tabulatr.rb +1 -1
  16. data/lib/tabulatr/data/button_builder.rb +71 -0
  17. data/lib/tabulatr/data/data.rb +4 -3
  18. data/lib/tabulatr/data/dsl.rb +77 -8
  19. data/lib/tabulatr/data/filtering.rb +1 -1
  20. data/lib/tabulatr/data/formatting.rb +4 -8
  21. data/lib/tabulatr/data/invoker.rb +1 -1
  22. data/lib/tabulatr/data/pagination.rb +1 -1
  23. data/lib/tabulatr/data/proxy.rb +4 -3
  24. data/lib/tabulatr/data/sorting.rb +1 -1
  25. data/lib/tabulatr/engine.rb +1 -1
  26. data/lib/tabulatr/generators/railtie.rb +1 -1
  27. data/lib/tabulatr/generators/resource_override.rb +1 -1
  28. data/lib/tabulatr/generators/tabulatr/install_generator.rb +1 -1
  29. data/lib/tabulatr/generators/tabulatr/table_generator.rb +1 -1
  30. data/lib/tabulatr/json_builder.rb +1 -1
  31. data/lib/tabulatr/rails/action_controller.rb +4 -2
  32. data/lib/tabulatr/rails/action_view.rb +1 -1
  33. data/lib/tabulatr/rails/active_record.rb +1 -1
  34. data/lib/tabulatr/renderer/action.rb +1 -1
  35. data/lib/tabulatr/renderer/association.rb +3 -2
  36. data/lib/tabulatr/renderer/buttons.rb +32 -0
  37. data/lib/tabulatr/renderer/checkbox.rb +1 -1
  38. data/lib/tabulatr/renderer/column.rb +13 -11
  39. data/lib/tabulatr/renderer/columns_from_block.rb +9 -1
  40. data/lib/tabulatr/renderer/renderer.rb +4 -3
  41. data/lib/tabulatr/utility/request_data_not_included_error.rb +2 -3
  42. data/lib/tabulatr/utility/utility.rb +1 -1
  43. data/lib/tabulatr/version.rb +2 -2
  44. data/spec/dummy/app/tabulatr_data/product_tabulatr_data.rb +11 -1
  45. data/spec/dummy/app/views/products/simple_index.html.erb +1 -1
  46. data/spec/dummy/app/views/products/stupid_array.html.erb +3 -0
  47. data/spec/dummy/config/routes.rb +1 -1
  48. metadata +5 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 69941415afe2bc08bd378cb68c1a67490f5082a2
4
- data.tar.gz: dc92b82263d3621383ba74c9cfaae51e291c392a
3
+ metadata.gz: 457d8adce27f3f902cc4df5215a32cc4672ebe6f
4
+ data.tar.gz: b8f3703af996ac13ba561401e113e34bf1b165fc
5
5
  SHA512:
6
- metadata.gz: 224bb32431f1fc7974742de1ee1bd735480568b81bff5af2463e4169983a1b28274dce41dda48d4a8fabdb4997a360d5e8699ad723732d38c1bc488e7e206319
7
- data.tar.gz: 74b7411b8933ba1fb6171ab5ae695fcf6fa66782cfad0b200126d72929846fc2e1c8fde54eb723fb9c83ec99503ad0fc5fbc74798e41170a076b2546045e7ecd
6
+ metadata.gz: c81f75442ed064dfb4918af18cc310e3185e06c8f500ce327117427e2e7cb42a6b64ed43c88be3317418f5d8a783def68e8a1c47ab44f18eedae4d211dd09f69
7
+ data.tar.gz: f6817a83f7bfe03822dde8e343148cea2337721ce6a2efa2f382e8d3bf4f7fa0188c91f156392ed7750d8c317131a30c9f1ac473497680e31b194e1728962290
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License
2
2
 
3
- Copyright (c) 2010-2011 by Provideal GmbH, Peter Horn
3
+ Copyright (c) 2010-2014 by tickettoaster GmbH, Peter Horn & Florian Thomas
4
4
  http://www.provideal.net, peter.horn@provideal.net
5
5
 
6
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
data/README.md CHANGED
@@ -134,6 +134,36 @@ class UserTabulatrData < Tabulatr::Data
134
134
  end
135
135
  ```
136
136
 
137
+ ### Actions
138
+
139
+ To provide a column that's not sortable and filterable but renders something nice:
140
+
141
+ ```ruby
142
+ class UserTabulatrData < Tabulatr::Data
143
+ action do |r|
144
+ link_to "edit", edit_product_path(r)
145
+ end
146
+ end
147
+ ```
148
+
149
+ ### Buttons
150
+
151
+ To render a fancy button group:
152
+
153
+ ```ruby
154
+ class UserTabulatrData < Tabulatr::Data
155
+ buttons do |b,r|
156
+ b.button :eye, product_path(r), class: 'btn-success'
157
+ b.button :pencil, edit_product_path(r), class: 'btn-warning'
158
+ b.submenu do |s|
159
+ s.button :star, star_product_path(r), label: 'Dolle Sache'
160
+ s.divider
161
+ s.button :'trash-o', product_path(r), label: 'Löschen', confirmation: 'echt?', class: 'btn-danger', method: :delete
162
+ end
163
+ end
164
+ end
165
+ ```
166
+
137
167
  ### Search
138
168
 
139
169
  The DSL provides you with a `search` method to define a custom fuzzy search method which is not bound
@@ -1,4 +1,4 @@
1
- // Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
1
+ // Copyright (c) 2010-2014 Peter Horn & Florian Thomas, tickettoaster GmbH
2
2
  //
3
3
  // Permission is hereby granted, free of charge, to any person obtaining
4
4
  // a copy of this software and associated documentation files (the
@@ -1,4 +1,4 @@
1
- / Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
1
+ / Copyright (c) 2010-2014 Peter Horn & Florian Thomas, tickettoaster GmbH
2
2
  /
3
3
  / Permission is hereby granted, free of charge, to any person obtaining
4
4
  / a copy of this software and associated documentation files (the
@@ -26,7 +26,7 @@
26
26
  tr
27
27
  - columns.each do |column|
28
28
  - classes = column.sortable ? ['tabulatr-sortable'] : []
29
- - classes = [classes, column.classes].flatten.compact.join(' ')
29
+ - classes = [classes, "tabulatr-column-#{column.coltype}", column.classes].flatten.compact.join(' ')
30
30
  th data-tabulatr-column-name=column.full_name style=column.html_header_style class=classes
31
31
  = column.human_name
32
32
  tbody
@@ -34,7 +34,7 @@
34
34
  tr.empty_row
35
35
  - columns.each do |column|
36
36
  - classes = column.sortable ? ['tabulatr-sortable'] : []
37
- - classes = [classes, column.classes].flatten.compact.join(' ')
37
+ - classes = [classes, "tabulatr-column-#{column.coltype}", column.classes].flatten.compact.join(' ')
38
38
  td data-tabulatr-column-name=column.full_name data-tabulatr-type=column.coltype style=column.html_cell_style class=classes
39
39
  .tabulatr-spinner-box data-table=table_id
40
40
  = image_tag "#{Tabulatr.spinner}-loader.gif"
@@ -1,4 +1,4 @@
1
- / Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
1
+ / Copyright (c) 2010-2014 Peter Horn & Florian Thomas, tickettoaster GmbH
2
2
  /
3
3
  / Permission is hereby granted, free of charge, to any person obtaining
4
4
  / a copy of this software and associated documentation files (the
@@ -24,7 +24,7 @@
24
24
  .dropdown
25
25
  a.btn.btn-default data-toggle="dropdown" href="#"
26
26
  i.icon-cog.glyphicon.glyphicon-cog.fa.fa-cog'
27
- i.icon-caret-down.glyphicon.glyphicon-caret-down.fa.fa-caret-down
27
+ i.icon-caret-down.glyphicon.glyphicon-chevron-down.fa.fa-caret-down
28
28
  ul.dropdown-menu role="menu" aria-labelledby="dLabel"
29
29
  - table_options[:batch_actions].each do |key, label|
30
30
  li
@@ -0,0 +1,19 @@
1
+ //{:buttons=>[{:icon=>:"eye-open", :path=>"/products/1", :options=>{:class=>"btn-success"}}, {:icon=>:pencil, :path=>"/products/1/edit", :options=>{:class=>"btn-warning"}}], :submenu=>[{:icon=>:star, :path=>"/products/1", :label=>"Dolle Sache"}, :divider, {:icon=>:"trash-o", :path=>"/products/1", :label=>"Löschen", :options=>{:confirm=>"echt?", :class=>"btn-danger", :method=>:delete}}]}
2
+ .btn-group
3
+ - buttons[:buttons].each do |button|
4
+ - o = (button[:options] || {}).merge(class: "btn btn-sm btn-default #{button[:options].try(:[], :class)}")
5
+ = link_to fa_icon(button[:icon]), button[:path], o
6
+ - if buttons[:submenu].present?
7
+ button.btn.btn-default.btn-sm.dropdown-toggle data-toggle='dropdown'
8
+ span.caret
9
+ ul.dropdown-menu role='menu'
10
+ - buttons[:submenu].each do |button|
11
+ - if button == :divider
12
+ li.divider role="presentation"
13
+ - else
14
+ li= link_to button[:path], button[:options] do
15
+ - if button[:icon].present?
16
+ => fa_icon(button[:icon])
17
+ - if button[:label].present?
18
+ = button[:label]
19
+
@@ -1,4 +1,4 @@
1
- / Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
1
+ / Copyright (c) 2010-2014 Peter Horn & Florian Thomas, tickettoaster GmbH
2
2
  /
3
3
  / Permission is hereby granted, free of charge, to any person obtaining
4
4
  / a copy of this software and associated documentation files (the
@@ -1,4 +1,4 @@
1
- / Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
1
+ / Copyright (c) 2010-2014 Peter Horn & Florian Thomas, tickettoaster GmbH
2
2
  /
3
3
  / Permission is hereby granted, free of charge, to any person obtaining
4
4
  / a copy of this software and associated documentation files (the
@@ -23,7 +23,7 @@
23
23
  .dropdown
24
24
  a.btn.btn-default data-toggle="dropdown" href="#"
25
25
  i.icon-filter.glyphicon.glyphicon-filter.fa.fa-filter'
26
- i.icon-caret-down.glyphicon.glyphicon-caret-down.fa.fa-caret-down
26
+ i.icon-caret-down.glyphicon.glyphicon-chevron-down.fa.fa-caret-down
27
27
  ul.dropdown-menu role="menu" aria-labelledby="dLabel"
28
28
  - columns.select(&:filter).each do |column|
29
29
  li
@@ -1,4 +1,4 @@
1
- / Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
1
+ / Copyright (c) 2010-2014 Peter Horn & Florian Thomas, tickettoaster GmbH
2
2
  /
3
3
  / Permission is hereby granted, free of charge, to any person obtaining
4
4
  / a copy of this software and associated documentation files (the
@@ -1,4 +1,4 @@
1
- / Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
1
+ / Copyright (c) 2010-2014 Peter Horn & Florian Thomas, tickettoaster GmbH
2
2
  /
3
3
  / Permission is hereby granted, free of charge, to any person obtaining
4
4
  / a copy of this software and associated documentation files (the
@@ -1,4 +1,4 @@
1
- / Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
1
+ / Copyright (c) 2010-2014 Peter Horn & Florian Thomas, tickettoaster GmbH
2
2
  /
3
3
  / Permission is hereby granted, free of charge, to any person obtaining
4
4
  / a copy of this software and associated documentation files (the
@@ -1,4 +1,4 @@
1
- / Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
1
+ / Copyright (c) 2010-2014 Peter Horn & Florian Thomas, tickettoaster GmbH
2
2
  /
3
3
  / Permission is hereby granted, free of charge, to any person obtaining
4
4
  / a copy of this software and associated documentation files (the
@@ -23,11 +23,11 @@ table class="#{table_options[:html_class]} tabulatr_static_table"
23
23
  thead
24
24
  tr
25
25
  - columns.each do |column|
26
- th data-tabulatr-column-name=column.full_name style=column.html_header_style
26
+ th data-tabulatr-column-name=column.full_name style=column.html_header_style class=["tabulatr-column-#{column.coltype}", column.classes].flatten.compact.join(' ')
27
27
  = column.human_name
28
28
  tbody
29
29
  - records.each do |record|
30
30
  tr data-id=record.try(:id)
31
31
  - columns.each do |column|
32
- td data-tabulatr-column-name=column.full_name data-tabulatr-type=column.coltype style=column.html_cell_style
32
+ td data-tabulatr-column-name=column.full_name data-tabulatr-type=column.coltype style=column.html_cell_style class=["tabulatr-column-#{column.coltype}", column.classes].flatten.compact.join(' ')
33
33
  = column.value_for(record, self)
@@ -1,4 +1,4 @@
1
- / Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
1
+ / Copyright (c) 2010-2014 Peter Horn & Florian Thomas, tickettoaster GmbH
2
2
  /
3
3
  / Permission is hereby granted, free of charge, to any person obtaining
4
4
  / a copy of this software and associated documentation files (the
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
2
+ # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, tickettoaster GmbH
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -0,0 +1,71 @@
1
+ #--
2
+ # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, tickettoaster GmbH
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ # buttons do |b,r|
25
+ # b.button :'eye-open', foo_path(r), class: 'btn-success'
26
+ # b.button :'pencil', edit_foo_path(r), class: 'btn-warning'
27
+ # b.submenu do |s|
28
+ # s.button :star, star_foor_path(r), label: 'Dolle Sache'
29
+ # s.divider
30
+ # s.button :'trash-o', foo_path(r), label: 'Löschen', confirm: 'echt?', class: 'btn-danger', method: :delete
31
+ # end
32
+ # end
33
+
34
+
35
+ class Tabulatr::Data::ButtonBuilder
36
+
37
+ def initialize
38
+ @mode = :buttons
39
+ @buttons = []
40
+ @submenu = []
41
+ val
42
+ end
43
+
44
+ def val
45
+ {buttons: @buttons, submenu: @submenu}
46
+ end
47
+
48
+ def button(icon, path, options={})
49
+ label = options.dup.delete(:label)
50
+ if @mode == :buttons
51
+ @buttons << {icon: icon, path: path, options: options}
52
+ else
53
+ @submenu << {icon: icon, label: label, path: path, options: options}
54
+ end
55
+ val
56
+ end
57
+
58
+ def submenu(&block)
59
+ raise "No submenus in submenus, sorry" if @mode == :submenu
60
+ @mode = :submenu
61
+ yield(self)
62
+ @mode = :buttons
63
+ val
64
+ end
65
+
66
+ def divider
67
+ raise "use dividers only in submenu" unless @mode == :submenu
68
+ @submenu << :divider
69
+ val
70
+ end
71
+ end
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
2
+ # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, tickettoaster GmbH
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -38,7 +38,7 @@ class Tabulatr::Data
38
38
  end
39
39
  end
40
40
 
41
- def data_for_table(params, locals: {}, &block)
41
+ def data_for_table(params, locals: {}, controller: nil, &block)
42
42
 
43
43
  @batch_actions = block if block_given?
44
44
 
@@ -59,7 +59,7 @@ class Tabulatr::Data
59
59
  # TODO: batch actions and checked ids
60
60
 
61
61
  # get the records
62
- found = apply_formats(locals: locals)
62
+ found = apply_formats(locals: locals, controller: controller)
63
63
 
64
64
  append = params[:append].present? ? Tabulatr::Utility.string_to_boolean(params[:append]) : false
65
65
 
@@ -139,3 +139,4 @@ require_relative './pagination'
139
139
  require_relative './formatting'
140
140
  require_relative './row'
141
141
  require_relative './proxy'
142
+ require_relative './button_builder'
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
2
+ # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, tickettoaster GmbH
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -44,8 +44,16 @@ module Tabulatr::Data::DSL
44
44
  end
45
45
  end
46
46
 
47
- def column(name, sort_sql: nil, filter_sql: nil, sql: nil, table_column_options: {}, &block)
47
+ def column(name, sort_sql: nil, filter_sql: nil, sql: nil, table_column_options: {},
48
+ classes: nil, width: false, align: false, valign: false, wrap: nil, th_html: false,
49
+ filter_html: false, filter: true, sortable: true, format: nil, map: true, cell_style: {},
50
+ header_style: {},
51
+ &block)
48
52
  @table_columns ||= []
53
+ table_column_options = {classes: classes, width: width, align: align, valign: valign, wrap: wrap,
54
+ th_html: th_html, filter_html: filter_html, filter: filter, sortable: sortable,
55
+ format: format, map: map, cell_style: cell_style, header_style: header_style
56
+ }.merge(table_column_options)
49
57
  table_name = main_class.table_name
50
58
  table_column = Tabulatr::Renderer::Column.from(
51
59
  table_column_options.merge(name: name,
@@ -56,8 +64,16 @@ module Tabulatr::Data::DSL
56
64
  @table_columns << table_column
57
65
  end
58
66
 
59
- def association(assoc, name, sort_sql: nil, filter_sql: nil, sql: nil, table_column_options: {}, &block)
67
+ def association(assoc, name, sort_sql: nil, filter_sql: nil, sql: nil, table_column_options: {},
68
+ classes: nil, width: false, align: false, valign: false, wrap: nil, th_html: false,
69
+ filter_html: false, filter: true, sortable: true, format: nil, map: true, cell_style: {},
70
+ header_style: {},
71
+ &block)
60
72
  @table_columns ||= []
73
+ table_column_options = {classes: classes, width: width, align: align, valign: valign, wrap: wrap,
74
+ th_html: th_html, filter_html: filter_html, filter: filter, sortable: sortable,
75
+ format: format, map: map, cell_style: cell_style, header_style: header_style
76
+ }.merge(table_column_options)
61
77
  assoc_klass = main_class.reflect_on_association(assoc.to_sym)
62
78
  t_name = assoc_klass.try(:table_name)
63
79
  table_column = Tabulatr::Renderer::Association.from(
@@ -69,17 +85,70 @@ module Tabulatr::Data::DSL
69
85
  @table_columns << table_column
70
86
  end
71
87
 
72
- def search(*args, &block)
73
- raise "either column or block" if args.present? && block_given?
74
- @search = args.presence || block
88
+ def actions(header: nil, name: nil, table_column_options: {},
89
+ classes: nil, width: false, align: false, valign: false, wrap: nil, th_html: false,
90
+ filter_html: false, filter: true, sortable: true, format: nil, map: true, cell_style: {},
91
+ header_style: {},
92
+ &block)
93
+ raise 'give a block to action column' unless block_given?
94
+ @table_columns ||= []
95
+ table_column_options = {classes: classes, width: width, align: align, valign: valign, wrap: wrap,
96
+ th_html: th_html, filter_html: filter_html, filter: filter, sortable: sortable,
97
+ format: format, map: map, cell_style: cell_style, header_style: header_style
98
+ }.merge(table_column_options)
99
+ table_column = Tabulatr::Renderer::Action.from(
100
+ table_column_options.merge(
101
+ name: (name || '_actions'), table_name: main_class.table_name.to_sym,
102
+ klass: @base, header: header || '',
103
+ filter: false, sortable: false,
104
+ output: block))
105
+ @table_columns << table_column
106
+ end
107
+
108
+ def buttons(header: nil, name: nil, table_column_options: {},
109
+ classes: nil, width: false, align: false, valign: false, wrap: nil, th_html: false,
110
+ filter_html: false, filter: true, sortable: true, format: nil, map: true, cell_style: {},
111
+ header_style: {},
112
+ &block)
113
+ raise 'give a block to action column' unless block_given?
114
+ @table_columns ||= []
115
+ table_column_options = {classes: classes, width: width, align: align, valign: valign, wrap: wrap,
116
+ th_html: th_html, filter_html: filter_html, filter: filter, sortable: sortable,
117
+ format: format, map: map, cell_style: cell_style, header_style: header_style
118
+ }.merge(table_column_options)
119
+ output = ->(r) {
120
+ tdbb = Tabulatr::Data::ButtonBuilder.new
121
+ self.instance_exec tdbb, r, &block
122
+ bb = tdbb.val
123
+ self.controller.render_to_string partial: '/tabulatr/tabulatr_buttons', locals: {buttons: bb}, formats: [:html]
124
+ }
125
+ table_column = Tabulatr::Renderer::Buttons.from(
126
+ table_column_options = table_column_options.merge(
127
+ name: (name || '_buttons'), table_name: main_class.table_name.to_sym,
128
+ klass: @base, header: header || '',
129
+ filter: false, sortable: false,
130
+ output: output))
131
+ @table_columns << table_column
75
132
  end
76
133
 
77
- def checkbox(table_column_options: {})
134
+ def checkbox(table_column_options: {},
135
+ classes: nil, width: false, align: false, valign: false, wrap: nil, th_html: false,
136
+ filter_html: false, filter: true, sortable: true, format: nil, map: true, cell_style: {},
137
+ header_style: {})
78
138
  @table_columns ||= []
79
- box = Tabulatr::Renderer::Checkbox.from(table_column_options.merge(klass: @base, filter: false, sortable: false))
139
+ table_column_options = {classes: classes, width: width, align: align, valign: valign, wrap: wrap,
140
+ th_html: th_html, filter_html: filter_html, filter: filter, sortable: sortable,
141
+ format: format, map: map, cell_style: cell_style, header_style: header_style
142
+ }.merge(table_column_options)
143
+ box = Tabulatr::Renderer::Checkbox.from(table_column_options = table_column_options.merge(klass: @base, filter: false, sortable: false))
80
144
  @table_columns << box
81
145
  end
82
146
 
147
+ def search(*args, &block)
148
+ raise "either column or block" if args.present? && block_given?
149
+ @search = args.presence || block
150
+ end
151
+
83
152
  def row &block
84
153
  raise 'Please pass a block to row if you want to use it.' unless block_given?
85
154
  @row = block
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
2
+ # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, tickettoaster GmbH
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
2
+ # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, tickettoaster GmbH
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -23,14 +23,14 @@
23
23
 
24
24
  module Tabulatr::Data::Formatting
25
25
 
26
- def apply_formats(locals: {})
27
- view = Data::Proxy.new(locals: locals)
26
+ def apply_formats(locals: {}, controller: nil)
27
+ view = Data::Proxy.new(locals: locals, controller: controller)
28
28
  return @relation.map do |record|
29
29
  view.record = record
30
30
  h = HashWithIndifferentAccess.new
31
31
  table_columns.each do |tc|
32
32
  h[tc.table_name] ||= HashWithIndifferentAccess.new
33
- h[tc.table_name][tc.name] = format_column(record, tc.output, view)
33
+ h[tc.table_name][tc.name] = tc.value_for(record, view)
34
34
  end
35
35
  h[:_row_config] = format_row(view, @row)
36
36
  h[:id] = record.id
@@ -38,10 +38,6 @@ module Tabulatr::Data::Formatting
38
38
  end # @relation map
39
39
  end # apply_formats
40
40
 
41
- def format_column(record, output, view)
42
- view.instance_exec(record, &output) if output.present?
43
- end
44
-
45
41
  def format_row(view, row)
46
42
  row_config = Row.new
47
43
  view.instance_exec(view.record, row_config.attributes, &row) if row.is_a?(Proc)
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
2
+ # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, tickettoaster GmbH
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
2
+ # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, tickettoaster GmbH
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
2
+ # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, tickettoaster GmbH
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -23,12 +23,13 @@
23
23
 
24
24
  class Data::Proxy < ActionView::Base
25
25
 
26
- attr_accessor :record
26
+ attr_accessor :record, :controller
27
27
 
28
- def initialize(record=nil, locals: {})
28
+ def initialize(record=nil, locals: {}, controller: nil)
29
29
  self.class._init
30
30
  Rails.application.routes.mounted_helpers.instance_methods.each{|f| self.send(f).instance_variable_set('@scope', self)}
31
31
  @record = record
32
+ @controller = controller
32
33
  locals.each do |nam, val|
33
34
  raise "cowardly refusing to override `#{nam}'" if respond_to? nam
34
35
  define_singleton_method nam do val end
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
2
+ # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, tickettoaster GmbH
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
2
+ # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, tickettoaster GmbH
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
2
+ # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, tickettoaster GmbH
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
2
+ # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, tickettoaster GmbH
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
2
+ # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, tickettoaster GmbH
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
2
+ # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, tickettoaster GmbH
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
2
+ # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, tickettoaster GmbH
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
2
+ # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, tickettoaster GmbH
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -30,11 +30,13 @@ class ActionController::Base
30
30
  klass = relation.respond_to?(:klass) ? relation.klass : relation
31
31
  respond_to do |format|
32
32
  format.json {
33
- records = klass.tabulatr(relation, tabulatr_data_class).data_for_table(params, locals: locals, &block)
33
+ records = klass.tabulatr(relation, tabulatr_data_class).data_for_table(params, locals: locals, controller: self, &block)
34
34
  render json: records.to_tabulatr_json(serializer)
35
+ records
35
36
  }
36
37
  format.html {
37
38
  render action: render_action || action_name
39
+ nil
38
40
  }
39
41
  end
40
42
  end
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
2
+ # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, tickettoaster GmbH
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
2
+ # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, tickettoaster GmbH
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
2
+ # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, tickettoaster GmbH
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
2
+ # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, tickettoaster GmbH
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -30,7 +30,8 @@ class Tabulatr::Renderer::Association < Tabulatr::Renderer::Column
30
30
  def column?() false end
31
31
  def association?() true end
32
32
 
33
- def principal_value(record)
33
+ def principal_value(record, view)
34
+ return super if output
34
35
  v = record.send(table_name)
35
36
  if v && v.respond_to?(:to_a) && map && name != :count
36
37
  v.map(&:"#{name}")
@@ -0,0 +1,32 @@
1
+ #--
2
+ # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, tickettoaster GmbH
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ class Tabulatr::Renderer::Buttons < Tabulatr::Renderer::Action
25
+ def human_name
26
+ header
27
+ end
28
+
29
+ def coltype() 'buttons' end
30
+ def column?() false end
31
+ def action?() true end
32
+ end
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
2
+ # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, tickettoaster GmbH
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
2
+ # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, tickettoaster GmbH
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -51,7 +51,6 @@ class Tabulatr::Renderer::Column
51
51
  filter_sql: nil,
52
52
  output: nil,
53
53
  &block)
54
- b = block_given? ? block : nil
55
54
  self.new(
56
55
  name: name,
57
56
  table_name: table_name,
@@ -68,7 +67,7 @@ class Tabulatr::Renderer::Column
68
67
  format: format,
69
68
  map: map,
70
69
  klass: klass,
71
- block: b,
70
+ block: block,
72
71
  cell_style: cell_style,
73
72
  header_style: header_style,
74
73
  sort_sql: sort_sql,
@@ -143,12 +142,7 @@ class Tabulatr::Renderer::Column
143
142
  end
144
143
 
145
144
  def value_for(record, view)
146
- if block
147
- r = view.instance_exec(record, &block)
148
- r = r.join(' ').html_safe if r.is_a?(Array)
149
- return r
150
- end
151
- val = principal_value(record) or return ''
145
+ val = principal_value(record, view)
152
146
  if format.present? && val.respond_to?(:to_ary)
153
147
  val.map do |v|
154
148
  case format
@@ -170,8 +164,16 @@ class Tabulatr::Renderer::Column
170
164
  end
171
165
  end
172
166
 
173
- def principal_value(record)
174
- record.send name
167
+ def principal_value(record, view)
168
+ if output
169
+ view.instance_exec(record, &output)
170
+ elsif block
171
+ view.instance_exec(record, &block)
172
+ elsif name
173
+ record.send name
174
+ else
175
+ nil
176
+ end
175
177
  end
176
178
 
177
179
  def determine_appropriate_filter!
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
2
+ # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, tickettoaster GmbH
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -57,6 +57,14 @@ class Tabulatr::Renderer
57
57
  @columns << Action.from(opts.merge(klass: klass, filter: false, sortable: false), &block)
58
58
  end
59
59
 
60
+ def buttons(opts={}, &block)
61
+ output = ->(r) {
62
+ bb = self.instance_exec Tabulatr::Data::ButtonBuilder.new, r, &block
63
+ self.controller.render_to_string partial: '/tabulatr/tabulatr_buttons', locals: {buttons: bb}, formats: [:html]
64
+ }
65
+ @columns << Buttons.from(opts.merge(klass: klass, filter: false, sortable: false, output: output), &block)
66
+ end
67
+
60
68
  def self.process(klass, table_data_object = nil, &block)
61
69
  i = self.new(klass, table_data_object)
62
70
  yield(i)
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
2
+ # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, tickettoaster GmbH
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -114,8 +114,8 @@ class Tabulatr::Renderer
114
114
  r = "#{r.keys.first}:#{r.values.first}"
115
115
  end
116
116
  result = available_columns.find{|column| column.full_name.to_sym == r.to_sym }
117
- result = available_columns.find{|column| column.name.to_sym == r.to_sym && column.table_name == main_table_name} if result.nil?
118
- result
117
+ result ||= available_columns.find{|column| column.name.to_sym == r.to_sym && column.table_name == main_table_name}
118
+ result or raise "Can't find column '#{r}'"
119
119
  end.flatten
120
120
  end
121
121
 
@@ -124,5 +124,6 @@ end
124
124
  require_relative './column'
125
125
  require_relative './association'
126
126
  require_relative './action'
127
+ require_relative './buttons'
127
128
  require_relative './checkbox'
128
129
  require_relative './columns_from_block'
@@ -2,8 +2,7 @@ module Tabulatr
2
2
  class RequestDataNotIncludedError < StandardError
3
3
 
4
4
  def self.raise_error(method, object)
5
- raise self, "You requested '#{method}' on '#{object}' but
6
- there was no such method included in your TabulatrData"
5
+ raise self, "You requested '#{method}' on '#{object}' but there was no such method included in your TabulatrData"
7
6
  end
8
7
  end
9
- end
8
+ end
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
2
+ # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, tickettoaster GmbH
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
2
+ # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, tickettoaster GmbH
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -22,5 +22,5 @@
22
22
  #++
23
23
 
24
24
  module Tabulatr
25
- VERSION = "0.9.7"
25
+ VERSION = "0.9.10"
26
26
  end
@@ -22,7 +22,7 @@ class ProductTabulatrData < Tabulatr::Data
22
22
  table_column_options: {header: 'Product by vendor'} do
23
23
  "#{record.title} from #{record.vendor.try(:name)}"
24
24
  end
25
- column :active, table_column_options: {sortable: false}
25
+ column :active, sortable: false
26
26
  column :updated_at, table_column_options: { filter: :date } do "#{record.updated_at.strftime('%H:%M %d.%m.%Y')}" end
27
27
  association :vendor, :name, table_column_options: { filter: :exact }
28
28
  association :tags, :title do |r|
@@ -30,4 +30,14 @@ class ProductTabulatrData < Tabulatr::Data
30
30
  end
31
31
  association :tags, :count
32
32
 
33
+ buttons width: '200px' do |b,r|
34
+ b.button :eye, product_path(r), class: 'btn-success'
35
+ b.button :pencil, edit_product_path(r), class: 'btn-warning'
36
+ b.submenu do |s|
37
+ s.button :star, product_path(r), label: 'Dolle Sache'
38
+ s.divider
39
+ s.button :'trash-o', product_path(r), label: 'Löschen', confirm: 'echt?', class: 'btn-danger', method: :delete
40
+ end
41
+ "haha!"
42
+ end
33
43
  end
@@ -1,4 +1,4 @@
1
1
  <%= table_for Product, paginate: true, persistent: false,
2
2
  batch_actions: {a: "Hallo", b: "Du da!"},
3
- columns: [:title, :price, :active, :vendor_product_name, :updated_at,
3
+ columns: [:'_buttons', :title, :price, :active, :vendor_product_name, :updated_at,
4
4
  {vendor: :name}, 'tags:title'] %>
@@ -17,4 +17,7 @@
17
17
  t.action header: "ACTION!" do |t|
18
18
  t.title.upcase
19
19
  end
20
+ t.buttons do |b,r|
21
+ b.button :eye, product_path(r)
22
+ end
20
23
  end or "empty" %>
@@ -1,5 +1,5 @@
1
1
  Rails.application.routes.draw do
2
- resources :products, only: [:index, :show] do
2
+ resources :products, only: [:index, :show, :edit] do
3
3
  collection do
4
4
  get :simple_index
5
5
  get :one_item_per_page_with_pagination
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.7
4
+ version: 0.9.10
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-05-27 00:00:00.000000000 Z
13
+ date: 2014-07-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -102,6 +102,7 @@ files:
102
102
  - app/assets/stylesheets/tabulatr/bootstrap2_fixes.css.scss
103
103
  - app/views/tabulatr/_tabulatr_actual_table.html.slim
104
104
  - app/views/tabulatr/_tabulatr_batch_actions_menu.html.slim
105
+ - app/views/tabulatr/_tabulatr_buttons.html.slim
105
106
  - app/views/tabulatr/_tabulatr_filter_dialog.html.slim
106
107
  - app/views/tabulatr/_tabulatr_filter_menu.html.slim
107
108
  - app/views/tabulatr/_tabulatr_fuzzy_search_field.html.slim
@@ -111,6 +112,7 @@ files:
111
112
  - app/views/tabulatr/_tabulatr_table.html.slim
112
113
  - init.rb
113
114
  - lib/tabulatr.rb
115
+ - lib/tabulatr/data/button_builder.rb
114
116
  - lib/tabulatr/data/data.rb
115
117
  - lib/tabulatr/data/dsl.rb
116
118
  - lib/tabulatr/data/filtering.rb
@@ -133,6 +135,7 @@ files:
133
135
  - lib/tabulatr/rails/active_record.rb
134
136
  - lib/tabulatr/renderer/action.rb
135
137
  - lib/tabulatr/renderer/association.rb
138
+ - lib/tabulatr/renderer/buttons.rb
136
139
  - lib/tabulatr/renderer/checkbox.rb
137
140
  - lib/tabulatr/renderer/column.rb
138
141
  - lib/tabulatr/renderer/columns_from_block.rb