effective_datatables 2.11.1 → 2.11.2
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 +4 -4
 - data/app/assets/javascripts/effective_datatables/charts.js.coffee +3 -2
 - data/app/assets/javascripts/effective_datatables/initialize.js.coffee +7 -0
 - data/app/helpers/effective_datatables_private_helper.rb +2 -2
 - data/app/models/effective/datatable.rb +2 -5
 - data/app/models/effective/effective_datatable/ajax.rb +1 -1
 - data/app/models/effective/effective_datatable/options.rb +13 -4
 - data/app/views/effective/datatables/_actions_column.html.haml +4 -4
 - data/app/views/effective/datatables/_datatable.html.haml +15 -3
 - data/lib/effective_datatables/version.rb +1 -1
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 89fe9d65ab41811c5fe6f99d2a30178cdd17558e
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 3778600b8979aeb4ec2553e00aef1dbd9d856e58
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: d25d50f56c92c86e72c812ff0d58ba59658cbe5856ff42965d5988406c7bca194e36114e6ad0958a135bd1447d7b3ed63bd6f2db7d2562eed02ae596662c0c1e
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: e5cf61f381816ab5946f7e5f689f644c522e9181d05940a73535018aae9ea5cc6b21394a8e7976921b53d4fde2a708d2b6458adcee37c59ac4ba775c0af09885
         
     | 
| 
         @@ -6,8 +6,9 @@ initializeCharts = -> 
     | 
|
| 
       6 
6 
     | 
    
         
             
                type = $chart.data('type') || 'BarChart'
         
     | 
| 
       7 
7 
     | 
    
         
             
                options = $chart.data('options') || {}
         
     | 
| 
       8 
8 
     | 
    
         | 
| 
       9 
     | 
    
         
            -
                 
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
      
 9 
     | 
    
         
            +
                if google
         
     | 
| 
      
 10 
     | 
    
         
            +
                  chart = new google.visualization[type](document.getElementById($chart.attr('id')))
         
     | 
| 
      
 11 
     | 
    
         
            +
                  chart.draw(google.visualization.arrayToDataTable(data), options)
         
     | 
| 
       11 
12 
     | 
    
         | 
| 
       12 
13 
     | 
    
         
             
            $ -> initializeCharts()
         
     | 
| 
       13 
14 
     | 
    
         
             
            $(document).on 'page:change', -> initializeCharts()
         
     | 
| 
         @@ -175,6 +175,13 @@ destroyDataTables = -> 
     | 
|
| 
       175 
175 
     | 
    
         
             
                if $.fn.DataTable.fnIsDataTable(this)
         
     | 
| 
       176 
176 
     | 
    
         
             
                  $(this).DataTable().destroy()
         
     | 
| 
       177 
177 
     | 
    
         | 
| 
      
 178 
     | 
    
         
            +
            anotherDestroy = ->
         
     | 
| 
      
 179 
     | 
    
         
            +
              for settings in $.fn.dataTable.settings
         
     | 
| 
      
 180 
     | 
    
         
            +
                $(settings.nTableWrapper).unbind('.DT').find(':not(tbody *)').unbind('.DT')
         
     | 
| 
      
 181 
     | 
    
         
            +
                $(window).unbind('.DT-'+settings.sInstance)
         
     | 
| 
      
 182 
     | 
    
         
            +
             
     | 
| 
      
 183 
     | 
    
         
            +
              $.fn.dataTable.settings.length = 0
         
     | 
| 
      
 184 
     | 
    
         
            +
             
     | 
| 
       178 
185 
     | 
    
         
             
            $ -> initializeDataTables()
         
     | 
| 
       179 
186 
     | 
    
         
             
            $(document).on 'page:change', -> initializeDataTables()
         
     | 
| 
       180 
187 
     | 
    
         
             
            $(document).on 'turbolinks:load', -> initializeDataTables()
         
     | 
| 
         @@ -43,7 +43,7 @@ module EffectiveDatatablesPrivateHelper 
     | 
|
| 
       43 
43 
     | 
    
         | 
| 
       44 
44 
     | 
    
         
             
                include_blank = opts[:filter].key?(:include_blank) ? opts[:filter][:include_blank] : (opts[:label] || name.titleize)
         
     | 
| 
       45 
45 
     | 
    
         
             
                pattern = opts[:filter].key?(:pattern) ? opts[:filter][:pattern] : nil
         
     | 
| 
       46 
     | 
    
         
            -
                placeholder =  
     | 
| 
      
 46 
     | 
    
         
            +
                placeholder = (opts[:filter][:placeholder] || '')
         
     | 
| 
       47 
47 
     | 
    
         
             
                title = opts[:filter].key?(:title) ? opts[:filter][:title] : (opts[:label] || name.titleize)
         
     | 
| 
       48 
48 
     | 
    
         
             
                wrapper_html = { class: 'datatable_filter' }
         
     | 
| 
       49 
49 
     | 
    
         | 
| 
         @@ -60,7 +60,7 @@ module EffectiveDatatablesPrivateHelper 
     | 
|
| 
       60 
60 
     | 
    
         | 
| 
       61 
61 
     | 
    
         
             
                  form.input name, label: false, required: false, value: value,
         
     | 
| 
       62 
62 
     | 
    
         
             
                    as: :string,
         
     | 
| 
       63 
     | 
    
         
            -
                    placeholder: placeholder,
         
     | 
| 
      
 63 
     | 
    
         
            +
                    placeholder: placeholder.presence || '###-####-###',
         
     | 
| 
       64 
64 
     | 
    
         
             
                    wrapper_html: wrapper_html,
         
     | 
| 
       65 
65 
     | 
    
         
             
                    input_html: { name: nil, value: value, title: title, pattern: pattern, autocomplete: 'off', data: {'column-name' => opts[:name], 'column-index' => opts[:index]} }
         
     | 
| 
       66 
66 
     | 
    
         
             
                when :date
         
     | 
| 
         @@ -22,13 +22,10 @@ module Effective 
     | 
|
| 
       22 
22 
     | 
    
         
             
                include Effective::EffectiveDatatable::Rendering
         
     | 
| 
       23 
23 
     | 
    
         | 
| 
       24 
24 
     | 
    
         
             
                def initialize(*args)
         
     | 
| 
       25 
     | 
    
         
            -
                  if respond_to?(:initialize_scopes) # There was at least one scope defined in the scopes do .. end block
         
     | 
| 
       26 
     | 
    
         
            -
                    initialize_scopes
         
     | 
| 
       27 
     | 
    
         
            -
                  end
         
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
25 
     | 
    
         
             
                  initialize_attributes(args)
         
     | 
| 
       30 
26 
     | 
    
         | 
| 
       31 
     | 
    
         
            -
                  if respond_to?(:initialize_scopes) 
     | 
| 
      
 27 
     | 
    
         
            +
                  if respond_to?(:initialize_scopes) # There was at least one scope defined in the scopes do .. end block
         
     | 
| 
      
 28 
     | 
    
         
            +
                    initialize_scopes
         
     | 
| 
       32 
29 
     | 
    
         
             
                    initialize_scope_options
         
     | 
| 
       33 
30 
     | 
    
         
             
                  end
         
     | 
| 
       34 
31 
     | 
    
         | 
| 
         @@ -27,7 +27,7 @@ module Effective 
     | 
|
| 
       27 
27 
     | 
    
         
             
                        (params[:columns][order_by_column_index] || {})[:name]
         
     | 
| 
       28 
28 
     | 
    
         
             
                      elsif @default_order.present?
         
     | 
| 
       29 
29 
     | 
    
         
             
                        @default_order.keys.first
         
     | 
| 
       30 
     | 
    
         
            -
                      end || table_columns.find { |col, opts| opts[:type] != :bulk_actions_column }.first
         
     | 
| 
      
 30 
     | 
    
         
            +
                      end || table_columns.find { |col, opts| opts[:type] != :bulk_actions_column }.try(:first)
         
     | 
| 
       31 
31 
     | 
    
         
             
                    end
         
     | 
| 
       32 
32 
     | 
    
         
             
                  end
         
     | 
| 
       33 
33 
     | 
    
         | 
| 
         @@ -29,11 +29,14 @@ module Effective 
     | 
|
| 
       29 
29 
     | 
    
         | 
| 
       30 
30 
     | 
    
         
             
                  def _initialize_attributes(args)
         
     | 
| 
       31 
31 
     | 
    
         
             
                    args.compact.each do |arg|
         
     | 
| 
       32 
     | 
    
         
            -
                       
     | 
| 
      
 32 
     | 
    
         
            +
                      # ActionController::Parameters / Rails 5 hack. TODO.
         
     | 
| 
      
 33 
     | 
    
         
            +
                      if arg.respond_to?(:permit)
         
     | 
| 
      
 34 
     | 
    
         
            +
                        arg = (arg.respond_to?(:to_unsafe_h) ? arg.to_unsafe_h : arg.to_h)
         
     | 
| 
      
 35 
     | 
    
         
            +
                      end
         
     | 
| 
       33 
36 
     | 
    
         | 
| 
       34 
37 
     | 
    
         
             
                      raise "#{self.class.name}.new() can only be initialized with a Hash like arguments" unless arg.kind_of?(Hash)
         
     | 
| 
       35 
38 
     | 
    
         | 
| 
       36 
     | 
    
         
            -
                      arg.each { |k, v| self.attributes[k] = v 
     | 
| 
      
 39 
     | 
    
         
            +
                      arg.each { |k, v| self.attributes[k] = v }
         
     | 
| 
       37 
40 
     | 
    
         
             
                    end
         
     | 
| 
       38 
41 
     | 
    
         
             
                  end
         
     | 
| 
       39 
42 
     | 
    
         | 
| 
         @@ -86,7 +89,7 @@ module Effective 
     | 
|
| 
       86 
89 
     | 
    
         
             
                    # We set some memoized helper values
         
     | 
| 
       87 
90 
     | 
    
         
             
                    @collection_class = (collection.respond_to?(:klass) ? collection.klass : self.class)
         
     | 
| 
       88 
91 
     | 
    
         
             
                    @active_record_collection = (collection.ancestors.include?(ActiveRecord::Base) rescue false)
         
     | 
| 
       89 
     | 
    
         
            -
                    @array_collection = (collection.kind_of?(Array) && collection.first.kind_of?(Array))
         
     | 
| 
      
 92 
     | 
    
         
            +
                    @array_collection = (collection.kind_of?(Array) && (collection.length == 0 || collection.first.kind_of?(Array)))
         
     | 
| 
       90 
93 
     | 
    
         | 
| 
       91 
94 
     | 
    
         
             
                    # And then parse all the colums
         
     | 
| 
       92 
95 
     | 
    
         
             
                    sql_table = (collection.table rescue nil)
         
     | 
| 
         @@ -118,7 +121,7 @@ module Effective 
     | 
|
| 
       118 
121 
     | 
    
         
             
                      end
         
     | 
| 
       119 
122 
     | 
    
         
             
                    end
         
     | 
| 
       120 
123 
     | 
    
         | 
| 
       121 
     | 
    
         
            -
                    table_columns = cols.each_with_index do |(name, _), index|
         
     | 
| 
      
 124 
     | 
    
         
            +
                    table_columns = (cols || {}).each_with_index do |(name, _), index|
         
     | 
| 
       122 
125 
     | 
    
         
             
                      sql_column = (collection.columns rescue []).find do |column|
         
     | 
| 
       123 
126 
     | 
    
         
             
                        column.name == name.to_s || (belong_tos.key?(name) && column.name == belong_tos[name][:foreign_key])
         
     | 
| 
       124 
127 
     | 
    
         
             
                      end
         
     | 
| 
         @@ -239,6 +242,8 @@ module Effective 
     | 
|
| 
       239 
242 
     | 
    
         
             
                        collection: (
         
     | 
| 
       240 
243 
     | 
    
         
             
                          if belongs_to[:klass].respond_to?(:datatables_filter)
         
     | 
| 
       241 
244 
     | 
    
         
             
                            Proc.new { belongs_to[:klass].datatables_filter }
         
     | 
| 
      
 245 
     | 
    
         
            +
                          elsif belongs_to[:klass].respond_to?(:sorted)
         
     | 
| 
      
 246 
     | 
    
         
            +
                            Proc.new { belongs_to[:klass].sorted }
         
     | 
| 
       242 
247 
     | 
    
         
             
                          else
         
     | 
| 
       243 
248 
     | 
    
         
             
                            Proc.new { belongs_to[:klass].all.map { |obj| [obj.to_s, obj.id] }.sort { |x, y| x[0] <=> y[0] } }
         
     | 
| 
       244 
249 
     | 
    
         
             
                          end
         
     | 
| 
         @@ -253,6 +258,8 @@ module Effective 
     | 
|
| 
       253 
258 
     | 
    
         
             
                        collection: (
         
     | 
| 
       254 
259 
     | 
    
         
             
                          if has_many[:klass].respond_to?(:datatables_filter)
         
     | 
| 
       255 
260 
     | 
    
         
             
                            Proc.new { has_many[:klass].datatables_filter }
         
     | 
| 
      
 261 
     | 
    
         
            +
                          elsif has_many[:klass].respond_to?(:sorted)
         
     | 
| 
      
 262 
     | 
    
         
            +
                            Proc.new { has_many[:klass].sorted }
         
     | 
| 
       256 
263 
     | 
    
         
             
                          else
         
     | 
| 
       257 
264 
     | 
    
         
             
                            Proc.new { has_many[:klass].all.map { |obj| [obj.to_s, obj.id] }.sort { |x, y| x[0] <=> y[0] } }
         
     | 
| 
       258 
265 
     | 
    
         
             
                          end
         
     | 
| 
         @@ -265,6 +272,8 @@ module Effective 
     | 
|
| 
       265 
272 
     | 
    
         
             
                        collection: (
         
     | 
| 
       266 
273 
     | 
    
         
             
                          if has_and_belongs_to_manys[:klass].respond_to?(:datatables_filter)
         
     | 
| 
       267 
274 
     | 
    
         
             
                            Proc.new { has_and_belongs_to_manys[:klass].datatables_filter }
         
     | 
| 
      
 275 
     | 
    
         
            +
                          elsif has_and_belongs_to_manys[:klass].respond_to?(:sorted)
         
     | 
| 
      
 276 
     | 
    
         
            +
                            Proc.new { has_and_belongs_to_manys[:klass].sorted }
         
     | 
| 
       268 
277 
     | 
    
         
             
                          else
         
     | 
| 
       269 
278 
     | 
    
         
             
                            Proc.new { has_and_belongs_to_manys[:klass].all.map { |obj| [obj.to_s, obj.id] }.sort { |x, y| x[0] <=> y[0] } }
         
     | 
| 
       270 
279 
     | 
    
         
             
                          end
         
     | 
| 
         @@ -23,19 +23,19 @@ 
     | 
|
| 
       23 
23 
     | 
    
         
             
                unarchive_action = instance_exec(resource, &unarchive_action)
         
     | 
| 
       24 
24 
     | 
    
         
             
              end
         
     | 
| 
       25 
25 
     | 
    
         | 
| 
       26 
     | 
    
         
            -
            - if show_action && show_path
         
     | 
| 
      
 26 
     | 
    
         
            +
            - if show_action && defined?(show_path)
         
     | 
| 
       27 
27 
     | 
    
         
             
              = show_icon_to show_path.gsub(':to_param', resource.to_param)
         
     | 
| 
       28 
28 
     | 
    
         | 
| 
       29 
     | 
    
         
            -
            - if edit_action && edit_path
         
     | 
| 
      
 29 
     | 
    
         
            +
            - if edit_action && defined?(edit_path)
         
     | 
| 
       30 
30 
     | 
    
         
             
              = edit_icon_to edit_path.gsub(':to_param', resource.to_param)
         
     | 
| 
       31 
31 
     | 
    
         | 
| 
       32 
     | 
    
         
            -
            - if destroy_action && destroy_path
         
     | 
| 
      
 32 
     | 
    
         
            +
            - if destroy_action && defined?(destroy_path)
         
     | 
| 
       33 
33 
     | 
    
         
             
              - if resource.respond_to?(:archived?) && !resource.archived?
         
     | 
| 
       34 
34 
     | 
    
         
             
                = archive_icon_to destroy_path.gsub(':to_param', resource.to_param)
         
     | 
| 
       35 
35 
     | 
    
         
             
              - elsif resource.respond_to?(:archived?) == false
         
     | 
| 
       36 
36 
     | 
    
         
             
                = destroy_icon_to destroy_path.gsub(':to_param', resource.to_param)
         
     | 
| 
       37 
37 
     | 
    
         | 
| 
       38 
     | 
    
         
            -
            - if unarchive_action && unarchive_path
         
     | 
| 
      
 38 
     | 
    
         
            +
            - if unarchive_action && defined?(unarchive_path)
         
     | 
| 
       39 
39 
     | 
    
         
             
              - if resource.respond_to?(:archived?) && resource.archived?
         
     | 
| 
       40 
40 
     | 
    
         
             
                = unarchive_icon_to unarchive_path.gsub(':to_param', resource.to_param)
         
     | 
| 
       41 
41 
     | 
    
         | 
| 
         @@ -18,9 +18,21 @@ 
     | 
|
| 
       18 
18 
     | 
    
         | 
| 
       19 
19 
     | 
    
         
             
            %table.effective-datatable{effective_datatable_params}
         
     | 
| 
       20 
20 
     | 
    
         
             
              %thead
         
     | 
| 
       21 
     | 
    
         
            -
                 
     | 
| 
       22 
     | 
    
         
            -
                   
     | 
| 
       23 
     | 
    
         
            -
                     
     | 
| 
      
 21 
     | 
    
         
            +
                - if datatable.table_columns.any? { |_, opts| opts[:th].present? } == false
         
     | 
| 
      
 22 
     | 
    
         
            +
                  %tr
         
     | 
| 
      
 23 
     | 
    
         
            +
                    - datatable.table_columns.each do |name, opts|
         
     | 
| 
      
 24 
     | 
    
         
            +
                      %th= opts[:label] || name
         
     | 
| 
      
 25 
     | 
    
         
            +
                - else
         
     | 
| 
      
 26 
     | 
    
         
            +
                  - max_depth = datatable.table_columns.map { |_, opts| opts[:th].try(:[], :depth) || 0 }.max
         
     | 
| 
      
 27 
     | 
    
         
            +
                  - [*0..max_depth].each do |depth|
         
     | 
| 
      
 28 
     | 
    
         
            +
                    %tr
         
     | 
| 
      
 29 
     | 
    
         
            +
                      - table_columns = datatable.table_columns.select { |_, opts| (opts[:th].try(:[], :depth) || 0) == depth }
         
     | 
| 
      
 30 
     | 
    
         
            +
                      - table_columns.each do |name, opts|
         
     | 
| 
      
 31 
     | 
    
         
            +
                        %th{(opts[:th] || {}).merge(title: (opts[:label] || name))}
         
     | 
| 
      
 32 
     | 
    
         
            +
                          = opts[:label] || name
         
     | 
| 
      
 33 
     | 
    
         
            +
                        - (opts[:append_th] || []).each do |faux_col|
         
     | 
| 
      
 34 
     | 
    
         
            +
                          %th{(faux_col[:th] || {}).merge(title: faux_col[:label])}
         
     | 
| 
      
 35 
     | 
    
         
            +
                            = faux_col[:label]
         
     | 
| 
       24 
36 
     | 
    
         | 
| 
       25 
37 
     | 
    
         
             
              %tbody
         
     | 
| 
       26 
38 
     | 
    
         
             
                - datatable.to_json[:data].each do |row|
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: effective_datatables
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 2.11. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 2.11.2
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Code and Effect
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2017- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2017-02-03 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: rails
         
     |