123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- /**
- * Licensed Materials - Property of IBM IBM Cognos Products: Modeling UI (C) Copyright IBM Corp. 2015, 2019
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP
- * Schedule Contract with IBM Corp.
- */
- define([
- 'bi/glass/app/util/View',
- 'underscore',
- 'jquery',
- '../../StringResourcesBridge',
- 'text!./templates/JoinPopupView.html',
- 'bi/commons/utils/ContentFormatter',
- '../../InternalBridge'
- ], function(BaseView, _, $, resources, Template, ContentFormatter, InternalBridge) {
- var JoinPopupView = BaseView.extend({
- templateString: Template,
- init: function(attributes) {
- JoinPopupView.inherited('init', this, arguments);
- _.extend(this, attributes);
- this.isMultipleRelations = this.relations.length > 1;
- },
- render: function() {
- var templateObject = this.isMultipleRelations ? this._multiTemplate() : this._singleTemplate();
- var tempHTML = this.dotTemplate(templateObject);
- $(tempHTML).hide().appendTo(this.$el).fadeIn(400, function(){
- this.$el.find('.mui_JoinPopup').focus();
- }.bind(this));
- var box = this.$el.find('.mui_JoinPopup');
- box.css({
- "top": Math.max(0, this.position[1] - box.height()/2 + 25),
- "left": Math.min(Math.max(0, this.position[0] - box.width()/2 + 90), this.$el.width() - box.width() - 20)
- });
- var $sourceTitle = box.find('.mui_joinTitle_source');
- var $targetTitle = box.find('.mui_joinTitle_target');
- ContentFormatter.middleShortenString($sourceTitle);
- ContentFormatter.middleShortenString($targetTitle);
- box.on('blur', this._onBlur.bind(this));
- this.$el.on('mousewheel', this._onBlur.bind(this));
- },
- _singleTemplate: function(){
- var joinType = InternalBridge.joinUtils.relationshipMappingMinMaxEx(this.relations[0]);
- var tableParameters = {
- leftTable: this.source.label,
- rightTable: this.target.label
- };
- var desc = resources.get('unknownString');
- if (joinType.type === 'left') {
- desc = resources.get('joinTypeLeft', tableParameters);
- }
- else if (joinType.type === 'right') {
- desc = resources.get('joinTypeRight', tableParameters);
- }
- else if (joinType.type === 'full') {
- desc = resources.get('joinTypeFull', tableParameters);
- }
- else if (joinType.type === 'inner') {
- desc = resources.get('joinTypeInner');
- }
- return {
- sourceTitle: _.escape(this.source.label),
- targetTitle: _.escape(this.target.label),
- type: joinType.type,
- description: _.escape(desc),
- joinedItems: this._updateQueryItemTitles()
- };
- },
- _multiTemplate: function(){
- return {
- sourceTitle: _.escape(this.source.label),
- targetTitle: _.escape(this.target.label),
- description: '',
- joinedItems: this._updateQueryItemTitles()
- };
- },
- /**
- * Ensure that legacy joins are displaying the title instead of the identifier
- * of the queryItems they are joining on
- *
- * @return array containing an object with the titles
- */
- _updateQueryItemTitles: function() {
- var titles = [];
- for(var i = 0; i < this.relations.length; i++) {
- var relationship = this.relations[i];
- var leftRefObject = relationship.left.getReferencedObject();
- var rightRefObject = relationship.right.getReferencedObject();
- var leftIsFromPackage = InternalBridge.moserUtils.isPartOfPackage(leftRefObject);
- var rightIsFromPackage = InternalBridge.moserUtils.isPartOfPackage(rightRefObject);
- var leftRef = relationship.left.ref;
- var rightRef = relationship.right.ref;
- var leftSide = leftIsFromPackage ? InternalBridge.moserUtils.getUseSpecByRef(leftRefObject, leftRef).identifier : leftRef;
- var rightSide = rightIsFromPackage ? InternalBridge.moserUtils.getUseSpecByRef(rightRefObject, rightRef).identifier : rightRef;
- if(this.source.identifier === leftSide && this.target.identifier === rightSide) {
- for(var j = 0; j < relationship.link.length; j++) {
- titles.push({
- leftRef: this._getQueryItemName(
- relationship.link[j].getReferencedObjectLeft(),
- relationship.link[j].leftRef
- ),
- rightRef: this._getQueryItemName(
- relationship.link[j].getReferencedObjectRight(),
- relationship.link[j].rightRef
- )
- });
- }
- }
- }
- return titles;
- },
- /**
- * Given the referenced queryItem,
- * retrieve the label of the corresponding queryItem
- *
- * @param linkReferencedObject
- * The referenced queryItem, if it can be found
- * @param queryItemRef
- * The queryItem's identifier
- * @return the label of the queryItem or unknown message
- */
- _getQueryItemName: function(linkReferencedObject, queryItemRef) {
- return _.escape(
- (linkReferencedObject && linkReferencedObject.getLabel()) ||
- resources.get('relationship_unknownItem', { value: queryItemRef })
- );
- },
- _onBlur: function(){
- this.$el.off('mousewheel');
- this.$el.find('.mui_JoinPopup ').remove();
- }
- });
- return JoinPopupView;
- });
|