CreateAuditTableLayoutView.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. define([ "require", "backbone", "hbs!tmpl/audit/CreateAuditTableLayoutView_tmpl", "utils/Enums", "utils/CommonViewFunction", "utils/Utils" ], function(require, Backbone, CreateAuditTableLayoutViewTmpl, Enums, CommonViewFunction, Utils) {
  2. "use strict";
  3. var CreateAuditTableLayoutView = Backbone.Marionette.LayoutView.extend({
  4. _viewName: "CreateAuditTableLayoutView",
  5. template: CreateAuditTableLayoutViewTmpl,
  6. templateHelpers: function() {
  7. return {
  8. technicalPropPanelId: this.technicalPropId,
  9. relationshipPropPanelId: this.relationshipPropId,
  10. userdefinedPropPanelId: this.userDefinedPropId
  11. };
  12. },
  13. regions: {},
  14. ui: {
  15. auditValue: "[data-id='auditValue']",
  16. name: "[data-id='name']",
  17. noData: "[data-id='noData']",
  18. tableAudit: "[data-id='tableAudit']",
  19. auditHeaderValue: "[data-id='auditHeaderValue']",
  20. attributeDetails: "[data-id='attributeDetails']",
  21. attributeCard: "[data-id='attribute-card']",
  22. labelsDetailsTable: "[data-id='labelsDetails']",
  23. labelCard: "[data-id='label-card']",
  24. customAttributeDetails: "[data-id='customAttributeDetails']",
  25. customAttrCard: "[data-id='custom-attr-card']",
  26. relationShipAttributeDetails: "[data-id='relationShipAttributeDetails']",
  27. relationshipAttrCard: "[data-id='relationship-attr-card']",
  28. attributeDetailCard: "[data-id='attributeDetail-card']",
  29. detailsAttribute: "[data-id='detailsAttribute']",
  30. panelAttrHeading: "[data-id='panel-attr-heading']",
  31. nameUpdate: "[data-id='name-update']"
  32. },
  33. events: function() {
  34. var events = {};
  35. return events;
  36. },
  37. initialize: function(options) {
  38. _.extend(this, _.pick(options, "guid", "entityModel", "action", "entity", "entityName", "attributeDefs"));
  39. var modelID = this.entityModel.cid || parseInt(100 * Math.random());
  40. this.technicalPropId = this.getRandomID(modelID), this.relationshipPropId = this.getRandomID(modelID, this.technicalPropId),
  41. this.userDefinedPropId = this.getRandomID(modelID, this.technicalPropId, this.userDefinedPropId);
  42. },
  43. bindEvents: function() {},
  44. onRender: function() {
  45. this.auditTableGenerate();
  46. },
  47. getRandomID: function(modelID, technicalPropId, relationshipPropId) {
  48. var randomIdObj = CommonViewFunction.getRandomIdAndAnchor();
  49. return randomIdObj.id = randomIdObj.id + modelID, randomIdObj.anchor = randomIdObj.anchor + modelID,
  50. randomIdObj === technicalPropId || randomIdObj === relationshipPropId ? this.getRandomID(technicalPropId, relationshipPropId) : randomIdObj;
  51. },
  52. createTableWithValues: function(tableDetails) {
  53. var attrTable = CommonViewFunction.propertyTable({
  54. scope: this,
  55. getValue: function(val, key) {
  56. return key && key.toLowerCase().indexOf("time") > 0 ? Utils.formatDate({
  57. date: val
  58. }) : val;
  59. },
  60. valueObject: tableDetails
  61. });
  62. return attrTable;
  63. },
  64. updateName: function(name) {
  65. this.ui.name.html("<span>Name: </span><span>" + name + "</span>");
  66. },
  67. noDetailsShow: function() {
  68. this.ui.noData.removeClass("hide");
  69. },
  70. auditTableGenerate: function() {
  71. var that = this, detailObj = this.entityModel.get("details");
  72. if (detailObj) if (detailObj.search(":") >= 0) {
  73. var parseDetailsObject = detailObj.split(":"), type = "", auditData = "";
  74. if (parseDetailsObject.length > 1 && (type = parseDetailsObject[0], parseDetailsObject.shift(),
  75. auditData = parseDetailsObject.join(":")), auditData.search("{") === -1) "Added labels" === type.trim() || "Deleted labels" === type.trim() ? this.updateName(auditData.trim().split(" ").join(",")) : this.updateName(auditData); else try {
  76. parseDetailsObject = JSON.parse(auditData);
  77. var skipAttribute = parseDetailsObject.typeName ? "guid" : null, name = Utils.getName(parseDetailsObject, null, skipAttribute);
  78. "-" == name && (name = _.escape(parseDetailsObject.typeName));
  79. var name = name ? name : this.entityName;
  80. if (that.updateName(name), parseDetailsObject) {
  81. var attributesDetails = $.extend(!0, {}, parseDetailsObject.attributes), customAttr = parseDetailsObject.customAttributes, labelsDetails = parseDetailsObject.labels, relationshipAttributes = parseDetailsObject.relationshipAttributes, bmAttributesDeails = that.entity.businessAttributes ? that.entity.businessAttributes[parseDetailsObject.typeName] : null;
  82. if (attributesDetails) {
  83. bmAttributesDeails && _.each(Object.keys(attributesDetails), function(key) {
  84. bmAttributesDeails[key].typeName.toLowerCase().indexOf("date") > -1 && (attributesDetails[key].length ? attributesDetails[key] = _.map(attributesDetails[key], function(dateValue) {
  85. return Utils.formatDate({
  86. date: dateValue
  87. });
  88. }) : attributesDetails[key] = Utils.formatDate({
  89. date: attributesDetails[key]
  90. }));
  91. }), that.ui.attributeDetails.removeClass("hide"), that.action.indexOf("Classification") === -1 ? that.ui.panelAttrHeading.html("Technical properties ") : that.ui.panelAttrHeading.html("Properties ");
  92. var attrTable = that.createTableWithValues(attributesDetails);
  93. that.ui.attributeCard.html(attrTable);
  94. }
  95. if (!_.isEmpty(customAttr)) {
  96. that.ui.customAttributeDetails.removeClass("hide");
  97. var customAttrTable = that.createTableWithValues(customAttr);
  98. that.ui.customAttrCard.html(customAttrTable);
  99. }
  100. if (!_.isEmpty(labelsDetails)) {
  101. this.ui.labelsDetailsTable.removeClass("hide");
  102. var labelsTable = "";
  103. _.each(labelsDetails, function(value, key, list) {
  104. labelsTable += "<label class='label badge-default'>" + value + "</label>";
  105. }), that.ui.labelCard.html(labelsTable);
  106. }
  107. if (!_.isEmpty(relationshipAttributes)) {
  108. that.ui.relationShipAttributeDetails.removeClass("hide");
  109. var relationshipAttrTable = that.createTableWithValues(relationshipAttributes);
  110. that.ui.relationshipAttrCard.html(relationshipAttrTable);
  111. }
  112. if (!(attributesDetails || customAttr || labelsDetails || relationshipAttributes)) {
  113. that.ui.detailsAttribute.removeClass("hide");
  114. var attrDetailTable = that.createTableWithValues(parseDetailsObject);
  115. that.ui.attributeDetailCard.html(attrDetailTable);
  116. }
  117. } else that.noDetailsShow();
  118. } catch (err) {
  119. if (_.isArray(parseDetailsObject)) var name = _.escape(parseDetailsObject[0]);
  120. that.updateName(name), that.noDetailsShow();
  121. }
  122. } else "Deleted entity" != detailObj && "Purged entity" != detailObj || (this.entityName ? this.updateName(this.entityName) : this.ui.name.hide() && this.ui.noData.removeClass("hide"));
  123. }
  124. });
  125. return CreateAuditTableLayoutView;
  126. });