JoinPopupView.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /**
  2. * Licensed Materials - Property of IBM IBM Cognos Products: Modeling UI (C) Copyright IBM Corp. 2015, 2019
  3. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP
  4. * Schedule Contract with IBM Corp.
  5. */
  6. define([
  7. 'bi/glass/app/util/View',
  8. 'underscore',
  9. 'jquery',
  10. '../../StringResourcesBridge',
  11. 'text!./templates/JoinPopupView.html',
  12. 'bi/commons/utils/ContentFormatter',
  13. '../../InternalBridge'
  14. ], function(BaseView, _, $, resources, Template, ContentFormatter, InternalBridge) {
  15. var JoinPopupView = BaseView.extend({
  16. templateString: Template,
  17. init: function(attributes) {
  18. JoinPopupView.inherited('init', this, arguments);
  19. _.extend(this, attributes);
  20. this.isMultipleRelations = this.relations.length > 1;
  21. },
  22. render: function() {
  23. var templateObject = this.isMultipleRelations ? this._multiTemplate() : this._singleTemplate();
  24. var tempHTML = this.dotTemplate(templateObject);
  25. $(tempHTML).hide().appendTo(this.$el).fadeIn(400, function(){
  26. this.$el.find('.mui_JoinPopup').focus();
  27. }.bind(this));
  28. var box = this.$el.find('.mui_JoinPopup');
  29. box.css({
  30. "top": Math.max(0, this.position[1] - box.height()/2 + 25),
  31. "left": Math.min(Math.max(0, this.position[0] - box.width()/2 + 90), this.$el.width() - box.width() - 20)
  32. });
  33. var $sourceTitle = box.find('.mui_joinTitle_source');
  34. var $targetTitle = box.find('.mui_joinTitle_target');
  35. ContentFormatter.middleShortenString($sourceTitle);
  36. ContentFormatter.middleShortenString($targetTitle);
  37. box.on('blur', this._onBlur.bind(this));
  38. this.$el.on('mousewheel', this._onBlur.bind(this));
  39. },
  40. _singleTemplate: function(){
  41. var joinType = InternalBridge.joinUtils.relationshipMappingMinMaxEx(this.relations[0]);
  42. var tableParameters = {
  43. leftTable: this.source.label,
  44. rightTable: this.target.label
  45. };
  46. var desc = resources.get('unknownString');
  47. if (joinType.type === 'left') {
  48. desc = resources.get('joinTypeLeft', tableParameters);
  49. }
  50. else if (joinType.type === 'right') {
  51. desc = resources.get('joinTypeRight', tableParameters);
  52. }
  53. else if (joinType.type === 'full') {
  54. desc = resources.get('joinTypeFull', tableParameters);
  55. }
  56. else if (joinType.type === 'inner') {
  57. desc = resources.get('joinTypeInner');
  58. }
  59. return {
  60. sourceTitle: _.escape(this.source.label),
  61. targetTitle: _.escape(this.target.label),
  62. type: joinType.type,
  63. description: _.escape(desc),
  64. joinedItems: this._updateQueryItemTitles()
  65. };
  66. },
  67. _multiTemplate: function(){
  68. return {
  69. sourceTitle: _.escape(this.source.label),
  70. targetTitle: _.escape(this.target.label),
  71. description: '',
  72. joinedItems: this._updateQueryItemTitles()
  73. };
  74. },
  75. /**
  76. * Ensure that legacy joins are displaying the title instead of the identifier
  77. * of the queryItems they are joining on
  78. *
  79. * @return array containing an object with the titles
  80. */
  81. _updateQueryItemTitles: function() {
  82. var titles = [];
  83. for(var i = 0; i < this.relations.length; i++) {
  84. var relationship = this.relations[i];
  85. var leftRefObject = relationship.left.getReferencedObject();
  86. var rightRefObject = relationship.right.getReferencedObject();
  87. var leftIsFromPackage = InternalBridge.moserUtils.isPartOfPackage(leftRefObject);
  88. var rightIsFromPackage = InternalBridge.moserUtils.isPartOfPackage(rightRefObject);
  89. var leftRef = relationship.left.ref;
  90. var rightRef = relationship.right.ref;
  91. var leftSide = leftIsFromPackage ? InternalBridge.moserUtils.getUseSpecByRef(leftRefObject, leftRef).identifier : leftRef;
  92. var rightSide = rightIsFromPackage ? InternalBridge.moserUtils.getUseSpecByRef(rightRefObject, rightRef).identifier : rightRef;
  93. if(this.source.identifier === leftSide && this.target.identifier === rightSide) {
  94. for(var j = 0; j < relationship.link.length; j++) {
  95. titles.push({
  96. leftRef: this._getQueryItemName(
  97. relationship.link[j].getReferencedObjectLeft(),
  98. relationship.link[j].leftRef
  99. ),
  100. rightRef: this._getQueryItemName(
  101. relationship.link[j].getReferencedObjectRight(),
  102. relationship.link[j].rightRef
  103. )
  104. });
  105. }
  106. }
  107. }
  108. return titles;
  109. },
  110. /**
  111. * Given the referenced queryItem,
  112. * retrieve the label of the corresponding queryItem
  113. *
  114. * @param linkReferencedObject
  115. * The referenced queryItem, if it can be found
  116. * @param queryItemRef
  117. * The queryItem's identifier
  118. * @return the label of the queryItem or unknown message
  119. */
  120. _getQueryItemName: function(linkReferencedObject, queryItemRef) {
  121. return _.escape(
  122. (linkReferencedObject && linkReferencedObject.getLabel()) ||
  123. resources.get('relationship_unknownItem', { value: queryItemRef })
  124. );
  125. },
  126. _onBlur: function(){
  127. this.$el.off('mousewheel');
  128. this.$el.find('.mui_JoinPopup ').remove();
  129. }
  130. });
  131. return JoinPopupView;
  132. });