cm-admin 1.2.7 → 1.2.9
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 +36 -16
- data/app/javascript/packs/cm_admin/scaffolds.js +3 -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/custom_action.rb +1 -1
- data/lib/cm_admin/models/dsl_method.rb +3 -2
- data/lib/cm_admin/models/nested_field.rb +26 -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: 0ea404058404f7948f1494c54f7a44f902be4ad7ed6ee3d9d16821202aee5c0e
|
4
|
+
data.tar.gz: a586637429a44643c18b88113254ae24127aa2b80383a93030e9d4a23b1c2958
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21327b7346f99b2fc2c2e7e9d4c6a30c0985670378aa08a435b8ffdafc5fc6d6bf4b0f54a9cbb4f2b22c5cf4b975dfeee1622da6bb182d93923686169f8d936d
|
7
|
+
data.tar.gz: 834908bf51760be3905ada3947d349d091a72b282af270f870aaedee1e702365b17c8810467f4ea60f3174ce92e8e62cec7fcfacefa1c42c4caa91d28610be52
|
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
|
}
|
@@ -135,7 +135,9 @@ module CmAdmin
|
|
135
135
|
end
|
136
136
|
elsif @action.display_type == :page
|
137
137
|
data = @action.parent == "index" ? @ar_object.data : @ar_object
|
138
|
-
|
138
|
+
# TODO: To set a default value for @action.layout, Since it is used in render above,
|
139
|
+
# Need to check and fix it.
|
140
|
+
format.html { render @action.partial, layout: @action.layout || 'cm_admin' }
|
139
141
|
else
|
140
142
|
begin
|
141
143
|
response_object = @action.code_block.call(@response_object)
|
@@ -160,9 +162,9 @@ module CmAdmin
|
|
160
162
|
nested_table_fields = []
|
161
163
|
fields.each do |field|
|
162
164
|
if field.class == CmAdmin::Models::Row
|
163
|
-
nested_table_fields += field.sections.map(&:nested_table_fields).
|
165
|
+
nested_table_fields += field.sections.map(&:nested_table_fields).flatten
|
164
166
|
elsif field.class == CmAdmin::Models::Section
|
165
|
-
nested_table_fields += field.nested_table_fields.
|
167
|
+
nested_table_fields += field.nested_table_fields.flatten
|
166
168
|
end
|
167
169
|
end
|
168
170
|
nested_table_fields.flatten
|
@@ -173,10 +175,11 @@ module CmAdmin
|
|
173
175
|
authorize controller_name.classify.constantize, policy_class: "CmAdmin::#{controller_name.classify}Policy".constantize if defined? "CmAdmin::#{controller_name.classify}Policy".constantize
|
174
176
|
aar_model = request.url.split('/')[-2].classify.constantize if params[:aar_id]
|
175
177
|
@associated_ar_object = aar_model.find(params[:aar_id]) if params[:aar_id]
|
176
|
-
|
177
|
-
|
178
|
+
nested_fields = get_nested_table_fields(@model.available_fields[:new])
|
179
|
+
nested_fields += get_nested_table_fields(@model.available_fields[:edit])
|
178
180
|
@reflections = @model.ar_model.reflect_on_all_associations
|
179
|
-
|
181
|
+
nested_fields.each do |nested_field|
|
182
|
+
table_name = nested_field.field_name
|
180
183
|
reflection = @reflections.select {|x| x if x.name == table_name}.first
|
181
184
|
if reflection.macro == :has_many
|
182
185
|
@ar_object.send(table_name).build if action_name == "new" || action_name == "edit"
|
@@ -255,6 +258,27 @@ module CmAdmin
|
|
255
258
|
return filtered_result
|
256
259
|
end
|
257
260
|
|
261
|
+
def generate_nested_params(nested_table_field)
|
262
|
+
if nested_table_field.parent_field
|
263
|
+
ar_model = nested_table_field.parent_field.to_s.classify.constantize
|
264
|
+
table_name = ar_model.reflections[nested_table_field.field_name.to_s].klass.table_name
|
265
|
+
else
|
266
|
+
table_name = @model.ar_model.reflections[nested_table_field.field_name.to_s].klass.table_name
|
267
|
+
end
|
268
|
+
column_names = table_name.to_s.classify.constantize.column_names
|
269
|
+
column_names = column_names.map {|column_name| column_name.gsub('_cents', '') }
|
270
|
+
column_names = column_names.reject { |column_name| CmAdmin::REJECTABLE_FIELDS.include?(column_name) }.map(&:to_sym) + [:id, :_destroy]
|
271
|
+
if nested_table_field.associated_fields
|
272
|
+
nested_table_field.associated_fields.each do |associated_field|
|
273
|
+
column_names << generate_nested_params(associated_field)
|
274
|
+
end
|
275
|
+
end
|
276
|
+
Hash[
|
277
|
+
"#{table_name}_attributes",
|
278
|
+
column_names
|
279
|
+
]
|
280
|
+
end
|
281
|
+
|
258
282
|
def resource_params(params)
|
259
283
|
columns = @model.ar_model.columns_hash.map {|key, ar_adapter|
|
260
284
|
ar_adapter.sql_type_metadata.sql_type.ends_with?('[]') ? Hash[ar_adapter.name, []] : ar_adapter.name.to_sym
|
@@ -269,21 +293,17 @@ module CmAdmin
|
|
269
293
|
Hash[x.name.to_s.gsub('_attachments', ''), []]
|
270
294
|
end
|
271
295
|
}.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
|
-
]
|
296
|
+
nested_table_fields = get_nested_table_fields(@model.available_fields[:new])
|
297
|
+
nested_table_fields += get_nested_table_fields(@model.available_fields[:edit])
|
298
|
+
nested_fields = nested_table_fields.uniq.map {|nested_table_field|
|
299
|
+
generate_nested_params(nested_table_field)
|
282
300
|
}
|
283
301
|
permittable_fields += nested_fields
|
284
302
|
@model.ar_model.columns.map { |col| permittable_fields << col.name.split('_cents') if col.name.include?('_cents') }
|
285
303
|
params.require(@model.name.underscore.to_sym).permit(*permittable_fields)
|
286
304
|
end
|
287
305
|
|
306
|
+
|
307
|
+
|
288
308
|
end
|
289
309
|
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 "#{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
|
+
- 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 "#{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 }}, 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'
|
@@ -121,13 +121,14 @@ module CmAdmin
|
|
121
121
|
# end
|
122
122
|
# end
|
123
123
|
# end
|
124
|
-
def custom_action(name: nil, page_title: nil, page_description: nil, display_name: nil, verb: nil, layout: nil, layout_type: nil, partial: nil, path: nil, display_type: nil, modal_configuration: {}, display_if: lambda { |arg| return true }, route_type: nil, icon_name: 'fa fa-th-large', &block)
|
124
|
+
def custom_action(name: nil, page_title: nil, page_description: nil, display_name: nil, verb: nil, layout: nil, layout_type: nil, partial: nil, path: nil, display_type: nil, modal_configuration: {}, url_params: {}, display_if: lambda { |arg| return true }, route_type: nil, icon_name: 'fa fa-th-large', &block)
|
125
125
|
action = CmAdmin::Models::CustomAction.new(
|
126
126
|
page_title: page_title, page_description: page_description,
|
127
127
|
name: name, display_name: display_name, verb: verb, layout: layout,
|
128
128
|
layout_type: layout_type, partial: partial, path: path,
|
129
129
|
parent: self.current_action.name, display_type: display_type, display_if: display_if,
|
130
|
-
action_type: :custom, route_type: route_type, icon_name: icon_name, modal_configuration: modal_configuration,
|
130
|
+
action_type: :custom, route_type: route_type, icon_name: icon_name, modal_configuration: modal_configuration,
|
131
|
+
url_params: url_params, &block)
|
131
132
|
@available_actions << action
|
132
133
|
# self.class.class_eval(&block)
|
133
134
|
end
|
@@ -0,0 +1,26 @@
|
|
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, :submit_text
|
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
|
+
self.submit_text = "+ Add #{@field_name.to_s.titleize}"
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
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, custom_action.url_params)
|
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.9
|
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-19 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
|