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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c6cf3d2c260e9964ab1aa9865d14af11fe287e49b6216ae260ae575567c0e89
|
4
|
+
data.tar.gz: 495df145a9060198ca69bfd1eaeea836b6bba24287a804e69d100fab5d36cbd1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03b3e0f445067d05f32313a7c4e519545ee6396eca549e75719de294380df8be3be2d5e95c6dfcf262d563eb5db4cd8e3ebabcae753075a4b61f69a6957c5c1d
|
7
|
+
data.tar.gz: 498e3dfb9d3580fa69bfaf959df282567590cbdee12d2ad3bc65fcbb7f7101c70fd9d7d5aba2e78ea6a09547afe0fc4161dd478495110bcfe8efe3887e0d7040
|
data/Gemfile.lock
CHANGED
@@ -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
|
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
|
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(
|
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
|
-
|
58
|
-
sql.concat("#{
|
59
|
-
sql.concat(' OR ') unless
|
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] *
|
80
|
+
*terms.map { |e| [e] * query_variables.size }.flatten
|
67
81
|
)
|
68
82
|
end
|
69
83
|
records
|
data/lib/cm_admin/version.rb
CHANGED
@@ -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
|