From 98a1b268c9d318d75a949f1f943b96d48d894c67 Mon Sep 17 00:00:00 2001
From: bnayal Output
+
+
@@ -143,6 +146,8 @@ Output
+
+
@@ -175,7 +180,8 @@ Output
'unique-filter': null,
'bt-checkbox': { color: 'primary' },
'invert': null,
- 'not-group': null
+ 'not-group': null,
+ 'readable-json': null
},
// standard operators in custom optgroups
@@ -199,10 +205,17 @@ Output
{ type: 'is_empty' },
{ type: 'is_not_empty' },
{ type: 'is_null' },
- { type: 'is_not_null' }
+ { type: 'is_not_null' },
+ { type: 'in_last_x_days' },
+ { type: 'not_in_last_x_days' }
],
filters: [
+ {
+ id: 'lastOrderDate',
+ label: 'Last order date',
+ type: 'datetime'
+ },
/*
* string with separator
*/
diff --git a/src/defaults.js b/src/defaults.js
index 84a888c3..942697cb 100644
--- a/src/defaults.js
+++ b/src/defaults.js
@@ -94,8 +94,8 @@ QueryBuilder.regional = {};
QueryBuilder.OPERATORS = {
equal: { type: 'equal', nb_inputs: 1, multiple: false, apply_to: ['string', 'number', 'datetime', 'boolean'] },
not_equal: { type: 'not_equal', nb_inputs: 1, multiple: false, apply_to: ['string', 'number', 'datetime', 'boolean'] },
- in: { type: 'in', nb_inputs: 1, multiple: true, apply_to: ['string', 'number', 'datetime'] },
- not_in: { type: 'not_in', nb_inputs: 1, multiple: true, apply_to: ['string', 'number', 'datetime'] },
+ in: { type: 'in', nb_inputs: 1, multiple: true, apply_to: ['string'] },
+ not_in: { type: 'not_in', nb_inputs: 1, multiple: true, apply_to: ['string'] },
less: { type: 'less', nb_inputs: 1, multiple: false, apply_to: ['number', 'datetime'] },
less_or_equal: { type: 'less_or_equal', nb_inputs: 1, multiple: false, apply_to: ['number', 'datetime'] },
greater: { type: 'greater', nb_inputs: 1, multiple: false, apply_to: ['number', 'datetime'] },
@@ -111,7 +111,9 @@ QueryBuilder.OPERATORS = {
is_empty: { type: 'is_empty', nb_inputs: 0, multiple: false, apply_to: ['string'] },
is_not_empty: { type: 'is_not_empty', nb_inputs: 0, multiple: false, apply_to: ['string'] },
is_null: { type: 'is_null', nb_inputs: 0, multiple: false, apply_to: ['string', 'number', 'datetime', 'boolean'] },
- is_not_null: { type: 'is_not_null', nb_inputs: 0, multiple: false, apply_to: ['string', 'number', 'datetime', 'boolean'] }
+ is_not_null: { type: 'is_not_null', nb_inputs: 0, multiple: false, apply_to: ['string', 'number', 'datetime', 'boolean'] },
+ in_last_x_days: {type: 'in_last_x_days', nb_inputs: 1, multiple: false, apply_to: ['datetime'], input_type: 'integer'},
+ not_in_last_x_days: {type: 'not_in_last_x_days', nb_inputs: 1, multiple: false, apply_to: ['datetime'], input_type: 'integer'}
};
/**
@@ -162,8 +164,6 @@ QueryBuilder.DEFAULTS = {
operators: [
'equal',
'not_equal',
- 'in',
- 'not_in',
'less',
'less_or_equal',
'greater',
@@ -178,8 +178,10 @@ QueryBuilder.DEFAULTS = {
'not_ends_with',
'is_empty',
'is_not_empty',
- 'is_null',
- 'is_not_null'
+ 'in_last_x_days',
+ 'not_in_last_x_days',
+ 'in',
+ 'not_in'
],
icons: {
diff --git a/src/i18n/en.json b/src/i18n/en.json
index b5828139..aa5679b5 100644
--- a/src/i18n/en.json
+++ b/src/i18n/en.json
@@ -32,7 +32,9 @@
"is_empty": "is empty",
"is_not_empty": "is not empty",
"is_null": "is null",
- "is_not_null": "is not null"
+ "is_not_null": "is not null",
+ "in_last_x_days": "is within the last x days",
+ "not_in_last_x_days": "is not within the last x days"
},
"errors": {
@@ -58,4 +60,4 @@
"boolean_not_valid": "Not a boolean",
"operator_not_multiple": "Operator {0} cannot accept multiple values"
}
-}
\ No newline at end of file
+}
diff --git a/src/model.js b/src/model.js
index b5b38e3c..2b8ca8ba 100644
--- a/src/model.js
+++ b/src/model.js
@@ -556,6 +556,14 @@ var Rule = function(parent, $el) {
* @instance
*/
this.__.value = undefined;
+
+ /**
+ * @name input_type
+ * @member {*}
+ * @memberof Rule
+ * @instance
+ */
+ this.__.input_type = null;
};
Rule.prototype = Object.create(Node.prototype);
diff --git a/src/plugins/rm-datepicker/plugin.js b/src/plugins/rm-datepicker/plugin.js
new file mode 100644
index 00000000..165d93f4
--- /dev/null
+++ b/src/plugins/rm-datepicker/plugin.js
@@ -0,0 +1,54 @@
+/**
+ * @module BtSelectpickerPlugin
+ * @descriptioon Applies Bootstrap Select on filters and operators combo-boxes.
+ */
+
+/**
+ * @function init
+ * @memberof module:BtSelectpickerPlugin
+ * @param {object} [options]
+ * @throws MissingLibraryError
+ */
+QueryBuilder.define('rm-datepicker', function(options) {
+ var Selectors = QueryBuilder.selectors;
+ if (!$.fn.datetimepicker || !$.fn.datetimepicker.constructor) {
+ Utils.error('MissingLibrary', 'datetimepicker is required to use "rm-datepicker" plugin.');
+ }
+
+ function onChange(rule, date){
+ rule.value = date.format('YYYY-MM-DD');
+ }
+
+ this.on('afterCreateRuleInput', function(e, rule) {
+ if(rule.filter.type == "date" || rule.filter.type == "datetime") {
+ if(!rule.operator.input_type || rule.operator.input_type !== "integer"){
+ var $inputs = rule.$el.find(Selectors.value_container).find('input');
+ $inputs.datetimepicker(options);
+ $inputs.on('dp.change', function(e){
+ onChange(rule, e.date);
+ });
+ }
+ }
+ });
+
+ this.on('afterUpdateRuleOperator', function(e, rule) {
+ if(rule.filter.type == "date" || rule.filter.type == "datetime") {
+ var $inputs = rule.$el.find(Selectors.value_container).find('input');
+ if(!rule.operator.input_type || rule.operator.input_type !== "integer"){
+ $inputs.datetimepicker(options);
+ $inputs.off('dp.change').on('dp.change', function(e){
+ onChange(rule, e.date);
+ });
+ } else {
+
+ $inputs.each(function(){
+ if($(this).data("DateTimePicker") && typeof $(this).data("DateTimePicker").destroy == "function"){
+ $(this).data("DateTimePicker").destroy();
+ $(this).val('');
+ };
+ });
+ }
+ }
+ });
+
+}, {format: "YYYY-MM-DD"});
From b4334c15f6ea63c01ec88b0da4bd62dacfea6b35 Mon Sep 17 00:00:00 2001
From: bnayal Output
'bt-checkbox': { color: 'primary' },
'invert': null,
'not-group': null,
- 'readable-json': null
+ 'readable-json': null,
+ 'rm-datepicker': null
},
// standard operators in custom optgroups