cm-admin 1.5.0 → 1.5.2
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 -3
- data/app/assets/javascripts/cm_admin/filters.js +6 -2
- data/app/assets/javascripts/cm_admin/form_validation.js +2 -2
- data/app/controllers/cm_admin/resource_controller.rb +15 -8
- data/app/views/cm_admin/main/_nested_fields.html.slim +8 -6
- data/app/views/cm_admin/main/_nested_table_form.html.slim +1 -1
- data/lib/cm_admin/models/nested_field.rb +3 -1
- data/lib/cm_admin/version.rb +1 -1
- data/lib/cm_admin/view_helpers/form_field_helper.rb +2 -2
- data/lib/cm_admin/view_helpers/form_helper.rb +1 -2
- 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: 6f7069da141483288102690ee44cb4343f343822031103677ab598d0a5ccb0b1
|
4
|
+
data.tar.gz: 50aa27e800231369711bd021dbe17f7ad456b76bc935acee234be6eb87f636b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6ed0804824162768e7edcd8156e58016760a038a1e4e018410b54caec4b197f7d79384e3c54383a5a977754a08b57818d86fdc2a41df596b0c2f74cb4a8bf57
|
7
|
+
data.tar.gz: f06e7efe409134da48d7fd95b3e741fa191cff10ae50ab18da19270653c7fccd316ce893d7fd91c4277deecade00ee2424ad808dd88e9a69e02397b0acfe4351
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
cm-admin (1.5.
|
4
|
+
cm-admin (1.5.2)
|
5
5
|
caxlsx_rails
|
6
6
|
cocoon (~> 1.2.15)
|
7
7
|
csv-importer (~> 0.8.2)
|
@@ -143,8 +143,6 @@ GEM
|
|
143
143
|
nio4r (2.7.1)
|
144
144
|
nokogiri (1.16.4-arm64-darwin)
|
145
145
|
racc (~> 1.4)
|
146
|
-
nokogiri (1.16.4-x86_64-linux)
|
147
|
-
racc (~> 1.4)
|
148
146
|
pagy (4.11.0)
|
149
147
|
parallel (1.22.1)
|
150
148
|
parser (3.1.2.1)
|
@@ -42,7 +42,9 @@ var getFilteredData = function(filterType, filterValue, filterColumn=null) {
|
|
42
42
|
// Generate the queryString by concatenating the filterParams and
|
43
43
|
// searchParams that are already applied, if searchParams are present.
|
44
44
|
var searchParams = window.location.search
|
45
|
-
|
45
|
+
var searchParamshash = getParamsAsObject(searchParams)
|
46
|
+
var tempsearchParamshash = delete searchParamshash['page']
|
47
|
+
if (tempsearchParamshash.length > 0) {
|
46
48
|
// Delete the previous applied value for multi_select filter from the
|
47
49
|
// searchParams as altering the array with new and old value will create
|
48
50
|
// more complicated logic. The new value is passed and structured in
|
@@ -212,6 +214,9 @@ var unhideClearFilterBtn = function(filterValue) {
|
|
212
214
|
}
|
213
215
|
}
|
214
216
|
|
217
|
+
$(document).on('click', '[data-behaviour="select-option"] .cm-checkbox', function(e) {
|
218
|
+
$(this).prop('checked', !$(this).prop('checked'));
|
219
|
+
})
|
215
220
|
// Selecting options for single and multi select filters
|
216
221
|
$(document).on('click', '[data-behaviour="select-option"]', function(e) {
|
217
222
|
var filterType = $(this).data('filter-type')
|
@@ -326,7 +331,6 @@ $(document).on('click', '[data-behaviour="selected-chip"]', function(e) {
|
|
326
331
|
var filterType = $(this).parents(':nth(5)').find('.filter-chip').data('filter-type')
|
327
332
|
var filterColumn = $(this).parents(':nth(5)').find('.filter-chip').data('db-column')
|
328
333
|
var filterValue = $(this).siblings().text()
|
329
|
-
|
330
334
|
var selectElement = $('[data-behaviour="select-option"][data-filter-type=' + filterType + '][data-db-column=' + filterColumn + ']')
|
331
335
|
$(this).parent().remove()
|
332
336
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
$(document).on('click', '
|
1
|
+
$(document).on('click', '[data-behaviour="form_submit"]', function (e) {
|
2
2
|
e.preventDefault();
|
3
3
|
var submit = [];
|
4
4
|
var form_class = $(this).data('form-class');
|
@@ -30,6 +30,6 @@ $(document).on('click', '.form_submit', function (e) {
|
|
30
30
|
});
|
31
31
|
if (submit.length === 0) {
|
32
32
|
$('.' + form_class).submit();
|
33
|
-
return $('
|
33
|
+
return $('[data-behaviour="form_submit"]').button('loading');
|
34
34
|
}
|
35
35
|
});
|
@@ -323,6 +323,7 @@ module CmAdmin
|
|
323
323
|
column_names << generate_nested_params(associated_field)
|
324
324
|
end
|
325
325
|
end
|
326
|
+
column_names += attachment_fields(table_name.to_s.classify.constantize)
|
326
327
|
Hash[
|
327
328
|
"#{table_name}_attributes",
|
328
329
|
column_names
|
@@ -335,14 +336,7 @@ module CmAdmin
|
|
335
336
|
}
|
336
337
|
columns += @model.ar_model.stored_attributes.values.flatten
|
337
338
|
permittable_fields = @model.additional_permitted_fields + columns.reject { |i| CmAdmin::REJECTABLE_FIELDS.include?(i) }
|
338
|
-
permittable_fields += @model.ar_model.name.constantize
|
339
|
-
next if x.options[:polymorphic]
|
340
|
-
if x.class.name.include?('HasOne')
|
341
|
-
x.name.to_s.gsub('_attachment', '').gsub('rich_text_', '').to_sym
|
342
|
-
elsif x.class.name.include?('HasMany')
|
343
|
-
Hash[x.name.to_s.gsub('_attachments', ''), []]
|
344
|
-
end
|
345
|
-
}.compact
|
339
|
+
permittable_fields += attachment_fields(@model.ar_model.name.constantize)
|
346
340
|
nested_table_fields = get_nested_table_fields(@model.available_fields[:new])
|
347
341
|
nested_table_fields += get_nested_table_fields(@model.available_fields[:edit])
|
348
342
|
nested_fields = nested_table_fields.uniq.map {|nested_table_field|
|
@@ -358,5 +352,18 @@ module CmAdmin
|
|
358
352
|
|
359
353
|
model_object.find(id)
|
360
354
|
end
|
355
|
+
|
356
|
+
private
|
357
|
+
|
358
|
+
def attachment_fields(model_object)
|
359
|
+
model_object.reflect_on_all_associations.map {|reflection|
|
360
|
+
next if reflection.options[:polymorphic]
|
361
|
+
if reflection.class.name.include?('HasOne')
|
362
|
+
reflection.name.to_s.gsub('_attachment', '').gsub('rich_text_', '').to_sym
|
363
|
+
elsif reflection.class.name.include?('HasMany')
|
364
|
+
Hash[reflection.name.to_s.gsub('_attachments', ''), []]
|
365
|
+
end
|
366
|
+
}.compact
|
367
|
+
end
|
361
368
|
end
|
362
369
|
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
- if nested_table_field.display_type == :table
|
2
2
|
tr.nested-fields
|
3
3
|
td.item-delete-cell
|
4
|
-
|
4
|
+
- if nested_table_field.is_deletable.call(f.object)
|
5
|
+
= link_to_remove_association "", f, class: 'fa-regular fa-trash-can btn-ghost'
|
5
6
|
- nested_table_field.fields.each do |field|
|
6
7
|
td data-field-type="#{field.input_type}"
|
7
8
|
= input_field_for_column(f, field)
|
@@ -9,11 +10,12 @@
|
|
9
10
|
.form-card.nested-fields
|
10
11
|
.card-body
|
11
12
|
.card-item data-card-name=assoc_name
|
12
|
-
.
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
- if nested_table_field.is_deletable.call(f.object)
|
14
|
+
.card-title-wrapper
|
15
|
+
h6.card-title
|
16
|
+
| Title 1
|
17
|
+
.card-delete
|
18
|
+
= link_to_remove_association "", f, class: 'fa-regular fa-trash-can btn-ghost'
|
17
19
|
div
|
18
20
|
- nested_table_field.fields.each do |field|
|
19
21
|
.form-field
|
@@ -17,7 +17,7 @@
|
|
17
17
|
= f.fields_for table_name do |record|
|
18
18
|
- if record.object.persisted? || @ar_object.errors.present?
|
19
19
|
= render partial: '/cm_admin/main/nested_fields', locals: { f: record, assoc_name: assoc_name, nested_table_field: nested_table_field }
|
20
|
-
- if f.object._reflections[assoc_name.to_s]&.macro == :has_many
|
20
|
+
- if f.object._reflections[assoc_name.to_s]&.macro == :has_many && nested_table_field.is_creatable.call(f.object)
|
21
21
|
.nested-table-footer
|
22
22
|
= link_to_add_association "#{nested_table_field.submit_text}", f, table_name, partial: '/cm_admin/main/nested_fields', render_options: {locals: { assoc_name: assoc_name, nested_table_field: nested_table_field }}, data: { association_insertion_node: ".insert-cocoon-position-#{uniq_no}", association_insertion_method: 'append' }, class: 'btn-primary'
|
23
23
|
- else
|
@@ -4,7 +4,7 @@ module CmAdmin
|
|
4
4
|
|
5
5
|
# NestedField is like a container to hold Field and FormField object
|
6
6
|
|
7
|
-
attr_accessor :field_name, :display_type, :fields, :associated_fields, :parent_field, :header, :label, :submit_text
|
7
|
+
attr_accessor :field_name, :display_type, :fields, :associated_fields, :parent_field, :header, :label, :submit_text, :is_deletable, :is_creatable
|
8
8
|
|
9
9
|
def initialize(field_name, attributes={})
|
10
10
|
@field_name = field_name
|
@@ -19,6 +19,8 @@ module CmAdmin
|
|
19
19
|
self.fields = []
|
20
20
|
self.associated_fields = []
|
21
21
|
self.submit_text = "+ Add #{@field_name.to_s.titleize}"
|
22
|
+
self.is_deletable = lambda { |arg| return true }
|
23
|
+
self.is_creatable = lambda { |arg| return true }
|
22
24
|
end
|
23
25
|
|
24
26
|
end
|
data/lib/cm_admin/version.rb
CHANGED
@@ -198,7 +198,7 @@ module CmAdmin
|
|
198
198
|
else
|
199
199
|
form_obj.check_box cm_field.field_name,
|
200
200
|
{
|
201
|
-
class: "
|
201
|
+
class: "cm-checkbox #{required_class} #{target_action.present? ? 'linked-field-request' : ''}",
|
202
202
|
disabled: cm_field.disabled.call(form_obj.object),
|
203
203
|
data: {
|
204
204
|
field_name: cm_field.field_name,
|
@@ -228,7 +228,7 @@ module CmAdmin
|
|
228
228
|
content_tag :div, class: 'cm-radio-tag' do
|
229
229
|
concat form_obj.check_box cm_field.field_name,
|
230
230
|
{
|
231
|
-
class: "
|
231
|
+
class: "cm-checkbox #{required_class} #{target_action.present? ? 'linked-field-request' : ''}",
|
232
232
|
disabled: cm_field.disabled.call(form_obj.object),
|
233
233
|
name: "#{@model.name.underscore}[#{cm_field.field_name}][]",
|
234
234
|
data: {
|
@@ -135,8 +135,7 @@ module CmAdmin
|
|
135
135
|
end
|
136
136
|
concat split_form_into_section(resource, form_obj, entities)
|
137
137
|
concat tag.br
|
138
|
-
|
139
|
-
concat form_obj.submit 'Save', class: 'btn-cta form_submit', data: {form_class: "cm_#{form_obj.object.class.name.downcase}_form"}
|
138
|
+
concat form_obj.submit 'Save', class: 'btn-cta', data: {behaviour: 'form_submit', form_class: "cm_#{form_obj.object.class.name.downcase}_form"}
|
140
139
|
end
|
141
140
|
end
|
142
141
|
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.2
|
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-
|
13
|
+
date: 2024-05-14 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.2.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
|