effective_resources 2.19.9 → 2.19.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a64aa8daa41dc12a1702ee128d8a972ec46a005f616f2091f9821075c817f9c7
4
- data.tar.gz: c59a857b8b39855a74bfda837b59c259d92b192081c9af65947ad22de202d074
3
+ metadata.gz: 0fc5b41757668d88d0ae83b6a52f332ad18e645658909bf80c69b3fa47dd3b98
4
+ data.tar.gz: 55830a5d7d49dfea77885a2741dd06f335f6dbbc6cf80b86beccc39b720e9535
5
5
  SHA512:
6
- metadata.gz: 71b49bf9d7152eeee999e1fffec4020355274f140c6c6e3bc4757cc8c69716808816bff5bf96b8332028ddedbf8ef24633616ea827118154bd7935aa0804a83a
7
- data.tar.gz: 1ff8ec49ce929e048e9582134447046c03448c7d0a2d0fb794c6024e83a03d705a9193a63336bd6fd7d4b0e64f1e08e44ceb2f54de281c175f3de0cb344170ac
6
+ metadata.gz: ef99fd38dede8d87305ef660a87cc95ea64b9307812d80b7dd14cd2f2b4da7dd5e8532ac2ddf9e39521cdd637ab5027a4c8534bb1a8bc5ee134576a148d16f24
7
+ data.tar.gz: 7527c0b651f37c1046299286e8165bb4a3670e879227b4be7ce83c6fb3c742eab7876f2c54138f1cd25bad281b13a69d2da5085c3b629d38f3a7d34e5fb07dd7
@@ -78,7 +78,9 @@ module EffectiveResourcesHelper
78
78
 
79
79
  # Assign actions
80
80
  # We filter out any actions passed to us that aren't supported
81
- actions = if atts.key?(:actions)
81
+ actions = if atts.key?(:actions) && atts[:actions] == false
82
+ {}
83
+ elsif atts.key?(:actions)
82
84
  {}.tap do |actions|
83
85
  atts[:actions].each do |commit, opts|
84
86
  actions[commit] = opts if (effective_resource.actions.include?(opts[:action]) || opts[:path]).present?
@@ -24,13 +24,15 @@ module ActsAsEmailForm
24
24
  attr_accessor :email_form_subject
25
25
  attr_accessor :email_form_body
26
26
 
27
- effective_resource do
28
- email_form_action :string, permitted: true
29
- email_form_skip :boolean, permitted: true
30
-
31
- email_form_from :string, permitted: true
32
- email_form_subject :string, permitted: true
33
- email_form_body :text, permitted: true
27
+ if respond_to?(:effective_resource)
28
+ effective_resource do
29
+ email_form_action :string, permitted: true
30
+ email_form_skip :boolean, permitted: true
31
+
32
+ email_form_from :string, permitted: true
33
+ email_form_subject :string, permitted: true
34
+ email_form_body :text, permitted: true
35
+ end
34
36
  end
35
37
 
36
38
  with_options(if: -> { email_form_action.present? && !email_form_skip? }) do
@@ -394,6 +394,7 @@ module Effective
394
394
  end
395
395
 
396
396
  return relation.none() if columns.blank?
397
+
397
398
  search_columns_by_ilike_term(relation, value, columns: columns, fuzzy: fuzzy)
398
399
  end
399
400
 
@@ -404,42 +405,33 @@ module Effective
404
405
 
405
406
  value = value.to_s
406
407
 
407
- raise('unsupported OR and AND syntax') if value.include?(' OR ') && value.include?(' AND ')
408
- raise('expected columns') unless columns.present?
409
-
410
- terms = []
411
- join = ''
412
-
413
- if value.include?(' OR ')
414
- terms = value.split(' OR ')
415
- join = ' OR '
408
+ # Process search terms
409
+ terms = if value.include?(' OR ')
410
+ value.split(' OR ')
416
411
  elsif value.include?(' AND ')
417
- terms = value.split(' AND ')
418
- join = ' AND '
412
+ value.split(' AND ')
419
413
  else
420
- terms = value.split(' ')
421
- join = ' AND '
414
+ value.split(' ')
422
415
  end
423
416
 
424
417
  terms = (terms - [nil, '', ' ']).map(&:strip)
425
- columns = Array(columns)
426
- fuzzy = true if fuzzy.nil?
427
418
 
428
- terms = terms.inject({}) do |hash, term|
429
- hash["term_#{hash.length}".to_sym] = (fuzzy ? "%#{term}%" : term); hash
430
- end
431
-
432
- # Do any of these columns contain all the terms?
433
- conditions = columns.map do |name|
434
- column = (name.to_s.include?('.') ? name : sql_column(name))
435
- raise("expected an sql column for #{name}") if column.blank?
419
+ # Searching these columns with this behaviour
420
+ fuzzy = true if fuzzy.nil?
421
+ joiner = value.include?(' OR ') ? :or : :and
436
422
 
437
- keys = terms.keys.map { |key| (fuzzy ? "#{column} #{ilike} :#{key}" : "#{column} = :#{key}") }
438
- '(' + keys.join(' AND ') + ')'
439
- end.join(' OR ')
423
+ # Each term must match some column. Depending on the joiner, each term must match some column
424
+ terms.map do |term|
425
+ Array(columns).map do |name|
426
+ column = (name.to_s.include?('.') ? name : sql_column(name))
440
427
 
441
- # Do the search
442
- collection.where(conditions, terms)
428
+ if fuzzy
429
+ collection.where("#{column} #{ilike} ?", "%#{term}%")
430
+ else
431
+ collection.where("#{column} = ?", term)
432
+ end
433
+ end.inject(:or)
434
+ end.inject(joiner)
443
435
  end
444
436
 
445
437
  def order_by_associated_conditions(association, sort: nil, direction: :asc, limit: nil)
@@ -2,5 +2,7 @@
2
2
  - action = opts.delete(:action)
3
3
  = link_to(label, (effective_resource.action_path(action, resource) || '#'), opts)
4
4
 
5
- = instance_exec(resource, &format_block) if local_assigns[:format_block]
6
- = yield if block_given?
5
+ - if local_assigns[:format_block] && local_assigns[:datatable]
6
+ = instance_exec(resource, datatable, &format_block)
7
+
8
+ = yield(resource) if block_given?
@@ -5,5 +5,7 @@
5
5
 
6
6
  = dropdown_link_to(label, (effective_resource.action_path(action, resource) || '#'), opts)
7
7
 
8
- = instance_exec(resource, &format_block) if local_assigns[:format_block]
8
+ - if local_assigns[:format_block] && local_assigns[:datatable]
9
+ = instance_exec(resource, datatable, &format_block)
10
+
9
11
  = yield(resource) if block_given?
@@ -4,5 +4,7 @@
4
4
 
5
5
  = glyphicon_to(action, (effective_resource.action_path(action, resource) || '#'), opts)
6
6
 
7
- = instance_exec(resource, &format_block) if local_assigns[:format_block]
7
+ - if local_assigns[:format_block] && local_assigns[:datatable]
8
+ = instance_exec(resource, datatable, &format_block)
9
+
8
10
  = yield(resource) if block_given?
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '2.19.9'.freeze
2
+ VERSION = '2.19.11'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_resources
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.19.9
4
+ version: 2.19.11
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: 2024-03-06 00:00:00.000000000 Z
11
+ date: 2024-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails