Commit 5527afb0 by kevalbhatt Committed by Madhan Neethiraj

ATLAS-1914: clear button in search UI to clear filter attributes

parent cda7f56d
......@@ -53,6 +53,10 @@ define([
'enumDefCollection': this.enumDefCollection,
'classificationDefCollection': this.classificationDefCollection
}
this.filterObj = {
'tagFilters': JSON.parse(Utils.localStorage.getValue('tagFilters')),
'entityFilters': JSON.parse(Utils.localStorage.getValue('entityFilters'))
}
},
bindCommonEvents: function() {
var that = this;
......@@ -125,6 +129,7 @@ define([
App.rSideNav.show(new SideNavLayoutView(
_.extend({
'url': url,
'filterObj': that.filterObj
}, that.preFetchedCollectionLists)
));
} else {
......@@ -156,7 +161,7 @@ define([
App.rNHeader.show(new Header());
if (!App.rSideNav.currentView) {
App.rSideNav.show(new SideNavLayoutView(
_.extend({}, that.preFetchedCollectionLists)
_.extend({ 'filterObj': that.filterObj }, that.preFetchedCollectionLists)
));
} else {
App.rSideNav.currentView.selectTab();
......@@ -193,7 +198,8 @@ define([
}
App.rSideNav.show(new SideNavLayoutView(
_.extend({
'tag': tagName
'tag': tagName,
'filterObj': that.filterObj
}, that.preFetchedCollectionLists)
));
} else {
......@@ -231,17 +237,13 @@ define([
'views/business_catalog/SideNavLayoutView',
'views/search/SearchDetailLayoutView',
], function(Header, BusinessCatalogLayoutView, SideNavLayoutView, SearchDetailLayoutView) {
var paramObj = Utils.getUrlState.getQueryParams(),
filterObj = {
'tagFilters': JSON.parse(Utils.localStorage.getValue('tagFilters')),
'entityFilters': JSON.parse(Utils.localStorage.getValue('entityFilters'))
}
var paramObj = Utils.getUrlState.getQueryParams();
App.rNHeader.show(new Header());
if (!App.rSideNav.currentView) {
App.rSideNav.show(new SideNavLayoutView(
_.extend({
'searchVent': that.searchVent,
'filterObj': filterObj
'filterObj': that.filterObj
}, that.preFetchedCollectionLists)
));
} else {
......@@ -257,7 +259,7 @@ define([
_.extend({
'value': paramObj,
'initialView': true,
'filterObj': filterObj,
'filterObj': that.filterObj,
'searchVent': that.searchVent
}, that.preFetchedCollectionLists)
));
......@@ -276,10 +278,7 @@ define([
'views/search/SearchDetailLayoutView'
], function(Header, BusinessCatalogLayoutView, SideNavLayoutView, SearchDetailLayoutView) {
var paramObj = Utils.getUrlState.getQueryParams(),
filterObj = {
'tagFilters': JSON.parse(Utils.localStorage.getValue('tagFilters')),
'entityFilters': JSON.parse(Utils.localStorage.getValue('entityFilters'))
}
filterObj = that.filterObj
if (paramObj && paramObj.searchType === "basic") {
if (paramObj.type) {
if (_.has(filterObj.entityFilters, paramObj.type)) {
......@@ -310,7 +309,7 @@ define([
_.extend({
'value': paramObj,
'searchVent': that.searchVent,
'filterObj': filterObj
'filterObj': that.filterObj
}, that.preFetchedCollectionLists)
));
} else {
......@@ -321,7 +320,7 @@ define([
_.extend({
'value': paramObj,
'searchVent': that.searchVent,
'filterObj': filterObj,
'filterObj': that.filterObj,
'initialView': (paramObj.type || (paramObj.dslChecked == "true" ? "" : paramObj.tag) || (paramObj.query ? paramObj.query.trim() : "")).length === 0
}, that.preFetchedCollectionLists)
));
......
......@@ -96,6 +96,8 @@ define(['require',
that.RTagLayoutView.show(new TagLayoutView({
collection: that.classificationDefCollection,
tag: that.tag,
value: that.value,
filterObj: that.filterObj,
typeHeaders: that.typeHeaders
}));
});
......
......@@ -138,13 +138,27 @@ define(['require',
}
}
}
_.each(this.attrObj, function(obj) {
var returnObj = that.getObjDef(obj, rules_widgets);
if (returnObj) {
filters.push(returnObj);
}
});
filters = _.uniq(filters, 'id');
if (rules_widgets) {
for (var i = 0; i < rules_widgets.rules.length; i++) {
if (!_.find(filters, { id: rules_widgets.rules[i].id })) {
var type = (this.tag ? 'tagFilters' : 'entityFilters');
var list = JSON.parse(Utils.localStorage.getValue(type));
delete list[this.value.tag];
list = _.isEmpty(list) ? null : list;
Utils.localStorage.setValue(type, JSON.stringify(list));
this.filterObj[type] = list;
rules_widgets = null;
break;
}
}
}
if (filters && !_.isEmpty(filters)) {
this.ui.builder.queryBuilder({
plugins: ['bt-tooltip-errors'],
......
......@@ -282,7 +282,9 @@ define(['require',
var filtertype = this.attrModal.tag ? 'tagFilters' : 'entityFilters',
rule = this.attrModal.RQueryBuilder.currentView.ui.builder.queryBuilder('getRules'),
result = this.getQueryBuilderParsData(rule);
if (result && !_.isEmpty(result.criterion)) {
if (result) {
if (!_.isEmpty(result.criterion)) {
this.query[this.type][filtertype] = +new Date();
if (result) {
var filterObj = this.filterObj ? this.filterObj[filtertype] : null;
......@@ -301,13 +303,15 @@ define(['require',
this.makeFilterButtonActive(this.attrModal.tag ? 'tag' : 'type');
Utils.localStorage.removeValue(filtertype);
}
}
this.attrModal.modal.close();
} else {
this.filterObj[filtertype] = null;
this.query[this.type][filtertype] = null;
this.makeFilterButtonActive(this.attrModal.tag ? 'tag' : 'type');
Utils.localStorage.removeValue(filtertype);
}
this.attrModal.modal.close();
},
getQueryBuilderParsData: function(obj) {
if (obj) {
......@@ -378,17 +382,26 @@ define(['require',
} else if (this.value.dslChecked == "false" && this.dsl == true) {
this.ui.searchType.prop("checked", false).trigger("change");
}
this.ui.typeLov.val(this.value.type);
if (this.ui.typeLov.data('select2')) {
this.ui.typeLov.val(this.value.type).trigger('change');
if (this.ui.typeLov.val() !== this.value.type) {
this.value.type = null;
this.ui.typeLov.val("").trigger("change");
} else {
this.ui.typeLov.val(this.value.type);
this.ui.typeLov.trigger("change");
}
}
if (!this.dsl) {
this.ui.tagLov.val(this.value.tag);
if (this.ui.tagLov.data('select2')) {
this.ui.tagLov.val(this.value.tag).trigger('change');
// To handle delete scenario.
if (this.ui.tagLov.val() !== this.value.tag) {
this.value.tag = null;
this.ui.tagLov.val("").trigger("change");
} else {
this.ui.typeLov.val(this.value.tag);
this.ui.tagLov.trigger("change");
}
}
}
this.ui.searchInput.val(this.value.query || "");
......@@ -468,7 +481,11 @@ define(['require',
this.ui.typeLov.val("").trigger("change");
this.ui.tagLov.val("").trigger("change");
this.ui.searchInput.val("");
this.checkForButtonVisiblity()
this.checkForButtonVisiblity();
Utils.localStorage.removeValue('tagFilters');
Utils.localStorage.removeValue('entityFilters');
this.filterObj.tagFilters = null;
this.filterObj.entityFilters = null;
Utils.setUrl({
url: '#!/search/searchResult',
urlParams: {
......
......@@ -59,7 +59,7 @@ define(['require',
* @constructs
*/
initialize: function(options) {
_.extend(this, _.pick(options, 'tag', 'collection', 'typeHeaders'));
_.extend(this, _.pick(options, 'tag', 'collection', 'typeHeaders', 'filterObj', 'value'));
},
bindEvents: function() {
var that = this;
......@@ -417,6 +417,15 @@ define(['require',
}
that.collection.remove(deleteTagData);
// to update tag list of search tab fetch typeHeaders.
var tagList = JSON.parse(Utils.localStorage.getValue('tagFilters'));
if (tagList) {
delete tagList[that.tagName];
}
tagList = _.isEmpty(tagList) ? null : tagList;
if (that.filterObj['tagFilters'] && that.filterObj['tagFilters'][that.tagName]) {
delete that.filterObj['tagFilters'][that.tagName];
}
Utils.localStorage.setValue('tagFilters', JSON.stringify(tagList));
that.typeHeaders.fetch({ reset: true });
}
});
......
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