cm-admin 1.2.6 → 1.2.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/app/assets/javascripts/cm_admin/scaffolds.js +3 -1
- data/app/assets/javascripts/cm_admin/shared_scaffolds.js +3 -3
- data/app/assets/stylesheets/cm_admin/base/form.scss +34 -21
- data/app/assets/stylesheets/cm_admin/base/scaffold.scss +3 -40
- data/app/assets/stylesheets/cm_admin/base/show.scss +3 -0
- data/app/assets/stylesheets/cm_admin/base/table.scss +6 -2
- data/app/controllers/cm_admin/resource_controller.rb +33 -15
- data/app/javascript/packs/cm_admin/scaffolds.js +3 -1
- data/app/models/concerns/cm_admin/bulk_action_processor.rb +2 -1
- data/app/views/cm_admin/main/_nested_fields.html.slim +25 -6
- data/app/views/cm_admin/main/_nested_table_form.html.slim +31 -18
- data/app/views/cm_admin/main/_nested_table_section.html.slim +29 -16
- data/app/views/cm_admin/main/_show_section.html.slim +2 -2
- data/app/views/layouts/cm_admin.html.slim +4 -0
- data/lib/cm_admin/model.rb +1 -0
- data/lib/cm_admin/models/nested_field.rb +25 -0
- data/lib/cm_admin/models/section.rb +17 -11
- data/lib/cm_admin/version.rb +1 -1
- data/lib/cm_admin/view_helpers/form_helper.rb +2 -2
- data/lib/cm_admin/view_helpers/page_info_helper.rb +10 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae65becafa199e298f7a291d69efcfb82bfd21ea14727d091bf0a6ec5040d642
|
4
|
+
data.tar.gz: 3b91abd5664970b2fcb6a4bcec060cd97d0461f62718a502fe0e78a5fe80762b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60dbdf4ad38f21fc435d3eda1bf0dbff8498fee67fd43622f8853a29954cb6b31de0dcf4f58057fa02e9a7e87eb83f360617940d303fb23d7ca5e9e930891595
|
7
|
+
data.tar.gz: d251828725a456d7acc754a7006ab5c995f2bf8188b8f88e8559e9cd0620c603df64f74fa47b6435d2b717a67ba832c26e06a0354e54af0d3460b182568fd994
|
data/Gemfile.lock
CHANGED
@@ -35,7 +35,9 @@ document.addEventListener("turbo:load", function () {
|
|
35
35
|
flatpickr("[data-behaviour='filter'][data-filter-type='date']", {
|
36
36
|
mode: 'range'
|
37
37
|
})
|
38
|
-
$('.select-2').select2(
|
38
|
+
$('.select-2').select2({
|
39
|
+
theme: "bootstrap-5",
|
40
|
+
});
|
39
41
|
jqueryJgrowl()
|
40
42
|
});
|
41
43
|
|
@@ -138,14 +138,14 @@ var replaceAccordionTitle = function (element) {
|
|
138
138
|
var table_name = $(element).data("table-name");
|
139
139
|
var model_name = $(element).data("model-name");
|
140
140
|
$(element)
|
141
|
-
.find("
|
141
|
+
.find("[data-card-name='" + table_name + "']")
|
142
142
|
.each(function () {
|
143
143
|
i++;
|
144
144
|
var accordion_title = model_name + " " + i;
|
145
145
|
var accordion_id = table_name + "-" + i;
|
146
|
-
$(this).find(".
|
146
|
+
$(this).find(".card-title").text(accordion_title);
|
147
147
|
$(this)
|
148
|
-
.find(".
|
148
|
+
.find(".card-title")
|
149
149
|
.attr("data-bs-target", "#" + accordion_id);
|
150
150
|
$(this).find(".accordion-collapse").attr("id", accordion_id);
|
151
151
|
});
|
@@ -49,32 +49,45 @@
|
|
49
49
|
margin-top: 4px;
|
50
50
|
}
|
51
51
|
|
52
|
-
//
|
53
|
-
.
|
54
|
-
.
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
a {
|
64
|
-
color: $primary-text-clr;
|
65
|
-
&:hover {
|
66
|
-
color: $primary-text-clr;
|
67
|
-
}
|
52
|
+
//Form card UI
|
53
|
+
.form-card {
|
54
|
+
@extend .card, .mt-3;
|
55
|
+
background-color: var(--bs-gray-100);
|
56
|
+
background-blend-mode: multiply;
|
57
|
+
mix-blend-mode: multiply;
|
58
|
+
.card-title-wrapper {
|
59
|
+
@extend .d-flex, .align-items-center, .mb-3;
|
60
|
+
&:hover {
|
61
|
+
div:last-of-type {
|
62
|
+
visibility: visible;
|
68
63
|
}
|
69
64
|
}
|
70
65
|
}
|
66
|
+
.card-title {
|
67
|
+
font-size: $t4-text;
|
68
|
+
color: var(--bs-tertiary-color);
|
69
|
+
margin: 0;
|
70
|
+
}
|
71
|
+
.card-delete {
|
72
|
+
visibility: hidden;
|
73
|
+
}
|
71
74
|
}
|
72
75
|
|
73
76
|
//Nested form table styles
|
74
|
-
.nested-form-table {
|
75
|
-
|
76
|
-
.
|
77
|
-
|
78
|
-
|
77
|
+
.nested-form-table-wrapper {
|
78
|
+
overflow-y: scroll;
|
79
|
+
.nested-form-table {
|
80
|
+
@extend .table, .table-light, .table-hover, .table-bordered, .m-0;
|
81
|
+
width: max-content;
|
82
|
+
.item-delete-cell {
|
83
|
+
vertical-align: middle;
|
84
|
+
text-align: center;
|
85
|
+
}
|
79
86
|
}
|
80
87
|
}
|
88
|
+
|
89
|
+
.nested-table-footer {
|
90
|
+
padding: 8px;
|
91
|
+
border: 1px solid var(--bs-border-color);
|
92
|
+
border-top: 0;
|
93
|
+
}
|
@@ -124,44 +124,7 @@ a {
|
|
124
124
|
}
|
125
125
|
|
126
126
|
//select 2 styles
|
127
|
-
.select2-container {
|
128
|
-
.
|
129
|
-
|
130
|
-
padding: 8px 16px;
|
131
|
-
background-color: $white;
|
132
|
-
border: 1px solid $grey-light-clr;
|
133
|
-
border-radius: $radius-4;
|
134
|
-
height: 40px;
|
135
|
-
.select2-selection__rendered {
|
136
|
-
padding-left: 0;
|
137
|
-
@include font($size: $t4-text, $color: $primary-text-clr);
|
138
|
-
line-height: 22px;
|
139
|
-
}
|
140
|
-
.select2-selection__arrow {
|
141
|
-
top: 6px;
|
142
|
-
}
|
143
|
-
}
|
144
|
-
}
|
145
|
-
.select2-dropdown {
|
146
|
-
border: 1px solid $grey-lighter-clr;
|
147
|
-
box-shadow: 0px 4px 16px rgba(0, 0, 0, 0.16);
|
148
|
-
border-radius: $radius-4;
|
149
|
-
.select2-results {
|
150
|
-
.select2-results__options {
|
151
|
-
.select2-results__option {
|
152
|
-
padding: 9px 16px;
|
153
|
-
@include font($size: $t4-text, $color: $primary-text-clr);
|
154
|
-
line-height: 22px;
|
155
|
-
}
|
156
|
-
}
|
157
|
-
.select2-results__option--highlighted.select2-results__option--selectable {
|
158
|
-
background: $grey-lighter-clr;
|
159
|
-
color: $primary-text-clr;
|
160
|
-
}
|
161
|
-
.select2-results__option--selected {
|
162
|
-
color: $brand-color !important;
|
163
|
-
background-color: $grey-lighter-clr !important;
|
164
|
-
}
|
165
|
-
}
|
166
|
-
}
|
127
|
+
.select2-container--bootstrap-5 .select2-selection--single {
|
128
|
+
padding: 0.375rem 0.75rem 0.375rem 0.75rem !important;
|
129
|
+
background-position: right 0.75rem center !important;
|
167
130
|
}
|
@@ -282,6 +282,10 @@
|
|
282
282
|
}
|
283
283
|
|
284
284
|
//Nested table styles
|
285
|
-
.nested-table {
|
286
|
-
|
285
|
+
.nested-table-wrapper {
|
286
|
+
overflow-y: scroll;
|
287
|
+
.nested-table {
|
288
|
+
@extend .table, .table-light, .table-hover, .table-bordered;
|
289
|
+
width: max-content;
|
290
|
+
}
|
287
291
|
}
|
@@ -160,9 +160,9 @@ module CmAdmin
|
|
160
160
|
nested_table_fields = []
|
161
161
|
fields.each do |field|
|
162
162
|
if field.class == CmAdmin::Models::Row
|
163
|
-
nested_table_fields += field.sections.map(&:nested_table_fields).
|
163
|
+
nested_table_fields += field.sections.map(&:nested_table_fields).flatten
|
164
164
|
elsif field.class == CmAdmin::Models::Section
|
165
|
-
nested_table_fields += field.nested_table_fields.
|
165
|
+
nested_table_fields += field.nested_table_fields.flatten
|
166
166
|
end
|
167
167
|
end
|
168
168
|
nested_table_fields.flatten
|
@@ -173,10 +173,11 @@ module CmAdmin
|
|
173
173
|
authorize controller_name.classify.constantize, policy_class: "CmAdmin::#{controller_name.classify}Policy".constantize if defined? "CmAdmin::#{controller_name.classify}Policy".constantize
|
174
174
|
aar_model = request.url.split('/')[-2].classify.constantize if params[:aar_id]
|
175
175
|
@associated_ar_object = aar_model.find(params[:aar_id]) if params[:aar_id]
|
176
|
-
|
177
|
-
|
176
|
+
nested_fields = get_nested_table_fields(@model.available_fields[:new])
|
177
|
+
nested_fields += get_nested_table_fields(@model.available_fields[:edit])
|
178
178
|
@reflections = @model.ar_model.reflect_on_all_associations
|
179
|
-
|
179
|
+
nested_fields.each do |nested_field|
|
180
|
+
table_name = nested_field.field_name
|
180
181
|
reflection = @reflections.select {|x| x if x.name == table_name}.first
|
181
182
|
if reflection.macro == :has_many
|
182
183
|
@ar_object.send(table_name).build if action_name == "new" || action_name == "edit"
|
@@ -255,6 +256,27 @@ module CmAdmin
|
|
255
256
|
return filtered_result
|
256
257
|
end
|
257
258
|
|
259
|
+
def generate_nested_params(nested_table_field)
|
260
|
+
if nested_table_field.parent_field
|
261
|
+
ar_model = nested_table_field.parent_field.to_s.classify.constantize
|
262
|
+
table_name = ar_model.reflections[nested_table_field.field_name.to_s].klass.table_name
|
263
|
+
else
|
264
|
+
table_name = @model.ar_model.reflections[nested_table_field.field_name.to_s].klass.table_name
|
265
|
+
end
|
266
|
+
column_names = table_name.to_s.classify.constantize.column_names
|
267
|
+
column_names = column_names.map {|column_name| column_name.gsub('_cents', '') }
|
268
|
+
column_names = column_names.reject { |column_name| CmAdmin::REJECTABLE_FIELDS.include?(column_name) }.map(&:to_sym) + [:id, :_destroy]
|
269
|
+
if nested_table_field.associated_fields
|
270
|
+
nested_table_field.associated_fields.each do |associated_field|
|
271
|
+
column_names << generate_nested_params(associated_field)
|
272
|
+
end
|
273
|
+
end
|
274
|
+
Hash[
|
275
|
+
"#{table_name}_attributes",
|
276
|
+
column_names
|
277
|
+
]
|
278
|
+
end
|
279
|
+
|
258
280
|
def resource_params(params)
|
259
281
|
columns = @model.ar_model.columns_hash.map {|key, ar_adapter|
|
260
282
|
ar_adapter.sql_type_metadata.sql_type.ends_with?('[]') ? Hash[ar_adapter.name, []] : ar_adapter.name.to_sym
|
@@ -269,21 +291,17 @@ module CmAdmin
|
|
269
291
|
Hash[x.name.to_s.gsub('_attachments', ''), []]
|
270
292
|
end
|
271
293
|
}.compact
|
272
|
-
|
273
|
-
|
274
|
-
nested_fields =
|
275
|
-
|
276
|
-
column_names = table_name.to_s.classify.constantize.column_names
|
277
|
-
column_names = column_names.map {|column_name| column_name.gsub('_cents', '') }
|
278
|
-
Hash[
|
279
|
-
"#{table_name}_attributes",
|
280
|
-
column_names.reject { |column_name| CmAdmin::REJECTABLE_FIELDS.include?(column_name) }.map(&:to_sym) + [:id, :_destroy]
|
281
|
-
]
|
294
|
+
nested_table_fields = get_nested_table_fields(@model.available_fields[:new])
|
295
|
+
nested_table_fields += get_nested_table_fields(@model.available_fields[:edit])
|
296
|
+
nested_fields = nested_table_fields.uniq.map {|nested_table_field|
|
297
|
+
generate_nested_params(nested_table_field)
|
282
298
|
}
|
283
299
|
permittable_fields += nested_fields
|
284
300
|
@model.ar_model.columns.map { |col| permittable_fields << col.name.split('_cents') if col.name.include?('_cents') }
|
285
301
|
params.require(@model.name.underscore.to_sym).permit(*permittable_fields)
|
286
302
|
end
|
287
303
|
|
304
|
+
|
305
|
+
|
288
306
|
end
|
289
307
|
end
|
@@ -15,12 +15,13 @@ class CmAdmin::BulkActionProcessor
|
|
15
15
|
column_name = @model.available_fields[:index].first.field_name
|
16
16
|
begin
|
17
17
|
@current_action.code_block.call(id)
|
18
|
+
@error_message = nil
|
18
19
|
rescue NoMethodError, NameError => e
|
19
20
|
@error_message = "#{e.message.slice(0..(e.message.index(' for')))} at #{ar_object.send(column_name)}"
|
20
21
|
rescue ActiveRecord::RecordInvalid => e
|
21
22
|
@error_message = "#{e.message} at #{ar_object.send(column_name)}"
|
22
23
|
rescue StandardError => e
|
23
|
-
@error_message = e.message
|
24
|
+
@error_message = "#{ar_object.send(column_name)} - #{e.message}"
|
24
25
|
end
|
25
26
|
@invalid_records << OpenStruct.new({ row_identifier: ar_object.send(column_name), error_message: @error_message }) if @error_message
|
26
27
|
end
|
@@ -1,7 +1,26 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
-
|
1
|
+
- if nested_table_field.display_type == :table
|
2
|
+
tr.nested-fields
|
3
|
+
td.item-delete-cell
|
4
4
|
= link_to_remove_association "", f, class: 'fa-regular fa-trash-can btn-ghost'
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
- nested_table_field.fields.each do |field|
|
6
|
+
td
|
7
|
+
= input_field_for_column(f, field)
|
8
|
+
- else
|
9
|
+
.form-card.nested-fields
|
10
|
+
.card-body
|
11
|
+
.card-item data-card-name=assoc_name
|
12
|
+
.card-title-wrapper
|
13
|
+
h6.card-title
|
14
|
+
| Title 1
|
15
|
+
.card-delete
|
16
|
+
= link_to_remove_association "", f, class: 'fa-regular fa-trash-can btn-ghost'
|
17
|
+
div
|
18
|
+
- nested_table_field.fields.each do |field|
|
19
|
+
.form-field
|
20
|
+
.field-label-wrapper
|
21
|
+
label.field-label = field.field_name.to_s.titleize
|
22
|
+
.field-input-wrapper
|
23
|
+
= input_field_for_column(f, field)
|
24
|
+
- if nested_table_field.associated_fields.present?
|
25
|
+
- nested_table_field.associated_fields.each do |associated_nested_field|
|
26
|
+
= render partial: '/cm_admin/main/nested_table_form', locals: { f: f, nested_table_field: associated_nested_field }
|
@@ -1,19 +1,32 @@
|
|
1
|
-
-
|
2
|
-
|
3
|
-
|
4
|
-
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
1
|
+
- assoc_name = nested_table_field.field_name
|
2
|
+
- table_name = f.object._reflections[assoc_name.to_s].klass.table_name.to_sym
|
3
|
+
- if nested_table_field.display_type == :table
|
4
|
+
.nested-field-wrapper data-table-name=assoc_name data-model-name=assoc_name.to_s.classify
|
5
|
+
/ label.field-label = nested_table_field.label.to_s.titleize
|
6
|
+
- uniq_no = Random.rand(10000)
|
7
|
+
.nested-form-table-wrapper
|
8
|
+
table.nested-form-table
|
9
|
+
thead
|
10
|
+
tr
|
11
|
+
th
|
12
|
+
|
|
13
|
+
- nested_table_field.fields.each do |field|
|
14
|
+
th
|
15
|
+
= field.field_name.to_s.titleize
|
16
|
+
tbody class="insert-cocoon-position-#{uniq_no}"
|
17
|
+
= f.fields_for table_name do |record|
|
18
|
+
- if record.object.persisted? || @ar_object.errors.present?
|
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
|
21
|
+
.nested-table-footer
|
22
|
+
= link_to_add_association "+ Add #{assoc_name.to_s.titleize}", 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
|
+
- else
|
24
|
+
.nested-field-wrapper data-table-name=assoc_name data-model-name=assoc_name.to_s.classify
|
25
|
+
/ label.nested-field-label = assoc_name.to_s.titleize
|
26
|
+
.nested-form
|
14
27
|
= f.fields_for table_name do |record|
|
15
|
-
- if record.object.persisted?
|
16
|
-
= render partial: '/cm_admin/main/nested_fields', locals: { f: record, assoc_name: assoc_name,
|
17
|
-
|
18
|
-
|
19
|
-
|
28
|
+
- if record.object.persisted?
|
29
|
+
= render partial: '/cm_admin/main/nested_fields', locals: { f: record, assoc_name: assoc_name, nested_table_field: nested_table_field }
|
30
|
+
- if f.object._reflections[assoc_name.to_s]&.macro == :has_many
|
31
|
+
.links.mt-3
|
32
|
+
= link_to_add_association "+ Add #{assoc_name.to_s.titleize}", f, table_name, partial: '/cm_admin/main/nested_fields', render_options: {locals: { assoc_name: assoc_name, nested_table_field: nested_table_field }}, class: 'd-inline-block btn-primary mt-2'
|
@@ -1,17 +1,30 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
.card-
|
4
|
-
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
th scope="col"
|
10
|
-
= field.label
|
11
|
-
tbody
|
12
|
-
- associated_records.each do |record|
|
1
|
+
- associated_records = ar_object.send(nested_field.field_name)
|
2
|
+
- if nested_field.display_type == :table
|
3
|
+
div class="#{nested_field.label ? 'card-info' : ''}"
|
4
|
+
- if nested_field.label
|
5
|
+
p.card-info__label = nested_field.label.to_s.titleize
|
6
|
+
.card-info__description.nested-table-wrapper
|
7
|
+
table.nested-table
|
8
|
+
thead
|
13
9
|
tr
|
14
|
-
-
|
15
|
-
|
16
|
-
=
|
17
|
-
|
10
|
+
- nested_field.fields.each do |field|
|
11
|
+
th scope="col"
|
12
|
+
= field.label || field.field_name.to_s.titleize
|
13
|
+
tbody
|
14
|
+
- associated_records.each do |record|
|
15
|
+
tr
|
16
|
+
- nested_field.fields.each do |field|
|
17
|
+
td
|
18
|
+
= record.send(field.field_name)
|
19
|
+
- else
|
20
|
+
- associated_records.each do |record|
|
21
|
+
.card.mb-3
|
22
|
+
.card-body
|
23
|
+
.card-info
|
24
|
+
.card-info__title = nested_section_title(record, nested_field)
|
25
|
+
- nested_field.fields.each do |field|
|
26
|
+
= show_field(record, field)
|
27
|
+
|
28
|
+
- if nested_field.associated_fields.present?
|
29
|
+
- nested_field.associated_fields.each do |associated_nested_field|
|
30
|
+
= render partial: 'cm_admin/main/nested_table_section', locals: { nested_field: associated_nested_field, ar_object: record }
|
@@ -6,5 +6,5 @@
|
|
6
6
|
.card-body
|
7
7
|
- section.section_fields.each do |field|
|
8
8
|
= show_field(@ar_object, field)
|
9
|
-
- section.nested_table_fields.each do |
|
10
|
-
= render partial: 'cm_admin/main/nested_table_section', locals: {
|
9
|
+
- section.nested_table_fields.each do |nested_field|
|
10
|
+
= render partial: 'cm_admin/main/nested_table_section', locals: { nested_field: nested_field, ar_object: @ar_object }
|
@@ -19,6 +19,10 @@ html
|
|
19
19
|
link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" /
|
20
20
|
|
21
21
|
script src="https://raw.githack.com/SortableJS/Sortable/master/Sortable.js"
|
22
|
+
|
23
|
+
link[rel="stylesheet" href="https://cdn.jsdelivr.net/npm/select2-bootstrap-5-theme@1.3.0/dist/select2-bootstrap-5-theme.min.css"]
|
24
|
+
link[rel="stylesheet" href="https://cdn.jsdelivr.net/npm/select2-bootstrap-5-theme@1.3.0/dist/select2-bootstrap-5-theme.rtl.min.css"]
|
25
|
+
|
22
26
|
body
|
23
27
|
.cm-admin
|
24
28
|
= render 'layouts/left_sidebar_nav'
|
data/lib/cm_admin/model.rb
CHANGED
@@ -3,6 +3,7 @@ require_relative 'models/action'
|
|
3
3
|
require_relative 'models/importer'
|
4
4
|
require_relative 'models/custom_action'
|
5
5
|
require_relative 'models/bulk_action'
|
6
|
+
require_relative 'models/nested_field'
|
6
7
|
require_relative 'models/field'
|
7
8
|
require_relative 'models/form_field'
|
8
9
|
require_relative 'models/blocks'
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module CmAdmin
|
2
|
+
module Models
|
3
|
+
class NestedField
|
4
|
+
|
5
|
+
# NestedField is like a container to hold Field and FormField object
|
6
|
+
|
7
|
+
attr_accessor :field_name, :display_type, :fields, :associated_fields, :parent_field, :header, :label
|
8
|
+
|
9
|
+
def initialize(field_name, attributes={})
|
10
|
+
@field_name = field_name
|
11
|
+
set_default_values
|
12
|
+
attributes.each do |key, value|
|
13
|
+
self.send("#{key.to_s}=", value)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def set_default_values
|
18
|
+
self.display_type = :table
|
19
|
+
self.fields = []
|
20
|
+
self.associated_fields = []
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -7,41 +7,47 @@ module CmAdmin
|
|
7
7
|
# These list of fields are iterated and displayed on show/new/edit page.
|
8
8
|
# It also contains rows, which contains sections and fields.
|
9
9
|
|
10
|
-
attr_accessor :section_name, :section_fields, :display_if, :current_action, :cm_model, :nested_table_fields, :rows, :col_size
|
10
|
+
attr_accessor :section_name, :section_fields, :display_if, :current_action, :cm_model, :nested_table_fields, :rows, :col_size, :current_nested_field
|
11
11
|
|
12
12
|
def initialize(section_name, current_action, cm_model, display_if, col_size, &block)
|
13
13
|
@section_fields = []
|
14
14
|
@rows = []
|
15
|
-
@nested_table_fields =
|
15
|
+
@nested_table_fields = []
|
16
16
|
@col_size = col_size
|
17
17
|
@section_name = section_name
|
18
18
|
@current_action = current_action
|
19
19
|
@cm_model = cm_model
|
20
20
|
@display_if = display_if || lambda { |arg| return true }
|
21
|
+
@current_nested_field = nil
|
21
22
|
instance_eval(&block)
|
22
23
|
end
|
23
24
|
|
24
25
|
def field(field_name, options={})
|
25
|
-
if @
|
26
|
-
@
|
27
|
-
@nested_table_fields[@current_action.nested_table_name] << CmAdmin::Models::Field.new(field_name, options)
|
26
|
+
if @current_nested_field
|
27
|
+
@current_nested_field.fields << CmAdmin::Models::Field.new(field_name, options)
|
28
28
|
else
|
29
29
|
@section_fields << CmAdmin::Models::Field.new(field_name, options)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
33
|
def form_field(field_name, options={}, arg=nil)
|
34
|
-
if @
|
35
|
-
@
|
36
|
-
@nested_table_fields[@current_action.nested_table_name] << CmAdmin::Models::FormField.new(field_name, options[:input_type], options)
|
34
|
+
if @current_nested_field
|
35
|
+
@current_nested_field.fields << CmAdmin::Models::FormField.new(field_name, options[:input_type], options)
|
37
36
|
else
|
38
37
|
@section_fields << CmAdmin::Models::FormField.new(field_name, options[:input_type], options)
|
39
38
|
end
|
40
39
|
end
|
41
40
|
|
42
|
-
def nested_form_field(field_name, &block)
|
43
|
-
@current_action.is_nested_field = true
|
44
|
-
@current_action.nested_table_name = field_name
|
41
|
+
def nested_form_field(field_name, options={}, &block)
|
42
|
+
# @current_action.is_nested_field = true
|
43
|
+
# @current_action.nested_table_name = field_name
|
44
|
+
nested_field = CmAdmin::Models::NestedField.new(field_name, options)
|
45
|
+
if nested_field.parent_field
|
46
|
+
@current_nested_field.associated_fields << nested_field
|
47
|
+
else
|
48
|
+
@nested_table_fields << nested_field
|
49
|
+
end
|
50
|
+
@current_nested_field = nested_field
|
45
51
|
yield
|
46
52
|
end
|
47
53
|
|
data/lib/cm_admin/version.rb
CHANGED
@@ -116,8 +116,8 @@ module CmAdmin
|
|
116
116
|
|
117
117
|
def set_nested_form_fields(form_obj, section)
|
118
118
|
content_tag(:div) do
|
119
|
-
section.nested_table_fields.
|
120
|
-
concat(render partial: '/cm_admin/main/nested_table_form', locals: { f: form_obj,
|
119
|
+
section.nested_table_fields.each do |nested_table_field|
|
120
|
+
concat(render partial: '/cm_admin/main/nested_table_form', locals: { f: form_obj, nested_table_field: nested_table_field })
|
121
121
|
end
|
122
122
|
end
|
123
123
|
end
|
@@ -48,7 +48,8 @@ module CmAdmin
|
|
48
48
|
when :modal
|
49
49
|
custom_modal_button(custom_action)
|
50
50
|
when :page
|
51
|
-
|
51
|
+
path = cm_admin.send("#{@model.name.underscore}_#{custom_action.name}_path", @ar_object.id)
|
52
|
+
link_to custom_action_title(custom_action), path, class: 'btn-secondary ms-2', method: custom_action.verb
|
52
53
|
end
|
53
54
|
end
|
54
55
|
end
|
@@ -92,6 +93,14 @@ module CmAdmin
|
|
92
93
|
return current_user.full_name if defined?(current_user.full_name)
|
93
94
|
current_user.email.split('@').first
|
94
95
|
end
|
96
|
+
|
97
|
+
def nested_section_title(record, nested_form_field)
|
98
|
+
if nested_form_field.header.present?
|
99
|
+
record.send(nested_form_field.header)
|
100
|
+
else
|
101
|
+
nested_form_field.field_name.to_s.titleize
|
102
|
+
end
|
103
|
+
end
|
95
104
|
end
|
96
105
|
end
|
97
106
|
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.2.
|
4
|
+
version: 1.2.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: 2023-10-
|
13
|
+
date: 2023-10-18 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
@@ -414,6 +414,7 @@ files:
|
|
414
414
|
- lib/cm_admin/models/filter.rb
|
415
415
|
- lib/cm_admin/models/form_field.rb
|
416
416
|
- lib/cm_admin/models/importer.rb
|
417
|
+
- lib/cm_admin/models/nested_field.rb
|
417
418
|
- lib/cm_admin/models/row.rb
|
418
419
|
- lib/cm_admin/models/section.rb
|
419
420
|
- lib/cm_admin/models/tab.rb
|