TechnicalView.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. /****************************************************************
  2. ** Licensed Materials - Property of IBM
  3. **
  4. ** IBM Cognos Products: mdsrv
  5. **
  6. ** (C) Copyright IBM Corp. 2008, 2015
  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. // Component: Technical View
  15. //***********************************************************************************************
  16. // Declare the LINEAGE namespace
  17. if ( ! LNS )
  18. var LNS = {};
  19. // Global constants
  20. LNS.oTechnicalView = null;
  21. LNS.arrItemsTypesWithIcon = [];
  22. LNS.arrItemsTypesWithIcon["filter"] = true;
  23. LNS.arrItemsTypesWithIcon["detailFilter"] = true;
  24. LNS.arrItemsTypesWithIcon["filterDefinition"] = true;
  25. LNS.arrItemsTypesWithIcon["summaryFilter"] = true;
  26. LNS.arrItemsTypesWithIcon["slicerMemberSet"] = true;
  27. LNS.arrClassIcons = [];
  28. LNS.arrClassIcons["querySubject"] = "query_subject.gif";
  29. LNS.arrClassIcons["query"] = "query_subject.gif";
  30. LNS.arrClassIcons["queryItem"] = "attribute.gif";
  31. LNS.arrClassIcons["dataItem"] = "attribute.gif";
  32. LNS.arrClassIcons["reportItem"] = "report_item.gif";
  33. LNS.arrClassIcons["measure"] = "measure.gif";
  34. LNS.arrClassIcons["dataSource"] = "data_source.gif";
  35. LNS.arrClassIcons["dimension"] = "dimension.gif";
  36. LNS.arrClassIcons["hierarchy"] = "hierarchy.gif";
  37. LNS.arrClassIcons["level"] = "level.gif";
  38. LNS.arrClassIcons["calculation"] = "calculation.gif";
  39. LNS.arrClassIcons["filter"] = "filter.gif";
  40. LNS.arrClassIcons["detailFilter"] = "filter_embedded.gif";
  41. LNS.arrClassIcons["filterDefinition"] = "filter_embedded.gif";
  42. LNS.arrClassIcons["summaryFilter"] = "filter_summary.gif";
  43. LNS.arrClassIcons["slicerMemberSet"] = "slicer.gif";
  44. LNS.arrClassIcons["queryItemFolder"] = "folder.gif";
  45. //-------------------------------------------------------------------------------------
  46. // class OnPostPopulate
  47. //-------------------------------------------------------------------------------------
  48. function OnPostPopulate ( graph, paneManager )
  49. {
  50. // Set events
  51. var timeStart = new Date().getTime();
  52. var elemGraph = document.getElementById ( graph.getId() );
  53. var elemCanvas = elemGraph.parentNode;
  54. var nGraphHeight = (UTIL.ElementHelper.setElem( elemGraph )).getClientSize().height;
  55. // Event callbacks
  56. //this.OnGraphTimer = function ()
  57. //{
  58. // var nGraphHeightNew = (UTIL.ElementHelper.setElem( elemGraph )).getClientSize().height;
  59. //
  60. // // A workaround for FF to respond to graph resize - FF 2.0.0.12 does NOT send the 'resize' event
  61. //
  62. // if ( nGraphHeightNew != nGraphHeight )
  63. // {
  64. // nGraphHeight = nGraphHeightNew;
  65. //
  66. // paneManager.updateSize ( false );
  67. //
  68. // //--------------------------------------------------------------
  69. // // Move all panes' captions and links
  70. // //--------------------------------------------------------------
  71. //
  72. // paneManager.OnGraphResize ();
  73. // }
  74. //}
  75. this.OnGraphResize = function ( evt )
  76. {
  77. var evtObj = new CMouseEvent ( evt );
  78. paneManager.updateSize ( false );
  79. //--------------------------------------------------------------
  80. // Move all panes' captions and links
  81. //--------------------------------------------------------------
  82. paneManager.OnGraphResize ();
  83. }
  84. this.OnGraphScroll = function ( evt )
  85. {
  86. var evtObj = new CMouseEvent ( evt );
  87. paneManager.OnScroll ( evtObj );
  88. }
  89. // addEvent( elemCanvas, 'scroll', this.OnGraphScroll, false );
  90. addEvent( elemGraph, 'scroll', this.OnGraphScroll, false );
  91. addEvent( elemGraph, 'resize', this.OnGraphResize, true );
  92. // FireFox resize workaround using timer intervals
  93. //window.setInterval ( "LNS.oTechnicalView.eventProcessor.OnGraphTimer()", 200 );
  94. // Any non-generic graph actions are to be done here !
  95. var gMainObjects = [];
  96. for ( var i = 0; i < graph.m_nodeList.length; i++)
  97. {
  98. var gNode = graph.m_nodeList[ i ];
  99. // Move the nodes to the correct position
  100. gNode.move ( gNode.x, gNode.y );
  101. if ( gNode.modelObject.isMainObject() )
  102. gMainObjects.push( gNode );
  103. }
  104. for (var i = 0; i < gMainObjects.length; i++)
  105. {
  106. gMainObjects[i].setTextBold ();
  107. gMainObjects[i].setBorderStyle ( 'dashed' );
  108. }
  109. if ( gMainObjects[0] )
  110. graph.SelectObject ( gMainObjects[0] );
  111. // Configure Initial Visible Nodes
  112. paneManager.setNodesVisibility ();
  113. // Configure the connections
  114. // graph.refreshConnections ();
  115. }
  116. //-------------------------------------------------------------------------------------
  117. // class CTechnicalView
  118. //-------------------------------------------------------------------------------------
  119. function CTechnicalView ( sCanvasId )
  120. {
  121. // Members
  122. this.canvasId = sCanvasId;
  123. this.bInitialized = false;
  124. this.modelData = null;
  125. this.GraphCtrl = null;
  126. this.paneManager = null;
  127. this.propertyPaneQuery = null;
  128. this.propertyPaneItem = null;
  129. this.propertyManager = null;
  130. this.idProgressTimer = null;
  131. this.eventProcessor = null;
  132. this.bShowActionLinks = false;
  133. this.sActionURL = 'http://www.google.ca';
  134. this.sActionIcon = 'action_custom.gif';
  135. this.sActionIconTooltip = 'Click to run action...';
  136. // API
  137. this.setCurrentDir = function ( sCurrentDir )
  138. {
  139. if ( DG.graphDefaults )
  140. DG.graphDefaults.sCurrentDir = sCurrentDir;
  141. }
  142. this.getCurrentDir = function ( )
  143. {
  144. return DG.graphDefaults.sCurrentDir;
  145. }
  146. this.processKeyEvent = function ( keyEvent )
  147. {
  148. var bProcessed = false;
  149. if ( this.GraphCtrl )
  150. {
  151. bProcessed = this.GraphCtrl.processKeyEvent( keyEvent );
  152. }
  153. return bProcessed;
  154. }
  155. //----------------------------------------------------------------------------
  156. // Overriding the Graph VIRTUAL METHODs to provide customized behaviour
  157. //----------------------------------------------------------------------------
  158. this.getObjectIcon = function ( modelObject )
  159. {
  160. ASSERT( modelObject != null, "getObjectIcon: modelObject is NOT valid !" );
  161. if ( ! modelObject )
  162. return 0;
  163. var sObjClass = modelObject.getObjClass();
  164. var sIconFile = LNS.arrClassIcons[ sObjClass ];
  165. // Specific cases
  166. if ( sObjClass == "dimension" )
  167. {
  168. if ( modelObject.getObjSubClass() == "measure" )
  169. sIconFile = "measure_dimension.gif";
  170. }
  171. else
  172. if ( sObjClass == "calculation" )
  173. {
  174. // alert( "calcType = " + modelObject.findPropertyValue( "calcType" ) );
  175. if ( modelObject.findPropertyValue( "calcType" ) == "Named Set" )
  176. sIconFile = "named_set.gif";
  177. }
  178. ASSERT( sIconFile != null, "getObjectIcon: Icon file for object class '" + sObjClass + "' is NOT found !" );
  179. var nIconIndex = this.GraphCtrl.getIconIndex ( sIconFile );
  180. return nIconIndex;
  181. }
  182. this.isShowItemIcon = function ( modelObject )
  183. {
  184. ASSERT( modelObject != null, "isShowItemIcon: modelObject is NOT valid !" );
  185. var bShow = false;
  186. if ( modelObject != null )
  187. {
  188. if ( LNS.arrItemsTypesWithIcon[ modelObject.getObjClass() ] )
  189. {
  190. // alert ("isShowItemIcon: show icon for type <" + modelObject.getObjClass() + ">");
  191. bShow = true;
  192. }
  193. }
  194. return bShow;
  195. }
  196. // OnActionClick - virtual callback method. Override it in the controller for a custom action.
  197. this.OnActionClick = function( modelObject )
  198. {
  199. var bAction = true;
  200. if ( bAction )
  201. {
  202. if ( this.sActionURL.length > 0 )
  203. {
  204. window.open( this.sActionURL );
  205. }
  206. }
  207. return bAction;
  208. }
  209. //----------------------------------------------------------------------------
  210. //----------------------------------------------------------------------------
  211. this.Init = function ( modelData )
  212. {
  213. LNS.oTechnicalView = this;
  214. if ( this.bInitialized )
  215. return;
  216. this.modelData = modelData;
  217. // Config global diagram settings
  218. DG.graphDefaults.bShowActionLinks = this.bShowActionLinks;
  219. DG.graphDefaults.sActionIcon = this.sActionIcon;
  220. DG.graphDefaults.sActionIconTooltip = this.sActionIconTooltip;
  221. try
  222. {
  223. var timeStart = new Date().getTime();
  224. // Initialize Graph Panes
  225. this.paneManager = new CPaneManager ( this.canvasId );
  226. ASSERT ( this.modelData.getPaneCount() > 0, "Init: No panes to display !!!" );
  227. if ( this.modelData.getPaneCount() > 0 )
  228. {
  229. var nInitialPaneWidth = 100 / this.modelData.getPaneCount();
  230. for ( var i = 0; i < this.modelData.getPaneCount(); i++ )
  231. {
  232. var pane = new CPaneInfo ( this.paneManager, this.modelData.getPaneName(i), "expanded", nInitialPaneWidth );
  233. this.paneManager.addPane ( pane );
  234. }
  235. }
  236. // Initialize Property Pane
  237. this.propertyPaneQuery = new CPropertyPane( "id_query_property_table" );
  238. this.propertyPaneItem = new CPropertyPane( "id_item_property_table" );
  239. this.propertyManager = new CPropertyMgr ( this.propertyPaneQuery, this.propertyPaneItem );
  240. // Initialize Main Graph
  241. this.GraphCtrl = new DG.CGraphControl( this, this.canvasId, this.propertyManager );
  242. // Initialize Pane Manager
  243. this.paneManager.Init ( this.GraphCtrl, 'id_graph_header' );
  244. this.populateGraph( this.modelData, this.GraphCtrl, this.paneManager );
  245. this.eventProcessor = new OnPostPopulate ( this.GraphCtrl, this.paneManager );
  246. this.updateGraphHeader ( 'id_graph_header', this.GraphCtrl, this.paneManager );
  247. this.paneManager.ExpandPanes ( true );
  248. // alertTimeDiff ( timeStart, "CTechnicalView.init" );
  249. // Debug Diagnostics
  250. // var sElemContents = walkChildNodes( document.body, false );
  251. // var sElemContents = walkChildNodes( this.GraphCtrl.gdi.id, false );
  252. // alert ( sElemContents );
  253. }
  254. catch ( err )
  255. {
  256. var txt = "Init: Error " + err.description + "\n\n";
  257. txt += "Click OK to continue.\n\n";
  258. alert ( txt );
  259. }
  260. finally
  261. {
  262. this.bInitialized = true;
  263. }
  264. }
  265. this.populateGraph = function ( modelData, graph, paneManager )
  266. {
  267. // Config Graph
  268. graph.m_isDragHorzAllowed = false;
  269. // Populate Graph
  270. for ( var i = 0; i < modelData.getObjectCount(); i++ )
  271. {
  272. var gNode = new DG.CGraphNode ( modelData.getObject( i ), graph );
  273. graph.addNode ( gNode );
  274. }
  275. // Split the node list into the corresponding pane node lists
  276. paneManager.splitNodes ( graph.m_nodeList );
  277. //-------------------------------------------------------------------------------------
  278. // Set Nodes' Initial Layout
  279. //-------------------------------------------------------------------------------------
  280. paneManager.Layout ();
  281. //----------------------------------------------------------------------
  282. // Add Connections
  283. //----------------------------------------------------------------------
  284. for ( var j = 0; j < modelData.getConnectionCount(); ++j )
  285. {
  286. var objLeft = modelData.getConnectionLeft( j );
  287. var objRight = modelData.getConnectionRight( j );
  288. // alert ( "populateGraph: create connection from " + objLeft + " to " + objRight );
  289. if ( objLeft && objRight )
  290. {
  291. var graphConn = new DG.CGraphConnection ( objLeft, objRight, graph );
  292. if ( graphConn.isValid )
  293. graph.addConnection ( graphConn );
  294. }
  295. }
  296. // Painting the graph objects
  297. graph.paint();
  298. }
  299. this.toggleReportPaneState = function ( idElemLink, cookieMgr )
  300. {
  301. var temp = idElemLink;
  302. var elemLink = document.getElementById( idElemLink );
  303. var sState = cookieMgr.getCookie( "lineageReportPaneState" );
  304. if ( sState == "collapsed" )
  305. {
  306. elemLink.innerHTML = "REPORT (+)";
  307. sState = "expanded";
  308. cookieMgr.setCookie( "lineageReportPaneState", sState );
  309. }
  310. else
  311. {
  312. elemLink.innerHTML = "REPORT (-)";
  313. sState = "collapsed";
  314. cookieMgr.setCookie( "lineageReportPaneState", sState );
  315. }
  316. }
  317. this.toggleModelPaneState = function( idElemLink, cookieMgr )
  318. {
  319. var temp = idElemLink;
  320. var elemLink = document.getElementById( idElemLink );
  321. var sState = cookieMgr.getCookie( "lineageModelPaneState" );
  322. if ( sState == "collapsed" )
  323. {
  324. elemLink.innerHTML = "MODEL (+)";
  325. sState = "expanded";
  326. cookieMgr.setCookie( "lineageModelPaneState", sState );
  327. }
  328. else
  329. {
  330. elemLink.innerHTML = "MODEL (-)";
  331. sState = "collapsed";
  332. cookieMgr.setCookie( "lineageModelPaneState", sState );
  333. }
  334. }
  335. this.updateGraphHeader = function ( headerId, graph, paneManager )
  336. {
  337. //----------------------------------------------------------------------------------
  338. // Create Pane Captions and Buttons
  339. //----------------------------------------------------------------------------------
  340. paneManager.createControls ( headerId );
  341. paneManager.moveControls ();
  342. }
  343. }