in dashboardv3/public/js/views/search/QueryBuilderView.js [386:576]
onRender: function() {
var that = this,
filters = [],
isGroupView = true,
placeHolder = '--Select Attribute--';
var rules_widgets = null;
if (this.adminAttrFilters) {
var entityDef = this.entityDefCollection.fullCollection.find({ name: "__AtlasAuditEntry" }),
auditEntryAttributeDefs = null;
if (entityDef) {
auditEntryAttributeDefs = $.extend(true, {}, entityDef.get("attributeDefs")) || null;
}
if (auditEntryAttributeDefs) {
_.each(auditEntryAttributeDefs, function(attributes) {
var returnObj = that.getObjDef(attributes, rules_widgets);
if (returnObj) {
filters.push(returnObj);
}
});
}
rules_widgets = CommonViewFunction.attributeFilter.extractUrl({ "value": this.searchTableFilters ? this.searchTableFilters["adminAttrFilters"] : null, "formatDate": true });;
} else {
if (this.value) {
rules_widgets = CommonViewFunction.attributeFilter.extractUrl({ "value": this.searchTableFilters[this.filterType][(this.tag ? this.value.tag : this.value.type) || this.value.relationshipName], "formatDate": true });
}
_.each(this.attrObj, function(obj) {
var type = that.tag ? that.value.tag : that.value.type;
if (that.value.relationshipName) {
type = that.value.relationshipName;
}
var returnObj = that.getObjDef(obj, rules_widgets, isGroupView, (type + ' Attribute'));
if (returnObj) {
filters.push(returnObj);
}
});
var sortMap = {
"__guid": 1,
"__typeName": 2,
"__timestamp": 3,
"__modificationTimestamp": 4,
"__createdBy": 5,
"__modifiedBy": 6,
"__isIncomplete": 7,
"__classificationNames": 9,
"__propagatedClassificationNames": 10,
"__labels": 11,
"__customAttributes": 12,
}
if (that.type) {
sortMap["__state"] = 8;
} else {
sortMap["__entityStatus"] = 8;
}
this.systemAttrArr = _.sortBy(this.systemAttrArr, function(obj) {
return sortMap[obj.name]
})
_.each(this.systemAttrArr, function(obj) {
var returnObj = that.getObjDef(obj, rules_widgets, isGroupView, 'System Attribute', true);
if (returnObj) {
filters.push(returnObj);
}
});
if (this.type) {
var pushBusinessMetadataFilter = function(sortedAttributes, businessMetadataKey) {
_.each(sortedAttributes, function(attrDetails) {
var returnObj = that.getObjDef(attrDetails, rules_widgets, isGroupView, "Business Attributes: " + businessMetadataKey);
if (returnObj) {
returnObj.id = businessMetadataKey + "." + returnObj.id;
returnObj.label = returnObj.label;
returnObj.data = { 'entityType': "businessMetadata" };
filters.push(returnObj);
}
});
};
if (this.value.type == "_ALL_ENTITY_TYPES") {
this.businessMetadataDefCollection.each(function(model) {
var sortedAttributes = model.get('attributeDefs');
sortedAttributes = _.sortBy(sortedAttributes, function(obj) {
return obj.name;
});
pushBusinessMetadataFilter(sortedAttributes, model.get('name'));
})
} else {
var entityDef = this.entityDefCollection.fullCollection.find({ name: this.value.type }),
businessMetadataAttributeDefs = null;
if (entityDef) {
businessMetadataAttributeDefs = entityDef.get("businessAttributeDefs");
}
if (businessMetadataAttributeDefs) {
_.each(businessMetadataAttributeDefs, function(attributes, key) {
var sortedAttributes = _.sortBy(attributes, function(obj) {
return obj.name;
});
pushBusinessMetadataFilter(sortedAttributes, key);
});
}
}
}
}
filters = _.uniq(filters, 'id');
if (filters && !_.isEmpty(filters)) {
this.ui.builder.off()
.on("afterUpdateRuleOperator.queryBuilder", function(e, rule) {
that.setDateValue(rule, rules_widgets);
})
.queryBuilder({
plugins: ['bt-tooltip-errors'],
filters: filters,
select_placeholder: placeHolder,
allow_empty: true,
conditions: ['AND', 'OR'],
allow_groups: true,
allow_empty: true,
templates: {
rule: '<div id="{{= it.rule_id }}" class="rule-container"> \
<div class="values-box"><div class="rule-filter-container"></div> \
<div class="rule-operator-container"></div> \
<div class="rule-value-container"></div></div> \
<div class="action-box"><div class="rule-header"> \
<div class="btn-group rule-actions"> \
<button type="button" class="btn btn-xs btn-danger" data-delete="rule"> \
<i class="{{= it.icons.remove_rule }}"></i> \
</button> \
</div> \
</div> </div>\
{{? it.settings.display_errors }} \
<div class="error-container"><i class="{{= it.icons.error }}"></i> <span></span></div> \
{{?}} \
</div>'
},
operators: [
{ type: '=', nb_inputs: 1, multiple: false, apply_to: ['number', 'string', 'boolean', 'enum'] },
{ type: '!=', nb_inputs: 1, multiple: false, apply_to: ['number', 'string', 'boolean', 'enum'] },
{ type: '>', nb_inputs: 1, multiple: false, apply_to: ['number', 'string', 'boolean'] },
{ type: '<', nb_inputs: 1, multiple: false, apply_to: ['number', 'string', 'boolean'] },
{ type: '>=', nb_inputs: 1, multiple: false, apply_to: ['number', 'string', 'boolean'] },
{ type: '<=', nb_inputs: 1, multiple: false, apply_to: ['number', 'string', 'boolean'] },
{ type: 'contains', nb_inputs: 1, multiple: false, apply_to: ['string'] },
{ type: 'like', nb_inputs: 1, multiple: false, apply_to: ['string'] },
{ type: 'in', nb_inputs: 1, multiple: false, apply_to: ['string'] },
{ type: 'begins_with', nb_inputs: 1, multiple: false, apply_to: ['string'] },
{ type: 'ends_with', nb_inputs: 1, multiple: false, apply_to: ['string'] },
{ type: 'is_null', nb_inputs: false, multiple: false, apply_to: ['number', 'string', 'boolean', 'enum'] },
{ type: 'not_null', nb_inputs: false, multiple: false, apply_to: ['number', 'string', 'boolean', 'enum'] },
{ type: 'TIME_RANGE', nb_inputs: 1, multiple: false, apply_to: ['date'] }
],
lang: {
add_rule: 'Add filter',
add_group: 'Add filter group',
operators: {
not_null: 'is not null',
TIME_RANGE: "Time Range"
}
},
icons: {
add_rule: 'fa fa-plus',
remove_rule: 'fa fa-times',
error: 'fa fa-exclamation-triangle'
},
rules: rules_widgets
})
.on("afterCreateRuleInput.queryBuilder", function(e, rule) {
rule.error = null;
if (rule.operator.nb_inputs && rule.filter.id === "__customAttributes") {
rule.$el.addClass("user-define");
} else if (rule.$el.hasClass("user-define")) {
rule.$el.removeClass("user-define");
}
if (rule.filter.type === "date") {
rule.$el.find('.rule-value-container >input').attr('readonly', true);
}
that.setDateValue(rule, rules_widgets);
})
.on('validationError.queryBuilder', function(e, rule, error, value) {
// never display error for my custom filter
var errorMsg = error[0];
if (that.queryBuilderLang && that.queryBuilderLang.errors && that.queryBuilderLang.errors[errorMsg]) {
errorMsg = that.queryBuilderLang.errors[errorMsg];
}
rule.$el.find(".error-container span").html(errorMsg);
});
var queryBuilderEl = that.ui.builder.data("queryBuilder");
if (queryBuilderEl && queryBuilderEl.lang) {
this.queryBuilderLang = queryBuilderEl.lang;
}
this.$('.rules-group-header .btn-group.pull-right.group-actions').toggleClass('pull-left');
} else {
this.ui.builder.html('<h4>No Attributes are available !</h4>')
}
}