SearchDefaultLayoutView.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. define([ "require", "backbone", "utils/Globals", "hbs!tmpl/search/SearchDefaultLayoutView_tmpl", "utils/Utils", "utils/CommonViewFunction", "utils/Enums" ], function(require, Backbone, Globals, SearchDefaultLayoutViewTmpl, Utils, CommonViewFunction, Enums) {
  2. "use strict";
  3. var SearchDefaultlLayoutView = Backbone.Marionette.LayoutView.extend({
  4. _viewName: "SearchDefaultlLayoutView",
  5. template: SearchDefaultLayoutViewTmpl,
  6. regions: {
  7. RGlobalSearchLayoutView: "#r_globalSearchLayoutView",
  8. RSearchResultLayoutView: "#r_searchResultLayoutView",
  9. RQueryBuilderEntity: "#r_attributeQueryBuilderEntity",
  10. RQueryBuilderClassification: "#r_attributeQueryBuilderClassification"
  11. },
  12. ui: {
  13. resizable: '[data-id="resizable"]',
  14. attrFilter: "[data-id='attrFilter']",
  15. attrApply: "[data-id='attrApply']",
  16. attrClose: "[data-id='attrClose']",
  17. entityRegion: "[data-id='entityRegion']",
  18. classificationRegion: "[data-id='classificationRegion']",
  19. checkDeletedEntity: "[data-id='checkDeletedEntity']",
  20. checkSubClassification: "[data-id='checkSubClassification']",
  21. checkSubType: "[data-id='checkSubType']",
  22. entityName: ".entityName",
  23. classificationName: ".classificationName",
  24. createNewEntity: '[data-id="createNewEntity"]',
  25. clearQuerySearch: "[data-id='clearQuerySearch']",
  26. refreshSearchQuery: "[data-id='refreshSearchResult']"
  27. },
  28. events: function() {
  29. var events = {}, that = this;
  30. return events["click " + this.ui.attrFilter] = function(e) {
  31. this.$(".attribute-filter-container").hasClass("hide") ? (this.onClickAttrFilter(),
  32. this.$(".attributeResultContainer").addClass("overlay")) : this.$(".attributeResultContainer").removeClass("overlay"),
  33. this.$(".fa-angle-right").toggleClass("fa-angle-down"), this.$(".attribute-filter-container, .attr-filter-overlay").toggleClass("hide");
  34. }, events["click " + this.ui.refreshSearchQuery] = function(e) {
  35. this.options.searchVent.trigger("search:refresh");
  36. }, events["click " + this.ui.attrApply] = function(e) {
  37. that.okAttrFilterButton(e);
  38. }, events["click " + this.ui.attrClose] = function(e) {
  39. this.$(".attributeResultContainer").removeClass("overlay"), this.$(".fa-angle-right").toggleClass("fa-angle-down"),
  40. this.$(".attribute-filter-container, .attr-filter-overlay").toggleClass("hide");
  41. }, events["click .clear-attr"] = function(e) {
  42. var type = $(e.currentTarget).data("type"), that = this;
  43. switch (type) {
  44. case "entityFilters":
  45. that.filtersQueryUpdate(e, !1);
  46. break;
  47. case "tagFilters":
  48. that.filtersQueryUpdate(e, !0);
  49. break;
  50. default:
  51. this.options.value[type] = null;
  52. }
  53. this.searchAttrFilter();
  54. }, events["click " + this.ui.clearQuerySearch] = function(e) {
  55. var notifyObj = {
  56. modal: !0,
  57. ok: function(argument) {
  58. Utils.setUrl({
  59. url: "#!/search",
  60. mergeBrowserUrl: !1,
  61. trigger: !0,
  62. updateTabState: !0
  63. });
  64. },
  65. cancel: function(argument) {}
  66. };
  67. notifyObj.text = "Search parameters will be reset and you will return to the default search page. Continue?",
  68. Utils.notifyConfirm(notifyObj);
  69. }, events["click " + this.ui.createNewEntity] = "onCreateNewEntity", events["click " + this.ui.checkDeletedEntity] = "onCheckExcludeIncludeResult",
  70. events["click " + this.ui.checkSubClassification] = "onCheckExcludeIncludeResult",
  71. events["click " + this.ui.checkSubType] = "onCheckExcludeIncludeResult", events;
  72. },
  73. templateHelpers: function() {
  74. return {
  75. entityCreate: Globals.entityCreate
  76. };
  77. },
  78. initialize: function(options) {
  79. _.extend(this.options, options), this.hidenFilter = !1, this.tagAttributeLength = 0,
  80. this.entityAttributeLength = 0, this.tagEntityCheck = !1, this.typeEntityCheck = !1;
  81. },
  82. bindEvents: function() {},
  83. onRender: function() {
  84. this.toggleLayoutClass = this.$(".col-sm-9.f-right, .col-sm-12.f-right"), this.renderGlobalSearch(),
  85. this.renderSearchResult(), this.updateView(), this.ui.entityRegion.hide(), this.ui.classificationRegion.hide();
  86. },
  87. filtersQueryUpdate: function(e, isTag) {
  88. var filters = CommonViewFunction.attributeFilter.extractUrl({
  89. value: isTag ? this.options.value.tagFilters : this.options.value.entityFilters,
  90. formatDate: !0
  91. }), rules = filters.rules, filtertype = isTag ? "tagFilters" : "entityFilters", that = this;
  92. filters.rules = _.filter(rules, function(obj, key) {
  93. return obj.id + key != $(e.currentTarget).data("id");
  94. }), filters && that.updateFilterOptions(filters, filtertype, isTag), 0 == filters.rules.length && (isTag ? this.options.searchTableFilters.tagFilters[that.options.value.tag] = "" : this.options.searchTableFilters.entityFilters[that.options.value.type] = "");
  95. },
  96. onCheckExcludeIncludeResult: function(e) {
  97. var flag = !1, val = $(e.currentTarget).attr("data-value");
  98. e.target.checked && (flag = !0), this.options.value && (this.options.value[val] = flag);
  99. },
  100. onCreateNewEntity: function(e) {
  101. var that = this;
  102. require([ "views/entity/CreateEntityLayoutView" ], function(CreateEntityLayoutView) {
  103. new CreateEntityLayoutView({
  104. entityDefCollection: that.options.entityDefCollection,
  105. typeHeaders: that.options.typeHeaders,
  106. searchVent: that.options.searchVent,
  107. callback: function() {}
  108. });
  109. });
  110. },
  111. updateView: function() {
  112. this.options.fromSearchResultView ? (this.$('.search-container,[data-id="createEntity"]').hide(),
  113. $("body").removeClass("ui-autocomplete-small-height"), this.$(".searchResultContainer,.attributeResultContainer").show()) : (this.$('.search-container,[data-id="createEntity"]').show(),
  114. $("body").addClass("ui-autocomplete-small-height"), this.$(".searchResultContainer,.attributeResultContainer").hide());
  115. },
  116. manualRender: function(options) {
  117. _.extend(this.options, options), this.updateView(), this.onClickAttrFilter(), this.renderSearchResult();
  118. },
  119. renderGlobalSearch: function() {
  120. var that = this;
  121. require([ "views/search/GlobalSearchLayoutView" ], function(GlobalSearchLayoutView) {
  122. that.RGlobalSearchLayoutView.show(new GlobalSearchLayoutView(_.extend({
  123. closeOnSubmit: !0
  124. }, _.omit(that.options, "value"))));
  125. });
  126. },
  127. renderSearchResult: function() {
  128. var that = this;
  129. require([ "views/search/SearchResultLayoutView" ], function(SearchResultLayoutView) {
  130. that.RSearchResultLayoutView.show(new SearchResultLayoutView(that.options));
  131. });
  132. },
  133. checkEntityFilter: function(options) {
  134. return options && options.value && (options.value.type && options.value.entityFilters && (options.searchTableFilters.entityFilters[options.value.type] = options.value.entityFilters),
  135. options.value.tag && options.value.tagFilters && (options.searchTableFilters.tagFilters[options.value.tag] = options.value.tagFilters)),
  136. options.searchTableFilters;
  137. },
  138. onClickAttrFilter: function() {
  139. var that = this, obj = {
  140. value: that.options.value,
  141. searchVent: that.options.searchVent,
  142. entityDefCollection: that.options.entityDefCollection,
  143. enumDefCollection: that.options.enumDefCollection,
  144. typeHeaders: that.options.typeHeaders,
  145. classificationDefCollection: that.options.classificationDefCollection,
  146. businessMetadataDefCollection: that.options.businessMetadataDefCollection,
  147. searchTableFilters: that.checkEntityFilter(that.options)
  148. };
  149. if (this.tagEntityCheck = !1, this.typeEntityCheck = !1, that.options.value) {
  150. if (this.ui.checkDeletedEntity.prop("checked", !!this.options.value.includeDE && this.options.value.includeDE),
  151. this.ui.checkSubClassification.prop("checked", !!this.options.value.excludeSC && this.options.value.excludeSC),
  152. this.ui.checkSubType.prop("checked", !!this.options.value.excludeST && this.options.value.excludeST),
  153. that.options.value.tag && that.options.value.type ? (this.$(".attribute-filter-container").removeClass("no-attr"),
  154. this.ui.classificationRegion.show(), this.ui.entityRegion.show()) : (that.options.value.tag || that.options.value.type || this.$(".attribute-filter-container").addClass("no-attr"),
  155. this.ui.entityRegion.hide(), this.ui.classificationRegion.hide()), that.options.value.tag) {
  156. this.ui.classificationRegion.show();
  157. var attrTagObj = that.options.classificationDefCollection.fullCollection.find({
  158. name: that.options.value.tag
  159. });
  160. attrTagObj && (attrTagObj = Utils.getNestedSuperTypeObj({
  161. data: attrTagObj.toJSON(),
  162. collection: that.options.classificationDefCollection,
  163. attrMerge: !0
  164. }), this.tagAttributeLength = attrTagObj.length), (Globals[that.options.value.tag] || Globals[Enums.addOnClassification[0]]) && (obj.systemAttrArr = (Globals[that.options.value.tag] || Globals[Enums.addOnClassification[0]]).attributeDefs,
  165. this.tagAttributeLength = obj.systemAttrArr.length), this.renderQueryBuilder(_.extend({}, obj, {
  166. tag: !0,
  167. type: !1,
  168. attrObj: attrTagObj
  169. }), this.RQueryBuilderClassification), this.ui.classificationName.html(that.options.value.tag);
  170. }
  171. if (that.options.value.type) {
  172. this.ui.entityRegion.show();
  173. var attrTypeObj = that.options.entityDefCollection.fullCollection.find({
  174. name: that.options.value.type
  175. });
  176. attrTypeObj && (attrTypeObj = Utils.getNestedSuperTypeObj({
  177. data: attrTypeObj.toJSON(),
  178. collection: that.options.entityDefCollection,
  179. attrMerge: !0
  180. }), this.entityAttributeLength = attrTypeObj.length), (Globals[that.options.value.type] || Globals[Enums.addOnEntities[0]]) && (obj.systemAttrArr = (Globals[that.options.value.type] || Globals[Enums.addOnEntities[0]]).attributeDefs,
  181. this.entityAttributeLength = obj.systemAttrArr.length), this.renderQueryBuilder(_.extend({}, obj, {
  182. tag: !1,
  183. type: !0,
  184. attrObj: attrTypeObj
  185. }), this.RQueryBuilderEntity), this.ui.entityName.html(_.escape(that.options.value.type));
  186. }
  187. }
  188. },
  189. okAttrFilterButton: function(e) {
  190. function searchAttribute() {
  191. var queryBuilderObj = queryBuilderRef.data("queryBuilder");
  192. if (queryBuilderObj) {
  193. var ruleWithInvalid = queryBuilderObj.getRules({
  194. allow_invalid: !0
  195. }), rule = queryBuilderObj.getRules();
  196. if (rule ? that.updateFilterOptions(rule, filtertype, isTag) : isFilterValidate = !1,
  197. ruleWithInvalid && 1 === ruleWithInvalid.rules.length && null === ruleWithInvalid.rules[0].id && (isFilterValidate = !0,
  198. queryBuilderObj.clearErrors()), rule && rule.rules) {
  199. if (!that.tagEntityCheck) {
  200. var state = _.find(rule.rules, {
  201. id: "__state"
  202. });
  203. state && (that.typeEntityCheck = !("ACTIVE" === state.value && "=" === state.operator || "DELETED" === state.value && "!=" === state.operator),
  204. that.options.value.includeDE = that.typeEntityCheck);
  205. }
  206. if (!that.typeEntityCheck) {
  207. var entityStatus = _.find(rule.rules, {
  208. id: "__entityStatus"
  209. });
  210. entityStatus && (that.tagEntityCheck = !("ACTIVE" === entityStatus.value && "=" === entityStatus.operator || "DELETED" === entityStatus.value && "!=" === entityStatus.operator),
  211. that.options.value.includeDE = that.tagEntityCheck);
  212. }
  213. }
  214. }
  215. }
  216. function filterPopupStatus() {
  217. isFilterValidate && $(e.currentTarget).hasClass("search") && (that.$(".fa-angle-right").toggleClass("fa-angle-down"),
  218. that.$(".attribute-filter-container, .attr-filter-overlay").toggleClass("hide"),
  219. that.searchAttrFilter(), that.$(".attributeResultContainer").removeClass("overlay"));
  220. }
  221. var isTag, filtertype, queryBuilderRef, isFilterValidate = !0, that = this;
  222. this.options.value.tag && (isTag = !0, filtertype = isTag ? "tagFilters" : "entityFilters",
  223. 0 !== this.tagAttributeLength && (queryBuilderRef = this.RQueryBuilderClassification.currentView.ui.builder,
  224. searchAttribute())), this.options.value.type && (isTag = !1, filtertype = isTag ? "tagFilters" : "entityFilters",
  225. 0 !== this.entityAttributeLength && (queryBuilderRef = this.RQueryBuilderEntity.currentView.ui.builder,
  226. searchAttribute())), filterPopupStatus();
  227. },
  228. getIdFromRuleObj: function(rule) {
  229. var that = this, col = new Set();
  230. return _.map(rule.rules, function(obj, key) {
  231. return _.has(obj, "condition") ? that.getIdFromRuleObj(obj) : col.add(obj.id);
  232. }), Array.from(col);
  233. },
  234. updateFilterOptions: function(rule, filtertype, isTag) {
  235. var ruleUrl = CommonViewFunction.attributeFilter.generateUrl({
  236. value: rule,
  237. formatedDateToLong: !0
  238. });
  239. this.options.searchTableFilters[filtertype][isTag ? this.options.value.tag : this.options.value.type] = ruleUrl,
  240. !isTag && this.options.value && this.options.value.type && this.options.searchTableColumns && (this.options.searchTableColumns[this.options.value.type] || (this.options.searchTableColumns[this.options.value.type] = [ "selected", "name", "description", "typeName", "owner", "tag", "term" ]),
  241. this.options.searchTableColumns[this.options.value.type] = _.sortBy(_.union(_.without(this.options.searchTableColumns[this.options.value.type]), this.getIdFromRuleObj(rule))));
  242. },
  243. renderQueryBuilder: function(obj, rQueryBuilder) {
  244. require([ "views/search/QueryBuilderView" ], function(QueryBuilderView) {
  245. rQueryBuilder.show(new QueryBuilderView(obj));
  246. });
  247. },
  248. searchAttrFilter: function() {
  249. var updatedUrl, entityFilterObj = (this.options.value.type || this.options.value.tag,
  250. this.options.searchTableFilters.entityFilters), tagFilterObj = this.options.searchTableFilters.tagFilters, params = {
  251. searchType: "basic",
  252. dslChecked: !1,
  253. tagFilters: null,
  254. entityFilters: null,
  255. query: null,
  256. type: null,
  257. tag: null,
  258. term: null,
  259. attributes: null,
  260. pageOffset: null,
  261. pageLimit: null,
  262. includeDE: null
  263. };
  264. if (this.options.value) {
  265. this.options.value.tag && (params.tag = this.options.value.tag), this.options.value.type && (params.type = this.options.value.type),
  266. this.options.value.term && (params.term = this.options.value.term), this.options.value.query && (params.query = this.options.value.query);
  267. var columnList = this.options.value && this.options.value.type && this.options.searchTableColumns ? this.options.searchTableColumns[this.options.value.type] : null;
  268. columnList && (params.attributes = columnList.join(",")), params.includeDE = !_.isUndefinedNull(this.options.value.includeDE) && this.options.value.includeDE,
  269. params.excludeST = !_.isUndefinedNull(this.options.value.excludeST) && this.options.value.excludeST,
  270. params.excludeSC = !_.isUndefinedNull(this.options.value.excludeSC) && this.options.value.excludeSC;
  271. }
  272. entityFilterObj && (params.entityFilters = entityFilterObj[this.options.value.type]),
  273. tagFilterObj && (params.tagFilters = tagFilterObj[this.options.value.tag]), params.pageOffset = 0,
  274. this.options.value.tag || this.options.value.type || this.options.value.term || this.options.value.query ? updatedUrl = "#!/search/searchResult" : (params.tag = null,
  275. params.type = null, params.term = null, params.query = null, params.attributes = null,
  276. params.includeDE = null, params.excludeST = null, params.excludeSC = null, updatedUrl = "#!/search"),
  277. Utils.setUrl({
  278. url: updatedUrl,
  279. urlParams: _.extend({}, params),
  280. mergeBrowserUrl: !1,
  281. trigger: !0,
  282. updateTabState: !0
  283. });
  284. var paramObj = Utils.getUrlState.getQueryParams();
  285. this.options.value = paramObj;
  286. }
  287. });
  288. return SearchDefaultlLayoutView;
  289. });