DashboardFactory.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. 'use strict';
  2. /*
  3. *+------------------------------------------------------------------------+
  4. *| Licensed Materials - Property of IBM
  5. *| IBM Cognos Products: Content Explorer
  6. *| (C) Copyright IBM Corp. 2017, 2018
  7. *|
  8. *| US Government Users Restricted Rights - Use, duplication or disclosure
  9. *| restricted by GSA ADP Schedule Contract with IBM Corp.
  10. *+------------------------------------------------------------------------+
  11. */
  12. define(['../../../lib/@waca/core-client/js/core-client/ui/core/Class', 'underscore'], function (BaseClass, _) {
  13. 'use strict';
  14. /**
  15. * @class DashboardFactory
  16. * @hideconstructor
  17. * @classdesc Factory class that is used to instantiate a {@link DashboardApi} instance.<br>
  18. * <strong>DashboardFactory</strong> can not be instantiated directly.
  19. * <strong>DashboardFactory</strong> can be obtained through an instance of {@link CognosApi}.
  20. * @example
  21. * // Create an instance of the CognosApi
  22. * const api = new CognosApi({
  23. * cognosRootURL: 'http://localhost/bi/',
  24. * node: document.getElementById('containerDivId'),
  25. * sessionCode: 'CD1a2b34567b8c901234d5'
  26. * });
  27. *
  28. * // initialize the CognosApi in order to obtain the service APIs
  29. * api.initialize().then(() => {
  30. * // create a new dashboard through the dashboard factory
  31. * api.dashboard.createNew();
  32. * ...
  33. * // open an existing dashboard through the dashboard factory
  34. * api.dashboard.openDashboard();
  35. * ...
  36. * });
  37. */
  38. var DashboardFactory = BaseClass.extend({
  39. API_METHODS: ['createNew', 'openDashboard'],
  40. API_ENUMS: [],
  41. init: function init(options) {
  42. this.glassContext = options.glassContext;
  43. },
  44. /**
  45. * Create a {@link DashboardApi} instance of a new dashboard
  46. * @function DashboardFactory#createNew
  47. * @example
  48. * const dashboardApi = null;
  49. * api.dashboard.createNew().then((dashboardApi) => {
  50. * console.log('Dashboard created successfully.');
  51. * dashboardApi = dashboardApi;
  52. * }).catch((err) => {
  53. * console.log('Cancelled by user.');
  54. * });
  55. */
  56. createNew: function createNew() {
  57. return new Promise(function (resolve, reject) {
  58. this.glassContext.appController.openAppView('createBoard', {
  59. content: {
  60. id: 'createBoardPage_dashboard',
  61. editMode: true,
  62. restrictTemplate: 'dashboard',
  63. containerAppOptions: {
  64. callbacks: {
  65. resolve: resolve,
  66. reject: reject
  67. },
  68. configuration: {
  69. ui: {},
  70. pinning: 'disabled'
  71. }
  72. },
  73. ui_appbar: false
  74. }
  75. });
  76. }.bind(this));
  77. },
  78. /**
  79. * Create a {@link DashboardApi} instance of an existing dashboard
  80. * @function DashboardFactory#openDashboard
  81. * @param {Object} option.dashboardSpec dashboard specification to open
  82. * @see {@link DashboardApi#getSpec DashboardApi.getSpec}
  83. * @example
  84. * const dashboardApi = null;
  85. * api.dashboard.openDashboard({
  86. * dashboardSpec: {...}
  87. * }).then((dashboardApi) => {
  88. * console.log('Dashboard opened successfully.');
  89. * dashboardApi = dashboardApi;
  90. * });
  91. */
  92. openDashboard: function openDashboard(options) {
  93. return new Promise(function (resolve, reject) {
  94. this.glassContext.appController.openAppView('dashboard', {
  95. content: {
  96. id: _.uniqueId(),
  97. editMode: false,
  98. containerAppOptions: {
  99. callbacks: {
  100. resolve: resolve,
  101. reject: reject
  102. },
  103. configuration: {
  104. ui: {},
  105. pinning: 'disabled'
  106. }
  107. },
  108. ui_appbar: false,
  109. boardId: options.dashboardId || null,
  110. boardSpec: options.dashboardSpec
  111. }
  112. });
  113. }.bind(this));
  114. }
  115. });
  116. return DashboardFactory;
  117. });
  118. //# sourceMappingURL=DashboardFactory.js.map