cm-admin 0.8.6 → 0.8.8
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/Gemfile.lock +4 -4
- data/app/assets/stylesheets/cm_admin/base/scaffold.scss +1 -1
- data/app/assets/stylesheets/cm_admin/base/table.scss +0 -1
- data/app/controllers/cm_admin/resource_controller.rb +20 -17
- data/app/views/cm_admin/main/_associated_table.html.slim +1 -1
- data/app/views/cm_admin/main/_table.html.slim +1 -1
- data/lib/cm-admin.rb +1 -0
- data/lib/cm_admin/models/filter.rb +20 -6
- data/lib/cm_admin/version.rb +1 -1
- data/lib/cm_admin/view_helpers.rb +5 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b0716af97418b0a394649987f80dc9ccffa7ebe3476f53c71be4ffee7d3121f
|
4
|
+
data.tar.gz: c920089946afedbe268496bd0a8cb05d44dd950aad3c5b5dd7eb296180700871
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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.
|
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.
|
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.
|
149
|
+
zeitwerk (2.6.4)
|
150
150
|
|
151
151
|
PLATFORMS
|
152
152
|
ruby
|
@@ -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
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
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
|
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
|
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(
|
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
|
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.
|
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-
|
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.
|
320
|
+
rubygems_version: 3.2.33
|
320
321
|
signing_key:
|
321
322
|
specification_version: 4
|
322
323
|
summary: This is an admin panel gem
|