Commit 6d8c50cc by kevalbhatt Committed by Madhan Neethiraj

ATLAS-2018: UI: Attribute filter does not preserve state

Signed-off-by: 's avatarMadhan Neethiraj <madhan@apache.org> (cherry picked from commit db317a4708fe1f6c87a1f7674f4fb3bbf70bebb1)
parent 86fb9da4
...@@ -54,7 +54,11 @@ define([ ...@@ -54,7 +54,11 @@ define([
'classificationDefCollection': this.classificationDefCollection 'classificationDefCollection': this.classificationDefCollection
} }
this.sharedObj = { this.sharedObj = {
searchTableColumns: {} searchTableColumns: {},
searchTableFilters: {
tagFilters: {},
entityFilters: {}
}
} }
}, },
bindCommonEvents: function() { bindCommonEvents: function() {
......
...@@ -408,7 +408,11 @@ define(['require', 'utils/Utils', 'modules/Modal', 'utils/Messages', 'utils/Enum ...@@ -408,7 +408,11 @@ define(['require', 'utils/Utils', 'modules/Modal', 'utils/Messages', 'utils/Enum
_.each(attrObj, function(obj) { _.each(attrObj, function(obj) {
attrQuery.push(obj.id + "::" + obj.operator + "::" + obj.value + "::" + obj.type); attrQuery.push(obj.id + "::" + obj.operator + "::" + obj.value + "::" + obj.type);
}); });
return attrQuery.join(); if (attrQuery.length) {
return attrQuery.join();
} else {
return null;
}
} else { } else {
return null; return null;
} }
......
...@@ -83,7 +83,7 @@ define(['require', ...@@ -83,7 +83,7 @@ define(['require',
return events; return events;
}, },
initialize: function(options) { initialize: function(options) {
_.extend(this, _.pick(options, 'url', 'value', 'tag', 'selectFirst', 'classificationDefCollection', 'typeHeaders', 'searchVent', 'entityDefCollection', 'enumDefCollection', 'searchTableColumns')); _.extend(this, _.pick(options, 'url', 'value', 'tag', 'selectFirst', 'classificationDefCollection', 'typeHeaders', 'searchVent', 'entityDefCollection', 'enumDefCollection', 'searchTableColumns', 'searchTableFilters'));
if (Globals.taxonomy) { if (Globals.taxonomy) {
this.tabClass = "tab col-sm-4"; this.tabClass = "tab col-sm-4";
} else { } else {
...@@ -128,7 +128,8 @@ define(['require', ...@@ -128,7 +128,8 @@ define(['require',
entityDefCollection: that.entityDefCollection, entityDefCollection: that.entityDefCollection,
enumDefCollection: that.enumDefCollection, enumDefCollection: that.enumDefCollection,
classificationDefCollection: that.classificationDefCollection, classificationDefCollection: that.classificationDefCollection,
searchTableColumns: that.searchTableColumns searchTableColumns: that.searchTableColumns,
searchTableFilters: that.searchTableFilters
})); }));
}); });
}, },
......
...@@ -52,7 +52,7 @@ define(['require', ...@@ -52,7 +52,7 @@ define(['require',
* @constructs * @constructs
*/ */
initialize: function(options) { initialize: function(options) {
_.extend(this, _.pick(options, 'attrObj', 'value', 'typeHeaders', 'entityDefCollection', 'enumDefCollection', 'tag')); _.extend(this, _.pick(options, 'attrObj', 'value', 'typeHeaders', 'entityDefCollection', 'enumDefCollection', 'tag', 'searchTableFilters'));
this.attrObj = _.sortBy(this.attrObj, 'name'); this.attrObj = _.sortBy(this.attrObj, 'name');
this.filterType = this.tag ? 'tagFilters' : 'entityFilters'; this.filterType = this.tag ? 'tagFilters' : 'entityFilters';
}, },
...@@ -134,7 +134,7 @@ define(['require', ...@@ -134,7 +134,7 @@ define(['require',
var that = this, var that = this,
filters = []; filters = [];
if (this.value) { if (this.value) {
var rules_widgets = CommonViewFunction.attributeFilter.extractUrl(this.value[this.filterType]); var rules_widgets = CommonViewFunction.attributeFilter.extractUrl(this.searchTableFilters[this.filterType][(this.tag ? this.value.tag : this.value.type)]);
} }
_.each(this.attrObj, function(obj) { _.each(this.attrObj, function(obj) {
var returnObj = that.getObjDef(obj, rules_widgets); var returnObj = that.getObjDef(obj, rules_widgets);
......
...@@ -81,7 +81,7 @@ define(['require', ...@@ -81,7 +81,7 @@ define(['require',
* @constructs * @constructs
*/ */
initialize: function(options) { initialize: function(options) {
_.extend(this, _.pick(options, 'value', 'typeHeaders', 'searchVent', 'entityDefCollection', 'enumDefCollection', 'classificationDefCollection', 'searchTableColumns')); _.extend(this, _.pick(options, 'value', 'typeHeaders', 'searchVent', 'entityDefCollection', 'enumDefCollection', 'classificationDefCollection', 'searchTableColumns', 'searchTableFilters'));
this.type = "basic"; this.type = "basic";
var param = Utils.getUrlState.getQueryParams(); var param = Utils.getUrlState.getQueryParams();
this.query = { this.query = {
...@@ -92,8 +92,6 @@ define(['require', ...@@ -92,8 +92,6 @@ define(['require',
basic: { basic: {
query: null, query: null,
type: null, type: null,
typeFilter: null,
tagFilter: null,
tag: null, tag: null,
attributes: null attributes: null
} }
...@@ -133,51 +131,39 @@ define(['require', ...@@ -133,51 +131,39 @@ define(['require',
filtertype = [filtertypeParam]; filtertype = [filtertypeParam];
} }
} }
var typeCheck = function(filterQueryObj, type) { var typeCheck = function(filterObj, type) {
var filterObj = filterQueryObj[type];
if (that.value.type) { if (that.value.type) {
if (filterObj && filterObj.length) { if (filterObj && filterObj.length) {
that.ui.typeAttrFilter.addClass('active'); that.ui.typeAttrFilter.addClass('active');
} else { } else {
filterQueryObj[type] = null;
that.value[type] = null;
that.ui.typeAttrFilter.removeClass('active'); that.ui.typeAttrFilter.removeClass('active');
} }
that.ui.typeAttrFilter.prop('disabled', false); that.ui.typeAttrFilter.prop('disabled', false);
} else { } else {
filterQueryObj[type] = null;
that.value[type] = null;
that.ui.typeAttrFilter.removeClass('active'); that.ui.typeAttrFilter.removeClass('active');
that.ui.typeAttrFilter.prop('disabled', true); that.ui.typeAttrFilter.prop('disabled', true);
} }
} }
var tagCheck = function(filterQueryObj, type) { var tagCheck = function(filterObj, type) {
var filterObj = filterQueryObj[type];
if (that.value.tag) { if (that.value.tag) {
that.ui.tagAttrFilter.prop('disabled', false); that.ui.tagAttrFilter.prop('disabled', false);
if (filterObj && filterObj.length) { if (filterObj && filterObj.length) {
that.ui.tagAttrFilter.addClass('active'); that.ui.tagAttrFilter.addClass('active');
} else { } else {
filterQueryObj[type] = null;
that.value[type] = null;
that.ui.tagAttrFilter.removeClass('active'); that.ui.tagAttrFilter.removeClass('active');
} }
} else { } else {
filterQueryObj[type] = null;
that.value[type] = null;
that.ui.tagAttrFilter.removeClass('active'); that.ui.tagAttrFilter.removeClass('active');
that.ui.tagAttrFilter.prop('disabled', true); that.ui.tagAttrFilter.prop('disabled', true);
} }
} }
_.each(filtertype, function(type) { _.each(filtertype, function(type) {
var filterObj = that.query[that.type][type], var filterObj = that.searchTableFilters[type];
filterQueryObj = that.query[that.type];
if (type == "entityFilters") { if (type == "entityFilters") {
typeCheck(filterQueryObj, type) typeCheck(filterObj[that.value.type], type);
} }
if (type == "tagFilters") { if (type == "tagFilters") {
tagCheck(filterQueryObj, type) tagCheck(filterObj[that.value.tag], type);
} }
}); });
}, },
...@@ -191,14 +177,19 @@ define(['require', ...@@ -191,14 +177,19 @@ define(['require',
filterType = (isTagEl ? 'tagFilters' : 'entityFilters'), filterType = (isTagEl ? 'tagFilters' : 'entityFilters'),
value = value.length ? value : null; value = value.length ? value : null;
if (this.value) { if (this.value) {
if (this.value[key] !== value || (!value && !this.value[key]) || (!this.value[filterType])) { //On Change handle
if (this.value[key] !== value || (!value && !this.value[key])) {
var temp = {}; var temp = {};
temp[key] = value; temp[key] = value;
_.extend(this.value, temp); _.extend(this.value, temp);
this.query[this.type][filterType] = null; } else {
this.value[filterType] = null; // Initial loading handle.
this.makeFilterButtonActive(filterType); var filterObj = this.searchTableFilters[filterType];
if (filterObj && this.value[key]) {
this.searchTableFilters[filterType][this.value[key]] = this.value[filterType] ? this.value[filterType] : null;
}
} }
this.makeFilterButtonActive(filterType);
} else { } else {
this.ui.tagAttrFilter.prop('disabled', true); this.ui.tagAttrFilter.prop('disabled', true);
this.ui.typeAttrFilter.prop('disabled', true); this.ui.typeAttrFilter.prop('disabled', true);
...@@ -244,8 +235,6 @@ define(['require', ...@@ -244,8 +235,6 @@ define(['require',
query: null, query: null,
type: null, type: null,
tag: null, tag: null,
entityFilters: null,
tagFilters: null,
attributes: null attributes: null
}), param); }), param);
}, },
...@@ -289,7 +278,8 @@ define(['require', ...@@ -289,7 +278,8 @@ define(['require',
typeHeaders: that.typeHeaders, typeHeaders: that.typeHeaders,
entityDefCollection: that.entityDefCollection, entityDefCollection: that.entityDefCollection,
enumDefCollection: that.enumDefCollection, enumDefCollection: that.enumDefCollection,
classificationDefCollection: that.classificationDefCollection classificationDefCollection: that.classificationDefCollection,
searchTableFilters: that.searchTableFilters
}); });
that.attrModal.on('ok', function(scope, e) { that.attrModal.on('ok', function(scope, e) {
that.okAttrFilterButton(e); that.okAttrFilterButton(e);
...@@ -297,11 +287,19 @@ define(['require', ...@@ -297,11 +287,19 @@ define(['require',
}); });
}, },
okAttrFilterButton: function(e) { okAttrFilterButton: function(e) {
var filtertype = this.attrModal.tag ? 'tagFilters' : 'entityFilters', var isTag = this.attrModal.tag ? true : false,
filtertype = isTag ? 'tagFilters' : 'entityFilters',
rule = this.attrModal.RQueryBuilder.currentView.ui.builder.queryBuilder('getRules'); rule = this.attrModal.RQueryBuilder.currentView.ui.builder.queryBuilder('getRules');
if (rule) { if (rule) {
this.query[this.type][filtertype] = CommonViewFunction.attributeFilter.generateUrl(rule.rules); var ruleUrl = CommonViewFunction.attributeFilter.generateUrl(rule.rules);
this.searchTableFilters[filtertype][(isTag ? this.value.tag : this.value.type)] = ruleUrl;
this.makeFilterButtonActive(filtertype); this.makeFilterButtonActive(filtertype);
if (this.value && this.searchTableColumns) {
if (!this.searchTableColumns[this.value.type]) {
this.searchTableColumns[this.value.type] = ["selected", "name", "owner", "description", "tag", "typeName"]
}
this.searchTableColumns[this.value.type] = _.sortBy(_.union(this.searchTableColumns[this.value.type], _.pluck(rule.rules, 'id')));
}
this.attrModal.modal.close(); this.attrModal.modal.close();
if ($(e.currentTarget).hasClass('search')) { if ($(e.currentTarget).hasClass('search')) {
this.findSearchResult(); this.findSearchResult();
...@@ -342,9 +340,9 @@ define(['require', ...@@ -342,9 +340,9 @@ define(['require',
this.value = paramObj; this.value = paramObj;
} }
if (this.value) { if (this.value) {
if (this.value.dslChecked == "true" && this.dsl == false) { if (this.value.dslChecked == "true") {
this.ui.searchType.prop("checked", true).trigger("change"); this.ui.searchType.prop("checked", true).trigger("change");
} else if (this.value.dslChecked == "false" && this.dsl == true) { } else {
this.ui.searchType.prop("checked", false).trigger("change"); this.ui.searchType.prop("checked", false).trigger("change");
} }
this.ui.typeLov.val(this.value.type); this.ui.typeLov.val(this.value.type);
...@@ -387,6 +385,14 @@ define(['require', ...@@ -387,6 +385,14 @@ define(['require',
this.query[this.type].type = this.ui.typeLov.select2('val') || null; this.query[this.type].type = this.ui.typeLov.select2('val') || null;
if (!this.dsl) { if (!this.dsl) {
this.query[this.type].tag = this.ui.tagLov.select2('val') || null; this.query[this.type].tag = this.ui.tagLov.select2('val') || null;
var entityFilterObj = this.searchTableFilters['entityFilters'],
tagFilterObj = this.searchTableFilters['tagFilters'];
if (this.value.tag) {
params['tagFilters'] = tagFilterObj[this.value.tag]
}
if (this.value.type) {
params['entityFilters'] = entityFilterObj[this.value.type]
}
} }
if (this.dsl) { if (this.dsl) {
params['attributes'] = null; params['attributes'] = null;
...@@ -416,9 +422,11 @@ define(['require', ...@@ -416,9 +422,11 @@ define(['require',
this.dsl = true; this.dsl = true;
this.$('.tagBox').hide(); this.$('.tagBox').hide();
this.$('.temFilterBtn').hide(); this.$('.temFilterBtn').hide();
this.$('.temFilter').toggleClass('col-sm-10 col-sm-12'); this.$('.temFilter').addClass('col-sm-12');
this.$('.temFilter').removeClass('col-sm-10');
} else { } else {
this.$('.temFilter').toggleClass('col-sm-10 col-sm-12'); this.$('.temFilter').addClass('col-sm-10');
this.$('.temFilter').removeClass('col-sm-12');
this.$('.temFilterBtn').show(); this.$('.temFilterBtn').show();
this.$('.tagBox').show(); this.$('.tagBox').show();
this.dsl = false; this.dsl = false;
...@@ -427,7 +435,7 @@ define(['require', ...@@ -427,7 +435,7 @@ define(['require',
if (paramObj && this.type == paramObj.searchType) { if (paramObj && this.type == paramObj.searchType) {
this.updateQueryObject(paramObj); this.updateQueryObject(paramObj);
} }
if (this.type == "basic") { if (paramObj && this.type == "basic") {
this.query[this.type].attribute = paramObj.attributes ? paramObj.attributes : null; this.query[this.type].attribute = paramObj.attributes ? paramObj.attributes : null;
} }
Utils.setUrl({ Utils.setUrl({
...@@ -448,6 +456,10 @@ define(['require', ...@@ -448,6 +456,10 @@ define(['require',
this.ui.typeLov.val("").trigger("change"); this.ui.typeLov.val("").trigger("change");
this.ui.tagLov.val("").trigger("change"); this.ui.tagLov.val("").trigger("change");
this.ui.searchInput.val(""); this.ui.searchInput.val("");
if (this.dsl) {
this.searchTableFilters.tagFilters = {};
this.searchTableFilters.entityFilters = {};
}
this.checkForButtonVisiblity(); this.checkForButtonVisiblity();
Utils.setUrl({ Utils.setUrl({
url: '#!/search/searchResult', url: '#!/search/searchResult',
......
...@@ -50,7 +50,7 @@ define(['require', ...@@ -50,7 +50,7 @@ define(['require',
* @constructs * @constructs
*/ */
initialize: function(options) { initialize: function(options) {
_.extend(this, _.pick(options, 'value', 'entityDefCollection', 'typeHeaders', 'searchVent', 'enumDefCollection', 'classificationDefCollection', 'tag')); _.extend(this, _.pick(options, 'value', 'entityDefCollection', 'typeHeaders', 'searchVent', 'enumDefCollection', 'classificationDefCollection', 'tag', 'searchTableFilters'));
this.bindEvents(); this.bindEvents();
var that = this; var that = this;
this.modal = new Modal({ this.modal = new Modal({
...@@ -83,7 +83,8 @@ define(['require', ...@@ -83,7 +83,8 @@ define(['require',
searchVent: this.searchVent, searchVent: this.searchVent,
entityDefCollection: this.entityDefCollection, entityDefCollection: this.entityDefCollection,
enumDefCollection: this.enumDefCollection, enumDefCollection: this.enumDefCollection,
classificationDefCollection: this.classificationDefCollection classificationDefCollection: this.classificationDefCollection,
searchTableFilters: this.searchTableFilters
} }
if (this.tag) { if (this.tag) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment