lineageui.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. /****************************************************************
  2. ** Licensed Materials - Property of IBM
  3. **
  4. ** IBM Cognos Products: mdsrv
  5. **
  6. ** (C) Copyright IBM Corp. 2008, 2017
  7. **
  8. ** US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  9. *****************************************************************/
  10. //***********************************************************************************************
  11. // Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved.
  12. // Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
  13. //***********************************************************************************************
  14. // Declare the LINEAGE namespace
  15. if ( ! LNS )
  16. var LNS = {};
  17. LNS.g_idTimer = null;
  18. LNS.g_idLoadTimer = null;
  19. LNS.g_defDocumentCursor = null;
  20. LNS.g_defTechTabCursor = null;
  21. LNS.idBusinessView = 0;
  22. LNS.idTechnicalView = 1;
  23. LNS.sTabCtrlId = 'idTabCtrl';
  24. LNS.tabNames = [];
  25. LNS.tabNames[ LNS.idBusinessView ] = 'id_tab_business_view';
  26. LNS.tabNames[ LNS.idTechnicalView ] = 'id_tab_technical_view';
  27. LNS.idCurTab = 0;
  28. LNS.textGraphCreated = false;
  29. LNS.getTabName = function ( nTab )
  30. {
  31. return this.tabNames[ nTab ];
  32. }
  33. LNS.getCurTabName = function()
  34. {
  35. return this.tabNames[ this.idCurTab ];
  36. }
  37. LNS.switchTabs = function( keyEvent )
  38. {
  39. var bProcessed = false;
  40. var evt = new CKeyboardEvent ( keyEvent );
  41. // When a user presses the TAB button -> switch the tab
  42. if ( evt.key === UTIL.KEYCODE_TAB )
  43. {
  44. if ( ++this.idCurTab >= this.tabNames.length )
  45. this.idCurTab = 0;
  46. // alert( this.getCurTabName() );
  47. this.OnSelectTab( this.getCurTabName() );
  48. bProcessed = true;
  49. }
  50. else
  51. if ( evt.key === UTIL.KEYCODE_ARROW_LEFT && evt.evt.altKey )
  52. {
  53. // Try to catch Alt+LeftArrow -> it's a shortcut for browser's BACK button
  54. bProcessed = true;
  55. }
  56. else
  57. if ( evt.key === UTIL.KEYCODE_ARROW_RIGHT && evt.evt.altKey )
  58. {
  59. // Try to catch Alt+RightArrow -> it's a shortcut for browser's FORWARD button
  60. bProcessed = true;
  61. }
  62. else
  63. {
  64. if ( this.idCurTab === this.idTechnicalView && this.g_TechnicalView && this.g_TechnicalView.bInitialized )
  65. {
  66. bProcessed = this.g_TechnicalView.processKeyEvent( keyEvent );
  67. }
  68. }
  69. return ! bProcessed;
  70. }
  71. LNS.showHourglassCursor = function ( bShow )
  72. {
  73. var cssHelper = new CElementStyleHelper ( 'id_tab_technical_view_span' );
  74. var defDocumentCursor = LNS.g_defDocumentCursor;
  75. var defTechTabCursor = LNS.g_defTechTabCursor;
  76. if ( bShow )
  77. {
  78. if (document.documentElement.clientHeight == 0)
  79. this.g_defDocumentCursor = document.body.style.cursor;
  80. else
  81. this.g_defDocumentCursor = document.documentElement.style.cursor;
  82. this.g_defTechTabCursor = cssHelper.getCursor();
  83. defDocumentCursor = "wait";
  84. defTechTabCursor = "wait";
  85. }
  86. if (document.documentElement.clientHeight == 0)
  87. document.body.style.cursor = defDocumentCursor;
  88. else
  89. document.documentElement.style.cursor = defDocumentCursor;
  90. cssHelper.setCursor( defTechTabCursor );
  91. }
  92. LNS.OnSelectTab = function ( sTabId )
  93. {
  94. var activeTab = document.getElementById( sTabId );
  95. activeTab.className = "classActiveTab";
  96. if ( sTabId === this.tabNames[ this.idBusinessView ] )
  97. {
  98. var techViewTab = document.getElementById( "id_tab_technical_view" );
  99. techViewTab.className = "classInactiveTab";
  100. var busView = document.getElementById( "id_business_view" );
  101. var techView = document.getElementById( "id_technical_view" );
  102. techView.style.display = "none";
  103. busView.style.display = "block";
  104. }
  105. else
  106. if ( sTabId === this.tabNames[ this.idTechnicalView ] )
  107. {
  108. var busViewTab = document.getElementById( "id_tab_business_view" );
  109. busViewTab.className = "classInactiveTab";
  110. var busView = document.getElementById( "id_business_view" );
  111. var techView = document.getElementById( "id_technical_view" );
  112. busView.style.display = "none";
  113. techView.style.display = "block";
  114. //defined in techView.jspf
  115. // MDSRV_initialize();
  116. // HACK: to display the hourglass cursor while the technical view is being initialized
  117. if ( ! this.TECH_VIEW_INITED )
  118. {
  119. this.showHourglassCursor ( true );
  120. this.g_idTimer = window.setTimeout( "LNS.initTechnicalView()", 100 );
  121. }
  122. //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)
  123. if(!LNS.techincalTabHasBeenSelected){
  124. LNS.techincalTabHasBeenSelected = true;
  125. window.resizeBy(1,0)
  126. }
  127. }
  128. }
  129. LNS.initBusinessView = function()
  130. {
  131. window.clearTimeout ( this.g_idLoadTimer );
  132. this.OnSelectTab( this.getCurTabName() );
  133. var tabCtrl = document.getElementById( this.sTabCtrlId );
  134. tabCtrl.focus();
  135. // tabCtrl.releaseCapture();
  136. }
  137. LNS.OnLoad = function()
  138. {
  139. // document.onkeydown = this.switchTabs;
  140. // Select the initial TAB
  141. this.g_idLoadTimer = window.setTimeout( "LNS.initBusinessView()", 100 );
  142. var tabCtrl = document.getElementById( this.sTabCtrlId );
  143. tabCtrl.focus();
  144. // tabCtrl.setCapture();
  145. LNS.replaceBlankTableCells(document.getElementById('id_business_view'));
  146. }
  147. LNS.initTechnicalView = function()
  148. {
  149. if ( ! this.TECH_VIEW_INITED )
  150. {
  151. var techView = document.getElementById( "id_technical_view" );
  152. //The technical view div needs to be visible when calculating the pane widths on the graph, otherwise the panes will overlap.
  153. //This style will only be applied while the technical view is being initialized, and is removed once it has been (see below).
  154. techView.style.opacity = 0;
  155. techView.style.display = "block";
  156. techView.style.position = "absolute";
  157. window.clearTimeout ( this.g_idTimer );
  158. MDSRV_initialize();
  159. //Reset the opacity
  160. techView.style.opacity = 1; // fully opaque
  161. techView.style.position = "relative";
  162. this.showHourglassCursor ( false );
  163. }
  164. }
  165. //hide the text based graph, show the Normal View tables and nesting tables, and indicate the Normal view is selected
  166. LNS.showBusinessDiv = function()
  167. {
  168. document.getElementById("textgraph").style.display = "none";
  169. document.getElementById("normalViewTables").style.display = "";
  170. }
  171. //same as above, but show the text based graph
  172. LNS.showTextGraphDiv = function()
  173. {
  174. if ( ! this.textGraphCreated )
  175. {
  176. LNS.initTechnicalView();
  177. // make sure the technicalView isn't displayed
  178. var techView = document.getElementById( "id_technical_view" );
  179. techView.style.display = "none";
  180. var textgraph = new CTextGraph(LNS.g_TechnicalView.GraphCtrl, LNS.g_modelData.responseHelper);
  181. textgraph.Init();
  182. this.textGraphCreated = true;
  183. }
  184. document.getElementById("textgraph").style.display = "";
  185. document.getElementById("normalViewTables").style.display = "none";
  186. }
  187. LNS.switchBusinessViews = function()
  188. {
  189. if(document.getElementById("NormalView").checked === true && document.getElementById("NormalView").style.display !== "none")
  190. {
  191. LNS.showBusinessDiv();
  192. }
  193. else if(document.getElementById("DetailedView").checked === true && document.getElementById("DetailedView").style.display !== "none")
  194. {
  195. LNS.showTextGraphDiv();
  196. }
  197. }
  198. LNS.replaceBlankTableCells = function (rootNode)
  199. {
  200. var tableCellsNodeList = rootNode.getElementsByTagName('td');
  201. var onlyWhitespace = /^\s*$/g;
  202. var emptyCells = [];
  203. for(var i = 0; i < tableCellsNodeList.length; i++)
  204. {
  205. var node = tableCellsNodeList[i];
  206. if(onlyWhitespace.test(node.innerHTML))
  207. {
  208. emptyCells.push(node);
  209. }
  210. //this catches the empty cells in the normal view that have a span with no text
  211. else if(node.childNodes.length === 1 && node.childNodes[0].className === "dataCell" && onlyWhitespace.test(node.childNodes[0].innerHTML))
  212. {
  213. emptyCells.push(node);
  214. }
  215. }
  216. for(var i = 0; i < emptyCells.length; i++)
  217. {
  218. emptyCells[i].parentNode.parentNode.removeChild(emptyCells[i].parentNode);
  219. }
  220. }
  221. //-------------------------------------------------------------------------
  222. function GetScreenXresolution()
  223. {
  224. return screen.width;
  225. }
  226. function GetScreenYresolution()
  227. {
  228. return screen.height;
  229. }
  230. function GetWindowClientHeight()
  231. {
  232. if (document.documentElement.clientHeight == 0)
  233. return window.innerHeight ? window.innerHeight : document.body.clientHeight;
  234. return window.innerHeight ? window.innerHeight : document.documentElement.clientHeight;
  235. }
  236. function GetWindowClientWidth()
  237. {
  238. if (document.documentElement.clientHeight == 0)
  239. return window.innerWidth ? window.innerWidth : document.body.clientWidth;
  240. return window.innerWidth ? window.innerWidth : document.documentElement.clientWidth;
  241. }
  242. function GetWindowOuterHeight()
  243. {
  244. if (document.documentElement.clientHeight == 0)
  245. return window.innerHeight ? window.innerHeight : document.body.clientHeight;
  246. return window.innerHeight ? window.innerHeight : document.documentElement.clientHeight;
  247. // return window.outerHeight;
  248. }
  249. function GetWindowOuterWidth()
  250. {
  251. if (document.documentElement.clientHeight == 0)
  252. return window.innerWidth ? window.innerWidth : document.body.clientWidth;
  253. return window.innerWidth ? window.innerWidth : document.documentElement.clientWidth;
  254. // return window.innerWidth;
  255. }
  256. function GetWindowXoffset()
  257. {
  258. return window.screenLeft ? window.screenLeft : window.screenX;
  259. }
  260. function GetWindowYoffset()
  261. {
  262. return window.screenTop ? window.screenTop : window.screenY;
  263. }
  264. /** This function resizes the lineage window to 80% the width and height of the screen. */
  265. function MDSRV_ResizeWindow()
  266. {
  267. var width = GetWindowOuterWidth();
  268. var height = GetWindowOuterHeight();
  269. var prefWidth = screen.availWidth * 0.80;
  270. var prefHeight = screen.availHeight * 0.80;
  271. if (width < prefWidth || width > screen.availWidth)
  272. {
  273. width = prefWidth;
  274. }
  275. if (height < prefHeight || height > screen.availHeight)
  276. {
  277. height = prefHeight;
  278. }
  279. window.resizeTo( width, height );
  280. var x = GetWindowXoffset();
  281. var y = GetWindowYoffset();
  282. if ( x + width > screen.availWidth )
  283. x = screen.availWidth - width;
  284. if ( y + height > screen.availHeight )
  285. y = screen.availHeight - height;
  286. window.moveTo( x, y );
  287. }
  288. function MDSRV_CheckForDebug(evt)
  289. {
  290. if (evt.shiftKey && evt.ctrlKey && evt.altKey)
  291. {
  292. if (evt.charCode == 68 || evt.keyCode == 68)
  293. {
  294. document.getElementById("MDSRV_debugForm").style.display="block";
  295. }
  296. }
  297. }
  298. function MDSRV_InitDebugKeyHandler()
  299. {
  300. if (document.addEventListener)
  301. {
  302. document.addEventListener('keypress', MDSRV_CheckForDebug, false);
  303. }
  304. else if (document.attachEvent)
  305. {
  306. document.attachEvent("onkeydown", MDSRV_CheckForDebug);
  307. }
  308. }
  309. //-----------------------------------------------------------------------------
  310. // class MDSRV_LineageResponse
  311. //
  312. // Creates an object structure from the given JS lineage representation
  313. // sent by the lineage ui service.
  314. //-----------------------------------------------------------------------------
  315. function MDSRV_LineageResponse( representation )
  316. {
  317. var linObj = "object";
  318. var i = 1;
  319. var lineageObject = representation[linObj+i];
  320. //first get all of the objects and put them into a map
  321. this.m_lineageObjects = new Array();
  322. while (lineageObject)
  323. {
  324. this.m_lineageObjects[MDSRV_decodeString(lineageObject['id'])] = new MDSRV_LineageObject(lineageObject);
  325. i++;
  326. lineageObject = representation[linObj+i];
  327. }
  328. //now get the objects that were asked about
  329. var queryStr = "query";
  330. var queryIdx = 1;
  331. var queryObj = representation[queryStr+queryIdx];
  332. this.m_queries = new Array();
  333. i = -1;
  334. while (queryObj)
  335. {
  336. objRef = MDSRV_decodeString(queryObj["objRef"]);
  337. this.m_queries[++i] = this.m_lineageObjects[objRef];
  338. // if ( this.m_lineageObjects[objRef].m_type == "filterDefinition" )
  339. // alert ( "MDSRV_LineageResponse: refObj type = " + this.m_lineageObjects[objRef].m_type );
  340. queryIdx++;
  341. queryObj = representation[queryStr+queryIdx];
  342. }
  343. }
  344. function MDSRV_LineageObject( lineageObject )
  345. {
  346. this.m_type = MDSRV_decodeString(lineageObject['type']);
  347. this.m_id = MDSRV_decodeString(lineageObject['id']);
  348. this.m_name = MDSRV_decodeString(lineageObject['name']);
  349. this.m_dispName = MDSRV_decodeString(lineageObject['dispName']);
  350. var props = lineageObject['properties'];
  351. this.m_properties = new Array();
  352. this.m_childRefs = new Array();
  353. //debugger;
  354. var property = "param";
  355. var propIdx = 1;
  356. var propObj = props[property+propIdx];
  357. var idx = 0;
  358. while ( propObj )
  359. {
  360. this.m_properties[idx] = new MDSRV_Property( MDSRV_decodeString(propObj['name']),
  361. MDSRV_decodeString(propObj['dispName']),
  362. MDSRV_decodeString(propObj['value']) );
  363. propIdx++;
  364. propObj = props[property+propIdx];
  365. idx++;
  366. }
  367. this.m_parentRef = MDSRV_decodeString( lineageObject['parent_ref'] );
  368. //now gather up any children we may have had
  369. var childObj = "child_ref";
  370. var childIdx = 1;
  371. var childObject = lineageObject[childObj+childIdx];
  372. while ( childObject )
  373. {
  374. this.m_childRefs.push( MDSRV_decodeString(childObject) );
  375. childIdx++;
  376. childObject = lineageObject[childObj+childIdx];
  377. }
  378. this.m_transformation = new MDSRV_Transformation(lineageObject['transformation']);
  379. }
  380. function MDSRV_Transformation( objTransformation )
  381. {
  382. var sources = objTransformation['source'];
  383. this.m_sources = new Array();
  384. var sourceStr = "source";
  385. var sourceIdx = 1;
  386. var sourceObj = objTransformation[sourceStr+sourceIdx];
  387. while (sourceObj)
  388. {
  389. var transSource = new MDSRV_TransformationSource(sourceObj);
  390. this.m_sources[sourceIdx-1] = transSource;
  391. sourceIdx++;
  392. sourceObj = objTransformation[sourceStr+sourceIdx];
  393. }
  394. }
  395. function MDSRV_TransformationSource(representation)
  396. {
  397. this.m_objectRef = MDSRV_decodeString( representation['objRef'] );
  398. }
  399. function MDSRV_Property(propName, propDispName, propValue)
  400. {
  401. this.m_name = propName;
  402. this.m_dispName = propDispName;
  403. this.m_value = propValue;
  404. }
  405. function MDSRV_decodeString(str)
  406. {
  407. if (str)
  408. {
  409. var str1 = str.replace(/&apos;/g, "'");
  410. str1 = str1.replace(/&quot;/g, "\"");
  411. str1 = str1.replace(/&gt;/g, ">");
  412. str1 = str1.replace(/&lt;/g, "<");
  413. return str1;
  414. }
  415. return "";
  416. }
  417. /* Public API */
  418. /** For this lineage request returns an array of MDSRV_LineageObjects representing the query'd objects.
  419. Return type array of MDSRV_LineageObjects. */
  420. MDSRV_LineageResponse.prototype.getQueryResults = function()
  421. {
  422. return this.m_queries;
  423. }
  424. /** Returns a MDSRV_LineageObject for the object with the given id. Return type MDSRV_LineageObject */
  425. MDSRV_LineageResponse.prototype.lookup = function(objectRef)
  426. {
  427. return this.m_lineageObjects[objectRef];
  428. }
  429. /** For the given lineage object returns the objects id. Return type string.*/
  430. MDSRV_LineageObject.prototype.getId = function()
  431. {
  432. return this.m_id;
  433. }
  434. MDSRV_LineageObject.prototype.toString = function()
  435. {
  436. var result = "name:" + this.m_name;
  437. result += ", type: " + this.m_type;
  438. result += ", parentRef: " + this.m_parentRef;
  439. result += " properties: {";
  440. for (var i=0; i < this.m_properties.length; i++)
  441. {
  442. result += this.m_properties[i].getName();
  443. result += ":";
  444. result += this.m_properties[i].getValue();
  445. if ( i + 1 < this.m_properties.length )
  446. {
  447. result += ",";
  448. }
  449. }
  450. result += "}";
  451. return result;
  452. }
  453. /** Returns the name of this lineage object. Return type strnig.*/
  454. MDSRV_LineageObject.prototype.getName = function()
  455. {
  456. return this.m_name;
  457. }
  458. /** Returns the type of this lineage object. Return type string.*/
  459. MDSRV_LineageObject.prototype.getType = function()
  460. {
  461. return this.m_type;
  462. }
  463. /*Returns array of properties of this lineage object. Return type Array of MDSRV_Property objects. */
  464. MDSRV_LineageObject.prototype.getProperties = function()
  465. {
  466. return this.m_properties;
  467. }
  468. /** Returns the transformation [if any] for this lineage object. Return type MDSRV_Transformation */
  469. MDSRV_LineageObject.prototype.getTransformation = function()
  470. {
  471. return this.m_transformation;
  472. }
  473. /** Returns the id of the parent of this LineageObject. Return type string.*/
  474. MDSRV_LineageObject.prototype.getParentRef = function()
  475. {
  476. return this.m_parentRef;
  477. }
  478. /** Returns the list of id's of child objects. Return type array of strings representing child id's. */
  479. MDSRV_LineageObject.prototype.getChildRefs = function()
  480. {
  481. return this.m_childRefs;
  482. }
  483. /** Returns the sources of this transformation. Return type Array of MDSRV_TransformationSource objects. */
  484. MDSRV_Transformation.prototype.getTransformationSourceList = function()
  485. {
  486. return this.m_sources;
  487. }
  488. /** Returns a string representing the id of the source object. Return type string. */
  489. MDSRV_TransformationSource.prototype.getObjectRef = function()
  490. {
  491. return this.m_objectRef;
  492. }
  493. /** Returns the name of this property. Return type string. */
  494. MDSRV_Property.prototype.getName = function()
  495. {
  496. return this.m_name;
  497. }
  498. /** Returns the display name of this property. Return type string. */
  499. MDSRV_Property.prototype.getDisplayName = function()
  500. {
  501. return this.m_dispName;
  502. }
  503. /** Returns the value of this property. Return type string. */
  504. MDSRV_Property.prototype.getValue = function()
  505. {
  506. return this.m_value;
  507. }
  508. /** Used to retrieve localized values. String map is an array of the form {key:'value', key:'value'}. Keys must be
  509. unique.*/
  510. function MDSRV_StringManager(stringMap)
  511. {
  512. this.m_stringMap = stringMap;
  513. }
  514. /** Returns the localized value for the given key. If a param is present,
  515. then the param will be subsituted if the param was a parameterized string.
  516. A parameterized string will contain '$$' whereever a param is locaed */
  517. MDSRV_StringManager.prototype.stringLookup = function(key, param)
  518. {
  519. var locStr = this.m_stringMap[key];
  520. //replace any occurences of $$ with param
  521. if (param)
  522. {
  523. locStr = locStr.replace("$$", param);
  524. }
  525. return locStr;
  526. }