cm-admin 0.8.6 → 0.8.8

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: 1b0716af97418b0a394649987f80dc9ccffa7ebe3476f53c71be4ffee7d3121f
4
+ data.tar.gz: c920089946afedbe268496bd0a8cb05d44dd950aad3c5b5dd7eb296180700871
5
5
  SHA512:
6
- metadata.gz: 13a83281f4010e9f7921089047e5c7ca60577ce61587413f2475cb0747b801bfdc9beb03744f8595a94743ad15a187b48f80547be5a8bd8b5217c40595551532
7
- data.tar.gz: 8ac891bb57c06f67ede8e325196a693a78c79ef4b7a19d0f2ba72e53ce65f0273e7872916ce7fbe0883dad8c959b2c11ee6195962a81f9c098210e24ca61eb67
6
+ metadata.gz: e7e2cea04419473813adb4d3d5500bf6fb3e5a897aaf0572387c9a42bff4207e1a7539b4314e1d6bea138b76708788018f9c30ac3132e685da992f0b649e4a6a
7
+ data.tar.gz: 95cda0809b447a0cce7cc4b20ffce7308a74ec8feac2b91e0b63ac02060472abe2fb360e8c44a525a3609be956ce18d7adb232b64a730911b93ce59951e19e33
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.8)
5
5
  caxlsx_rails
6
6
  cocoon (~> 1.2.15)
7
7
  csv-importer (~> 0.8.2)
@@ -38,7 +38,7 @@ GEM
38
38
  ice_nine (~> 0.11.0)
39
39
  thread_safe (~> 0.3, >= 0.3.1)
40
40
  builder (3.2.4)
41
- caxlsx (3.2.0)
41
+ caxlsx (3.3.0)
42
42
  htmlentities (~> 4.3, >= 4.3.4)
43
43
  marcel (~> 1.0)
44
44
  nokogiri (~> 1.10, >= 1.10.4)
@@ -69,7 +69,7 @@ GEM
69
69
  method_source (1.0.0)
70
70
  mini_portile2 (2.8.0)
71
71
  minitest (5.16.2)
72
- nokogiri (1.13.8)
72
+ nokogiri (1.13.9)
73
73
  mini_portile2 (~> 2.8.0)
74
74
  racc (~> 1.4)
75
75
  pagy (4.11.0)
@@ -146,7 +146,7 @@ GEM
146
146
  rack-proxy (>= 0.6.1)
147
147
  railties (>= 5.2)
148
148
  semantic_range (>= 2.3.0)
149
- zeitwerk (2.6.1)
149
+ zeitwerk (2.6.4)
150
150
 
151
151
  PLATFORMS
152
152
  ruby
@@ -72,7 +72,7 @@ a {
72
72
  position: sticky;
73
73
  top: 0;
74
74
  background-color: #fff;
75
- z-index: 1;
75
+ z-index: 4;
76
76
  }
77
77
 
78
78
  .scrollable {
@@ -6,7 +6,6 @@
6
6
  overflow: auto;
7
7
 
8
8
  .sticky-container {
9
- z-index: 4;
10
9
  .cm-filters-v2 {
11
10
  padding: 16px 24px 36px 24px;
12
11
  }
@@ -153,22 +153,25 @@ module CmAdmin
153
153
  end
154
154
 
155
155
  def custom_controller_action(action_name, params)
156
- current_action = CmAdmin::Models::Action.find_by(@model, name: action_name.to_s)
157
- if current_action
158
- @current_action = current_action
159
- @ar_object = @model.ar_model.name.classify.constantize.find(params[:id])
160
- if @current_action.child_records
161
- child_records = @ar_object.send(@current_action.child_records)
162
- @associated_model = CmAdmin::Model.find_by(name: @model.ar_model.reflect_on_association(@current_action.child_records).klass.name)
163
- if child_records.is_a? ActiveRecord::Relation
164
- @associated_ar_object = filter_by(params, child_records, @associated_model.filter_params(params))
165
- else
166
- @associated_ar_object = child_records
167
- end
168
- return @ar_object, @associated_model, @associated_ar_object
169
- end
170
- return @ar_object
171
- end
156
+ @current_action = CmAdmin::Models::Action.find_by(@model, name: action_name.to_s)
157
+ return unless @current_action
158
+
159
+ @ar_object = @model.ar_model.name.classify.constantize.find(params[:id])
160
+ return @ar_object unless @current_action.child_records
161
+
162
+ child_records = @ar_object.send(@current_action.child_records)
163
+ @reflection = @model.ar_model.reflect_on_association(@current_action.child_records)
164
+ @associated_model = if @reflection.klass.column_names.include?('type')
165
+ CmAdmin::Model.find_by(name: @reflection.plural_name.classify)
166
+ else
167
+ CmAdmin::Model.find_by(name: @reflection.klass.name)
168
+ end
169
+ @associated_ar_object = if child_records.is_a? ActiveRecord::Relation
170
+ filter_by(params, child_records, @associated_model.filter_params(params))
171
+ else
172
+ child_records
173
+ end
174
+ return @ar_object, @associated_model, @associated_ar_object
172
175
  end
173
176
 
174
177
  def filter_by(params, records, filter_params={}, sort_params={})
@@ -176,7 +179,7 @@ module CmAdmin
176
179
  sort_column = "created_at"
177
180
  sort_direction = %w[asc desc].include?(sort_params[:sort_direction]) ? sort_params[:sort_direction] : "asc"
178
181
  sort_params = {sort_column: sort_column, sort_direction: sort_direction}
179
-
182
+
180
183
  records = "CmAdmin::#{@model.name}Policy::Scope".constantize.new(Current.user, @model.name.constantize).resolve if records.nil?
181
184
  records = records.order("#{@current_action.sort_column} #{@current_action.sort_direction}")
182
185
  final_data = CmAdmin::Models::Filter.filtered_data(filter_params, records, @associated_model ? @associated_model.filters : @model.filters)
@@ -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
data/lib/cm-admin.rb ADDED
@@ -0,0 +1 @@
1
+ require 'cm_admin'
@@ -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.8"
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.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - sajinmp
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2022-10-22 00:00:00.000000000 Z
13
+ date: 2022-11-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: caxlsx_rails
@@ -231,6 +231,7 @@ files:
231
231
  - config/webpack/test.js
232
232
  - config/webpacker.yml
233
233
  - lib/.DS_Store
234
+ - lib/cm-admin.rb
234
235
  - lib/cm_admin.rb
235
236
  - lib/cm_admin/configuration.rb
236
237
  - lib/cm_admin/constants.rb
@@ -316,7 +317,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
316
317
  - !ruby/object:Gem::Version
317
318
  version: '0'
318
319
  requirements: []
319
- rubygems_version: 3.2.3
320
+ rubygems_version: 3.2.33
320
321
  signing_key:
321
322
  specification_version: 4
322
323
  summary: This is an admin panel gem