cm-admin 1.0.2 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/linters.yml +6 -2
- data/.gitignore +1 -1
- data/.stylelintrc.json +3 -0
- data/Gemfile.lock +19 -18
- data/app/assets/javascripts/cm_admin/application.js +1 -0
- data/app/assets/javascripts/cm_admin/exports.js +1 -1
- data/app/assets/javascripts/cm_admin/scaffolds.js +5 -1
- data/app/assets/javascripts/cm_admin/shared_scaffolds.js +132 -0
- data/app/assets/stylesheets/cm_admin/base/auth.scss +113 -0
- data/app/assets/stylesheets/cm_admin/base/common.scss +2 -2
- data/app/assets/stylesheets/cm_admin/base/form.scss +4 -0
- data/app/assets/stylesheets/cm_admin/base/table.scss +2 -1
- data/app/assets/stylesheets/cm_admin/cm_admin.css.scss +2 -0
- data/app/assets/stylesheets/cm_admin/dependency/flatpickr.min.css +13 -0
- data/app/assets/stylesheets/cm_admin/helpers/_mixins.scss +1 -1
- data/app/assets/stylesheets/cm_admin/pages/history_page.scss +49 -0
- data/app/controllers/cm_admin/resource_controller.rb +31 -7
- data/app/javascript/packs/cm_admin/application.js +1 -0
- data/app/javascript/packs/cm_admin/scaffolds.js +1 -136
- data/app/views/cm_admin/main/_nested_fields.html.slim +1 -1
- data/app/views/cm_admin/main/_nested_table_form.html.slim +2 -2
- data/app/views/cm_admin/main/_tabs.html.slim +5 -1
- data/app/views/cm_admin/main/associated_show.html.slim +1 -1
- data/app/views/cm_admin/main/history.html.slim +17 -0
- data/app/views/cm_admin/main/new.html.slim +2 -5
- data/app/views/cm_admin/main/show.html.slim +1 -1
- data/app/views/layouts/_left_sidebar_nav.html.slim +15 -19
- data/app/views/layouts/cm_admin.html.slim +2 -1
- data/config/routes.rb +9 -1
- data/lib/cm_admin/constants.rb +4 -0
- data/lib/cm_admin/model.rb +2 -2
- data/lib/cm_admin/models/action.rb +2 -1
- data/lib/cm_admin/models/dsl_method.rb +17 -19
- data/lib/cm_admin/models/section.rb +38 -0
- data/lib/cm_admin/version.rb +1 -1
- data/lib/cm_admin/view_helpers/form_helper.rb +55 -30
- data/lib/cm_admin/view_helpers/page_info_helper.rb +8 -0
- data/lib/generators/cm_admin/templates/application_policy.rb +4 -0
- data/package-lock.json +61 -61
- data/package.json +1 -1
- data/yarn.lock +64 -46
- metadata +8 -5
- data/.github/workflows/.stylelintrc.json +0 -3
- data/lib/cm_admin/models/cm_show_section.rb +0 -19
- data/tmp/cache/webpacker/last-compilation-digest-development +0 -1
@@ -9,6 +9,7 @@ require('flatpickr')
|
|
9
9
|
require("jgrowl")
|
10
10
|
require("trix")
|
11
11
|
require('./scaffolds.js')
|
12
|
+
require('/app/assets/javascripts/cm_admin/shared_scaffolds.js')
|
12
13
|
require('/app/assets/javascripts/cm_admin/form_validation.js')
|
13
14
|
require('/app/assets/javascripts/cm_admin/quick_search.js')
|
14
15
|
require('/app/assets/javascripts/cm_admin/filters.js')
|
@@ -19,139 +19,4 @@ $(document).on('turbolinks:load', function () {
|
|
19
19
|
var headerElemHeight = $('.page-top-bar').height() + 64
|
20
20
|
var calculatedHeight = "calc(100vh - " + headerElemHeight+"px"+")"
|
21
21
|
$('.new-admin-table').css("maxHeight", calculatedHeight);
|
22
|
-
});
|
23
|
-
|
24
|
-
$(document).on("keypress keyup blur", "[data-behaviour='decimal-only'], [data-behaviour='filter'][data-filter-type='range']", function (e) {
|
25
|
-
var charCode = (e.which) ? e.which : e.keyCode
|
26
|
-
if (charCode > 31 && (charCode != 46 &&(charCode < 48 || charCode > 57)))
|
27
|
-
return false;
|
28
|
-
return true;
|
29
|
-
});
|
30
|
-
|
31
|
-
$(document).on("keypress keyup blur", "[data-behaviour='integer-only']", function (event) {
|
32
|
-
$(this).val($(this).val().replace(/[^\d].+/, ""));
|
33
|
-
if ((event.which < 48 || event.which > 57)) {
|
34
|
-
event.preventDefault();
|
35
|
-
}
|
36
|
-
});
|
37
|
-
|
38
|
-
$(document).on('click', '.row-action-cell', function(e) {
|
39
|
-
e.stopPropagation();
|
40
|
-
if ($(this).hasClass('opacity-1')) {
|
41
|
-
$('.row-action-cell').removeClass('opacity-1')
|
42
|
-
} else {
|
43
|
-
$('.row-action-cell').removeClass('opacity-1')
|
44
|
-
$(this).addClass('opacity-1');
|
45
|
-
}
|
46
|
-
if ($(this).find('.table-export-popup').hasClass('hidden')) {
|
47
|
-
return $(this).find('.table-export-popup').removeClass('hidden');
|
48
|
-
} else {
|
49
|
-
return $(this).find('.table-export-popup').addClass('hidden');
|
50
|
-
}
|
51
|
-
});
|
52
|
-
|
53
|
-
|
54
|
-
$(document).on('click', '.drawer-btn', function(e) {
|
55
|
-
e.stopPropagation();
|
56
|
-
drawer_el = $(this).parent().closest('.drawer').find('.cm-drawer')
|
57
|
-
if (drawer_el.hasClass('hidden')) {
|
58
|
-
drawer_el.removeClass('hidden');
|
59
|
-
drawer_container = drawer_el.find('.drawer-container')
|
60
|
-
if (drawer_container.hasClass('drawer-slide-out')) {
|
61
|
-
drawer_container.removeClass('drawer-slide-out');
|
62
|
-
}
|
63
|
-
drawer_container.addClass('drawer-slide-in');
|
64
|
-
} else {
|
65
|
-
return drawer_el.addClass('hidden');
|
66
|
-
}
|
67
|
-
});
|
68
|
-
|
69
|
-
$(document).on('click', '.drawer-close', function(e) {
|
70
|
-
e.stopPropagation();
|
71
|
-
$('.drawer-container').removeClass('drawer-slide-in');
|
72
|
-
$('.drawer-container').addClass('drawer-slide-out');
|
73
|
-
setTimeout(() => {
|
74
|
-
$('.cm-drawer').addClass('hidden');
|
75
|
-
}, 300);
|
76
|
-
});
|
77
|
-
|
78
|
-
$(document).on('change', '[data-field-type="linked-field"]', function(e) {
|
79
|
-
e.stopPropagation();
|
80
|
-
params = {}
|
81
|
-
params[$(this).data('field-name')] = $(this).val()
|
82
|
-
request_url = $(this).data('target-url') + '?' + $.param(params);
|
83
|
-
console.log(request_url)
|
84
|
-
$.ajax(request_url, {
|
85
|
-
type: 'GET',
|
86
|
-
success: function(data) {
|
87
|
-
apply_response_to_field(data)
|
88
|
-
},
|
89
|
-
error: function(jqxhr, textStatus, errorThrown) {
|
90
|
-
alert('Something went wrong. Please try again later.\n' + errorThrown);
|
91
|
-
}
|
92
|
-
});
|
93
|
-
});
|
94
|
-
|
95
|
-
function apply_response_to_field(response) {
|
96
|
-
$.each(response['fields'], function(key, value) {
|
97
|
-
switch(value['target_type']) {
|
98
|
-
case 'select':
|
99
|
-
update_options_in_select(value['target_value'])
|
100
|
-
break;
|
101
|
-
case 'input':
|
102
|
-
update_options_input_value(value['target_value'])
|
103
|
-
break;
|
104
|
-
case 'toggle_visibility':
|
105
|
-
toggle_field_visibility(value['target_value'])
|
106
|
-
}
|
107
|
-
})
|
108
|
-
}
|
109
|
-
|
110
|
-
function update_options_input_value(field_obj) {
|
111
|
-
input_tag = $('#' + field_obj['table'] + '_' + field_obj['field_name'])
|
112
|
-
input_tag.val(field_obj['field_value'])
|
113
|
-
}
|
114
|
-
|
115
|
-
function update_options_in_select(field_obj) {
|
116
|
-
select_tag = $('#' + field_obj['table'] + '_' + field_obj['field_name'])
|
117
|
-
select_tag.empty();
|
118
|
-
$.each(field_obj['field_value'], function(key, value) {
|
119
|
-
select_tag.append($("<option></option>")
|
120
|
-
.attr("value", value[1]).text(value[0]));
|
121
|
-
});
|
122
|
-
}
|
123
|
-
|
124
|
-
function toggle_field_visibility(field_obj) {
|
125
|
-
element = $('#' + field_obj['table'] + '_' + field_obj['field_name'])
|
126
|
-
element.closest('.input-wrapper').toggleClass('hidden')
|
127
|
-
}
|
128
|
-
|
129
|
-
$(document).on('cocoon:after-insert', '.nested-field-wrapper', function(e) {
|
130
|
-
e.stopPropagation();
|
131
|
-
replaceAccordionTitle($(this))
|
132
|
-
});
|
133
|
-
|
134
|
-
$(document).on('cocoon:after-remove', '.nested-field-wrapper', function(e) {
|
135
|
-
e.stopPropagation();
|
136
|
-
replaceAccordionTitle($(this))
|
137
|
-
});
|
138
|
-
|
139
|
-
$(document).ready( function () {
|
140
|
-
$('.nested-field-wrapper').each(function() {
|
141
|
-
replaceAccordionTitle($(this))
|
142
|
-
})
|
143
|
-
});
|
144
|
-
|
145
|
-
var replaceAccordionTitle = function(element) {
|
146
|
-
var i = 0;
|
147
|
-
var table_name = $(element).data('table-name')
|
148
|
-
var model_name = $(element).data('model-name')
|
149
|
-
$(element).find('.accordion-item:visible').each(function() {
|
150
|
-
i++;
|
151
|
-
var accordion_title = model_name + ' ' + i
|
152
|
-
var accordion_id = table_name + '-' + i
|
153
|
-
$(this).find('.accordion-button').text(accordion_title);
|
154
|
-
$(this).find('.accordion-button').attr('data-bs-target', '#' + accordion_id);
|
155
|
-
$(this).find('.accordion-collapse').attr('id', accordion_id);
|
156
|
-
});
|
157
|
-
}
|
22
|
+
});
|
@@ -3,7 +3,7 @@
|
|
3
3
|
.accordion.nested-form-accordion
|
4
4
|
= f.fields_for table_name do |record|
|
5
5
|
- if record.object.persisted?
|
6
|
-
= render partial: '/cm_admin/main/nested_fields', locals: { f: record, assoc_name: table_name }
|
6
|
+
= render partial: '/cm_admin/main/nested_fields', locals: { f: record, assoc_name: table_name, section: section }
|
7
7
|
- if @reflections.select {|x| x if x.name == table_name}.first.macro == :has_many
|
8
8
|
.links
|
9
|
-
= link_to_add_association "+ Add #{table_name.to_s.titleize}", f, table_name, partial: '/cm_admin/main/nested_fields', render_options: {locals: { assoc_name: table_name }}, class: 'd-inline-block secondary-btn mt-2'
|
9
|
+
= link_to_add_association "+ Add #{table_name.to_s.titleize}", f, table_name, partial: '/cm_admin/main/nested_fields', render_options: {locals: { assoc_name: table_name, section: section }}, class: 'd-inline-block secondary-btn mt-2'
|
@@ -4,4 +4,8 @@ ul.nav.nav-pills
|
|
4
4
|
- if nav_item.custom_action.empty? || (nav_item.custom_action.present? && policy([:cm_admin, @model.name.classify.constantize]).send(:"#{nav_item.custom_action}?"))
|
5
5
|
li.nav-item
|
6
6
|
- nav_item_action_name = nav_item.custom_action.present? ? nav_item.custom_action : 'show'
|
7
|
-
= link_to tab_display_name(nav_item.nav_item_name), cm_admin.send("#{@ar_object.model_name.singular}_#{nav_item_action_name}_path", @ar_object.id), class: "nav-link #{ nav_item_action_name == action_name ? 'active' : ''}"
|
7
|
+
= link_to tab_display_name(nav_item.nav_item_name), cm_admin.send("#{@ar_object.model_name.singular}_#{nav_item_action_name}_path", @ar_object.id), class: "nav-link #{ nav_item_action_name == action_name ? 'active' : ''}"
|
8
|
+
// current_action_name is defined when action trail is added to that model
|
9
|
+
- if defined?(@ar_object.current_action_name)
|
10
|
+
li.nav-item
|
11
|
+
= link_to 'History', cm_admin.send("#{@ar_object.model_name.singular}_history_path", @ar_object.id), class: "nav-link #{ action_name == 'history' ? 'active' : ''}"
|
@@ -0,0 +1,17 @@
|
|
1
|
+
.show-page.cm-page-container
|
2
|
+
.show-page__tabs.sticky-container.page-top-bar
|
3
|
+
.cm-tabs-bar
|
4
|
+
== render 'cm_admin/main/top_navbar'
|
5
|
+
== render 'cm_admin/main/tabs'
|
6
|
+
.show-page__inner.scrollable
|
7
|
+
.history-box
|
8
|
+
- @ar_object.action_trails.each do |at|
|
9
|
+
.history-item
|
10
|
+
.profile-pic
|
11
|
+
img alt=("profile") src="https://www.pngitem.com/pimgs/m/264-2647677_avatar-icon-human-user-avatar-svg-hd-png.png"
|
12
|
+
.history-info
|
13
|
+
span.bold-text = at.actor.first_name
|
14
|
+
span.normal-text = at.trail_type.titleize
|
15
|
+
span.normal-text the
|
16
|
+
span.bold-text = at.entity_type
|
17
|
+
span.light-text = at.created_at.strftime("%B")
|
@@ -15,8 +15,5 @@
|
|
15
15
|
ul
|
16
16
|
- @ar_object.errors.full_messages.each do |error_message|
|
17
17
|
li = error_message
|
18
|
-
|
19
|
-
|
20
|
-
| Section heading
|
21
|
-
.form-container__inner
|
22
|
-
= generate_form(@ar_object.class.name.constantize.new, @model)
|
18
|
+
|
19
|
+
= generate_form(@ar_object.class.name.constantize.new, @model)
|
@@ -12,23 +12,19 @@
|
|
12
12
|
|
13
13
|
.sidebar-menu__tabs-wrapper
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
.profile-
|
22
|
-
.profile-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
| Settings
|
31
|
-
.auth-option
|
32
|
-
= link_to '/sign-out', method: :delete, class: 'auth-link'
|
33
|
-
| Logout
|
15
|
+
- if defined?(user_full_name)
|
16
|
+
.sidebar__footer
|
17
|
+
.menu-item
|
18
|
+
.profile-name
|
19
|
+
span.profile-avatar J
|
20
|
+
| #{user_full_name}
|
21
|
+
.profile-popup.hidden
|
22
|
+
.profile-info
|
23
|
+
.profile-info__left
|
24
|
+
p.name-text = user_full_name
|
25
|
+
p.email-text = current_user.email
|
26
|
+
.profile-info__right
|
27
|
+
.auth-option
|
28
|
+
= link_to destroy_user_session_path, method: :delete, class: 'auth-link', data: { turbo_method: :delete }
|
29
|
+
| Logout
|
34
30
|
= render 'layouts/quick_links'
|
@@ -36,7 +36,8 @@ html
|
|
36
36
|
.show-page__tabs.sticky-container.page-top-bar
|
37
37
|
.cm-tabs-bar
|
38
38
|
== render 'cm_admin/main/top_navbar'
|
39
|
-
|
39
|
+
- if @ar_object.model_name
|
40
|
+
== render 'cm_admin/main/tabs'
|
40
41
|
- if @associated_model && @associated_model.filters.present?
|
41
42
|
.filters-bar
|
42
43
|
== render partial: 'cm_admin/main/filters', locals: { filters: @associated_model.filters }
|
data/config/routes.rb
CHANGED
@@ -16,9 +16,17 @@ CmAdmin::Engine.routes.draw do
|
|
16
16
|
send(:post, 'import', to: "#{model.name.underscore}#import", as: "#{model.name.underscore}_import")
|
17
17
|
end
|
18
18
|
end
|
19
|
+
|
19
20
|
model.available_actions.sort_by {|act| act.name}.each do |act|
|
20
21
|
scope model.name.tableize do
|
21
|
-
|
22
|
+
# Define route only when action trail related field is present
|
23
|
+
if act.name == 'history'
|
24
|
+
if defined?(model.ar_model.new.current_action_name)
|
25
|
+
send(:get, ':id/history', to: "#{model.name.underscore}#history", as: "#{model.name.underscore}_history")
|
26
|
+
end
|
27
|
+
else
|
28
|
+
send(act.verb, act.path.present? ? act.path : act.name, to: "#{model.name.underscore}##{act.name}", as: "#{model.name.underscore}_#{act.name}")
|
29
|
+
end
|
22
30
|
end
|
23
31
|
end
|
24
32
|
end
|
data/lib/cm_admin/constants.rb
CHANGED
data/lib/cm_admin/model.rb
CHANGED
@@ -8,7 +8,7 @@ require_relative 'models/blocks'
|
|
8
8
|
require_relative 'models/column'
|
9
9
|
require_relative 'models/filter'
|
10
10
|
require_relative 'models/export'
|
11
|
-
require_relative 'models/
|
11
|
+
require_relative 'models/section'
|
12
12
|
require_relative 'models/tab'
|
13
13
|
require_relative 'models/dsl_method'
|
14
14
|
require 'pagy'
|
@@ -36,7 +36,7 @@ module CmAdmin
|
|
36
36
|
@additional_permitted_fields ||= []
|
37
37
|
@current_action = nil
|
38
38
|
@available_tabs ||= []
|
39
|
-
@available_fields ||= {index: [], show: [], edit:
|
39
|
+
@available_fields ||= {index: [], show: [], edit: [], new: []}
|
40
40
|
@params = nil
|
41
41
|
@filters ||= []
|
42
42
|
instance_eval(&block) if block_given?
|
@@ -6,7 +6,7 @@ module CmAdmin
|
|
6
6
|
include Actions::Blocks
|
7
7
|
attr_accessor :name, :display_name, :verb, :layout_type, :layout, :partial, :path, :page_title, :page_description,
|
8
8
|
:child_records, :is_nested_field, :nested_table_name, :parent, :display_if, :route_type, :code_block,
|
9
|
-
:display_type, :action_type, :redirection_url, :sort_direction, :sort_column, :icon_name
|
9
|
+
:display_type, :action_type, :redirection_url, :sort_direction, :sort_column, :icon_name, :scopes
|
10
10
|
|
11
11
|
VALID_SORT_DIRECTION = Set[:asc, :desc].freeze
|
12
12
|
|
@@ -34,6 +34,7 @@ module CmAdmin
|
|
34
34
|
self.action_type = :default
|
35
35
|
self.sort_column = :created_at
|
36
36
|
self.sort_direction = :desc
|
37
|
+
self.scopes ||= []
|
37
38
|
self.icon_name = 'fa fa-th-large'
|
38
39
|
end
|
39
40
|
|
@@ -39,6 +39,12 @@ module CmAdmin
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
+
def scope_list(scopes=[])
|
43
|
+
return unless @current_action
|
44
|
+
|
45
|
+
@current_action.scopes = scopes
|
46
|
+
end
|
47
|
+
|
42
48
|
def tab(tab_name, custom_action, associated_model: nil, layout_type: nil, layout: nil, partial: nil, display_if: nil, &block)
|
43
49
|
if custom_action.to_s == ''
|
44
50
|
@current_action = CmAdmin::Models::Action.find_by(self, name: 'show')
|
@@ -54,24 +60,14 @@ module CmAdmin
|
|
54
60
|
yield if block
|
55
61
|
end
|
56
62
|
|
57
|
-
def
|
63
|
+
def cm_section(section_name, display_if: nil, &block)
|
58
64
|
@available_fields[@current_action.name.to_sym] ||= []
|
59
|
-
@available_fields[@current_action.name.to_sym] << CmAdmin::Models::
|
60
|
-
end
|
61
|
-
|
62
|
-
def form_field(field_name, options={}, arg=nil)
|
63
|
-
unless @current_action.is_nested_field
|
64
|
-
@available_fields[@current_action.name.to_sym][:fields] << CmAdmin::Models::FormField.new(field_name, options[:input_type], options)
|
65
|
-
else
|
66
|
-
@available_fields[@current_action.name.to_sym][@current_action.nested_table_name] ||= []
|
67
|
-
@available_fields[@current_action.name.to_sym][@current_action.nested_table_name] << CmAdmin::Models::FormField.new(field_name, options[:input_type], options)
|
68
|
-
end
|
65
|
+
@available_fields[@current_action.name.to_sym] << CmAdmin::Models::Section.new(section_name, @current_action, @model, display_if, &block)
|
69
66
|
end
|
70
67
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
yield
|
68
|
+
# This method is deprecated. Use cm_section instead.
|
69
|
+
def cm_show_section(section_name, display_if: nil, &block)
|
70
|
+
cm_section(section_name, display_if: display_if, &block)
|
75
71
|
end
|
76
72
|
|
77
73
|
def column(field_name, options={})
|
@@ -120,11 +116,13 @@ module CmAdmin
|
|
120
116
|
# end
|
121
117
|
# end
|
122
118
|
# end
|
123
|
-
def custom_action(name: nil, display_name: nil, verb: nil, layout: nil, layout_type: nil, partial: nil, path: nil, display_type: nil, display_if: lambda { |arg| return true }, route_type: nil, icon_name: 'fa fa-th-large', &block)
|
119
|
+
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, display_if: lambda { |arg| return true }, route_type: nil, icon_name: 'fa fa-th-large', &block)
|
124
120
|
action = CmAdmin::Models::CustomAction.new(
|
125
|
-
|
126
|
-
|
127
|
-
|
121
|
+
page_title: page_title, page_description: page_description,
|
122
|
+
name: name, display_name: display_name, verb: verb, layout: layout,
|
123
|
+
layout_type: layout_type, partial: partial, path: path,
|
124
|
+
parent: self.current_action.name, display_type: display_type, display_if: display_if,
|
125
|
+
action_type: :custom, route_type: route_type, icon_name: icon_name, &block)
|
128
126
|
@available_actions << action
|
129
127
|
# self.class.class_eval(&block)
|
130
128
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module CmAdmin
|
2
|
+
module Models
|
3
|
+
class Section
|
4
|
+
|
5
|
+
attr_accessor :section_name, :section_fields, :display_if, :current_action, :cm_model, :nested_table_fields
|
6
|
+
|
7
|
+
def initialize(section_name, current_action, cm_model, display_if, &block)
|
8
|
+
@section_fields = []
|
9
|
+
@nested_table_fields = {}
|
10
|
+
@section_name = section_name
|
11
|
+
@current_action = current_action
|
12
|
+
@cm_model = cm_model
|
13
|
+
@display_if = display_if || lambda { |arg| return true }
|
14
|
+
instance_eval(&block)
|
15
|
+
end
|
16
|
+
|
17
|
+
def field(field_name, options={})
|
18
|
+
@section_fields << CmAdmin::Models::Field.new(field_name, options)
|
19
|
+
end
|
20
|
+
|
21
|
+
def form_field(field_name, options={}, arg=nil)
|
22
|
+
if @current_action.is_nested_field
|
23
|
+
@nested_table_fields[@current_action.nested_table_name] ||= []
|
24
|
+
@nested_table_fields[@current_action.nested_table_name] << CmAdmin::Models::FormField.new(field_name, options[:input_type], options)
|
25
|
+
else
|
26
|
+
@section_fields << CmAdmin::Models::FormField.new(field_name, options[:input_type], options)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def nested_form_field(field_name, &block)
|
31
|
+
@current_action.is_nested_field = true
|
32
|
+
@current_action.nested_table_name = field_name
|
33
|
+
yield
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/cm_admin/version.rb
CHANGED
@@ -28,48 +28,73 @@ module CmAdmin
|
|
28
28
|
set_form_for_fields(resource, columns, url, method)
|
29
29
|
end
|
30
30
|
|
31
|
-
def form_with_mentioned_fields(resource,
|
31
|
+
def form_with_mentioned_fields(resource, sections_array, method)
|
32
32
|
# columns = resource.class.columns.select { |i| available_fields.map(&:field_name).include?(i.name.to_sym) }
|
33
33
|
table_name = resource.model_name.collection
|
34
34
|
# columns.reject! { |i| REJECTABLE.include?(i.name) }
|
35
35
|
url = CmAdmin::Engine.mount_path + "/#{table_name}/#{resource.id}"
|
36
|
-
|
36
|
+
set_form_with_sections(resource, sections_array, url, method)
|
37
37
|
end
|
38
38
|
|
39
|
-
def
|
40
|
-
|
39
|
+
def split_form_into_section(resource, form_obj, sections_array)
|
40
|
+
content_tag :div do
|
41
|
+
sections_array.each do |section|
|
42
|
+
concat create_sections(resource, form_obj, section)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def create_sections(resource, form_obj, section)
|
48
|
+
content_tag :div, class: 'form-container' do
|
49
|
+
concat content_tag(:p, section.section_name, class: 'form-title')
|
50
|
+
concat set_form_for_fields(resource, form_obj, section)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def set_form_for_fields(resource, form_obj, section)
|
55
|
+
content_tag(:div, class: 'form-container__inner') do
|
56
|
+
section.section_fields.each do |field|
|
57
|
+
next unless field.display_if.call(form_obj.object)
|
58
|
+
|
59
|
+
if field.input_type.eql?(:hidden)
|
60
|
+
concat input_field_for_column(form_obj, field)
|
61
|
+
else
|
62
|
+
concat(content_tag(:div, class: "input-wrapper #{field.disabled ? 'disabled' : ''}") do
|
63
|
+
concat form_obj.label field.label, field.label, class: 'field-label'
|
64
|
+
concat tag.br
|
65
|
+
concat(content_tag(:div, class: 'datetime-wrapper') do
|
66
|
+
concat input_field_for_column(form_obj, field)
|
67
|
+
end)
|
68
|
+
concat tag.p resource.errors[field.field_name].first if resource.errors[field.field_name].present?
|
69
|
+
end)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
concat set_nested_form_fields(form_obj, section)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def set_nested_form_fields(form_obj, section)
|
77
|
+
content_tag(:div) do
|
78
|
+
section.nested_table_fields.keys.each do |key|
|
79
|
+
concat(render partial: '/cm_admin/main/nested_table_form', locals: {f: form_obj, table_name: key, section: section})
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def set_form_with_sections(resource, sections_array, url, method)
|
85
|
+
form_for(resource, url: url, method: method, html: { class: "cm_#{resource.class.name.downcase}_form" } ) do |form_obj|
|
41
86
|
if params[:referrer]
|
42
|
-
concat
|
87
|
+
concat form_obj.text_field "referrer", class: "normal-input", hidden: true, value: params[:referrer], name: 'referrer'
|
43
88
|
end
|
44
89
|
if params[:polymorphic_name].present?
|
45
|
-
concat
|
46
|
-
concat
|
90
|
+
concat form_obj.text_field params[:polymorphic_name] + '_type', class: "normal-input", hidden: true, value: params[:associated_class].classify
|
91
|
+
concat form_obj.text_field params[:polymorphic_name] + '_id', class: "normal-input", hidden: true, value: params[:associated_id]
|
47
92
|
elsif params[:associated_class] && params[:associated_id]
|
48
|
-
concat
|
49
|
-
end
|
50
|
-
available_fields_hash.each do |key, fields_array|
|
51
|
-
if key == :fields
|
52
|
-
fields_array.each do |field|
|
53
|
-
next unless field.display_if.call(f.object)
|
54
|
-
if field.input_type.eql?(:hidden)
|
55
|
-
concat input_field_for_column(f, field)
|
56
|
-
else
|
57
|
-
concat(content_tag(:div, class: "input-wrapper #{field.disabled ? 'disabled' : ''}") do
|
58
|
-
concat f.label field.label, field.label, class: "field-label"
|
59
|
-
concat tag.br
|
60
|
-
concat(content_tag(:div, class: "datetime-wrapper") do
|
61
|
-
concat input_field_for_column(f, field)
|
62
|
-
end)
|
63
|
-
concat tag.p resource.errors[field.field_name].first if resource.errors[field.field_name].present?
|
64
|
-
end)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
else
|
68
|
-
concat(render partial: '/cm_admin/main/nested_table_form', locals: {f: f, table_name: key})
|
69
|
-
end
|
93
|
+
concat form_obj.text_field params[:associated_class] + '_id', class: "normal-input", hidden: true, value: params[:associated_id]
|
70
94
|
end
|
95
|
+
concat split_form_into_section(resource, form_obj, sections_array)
|
71
96
|
concat tag.br
|
72
|
-
concat
|
97
|
+
concat form_obj.submit 'Save', class: 'cta-btn mt-3 form_submit', data: {form_class: "cm_#{form_obj.object.class.name.downcase}_form"}
|
73
98
|
end
|
74
99
|
end
|
75
100
|
end
|
@@ -64,6 +64,8 @@ module CmAdmin
|
|
64
64
|
custom_action_button(custom_action, current_action_name)
|
65
65
|
when :modal
|
66
66
|
custom_modal_button(custom_action)
|
67
|
+
when :page
|
68
|
+
link_to custom_action_title(custom_action), "#{@model.ar_model.table_name}/#{custom_action.path}", class: 'secondary-btn ml-2', method: custom_action.verb
|
67
69
|
end
|
68
70
|
end
|
69
71
|
end
|
@@ -88,6 +90,12 @@ module CmAdmin
|
|
88
90
|
def tab_display_name(nav_item_name)
|
89
91
|
nav_item_name.instance_of?(Symbol) ? nav_item_name.to_s.titleize : nav_item_name.to_s
|
90
92
|
end
|
93
|
+
|
94
|
+
def user_full_name
|
95
|
+
return false unless current_user
|
96
|
+
return current_user.full_name if defined?(current_user.full_name)
|
97
|
+
current_user.email.split('@').first
|
98
|
+
end
|
91
99
|
end
|
92
100
|
end
|
93
101
|
end
|