SearchLayoutView.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. define([ "require", "backbone", "hbs!tmpl/search/SearchLayoutView_tmpl", "utils/Utils", "utils/UrlLinks", "utils/Globals", "utils/Enums", "collection/VSearchList", "utils/CommonViewFunction", "modules/Modal" ], function(require, Backbone, SearchLayoutViewTmpl, Utils, UrlLinks, Globals, Enums, VSearchList, CommonViewFunction, Modal) {
  2. "use strict";
  3. var SearchLayoutView = Backbone.Marionette.LayoutView.extend({
  4. _viewName: "SearchLayoutView",
  5. template: SearchLayoutViewTmpl,
  6. regions: {
  7. RSaveSearchBasic: "[data-id='r_saveSearchBasic']",
  8. RSaveSearchAdvance: "[data-id='r_saveSearchAdvance']"
  9. },
  10. ui: {
  11. searchInput: '[data-id="searchInput"]',
  12. searchType: 'input[name="queryType"]',
  13. searchBtn: '[data-id="searchBtn"]',
  14. clearSearch: '[data-id="clearSearch"]',
  15. typeLov: '[data-id="typeLOV"]',
  16. tagLov: '[data-id="tagLOV"]',
  17. termLov: '[data-id="termLOV"]',
  18. refreshBtn: '[data-id="refreshBtn"]',
  19. advancedInfoBtn: '[data-id="advancedInfo"]',
  20. typeAttrFilter: '[data-id="typeAttrFilter"]',
  21. tagAttrFilter: '[data-id="tagAttrFilter"]'
  22. },
  23. events: function() {
  24. var events = {}, that = this;
  25. return events["keyup " + this.ui.searchInput] = function(e) {
  26. var code = e.which;
  27. this.value.query = e.currentTarget.value, this.query[this.type].query = this.value.query,
  28. 13 == code && that.findSearchResult(), this.checkForButtonVisiblity();
  29. }, events["change " + this.ui.searchType] = "dslFulltextToggle", events["click " + this.ui.searchBtn] = "findSearchResult",
  30. events["click " + this.ui.clearSearch] = "clearSearchData", events["change " + this.ui.typeLov] = "checkForButtonVisiblity",
  31. events["change " + this.ui.tagLov] = "checkForButtonVisiblity", events["change " + this.ui.termLov] = "checkForButtonVisiblity",
  32. events["click " + this.ui.refreshBtn] = "onRefreshButton", events["click " + this.ui.advancedInfoBtn] = "advancedInfo",
  33. events["click " + this.ui.typeAttrFilter] = function() {
  34. this.openAttrFilter("type");
  35. }, events["click " + this.ui.tagAttrFilter] = function() {
  36. this.openAttrFilter("tag");
  37. }, events;
  38. },
  39. initialize: function(options) {
  40. _.extend(this, _.pick(options, "value", "typeHeaders", "searchVent", "entityDefCollection", "enumDefCollection", "classificationDefCollection", "businessMetadataDefCollection", "searchTableColumns", "searchTableFilters", "metricCollection", "classificationAndMetricEvent")),
  41. this.type = "basic", this.entityCountObj = _.first(this.metricCollection.toJSON()) || {
  42. entity: {
  43. entityActive: {},
  44. entityDeleted: {}
  45. },
  46. tag: {
  47. tagEntities: {}
  48. }
  49. }, this.selectedFilter = {
  50. basic: [],
  51. dsl: []
  52. };
  53. var param = Utils.getUrlState.getQueryParams();
  54. this.query = {
  55. dsl: {
  56. query: this.value ? this.value.query : null,
  57. type: this.value ? this.value.type : null,
  58. pageOffset: this.value ? this.value.pageOffset : null,
  59. pageLimit: this.value ? this.value.pageLimit : null
  60. },
  61. basic: {
  62. query: this.value ? this.value.query : null,
  63. type: this.value ? this.value.type : null,
  64. tag: this.value ? this.value.tag : null,
  65. term: this.value ? this.value.term : null,
  66. attributes: this.value ? this.value.attributes : null,
  67. tagFilters: this.value ? this.value.tagFilters : null,
  68. pageOffset: this.value ? this.value.pageOffset : null,
  69. pageLimit: this.value ? this.value.pageLimit : null,
  70. entityFilters: this.value ? this.value.entityFilters : null,
  71. includeDE: this.value ? this.value.includeDE : null,
  72. excludeST: this.value ? this.value.excludeST : null,
  73. excludeSC: this.value ? this.value.excludeSC : null
  74. }
  75. }, this.value || (this.value = {}), this.dsl = !1, param && param.searchType && (this.type = param.searchType,
  76. this.updateQueryObject(param)), this.value && this.value.type || this.value && this.value.tag && "basic" === this.value.searchType ? this.setInitialEntityVal = !1 : this.setInitialEntityVal = !0,
  77. this.tagEntityCheck = !1, this.typeEntityCheck = !1, this.bindEvents();
  78. },
  79. renderSaveSearch: function() {
  80. var that = this;
  81. require([ "views/search/save/SaveSearchView" ], function(SaveSearchView) {
  82. function fetchSaveSearchCollection() {
  83. saveSearchCollection.fetch({
  84. success: function(collection, data) {
  85. saveSearchAdvanceCollection.fullCollection.reset(_.where(data, {
  86. searchType: "ADVANCED"
  87. })), saveSearchBaiscCollection.fullCollection.reset(_.where(data, {
  88. searchType: "BASIC"
  89. }));
  90. },
  91. silent: !0
  92. });
  93. }
  94. var saveSearchBaiscCollection = new VSearchList(), saveSearchAdvanceCollection = new VSearchList(), saveSearchCollection = new VSearchList();
  95. saveSearchCollection.url = UrlLinks.saveSearchApiUrl(), saveSearchBaiscCollection.fullCollection.comparator = function(model) {
  96. return model.get("name").toLowerCase();
  97. }, saveSearchAdvanceCollection.fullCollection.comparator = function(model) {
  98. return model.get("name").toLowerCase();
  99. };
  100. var obj = {
  101. value: that.value,
  102. searchVent: that.searchVent,
  103. typeHeaders: that.typeHeaders,
  104. fetchCollection: fetchSaveSearchCollection,
  105. classificationDefCollection: that.classificationDefCollection,
  106. entityDefCollection: that.entityDefCollection,
  107. getValue: function() {
  108. var queryObj = that.query[that.type], entityObj = that.searchTableFilters.entityFilters, tagObj = that.searchTableFilters.tagFilters, urlObj = Utils.getUrlState.getQueryParams();
  109. return urlObj && (urlObj.includeDE = "true" == urlObj.includeDE, urlObj.excludeSC = "true" == urlObj.excludeSC,
  110. urlObj.excludeST = "true" == urlObj.excludeST), _.extend({}, queryObj, urlObj, {
  111. entityFilters: entityObj ? entityObj[queryObj.type] : null,
  112. tagFilters: tagObj ? tagObj[queryObj.tag] : null,
  113. type: queryObj.type,
  114. query: queryObj.query,
  115. term: queryObj.term,
  116. tag: queryObj.tag
  117. });
  118. },
  119. applyValue: function(model, searchType) {
  120. that.manualRender(_.extend(searchType, CommonViewFunction.generateUrlFromSaveSearchObject({
  121. value: {
  122. searchParameters: model.get("searchParameters"),
  123. uiParameters: model.get("uiParameters")
  124. },
  125. classificationDefCollection: that.classificationDefCollection,
  126. entityDefCollection: that.entityDefCollection
  127. })));
  128. }
  129. };
  130. that.RSaveSearchBasic.show(new SaveSearchView(_.extend(obj, {
  131. isBasic: !0,
  132. collection: saveSearchBaiscCollection.fullCollection
  133. }))), that.RSaveSearchAdvance.show(new SaveSearchView(_.extend(obj, {
  134. isBasic: !1,
  135. collection: saveSearchAdvanceCollection.fullCollection
  136. }))), fetchSaveSearchCollection();
  137. });
  138. },
  139. bindEvents: function(param) {
  140. var that = this;
  141. this.listenTo(this.typeHeaders, "reset", function(value) {
  142. this.initializeValues();
  143. }, this), this.listenTo(this.searchVent, "entityList:refresh", function(model, response) {
  144. this.onRefreshButton();
  145. }, this), this.classificationAndMetricEvent.on("classification:Update:Search", function(options) {
  146. that.entityCountObj = _.first(that.metricCollection.toJSON()), that.value = Utils.getUrlState.getQueryParams() || {},
  147. that.value.type || (that.setInitialEntityVal = !0), that.initializeValues();
  148. });
  149. },
  150. initializeValues: function() {
  151. this.renderTypeTagList(), this.renderTermList(), this.setValues(), this.checkForButtonVisiblity(),
  152. this.renderSaveSearch(), this.setInitialEntityVal && (this.setInitialEntityVal = !1);
  153. },
  154. makeFilterButtonActive: function(filtertypeParam) {
  155. var filtertype = [ "entityFilters", "tagFilters" ], that = this;
  156. filtertypeParam && (_.isArray(filtertypeParam) ? filtertype = filtertypeParam : _.isString(filtertypeParam) && (filtertype = [ filtertypeParam ]));
  157. var typeCheck = function(filterObj, type) {
  158. that.value.type ? (filterObj && filterObj.length ? that.ui.typeAttrFilter.addClass("active") : that.ui.typeAttrFilter.removeClass("active"),
  159. that.ui.typeAttrFilter.prop("disabled", !1)) : (that.ui.typeAttrFilter.removeClass("active"),
  160. that.ui.typeAttrFilter.prop("disabled", !0));
  161. }, tagCheck = function(filterObj, type) {
  162. var filterAddOn = Enums.addOnClassification.filter(function(a) {
  163. a !== Enums.addOnClassification[0];
  164. });
  165. that.value.tag && !_.contains(filterAddOn, that.value.tag) ? (that.ui.tagAttrFilter.prop("disabled", !1),
  166. filterObj && filterObj.length ? that.ui.tagAttrFilter.addClass("active") : that.ui.tagAttrFilter.removeClass("active")) : (that.ui.tagAttrFilter.removeClass("active"),
  167. that.ui.tagAttrFilter.prop("disabled", !0));
  168. };
  169. _.each(filtertype, function(type) {
  170. var filterObj = that.searchTableFilters[type];
  171. "entityFilters" == type && typeCheck(filterObj[that.value.type], type), "tagFilters" == type && tagCheck(filterObj[that.value.tag], type);
  172. });
  173. },
  174. checkForButtonVisiblity: function(e, options) {
  175. var that = this, isBasicSearch = "basic" == this.type;
  176. if (e && e.currentTarget) {
  177. var $el = $(e.currentTarget), isTagEl = "tagLOV" == $el.data("id"), isTermEl = "termLOV" == $el.data("id"), isTypeEl = "typeLOV" == $el.data("id"), select2Data = $el.select2("data");
  178. if ("change" == e.type && select2Data) {
  179. var value = _.isEmpty(select2Data) ? select2Data : _.first(select2Data).id, key = "tag", filterType = isBasicSearch ? "tagFilters" : null, value = value && value.length ? value : null;
  180. if (isTagEl || (key = isTermEl ? "term" : "type", isBasicSearch && (filterType = isTypeEl ? "entityFilters" : null)),
  181. this.value) {
  182. if (this.value[key] !== value || !value && !this.value[key]) {
  183. var temp = {};
  184. temp[key] = value, _.extend(this.value, temp), _.isUndefined(options) && (this.value.pageOffset = 0),
  185. _.extend(this.query[this.type], temp);
  186. } else if (isBasicSearch) {
  187. if (filterType) {
  188. var filterObj = this.searchTableFilters[filterType];
  189. filterObj && this.value[key] && (this.searchTableFilters[filterType][this.value[key]] = this.value[filterType] ? this.value[filterType] : null);
  190. }
  191. if (this.value.type) if (this.value.attributes) {
  192. var attributes = _.sortBy(this.value.attributes.split(",")), tableColumn = this.searchTableColumns[this.value.type];
  193. _.isEmpty(this.searchTableColumns) || !tableColumn ? this.searchTableColumns[this.value.type] = attributes : tableColumn.join(",") !== attributes.join(",") && (this.searchTableColumns[this.value.type] = attributes);
  194. } else this.searchTableColumns[this.value.type] && (this.searchTableColumns[this.value.type] = void 0);
  195. }
  196. isBasicSearch && filterType && this.makeFilterButtonActive(filterType);
  197. } else isBasicSearch && (this.ui.tagAttrFilter.prop("disabled", !0), this.ui.typeAttrFilter.prop("disabled", !0));
  198. }
  199. }
  200. var value = this.ui.searchInput.val() || _.first($(this.ui.typeLov).select2("data")).id;
  201. if (!this.dsl && _.isEmpty(value)) {
  202. var termData = _.first($(this.ui.termLov).select2("data"));
  203. value = _.first($(this.ui.tagLov).select2("data")).id || (termData ? termData.id : "");
  204. }
  205. value && value.length ? (this.ui.searchBtn.removeAttr("disabled"), setTimeout(function() {
  206. that.ui.searchInput.focus();
  207. }, 0)) : this.ui.searchBtn.attr("disabled", "true");
  208. },
  209. onRender: function() {
  210. this.initializeValues();
  211. },
  212. updateQueryObject: function(param) {
  213. param && param.searchType && (this.type = param.searchType), _.extend(this.query[this.type], "dsl" == this.type ? {
  214. query: null,
  215. type: null,
  216. pageOffset: null,
  217. pageLimit: null
  218. } : {
  219. query: null,
  220. type: null,
  221. tag: null,
  222. term: null,
  223. attributes: null,
  224. tagFilters: null,
  225. pageOffset: null,
  226. pageLimit: null,
  227. entityFilters: null,
  228. includeDE: null
  229. }, param);
  230. },
  231. onRefreshButton: function() {
  232. var that = this, apiCount = 2, updateSearchList = function() {
  233. if (0 === apiCount) {
  234. that.initializeValues();
  235. var checkURLValue = Utils.getUrlState.getQueryParams(that.url);
  236. that.searchVent && (_.has(checkURLValue, "tag") || _.has(checkURLValue, "type") || _.has(checkURLValue, "query")) && that.searchVent.trigger("search:refresh");
  237. }
  238. };
  239. this.metricCollection.fetch({
  240. complete: function() {
  241. --apiCount, that.entityCountObj = _.first(that.metricCollection.toJSON()), updateSearchList();
  242. }
  243. }), this.typeHeaders.fetch({
  244. silent: !0,
  245. complete: function() {
  246. --apiCount, updateSearchList();
  247. }
  248. });
  249. },
  250. advancedInfo: function(e) {
  251. require([ "views/search/AdvancedSearchInfoView", "modules/Modal" ], function(AdvancedSearchInfoView, Modal) {
  252. var view = new AdvancedSearchInfoView(), modal = new Modal({
  253. title: "高级搜索查询",
  254. content: view,
  255. okCloses: !0,
  256. showFooter: !0,
  257. allowCancel: !1
  258. }).open();
  259. view.on("closeModal", function() {
  260. modal.trigger("cancel");
  261. });
  262. });
  263. },
  264. openAttrFilter: function(filterType) {
  265. var that = this;
  266. require([ "views/search/SearchQueryView" ], function(SearchQueryView) {
  267. that.attrModal = new SearchQueryView({
  268. value: that.value,
  269. tag: "tag" === filterType,
  270. type: "type" === filterType,
  271. searchVent: that.searchVent,
  272. typeHeaders: that.typeHeaders,
  273. entityDefCollection: that.entityDefCollection,
  274. enumDefCollection: that.enumDefCollection,
  275. classificationDefCollection: that.classificationDefCollection,
  276. businessMetadataDefCollection: that.businessMetadataDefCollection,
  277. searchTableFilters: that.searchTableFilters
  278. }), that.attrModal.on("ok", function(scope, e) {
  279. that.okAttrFilterButton(e);
  280. });
  281. });
  282. },
  283. okAttrFilterButton: function(e) {
  284. function getIdFromRuleObject(rule) {
  285. return _.map(rule.rules, function(obj, key) {
  286. return _.has(obj, "condition") ? getIdFromRuleObject(obj) : col.push(obj.id);
  287. }), col;
  288. }
  289. var that = this, isTag = !!this.attrModal.tag, filtertype = isTag ? "tagFilters" : "entityFilters", queryBuilderRef = this.attrModal.RQueryBuilder.currentView.ui.builder, col = [];
  290. if (queryBuilderRef.data("queryBuilder")) var rule = queryBuilderRef.queryBuilder("getRules");
  291. if (rule) {
  292. var ruleUrl = CommonViewFunction.attributeFilter.generateUrl({
  293. value: rule,
  294. formatedDateToLong: !0
  295. });
  296. if (this.searchTableFilters[filtertype][isTag ? this.value.tag : this.value.type] = ruleUrl,
  297. this.makeFilterButtonActive(filtertype), !isTag && this.value && this.value.type && this.searchTableColumns && (this.searchTableColumns[this.value.type] || (this.searchTableColumns[this.value.type] = [ "selected", "name", "owner", "description", "tag", "typeName" ]),
  298. this.searchTableColumns[this.value.type] = _.sortBy(_.union(this.searchTableColumns[this.value.type], getIdFromRuleObject(rule)))),
  299. rule.rules) {
  300. if (!isTag && !that.tagEntityCheck) {
  301. var state = _.find(rule.rules, {
  302. id: "__state"
  303. });
  304. state ? (that.typeEntityCheck = !("ACTIVE" === state.value && "=" === state.operator || "DELETED" === state.value && "!=" === state.operator),
  305. that.value.includeDE = that.typeEntityCheck) : that.typeEntityCheck && (that.typeEntityCheck = !1,
  306. that.tagEntityCheck || (that.value.includeDE = !1));
  307. }
  308. if (isTag && !that.typeEntityCheck) {
  309. var entityStatus = _.find(rule.rules, {
  310. id: "__entityStatus"
  311. });
  312. entityStatus ? (that.tagEntityCheck = !("ACTIVE" === entityStatus.value && "=" === entityStatus.operator || "DELETED" === entityStatus.value && "!=" === entityStatus.operator),
  313. that.value.includeDE = that.tagEntityCheck) : that.tagEntityCheck && (that.tagEntityCheck = !1,
  314. that.typeEntityCheck || (that.value.includeDE = !1));
  315. }
  316. }
  317. this.attrModal.modal.close(), $(e.currentTarget).hasClass("search") && this.findSearchResult();
  318. }
  319. },
  320. manualRender: function(paramObj) {
  321. paramObj && (this.value = paramObj), this.updateQueryObject(paramObj), this.renderTypeTagList(),
  322. this.setValues(paramObj);
  323. },
  324. getFilterBox: function() {
  325. var serviceStr = "", serviceArr = [], that = this;
  326. this.typeHeaders.fullCollection.each(function(model) {
  327. var serviceType = model.toJSON().serviceType;
  328. serviceType && serviceArr.push(serviceType);
  329. }), _.each(_.uniq(serviceArr), function(service) {
  330. serviceStr += '<li><div class="pretty p-switch p-fill"><input type="checkbox" class="pull-left" data-value="' + service + '" value="" ' + (_.contains(that.selectedFilter[that.type], service) ? "checked" : "") + '/><div class="state p-primary"><label>' + service.toUpperCase() + "</label></div></div></li>";
  331. });
  332. var templt = serviceStr + '<hr class="hr-filter"/><div class="text-right"><div class="divider"></div><button class="btn btn-action btn-sm filterDone">Done</button></div>';
  333. return templt;
  334. },
  335. renderTypeTagList: function(options) {
  336. var that = this, serviceTypeToBefiltered = options && options.filterList, isTypeOnly = options && options.isTypeOnly;
  337. this.selectedFilter[this.type].length && (serviceTypeToBefiltered = this.selectedFilter[this.type]),
  338. this.ui.typeLov.empty();
  339. var typeStr = "<option></option>", tagStr = typeStr, foundNewClassification = !1;
  340. if (this.typeHeaders.fullCollection.each(function(model) {
  341. var name = Utils.getName(model.toJSON(), "name");
  342. if ("ENTITY" == model.get("category") && (!serviceTypeToBefiltered || !serviceTypeToBefiltered.length || _.contains(serviceTypeToBefiltered, model.get("serviceType")))) {
  343. var entityCount = (that.entityCountObj.entity.entityActive[name] || 0) + (that.entityCountObj.entity.entityDeleted[name] || 0);
  344. typeStr += '<option value="' + name + '" data-name="' + name + '">' + name + " " + (entityCount ? "(" + _.numberFormatWithComma(entityCount) + ")" : "") + "</option>";
  345. }
  346. if (void 0 == isTypeOnly && "CLASSIFICATION" == model.get("category")) {
  347. var tagEntityCount = that.entityCountObj.tag.tagEntities[name];
  348. that.value && that.value.tag && name === that.value.tag && (foundNewClassification = !0),
  349. tagStr += '<option value="' + name + '" data-name="' + name + '">' + name + " " + (tagEntityCount ? "(" + _.numberFormatWithComma(tagEntityCount) + ")" : "") + "</option>";
  350. }
  351. }), "dsl" !== this.type && _.each(Enums.addOnEntities, function(entity) {
  352. typeStr += '<option value="' + entity + '" data-name="' + entity + '">' + entity + "</option>";
  353. }), !foundNewClassification && that.value && that.value.tag) {
  354. var classificationValue = decodeURIComponent(that.value.tag);
  355. tagStr += '<option value="' + classificationValue + '" data-name="' + classificationValue + '">' + classificationValue + "</option>";
  356. }
  357. _.isUndefined(isTypeOnly) && (that.value && _.each(Enums.addOnClassification, function(classificationName) {
  358. classificationName !== that.value.tag && (tagStr += '<option value="' + classificationName + '" data-name="' + classificationName + '">' + classificationName + "</option>");
  359. }), that.ui.tagLov.html(tagStr), this.ui.tagLov.select2({
  360. placeholder: "请选择分类",
  361. allowClear: !0,
  362. tags: !0,
  363. createTag: function(tag) {
  364. if (tag.term.indexOf("*") != -1) return {
  365. id: tag.term,
  366. text: tag.term,
  367. isNew: !0
  368. };
  369. }
  370. })), that.ui.typeLov.html(typeStr);
  371. var typeLovSelect2 = this.ui.typeLov.select2({
  372. placeholder: "请选择类型",
  373. dropdownAdapter: $.fn.select2.amd.require("ServiceTypeFilterDropdownAdapter"),
  374. allowClear: !0,
  375. getFilterBox: this.getFilterBox.bind(this),
  376. onFilterSubmit: function(options) {
  377. that.selectedFilter[that.type] = options.filterVal, that.renderTypeTagList({
  378. filterList: options.filterVal,
  379. isTypeOnly: !0
  380. });
  381. }
  382. });
  383. if (typeLovSelect2.on("select2:close", function() {
  384. typeLovSelect2.trigger("hideFilter");
  385. }), typeLovSelect2 && isTypeOnly && typeLovSelect2.select2("open").trigger("change", {
  386. manual: !0
  387. }), that.setInitialEntityVal) {
  388. var defaultEntity = Enums.addOnEntities[0];
  389. that.value.type = defaultEntity, that.ui.typeLov.val(defaultEntity, null);
  390. }
  391. },
  392. renderTermList: function() {
  393. this.glossaryTermArray = null;
  394. var that = this, getTypeAheadData = function(data, params) {
  395. var dataList = data.entities, foundOptions = [];
  396. return _.each(dataList, function(obj) {
  397. obj && (obj.guid && (obj.id = obj.attributes.qualifiedName), foundOptions.push(obj));
  398. }), foundOptions;
  399. };
  400. this.ui.termLov.select2({
  401. placeholder: "搜索术语",
  402. allowClear: !0,
  403. ajax: {
  404. url: UrlLinks.searchApiUrl("attribute"),
  405. dataType: "json",
  406. delay: 250,
  407. data: function(params) {
  408. return {
  409. attrValuePrefix: params.term,
  410. typeName: "AtlasGlossaryTerm",
  411. limit: 10,
  412. offset: 0
  413. };
  414. },
  415. processResults: function(data, params) {
  416. return that.glossaryTermArray = getTypeAheadData(data, params), {
  417. results: getTypeAheadData(data, params)
  418. };
  419. },
  420. cache: !0
  421. },
  422. templateResult: function(option) {
  423. var name = Utils.getName(option, "qualifiedName");
  424. return "-" === name ? option.text : name;
  425. },
  426. templateSelection: function(option) {
  427. var name = Utils.getName(option, "qualifiedName");
  428. return "-" === name ? option.text : name;
  429. },
  430. escapeMarkup: function(markup) {
  431. return markup;
  432. },
  433. minimumInputLength: 1
  434. });
  435. },
  436. setValues: function(paramObj) {
  437. var that = this;
  438. paramObj && (this.value = paramObj), this.value && (this.ui.searchInput.val(this.value.query || ""),
  439. "true" == this.value.dslChecked ? this.ui.searchType.prop("checked") || this.ui.searchType.prop("checked", !0).trigger("change") : this.ui.searchType.prop("checked") && this.ui.searchType.prop("checked", !1).trigger("change"),
  440. this.ui.typeLov.val(this.value.type), this.ui.typeLov.data("select2") && (this.ui.typeLov.val() !== this.value.type ? (this.value.type = null,
  441. this.ui.typeLov.val("").trigger("change", {
  442. manual: !0
  443. })) : this.ui.typeLov.trigger("change", {
  444. manual: !0
  445. })), this.dsl || (this.ui.tagLov.val(this.value.tag), this.ui.tagLov.data("select2") && (this.ui.tagLov.val() !== this.value.tag ? (this.value.tag = null,
  446. this.ui.tagLov.val("").trigger("change", {
  447. manual: !0
  448. })) : this.ui.tagLov.trigger("change", {
  449. manual: !0
  450. })), this.value.term && this.ui.termLov.append('<option value="' + _.escape(this.value.term) + '" selected="selected">' + _.escape(this.value.term) + "</option>"),
  451. this.ui.termLov.data("select2") && (this.ui.termLov.val() !== this.value.term ? (this.value.term = null,
  452. this.ui.termLov.val("").trigger("change", {
  453. manual: !0
  454. })) : this.ui.termLov.trigger("change", {
  455. manual: !0
  456. }))), setTimeout(function() {
  457. that.ui.searchInput.focus();
  458. }, 0));
  459. },
  460. findSearchResult: function() {
  461. this.triggerSearch(this.ui.searchInput.val());
  462. },
  463. getSearchedTermGuid: function() {
  464. var searchedTerm = this.ui.termLov.select2("val"), searchedTermGuid = null;
  465. return searchedTerm && this.glossaryTermArray.find(function(obj) {
  466. searchedTerm === obj.id && (searchedTermGuid = obj.guid);
  467. }), searchedTermGuid;
  468. },
  469. triggerSearch: function(value) {
  470. var params = {
  471. searchType: this.type,
  472. dslChecked: this.ui.searchType.is(":checked"),
  473. tagFilters: null,
  474. entityFilters: null
  475. }, typeLovValue = this.ui.typeLov.find(":selected").data("name"), tagLovValue = this.ui.tagLov.find(":selected").data("name") || this.ui.tagLov.val(), termLovValue = this.ui.termLov.select2("val");
  476. if (params.type = typeLovValue || null, !this.dsl) {
  477. params.tag = tagLovValue || null, params.term = termLovValue || null, params.guid = this.getSearchedTermGuid();
  478. var entityFilterObj = this.searchTableFilters.entityFilters, tagFilterObj = this.searchTableFilters.tagFilters;
  479. if (params.includeDE = !1, params.excludeST = !1, params.excludeSC = !1, this.value) {
  480. this.value.tag && (params.tagFilters = tagFilterObj[this.value.tag]), this.value.type && (params.entityFilters = entityFilterObj[this.value.type]);
  481. var columnList = this.value.type && this.searchTableColumns ? this.searchTableColumns[this.value.type] : null;
  482. columnList && (params.attributes = columnList.join(",")), params.includeDE = !_.isUndefinedNull(this.value.includeDE) && this.value.includeDE,
  483. params.excludeST = !_.isUndefinedNull(this.value.excludeST) && this.value.excludeST,
  484. params.excludeSC = !_.isUndefinedNull(this.value.excludeSC) && this.value.excludeSC;
  485. }
  486. }
  487. this.value && !_.isUndefinedNull(this.value.pageLimit) && (params.pageLimit = this.value.pageLimit),
  488. this.value && !_.isUndefinedNull(this.value.pageOffset) && (_.isUndefinedNull(this.query[this.type]) || this.query[this.type].query == value ? params.pageOffset = this.value.pageOffset : params.pageOffset = 0),
  489. params.query = value || null, _.extend(this.query[this.type], params), Utils.setUrl({
  490. url: "#!/search/searchResult",
  491. urlParams: _.extend({}, this.query[this.type]),
  492. mergeBrowserUrl: !1,
  493. trigger: !0,
  494. updateTabState: !0
  495. });
  496. },
  497. dslFulltextToggle: function(e) {
  498. var paramObj = Utils.getUrlState.getQueryParams();
  499. paramObj && this.type == paramObj.searchType && this.updateQueryObject(paramObj),
  500. e.currentTarget.checked ? (this.type = "dsl", this.dsl = !0, this.$(".typeFilterBtn,.tagBox,.termBox,.basicSaveSearch").hide(),
  501. this.$(".typeFilter").addClass("col-sm-12"), this.$(".typeFilter").removeClass("col-sm-10"),
  502. // this.$(".advanceSaveSearch").show(), this.$(".searchText").text("Search By Query"),
  503. this.$(".advanceSaveSearch").show(), this.$(".searchText").text("根据查询搜索"),
  504. // this.ui.searchInput.attr("placeholder", 'Search By Query eg. where name="sales_fact"')) : (this.$(".typeFilter").addClass("col-sm-10"),
  505. this.ui.searchInput.attr("placeholder", '根据查询搜索,例如:where name="sales_fact"')) : (this.$(".typeFilter").addClass("col-sm-10"),
  506. this.$(".typeFilter").removeClass("col-sm-12"), this.$(".typeFilterBtn,.tagBox,.termBox,.basicSaveSearch").show(),
  507. this.$(".advanceSaveSearch").hide(), this.dsl = !1, this.type = "basic", this.$(".searchText").text("根据语句搜索"),
  508. this.ui.searchInput.attr("placeholder", "根据语句搜索")), Utils.getUrlState.isSearchTab() && Utils.setUrl({
  509. url: "#!/search/searchResult",
  510. urlParams: _.extend(this.query[this.type], {
  511. searchType: this.type,
  512. dslChecked: this.ui.searchType.is(":checked")
  513. }),
  514. mergeBrowserUrl: !1,
  515. trigger: !0,
  516. updateTabState: !0
  517. });
  518. },
  519. clearSearchData: function() {
  520. this.selectedFilter[this.type] = [], this.renderTypeTagList(), this.updateQueryObject(),
  521. this.ui.typeLov.val("").trigger("change"), this.ui.tagLov.val("").trigger("change"),
  522. this.ui.searchInput.val("");
  523. var type = "basicSaveSearch";
  524. "dsl" == this.type && (type = "advanceSaveSearch"), this.$("." + type + " .saveSearchList").find("li.active").removeClass("active"),
  525. this.$("." + type + ' [data-id="saveBtn"]').attr("disabled", !0), this.dsl || (this.searchTableFilters.tagFilters = {},
  526. this.searchTableFilters.entityFilters = {}), this.checkForButtonVisiblity(), Utils.setUrl({
  527. url: "#!/search/searchResult",
  528. urlParams: {
  529. searchType: this.type,
  530. dslChecked: this.ui.searchType.is(":checked")
  531. },
  532. mergeBrowserUrl: !1,
  533. trigger: !0
  534. });
  535. }
  536. });
  537. return SearchLayoutView;
  538. });