/**************************************************************** ** Licensed Materials - Property of IBM ** ** IBM Cognos Products: mdsrv ** ** (C) Copyright IBM Corp. 2008, 2017 ** ** US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. *****************************************************************/ //*********************************************************************************************** // Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved. // Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated). //*********************************************************************************************** // Declare the LINEAGE namespace if ( ! LNS ) var LNS = {}; LNS.g_idTimer = null; LNS.g_idLoadTimer = null; LNS.g_defDocumentCursor = null; LNS.g_defTechTabCursor = null; LNS.idBusinessView = 0; LNS.idTechnicalView = 1; LNS.sTabCtrlId = 'idTabCtrl'; LNS.tabNames = []; LNS.tabNames[ LNS.idBusinessView ] = 'id_tab_business_view'; LNS.tabNames[ LNS.idTechnicalView ] = 'id_tab_technical_view'; LNS.idCurTab = 0; LNS.textGraphCreated = false; LNS.getTabName = function ( nTab ) { return this.tabNames[ nTab ]; } LNS.getCurTabName = function() { return this.tabNames[ this.idCurTab ]; } LNS.switchTabs = function( keyEvent ) { var bProcessed = false; var evt = new CKeyboardEvent ( keyEvent ); // When a user presses the TAB button -> switch the tab if ( evt.key === UTIL.KEYCODE_TAB ) { if ( ++this.idCurTab >= this.tabNames.length ) this.idCurTab = 0; // alert( this.getCurTabName() ); this.OnSelectTab( this.getCurTabName() ); bProcessed = true; } else if ( evt.key === UTIL.KEYCODE_ARROW_LEFT && evt.evt.altKey ) { // Try to catch Alt+LeftArrow -> it's a shortcut for browser's BACK button bProcessed = true; } else if ( evt.key === UTIL.KEYCODE_ARROW_RIGHT && evt.evt.altKey ) { // Try to catch Alt+RightArrow -> it's a shortcut for browser's FORWARD button bProcessed = true; } else { if ( this.idCurTab === this.idTechnicalView && this.g_TechnicalView && this.g_TechnicalView.bInitialized ) { bProcessed = this.g_TechnicalView.processKeyEvent( keyEvent ); } } return ! bProcessed; } LNS.showHourglassCursor = function ( bShow ) { var cssHelper = new CElementStyleHelper ( 'id_tab_technical_view_span' ); var defDocumentCursor = LNS.g_defDocumentCursor; var defTechTabCursor = LNS.g_defTechTabCursor; if ( bShow ) { if (document.documentElement.clientHeight == 0) this.g_defDocumentCursor = document.body.style.cursor; else this.g_defDocumentCursor = document.documentElement.style.cursor; this.g_defTechTabCursor = cssHelper.getCursor(); defDocumentCursor = "wait"; defTechTabCursor = "wait"; } if (document.documentElement.clientHeight == 0) document.body.style.cursor = defDocumentCursor; else document.documentElement.style.cursor = defDocumentCursor; cssHelper.setCursor( defTechTabCursor ); } LNS.OnSelectTab = function ( sTabId ) { var activeTab = document.getElementById( sTabId ); activeTab.className = "classActiveTab"; if ( sTabId === this.tabNames[ this.idBusinessView ] ) { var techViewTab = document.getElementById( "id_tab_technical_view" ); techViewTab.className = "classInactiveTab"; var busView = document.getElementById( "id_business_view" ); var techView = document.getElementById( "id_technical_view" ); techView.style.display = "none"; busView.style.display = "block"; } else if ( sTabId === this.tabNames[ this.idTechnicalView ] ) { var busViewTab = document.getElementById( "id_tab_business_view" ); busViewTab.className = "classInactiveTab"; var busView = document.getElementById( "id_business_view" ); var techView = document.getElementById( "id_technical_view" ); busView.style.display = "none"; techView.style.display = "block"; //defined in techView.jspf // MDSRV_initialize(); // HACK: to display the hourglass cursor while the technical view is being initialized if ( ! this.TECH_VIEW_INITED ) { this.showHourglassCursor ( true ); this.g_idTimer = window.setTimeout( "LNS.initTechnicalView()", 100 ); } //HACK: If we "draw" the graph while the techincal view tab isn't selected, the div we place the graph in won't be redrawn until we resize the window (there has got to be a better way to do this) if(!LNS.techincalTabHasBeenSelected){ LNS.techincalTabHasBeenSelected = true; window.resizeBy(1,0) } } } LNS.initBusinessView = function() { window.clearTimeout ( this.g_idLoadTimer ); this.OnSelectTab( this.getCurTabName() ); var tabCtrl = document.getElementById( this.sTabCtrlId ); tabCtrl.focus(); // tabCtrl.releaseCapture(); } LNS.OnLoad = function() { // document.onkeydown = this.switchTabs; // Select the initial TAB this.g_idLoadTimer = window.setTimeout( "LNS.initBusinessView()", 100 ); var tabCtrl = document.getElementById( this.sTabCtrlId ); tabCtrl.focus(); // tabCtrl.setCapture(); LNS.replaceBlankTableCells(document.getElementById('id_business_view')); } LNS.initTechnicalView = function() { if ( ! this.TECH_VIEW_INITED ) { var techView = document.getElementById( "id_technical_view" ); //The technical view div needs to be visible when calculating the pane widths on the graph, otherwise the panes will overlap. //This style will only be applied while the technical view is being initialized, and is removed once it has been (see below). techView.style.opacity = 0; techView.style.display = "block"; techView.style.position = "absolute"; window.clearTimeout ( this.g_idTimer ); MDSRV_initialize(); //Reset the opacity techView.style.opacity = 1; // fully opaque techView.style.position = "relative"; this.showHourglassCursor ( false ); } } //hide the text based graph, show the Normal View tables and nesting tables, and indicate the Normal view is selected LNS.showBusinessDiv = function() { document.getElementById("textgraph").style.display = "none"; document.getElementById("normalViewTables").style.display = ""; } //same as above, but show the text based graph LNS.showTextGraphDiv = function() { if ( ! this.textGraphCreated ) { LNS.initTechnicalView(); // make sure the technicalView isn't displayed var techView = document.getElementById( "id_technical_view" ); techView.style.display = "none"; var textgraph = new CTextGraph(LNS.g_TechnicalView.GraphCtrl, LNS.g_modelData.responseHelper); textgraph.Init(); this.textGraphCreated = true; } document.getElementById("textgraph").style.display = ""; document.getElementById("normalViewTables").style.display = "none"; } LNS.switchBusinessViews = function() { if(document.getElementById("NormalView").checked === true && document.getElementById("NormalView").style.display !== "none") { LNS.showBusinessDiv(); } else if(document.getElementById("DetailedView").checked === true && document.getElementById("DetailedView").style.display !== "none") { LNS.showTextGraphDiv(); } } LNS.replaceBlankTableCells = function (rootNode) { var tableCellsNodeList = rootNode.getElementsByTagName('td'); var onlyWhitespace = /^\s*$/g; var emptyCells = []; for(var i = 0; i < tableCellsNodeList.length; i++) { var node = tableCellsNodeList[i]; if(onlyWhitespace.test(node.innerHTML)) { emptyCells.push(node); } //this catches the empty cells in the normal view that have a span with no text else if(node.childNodes.length === 1 && node.childNodes[0].className === "dataCell" && onlyWhitespace.test(node.childNodes[0].innerHTML)) { emptyCells.push(node); } } for(var i = 0; i < emptyCells.length; i++) { emptyCells[i].parentNode.parentNode.removeChild(emptyCells[i].parentNode); } } //------------------------------------------------------------------------- function GetScreenXresolution() { return screen.width; } function GetScreenYresolution() { return screen.height; } function GetWindowClientHeight() { if (document.documentElement.clientHeight == 0) return window.innerHeight ? window.innerHeight : document.body.clientHeight; return window.innerHeight ? window.innerHeight : document.documentElement.clientHeight; } function GetWindowClientWidth() { if (document.documentElement.clientHeight == 0) return window.innerWidth ? window.innerWidth : document.body.clientWidth; return window.innerWidth ? window.innerWidth : document.documentElement.clientWidth; } function GetWindowOuterHeight() { if (document.documentElement.clientHeight == 0) return window.innerHeight ? window.innerHeight : document.body.clientHeight; return window.innerHeight ? window.innerHeight : document.documentElement.clientHeight; // return window.outerHeight; } function GetWindowOuterWidth() { if (document.documentElement.clientHeight == 0) return window.innerWidth ? window.innerWidth : document.body.clientWidth; return window.innerWidth ? window.innerWidth : document.documentElement.clientWidth; // return window.innerWidth; } function GetWindowXoffset() { return window.screenLeft ? window.screenLeft : window.screenX; } function GetWindowYoffset() { return window.screenTop ? window.screenTop : window.screenY; } /** This function resizes the lineage window to 80% the width and height of the screen. */ function MDSRV_ResizeWindow() { var width = GetWindowOuterWidth(); var height = GetWindowOuterHeight(); var prefWidth = screen.availWidth * 0.80; var prefHeight = screen.availHeight * 0.80; if (width < prefWidth || width > screen.availWidth) { width = prefWidth; } if (height < prefHeight || height > screen.availHeight) { height = prefHeight; } window.resizeTo( width, height ); var x = GetWindowXoffset(); var y = GetWindowYoffset(); if ( x + width > screen.availWidth ) x = screen.availWidth - width; if ( y + height > screen.availHeight ) y = screen.availHeight - height; window.moveTo( x, y ); } function MDSRV_CheckForDebug(evt) { if (evt.shiftKey && evt.ctrlKey && evt.altKey) { if (evt.charCode == 68 || evt.keyCode == 68) { document.getElementById("MDSRV_debugForm").style.display="block"; } } } function MDSRV_InitDebugKeyHandler() { if (document.addEventListener) { document.addEventListener('keypress', MDSRV_CheckForDebug, false); } else if (document.attachEvent) { document.attachEvent("onkeydown", MDSRV_CheckForDebug); } } //----------------------------------------------------------------------------- // class MDSRV_LineageResponse // // Creates an object structure from the given JS lineage representation // sent by the lineage ui service. //----------------------------------------------------------------------------- function MDSRV_LineageResponse( representation ) { var linObj = "object"; var i = 1; var lineageObject = representation[linObj+i]; //first get all of the objects and put them into a map this.m_lineageObjects = new Array(); while (lineageObject) { this.m_lineageObjects[MDSRV_decodeString(lineageObject['id'])] = new MDSRV_LineageObject(lineageObject); i++; lineageObject = representation[linObj+i]; } //now get the objects that were asked about var queryStr = "query"; var queryIdx = 1; var queryObj = representation[queryStr+queryIdx]; this.m_queries = new Array(); i = -1; while (queryObj) { objRef = MDSRV_decodeString(queryObj["objRef"]); this.m_queries[++i] = this.m_lineageObjects[objRef]; // if ( this.m_lineageObjects[objRef].m_type == "filterDefinition" ) // alert ( "MDSRV_LineageResponse: refObj type = " + this.m_lineageObjects[objRef].m_type ); queryIdx++; queryObj = representation[queryStr+queryIdx]; } } function MDSRV_LineageObject( lineageObject ) { this.m_type = MDSRV_decodeString(lineageObject['type']); this.m_id = MDSRV_decodeString(lineageObject['id']); this.m_name = MDSRV_decodeString(lineageObject['name']); this.m_dispName = MDSRV_decodeString(lineageObject['dispName']); var props = lineageObject['properties']; this.m_properties = new Array(); this.m_childRefs = new Array(); //debugger; var property = "param"; var propIdx = 1; var propObj = props[property+propIdx]; var idx = 0; while ( propObj ) { this.m_properties[idx] = new MDSRV_Property( MDSRV_decodeString(propObj['name']), MDSRV_decodeString(propObj['dispName']), MDSRV_decodeString(propObj['value']) ); propIdx++; propObj = props[property+propIdx]; idx++; } this.m_parentRef = MDSRV_decodeString( lineageObject['parent_ref'] ); //now gather up any children we may have had var childObj = "child_ref"; var childIdx = 1; var childObject = lineageObject[childObj+childIdx]; while ( childObject ) { this.m_childRefs.push( MDSRV_decodeString(childObject) ); childIdx++; childObject = lineageObject[childObj+childIdx]; } this.m_transformation = new MDSRV_Transformation(lineageObject['transformation']); } function MDSRV_Transformation( objTransformation ) { var sources = objTransformation['source']; this.m_sources = new Array(); var sourceStr = "source"; var sourceIdx = 1; var sourceObj = objTransformation[sourceStr+sourceIdx]; while (sourceObj) { var transSource = new MDSRV_TransformationSource(sourceObj); this.m_sources[sourceIdx-1] = transSource; sourceIdx++; sourceObj = objTransformation[sourceStr+sourceIdx]; } } function MDSRV_TransformationSource(representation) { this.m_objectRef = MDSRV_decodeString( representation['objRef'] ); } function MDSRV_Property(propName, propDispName, propValue) { this.m_name = propName; this.m_dispName = propDispName; this.m_value = propValue; } function MDSRV_decodeString(str) { if (str) { var str1 = str.replace(/'/g, "'"); str1 = str1.replace(/"/g, "\""); str1 = str1.replace(/>/g, ">"); str1 = str1.replace(/</g, "<"); return str1; } return ""; } /* Public API */ /** For this lineage request returns an array of MDSRV_LineageObjects representing the query'd objects. Return type array of MDSRV_LineageObjects. */ MDSRV_LineageResponse.prototype.getQueryResults = function() { return this.m_queries; } /** Returns a MDSRV_LineageObject for the object with the given id. Return type MDSRV_LineageObject */ MDSRV_LineageResponse.prototype.lookup = function(objectRef) { return this.m_lineageObjects[objectRef]; } /** For the given lineage object returns the objects id. Return type string.*/ MDSRV_LineageObject.prototype.getId = function() { return this.m_id; } MDSRV_LineageObject.prototype.toString = function() { var result = "name:" + this.m_name; result += ", type: " + this.m_type; result += ", parentRef: " + this.m_parentRef; result += " properties: {"; for (var i=0; i < this.m_properties.length; i++) { result += this.m_properties[i].getName(); result += ":"; result += this.m_properties[i].getValue(); if ( i + 1 < this.m_properties.length ) { result += ","; } } result += "}"; return result; } /** Returns the name of this lineage object. Return type strnig.*/ MDSRV_LineageObject.prototype.getName = function() { return this.m_name; } /** Returns the type of this lineage object. Return type string.*/ MDSRV_LineageObject.prototype.getType = function() { return this.m_type; } /*Returns array of properties of this lineage object. Return type Array of MDSRV_Property objects. */ MDSRV_LineageObject.prototype.getProperties = function() { return this.m_properties; } /** Returns the transformation [if any] for this lineage object. Return type MDSRV_Transformation */ MDSRV_LineageObject.prototype.getTransformation = function() { return this.m_transformation; } /** Returns the id of the parent of this LineageObject. Return type string.*/ MDSRV_LineageObject.prototype.getParentRef = function() { return this.m_parentRef; } /** Returns the list of id's of child objects. Return type array of strings representing child id's. */ MDSRV_LineageObject.prototype.getChildRefs = function() { return this.m_childRefs; } /** Returns the sources of this transformation. Return type Array of MDSRV_TransformationSource objects. */ MDSRV_Transformation.prototype.getTransformationSourceList = function() { return this.m_sources; } /** Returns a string representing the id of the source object. Return type string. */ MDSRV_TransformationSource.prototype.getObjectRef = function() { return this.m_objectRef; } /** Returns the name of this property. Return type string. */ MDSRV_Property.prototype.getName = function() { return this.m_name; } /** Returns the display name of this property. Return type string. */ MDSRV_Property.prototype.getDisplayName = function() { return this.m_dispName; } /** Returns the value of this property. Return type string. */ MDSRV_Property.prototype.getValue = function() { return this.m_value; } /** Used to retrieve localized values. String map is an array of the form {key:'value', key:'value'}. Keys must be unique.*/ function MDSRV_StringManager(stringMap) { this.m_stringMap = stringMap; } /** Returns the localized value for the given key. If a param is present, then the param will be subsituted if the param was a parameterized string. A parameterized string will contain '$$' whereever a param is locaed */ MDSRV_StringManager.prototype.stringLookup = function(key, param) { var locStr = this.m_stringMap[key]; //replace any occurences of $$ with param if (param) { locStr = locStr.replace("$$", param); } return locStr; }