cm-admin 1.3.3 → 1.3.5
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/form_validation.js +4 -5
- data/app/views/cm_admin/main/_nested_table_section.html.slim +1 -1
- data/app/views/cm_admin/main/new.html.slim +1 -1
- data/lib/cm_admin/models/dsl_method.rb +1 -1
- data/lib/cm_admin/models/filter.rb +37 -33
- data/lib/cm_admin/models/form_field.rb +2 -2
- data/lib/cm_admin/version.rb +1 -1
- data/lib/cm_admin/view_helpers/form_field_helper.rb +50 -13
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d3ee61a20da53d4f971707c68d72d47665c39a59eebdd554d13b96254cf666c
|
4
|
+
data.tar.gz: 9c2e4b2fb2ca38f03a8f799c69d3f966088211b10909d1a19ca437e5437dc93c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b0b6889ee66cb8b6cc230d015356478dba9ccd348003334ddb315bdc34d2071033a91c65c196c92207fb01f8551377043effd3117dac910118bfcd71b20523b
|
7
|
+
data.tar.gz: 64600259cd7a8e671a5393f7a0058182303f99c8cc80c2fe0fa41441c8a1a7ce7c2124658bec77b3cf26cdfc602a9945a0f9b77279c15bfb3f28a923608c8637
|
data/Gemfile.lock
CHANGED
@@ -1,20 +1,19 @@
|
|
1
1
|
$(document).on('click', '.form_submit', function(e) {
|
2
|
-
console.log('Came here')
|
3
2
|
e.preventDefault();
|
4
3
|
var submit = [];
|
5
4
|
var form_class = $(this).data('form-class');
|
6
5
|
$("." + form_class + " input.required, ." + form_class + " textarea.required").each(function() {
|
7
|
-
$(this).removeClass('
|
6
|
+
$(this).removeClass('is-invalid');
|
8
7
|
if ($(this).val().trim().length === 0) {
|
9
|
-
$(this).addClass('
|
8
|
+
$(this).addClass('is-invalid');
|
10
9
|
$(this)[0].scrollIntoView(true);
|
11
10
|
submit.push(true);
|
12
11
|
}
|
13
12
|
});
|
14
13
|
$("." + form_class + " select.required").each(function() {
|
15
|
-
$(this).removeClass('
|
14
|
+
$(this).removeClass('is-invalid');
|
16
15
|
if ($(this).val().trim().length === 0) {
|
17
|
-
$(this).parent().find('.select2').addClass('
|
16
|
+
$(this).parent().find('.select2').addClass('is-invalid');
|
18
17
|
$(this)[0].scrollIntoView(true);
|
19
18
|
submit.push(true);
|
20
19
|
}
|
@@ -15,7 +15,7 @@
|
|
15
15
|
tr
|
16
16
|
- nested_field.fields.each do |field|
|
17
17
|
td data-field-type="#{field.field_type}"
|
18
|
-
= record
|
18
|
+
= show_field_value(record, field)
|
19
19
|
- else
|
20
20
|
- associated_records.each do |record|
|
21
21
|
.card.mb-3 data-table-name="#{nested_field.field_name}"
|
@@ -142,7 +142,7 @@ module CmAdmin
|
|
142
142
|
@available_actions << bulk_action
|
143
143
|
end
|
144
144
|
|
145
|
-
def filter(db_column_name, filter_type, options={})
|
145
|
+
def filter(db_column_name, filter_type, options = {})
|
146
146
|
@filters << CmAdmin::Models::Filter.new(db_column_name: db_column_name, filter_type: filter_type, options: options)
|
147
147
|
end
|
148
148
|
|
@@ -5,7 +5,7 @@ module CmAdmin
|
|
5
5
|
class Filter
|
6
6
|
include Utils::Helpers
|
7
7
|
|
8
|
-
attr_accessor :db_column_name, :filter_type, :placeholder, :collection
|
8
|
+
attr_accessor :db_column_name, :filter_type, :placeholder, :collection, :scope_name
|
9
9
|
|
10
10
|
VALID_FILTER_TYPES = Set[:date, :multi_select, :range, :search, :single_select].freeze
|
11
11
|
|
@@ -14,6 +14,7 @@ module CmAdmin
|
|
14
14
|
raise ArgumentError, "Kindly select a valid filter type like #{VALID_FILTER_TYPES.sort.to_sentence(last_word_connector: ', or ')} instead of #{filter_type} for column #{db_column_name}" unless VALID_FILTER_TYPES.include?(filter_type.to_sym)
|
15
15
|
|
16
16
|
@db_column_name, @filter_type = structure_data(db_column_name, filter_type)
|
17
|
+
@scope_name = nil
|
17
18
|
set_default_values
|
18
19
|
options.each do |key, value|
|
19
20
|
send("#{key}=", value)
|
@@ -52,7 +53,7 @@ module CmAdmin
|
|
52
53
|
def filtered_data(filter_params, records, filters)
|
53
54
|
if filter_params
|
54
55
|
filter_params.each do |scope_type, scope_value|
|
55
|
-
|
56
|
+
filter_method = case scope_type
|
56
57
|
when 'date', 'range'
|
57
58
|
'date_and_range'
|
58
59
|
when 'single_select', 'multi_select'
|
@@ -60,7 +61,7 @@ module CmAdmin
|
|
60
61
|
else
|
61
62
|
scope_type
|
62
63
|
end
|
63
|
-
records = send("cm_#{
|
64
|
+
records = send("cm_#{filter_method}_filter", scope_value, records, filters) if scope_value.present?
|
64
65
|
end
|
65
66
|
end
|
66
67
|
records
|
@@ -71,40 +72,44 @@ module CmAdmin
|
|
71
72
|
|
72
73
|
table_name = records.table_name
|
73
74
|
filters.select { |x| x if x.filter_type.eql?(:search) }.each do |filter|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
75
|
+
if filter.scope_name.present?
|
76
|
+
return records.send(filter.scope_name, scope_value)
|
77
|
+
else
|
78
|
+
query_variables = []
|
79
|
+
filter.db_column_name.each do |col|
|
80
|
+
case col
|
81
|
+
when Symbol
|
82
|
+
query_variables << "#{table_name.pluralize}.#{col}"
|
83
|
+
when Hash
|
84
|
+
col.map do |key, value|
|
85
|
+
value.map { |val| query_variables << "#{key.to_s.pluralize}.#{val}" }
|
86
|
+
end
|
82
87
|
end
|
83
88
|
end
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
end
|
89
|
+
terms = scope_value.downcase.split(/\s+/)
|
90
|
+
terms = terms.map { |e|
|
91
|
+
(e.gsub('*', '%').prepend('%') + '%').gsub(/%+/, '%')
|
92
|
+
}
|
93
|
+
sql = ''
|
94
|
+
query_variables.each.with_index do |column, i|
|
95
|
+
sql.concat("#{column} ILIKE ?")
|
96
|
+
sql.concat(' OR ') unless query_variables.size.eql?(i + 1)
|
97
|
+
end
|
94
98
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
+
if filter.db_column_name.map { |x| x.is_a?(Hash) }.include?(true)
|
100
|
+
associations_hash = filter.db_column_name.select { |x| x if x.is_a?(Hash) }.last
|
101
|
+
records = records.left_joins(associations_hash.keys).distinct
|
102
|
+
end
|
99
103
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
104
|
+
records = records.where(
|
105
|
+
terms.map { |term|
|
106
|
+
sql
|
107
|
+
}.join(' AND '),
|
108
|
+
*terms.map { |e| [e] * query_variables.size }.flatten
|
109
|
+
)
|
110
|
+
return records
|
111
|
+
end
|
106
112
|
end
|
107
|
-
records
|
108
113
|
end
|
109
114
|
|
110
115
|
def cm_date_and_range_filter(scope_value, records, filters)
|
@@ -123,7 +128,6 @@ module CmAdmin
|
|
123
128
|
|
124
129
|
def cm_dropdown_filter(scope_value, records, filters)
|
125
130
|
return nil if scope_value.nil?
|
126
|
-
|
127
131
|
scope_value.each do |key, value|
|
128
132
|
records = records.where(key => value) if value.present?
|
129
133
|
end
|
@@ -10,7 +10,7 @@ module CmAdmin
|
|
10
10
|
|
11
11
|
VALID_INPUT_TYPES = %i[
|
12
12
|
integer decimal string single_select multi_select date date_time text
|
13
|
-
single_file_upload multi_file_upload hidden rich_text check_box radio_button
|
13
|
+
single_file_upload multi_file_upload hidden rich_text check_box radio_button custom_string custom_date custom_single_select
|
14
14
|
].freeze
|
15
15
|
|
16
16
|
def initialize(field_name, input_type, attributes = {})
|
@@ -25,7 +25,7 @@ module CmAdmin
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def set_default_values
|
28
|
-
self.disabled = false
|
28
|
+
self.disabled = lambda { |arg| return false } if display_if.nil?
|
29
29
|
self.label = self.field_name.to_s.titleize
|
30
30
|
self.input_type = :string
|
31
31
|
self.html_attr = {}
|
data/lib/cm_admin/version.rb
CHANGED
@@ -3,8 +3,14 @@ module CmAdmin
|
|
3
3
|
module FormFieldHelper
|
4
4
|
def input_field_for_column(form_obj, cm_field)
|
5
5
|
return unless cm_field.display_if.call(form_obj.object)
|
6
|
-
|
7
|
-
|
6
|
+
if cm_field.helper_method
|
7
|
+
value = send(cm_field.helper_method, form_obj.object, cm_field.field_name)
|
8
|
+
elsif cm_field.input_type.to_s.include?('custom')
|
9
|
+
value = nil
|
10
|
+
else
|
11
|
+
value = form_obj.object.send(cm_field.field_name)
|
12
|
+
end
|
13
|
+
# value = cm_field.helper_method ? send(cm_field.helper_method, form_obj.object, cm_field.field_name) : form_obj.object.send(cm_field.field_name)
|
8
14
|
is_required = form_obj.object._validators[cm_field.field_name].map(&:kind).include?(:presence)
|
9
15
|
required_class = is_required ? 'required' : ''
|
10
16
|
target_action = @model.available_actions.select { |x| x.name == cm_field.target[:action_name].to_s }.first if cm_field.target.present?
|
@@ -14,7 +20,7 @@ module CmAdmin
|
|
14
20
|
def cm_integer_field(form_obj, cm_field, value, required_class, _target_action)
|
15
21
|
form_obj.text_field cm_field.field_name,
|
16
22
|
class: "field-control #{required_class}",
|
17
|
-
disabled: cm_field.disabled,
|
23
|
+
disabled: cm_field.disabled.call(form_obj.object),
|
18
24
|
value: value,
|
19
25
|
placeholder: cm_field.placeholder,
|
20
26
|
data: { behaviour: 'integer-only' }
|
@@ -23,7 +29,7 @@ module CmAdmin
|
|
23
29
|
def cm_decimal_field(form_obj, cm_field, value, required_class, _target_action)
|
24
30
|
form_obj.number_field cm_field.field_name,
|
25
31
|
class: "field-control #{required_class}",
|
26
|
-
disabled: cm_field.disabled,
|
32
|
+
disabled: cm_field.disabled.call(form_obj.object),
|
27
33
|
value: value,
|
28
34
|
placeholder: cm_field.placeholder,
|
29
35
|
data: { behaviour: 'decimal-only' }
|
@@ -32,16 +38,23 @@ module CmAdmin
|
|
32
38
|
def cm_string_field(form_obj, cm_field, value, required_class, _target_action)
|
33
39
|
form_obj.text_field cm_field.field_name,
|
34
40
|
class: "field-control #{required_class}",
|
35
|
-
disabled: cm_field.disabled,
|
41
|
+
disabled: cm_field.disabled.call(form_obj.object),
|
36
42
|
value: value,
|
37
43
|
placeholder: cm_field.placeholder
|
38
44
|
end
|
39
45
|
|
46
|
+
def cm_custom_string_field(form_obj, cm_field, value, required_class, _target_action)
|
47
|
+
text_field_tag cm_field.html_attr[:name] || cm_field.field_name,
|
48
|
+
value, class: "field-control #{required_class}",
|
49
|
+
disabled: cm_field.disabled.call(form_obj.object),
|
50
|
+
placeholder: cm_field.placeholder
|
51
|
+
end
|
52
|
+
|
40
53
|
def cm_single_select_field(form_obj, cm_field, value, required_class, target_action)
|
41
54
|
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
55
|
{ include_blank: cm_field.placeholder },
|
43
56
|
class: "field-control #{required_class} select-2",
|
44
|
-
disabled: cm_field.disabled,
|
57
|
+
disabled: cm_field.disabled.call(form_obj.object),
|
45
58
|
data: {
|
46
59
|
field_name: cm_field.field_name,
|
47
60
|
field_type: 'linked-field',
|
@@ -50,18 +63,42 @@ module CmAdmin
|
|
50
63
|
}
|
51
64
|
end
|
52
65
|
|
66
|
+
def cm_custom_single_select_field(form_obj, cm_field, value, required_class, target_action)
|
67
|
+
select_tag cm_field.html_attr[:name] || cm_field.field_name,
|
68
|
+
options_for_select(select_collection_value(form_obj.object, cm_field)),
|
69
|
+
{
|
70
|
+
include_blank: cm_field.placeholder,
|
71
|
+
class: "field-control #{required_class} select-2",
|
72
|
+
disabled: cm_field.disabled.call(form_obj.object),
|
73
|
+
data: {
|
74
|
+
field_name: cm_field.field_name,
|
75
|
+
field_type: 'linked-field',
|
76
|
+
target_action: target_action&.name,
|
77
|
+
target_url: target_action&.name ? cm_admin.send("#{@model.name.underscore}_#{target_action&.name}_path") : ''
|
78
|
+
}
|
79
|
+
}
|
80
|
+
end
|
81
|
+
|
53
82
|
def cm_multi_select_field(form_obj, cm_field, value, required_class, target_action)
|
54
83
|
form_obj.select cm_field.field_name,
|
55
84
|
options_for_select(select_collection_value(form_obj.object, cm_field), form_obj.object.send(cm_field.field_name)),
|
56
85
|
{ include_blank: cm_field.placeholder },
|
57
86
|
class: "field-control #{required_class} select-2",
|
58
|
-
disabled: cm_field.disabled, multiple: true
|
87
|
+
disabled: cm_field.disabled.call(form_obj.object), multiple: true
|
59
88
|
end
|
60
89
|
|
61
90
|
def cm_date_field(form_obj, cm_field, value, required_class, _target_action)
|
62
91
|
form_obj.text_field cm_field.field_name,
|
63
92
|
class: "field-control #{required_class}",
|
64
|
-
disabled: cm_field.disabled,
|
93
|
+
disabled: cm_field.disabled.call(form_obj.object),
|
94
|
+
placeholder: cm_field.placeholder,
|
95
|
+
data: { behaviour: 'date-only' }
|
96
|
+
end
|
97
|
+
|
98
|
+
def cm_custom_date_field(form_obj, cm_field, value, required_class, _target_action)
|
99
|
+
text_field_tag cm_field.html_attr[:name] || cm_field.field_name, value&.strftime('%d-%m-%Y'),
|
100
|
+
class: "field-control #{required_class}",
|
101
|
+
disabled: cm_field.disabled.call(form_obj.object),
|
65
102
|
value: value&.strftime('%d-%m-%Y'),
|
66
103
|
placeholder: cm_field.placeholder,
|
67
104
|
data: { behaviour: 'date-only' }
|
@@ -70,7 +107,7 @@ module CmAdmin
|
|
70
107
|
def cm_date_time_field(form_obj, cm_field, value, required_class, _target_action)
|
71
108
|
form_obj.text_field cm_field.field_name,
|
72
109
|
class: "field-control #{required_class}",
|
73
|
-
disabled: cm_field.disabled,
|
110
|
+
disabled: cm_field.disabled.call(form_obj.object),
|
74
111
|
value: value,
|
75
112
|
placeholder: cm_field.placeholder,
|
76
113
|
data: { behaviour: 'date-time' }
|
@@ -90,14 +127,14 @@ module CmAdmin
|
|
90
127
|
|
91
128
|
def cm_single_file_upload_field(form_obj, cm_field, _value, required_class, _target_action)
|
92
129
|
content_tag(:div) do
|
93
|
-
concat form_obj.file_field cm_field.field_name, class: "
|
130
|
+
concat form_obj.file_field cm_field.field_name, class: "field-control #{required_class}", disabled: cm_field.disabled.call(form_obj.object)
|
94
131
|
concat attachment_list(form_obj, cm_field, _value, required_class, _target_action)
|
95
132
|
end
|
96
133
|
end
|
97
134
|
|
98
135
|
def cm_multi_file_upload_field(form_obj, cm_field, _value, required_class, _target_action)
|
99
136
|
content_tag(:div) do
|
100
|
-
concat form_obj.file_field cm_field.field_name, multiple: true, class: "
|
137
|
+
concat form_obj.file_field cm_field.field_name, multiple: true, class: "field-control #{required_class}", disabled: cm_field.disabled.call(form_obj.object)
|
101
138
|
concat attachment_list(form_obj, cm_field, _value, required_class, _target_action)
|
102
139
|
end
|
103
140
|
end
|
@@ -159,7 +196,7 @@ module CmAdmin
|
|
159
196
|
form_obj.check_box cm_field.field_name,
|
160
197
|
{
|
161
198
|
class: "field-control cm-checkbox #{required_class} #{target_action.present? ? 'linked-field-request' : ''}",
|
162
|
-
disabled: cm_field.disabled,
|
199
|
+
disabled: cm_field.disabled.call(form_obj.object),
|
163
200
|
data: {
|
164
201
|
field_name: cm_field.field_name,
|
165
202
|
target_action: target_action&.name,
|
@@ -189,7 +226,7 @@ module CmAdmin
|
|
189
226
|
concat form_obj.check_box cm_field.field_name,
|
190
227
|
{
|
191
228
|
class: "field-control cm-checkbox #{required_class} #{target_action.present? ? 'linked-field-request' : ''}",
|
192
|
-
disabled: cm_field.disabled,
|
229
|
+
disabled: cm_field.disabled.call(form_obj.object),
|
193
230
|
name: "#{@model.name.underscore}[#{cm_field.field_name}][]",
|
194
231
|
data: {
|
195
232
|
target_action: target_action&.name,
|
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.3.
|
4
|
+
version: 1.3.5
|
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-11-
|
13
|
+
date: 2023-11-10 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|