PropagationPropertyModal.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. define([ "require", "hbs!tmpl/graph/PropagationPropertyModalView_tmpl", "models/VRelationship", "models/VEntity", "modules/Modal", "utils/Utils", "utils/UrlLinks", "utils/Messages" ], function(require, PropagationPropertyModalViewTmpl, VRelationship, VEntity, Modal, Utils, UrlLinks, Messages) {
  2. "use strict";
  3. var PropogationPropertyModal = Backbone.Marionette.CompositeView.extend({
  4. template: PropagationPropertyModalViewTmpl,
  5. templateHelpers: function() {},
  6. regions: {},
  7. ui: {
  8. propagationOptions: '[data-id="propagationOptions"]',
  9. edgeDetailName: '[data-id="edgeDetailName"]',
  10. propagationState: "[data-id='propagationState']",
  11. entityClick: "[data-id='entityClick']",
  12. editPropagationType: 'input[name="editPropagationType"]',
  13. PropagatedClassificationTable: "[data-id='PropagatedClassificationTable']"
  14. },
  15. events: function() {
  16. var events = {}, that = this;
  17. return events["change " + this.ui.propagationOptions] = function() {
  18. this.modalEdited = !0, this.modal.$el.find("button.ok").attr("disabled", !1);
  19. }, events["click " + this.ui.editPropagationType] = function(e) {
  20. this.modalEdited === !0 && (e.preventDefault(), that.notifyModal());
  21. }, events["change " + this.ui.editPropagationType] = function(e) {
  22. e.target.checked ? (this.showPropagatedClassificationTable(), this.viewType = "table") : (this.showEditPropagation(),
  23. this.viewType = "flow");
  24. }, events["click " + this.ui.entityClick] = function(e) {
  25. var that = this, url = "", notifyObj = {
  26. modal: !0,
  27. text: "Are you sure you want to navigate away from this page ?",
  28. ok: function(argument) {
  29. that.modal.trigger("cancel"), Utils.setUrl({
  30. url: url,
  31. mergeBrowserUrl: !1,
  32. trigger: !0
  33. });
  34. },
  35. cancel: function(argument) {}
  36. }, $el = $(e.currentTarget), guid = $el.parents("tr").data("entityguid");
  37. url = $el.hasClass("entityName") ? "#!/detailPage/" + guid + "?tabActive=lineage" : "#!/tag/tagAttribute/" + $el.data("name"),
  38. Utils.notifyConfirm(notifyObj);
  39. }, events["change " + this.ui.propagationState] = function(e) {
  40. this.modalEdited = !0, this.modal.$el.find("button.ok").attr("disabled", !1);
  41. var $el = $(e.currentTarget).parents("tr"), entityguid = $el.data("entityguid"), classificationName = $el.find("[data-name]").data("name");
  42. e.target.checked ? this.propagatedClassifications = _.reject(this.propagatedClassifications, function(val, key) {
  43. if (val.entityGuid == entityguid && classificationName == val.typeName) return that.blockedPropagatedClassifications.push(val),
  44. !0;
  45. }) : this.blockedPropagatedClassifications = _.reject(this.blockedPropagatedClassifications, function(val, key) {
  46. if (val.entityGuid == entityguid && classificationName == val.typeName) return that.propagatedClassifications.push(val),
  47. !0;
  48. });
  49. }, events;
  50. },
  51. initialize: function(options) {
  52. _.extend(this, _.pick(options, "edgeInfo", "relationshipId", "lineageData", "apiGuid", "detailPageFetchCollection")),
  53. this.entityModel = new VRelationship(), this.VEntityModel = new VEntity(), this.modalEdited = !1,
  54. this.viewType = "flow";
  55. var that = this, modalObj = {
  56. title: "启用/禁用 传播",
  57. content: this,
  58. okText: "更新",
  59. okCloses: !1,
  60. cancelText: "取消",
  61. mainClass: "modal-lg",
  62. allowCancel: !0
  63. };
  64. this.modal = new Modal(modalObj), this.modal.open(), this.modal.$el.find("button.ok").attr("disabled", !0),
  65. this.on("ok", function() {
  66. that.updateRelation();
  67. }), this.on("closeModal", function() {
  68. this.modal.trigger("cancel");
  69. }), this.updateEdgeView(this.edgeInfo);
  70. },
  71. onRender: function() {},
  72. updateEdgeView: function(options) {
  73. var obj = options, fromEntity = this.lineageData.guidEntityMap[obj.fromEntityId], toEntity = this.lineageData.guidEntityMap[obj.toEntityId];
  74. fromEntity && toEntity && this.ui.edgeDetailName.html(_.escape(fromEntity.displayText) + " <span class='navigation-font'><i class='fa fa-long-arrow-right fa-color'></i></span> " + _.escape(toEntity.displayText)),
  75. obj && obj.relationshipId && (this.showLoader(), this.getEdgeEntity({
  76. id: obj.relationshipId,
  77. from: fromEntity,
  78. to: toEntity
  79. }));
  80. },
  81. getPropagationFlow: function(options) {
  82. var relationshipData = options.relationshipData, graphData = options.graphData, propagateTags = relationshipData.propagateTags;
  83. return relationshipData.end1 ? relationshipData.end1.guid == graphData.from.guid || "BOTH" == propagateTags || "NONE" == propagateTags ? propagateTags : "ONE_TO_TWO" == propagateTags ? "TWO_TO_ONE" : "ONE_TO_TWO" : propagateTags;
  84. },
  85. getEdgeEntity: function(options) {
  86. var that = this, id = options.id, from = options.from, to = options.to, enableOtherFlow = function(relationshipObj) {
  87. var isTwoToOne = !1;
  88. "BOTH" == relationshipObj.propagateTags ? that.ui.propagationOptions.find(".both").show() : (that.ui.propagationOptions.find(".both").hide(),
  89. that.edgeInfo.fromEntityId != relationshipObj.end1.guid && "ONE_TO_TWO" == relationshipObj.propagateTags ? isTwoToOne = !0 : that.edgeInfo.fromEntityId == relationshipObj.end1.guid && "TWO_TO_ONE" == relationshipObj.propagateTags && (isTwoToOne = !0),
  90. isTwoToOne ? that.ui.propagationOptions.find(".TWO_TO_ONE").show() : that.ui.propagationOptions.find(".TWO_TO_ONE").hide());
  91. }, updateValue = function(relationshipData) {
  92. var relationshipObj = relationshipData.relationship;
  93. relationshipObj && (that.$("input[name='propagateRelation'][value=" + that.getPropagationFlow({
  94. relationshipData: relationshipObj,
  95. graphData: options
  96. }) + "]").prop("checked", !0), enableOtherFlow(relationshipObj), that.showBlockedClassificationTable(relationshipData),
  97. that.hideLoader({
  98. buttonDisabled: !0
  99. }));
  100. };
  101. this.ui.propagationOptions.find("li label>span.fromName").text(from.typeName), this.ui.propagationOptions.find("li label>span.toName").text(to.typeName),
  102. id !== this.ui.propagationOptions.attr("entity-id") && (this.ui.propagationOptions.attr("entity-id", id),
  103. this.apiGuid[id] ? updateValue(this.apiGuid[id]) : (this.edgeCall && 4 != this.edgeCall.readyState && this.edgeCall.abort(),
  104. this.edgeCall = this.entityModel.getRelationship(id, {
  105. success: function(relationshipData) {
  106. that.apiGuid[relationshipData.relationship.guid] = relationshipData, updateValue(relationshipData);
  107. },
  108. cust_error: function() {
  109. that.hideLoader();
  110. }
  111. })));
  112. },
  113. updateRelation: function() {
  114. var that = this, entityId = that.ui.propagationOptions.attr("entity-id"), PropagationValue = this.$("input[name='propagateRelation']:checked").val(), relationshipProp = {};
  115. this.ui.propagationOptions.attr("propagation", PropagationValue), relationshipProp = "flow" == this.viewType ? {
  116. propagateTags: that.getPropagationFlow({
  117. relationshipData: _.extend({}, this.apiGuid[entityId].relationship, {
  118. propagateTags: PropagationValue
  119. }),
  120. graphData: {
  121. from: {
  122. guid: this.edgeInfo.fromEntityId
  123. }
  124. }
  125. })
  126. } : {
  127. blockedPropagatedClassifications: this.blockedPropagatedClassifications,
  128. propagatedClassifications: this.propagatedClassifications
  129. }, this.showLoader(), this.entityModel.saveRelationship({
  130. data: JSON.stringify(_.extend({}, that.apiGuid[entityId].relationship, relationshipProp)),
  131. success: function(relationshipData) {
  132. relationshipData && (that.hideLoader({
  133. buttonDisabled: !0
  134. }), that.modal.trigger("cancel"), that.apiGuid[relationshipData.guid] = relationshipData,
  135. that.detailPageFetchCollection(), Utils.notifySuccess({
  136. content: "Propagation flow updated succesfully."
  137. }));
  138. },
  139. cust_error: function() {
  140. that.hideLoader();
  141. }
  142. });
  143. },
  144. showBlockedClassificationTable: function(options) {
  145. var propagationStringValue = "", classificationTableValue = "", relationship = options.relationship, referredEntities = options.referredEntities, getEntityName = function(guid) {
  146. var entityObj = referredEntities[guid], name = guid;
  147. return entityObj && (name = Utils.getName(entityObj) + " (" + entityObj.typeName + ")"),
  148. "<a class='entityName' data-id='entityClick'>" + name + "</a>";
  149. }, getTableRow = function(options) {
  150. var val = options.val, fromBlockClassification = options.fromBlockClassification;
  151. return "<tr data-entityguid=" + val.entityGuid + "><td class='text-center w30'><a class='classificationName' data-id='entityClick' title='" + val.typeName + "' data-name='" + val.typeName + "''>" + val.typeName + "</a></td><td class='text-center'>" + getEntityName(val.entityGuid) + "</td><td class='text-center w30'><input type='checkbox' " + (fromBlockClassification ? "checked" : "") + " data-id='propagationState' class='input'></td></tr>";
  152. };
  153. this.blockedPropagatedClassifications = _.isUndefined(relationship.blockedPropagatedClassifications) ? [] : _.clone(relationship.blockedPropagatedClassifications),
  154. this.propagatedClassifications = _.isUndefined(relationship.propagatedClassifications) ? [] : _.clone(relationship.propagatedClassifications),
  155. _.each(this.blockedPropagatedClassifications, function(val, key) {
  156. propagationStringValue += getTableRow({
  157. val: val,
  158. fromBlockClassification: !0
  159. });
  160. }), _.each(this.propagatedClassifications, function(val, key) {
  161. propagationStringValue += getTableRow({
  162. val: val,
  163. fromBlockClassification: !1
  164. });
  165. }), classificationTableValue = "<table class='attriTable'><tr><th class='w30'>Classification</th><th>Entity Name</th><th class='w30'>Block Propagatation</th>" + propagationStringValue + "</table>",
  166. this.ui.PropagatedClassificationTable.append(_.isEmpty(propagationStringValue) ? "没有找到记录!" : classificationTableValue);
  167. },
  168. showLoader: function() {
  169. this.modal.$el.find("button.ok").showButtonLoader(), this.$(".overlay").removeClass("hide").addClass("show");
  170. },
  171. hideLoader: function(options) {
  172. var buttonDisabled = options && options.buttonDisabled;
  173. this.modal.$el.find("button.ok").hideButtonLoader(), this.modal.$el.find("button.ok").attr("disabled", !!buttonDisabled && buttonDisabled),
  174. this.$(".overlay").removeClass("show").addClass("hide");
  175. },
  176. notifyModal: function(options) {
  177. var that = this, notifyObj = {
  178. modal: !0,
  179. text: "It looks like you have edited something. If you leave before saving, your changes will be lost.",
  180. ok: function(argument) {
  181. that.viewType = that.ui.editPropagationType.is(":checked") ? "flow" : "table", that.ui.editPropagationType.prop("checked", "flow" !== that.viewType).trigger("change"),
  182. that.modal.$el.find("button.ok").attr("disabled", !0);
  183. },
  184. cancel: function(argument) {
  185. that.viewType = that.ui.editPropagationType.is(":checked") ? "table" : "flow";
  186. }
  187. };
  188. Utils.notifyConfirm(notifyObj);
  189. },
  190. showEditPropagation: function() {
  191. this.$(".editPropagation").show(), this.$(".propagatedClassificationTable").hide(),
  192. this.modal.$el.find(".modal-title").text("启用/禁用 传播");
  193. },
  194. showPropagatedClassificationTable: function() {
  195. this.$(".editPropagation").hide(), this.$(".propagatedClassificationTable").show(),
  196. this.modal.$el.find(".modal-title").text("请选择阻止传播的分类");
  197. }
  198. });
  199. return PropogationPropertyModal;
  200. });