visual_condition_builder 2.1.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/visual_condition_builder/condition_builder.js +29 -2
- data/app/assets/stylesheets/visual_condition_builder/condition_builder.css +32 -21
- data/app/helpers/visual_condition_builder/application_helper.rb +3 -12
- data/app/views/visual_condition_builder/_conditions_fields.html.erb +13 -0
- data/app/views/visual_condition_builder/_conditions_fields_item.html.erb +12 -0
- data/lib/visual_condition_builder/converter.rb +116 -0
- data/lib/visual_condition_builder/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29c7b9f0c2676e707c087a1f800b69bb51d2db65
|
4
|
+
data.tar.gz: 5a6f334ce10f479ed1b6a5666eab2d9a0d46b991
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c65a6b40f4fb6ed9e7a5afb218c0c5df3e4f45814c8fe798b1c5b19be56d2bfd38b18eb1dfb6fe1389291ad46db6522b01c6e551182631a2fb8d372dc7cba491
|
7
|
+
data.tar.gz: 4813cea48ec606be4c682b50e1b68b5358a3f6e7ec3c4efa1059465db216d90c391cb934fc33d6d812f3332ded2c0165bf9336e5c1107c9a17f7f08ec47753a3
|
@@ -164,7 +164,11 @@
|
|
164
164
|
plugin.load_values_from_input = function (element_input) {
|
165
165
|
var $elInput = $(element_input);
|
166
166
|
if ($elInput.length > 0) {
|
167
|
-
|
167
|
+
try {
|
168
|
+
plugin.parameters.values = JSON.parse($elInput.val());
|
169
|
+
} catch(e) {
|
170
|
+
plugin.parameters.values = '';
|
171
|
+
}
|
168
172
|
}
|
169
173
|
plugin.load_values(plugin.parameters.values);
|
170
174
|
}; //END load_values_from_input
|
@@ -639,5 +643,28 @@ $(document).on('click', '.add-condition-field', function (ev) {
|
|
639
643
|
var container = $(this).closest('.add-condition').attr('data-target');
|
640
644
|
var field_name = $(this).attr('data-field');
|
641
645
|
var $conditionBuilder = $(container).data('conditionBuilder');
|
646
|
+
console.log('a');
|
642
647
|
$conditionBuilder.add_condition(field_name);
|
643
|
-
});
|
648
|
+
});
|
649
|
+
|
650
|
+
//DROPDOWN WITH SEARCH
|
651
|
+
$(document).on('keyup','.dropdown-filter-control', function(ev){
|
652
|
+
var ulEl = $(this).closest('ul.dropdown-menu');
|
653
|
+
var searchTerm = $(this).val().toLowerCase();
|
654
|
+
ulEl.find('li.dropdown-menu-item').each(function(){
|
655
|
+
var filter = $(this).filter(function() {
|
656
|
+
return $(this).attr('data-search-term').toLowerCase().indexOf(searchTerm) > -1;
|
657
|
+
});
|
658
|
+
// $(this).filter('[data-search-term *= ' + searchTerm + ']')
|
659
|
+
if (searchTerm.length < 1 || filter.length > 0) {
|
660
|
+
$(this).show();
|
661
|
+
} else {
|
662
|
+
$(this).hide();
|
663
|
+
}
|
664
|
+
});
|
665
|
+
});
|
666
|
+
|
667
|
+
//AUTO FOCUS
|
668
|
+
$(document).on('shown.bs.dropdown', '.dropdown.add-condition', function () {
|
669
|
+
$(this).find('input.dropdown-filter-control:first').focus();
|
670
|
+
});
|
@@ -21,31 +21,32 @@
|
|
21
21
|
display: none !important;
|
22
22
|
}
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
}
|
24
|
+
/*.add-condition {*/
|
25
|
+
/*display: inline-block;*/
|
26
|
+
/*}*/
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
}
|
28
|
+
/*.add-condition-menu {*/
|
29
|
+
/*height: auto;*/
|
30
|
+
/*max-height: 200px;*/
|
31
|
+
/*overflow-x: hidden;*/
|
32
|
+
/*}*/
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
}
|
34
|
+
/*.add-condition-menu > li > a {*/
|
35
|
+
/*display: block;*/
|
36
|
+
/*padding: 3px 20px;*/
|
37
|
+
/*clear: both;*/
|
38
|
+
/*font-weight: 400;*/
|
39
|
+
/*line-height: 1.42857143;*/
|
40
|
+
/*color: #333;*/
|
41
|
+
/*white-space: nowrap;*/
|
42
|
+
/*}*/
|
43
43
|
|
44
44
|
.condition-builder .remove-condition {
|
45
45
|
margin-left: 5px;
|
46
46
|
font-size: 16px;
|
47
47
|
vertical-align: middle;
|
48
48
|
}
|
49
|
+
|
49
50
|
.condition-builder .remove-condition:hover {
|
50
51
|
text-decoration: none;
|
51
52
|
}
|
@@ -87,6 +88,7 @@
|
|
87
88
|
padding-left: 1.25em;
|
88
89
|
cursor: row-resize;
|
89
90
|
}
|
91
|
+
|
90
92
|
.condition-builder .conditions-move:before {
|
91
93
|
content: "";
|
92
94
|
position: absolute;
|
@@ -95,7 +97,16 @@
|
|
95
97
|
width: 1em;
|
96
98
|
height: 0.15em;
|
97
99
|
background: black;
|
98
|
-
box-shadow:
|
99
|
-
|
100
|
-
|
101
|
-
|
100
|
+
box-shadow: 0 0.25em 0 0 black,
|
101
|
+
0 0.5em 0 0 black;
|
102
|
+
}
|
103
|
+
|
104
|
+
.dropdown-menu-scrollable {
|
105
|
+
height: auto;
|
106
|
+
max-height: 200px;
|
107
|
+
overflow-x: hidden;
|
108
|
+
}
|
109
|
+
|
110
|
+
.dropdown-menu .dropdown-filter {
|
111
|
+
padding: 0px 0px 0px 3px;
|
112
|
+
}
|
@@ -27,18 +27,9 @@ txtjs
|
|
27
27
|
def conditions_fields(dictionary)
|
28
28
|
dictionary_name = get_dictionary_name(dictionary)
|
29
29
|
dictionary_klass = get_dictionary_klass(dictionary)
|
30
|
-
container_name = "
|
31
|
-
|
32
|
-
|
33
|
-
concat(content_tag(:button, class: 'btn btn-default dropdown-toggle', data: {toggle: 'dropdown'}, type: 'button') do
|
34
|
-
concat(I18n.t(:dropdown, default: ['Fields'], scope: [:condition_builder]))
|
35
|
-
concat(content_tag(:span, nil, class:'caret'))
|
36
|
-
end)
|
37
|
-
concat(content_tag(:ul, class: 'dropdown-menu add-condition-menu') do
|
38
|
-
create_conditions_fields_item(dictionary_klass.fields(get_dictionary_context(dictionary)))
|
39
|
-
end)
|
40
|
-
end
|
41
|
-
end
|
30
|
+
@container_name = "##{dictionary_name}_condition_container"
|
31
|
+
@fields = dictionary_klass.fields(get_dictionary_context(dictionary))
|
32
|
+
render partial: 'visual_condition_builder/conditions_fields'
|
42
33
|
end
|
43
34
|
|
44
35
|
private
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<div class="dropdown add-condition" data-target="<%= @container_name %>">
|
2
|
+
<button class="btn btn-default dropdown-toggle" data-toggle="dropdown", data-type="button">
|
3
|
+
<%= I18n.t(:dropdown, default: ['Fields'], scope: [:condition_builder]) %>
|
4
|
+
<span class="caret"></span>
|
5
|
+
</button>
|
6
|
+
<ul class="dropdown-menu dropdown-menu-scrollable add-condition-menu">
|
7
|
+
<li class="dropdown-filter">
|
8
|
+
<input type="text" class="form-control dropdown-filter-control" autocomplete="off" role="textbox" aria-label="Search">
|
9
|
+
</li>
|
10
|
+
<li role="separator" class="divider"></li>
|
11
|
+
<%= render partial: 'visual_condition_builder/conditions_fields_item', locals: {fields: @fields} %>
|
12
|
+
</ul>
|
13
|
+
</div>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<% fields.each do |field, attrs| %>
|
2
|
+
<% if field.is_a?(Hash) #GROUP %>
|
3
|
+
<li class="dropdown-header dropdown-menu-item">
|
4
|
+
<%= field.values.first %>
|
5
|
+
</li>
|
6
|
+
<%= render partial: 'visual_condition_builder/conditions_fields_item', locals: {fields: attrs} %>
|
7
|
+
<% else %>
|
8
|
+
<li class="dropdown-menu-item" data-search-term="<%= attrs[:label] %>">
|
9
|
+
<a href="#" class="add-condition-field" data-field="<%= field%>"><%= attrs[:label] %></a>
|
10
|
+
</li>
|
11
|
+
<% end %>
|
12
|
+
<% end %>
|
@@ -33,5 +33,121 @@ module VisualConditionBuilder
|
|
33
33
|
end
|
34
34
|
ransack_q
|
35
35
|
end
|
36
|
+
|
37
|
+
def self.to_mongo(params)
|
38
|
+
query = []
|
39
|
+
conditions = params.is_a?(Array) ? params : JSON.parse(params ||= '[]')
|
40
|
+
conditions.map do |p|
|
41
|
+
tmp = {}
|
42
|
+
case p[1].to_s.downcase.to_sym
|
43
|
+
when :eq
|
44
|
+
tmp[p[0]] = p[2]
|
45
|
+
when :not_eq
|
46
|
+
tmp[p[0]] = Hash["$ne", p[2]]
|
47
|
+
when :matches
|
48
|
+
tmp[p[0]] = Hash["$regex",p[2]]
|
49
|
+
when :does_not_match
|
50
|
+
tmp[p[0]] = Hash["$regex","^((?!#{p[2]}).)*$"]
|
51
|
+
tmp[p[0]]["$options"] = "s"
|
52
|
+
when :lt
|
53
|
+
tmp[p[0]] = Hash["$lt", p[2]]
|
54
|
+
when :gt
|
55
|
+
tmp[p[0]] = Hash["$gt", p[2]]
|
56
|
+
when :lteq
|
57
|
+
tmp[p[0]] = Hash["$lte", p[2]]
|
58
|
+
when :gteq
|
59
|
+
tmp[p[0]] = Hash["$gte", p[2]]
|
60
|
+
when :in
|
61
|
+
tmp[p[0]] = Hash["$in", p[2]]
|
62
|
+
when :not_in
|
63
|
+
tmp[p[0]] = Hash["$nin", p[2]]
|
64
|
+
when :cont
|
65
|
+
tmp[p[0]] = Hash["$regex",p[2]]
|
66
|
+
when :not_cont
|
67
|
+
tmp[p[0]] = Hash["$regex","^((?!#{p[2]}).)*$"]
|
68
|
+
tmp[p[0]]["$options"] = "s"
|
69
|
+
when :cont_any
|
70
|
+
if p[2].is_a?(Array)
|
71
|
+
tmpAny = []
|
72
|
+
p[2].each do |v|
|
73
|
+
tmpAny << Hash[tmp[p[0]], Hash["$regex", v]]
|
74
|
+
end
|
75
|
+
tmp["$or"] = tmpAny
|
76
|
+
end
|
77
|
+
when :not_cont_any
|
78
|
+
if p[2].is_a?(Array)
|
79
|
+
tmpAny = []
|
80
|
+
p[2].each do |v|
|
81
|
+
tmpAny << Hash[tmp[p[0]], Hash["$regex", "^((?!#{v}).)*$", "$options" => "s"]]
|
82
|
+
end
|
83
|
+
tmp["$or"] = tmpAny
|
84
|
+
end
|
85
|
+
when :cont_all
|
86
|
+
if p[2].is_a?(Array)
|
87
|
+
tmpAny = []
|
88
|
+
p[2].each do |v|
|
89
|
+
tmpAny << Hash[tmp[p[0]], Hash["$regex", v]]
|
90
|
+
end
|
91
|
+
tmp["$and"] = tmpAny
|
92
|
+
end
|
93
|
+
when :not_cont_all
|
94
|
+
if p[2].is_a?(Array)
|
95
|
+
tmpAny = []
|
96
|
+
p[2].each do |v|
|
97
|
+
tmpAny << Hash[tmp[p[0]], Hash["$regex", "^((?!#{v}).)*$", "$options" => "s"]]
|
98
|
+
end
|
99
|
+
tmp["$and"] = tmpAny
|
100
|
+
end
|
101
|
+
when :start
|
102
|
+
tmp[p[0]] = Hash["$regex", "^#{p[2]}"]
|
103
|
+
when :not_start
|
104
|
+
tmp[p[0]] = Hash["$regex", "^(?!#{p[2]})"]
|
105
|
+
when :end
|
106
|
+
tmp[p[0]] = Hash["$regex", "#{p[2]}$"]
|
107
|
+
when :not_end
|
108
|
+
tmp[p[0]] = Hash["$regex", "(?<!#{p[2]})$"]
|
109
|
+
when :true
|
110
|
+
tmp[p[0]] = 'true'
|
111
|
+
when :not_true
|
112
|
+
tmp[p[0]] = Hash["$ne", 'true']
|
113
|
+
when :false
|
114
|
+
tmp[p[0]] = 'false'
|
115
|
+
when :not_false
|
116
|
+
tmp[p[0]] = Hash["$ne", 'false']
|
117
|
+
when :present
|
118
|
+
tmp[p[0]] = Hash["$ne", '']
|
119
|
+
when :blank
|
120
|
+
tmp[p[0]] = ''
|
121
|
+
when :null
|
122
|
+
tmp[p[0]] = 'null'
|
123
|
+
when :not_null
|
124
|
+
tmp[p[0]] = Hash["$ne", 'null']
|
125
|
+
when :between
|
126
|
+
if p[2].is_a?(Array)
|
127
|
+
tmp[p[0]]["$gte"] = p[2][0] if p[2][0]
|
128
|
+
tmp[p[0]]["$lte"] = p[2][1] if p[2][1]
|
129
|
+
end
|
130
|
+
when :today
|
131
|
+
tmp[p[0]] = Date.today
|
132
|
+
when :yesterday
|
133
|
+
tmp[p[0]] = Date.yesterday
|
134
|
+
when :tomorrow
|
135
|
+
tmp[p[0]] = Date.tomorrow
|
136
|
+
when :this_week
|
137
|
+
tmp[p[0]] = Hash["$gte", Date.today.beginning_of_week]
|
138
|
+
tmp[p[0]]["$lte"] = Date.today.end_of_week
|
139
|
+
when :last_week
|
140
|
+
tmp[p[0]] = Hash["$gte", 1.week.ago.beginning_of_week]
|
141
|
+
tmp[p[0]]["$lte"] = 1.week.ago.end_of_week
|
142
|
+
when :next_week
|
143
|
+
tmp[p[0]] = Hash["$gte", Date.today.next_week.beginning_of_week]
|
144
|
+
tmp[p[0]]["$lte"] = Date.today.next_week.end_of_week
|
145
|
+
else
|
146
|
+
tmp[p[0]] = Hash[p[1],p[2]]
|
147
|
+
end
|
148
|
+
query << tmp if tmp.present?
|
149
|
+
end
|
150
|
+
query.present? ? Hash["$and", query] : {}
|
151
|
+
end
|
36
152
|
end
|
37
153
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: visual_condition_builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bruno Porto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -100,6 +100,8 @@ files:
|
|
100
100
|
- app/controllers/application_dictionary.rb
|
101
101
|
- app/controllers/visual_condition_builder/application_controller.rb
|
102
102
|
- app/helpers/visual_condition_builder/application_helper.rb
|
103
|
+
- app/views/visual_condition_builder/_conditions_fields.html.erb
|
104
|
+
- app/views/visual_condition_builder/_conditions_fields_item.html.erb
|
103
105
|
- config/initializers/assets.rb
|
104
106
|
- config/initializers/visual_condition_builder.rb
|
105
107
|
- config/locales/visual_condition_builder.en.yml
|