criteria_operator-ui_component 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e59209173c826deb5e89edbd128dc8875980a835
4
- data.tar.gz: 9a6b936f6fd41493dfe9d8e4ee581a4c7d3198c1
3
+ metadata.gz: 34d248889761e6d31e3148506b089f3ea88481f6
4
+ data.tar.gz: 511d5fb6743d803453c4311f6b3cbea841ccaf48
5
5
  SHA512:
6
- metadata.gz: 5b5f5596ee42e83b0a33f38309ff529aaf98e7b02b983d59d6b1993f2528a517c909d1666606530ecaf6be0f5b5f32ebf0c27856994d271ca7531e53f30e7177
7
- data.tar.gz: 57340e412354213ef57c2753d289c08aa0a2f1a74333c8626dfafdb2843c9fcc7cc8e52662bff3fc2a37d1a44b861aab45083061eb73e90c692b1d3c2d046f2b
6
+ metadata.gz: 529c2e61693320dacc0444ecb9d1e58f15c862a965ed756cb83783262679a417908f94f07d15062a240f09930b474057b0651ea1b84ccf4ac704b8ae31941703
7
+ data.tar.gz: 48a4434e5a24b909ed3477356f2258d37976a17266ca0775b364d373b0f5233ef8c61909cef2a7ba760840e243231181ee242a310c125451355816dca4904d8c
@@ -13,37 +13,3 @@
13
13
  *= require_tree .
14
14
  *= require_self
15
15
  */
16
-
17
- .criteria_editor {
18
- border: dashed #2E2F30 thin;
19
- padding: 5px;
20
- }
21
-
22
- .criteria_editor_header {
23
- font-size: large;
24
- font-weight: bold;
25
- margin-bottom: 10px;
26
- }
27
-
28
- .criteria_group_row {
29
- border: dashed #666666 thin;
30
- }
31
-
32
- .criteria_group_row_header {
33
- font-size: medium;
34
- font-weight: bold;
35
- }
36
-
37
- .criteria_expression_row {
38
- border: dotted #999999 thin;
39
- }
40
-
41
- .criteria_editor_empty_placeholder {
42
- color: #999999;
43
- padding: 15px;
44
- border: dashed #999999;
45
- }
46
-
47
- .criteria_editor_row_wrapper {
48
- margin-left: 10px;
49
- }
@@ -0,0 +1,33 @@
1
+ .criteria_editor {
2
+ border: dashed #2E2F30 thin;
3
+ padding: 5px;
4
+ }
5
+
6
+ .criteria_editor_header {
7
+ font-size: large;
8
+ font-weight: bold;
9
+ margin-bottom: 10px;
10
+ }
11
+
12
+ .criteria_group_row {
13
+ border: dashed #666666 thin;
14
+ }
15
+
16
+ .criteria_group_row_header {
17
+ font-size: medium;
18
+ font-weight: bold;
19
+ }
20
+
21
+ .criteria_expression_row {
22
+ border: dotted #999999 thin;
23
+ }
24
+
25
+ .criteria_editor_empty_placeholder {
26
+ color: #999999;
27
+ padding: 15px;
28
+ border: dashed #999999;
29
+ }
30
+
31
+ .criteria_editor_row_wrapper {
32
+ margin-left: 10px;
33
+ }
@@ -1,4 +1,4 @@
1
- <div class="criteria_group_row" data-locator="<%= @locator %>" data-childcount="<%= @group.operand_collection.count %>">
1
+ <div class="criteria_group_row" data-locator="<%= @locator %>" data-childcount="<%= @group.nil? ? 0 : @group.operand_collection.count %>">
2
2
  <select class="criteria_operator_type_input group_operator_type">
3
3
  <% operators.each do |op| %>
4
4
  <option value="<%= op[:value] %>" <% if op[:value] == operator_type %>selected<% end %>><%= op[:text] %></option>
@@ -1,146 +1,146 @@
1
- require_dependency "criteria_operator/ui_component/application_controller"
2
- require 'cell'
3
- require 'cell/erb'
4
- require 'yaml'
5
-
6
- module CriteriaOperator
7
- module UiComponent
8
- class AjaxController < ApplicationController
9
- def create_expression
10
- return unless ajax_params.has_key? :root_operator
11
- root_operator = root_op_from_params
12
- operator = BinaryOperator.new
13
- add_sub_operator root_operator, operator, ajax_params[:locator]
14
- html = ExpressionCell.call(operator).call(:show, locator: new_locator)
15
- render json: { html: html, operator: YAML.dump(root_operator) }
16
- end
17
-
18
- def create_group
19
- return unless ajax_params.has_key? :root_operator
20
- root_operator = root_op_from_params
21
- operator = GroupOperator.new
22
- add_sub_operator root_operator, operator, ajax_params[:locator]
23
- html = GroupCell.call(operator).call(:show, locator: new_locator)
24
- render json: { html: html, operator: YAML.dump(root_operator) }
25
- end
26
-
27
- def delete_element
28
- return unless (ajax_params.has_key? :root_operator) && (ajax_params.has_key? :locator)
29
- root_operator = root_op_from_params
30
- remove_sub_operator root_operator, ajax_params[:locator]
31
- render json: { operator: YAML.dump(root_operator) }
32
- end
33
-
34
- def operand_change
35
- return unless (ajax_params.has_key? :root_operator) && (ajax_params.has_key? :locator)
36
- root_operator = root_op_from_params
37
- op = locate_sub_operator root_operator, ajax_params[:locator]
38
- op.left_operand = OperandProperty.new(ajax_params[:operand_value]) if ajax_params[:operand_type] == 'left'
39
- op.right_operand = OperandValue.new(ajax_params[:operand_value]) if ajax_params[:operand_type] == 'right'
40
- render json: { operator: YAML.dump(root_operator) }
41
- end
42
-
43
- def expression_type_change
44
- return unless (ajax_params.has_key? :root_operator) && (ajax_params.has_key? :locator)
45
- root_operator = root_op_from_params
46
- op = locate_sub_operator root_operator, ajax_params[:locator]
47
- op.operator_type = ajax_params[:operator_type_value]
48
- render json: { operator: YAML.dump(root_operator) }
49
- end
50
-
51
- def group_type_change
52
- return unless (ajax_params.has_key? :root_operator) && (ajax_params.has_key? :locator)
53
- root_operator = root_op_from_params
54
- root_operator = change_sub_group_type root_operator, ajax_params[:locator], ajax_params[:operator_type_value].to_i
55
- render json: { operator: YAML.dump(root_operator) }
56
- end
57
-
58
- private
59
-
60
- def ajax_params
61
- params.permit :root_operator, :locator, :child_count, :operand_type, :operand_value, :operator_type_value
62
- end
63
-
64
- def root_op_from_params
65
- YAML.safe_load ajax_params[:root_operator], (ObjectSpace.each_object(Class).select { |klass| klass < BaseOperator })
66
- end
67
-
68
- def new_locator
69
- if ajax_params.has_key? :child_count
70
- ajax_params[:child_count].to_s
71
- else
72
- '0'
73
- end
74
- end
75
-
76
- def locate_sub_operator(operator, locator)
77
- op = get_negated_group_if_exist operator
78
- locator.split(',').map(&:to_i).each do |pos|
79
- # TODO: some kind of error handling beside cancelling?
80
- return nil unless op.is_a? GroupOperator
81
- op = op.operand_collection[pos]
82
- op = get_negated_group_if_exist op
83
- end
84
- op
85
- end
86
-
87
- def add_sub_operator(root_op, extend_op, locator)
88
- op = locate_sub_operator root_op, locator
89
- op.operand_collection << extend_op
90
- end
91
-
92
- def remove_sub_operator(root_op, locator)
93
- locator_array = locator.split(',')
94
- pos = locator_array.pop
95
- op = root_op
96
- unless locator_array.empty?
97
- op = locate_sub_operator op, locator_array.join(',')
98
- end
99
- op = get_negated_group_if_exist op
100
- op.operand_collection.delete_at pos.to_i
101
- end
102
-
103
- def change_sub_group_type(root_op, locator, op_type)
104
- op = root_op
105
- last_pos = -1
106
- parent_op = nil
107
- locator_array = locator.split(',')
108
- locator_array.map(&:to_i).each do |pos|
109
- op = get_negated_group_if_exist op
110
- last_pos = pos
111
- parent_op = op
112
- op = op.operand_collection[pos]
113
- end
114
-
115
- if negation? op
116
- if op_type > 0
117
- parent_op.operand_collection[last_pos] = op.operand
118
- op.operand.operator_type = op_type
119
- else
120
- op.operand.operator_type = op_type * -1
121
- end
122
- else
123
- if op_type < 0
124
- parent_op.operand_collection[last_pos] = UnaryOperator.new op, UnaryOperatorType::NOT
125
- op.operator_type = op_type * -1
126
- else
127
- op.operator_type = op_type
128
- end
129
- end
130
- root_op
131
- end
132
-
133
- def get_negated_group_if_exist(op)
134
- if negation? op
135
- op.operand
136
- else
137
- op
138
- end
139
- end
140
-
141
- def negation?(op)
142
- op.is_a?(UnaryOperator) && (op.operator_type == UnaryOperatorType::NOT)
143
- end
144
- end
145
- end
146
- end
1
+ require_dependency "criteria_operator/ui_component/application_controller"
2
+ require 'cell'
3
+ require 'cell/erb'
4
+ require 'yaml'
5
+
6
+ module CriteriaOperator
7
+ module UiComponent
8
+ class AjaxController < ApplicationController
9
+ def create_expression
10
+ return unless ajax_params.has_key? :root_operator
11
+ root_operator = root_op_from_params
12
+ operator = BinaryOperator.new
13
+ add_sub_operator root_operator, operator, ajax_params[:locator]
14
+ html = ExpressionCell.call(operator).call(:show, locator: new_locator)
15
+ render json: { html: html, operator: YAML.dump(root_operator) }
16
+ end
17
+
18
+ def create_group
19
+ return unless ajax_params.has_key? :root_operator
20
+ root_operator = root_op_from_params
21
+ operator = GroupOperator.new
22
+ add_sub_operator root_operator, operator, ajax_params[:locator]
23
+ html = GroupCell.call(operator).call(:show, locator: new_locator)
24
+ render json: { html: html, operator: YAML.dump(root_operator) }
25
+ end
26
+
27
+ def delete_element
28
+ return unless (ajax_params.has_key? :root_operator) && (ajax_params.has_key? :locator)
29
+ root_operator = root_op_from_params
30
+ remove_sub_operator root_operator, ajax_params[:locator]
31
+ render json: { operator: YAML.dump(root_operator) }
32
+ end
33
+
34
+ def operand_change
35
+ return unless (ajax_params.has_key? :root_operator) && (ajax_params.has_key? :locator)
36
+ root_operator = root_op_from_params
37
+ op = locate_sub_operator root_operator, ajax_params[:locator]
38
+ op.left_operand = OperandProperty.new(ajax_params[:operand_value]) if ajax_params[:operand_type] == 'left'
39
+ op.right_operand = OperandValue.new(ajax_params[:operand_value]) if ajax_params[:operand_type] == 'right'
40
+ render json: { operator: YAML.dump(root_operator) }
41
+ end
42
+
43
+ def expression_type_change
44
+ return unless (ajax_params.has_key? :root_operator) && (ajax_params.has_key? :locator)
45
+ root_operator = root_op_from_params
46
+ op = locate_sub_operator root_operator, ajax_params[:locator]
47
+ op.operator_type = ajax_params[:operator_type_value]
48
+ render json: { operator: YAML.dump(root_operator) }
49
+ end
50
+
51
+ def group_type_change
52
+ return unless (ajax_params.has_key? :root_operator) && (ajax_params.has_key? :locator)
53
+ root_operator = root_op_from_params
54
+ root_operator = change_sub_group_type root_operator, ajax_params[:locator], ajax_params[:operator_type_value].to_i
55
+ render json: { operator: YAML.dump(root_operator) }
56
+ end
57
+
58
+ private
59
+
60
+ def ajax_params
61
+ params.permit :root_operator, :locator, :child_count, :operand_type, :operand_value, :operator_type_value
62
+ end
63
+
64
+ def root_op_from_params
65
+ YAML.safe_load ajax_params[:root_operator], (ObjectSpace.each_object(Class).select { |klass| klass < BaseOperator })
66
+ end
67
+
68
+ def new_locator
69
+ if ajax_params.has_key? :child_count
70
+ ajax_params[:child_count].to_s
71
+ else
72
+ '0'
73
+ end
74
+ end
75
+
76
+ def locate_sub_operator(operator, locator)
77
+ op = get_negated_group_if_exist operator
78
+ locator.split(',').map(&:to_i).each do |pos|
79
+ # TODO: some kind of error handling beside cancelling?
80
+ return nil unless op.is_a? GroupOperator
81
+ op = op.operand_collection[pos]
82
+ op = get_negated_group_if_exist op
83
+ end
84
+ op
85
+ end
86
+
87
+ def add_sub_operator(root_op, extend_op, locator)
88
+ op = locate_sub_operator root_op, locator
89
+ op.operand_collection << extend_op
90
+ end
91
+
92
+ def remove_sub_operator(root_op, locator)
93
+ locator_array = locator.split(',')
94
+ pos = locator_array.pop
95
+ op = root_op
96
+ unless locator_array.empty?
97
+ op = locate_sub_operator op, locator_array.join(',')
98
+ end
99
+ op = get_negated_group_if_exist op
100
+ op.operand_collection.delete_at pos.to_i
101
+ end
102
+
103
+ def change_sub_group_type(root_op, locator, op_type)
104
+ op = root_op
105
+ last_pos = -1
106
+ parent_op = nil
107
+ locator_array = locator.split(',')
108
+ locator_array.map(&:to_i).each do |pos|
109
+ op = get_negated_group_if_exist op
110
+ last_pos = pos
111
+ parent_op = op
112
+ op = op.operand_collection[pos]
113
+ end
114
+
115
+ if negation? op
116
+ if op_type > 0
117
+ parent_op.operand_collection[last_pos] = op.operand
118
+ op.operand.operator_type = op_type
119
+ else
120
+ op.operand.operator_type = op_type * -1
121
+ end
122
+ else
123
+ if op_type < 0
124
+ parent_op.operand_collection[last_pos] = UnaryOperator.new op, UnaryOperatorType::NOT
125
+ op.operator_type = op_type * -1
126
+ else
127
+ op.operator_type = op_type
128
+ end
129
+ end
130
+ root_op
131
+ end
132
+
133
+ def get_negated_group_if_exist(op)
134
+ if negation? op
135
+ op.operand
136
+ else
137
+ op
138
+ end
139
+ end
140
+
141
+ def negation?(op)
142
+ op.is_a?(UnaryOperator) && (op.operator_type == UnaryOperatorType::NOT)
143
+ end
144
+ end
145
+ end
146
+ end
@@ -1,8 +1,8 @@
1
- require 'criteria_operator/ui_component/engine'
2
- require 'cells/rails'
3
-
4
- module CriteriaOperator
5
- module UiComponent
6
- # Your code goes here...
7
- end
8
- end
1
+ require 'criteria_operator/ui_component/engine'
2
+ require 'cells/rails'
3
+
4
+ module CriteriaOperator
5
+ module UiComponent
6
+ # Your code goes here...
7
+ end
8
+ end
@@ -1,5 +1,5 @@
1
- module CriteriaOperator
2
- module UiComponent
3
- VERSION = '0.2.0'
4
- end
5
- end
1
+ module CriteriaOperator
2
+ module UiComponent
3
+ VERSION = '0.2.1'
4
+ end
5
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: criteria_operator-ui_component
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Koch
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-05-24 00:00:00.000000000 Z
11
+ date: 2017-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -199,6 +199,7 @@ files:
199
199
  - app/assets/javascripts/criteria_operator/ui_component/application.js
200
200
  - app/assets/javascripts/criteria_operator/ui_component/criteria_editor.js
201
201
  - app/assets/stylesheets/criteria_operator/ui_component/application.css
202
+ - app/assets/stylesheets/criteria_operator/ui_component/criteria_editor.css
202
203
  - app/cells/criteria_operator/ui_component/base_cell.rb
203
204
  - app/cells/criteria_operator/ui_component/criteria_editor/show.erb
204
205
  - app/cells/criteria_operator/ui_component/criteria_editor_cell.rb