cm-admin 1.1.8 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.vscode/settings.json +3 -0
- data/Gemfile.lock +1 -1
- data/app/assets/javascripts/cm_admin/scaffolds.js +6 -0
- data/app/assets/javascripts/cm_admin/shared_scaffolds.js +97 -81
- data/app/assets/stylesheets/cm_admin/base/form.scss +31 -225
- data/app/assets/stylesheets/cm_admin/base/navbar.scss +11 -38
- data/app/assets/stylesheets/cm_admin/base/quicksearch.scss +3 -4
- data/app/assets/stylesheets/cm_admin/base/scaffold.scss +8 -5
- data/app/assets/stylesheets/cm_admin/base/show.scss +17 -35
- data/app/assets/stylesheets/cm_admin/base/table.scss +8 -14
- data/app/assets/stylesheets/cm_admin/components/_buttons.scss +28 -140
- data/app/assets/stylesheets/cm_admin/components/_modal.scss +7 -30
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/_accordion.scss +158 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/_alert.scss +68 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/_badge.scss +38 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/_breadcrumb.scss +40 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/_button-group.scss +142 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/_buttons.scss +207 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/_card.scss +239 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/_carousel.scss +244 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/_close.scss +63 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/_containers.scss +41 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/_dropdown.scss +250 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/_forms.scss +9 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/_functions.scss +302 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/_grid.scss +39 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/_helpers.scss +12 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/_images.scss +42 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/_list-group.scss +197 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/_maps.scss +174 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/_mixins.scss +42 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/_modal.scss +237 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/_nav.scss +197 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/_navbar.scss +289 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/_offcanvas.scss +146 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/_pagination.scss +109 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/_placeholders.scss +51 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/_popover.scss +196 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/_progress.scss +68 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/_reboot.scss +610 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/_root.scss +184 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/_spinners.scss +85 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/_tables.scss +171 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/_toasts.scss +73 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/_tooltip.scss +119 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/_transitions.scss +27 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/_type.scss +106 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/_utilities.scss +806 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/_variables-dark.scss +85 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/_variables.scss +1745 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/bootstrap-grid.scss +62 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/bootstrap-reboot.scss +10 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/bootstrap-utilities.scss +19 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/bootstrap.scss +52 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/forms/_floating-labels.scss +95 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/forms/_form-check.scss +188 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/forms/_form-control.scss +214 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/forms/_form-range.scss +91 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/forms/_form-select.scss +80 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/forms/_form-text.scss +11 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/forms/_input-group.scss +132 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/forms/_labels.scss +36 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/forms/_validation.scss +12 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/helpers/_clearfix.scss +3 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/helpers/_color-bg.scss +7 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/helpers/_colored-links.scss +30 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/helpers/_focus-ring.scss +5 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/helpers/_icon-link.scss +25 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/helpers/_position.scss +36 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/helpers/_ratio.scss +26 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/helpers/_stacks.scss +15 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/helpers/_stretched-link.scss +15 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/helpers/_text-truncation.scss +7 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/helpers/_visually-hidden.scss +8 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/helpers/_vr.scss +8 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/mixins/_alert.scss +18 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/mixins/_backdrop.scss +14 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/mixins/_banner.scss +7 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/mixins/_border-radius.scss +78 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/mixins/_box-shadow.scss +18 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/mixins/_breakpoints.scss +127 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/mixins/_buttons.scss +70 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/mixins/_caret.scss +69 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/mixins/_clearfix.scss +9 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/mixins/_color-mode.scss +21 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/mixins/_color-scheme.scss +7 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/mixins/_container.scss +11 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/mixins/_deprecate.scss +10 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/mixins/_forms.scss +153 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/mixins/_gradients.scss +47 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/mixins/_grid.scss +151 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/mixins/_image.scss +16 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/mixins/_list-group.scss +26 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/mixins/_lists.scss +7 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/mixins/_pagination.scss +10 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/mixins/_reset-text.scss +17 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/mixins/_resize.scss +6 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/mixins/_table-variants.scss +24 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/mixins/_text-truncate.scss +8 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/mixins/_transition.scss +26 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/mixins/_utilities.scss +97 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/mixins/_visually-hidden.scss +33 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/tests/jasmine.js +16 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/tests/mixins/_color-modes.test.scss +69 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/tests/mixins/_media-query-color-mode-full.test.scss +8 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/tests/mixins/_utilities.test.scss +393 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/tests/sass-true/register.js +14 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/tests/sass-true/runner.js +17 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/tests/utilities/_api.test.scss +75 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/utilities/_api.scss +47 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/vendor/_rfs.scss +348 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap.min.css +4 -5
- data/app/assets/stylesheets/cm_admin/pages/import_page.scss +3 -10
- data/app/controllers/cm_admin/resource_controller.rb +22 -5
- data/app/helpers/cm_admin/application_helper.rb +4 -4
- data/app/views/cm_admin/main/_actions_dropdown.html.slim +3 -5
- data/app/views/cm_admin/main/_associated_table.html.slim +1 -1
- data/app/views/cm_admin/main/_custom_action_modal_form.html.slim +6 -0
- data/app/views/cm_admin/main/_nested_fields.html.slim +36 -16
- data/app/views/cm_admin/main/_nested_table_form.html.slim +17 -8
- data/app/views/cm_admin/main/_nested_table_section.html.slim +17 -0
- data/app/views/cm_admin/main/_show_section.html.slim +10 -0
- data/app/views/cm_admin/main/_tabs.html.slim +2 -2
- data/app/views/cm_admin/main/_top_navbar.html.slim +17 -17
- data/app/views/cm_admin/main/associated_show.html.slim +5 -4
- data/app/views/cm_admin/main/edit.html.slim +18 -18
- data/app/views/cm_admin/main/history.html.slim +5 -6
- data/app/views/cm_admin/main/import_form.html.slim +3 -3
- data/app/views/cm_admin/main/new.html.slim +17 -17
- data/app/views/cm_admin/main/show.html.slim +12 -13
- data/app/views/layouts/_custom_action_modal.html.slim +11 -0
- data/app/views/layouts/_custom_action_modals.html.slim +13 -9
- data/app/views/layouts/_destroy_action_modal.html.slim +16 -0
- data/app/views/layouts/_quick_links.html.slim +2 -2
- data/app/views/layouts/cm_admin.html.slim +13 -15
- data/config/routes.rb +1 -3
- data/lib/cm_admin/model.rb +1 -0
- data/lib/cm_admin/models/custom_action.rb +6 -0
- data/lib/cm_admin/models/dsl_method.rb +9 -4
- data/lib/cm_admin/models/field.rb +2 -1
- data/lib/cm_admin/models/form_field.rb +2 -1
- data/lib/cm_admin/models/row.rb +40 -0
- data/lib/cm_admin/models/section.rb +20 -3
- data/lib/cm_admin/version.rb +1 -1
- data/lib/cm_admin/view_helpers/field_display_helper.rb +3 -3
- data/lib/cm_admin/view_helpers/form_field_helper.rb +40 -14
- data/lib/cm_admin/view_helpers/form_helper.rb +60 -22
- data/lib/cm_admin/view_helpers/manage_column_popup_helper.rb +2 -2
- data/lib/cm_admin/view_helpers/page_info_helper.rb +4 -4
- data/lib/cm_admin/view_helpers.rb +3 -2
- metadata +108 -2
data/lib/cm_admin/model.rb
CHANGED
@@ -10,6 +10,7 @@ require_relative 'models/column'
|
|
10
10
|
require_relative 'models/filter'
|
11
11
|
require_relative 'models/export'
|
12
12
|
require_relative 'models/section'
|
13
|
+
require_relative 'models/row'
|
13
14
|
require_relative 'models/tab'
|
14
15
|
require_relative 'models/dsl_method'
|
15
16
|
require 'pagy'
|
@@ -3,6 +3,12 @@ require_relative 'actions/blocks'
|
|
3
3
|
module CmAdmin
|
4
4
|
module Models
|
5
5
|
class CustomAction < Action
|
6
|
+
attr_accessor :modal_configuration
|
7
|
+
|
8
|
+
def initialize(attributes = {}, &block)
|
9
|
+
super
|
10
|
+
end
|
11
|
+
|
6
12
|
class << self
|
7
13
|
def find_by(model, search_hash)
|
8
14
|
model.available_actions.find { |i| i.name == search_hash[:name] }
|
@@ -60,9 +60,14 @@ module CmAdmin
|
|
60
60
|
yield if block
|
61
61
|
end
|
62
62
|
|
63
|
-
def
|
63
|
+
def row(display_if: nil, &block)
|
64
64
|
@available_fields[@current_action.name.to_sym] ||= []
|
65
|
-
@available_fields[@current_action.name.to_sym] << CmAdmin::Models::
|
65
|
+
@available_fields[@current_action.name.to_sym] << CmAdmin::Models::Row.new(@current_action, @model, display_if, &block)
|
66
|
+
end
|
67
|
+
|
68
|
+
def cm_section(section_name, display_if: nil, col_size: nil, &block)
|
69
|
+
@available_fields[@current_action.name.to_sym] ||= []
|
70
|
+
@available_fields[@current_action.name.to_sym] << CmAdmin::Models::Section.new(section_name, @current_action, @model, display_if, col_size, &block)
|
66
71
|
end
|
67
72
|
|
68
73
|
# This method is deprecated. Use cm_section instead.
|
@@ -116,13 +121,13 @@ module CmAdmin
|
|
116
121
|
# end
|
117
122
|
# end
|
118
123
|
# end
|
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
|
+
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)
|
120
125
|
action = CmAdmin::Models::CustomAction.new(
|
121
126
|
page_title: page_title, page_description: page_description,
|
122
127
|
name: name, display_name: display_name, verb: verb, layout: layout,
|
123
128
|
layout_type: layout_type, partial: partial, path: path,
|
124
129
|
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)
|
130
|
+
action_type: :custom, route_type: route_type, icon_name: icon_name, modal_configuration: modal_configuration, &block)
|
126
131
|
@available_actions << action
|
127
132
|
# self.class.class_eval(&block)
|
128
133
|
end
|
@@ -7,7 +7,7 @@ module CmAdmin
|
|
7
7
|
|
8
8
|
attr_accessor :field_name, :label, :header, :field_type, :format, :precision, :height,
|
9
9
|
:width, :helper_method, :preview, :custom_link, :prefix, :suffix, :tag_class,
|
10
|
-
:display_if, :association_name, :association_type
|
10
|
+
:display_if, :association_name, :association_type, :col_size
|
11
11
|
|
12
12
|
def initialize(field_name, attributes = {})
|
13
13
|
@field_name = field_name
|
@@ -24,6 +24,7 @@ module CmAdmin
|
|
24
24
|
|
25
25
|
def set_default_values
|
26
26
|
self.tag_class = {}
|
27
|
+
self.col_size = nil
|
27
28
|
end
|
28
29
|
end
|
29
30
|
end
|
@@ -6,7 +6,7 @@ module CmAdmin
|
|
6
6
|
include Utils::Helpers
|
7
7
|
|
8
8
|
attr_accessor :field_name, :label, :header, :input_type, :collection, :disabled, :helper_method,
|
9
|
-
:placeholder, :display_if, :html_attr, :target
|
9
|
+
:placeholder, :display_if, :html_attr, :target, :col_size
|
10
10
|
|
11
11
|
VALID_INPUT_TYPES = %i[
|
12
12
|
integer decimal string single_select multi_select date date_time text
|
@@ -30,6 +30,7 @@ module CmAdmin
|
|
30
30
|
self.input_type = :string
|
31
31
|
self.html_attr = {}
|
32
32
|
self.target = {}
|
33
|
+
self.col_size = nil
|
33
34
|
end
|
34
35
|
|
35
36
|
def set_default_placeholder
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module CmAdmin
|
2
|
+
module Models
|
3
|
+
class Row
|
4
|
+
|
5
|
+
# Description
|
6
|
+
# A row is like a container which holds a list of form_field or section.
|
7
|
+
# These list of fields or section are iterated and displayed on new/edit page.
|
8
|
+
# A row is like a wrapper on the HTML, which adds a div element 'row' class from bootstrap.
|
9
|
+
|
10
|
+
attr_accessor :sections, :display_if, :row_fields
|
11
|
+
|
12
|
+
def initialize(current_action, cm_model, display_if, &block)
|
13
|
+
@sections = []
|
14
|
+
@row_fields = []
|
15
|
+
@display_if = display_if || lambda { |arg| return true }
|
16
|
+
@current_action = current_action
|
17
|
+
@cm_model = cm_model
|
18
|
+
instance_eval(&block)
|
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
|
+
@row_fields << CmAdmin::Models::FormField.new(field_name, options[:input_type], options)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def cm_section(section_name, col_size: nil, display_if: nil, &block)
|
31
|
+
@sections << CmAdmin::Models::Section.new(section_name, @current_action, @model, display_if, col_size, &block)
|
32
|
+
end
|
33
|
+
|
34
|
+
# This method is deprecated. Use cm_section instead.
|
35
|
+
def cm_show_section(section_name, col_size: nil, display_if: nil, &block)
|
36
|
+
cm_section(section_name, col_size: col_size, display_if: display_if, &block)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -2,11 +2,18 @@ module CmAdmin
|
|
2
2
|
module Models
|
3
3
|
class Section
|
4
4
|
|
5
|
-
|
5
|
+
# Description
|
6
|
+
# A section is like a container which holds a list of fields or form fields
|
7
|
+
# These list of fields are iterated and displayed on show/new/edit page.
|
8
|
+
# It also contains rows, which contains sections and fields.
|
6
9
|
|
7
|
-
|
10
|
+
attr_accessor :section_name, :section_fields, :display_if, :current_action, :cm_model, :nested_table_fields, :rows, :col_size
|
11
|
+
|
12
|
+
def initialize(section_name, current_action, cm_model, display_if, col_size, &block)
|
8
13
|
@section_fields = []
|
14
|
+
@rows = []
|
9
15
|
@nested_table_fields = {}
|
16
|
+
@col_size = col_size
|
10
17
|
@section_name = section_name
|
11
18
|
@current_action = current_action
|
12
19
|
@cm_model = cm_model
|
@@ -15,7 +22,12 @@ module CmAdmin
|
|
15
22
|
end
|
16
23
|
|
17
24
|
def field(field_name, options={})
|
18
|
-
@
|
25
|
+
if @current_action.is_nested_field
|
26
|
+
@nested_table_fields[@current_action.nested_table_name] ||= []
|
27
|
+
@nested_table_fields[@current_action.nested_table_name] << CmAdmin::Models::Field.new(field_name, options)
|
28
|
+
else
|
29
|
+
@section_fields << CmAdmin::Models::Field.new(field_name, options)
|
30
|
+
end
|
19
31
|
end
|
20
32
|
|
21
33
|
def form_field(field_name, options={}, arg=nil)
|
@@ -33,6 +45,11 @@ module CmAdmin
|
|
33
45
|
yield
|
34
46
|
end
|
35
47
|
|
48
|
+
def row(display_if: nil, &block)
|
49
|
+
@rows ||= []
|
50
|
+
@rows << CmAdmin::Models::Row.new(@current_action, @model, display_if, &block)
|
51
|
+
end
|
52
|
+
|
36
53
|
end
|
37
54
|
end
|
38
55
|
end
|
data/lib/cm_admin/version.rb
CHANGED
@@ -3,14 +3,14 @@ module CmAdmin
|
|
3
3
|
module FieldDisplayHelper
|
4
4
|
def show_field(ar_object, field)
|
5
5
|
return unless field.display_if.call(ar_object)
|
6
|
-
content_tag(:div, class: "info
|
6
|
+
content_tag(:div, class: "card-info") do
|
7
7
|
concat show_field_label(ar_object, field)
|
8
8
|
concat value_with_prefix_and_suffix(ar_object, field)
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
12
|
def show_field_label(ar_object, field)
|
13
|
-
content_tag(:div, class: "
|
13
|
+
content_tag(:div, class: "card-info__label") do
|
14
14
|
field_label = if field.label.present?
|
15
15
|
field.label.to_s
|
16
16
|
elsif field.association_type.to_s == "polymorphic"
|
@@ -24,7 +24,7 @@ module CmAdmin
|
|
24
24
|
|
25
25
|
def value_with_prefix_and_suffix(ar_object, field)
|
26
26
|
value = show_field_value(ar_object, field)
|
27
|
-
content_tag(:div, class: "
|
27
|
+
content_tag(:div, class: "card-info__description") do
|
28
28
|
concat field.prefix
|
29
29
|
concat value
|
30
30
|
concat field.suffix
|
@@ -13,7 +13,7 @@ module CmAdmin
|
|
13
13
|
|
14
14
|
def cm_integer_field(form_obj, cm_field, value, required_class, _target_action)
|
15
15
|
form_obj.text_field cm_field.field_name,
|
16
|
-
class: "
|
16
|
+
class: "field-control #{required_class}",
|
17
17
|
disabled: cm_field.disabled,
|
18
18
|
value: value,
|
19
19
|
placeholder: cm_field.placeholder,
|
@@ -22,7 +22,7 @@ module CmAdmin
|
|
22
22
|
|
23
23
|
def cm_decimal_field(form_obj, cm_field, value, required_class, _target_action)
|
24
24
|
form_obj.number_field cm_field.field_name,
|
25
|
-
class: "
|
25
|
+
class: "field-control #{required_class}",
|
26
26
|
disabled: cm_field.disabled,
|
27
27
|
value: value,
|
28
28
|
placeholder: cm_field.placeholder,
|
@@ -31,7 +31,7 @@ module CmAdmin
|
|
31
31
|
|
32
32
|
def cm_string_field(form_obj, cm_field, value, required_class, _target_action)
|
33
33
|
form_obj.text_field cm_field.field_name,
|
34
|
-
class: "
|
34
|
+
class: "field-control #{required_class}",
|
35
35
|
disabled: cm_field.disabled,
|
36
36
|
value: value,
|
37
37
|
placeholder: cm_field.placeholder
|
@@ -40,7 +40,7 @@ module CmAdmin
|
|
40
40
|
def cm_single_select_field(form_obj, cm_field, value, required_class, target_action)
|
41
41
|
form_obj.select cm_field.field_name, options_for_select(select_collection_value(form_obj.object, cm_field), form_obj.object.send(cm_field.field_name)),
|
42
42
|
{ include_blank: cm_field.placeholder },
|
43
|
-
class: "
|
43
|
+
class: "field-control #{required_class} select-2",
|
44
44
|
disabled: cm_field.disabled,
|
45
45
|
data: {
|
46
46
|
field_name: cm_field.field_name,
|
@@ -54,13 +54,13 @@ module CmAdmin
|
|
54
54
|
form_obj.select cm_field.field_name,
|
55
55
|
options_for_select(select_collection_value(form_obj.object, cm_field), form_obj.object.send(cm_field.field_name)),
|
56
56
|
{ include_blank: cm_field.placeholder },
|
57
|
-
class: "
|
57
|
+
class: "field-control #{required_class} select-2",
|
58
58
|
disabled: cm_field.disabled, multiple: true
|
59
59
|
end
|
60
60
|
|
61
61
|
def cm_date_field(form_obj, cm_field, value, required_class, _target_action)
|
62
62
|
form_obj.text_field cm_field.field_name,
|
63
|
-
class: "
|
63
|
+
class: "field-control #{required_class}",
|
64
64
|
disabled: cm_field.disabled,
|
65
65
|
value: value&.strftime('%d-%m-%Y'),
|
66
66
|
placeholder: cm_field.placeholder,
|
@@ -69,7 +69,7 @@ module CmAdmin
|
|
69
69
|
|
70
70
|
def cm_date_time_field(form_obj, cm_field, value, required_class, _target_action)
|
71
71
|
form_obj.text_field cm_field.field_name,
|
72
|
-
class: "
|
72
|
+
class: "field-control #{required_class}",
|
73
73
|
disabled: cm_field.disabled,
|
74
74
|
value: value,
|
75
75
|
placeholder: cm_field.placeholder,
|
@@ -78,22 +78,48 @@ module CmAdmin
|
|
78
78
|
|
79
79
|
def cm_text_field(form_obj, cm_field, value, required_class, _target_action)
|
80
80
|
form_obj.text_area cm_field.field_name,
|
81
|
-
class: "
|
81
|
+
class: "field-control #{required_class}",
|
82
82
|
placeholder: cm_field.placeholder
|
83
83
|
end
|
84
84
|
|
85
85
|
def cm_rich_text_field(form_obj, cm_field, value, required_class, _target_action)
|
86
86
|
form_obj.rich_text_area cm_field.field_name,
|
87
|
-
class: "
|
87
|
+
class: "field-control #{required_class}",
|
88
88
|
placeholder: cm_field.placeholder
|
89
89
|
end
|
90
90
|
|
91
91
|
def cm_single_file_upload_field(form_obj, cm_field, _value, required_class, _target_action)
|
92
|
-
|
92
|
+
content_tag(:div) do
|
93
|
+
concat form_obj.file_field cm_field.field_name, class: "normal-input #{required_class}"
|
94
|
+
concat attachment_list(form_obj, cm_field, _value, required_class, _target_action)
|
95
|
+
end
|
93
96
|
end
|
94
97
|
|
95
98
|
def cm_multi_file_upload_field(form_obj, cm_field, _value, required_class, _target_action)
|
96
|
-
|
99
|
+
content_tag(:div) do
|
100
|
+
concat form_obj.file_field cm_field.field_name, multiple: true, class: "normal-input #{required_class}"
|
101
|
+
concat attachment_list(form_obj, cm_field, _value, required_class, _target_action)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def attachment_list(form_obj, cm_field, _value, required_class, _target_action)
|
106
|
+
attached = form_obj.object.send(cm_field.field_name)
|
107
|
+
content_tag(:div) do
|
108
|
+
if attached.class == ActiveStorage::Attached::Many
|
109
|
+
attached.each do |attachment|
|
110
|
+
concat attachment_with_icon(attachment)
|
111
|
+
end
|
112
|
+
else
|
113
|
+
concat attachment_with_icon(attached)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def attachment_with_icon(attachment)
|
119
|
+
content_tag(:div, class: 'destroy-attachment', data: { ar_id: attachment.id}) do
|
120
|
+
concat content_tag(:i, '', class: 'fa-solid fa-trash-can')
|
121
|
+
concat content_tag(:span, attachment.filename.to_s)
|
122
|
+
end
|
97
123
|
end
|
98
124
|
|
99
125
|
def cm_check_box_field(form_obj, cm_field, value, required_class, target_action)
|
@@ -128,7 +154,7 @@ module CmAdmin
|
|
128
154
|
else
|
129
155
|
form_obj.check_box cm_field.field_name,
|
130
156
|
{
|
131
|
-
class: "
|
157
|
+
class: "field-control cm-checkbox #{required_class} #{target_action.present? ? 'linked-field-request' : ''}",
|
132
158
|
disabled: cm_field.disabled,
|
133
159
|
data: {
|
134
160
|
field_name: cm_field.field_name,
|
@@ -158,7 +184,7 @@ module CmAdmin
|
|
158
184
|
content_tag :div, class: 'cm-radio-tag' do
|
159
185
|
concat form_obj.check_box cm_field.field_name,
|
160
186
|
{
|
161
|
-
class: "
|
187
|
+
class: "field-control cm-checkbox #{required_class} #{target_action.present? ? 'linked-field-request' : ''}",
|
162
188
|
disabled: cm_field.disabled,
|
163
189
|
name: "#{@model.name.underscore}[#{cm_field.field_name}][]",
|
164
190
|
data: {
|
@@ -186,7 +212,7 @@ module CmAdmin
|
|
186
212
|
|
187
213
|
def format_radio_button(val, form_obj)
|
188
214
|
content_tag :div, class: 'cm-radio-tag' do
|
189
|
-
concat form_obj.radio_button :level, val, class: '
|
215
|
+
concat form_obj.radio_button :level, val, class: 'field-control cm-radio'
|
190
216
|
end
|
191
217
|
end
|
192
218
|
end
|
@@ -28,48 +28,85 @@ 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, entities, 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
|
-
set_form_with_sections(resource,
|
36
|
+
set_form_with_sections(resource, entities, url, method)
|
37
37
|
end
|
38
38
|
|
39
|
-
def split_form_into_section(resource, form_obj,
|
39
|
+
def split_form_into_section(resource, form_obj, entities)
|
40
40
|
content_tag :div do
|
41
|
-
|
41
|
+
entities.each do |entity|
|
42
|
+
if entity.class == CmAdmin::Models::Row
|
43
|
+
concat create_rows(resource, form_obj, entity)
|
44
|
+
elsif entity.class == CmAdmin::Models::Section
|
45
|
+
concat(content_tag(:div, class: 'row') do
|
46
|
+
concat create_sections(resource, form_obj, entity)
|
47
|
+
end)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def create_rows(resource, form_obj, row)
|
54
|
+
content_tag :div, class: 'row' do
|
55
|
+
row.sections.each do |section|
|
42
56
|
concat create_sections(resource, form_obj, section)
|
43
57
|
end
|
44
58
|
end
|
45
59
|
end
|
46
60
|
|
47
61
|
def create_sections(resource, form_obj, section)
|
48
|
-
content_tag :div, class: 'form-container' do
|
62
|
+
content_tag :div, class: 'col form-container' do
|
49
63
|
concat content_tag(:p, section.section_name, class: 'form-title')
|
50
64
|
concat set_form_for_fields(resource, form_obj, section)
|
51
65
|
end
|
52
66
|
end
|
53
67
|
|
68
|
+
def create_row_inside_section(resource, form_obj, rows)
|
69
|
+
rows.each do |row|
|
70
|
+
concat(content_tag(:div, class: 'row') do
|
71
|
+
row.row_fields.each do |field|
|
72
|
+
concat set_form_field(resource, form_obj, field)
|
73
|
+
end
|
74
|
+
end)
|
75
|
+
end
|
76
|
+
return
|
77
|
+
end
|
78
|
+
|
54
79
|
def set_form_for_fields(resource, form_obj, section)
|
55
80
|
content_tag(:div, class: 'form-container__inner') do
|
56
|
-
section.
|
57
|
-
|
81
|
+
concat create_row_inside_section(resource, form_obj, section.rows) if section.rows.present?
|
82
|
+
concat set_form_fields(resource, form_obj, section.section_fields)
|
83
|
+
concat set_nested_form_fields(form_obj, section)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def set_form_fields(resource, form_obj, fields)
|
88
|
+
fields.each do |field|
|
89
|
+
concat(content_tag(:div, class: 'row') do
|
90
|
+
concat set_form_field(resource, form_obj, field)
|
91
|
+
end)
|
92
|
+
end
|
93
|
+
return
|
94
|
+
end
|
95
|
+
|
96
|
+
def set_form_field(resource, form_obj, field)
|
97
|
+
content_tag(:div, class: field.col_size ? "col-#{field.col_size}" : 'col') do
|
98
|
+
next unless field.display_if.call(form_obj.object)
|
58
99
|
|
59
|
-
|
100
|
+
if field.input_type.eql?(:hidden)
|
101
|
+
concat input_field_for_column(form_obj, field)
|
102
|
+
else
|
103
|
+
concat(content_tag(:div, class: "form-field #{field.disabled ? 'disabled' : ''}") do
|
104
|
+
concat form_obj.label field.label, field.label, class: 'field-label'
|
105
|
+
concat tag.br
|
60
106
|
concat input_field_for_column(form_obj, field)
|
61
|
-
|
62
|
-
|
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
|
107
|
+
concat tag.p resource.errors[field.field_name].first if resource.errors[field.field_name].present?
|
108
|
+
end)
|
71
109
|
end
|
72
|
-
concat set_nested_form_fields(form_obj, section)
|
73
110
|
end
|
74
111
|
end
|
75
112
|
|
@@ -81,7 +118,7 @@ module CmAdmin
|
|
81
118
|
end
|
82
119
|
end
|
83
120
|
|
84
|
-
def set_form_with_sections(resource,
|
121
|
+
def set_form_with_sections(resource, entities, url, method)
|
85
122
|
form_for(resource, url: url, method: method, html: { class: "cm_#{resource.class.name.downcase}_form" } ) do |form_obj|
|
86
123
|
if params[:referrer]
|
87
124
|
concat form_obj.text_field "referrer", class: "normal-input", hidden: true, value: params[:referrer], name: 'referrer'
|
@@ -92,9 +129,10 @@ module CmAdmin
|
|
92
129
|
elsif params[:associated_class] && params[:associated_id]
|
93
130
|
concat form_obj.text_field params[:associated_class] + '_id', class: "normal-input", hidden: true, value: params[:associated_id]
|
94
131
|
end
|
95
|
-
concat split_form_into_section(resource, form_obj,
|
132
|
+
concat split_form_into_section(resource, form_obj, entities)
|
96
133
|
concat tag.br
|
97
|
-
|
134
|
+
# TODO: form_submit class is used for JS functionality, Have to remove
|
135
|
+
concat form_obj.submit 'Save', class: 'btn-cta form_submit', data: {form_class: "cm_#{form_obj.object.class.name.downcase}_form"}
|
98
136
|
end
|
99
137
|
end
|
100
138
|
end
|
@@ -65,8 +65,8 @@ module CmAdmin
|
|
65
65
|
|
66
66
|
def manage_column_footer
|
67
67
|
concat(content_tag(:div, class: 'modal-footer') do
|
68
|
-
concat tag.button 'Close', class: '
|
69
|
-
concat tag.button 'Save', class: 'cta
|
68
|
+
concat tag.button 'Close', class: 'btn-secondary', data: {bs_dismiss: 'modal'}
|
69
|
+
concat tag.button 'Save', class: 'btn-cta'
|
70
70
|
end)
|
71
71
|
return
|
72
72
|
end
|
@@ -67,7 +67,7 @@ module CmAdmin
|
|
67
67
|
when :modal
|
68
68
|
custom_modal_button(custom_action)
|
69
69
|
when :page
|
70
|
-
link_to custom_action_title(custom_action), "#{@model.ar_model.table_name}/#{custom_action.path}", class: 'secondary
|
70
|
+
link_to custom_action_title(custom_action), "#{@model.ar_model.table_name}/#{custom_action.path}", class: 'btn-secondary ms-2', method: custom_action.verb
|
71
71
|
end
|
72
72
|
end
|
73
73
|
end
|
@@ -83,14 +83,14 @@ module CmAdmin
|
|
83
83
|
|
84
84
|
def custom_action_button(custom_action, current_action_name)
|
85
85
|
if current_action_name == "index"
|
86
|
-
button_to custom_action_title(custom_action), @model.ar_model.table_name + '/' + custom_action.path, class: 'secondary
|
86
|
+
button_to custom_action_title(custom_action), @model.ar_model.table_name + '/' + custom_action.path, class: 'btn-secondary ms-2', method: custom_action.verb
|
87
87
|
elsif current_action_name == "show"
|
88
|
-
button_to custom_action_title(custom_action), custom_action.path.gsub(':id', params[:id]), class: 'secondary
|
88
|
+
button_to custom_action_title(custom_action), custom_action.path.gsub(':id', params[:id]), class: 'btn-secondary ms-2', method: custom_action.verb
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
92
|
def custom_modal_button(custom_action)
|
93
|
-
link_to custom_action_title(custom_action), '', class: 'secondary
|
93
|
+
link_to custom_action_title(custom_action), '', class: 'btn-secondary ms-2', data: { bs_toggle: "modal", bs_target: "##{custom_action.name.classify}Modal-#{@ar_object.id}" }
|
94
94
|
end
|
95
95
|
|
96
96
|
def custom_action_title(custom_action)
|
@@ -15,7 +15,7 @@ module CmAdmin
|
|
15
15
|
include ActionView::Helpers::TagHelper
|
16
16
|
|
17
17
|
def exportable(_klass, html_class: [])
|
18
|
-
tag.a 'Export as excel', class: html_class.append('filter-btn modal-btn
|
18
|
+
tag.a 'Export as excel', class: html_class.append('filter-btn modal-btn me-2'), data: { toggle: 'modal', target: '#exportmodal' } do
|
19
19
|
concat tag.i class: 'fa fa-download'
|
20
20
|
concat tag.span ' Export'
|
21
21
|
end
|
@@ -53,7 +53,8 @@ module CmAdmin
|
|
53
53
|
concat hidden_field_tag 'class_name', klass.name.to_s, id: 'export-to-file-klass'
|
54
54
|
concat checkbox_row(klass)
|
55
55
|
concat tag.hr
|
56
|
-
|
56
|
+
# TODO: export-to-file-btn class is used for JS functionality, Have to remove
|
57
|
+
concat submit_tag 'Export', class: 'btn-primary export-to-file-btn'
|
57
58
|
end
|
58
59
|
end
|
59
60
|
end
|