ATLAS-2018: UI: Attribute filter does not preserve state
Signed-off-by: Madhan Neethiraj <madhan@apache.org>
(cherry picked from commit db317a4708fe1f6c87a1f7674f4fb3bbf70bebb1)
diff --git a/dashboardv2/public/js/router/Router.js b/dashboardv2/public/js/router/Router.js
index 4f14d4d..4fac9c9 100644
--- a/dashboardv2/public/js/router/Router.js
+++ b/dashboardv2/public/js/router/Router.js
@@ -54,7 +54,11 @@
'classificationDefCollection': this.classificationDefCollection
}
this.sharedObj = {
- searchTableColumns: {}
+ searchTableColumns: {},
+ searchTableFilters: {
+ tagFilters: {},
+ entityFilters: {}
+ }
}
},
bindCommonEvents: function() {
diff --git a/dashboardv2/public/js/utils/CommonViewFunction.js b/dashboardv2/public/js/utils/CommonViewFunction.js
index 177e052..48ee41f 100644
--- a/dashboardv2/public/js/utils/CommonViewFunction.js
+++ b/dashboardv2/public/js/utils/CommonViewFunction.js
@@ -408,7 +408,11 @@
_.each(attrObj, function(obj) {
attrQuery.push(obj.id + "::" + obj.operator + "::" + obj.value + "::" + obj.type);
});
- return attrQuery.join();
+ if (attrQuery.length) {
+ return attrQuery.join();
+ } else {
+ return null;
+ }
} else {
return null;
}
diff --git a/dashboardv2/public/js/views/business_catalog/SideNavLayoutView.js b/dashboardv2/public/js/views/business_catalog/SideNavLayoutView.js
index 42fbc83..28a658a 100644
--- a/dashboardv2/public/js/views/business_catalog/SideNavLayoutView.js
+++ b/dashboardv2/public/js/views/business_catalog/SideNavLayoutView.js
@@ -83,7 +83,7 @@
return events;
},
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) {
this.tabClass = "tab col-sm-4";
} else {
@@ -128,7 +128,8 @@
entityDefCollection: that.entityDefCollection,
enumDefCollection: that.enumDefCollection,
classificationDefCollection: that.classificationDefCollection,
- searchTableColumns: that.searchTableColumns
+ searchTableColumns: that.searchTableColumns,
+ searchTableFilters: that.searchTableFilters
}));
});
},
diff --git a/dashboardv2/public/js/views/search/QueryBuilderView.js b/dashboardv2/public/js/views/search/QueryBuilderView.js
index ebef684..e94c05d 100644
--- a/dashboardv2/public/js/views/search/QueryBuilderView.js
+++ b/dashboardv2/public/js/views/search/QueryBuilderView.js
@@ -52,7 +52,7 @@
* @constructs
*/
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.filterType = this.tag ? 'tagFilters' : 'entityFilters';
},
@@ -134,7 +134,7 @@
var that = this,
filters = [];
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) {
var returnObj = that.getObjDef(obj, rules_widgets);
diff --git a/dashboardv2/public/js/views/search/SearchLayoutView.js b/dashboardv2/public/js/views/search/SearchLayoutView.js
index 6af9b2a..5957a46 100644
--- a/dashboardv2/public/js/views/search/SearchLayoutView.js
+++ b/dashboardv2/public/js/views/search/SearchLayoutView.js
@@ -81,7 +81,7 @@
* @constructs
*/
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";
var param = Utils.getUrlState.getQueryParams();
this.query = {
@@ -92,8 +92,6 @@
basic: {
query: null,
type: null,
- typeFilter: null,
- tagFilter: null,
tag: null,
attributes: null
}
@@ -133,51 +131,39 @@
filtertype = [filtertypeParam];
}
}
- var typeCheck = function(filterQueryObj, type) {
- var filterObj = filterQueryObj[type];
+ var typeCheck = function(filterObj, type) {
if (that.value.type) {
if (filterObj && filterObj.length) {
that.ui.typeAttrFilter.addClass('active');
} else {
- filterQueryObj[type] = null;
- that.value[type] = null;
that.ui.typeAttrFilter.removeClass('active');
}
that.ui.typeAttrFilter.prop('disabled', false);
} else {
- filterQueryObj[type] = null;
- that.value[type] = null;
that.ui.typeAttrFilter.removeClass('active');
that.ui.typeAttrFilter.prop('disabled', true);
}
-
}
- var tagCheck = function(filterQueryObj, type) {
- var filterObj = filterQueryObj[type];
+ var tagCheck = function(filterObj, type) {
if (that.value.tag) {
that.ui.tagAttrFilter.prop('disabled', false);
if (filterObj && filterObj.length) {
that.ui.tagAttrFilter.addClass('active');
} else {
- filterQueryObj[type] = null;
- that.value[type] = null;
that.ui.tagAttrFilter.removeClass('active');
}
} else {
- filterQueryObj[type] = null;
- that.value[type] = null;
that.ui.tagAttrFilter.removeClass('active');
that.ui.tagAttrFilter.prop('disabled', true);
}
}
_.each(filtertype, function(type) {
- var filterObj = that.query[that.type][type],
- filterQueryObj = that.query[that.type];
+ var filterObj = that.searchTableFilters[type];
if (type == "entityFilters") {
- typeCheck(filterQueryObj, type)
+ typeCheck(filterObj[that.value.type], type);
}
if (type == "tagFilters") {
- tagCheck(filterQueryObj, type)
+ tagCheck(filterObj[that.value.tag], type);
}
});
},
@@ -191,14 +177,19 @@
filterType = (isTagEl ? 'tagFilters' : 'entityFilters'),
value = value.length ? value : null;
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 = {};
temp[key] = value;
_.extend(this.value, temp);
- this.query[this.type][filterType] = null;
- this.value[filterType] = null;
- this.makeFilterButtonActive(filterType);
+ } else {
+ // Initial loading handle.
+ 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 {
this.ui.tagAttrFilter.prop('disabled', true);
this.ui.typeAttrFilter.prop('disabled', true);
@@ -244,8 +235,6 @@
query: null,
type: null,
tag: null,
- entityFilters: null,
- tagFilters: null,
attributes: null
}), param);
},
@@ -289,7 +278,8 @@
typeHeaders: that.typeHeaders,
entityDefCollection: that.entityDefCollection,
enumDefCollection: that.enumDefCollection,
- classificationDefCollection: that.classificationDefCollection
+ classificationDefCollection: that.classificationDefCollection,
+ searchTableFilters: that.searchTableFilters
});
that.attrModal.on('ok', function(scope, e) {
that.okAttrFilterButton(e);
@@ -297,11 +287,19 @@
});
},
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');
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);
+ 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();
if ($(e.currentTarget).hasClass('search')) {
this.findSearchResult();
@@ -342,9 +340,9 @@
this.value = paramObj;
}
if (this.value) {
- if (this.value.dslChecked == "true" && this.dsl == false) {
+ if (this.value.dslChecked == "true") {
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.typeLov.val(this.value.type);
@@ -387,6 +385,14 @@
this.query[this.type].type = this.ui.typeLov.select2('val') || null;
if (!this.dsl) {
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) {
params['attributes'] = null;
@@ -416,9 +422,11 @@
this.dsl = true;
this.$('.tagBox').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 {
- 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.$('.tagBox').show();
this.dsl = false;
@@ -427,7 +435,7 @@
if (paramObj && this.type == paramObj.searchType) {
this.updateQueryObject(paramObj);
}
- if (this.type == "basic") {
+ if (paramObj && this.type == "basic") {
this.query[this.type].attribute = paramObj.attributes ? paramObj.attributes : null;
}
Utils.setUrl({
@@ -448,6 +456,10 @@
this.ui.typeLov.val("").trigger("change");
this.ui.tagLov.val("").trigger("change");
this.ui.searchInput.val("");
+ if (this.dsl) {
+ this.searchTableFilters.tagFilters = {};
+ this.searchTableFilters.entityFilters = {};
+ }
this.checkForButtonVisiblity();
Utils.setUrl({
url: '#!/search/searchResult',
diff --git a/dashboardv2/public/js/views/search/SearchQueryView.js b/dashboardv2/public/js/views/search/SearchQueryView.js
index 281e37e..b07c325 100644
--- a/dashboardv2/public/js/views/search/SearchQueryView.js
+++ b/dashboardv2/public/js/views/search/SearchQueryView.js
@@ -50,7 +50,7 @@
* @constructs
*/
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();
var that = this;
this.modal = new Modal({
@@ -83,7 +83,8 @@
searchVent: this.searchVent,
entityDefCollection: this.entityDefCollection,
enumDefCollection: this.enumDefCollection,
- classificationDefCollection: this.classificationDefCollection
+ classificationDefCollection: this.classificationDefCollection,
+ searchTableFilters: this.searchTableFilters
}
if (this.tag) {