Repository: incubator-atlas Updated Branches: refs/heads/0.8-incubating 40d59a32d -> cac1fb9fb
ATLAS-1914: clear button in search UI to clear filter attributes Signed-off-by: Madhan Neethiraj <mad...@apache.org> (cherry picked from commit 5527afb0d4cdf4414f2e95e0d419392dc78c9d9a) Project: http://git-wip-us.apache.org/repos/asf/incubator-atlas/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-atlas/commit/cac1fb9f Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/cac1fb9f Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/cac1fb9f Branch: refs/heads/0.8-incubating Commit: cac1fb9fb5370196e9a120eb65300250517bfac7 Parents: 40d59a3 Author: kevalbhatt <kbh...@apache.org> Authored: Wed Jul 19 19:36:01 2017 +0530 Committer: Madhan Neethiraj <mad...@apache.org> Committed: Wed Jul 19 10:15:52 2017 -0700 ---------------------------------------------------------------------- dashboardv2/public/js/router/Router.js | 31 +++++---- .../views/business_catalog/SideNavLayoutView.js | 4 +- .../public/js/views/search/QueryBuilderView.js | 18 ++++- .../public/js/views/search/SearchLayoutView.js | 69 ++++++++++++-------- .../public/js/views/tag/TagLayoutView.js | 13 +++- 5 files changed, 88 insertions(+), 47 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/cac1fb9f/dashboardv2/public/js/router/Router.js ---------------------------------------------------------------------- diff --git a/dashboardv2/public/js/router/Router.js b/dashboardv2/public/js/router/Router.js index 8a1d241..f705843 100644 --- a/dashboardv2/public/js/router/Router.js +++ b/dashboardv2/public/js/router/Router.js @@ -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) )); @@ -342,4 +341,4 @@ define([ } }); return AppRouter; -}); +}); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/cac1fb9f/dashboardv2/public/js/views/business_catalog/SideNavLayoutView.js ---------------------------------------------------------------------- diff --git a/dashboardv2/public/js/views/business_catalog/SideNavLayoutView.js b/dashboardv2/public/js/views/business_catalog/SideNavLayoutView.js index 013c72e..8f41399 100644 --- a/dashboardv2/public/js/views/business_catalog/SideNavLayoutView.js +++ b/dashboardv2/public/js/views/business_catalog/SideNavLayoutView.js @@ -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 })); }); @@ -128,4 +130,4 @@ define(['require', }, }); return SideNavLayoutView; -}); +}); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/cac1fb9f/dashboardv2/public/js/views/search/QueryBuilderView.js ---------------------------------------------------------------------- diff --git a/dashboardv2/public/js/views/search/QueryBuilderView.js b/dashboardv2/public/js/views/search/QueryBuilderView.js index 468a2d7..ec20734 100644 --- a/dashboardv2/public/js/views/search/QueryBuilderView.js +++ b/dashboardv2/public/js/views/search/QueryBuilderView.js @@ -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'], @@ -178,4 +192,4 @@ define(['require', } }); return QueryBuilderView; -}); +}); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/cac1fb9f/dashboardv2/public/js/views/search/SearchLayoutView.js ---------------------------------------------------------------------- diff --git a/dashboardv2/public/js/views/search/SearchLayoutView.js b/dashboardv2/public/js/views/search/SearchLayoutView.js index cb8844d..76d6f77 100644 --- a/dashboardv2/public/js/views/search/SearchLayoutView.js +++ b/dashboardv2/public/js/views/search/SearchLayoutView.js @@ -282,32 +282,36 @@ 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)) { - this.query[this.type][filtertype] = +new Date(); - if (result) { - var filterObj = this.filterObj ? this.filterObj[filtertype] : null; - if (!filterObj) { - filterObj = {}; + + if (result) { + if (!_.isEmpty(result.criterion)) { + this.query[this.type][filtertype] = +new Date(); + if (result) { + var filterObj = this.filterObj ? this.filterObj[filtertype] : null; + if (!filterObj) { + filterObj = {}; + } + var temp = {}; // IE fix + temp[(this.attrModal.tag ? this.value.tag : this.value.type)] = { 'result': result, 'rule': rule }; + _.extend(filterObj, temp); + this.filterObj[filtertype] = filterObj; + this.makeFilterButtonActive(this.attrModal.tag ? 'tag' : 'type'); + Utils.localStorage.setValue((filtertype), JSON.stringify(filterObj)); + } else { + this.filterObj[filtertype] = null; + this.query[this.type][filtertype] = null; + this.makeFilterButtonActive(this.attrModal.tag ? 'tag' : 'type'); + Utils.localStorage.removeValue(filtertype); } - var temp = {}; // IE fix - temp[(this.attrModal.tag ? this.value.tag : this.value.type)] = { 'result': result, 'rule': rule }; - _.extend(filterObj, temp); - this.filterObj[filtertype] = filterObj; - this.makeFilterButtonActive(this.attrModal.tag ? 'tag' : 'type'); - Utils.localStorage.setValue((filtertype), JSON.stringify(filterObj)); - } 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(); } 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'); - } else { - this.ui.typeLov.val(this.value.type); + if (this.ui.typeLov.val() !== this.value.type) { + this.value.type = null; + this.ui.typeLov.val("").trigger("change"); + } else { + 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'); - } else { - this.ui.typeLov.val(this.value.tag); + // 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.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: { @@ -481,4 +498,4 @@ define(['require', } }); return SearchLayoutView; -}); +}); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/cac1fb9f/dashboardv2/public/js/views/tag/TagLayoutView.js ---------------------------------------------------------------------- diff --git a/dashboardv2/public/js/views/tag/TagLayoutView.js b/dashboardv2/public/js/views/tag/TagLayoutView.js index b8a1cd1..2714770 100644 --- a/dashboardv2/public/js/views/tag/TagLayoutView.js +++ b/dashboardv2/public/js/views/tag/TagLayoutView.js @@ -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,10 +417,19 @@ 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 }); } }); } }); return TagLayoutView; -}); +}); \ No newline at end of file