rsShareHelper.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /*
  2. IBM Confidential
  3. OCO Source Materials
  4. IBM Cognos Products: rs
  5. (C) Copyright IBM Corp. 2017, 2020
  6. The source code for this program is not published or otherwise divested of its trade secrets, irrespective of what has been deposited with the U.S. Copyright Office.
  7. */
  8. define(['bi/authoring/utils/pat/rsPromptParameters', 'bi/authoring/utils/rsOpenHelper','bi/authoring/utils/rsCommon', 'jquery', 'q'], function(rsPromptParameters, OpenHelper, rsCommon, $, Q){
  9. 'use strict';
  10. // CM properties needed to generate share URL
  11. var M_aShareProperties = [
  12. { property: 'id', type: null },
  13. { property: 'type', type: null },
  14. { property: 'burstKey', type: ['output'] },
  15. { property: 'parent', type: null }
  16. ];
  17. function createShareUrl(v_oOpenSpec, v_oCmProperties) {
  18. var v_oUrlMap = {};
  19. if (v_oOpenSpec && v_oOpenSpec.contentView) {
  20. v_oUrlMap = $.extend(v_oUrlMap, rsCommon.extractGlassSettings(v_oOpenSpec.contentView));
  21. }
  22. var v_sObjRef = v_oCmProperties.id;
  23. switch (v_oCmProperties.type)
  24. {
  25. case 'dataSet2':
  26. v_oUrlMap.objRef = v_sObjRef;
  27. break;
  28. case 'output':
  29. // For burst output, use the id of the actual output object
  30. // otherwise use the id of output parent i.e. reportVersion
  31. // Using the version allows the system to select the most appropriate format/locale based on user's preferences
  32. // However there is no support for this if the output needs to be filtered by burst key
  33. // so in that case we go with the specific output object.
  34. v_oUrlMap.objRef = v_oCmProperties.burstKey ? v_sObjRef : v_oCmProperties.parent[0].id;
  35. break;
  36. default:
  37. v_oUrlMap.objRef = v_sObjRef;
  38. if (v_oOpenSpec.mode === 'current')
  39. {
  40. if (v_oOpenSpec.glassContext.currentAppView)
  41. {
  42. var v_oCurrentContentView = v_oOpenSpec.glassContext.currentAppView.currentContentView;
  43. if (v_oCurrentContentView)
  44. {
  45. switch (v_oCurrentContentView.perspective)
  46. {
  47. case 'authoring':
  48. var v_oApplication = v_oCurrentContentView.getAuthoringApplication && v_oCurrentContentView.getAuthoringApplication();
  49. if (v_oApplication)
  50. {
  51. if (v_oApplication.SharedState.Get("isViewer"))
  52. {
  53. v_oUrlMap.action = 'run';
  54. var v_sObjectType = v_oApplication.SharedState.Get("objectType");
  55. if (v_sObjectType != 'interactiveReport')
  56. {
  57. // No format needed on active reports
  58. var v_sViewer = v_oApplication.SharedState.Get("viewer");
  59. switch(v_sViewer.toUpperCase())
  60. {
  61. case "HTML":
  62. v_oUrlMap.format = "HTML";
  63. break;
  64. case "PDF":
  65. v_oUrlMap.format = "PDF";
  66. break;
  67. }
  68. }
  69. }
  70. else
  71. {
  72. v_oUrlMap.action = 'edit';
  73. }
  74. }
  75. else
  76. {
  77. // Being called before application was loaded so try alternative source of information
  78. v_oUrlMap.action = v_oCurrentContentView.action || (v_oCurrentContentView.isViewer ? 'run' : 'edit');
  79. if (v_oUrlMap.action != 'edit')
  80. {
  81. v_oUrlMap.format = v_oCurrentContentView.format;
  82. }
  83. }
  84. break;
  85. case 'classicviewer':
  86. // If requesting share link in classic viewer for non-output object, then action is
  87. // always run. No need to check for active report when setting format since
  88. // classic active reports are displayed stand alone (no glass) so there is no way
  89. // to request a share URL.
  90. v_oUrlMap.action = 'run';
  91. var v_sOutputFormat;
  92. if (v_oCurrentContentView.m_oRVFormParameters && v_oCurrentContentView.m_oRVFormParameters['run.outputFormat'] )
  93. {
  94. v_sOutputFormat = v_oCurrentContentView.m_oRVFormParameters['run.outputFormat'];
  95. }
  96. else
  97. {
  98. v_sOutputFormat = v_oCurrentContentView.format;
  99. }
  100. v_oUrlMap.format = v_sOutputFormat || 'HTML';
  101. break;
  102. }
  103. }
  104. }
  105. }
  106. break;
  107. }
  108. return v_oUrlMap;
  109. }
  110. function retrievePromptParameters(v_oOpenSpec, v_oUrlMap) {
  111. //Only include prompt values if sharing from current view/set as home
  112. if (v_oOpenSpec.mode == 'current')
  113. {
  114. if (v_oOpenSpec.glassContext.currentAppView)
  115. {
  116. var v_oCurrentContentView = v_oOpenSpec.glassContext.currentAppView.currentContentView;
  117. if (v_oCurrentContentView)
  118. {
  119. var v_oApplication = v_oCurrentContentView.getAuthoringApplication && v_oCurrentContentView.getAuthoringApplication();
  120. // If in classic viewer or authoring viewer, then get parameters
  121. if (v_oCurrentContentView.perspective == 'classicviewer' || (v_oApplication && v_oApplication.SharedState.Get("isViewer")))
  122. {
  123. var v_aParameters = v_oCurrentContentView.getParameterValues(true);
  124. if (v_aParameters && v_aParameters.length > 0)
  125. {
  126. v_oUrlMap.prompt = false;
  127. rsPromptParameters.rsBuildParameterUrl( v_oUrlMap, v_aParameters );
  128. }
  129. }
  130. }
  131. }
  132. }
  133. return v_oUrlMap;
  134. }
  135. function buildShareUrl( v_oOpenSpec, v_oCmProperties ) {
  136. var v_oUrlMap = createShareUrl(v_oOpenSpec, v_oCmProperties);
  137. return retrievePromptParameters(v_oOpenSpec, v_oUrlMap);
  138. }
  139. function prepareShareUrlMap(v_oOpenSpec) {
  140. var deferred = Q.defer();
  141. // Only ask for minimal set of properties needed to generate share URL
  142. OpenHelper.retreiveCMInfo(v_oOpenSpec.cmProperties, v_oOpenSpec.glassContext, M_aShareProperties)
  143. .then( buildShareUrl.bind(null, v_oOpenSpec) )
  144. .fail(function(err){
  145. console.log('OpenHelper.prepareShareUrlMap ... FAILED');
  146. deferred.reject(err);
  147. })
  148. .done( function(v_oUrlMap){
  149. deferred.resolve(v_oUrlMap);
  150. });
  151. return deferred.promise;
  152. }
  153. return {
  154. getShareUrlMap: function(v_oOpenSpec) {
  155. var deferred = Q.defer();
  156. prepareShareUrlMap(v_oOpenSpec)
  157. .catch( function(err){
  158. console.log('rsShareHelper.getShareUrlMap ... FAILED');
  159. deferred.reject(err);
  160. }).done( function(v_oUrlMap) {
  161. deferred.resolve(v_oUrlMap);
  162. });
  163. return deferred.promise;
  164. },
  165. buildShareUrlMap: function(v_oContentView ) {
  166. var v_oCmProperties = v_oContentView.cmProperties;
  167. var glassContext = v_oContentView.glassContext;
  168. var v_oOpenSpec = {
  169. mode: "current",
  170. glassContext: glassContext,
  171. contentView: v_oContentView
  172. };
  173. return buildShareUrl( v_oOpenSpec, v_oCmProperties );
  174. },
  175. isShareable: function(v_oCurrentContentView, v_bEmbed) {
  176. var v_bShareable = false;
  177. if (v_oCurrentContentView && v_oCurrentContentView.canRun())
  178. {
  179. var v_oAuthoringApp = v_oCurrentContentView.getAuthoringApplication();
  180. if (v_oCurrentContentView.perspective == 'datasets')
  181. {
  182. // Datasets don't support embed from overflow menu
  183. v_bShareable = !v_bEmbed;
  184. }
  185. // Must check shared state for viewer since this can change one perspective is opened (click pencil)
  186. else if (v_oCurrentContentView.perspective == 'classicviewer' || (v_oAuthoringApp && v_oAuthoringApp.SharedState.Get("isViewer")))
  187. {
  188. if (v_oAuthoringApp && v_oAuthoringApp.SharedState.Get("storeID"))
  189. {
  190. v_bShareable = true;
  191. }
  192. }
  193. }
  194. return v_bShareable;
  195. }
  196. };
  197. });