DashboardRuntimeService.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. /**
  4. * Licensed Materials - Property of IBM
  5. * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2018, 2020
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. define(['../../../api/core/glass/GlassDashboardFactory'], function (GlassDashboardFactory) {
  9. /**
  10. * Dashboard service that can be used to provide a dashboard runtime environment
  11. * that is needed to run code that is dashboard dependant (e.g. live widget) but without a dashboard Perspective
  12. * The service will require the dashboard perspective json, and use it to provide all the needed extensions and collections
  13. */
  14. var DashboardRuntimeService = function () {
  15. function DashboardRuntimeService() {
  16. _classCallCheck(this, DashboardRuntimeService);
  17. }
  18. DashboardRuntimeService.prototype.initialize = function initialize(glassContext) {
  19. this.dashboardFactory = new GlassDashboardFactory({
  20. glassContext: glassContext
  21. });
  22. return Promise.resolve();
  23. };
  24. DashboardRuntimeService.prototype.getDefaultSpec = function getDefaultSpec() {
  25. return {
  26. 'name': 'New dashboard',
  27. 'layout': {
  28. 'id': 'page0',
  29. 'items': [],
  30. 'style': {},
  31. 'type': 'tab'
  32. },
  33. 'theme': 'defaultTheme',
  34. 'eventGroups': [],
  35. 'fredIsRed': {
  36. 'colorMap': {},
  37. 'saveId': 2
  38. },
  39. 'pageContext': [],
  40. 'dataSources': {
  41. 'version': '1.0',
  42. 'sources': []
  43. },
  44. 'widgets': {}
  45. };
  46. };
  47. DashboardRuntimeService.prototype.getRuntimeEnvironment = function getRuntimeEnvironment(options) {
  48. var _this = this;
  49. if (!options && this.defaultRuntimeEnv) {
  50. return Promise.resolve(this.defaultRuntimeEnv);
  51. }
  52. return this.dashboardFactory.initializeRuntime().then(function () {
  53. return _this.dashboardFactory.runtimeEnv.getRuntimeEnvironment(options, _this.getDefaultSpec.bind(_this)).then(function (env) {
  54. if (!options) {
  55. _this.defaultRuntimeEnv = env;
  56. }
  57. return env;
  58. });
  59. });
  60. };
  61. return DashboardRuntimeService;
  62. }();
  63. return DashboardRuntimeService;
  64. });
  65. //# sourceMappingURL=DashboardRuntimeService.js.map