CCognosViewerDebugLogger.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /*
  2. *+------------------------------------------------------------------------+
  3. *| Licensed Materials - Property of IBM
  4. *| IBM Cognos Products: Viewer
  5. *| (C) Copyright IBM Corp. 2013
  6. *|
  7. *| US Government Users Restricted Rights - Use, duplication or
  8. *| disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  9. *|
  10. *+------------------------------------------------------------------------+
  11. */
  12. if (!window.gViewerLogger) {
  13. window.gViewerLogger = {};
  14. }
  15. window.gViewerLogger.clientLogs = [];
  16. window.gViewerLogger.logTimerStarted = false;
  17. window.gViewerLogger.getCookie = function(name) {
  18. var arg = name + "=";
  19. var alen = arg.length;
  20. var clen = document.cookie.length;
  21. var i = 0;
  22. while (i < clen) {
  23. var j = i + alen;
  24. if (document.cookie.substring(i, j) == arg) {
  25. return window.gViewerLogger.getCookieVal(j);
  26. }
  27. i = document.cookie.indexOf(" ", i) + 1;
  28. if (i === 0) {
  29. break;
  30. }
  31. }
  32. return null;
  33. };
  34. window.gViewerLogger.getCookieVal = function(offset) {
  35. var endstr = document.cookie.indexOf(";", offset);
  36. if (endstr == -1) {
  37. endstr = document.cookie.length;
  38. }
  39. return document.cookie.substring(offset, endstr);
  40. };
  41. window.gViewerLogger.isLoggingEnabled = function() {
  42. return window.gViewerLogger.getCookie("captureViewerClientLogs") === "true";
  43. };
  44. window.gViewerLogger.log = function(hint, content, type) {
  45. if (!window.gViewerLogger.isLoggingEnabled()) {
  46. return;
  47. }
  48. var contentText = typeof content == "string" ? content : CViewerCommon.toJSON(content);
  49. var logs = {
  50. "label" : hint.replace(/\"/g,"\\\""),
  51. "content" : contentText.replace(/\"/g,"\\\""),
  52. "type" : type
  53. };
  54. window.gViewerLogger.clientLogs.push(logs);
  55. if (!window.gViewerLogger.logTimerStarted) {
  56. window.gViewerLogger.logTimerStarted = true;
  57. setTimeout(window.gViewerLogger.uploadLogs, 5000);
  58. }
  59. };
  60. window.gViewerLogger.uploadLogs = function() {
  61. var logs = {"clientLog" : true, "logs" : window.gViewerLogger.clientLogs};
  62. var jsonLogs = CViewerCommon.toJSON(logs);
  63. var httpRequest = new XmlHttpObject();
  64. httpRequest.addFormField("b_action", "cognosViewer");
  65. httpRequest.addFormField("ui.action", "saveJSONLogs");
  66. httpRequest.addFormField("cv.responseFormat", "successfulRequest");
  67. httpRequest.addFormField("cv.jsonLogs", jsonLogs);
  68. //send asynchronous request
  69. httpRequest.sendHtmlRequest("POST", window.gaRV_INSTANCES[0].getGateway(), "", true);
  70. window.gViewerLogger.clientLogs = [];
  71. window.gViewerLogger.logTimerStarted = false;
  72. };
  73. window.gViewerLogger.addSubscriptionSpec = function(sc) {
  74. if (!window.gViewerLogger.isLoggingEnabled()) {
  75. return;
  76. }
  77. if (sc && sc.m_oCognosViewer !== null && typeof sc.m_oCognosViewer != "undefined") {
  78. var oCV = sc.m_oCognosViewer;
  79. if (oCV.getSubscriptionManager() !== null) {
  80. try {
  81. var fWR = document.getElementById("formWarpRequest" + oCV.getId());
  82. var selectionXml = new CSelectionXml( fWR["ui.burstID"].value,
  83. fWR["ui.contentLocale"].value,
  84. fWR["ui.outputLocale"].value
  85. );
  86. selectionXml.BuildSelectionFromController(sc);
  87. window.gViewerLogger.log("Subscription Spec", selectionXml.toXml(), "xml");
  88. }
  89. catch (e) {}
  90. }
  91. }
  92. };
  93. window.gViewerLogger.addContextInfo = function(sc) {
  94. if (!window.gViewerLogger.isLoggingEnabled()) {
  95. return;
  96. }
  97. if (sc) {
  98. var sText = "";
  99. var selectedObjects = sc.getAllSelectedObjects();
  100. if (selectedObjects.length <= 0) {
  101. return;
  102. }
  103. this.addSubscriptionSpec(sc);
  104. for(var s = 0; s < selectedObjects.length; ++s) {
  105. var selection = selectedObjects[s];
  106. var sCTX = "";
  107. var aContextIds = selection.getSelectedContextIds();
  108. var i,j;
  109. for(i = 0; i < aContextIds.length; ++i) {
  110. if (i > 0) {
  111. sCTX += "::";
  112. }
  113. for(j = 0; j < aContextIds[i].length; ++j) {
  114. if (j > 0)
  115. {
  116. sCTX += ":";
  117. }
  118. sCTX += aContextIds[i][j];
  119. }
  120. }
  121. if (sText !== "") {
  122. sText += "\\n\\n\\n";
  123. }
  124. sText += "selection ctx: " + sCTX;
  125. var bookletItem = sc.getBookletItemForCurrentSelection();
  126. if (bookletItem) {
  127. var md = sc.m_oCDManager.m_md;
  128. var rr = md[bookletItem];
  129. sText += "\\n\\nBooklet Item: " + bookletItem;
  130. sText += "\\n\tReport Reference: " + rr.b;
  131. sText += "\\n\tSource Report: " + md[rr.sp].sp;
  132. sText += "\\n\tModel Path: " + md[rr.mp].mp;
  133. sText += "\\n\tExpression Locale: " + rr.expressionLocale;
  134. sText += "\\n\tDrill Flag: " + rr.drillUpDown;
  135. sText += "\\n\tPackage Drill Through: " + rr.modelBasedDrillThru;
  136. }
  137. var oCell = selection.getCellRef();
  138. var dttargets = "";
  139. if (oCell && oCell.firstChild) {
  140. dttargets = oCell.firstChild.getAttribute("dttargets");
  141. if (typeof oCell.firstChild.getAttribute("dttargets") != "undefined" && oCell.firstChild.getAttribute("dttargets") !== null) {
  142. dttargets = oCell.firstChild.getAttribute("dttargets");
  143. }
  144. }
  145. var selectionCtx = selection.getSelectedContextIds();
  146. var muns = selection.getMuns();
  147. var munCount = muns.length;
  148. for(i = 0; i < munCount; ++i) {
  149. for(j = 0; j < muns[i].length; ++j) {
  150. var ctxId = selectionCtx[i][j];
  151. sText += "\\n\\nctx: " + ctxId;
  152. sText += "\\n\tabc: " + sc.getDisplayValue(ctxId);
  153. sText += "\\n\tuse value: " + sc.getUseValue(ctxId);
  154. sText += "\\n\tref data item: " + sc.getRefDataItem(ctxId);
  155. sText += "\\n\tmun: " + sc.getMun(ctxId);
  156. sText += "\\n\tlun: " + sc.getLun(ctxId);
  157. sText += "\\n\thun: " + sc.getHun(ctxId);
  158. sText += "\\n\tusage: " + sc.getCCDManager().GetUsage(ctxId);
  159. sText += "\\n\tdrill: " + sc.getCCDManager().GetDrillFlag(ctxId);
  160. if (i === 0 && j === 0 && dttargets) {
  161. sText += "\\n\tdttargets: " + dttargets.replace(/\\\"/g,"\"");
  162. }
  163. }
  164. }
  165. }
  166. window.gViewerLogger.log("Context Info", sText, "text");
  167. }
  168. };