cm-admin 0.8.6 → 0.8.7

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: 47fc71a05e69092828694cc38ea2722580571bff16dfd6a9e52a59fd1177820f
4
- data.tar.gz: 547bbce4e9127b0c411a9a869cdb0621ce3dcd191d24846e64bdec0415403d26
3
+ metadata.gz: 7c6cf3d2c260e9964ab1aa9865d14af11fe287e49b6216ae260ae575567c0e89
4
+ data.tar.gz: 495df145a9060198ca69bfd1eaeea836b6bba24287a804e69d100fab5d36cbd1
5
5
  SHA512:
6
- metadata.gz: 13a83281f4010e9f7921089047e5c7ca60577ce61587413f2475cb0747b801bfdc9beb03744f8595a94743ad15a187b48f80547be5a8bd8b5217c40595551532
7
- data.tar.gz: 8ac891bb57c06f67ede8e325196a693a78c79ef4b7a19d0f2ba72e53ce65f0273e7872916ce7fbe0883dad8c959b2c11ee6195962a81f9c098210e24ca61eb67
6
+ metadata.gz: 03b3e0f445067d05f32313a7c4e519545ee6396eca549e75719de294380df8be3be2d5e95c6dfcf262d563eb5db4cd8e3ebabcae753075a4b61f69a6957c5c1d
7
+ data.tar.gz: 498e3dfb9d3580fa69bfaf959df282567590cbdee12d2ad3bc65fcbb7f7101c70fd9d7d5aba2e78ea6a09547afe0fc4161dd478495110bcfe8efe3887e0d7040
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cm-admin (0.8.6)
4
+ cm-admin (0.8.7)
5
5
  caxlsx_rails
6
6
  cocoon (~> 1.2.15)
7
7
  csv-importer (~> 0.8.2)
@@ -3,7 +3,7 @@
3
3
  - if @associated_model.filters.present? && @action.partial.nil?
4
4
  .index-page__filters
5
5
  == render partial: 'cm_admin/main/filters', locals: { filters: @associated_model.filters }
6
- p.table-top__total-count = "#{@associated_ar_object.pagy.count} #{@action.child_records.to_s.gsub('_', ' ')} found"
6
+ p.table-top__total-count = "#{humanized_ar_collection_count(@associated_ar_object.pagy.count, @action.child_records.to_s)}"
7
7
  .table-top__column-action
8
8
  - if @associated_model && @associated_model.available_actions.map(&:name).include?('new') && has_valid_policy(@associated_model.name, 'new')
9
9
  - association = @ar_object.class.reflect_on_all_associations.select{|x| x.name == @associated_model.name.tableize.to_sym }.first
@@ -1,6 +1,6 @@
1
1
  .admin-table-index
2
2
  .table-top
3
- p.table-top__total-count = "#{@ar_object.pagy.count} #{@model.ar_model.table_name} found"
3
+ p.table-top__total-count = "#{humanized_ar_collection_count(@ar_object.pagy.count, @model.ar_model.table_name)}"
4
4
  // .table-top__column-action
5
5
  // button.secondary-btn.column-btn data-bs-target="#columnActionModal" data-bs-toggle="modal"
6
6
  // span
@@ -19,7 +19,7 @@ module CmAdmin
19
19
 
20
20
  case filter_type
21
21
  when :search
22
- db_column_name = (Array.new << db_column_name).flatten.map(&:to_sym)
22
+ db_column_name = (Array.new << db_column_name).flatten.map{|x| x.class.eql?(Hash) ? x : x.to_sym}
23
23
  else
24
24
  db_column_name = db_column_name.is_a?(Array) ? db_column_name[0].to_sym : db_column_name.to_sym
25
25
  end
@@ -47,23 +47,37 @@ module CmAdmin
47
47
  def cm_search_filter(scope_value, records, filters)
48
48
  return nil if scope_value.blank?
49
49
  table_name = records.table_name
50
-
51
50
  filters.select{|x| x if x.filter_type.eql?(:search)}.each do |filter|
51
+ query_variables = []
52
+ filter.db_column_name.each do |col|
53
+ if col.is_a?(Symbol)
54
+ query_variables << "#{table_name.pluralize}.#{col}"
55
+ elsif col.is_a?(Hash)
56
+ col.map do |key, value|
57
+ value.map {|val| query_variables << "#{key.to_s.pluralize}.#{val}" }
58
+ end
59
+ end
60
+ end
52
61
  terms = scope_value.downcase.split(/\s+/)
53
62
  terms = terms.map { |e|
54
63
  (e.gsub('*', '%').prepend('%') + '%').gsub(/%+/, '%')
55
64
  }
56
65
  sql = ""
57
- filter.db_column_name.each.with_index do |column, i|
58
- sql.concat("#{table_name}.#{column} ILIKE ?")
59
- sql.concat(' OR ') unless filter.db_column_name.size.eql?(i+1)
66
+ query_variables.each.with_index do |column, i|
67
+ sql.concat("#{column} ILIKE ?")
68
+ sql.concat(' OR ') unless query_variables.size.eql?(i+1)
69
+ end
70
+
71
+ if filter.db_column_name.map{|x| x.is_a?(Hash)}.include?(true)
72
+ associations_hash = filter.db_column_name.select{|x| x if x.is_a?(Hash)}.last
73
+ records = records.joins(associations_hash.keys)
60
74
  end
61
75
 
62
76
  records = records.where(
63
77
  terms.map { |term|
64
78
  sql
65
79
  }.join(' AND '),
66
- *terms.map { |e| [e] * filter.db_column_name.size }.flatten
80
+ *terms.map { |e| [e] * query_variables.size }.flatten
67
81
  )
68
82
  end
69
83
  records
@@ -1,3 +1,3 @@
1
1
  module CmAdmin
2
- VERSION = "0.8.6"
2
+ VERSION = "0.8.7"
3
3
  end
@@ -72,5 +72,10 @@ module CmAdmin
72
72
  concat " #{column_path.to_s.gsub('/', '_').humanize}"
73
73
  end
74
74
  end
75
+
76
+ def humanized_ar_collection_count(count, model_name)
77
+ table_name = count == 1 ? model_name.singularize : model_name.pluralize
78
+ return "#{count} #{table_name.humanize.downcase} found"
79
+ end
75
80
  end
76
81
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cm-admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.6
4
+ version: 0.8.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - sajinmp