cm-admin 1.5.5 → 1.5.7
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 +1 -1
- data/app/controllers/cm_admin/resource_controller.rb +11 -6
- data/app/helpers/cm_admin/application_helper.rb +17 -4
- data/app/views/cm_admin/main/_associated_table.html.slim +3 -2
- data/lib/cm_admin/model.rb +1 -1
- data/lib/cm_admin/version.rb +1 -1
- data/lib/cm_admin/view_helpers/form_helper.rb +25 -5
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2683d5547505d258f1bf7c0ea82236130ec6287ead5ab3670a29d909bc7a895
|
4
|
+
data.tar.gz: ad8a5db9a2a05d60ba04ced18d09591c56b78dc0cf849823c9a63b296ec43454
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7630c3561997e736dc4a0400d2c734d3e383545f11a5173061196fc84ab12b27322ac6f3945168db80e50713158d341534573632b148c3f682314c7a32fbdc0f
|
7
|
+
data.tar.gz: edef5e258984bdd78e2a195ad0434df645d13a8c8c4a84254ea9689b7ede1d1aaa6b0e1fad0a2e0ed87c415e1219f4406991411e8bb7f7dfc93b66a6f672ea4a
|
data/Gemfile.lock
CHANGED
@@ -11,11 +11,11 @@ module CmAdmin
|
|
11
11
|
records = "CmAdmin::#{@model.name}Policy::Scope".constantize.new(Current.user, @model.name.constantize).resolve
|
12
12
|
records = apply_scopes(records)
|
13
13
|
if (['table', 'card'].include?(params[:view_type]) || [:table, :card].include?(@current_action.view_type))
|
14
|
-
@ar_object = filter_by(params, records, @model.filter_params(params))
|
14
|
+
@ar_object = filter_by(params, records, filter_params: @model.filter_params(params))
|
15
15
|
elsif (request.xhr? && params[:view_type] == 'kanban') || @current_action.view_type == :kanban
|
16
16
|
@ar_object = kanban_filter_by(params, records, @model.filter_params(params))
|
17
17
|
else
|
18
|
-
@ar_object = filter_by(params, records, @model.filter_params(params))
|
18
|
+
@ar_object = filter_by(params, records, filter_params: @model.filter_params(params))
|
19
19
|
end
|
20
20
|
respond_to do |format|
|
21
21
|
if request.xhr? && (params[:view_type] == 'kanban' || @current_action.view_type == :kanban)
|
@@ -132,7 +132,7 @@ module CmAdmin
|
|
132
132
|
@current_action = @action
|
133
133
|
if @action.parent == 'index'
|
134
134
|
records = apply_scopes(records)
|
135
|
-
@ar_object = filter_by(params, records, @model.filter_params(params))
|
135
|
+
@ar_object = filter_by(params, records, filter_params: @model.filter_params(params))
|
136
136
|
else
|
137
137
|
resource_identifier
|
138
138
|
end
|
@@ -233,8 +233,10 @@ module CmAdmin
|
|
233
233
|
else
|
234
234
|
CmAdmin::Model.find_by(name: @reflection.klass.name)
|
235
235
|
end
|
236
|
+
|
236
237
|
@associated_ar_object = if child_records.is_a? ActiveRecord::Relation
|
237
|
-
|
238
|
+
|
239
|
+
filter_by(params, child_records, parent_record: @ar_object, filter_params: @associated_model.filter_params(params))
|
238
240
|
else
|
239
241
|
child_records
|
240
242
|
end
|
@@ -248,7 +250,7 @@ module CmAdmin
|
|
248
250
|
records
|
249
251
|
end
|
250
252
|
|
251
|
-
def filter_by(params, records, filter_params
|
253
|
+
def filter_by(params, records, parent_record: nil, filter_params: {}, sort_params: {})
|
252
254
|
filtered_result = OpenStruct.new
|
253
255
|
cm_model = @associated_model || @model
|
254
256
|
db_columns = cm_model.ar_model&.columns&.map{|x| x.name.to_sym}
|
@@ -263,6 +265,9 @@ module CmAdmin
|
|
263
265
|
pagy, records = pagy(final_data)
|
264
266
|
filtered_result.data = records
|
265
267
|
filtered_result.pagy = pagy
|
268
|
+
filtered_result.parent_record = parent_record
|
269
|
+
filtered_result.associated_model = @associated_model.name if @associated_model
|
270
|
+
# filtered_result.ar_model =
|
266
271
|
# filtered_result.facets = paginate(page, raw_data.size)
|
267
272
|
# filtered_result.sort = sort_params
|
268
273
|
# filtered_result.facets.sort = sort_params
|
@@ -354,7 +359,7 @@ module CmAdmin
|
|
354
359
|
end
|
355
360
|
|
356
361
|
private
|
357
|
-
|
362
|
+
|
358
363
|
def attachment_fields(model_object)
|
359
364
|
model_object.reflect_on_all_associations.map {|reflection|
|
360
365
|
next if reflection.options[:polymorphic]
|
@@ -7,10 +7,22 @@ module CmAdmin
|
|
7
7
|
|
8
8
|
# Allow if policy is not defined.
|
9
9
|
def has_valid_policy(ar_object, action_name)
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
if ar_object.instance_of?(OpenStruct) && ar_object&.parent_record.present? && ar_object&.associated_model.present?
|
11
|
+
policy_object = ar_object.parent_record
|
12
|
+
associated_model = ar_object.associated_model
|
13
|
+
|
14
|
+
policy_instance = "CmAdmin::#{associated_model}Policy".constantize.new(:cm_admin, policy_object)
|
15
|
+
|
16
|
+
return true unless policy_instance.methods.include?(:"#{action_name}?")
|
17
|
+
|
18
|
+
policy_instance.send(:"#{action_name}?")
|
19
|
+
else
|
20
|
+
policy_object = ar_object.instance_of?(OpenStruct) ? @model.name.classify.constantize : ar_object
|
21
|
+
|
22
|
+
return true unless policy([:cm_admin, policy_object]).methods.include?(:"#{action_name}?")
|
23
|
+
|
24
|
+
policy([:cm_admin, policy_object]).send(:"#{action_name}?")
|
25
|
+
end
|
14
26
|
end
|
15
27
|
|
16
28
|
def action(action_name)
|
@@ -66,6 +78,7 @@ module CmAdmin
|
|
66
78
|
end
|
67
79
|
|
68
80
|
def is_show_action_available(model, ar_object)
|
81
|
+
|
69
82
|
model &&
|
70
83
|
model.available_actions.map(&:name).include?('show') &&
|
71
84
|
has_valid_policy(ar_object, 'show')
|
@@ -4,6 +4,7 @@
|
|
4
4
|
== render partial: 'cm_admin/main/filters', locals: { filters: @associated_model.filters }
|
5
5
|
p.table-top__total-count = "#{humanized_ar_collection_count(@associated_ar_object.pagy.count, @action.child_records.to_s)}"
|
6
6
|
.table-top__column-action
|
7
|
+
-
|
7
8
|
- if @associated_model && @associated_model.available_actions.map(&:name).include?('new') && has_valid_policy(@associated_ar_object, 'new')
|
8
9
|
- association = @ar_object.class.reflect_on_all_associations.select{|x| x.name == @associated_model.name.tableize.to_sym }.first
|
9
10
|
- polymorphic_name = (association && association.inverse_of && association.inverse_of.options[:polymorphic]) ? association.inverse_of.name : ''
|
@@ -53,11 +54,11 @@
|
|
53
54
|
= show_field_value(ar_object, column)
|
54
55
|
- if column.field_type == :drawer
|
55
56
|
= render partial: column.drawer_partial, locals: { ar_object: ar_object }
|
56
|
-
|
57
|
+
|
57
58
|
- if @associated_model
|
58
59
|
== render partial: 'cm_admin/main/actions_dropdown', locals: { cm_model: @associated_model, ar_object: ar_object }
|
59
60
|
|
60
61
|
.pagination-bar
|
61
62
|
p.count-text.m-0 Showing #{@associated_ar_object.pagy.from} to #{@associated_ar_object.pagy.to} out of #{@associated_ar_object.pagy.count}
|
62
63
|
== render partial: 'cm_admin/main/cm_pagy_nav', locals: { pagy: @associated_ar_object.pagy }
|
63
|
-
/ = render partial: 'cm_admin/main/member_custom_action_modal', locals: { cm_model: @associated_model, ar_collection: @associated_ar_object }
|
64
|
+
/ = render partial: 'cm_admin/main/member_custom_action_modal', locals: { cm_model: @associated_model, ar_collection: @associated_ar_object }
|
data/lib/cm_admin/model.rb
CHANGED
data/lib/cm_admin/version.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
require_relative 'form_field_helper'
|
2
|
+
require 'cgi'
|
3
|
+
require 'uri'
|
4
|
+
|
2
5
|
module CmAdmin
|
3
6
|
module ViewHelpers
|
4
7
|
module FormHelper
|
@@ -123,21 +126,38 @@ module CmAdmin
|
|
123
126
|
end
|
124
127
|
|
125
128
|
def set_form_with_sections(resource, entities, url, method)
|
129
|
+
polymorphic_name, associated_id, associated_class = extract_referrer_query_params
|
126
130
|
form_for(resource, url: url, method: method, html: { class: "cm_#{resource.class.name.downcase}_form" } ) do |form_obj|
|
127
131
|
if params[:referrer]
|
128
132
|
concat form_obj.text_field "referrer", class: "normal-input", hidden: true, value: params[:referrer], name: 'referrer'
|
129
133
|
end
|
130
|
-
if params[:polymorphic_name].present?
|
131
|
-
concat form_obj.text_field params[:polymorphic_name] + '_type', class: "normal-input", hidden: true, value: params[:associated_class].classify
|
132
|
-
concat form_obj.text_field params[:polymorphic_name] + '_id', class: "normal-input", hidden: true, value: params[:associated_id]
|
133
|
-
elsif params[:associated_class] && params[:associated_id]
|
134
|
-
concat form_obj.text_field params[:associated_class] + '_id', class: "normal-input", hidden: true, value: params[:associated_id]
|
134
|
+
if params[:polymorphic_name].present? || polymorphic_name.present?
|
135
|
+
concat form_obj.text_field ( params[:polymorphic_name] || polymorphic_name ) + '_type', class: "normal-input", hidden: true, value: ( params[:associated_class] || associated_class ).classify
|
136
|
+
concat form_obj.text_field ( params[:polymorphic_name] || polymorphic_name ) + '_id', class: "normal-input", hidden: true, value: ( params[:associated_id] || associated_id )
|
137
|
+
elsif (params[:associated_class] && params[:associated_id] || associated_id.present? && associated_class.present? )
|
138
|
+
concat form_obj.text_field ( params[:associated_class] || associated_class ) + '_id', class: "normal-input", hidden: true, value: ( params[:associated_id] || associated_id )
|
135
139
|
end
|
140
|
+
|
136
141
|
concat split_form_into_section(resource, form_obj, entities)
|
137
142
|
concat tag.br
|
138
143
|
concat form_obj.submit 'Save', class: 'btn-cta', data: {behaviour: 'form_submit', form_class: "cm_#{form_obj.object.class.name.downcase}_form"}
|
139
144
|
end
|
140
145
|
end
|
146
|
+
|
147
|
+
|
148
|
+
def extract_referrer_query_params
|
149
|
+
uri = URI.parse(request.referrer)
|
150
|
+
|
151
|
+
return unless uri.query.present?
|
152
|
+
|
153
|
+
query_params = CGI.parse(uri.query)
|
154
|
+
|
155
|
+
polymorphic_name = query_params['polymorphic_name'].first
|
156
|
+
associated_id = query_params['associated_id'].first
|
157
|
+
associated_class = query_params['associated_class'].first
|
158
|
+
|
159
|
+
return polymorphic_name, associated_id, associated_class
|
160
|
+
end
|
141
161
|
end
|
142
162
|
end
|
143
163
|
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: 1.5.
|
4
|
+
version: 1.5.7
|
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: 2024-05-
|
13
|
+
date: 2024-05-30 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: caxlsx_rails
|
@@ -498,7 +498,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
498
498
|
- !ruby/object:Gem::Version
|
499
499
|
version: '0'
|
500
500
|
requirements: []
|
501
|
-
rubygems_version: 3.
|
501
|
+
rubygems_version: 3.5.3
|
502
502
|
signing_key:
|
503
503
|
specification_version: 4
|
504
504
|
summary: CmAdmin is a robust gem designed to assist in creating admin panels for Rails
|