alchemy-form 0.1.5 → 0.1.8
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.
- package/CHANGELOG.md +29 -0
- package/assets/stylesheets/form/alchemy_field_array.scss +4 -0
- package/assets/stylesheets/form/alchemy_select.scss +1 -3
- package/assets/stylesheets/form/alchemy_toggle.scss +2 -0
- package/assets/stylesheets/form/query_builder.scss +185 -0
- package/config/routes.js +8 -0
- package/controller/form_api_controller.js +43 -4
- package/element/20_query_builder_base.js +82 -0
- package/element/25_query_builder_data.js +139 -0
- package/element/alchemy_field.js +31 -7
- package/element/alchemy_select.js +172 -39
- package/element/alchemy_select_item.js +9 -0
- package/element/alchemy_table.js +172 -26
- package/element/query_builder.js +90 -0
- package/element/query_builder_entry.js +388 -0
- package/element/query_builder_group.js +248 -0
- package/element/query_builder_value.js +316 -0
- package/element/query_builder_variable.js +103 -0
- package/helper/form_actions/00_form_action.js +328 -0
- package/helper/form_actions/url_action.js +69 -0
- package/helper/query_builder_variable_definition/00_variable_definition.js +371 -0
- package/helper/query_builder_variable_definition/boolean_variable_definition.js +24 -0
- package/helper/query_builder_variable_definition/list_variable_definition.js +38 -0
- package/helper/query_builder_variable_definition/number_variable_definition.js +106 -0
- package/helper/query_builder_variable_definition/string_variable_definition.js +46 -0
- package/helper_field/query_builder_assignment.js +11 -0
- package/helper_field/query_builder_field.js +91 -0
- package/helper_field/query_builder_value.js +56 -0
- package/helper_field/query_builder_variable.js +56 -0
- package/package.json +2 -2
- package/view/form/elements/alchemy_field_array.hwk +3 -1
- package/view/form/elements/alchemy_field_array_entry.hwk +3 -1
- package/view/form/elements/alchemy_select_item.hwk +6 -1
- package/view/form/elements/query_builder.hwk +1 -0
- package/view/form/elements/query_builder_entry.hwk +33 -0
- package/view/form/elements/query_builder_group.hwk +64 -0
- package/view/form/elements/query_builder_value.hwk +10 -0
- package/view/form/elements/query_builder_variable.hwk +6 -0
- package/view/form/inputs/edit/belongs_to.hwk +1 -1
- package/view/form/inputs/edit/html.hwk +5 -0
- package/view/form/inputs/edit/query_builder.hwk +5 -0
- package/view/form/inputs/edit/query_builder_assignment.hwk +6 -0
- package/view/form/inputs/edit/query_builder_value.hwk +11 -0
- package/view/form/inputs/edit/query_builder_variable.hwk +10 -0
- package/view/form/inputs/view/string.hwk +1 -0
- package/view/form/inputs/view_inline/string.hwk +1 -0
- package/view/form/select/qb_item.hwk +7 -0
- package/view/form/wrappers/view_inline/default.hwk +1 -0
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The alchemy-query-builder-value custom element
|
|
3
|
+
*
|
|
4
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
5
|
+
* @since 0.1.6
|
|
6
|
+
* @version 0.1.6
|
|
7
|
+
*/
|
|
8
|
+
const QueryBuilderValue = Function.inherits('Alchemy.Element.Form.QueryBuilderData', 'QueryBuilderValue');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The template to use for the content of this element
|
|
12
|
+
*
|
|
13
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
14
|
+
* @since 0.1.6
|
|
15
|
+
* @version 0.1.6
|
|
16
|
+
*/
|
|
17
|
+
QueryBuilderValue.setTemplateFile('form/elements/query_builder_value');
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Does this use a single source type?
|
|
21
|
+
* (Set automatically, based on source-types attribute)
|
|
22
|
+
*
|
|
23
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
24
|
+
* @since 0.1.6
|
|
25
|
+
* @version 0.1.6
|
|
26
|
+
*/
|
|
27
|
+
QueryBuilderValue.setAttribute('single-source-type');
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Does this use a single variable type?
|
|
31
|
+
* (Set automatically, based on variable-types attribute)
|
|
32
|
+
*
|
|
33
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
34
|
+
* @since 0.1.6
|
|
35
|
+
* @version 0.1.6
|
|
36
|
+
*/
|
|
37
|
+
QueryBuilderValue.setAttribute('single-variable-type');
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* A filter of variable definition types
|
|
41
|
+
* (number, string, ...)
|
|
42
|
+
*
|
|
43
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
44
|
+
* @since 0.1.6
|
|
45
|
+
* @version 0.1.6
|
|
46
|
+
*/
|
|
47
|
+
QueryBuilderValue.setAttribute('variable-types');
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* A filter of source types
|
|
51
|
+
* (variable, value)
|
|
52
|
+
*
|
|
53
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
54
|
+
* @since 0.1.6
|
|
55
|
+
* @version 0.1.6
|
|
56
|
+
*/
|
|
57
|
+
QueryBuilderValue.setAttribute('source-types');
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Getter for the source type selector
|
|
61
|
+
* (variable, value)
|
|
62
|
+
*
|
|
63
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
64
|
+
* @since 0.1.6
|
|
65
|
+
* @version 0.1.6
|
|
66
|
+
*/
|
|
67
|
+
QueryBuilderValue.addElementGetter('source_type_select', '.qb-source-type');
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Getter for the value input wrapper
|
|
71
|
+
*
|
|
72
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
73
|
+
* @since 0.1.6
|
|
74
|
+
* @version 0.1.6
|
|
75
|
+
*/
|
|
76
|
+
QueryBuilderValue.addElementGetter('value_input_wrapper', '.qb-value-input-wrapper');
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Get/set the value
|
|
80
|
+
*
|
|
81
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
82
|
+
* @since 0.1.6
|
|
83
|
+
* @version 0.1.6
|
|
84
|
+
*/
|
|
85
|
+
QueryBuilderValue.setProperty(function value() {
|
|
86
|
+
|
|
87
|
+
if (!this.source_type_select.value) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
let result = {
|
|
92
|
+
type : 'qb_value',
|
|
93
|
+
source_type : this.source_type_select.value,
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
if (result.source_type == 'variable') {
|
|
97
|
+
let select = this.value_input_wrapper.querySelector('.qb-value-variable');
|
|
98
|
+
|
|
99
|
+
if (select) {
|
|
100
|
+
result.value_variable = select.value;
|
|
101
|
+
}
|
|
102
|
+
} else if (result.source_type == 'value') {
|
|
103
|
+
let input = this.value_input_wrapper.querySelector('.qb-value-input');
|
|
104
|
+
|
|
105
|
+
if (input) {
|
|
106
|
+
|
|
107
|
+
let value_explicit = {
|
|
108
|
+
type : this.getValueType(input),
|
|
109
|
+
value : null,
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (value_explicit.type == 'number' && typeof input.valueAsNumber != 'undefined') {
|
|
113
|
+
value_explicit.value = input.valueAsNumber;
|
|
114
|
+
} else {
|
|
115
|
+
value_explicit.value = input.value;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
result.value_explicit = value_explicit;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return result;
|
|
123
|
+
}, function setValue(value) {
|
|
124
|
+
this.assigned_data.value = value;
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Load value type data
|
|
129
|
+
*
|
|
130
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
131
|
+
* @since 0.1.6
|
|
132
|
+
* @version 0.1.6
|
|
133
|
+
*/
|
|
134
|
+
QueryBuilderValue.setMethod(async function loadSourceTypeData(config) {
|
|
135
|
+
|
|
136
|
+
let items = [];
|
|
137
|
+
|
|
138
|
+
items.push({id: 'variable', title: 'Variable'});
|
|
139
|
+
items.push({id: 'value', title: 'Value'});
|
|
140
|
+
|
|
141
|
+
return items;
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Show the correct value input
|
|
146
|
+
*
|
|
147
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
148
|
+
* @since 0.1.6
|
|
149
|
+
* @version 0.1.6
|
|
150
|
+
*/
|
|
151
|
+
QueryBuilderValue.setMethod(async function showValueInput() {
|
|
152
|
+
|
|
153
|
+
let variable_type = this.single_variable_type;
|
|
154
|
+
|
|
155
|
+
if (!variable_type) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
let constructor = Blast.Classes.Alchemy.QueryBuilder.VariableDefinition.VariableDefinition.getMember(variable_type);
|
|
160
|
+
|
|
161
|
+
if (!constructor) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
let instance = new constructor();
|
|
166
|
+
|
|
167
|
+
let element = instance.createValueInput(this.hawkejs_renderer);
|
|
168
|
+
|
|
169
|
+
element.classList.add('qb-value-input');
|
|
170
|
+
|
|
171
|
+
this.value_input_wrapper.append(element);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Apply source type changes
|
|
177
|
+
*
|
|
178
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
179
|
+
* @since 0.1.6
|
|
180
|
+
* @version 0.1.6
|
|
181
|
+
*/
|
|
182
|
+
QueryBuilderValue.setMethod(async function applySourceTypeChanges() {
|
|
183
|
+
|
|
184
|
+
Hawkejs.removeChildren(this.value_input_wrapper);
|
|
185
|
+
|
|
186
|
+
let type = this.source_type_select.value;
|
|
187
|
+
|
|
188
|
+
if (type == 'variable') {
|
|
189
|
+
let select = this.createElement('alchemy-select');
|
|
190
|
+
select.dataprovider = this;
|
|
191
|
+
select.classList.add('qb-value-variable');
|
|
192
|
+
this.value_input_wrapper.append(select);
|
|
193
|
+
} else if (type == 'value') {
|
|
194
|
+
await this.showValueInput();
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Apply the given value
|
|
200
|
+
*
|
|
201
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
202
|
+
* @since 0.1.6
|
|
203
|
+
* @version 0.1.6
|
|
204
|
+
*/
|
|
205
|
+
QueryBuilderValue.setMethod(async function applyValue(value) {
|
|
206
|
+
|
|
207
|
+
if (!value) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
this.source_type_select.value = value.source_type;
|
|
212
|
+
|
|
213
|
+
await this.applySourceTypeChanges();
|
|
214
|
+
|
|
215
|
+
if (value.source_type == 'variable') {
|
|
216
|
+
let select = this.value_input_wrapper.querySelector('.qb-value-variable');
|
|
217
|
+
|
|
218
|
+
if (select) {
|
|
219
|
+
select.value = value.value_variable;
|
|
220
|
+
}
|
|
221
|
+
} else if (value.source_type == 'value') {
|
|
222
|
+
let input = this.value_input_wrapper.querySelector('.qb-value-input');
|
|
223
|
+
|
|
224
|
+
if (input && value.value_explicit) {
|
|
225
|
+
input.value = value.value_explicit.value;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Set the source type selector visibility
|
|
232
|
+
* (It should be hidden if there is only 1 possible value)
|
|
233
|
+
*
|
|
234
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
235
|
+
* @since 0.1.6
|
|
236
|
+
* @version 0.1.6
|
|
237
|
+
*/
|
|
238
|
+
QueryBuilderValue.setMethod(function checkTypeConfig() {
|
|
239
|
+
|
|
240
|
+
// Don't hide the source type select by default
|
|
241
|
+
let single_source_type,
|
|
242
|
+
hide_source_type = false;
|
|
243
|
+
|
|
244
|
+
// Check the variable types first
|
|
245
|
+
let variable_types = this.variable_types,
|
|
246
|
+
single_variable_type;
|
|
247
|
+
|
|
248
|
+
if (variable_types) {
|
|
249
|
+
let pieces = variable_types.split(',');
|
|
250
|
+
|
|
251
|
+
if (pieces && pieces.length == 1) {
|
|
252
|
+
single_variable_type = pieces[0];
|
|
253
|
+
} else {
|
|
254
|
+
// There are NO or MULTIPLE variable types, so we can't use the "value" source type
|
|
255
|
+
single_source_type = 'variable';
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
if (single_variable_type) {
|
|
260
|
+
this.single_variable_type = single_variable_type;
|
|
261
|
+
} else {
|
|
262
|
+
this.removeAttribute('single-variable-type');
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// If we don't have to hide the source type yet
|
|
266
|
+
if (!single_source_type) {
|
|
267
|
+
let source_types = this.source_types;
|
|
268
|
+
|
|
269
|
+
if (source_types) {
|
|
270
|
+
let pieces = source_types.split(',');
|
|
271
|
+
|
|
272
|
+
if (pieces && pieces.length == 1) {
|
|
273
|
+
single_source_type = pieces[0];
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// If we have a single source type, apply it now
|
|
279
|
+
if (single_source_type) {
|
|
280
|
+
if (this.source_type_select.value != single_source_type) {
|
|
281
|
+
this.source_type_select.value = single_source_type;
|
|
282
|
+
this.applySourceTypeChanges();
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
hide_source_type = true;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
this.source_type_select.hidden = hide_source_type;
|
|
289
|
+
|
|
290
|
+
if (single_source_type) {
|
|
291
|
+
this.single_source_type = single_source_type;
|
|
292
|
+
} else {
|
|
293
|
+
this.removeAttribute('single-source-type');
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Added to the dom
|
|
299
|
+
*
|
|
300
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
301
|
+
* @since 0.1.6
|
|
302
|
+
* @version 0.1.6
|
|
303
|
+
*/
|
|
304
|
+
QueryBuilderValue.setMethod(async function introduced() {
|
|
305
|
+
|
|
306
|
+
this.source_type_select.addEventListener('change', e => {
|
|
307
|
+
e.preventDefault();
|
|
308
|
+
this.applySourceTypeChanges();
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
this.checkTypeConfig();
|
|
312
|
+
|
|
313
|
+
if (this.assigned_data.value) {
|
|
314
|
+
await this.applyValue(this.assigned_data.value);
|
|
315
|
+
}
|
|
316
|
+
});
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The alchemy-query-builder-value custom element
|
|
3
|
+
*
|
|
4
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
5
|
+
* @since 0.1.7
|
|
6
|
+
* @version 0.1.7
|
|
7
|
+
*/
|
|
8
|
+
const QueryBuilderVariable = Function.inherits('Alchemy.Element.Form.QueryBuilderData', 'QueryBuilderVariable');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The template to use for the content of this element
|
|
12
|
+
*
|
|
13
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
14
|
+
* @since 0.1.7
|
|
15
|
+
* @version 0.1.7
|
|
16
|
+
*/
|
|
17
|
+
QueryBuilderVariable.setTemplateFile('form/elements/query_builder_variable');
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A filter of variable definition types
|
|
21
|
+
* (number, string, ...)
|
|
22
|
+
*
|
|
23
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
24
|
+
* @since 0.1.7
|
|
25
|
+
* @version 0.1.7
|
|
26
|
+
*/
|
|
27
|
+
QueryBuilderVariable.setAttribute('variable-types');
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Getter for the value input wrapper
|
|
31
|
+
*
|
|
32
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
33
|
+
* @since 0.1.7
|
|
34
|
+
* @version 0.1.7
|
|
35
|
+
*/
|
|
36
|
+
QueryBuilderVariable.addElementGetter('variable_select', '.qb-variable');
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Get/set the value
|
|
40
|
+
*
|
|
41
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
42
|
+
* @since 0.1.7
|
|
43
|
+
* @version 0.1.7
|
|
44
|
+
*/
|
|
45
|
+
QueryBuilderVariable.setProperty(function value() {
|
|
46
|
+
|
|
47
|
+
let result = {
|
|
48
|
+
type : 'qb_variable',
|
|
49
|
+
variable_type : null,
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
let select = this.variable_select;
|
|
53
|
+
|
|
54
|
+
if (select) {
|
|
55
|
+
result.variable = select.value;
|
|
56
|
+
|
|
57
|
+
if (select.values) {
|
|
58
|
+
let value_def = select.values[result.variable];
|
|
59
|
+
|
|
60
|
+
if (value_def) {
|
|
61
|
+
result.variable_type = value_def.type_name;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return result;
|
|
67
|
+
}, function setValue(value) {
|
|
68
|
+
this.assigned_data.value = value;
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Apply the given value
|
|
73
|
+
*
|
|
74
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
75
|
+
* @since 0.1.7
|
|
76
|
+
* @version 0.1.7
|
|
77
|
+
*/
|
|
78
|
+
QueryBuilderVariable.setMethod(async function applyValue(value) {
|
|
79
|
+
|
|
80
|
+
if (!value) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
let select = this.variable_select;
|
|
85
|
+
|
|
86
|
+
if (select) {
|
|
87
|
+
select.value = value.variable;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Added to the dom
|
|
93
|
+
*
|
|
94
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
95
|
+
* @since 0.1.7
|
|
96
|
+
* @version 0.1.7
|
|
97
|
+
*/
|
|
98
|
+
QueryBuilderVariable.setMethod(async function introduced() {
|
|
99
|
+
|
|
100
|
+
if (this.assigned_data.value) {
|
|
101
|
+
await this.applyValue(this.assigned_data.value);
|
|
102
|
+
}
|
|
103
|
+
});
|