BusinessMetadataTreeLayoutView.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. define([ "require", "hbs!tmpl/search/tree/BusinessMetadataTreeLayoutView_tmpl", "utils/Utils", "utils/Messages", "utils/Globals", "utils/UrlLinks", "utils/CommonViewFunction", "collection/VSearchList", "collection/VGlossaryList", "utils/Enums", "jstree" ], function(require, BusinessMetadataTreeLayoutViewTmpl, Utils, Messages, Globals, UrlLinks, CommonViewFunction, VSearchList, VGlossaryList, Enums) {
  2. "use strict";
  3. var BusinessMetadataTreeLayoutView = Marionette.LayoutView.extend({
  4. template: BusinessMetadataTreeLayoutViewTmpl,
  5. regions: {},
  6. ui: {
  7. refreshTree: '[data-id="refreshTree"]',
  8. businessMetadataSearchTree: '[data-id="businessMetadataSearchTree"]',
  9. createBusinessMetadata: '[data-id="createBusinessMetadata"]',
  10. businessMetadataTreeLoader: '[data-id="businessMetadataTreeLoader"]'
  11. },
  12. templateHelpers: function() {
  13. return {
  14. apiBaseUrl: UrlLinks.apiBaseUrl
  15. };
  16. },
  17. events: function() {
  18. var events = {}, that = this;
  19. return events["click " + this.ui.refreshTree] = function(e) {
  20. that.changeLoaderState(!0), that.ui.refreshTree.attr("disabled", !0).tooltip("hide"),
  21. e.stopPropagation(), that.refresh();
  22. }, events["click " + this.ui.createBusinessMetadata] = function(e) {
  23. e.stopPropagation(), that.triggerUrl("#!/administrator?tabActive=bm");
  24. }, events;
  25. },
  26. initialize: function(options) {
  27. this.options = options, _.extend(this, _.pick(options, "typeHeaders", "guid", "searchVent", "entityDefCollection", "enumDefCollection", "businessMetadataDefCollection", "searchTableColumns", "searchTableFilters", "metricCollection")),
  28. this.bindEvents();
  29. },
  30. onRender: function() {
  31. this.changeLoaderState(!0), this.renderBusinessMetadataTree(), this.changeLoaderState(!1);
  32. },
  33. bindEvents: function() {
  34. var that = this;
  35. this.listenTo(this.businessMetadataDefCollection.fullCollection, "reset add remove", function() {
  36. this.ui.businessMetadataSearchTree.jstree(!0) ? that.ui.businessMetadataSearchTree.jstree(!0).refresh() : this.renderBusinessMetadataTree();
  37. }, this), $("body").on("click", ".businessMetadataPopoverOptions li", function(e) {
  38. that.$(".businessMetadataPopover").popover("hide"), that[$(this).find("a").data("fn") + "BusinessMetadata"](e);
  39. });
  40. },
  41. changeLoaderState: function(showLoader) {
  42. showLoader ? (this.ui.businessMetadataSearchTree.hide(), this.ui.businessMetadataTreeLoader.show()) : (this.ui.businessMetadataSearchTree.show(),
  43. this.ui.businessMetadataTreeLoader.hide());
  44. },
  45. createBusinessMetadataAction: function() {
  46. Utils.generatePopover({
  47. el: this.$el,
  48. contentClass: "businessMetadataPopoverOptions",
  49. popoverOptions: {
  50. selector: ".businessMetadataPopover",
  51. content: function() {
  52. var liString = ($(this).data("detail"), "<li><i class='fa fa-list-alt'></i><a href='javascript:void(0)' data-fn='onViewEdit'>View/Edit</a></li><li><i class='fa fa-search'></i><a href='javascript:void(0)' data-fn='onSelectedSearch'>Search</a></li>");
  53. return "<ul>" + liString + "</ul>";
  54. }
  55. }
  56. });
  57. },
  58. renderBusinessMetadataTree: function() {
  59. this.generateSearchTree({
  60. $el: this.ui.businessMetadataSearchTree
  61. });
  62. },
  63. manualRender: function(options) {
  64. _.extend(this, options), Utils.getUrlState.isBMDetailPage() && this.guid ? this.ui.businessMetadataSearchTree.jstree(!0).select_node(this.guid) : (this.ui.businessMetadataSearchTree.jstree(!0).deselect_all(),
  65. this.guid = null);
  66. },
  67. onNodeSelect: function(nodeData) {
  68. var options = nodeData.node.original, url = "#!/administrator/businessMetadata", trigger = !0, queryParams = Utils.getUrlState.getQueryParams();
  69. void 0 === options.parent && (url += "/" + options.id), queryParams && "bm" === queryParams.from && Utils.getUrlState.getQueryUrl().queyParams[0] === url && (trigger = !1),
  70. trigger && this.triggerUrl(url);
  71. },
  72. onViewEditBusinessMetadata: function() {
  73. var selectedNode = this.ui.businessMetadataSearchTree.jstree("get_selected", !0);
  74. if (selectedNode && selectedNode[0]) {
  75. selectedNode = selectedNode[0];
  76. var url = "#!/administrator?tabActive=bm";
  77. selectedNode.parent && selectedNode.original && selectedNode.original.name && (url += "&ns=" + selectedNode.parent + "&nsa=" + selectedNode.original.name,
  78. this.triggerUrl(url));
  79. }
  80. },
  81. triggerUrl: function(url) {
  82. Utils.setUrl({
  83. url: url,
  84. mergeBrowserUrl: !1,
  85. trigger: !0,
  86. updateTabState: !0
  87. });
  88. },
  89. refresh: function(options) {
  90. var that = this;
  91. this.businessMetadataDefCollection.fetch({
  92. silent: !0,
  93. complete: function() {
  94. that.businessMetadataDefCollection.fullCollection.comparator = function(model) {
  95. return model.get("name").toLowerCase();
  96. }, that.businessMetadataDefCollection.fullCollection.sort({
  97. silent: !0
  98. }), that.ui.businessMetadataSearchTree.jstree(!0).refresh(), that.changeLoaderState(!1),
  99. that.ui.refreshTree.attr("disabled", !1);
  100. }
  101. });
  102. },
  103. getBusinessMetadataTree: function(options) {
  104. var that = this, businessMetadataList = [], namsSpaceTreeData = that.businessMetadataDefCollection.fullCollection.models, generateNode = function(nodeOptions, attrNode) {
  105. var nodeStructure = (attrNode ? null : nodeOptions.get("attributeDefs"), {
  106. text: attrNode ? _.escape(nodeOptions.name) : _.escape(nodeOptions.get("name")),
  107. name: attrNode ? _.escape(nodeOptions.name) : _.escape(nodeOptions.get("name")),
  108. type: "businessMetadata",
  109. id: attrNode ? _.escape(nodeOptions.name) : nodeOptions.get("guid"),
  110. icon: attrNode ? "fa fa-file-o" : "fa fa-folder-o",
  111. children: [],
  112. state: {
  113. selected: nodeOptions.get("guid") === that.guid
  114. },
  115. gType: "BusinessMetadata",
  116. model: nodeOptions
  117. });
  118. return nodeStructure;
  119. };
  120. _.each(namsSpaceTreeData, function(filterNode) {
  121. businessMetadataList.push(generateNode(filterNode));
  122. });
  123. return businessMetadataList;
  124. },
  125. generateSearchTree: function(options) {
  126. var $el = options && options.$el, that = (options && options.type, this), getEntityTreeConfig = function(opt) {
  127. return {
  128. plugins: [ "search", "core", "sort", "conditionalselect", "changed", "wholerow", "node_customize" ],
  129. conditionalselect: function(node) {
  130. var type = node.original.type;
  131. return "businessMetadataFolder" != type || !node.children.length;
  132. },
  133. state: {
  134. opened: !0
  135. },
  136. search: {
  137. show_only_matches: !0,
  138. case_sensitive: !1
  139. },
  140. node_customize: {
  141. default: function(el, node) {
  142. var aTag = $(el).find(">a.jstree-anchor");
  143. aTag.append("<span class='tree-tooltip'>" + aTag.text() + "</span>"), "#" === node.parent ? $(el).append('<div class="tools"><i class="fa"></i></div>') : $(el).append('<div class="tools"><i class="fa fa-ellipsis-h businessMetadataPopover" rel="popover"></i></div>');
  144. }
  145. },
  146. core: {
  147. multiple: !1,
  148. data: function(node, cb) {
  149. "#" === node.id && cb(that.getBusinessMetadataTree());
  150. }
  151. }
  152. };
  153. };
  154. $el.jstree(getEntityTreeConfig({
  155. type: ""
  156. })).on("open_node.jstree", function(e, data) {
  157. that.isTreeOpen = !0;
  158. }).on("select_node.jstree", function(e, data) {
  159. that.onNodeSelect(data);
  160. }).on("search.jstree", function(nodes, str, res) {
  161. 0 === str.nodes.length ? ($el.jstree(!0).hide_all(), $el.parents(".panel").addClass("hide")) : $el.parents(".panel").removeClass("hide");
  162. }).on("hover_node.jstree", function(nodes, str, res) {
  163. var aFilter = that.$("#" + str.node.a_attr.id), filterOffset = aFilter.find(">.jstree-icon").offset();
  164. that.$(".tree-tooltip").removeClass("show"), setTimeout(function() {
  165. aFilter.hasClass("jstree-hovered") && ($(":hover").last().hasClass("jstree-hovered") || $(":hover").last().parent().hasClass("jstree-hovered")) && filterOffset.top && filterOffset.left && aFilter.find(">span.tree-tooltip").css({
  166. top: "calc(" + filterOffset.top + "px - 45px)",
  167. left: "24px"
  168. }).addClass("show");
  169. }, 1200);
  170. }).on("dehover_node.jstree", function(nodes, str, res) {
  171. that.$(".tree-tooltip").removeClass("show");
  172. });
  173. }
  174. });
  175. return BusinessMetadataTreeLayoutView;
  176. });