VidaResourceLoaderService.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. /**
  4. *+------------------------------------------------------------------------+
  5. *| Licensed Materials - Property of IBM
  6. *| IBM Cognos Products: Dashboard
  7. *| (C) Copyright IBM Corp. 2020
  8. *|
  9. *| US Government Users Restricted Rights - Use, duplication or disclosure
  10. *| restricted by GSA ADP Schedule Contract with IBM Corp.
  11. *+------------------------------------------------------------------------+
  12. */
  13. define(['underscore', 'com/ibm/vida/control/vida', 'text!../../visualizations/vipr/viprVisLibrary.json'], function (_, vida, viprVisLibrary) {
  14. 'use strict';
  15. var hostAPI = {};
  16. /**
  17. * This class is exposed as a glass service; the CA Mobile App will use it to "warm up" VIDA
  18. */
  19. var VidaResourceLoader = function () {
  20. function VidaResourceLoader() {
  21. _classCallCheck(this, VidaResourceLoader);
  22. }
  23. VidaResourceLoader.prototype.initialize = function initialize() {
  24. var _this = this;
  25. if (this.done) return Promise.resolve();
  26. this.done = true;
  27. try {
  28. var bundles = JSON.parse(viprVisLibrary).system;
  29. _.extend(this, vida.VIPR.create({ bundles: bundles }));
  30. var bundleIds = bundles.map(function (bundle) {
  31. return bundle.id;
  32. });
  33. var promises = [];
  34. bundleIds.forEach(function (id) {
  35. return promises.push(_this._loadBundle(id));
  36. });
  37. var loadPromise = this._delay();
  38. return Promise.all(promises).then(function () {
  39. bundleIds.forEach(function (id) {
  40. loadPromise = loadPromise.then(_this._loadWidgetResources.bind(_this, id));
  41. });
  42. return loadPromise;
  43. });
  44. } catch (err) {
  45. console.debug(err);
  46. return Promise.resolve();
  47. }
  48. };
  49. VidaResourceLoader.prototype._loadWidgetResources = function _loadWidgetResources(id) {
  50. var _this2 = this;
  51. var widget = void 0;
  52. return this._delay().then(function () {
  53. widget = new vida.SmallMultipleGrid({ vipr: _this2, hostAPI: hostAPI }, id);
  54. return widget.newViz(id, 'client');
  55. }).then(function () {
  56. if (widget && typeof widget.destroy === 'function') {
  57. return widget.destroy();
  58. }
  59. }).catch(console.debug);
  60. };
  61. VidaResourceLoader.prototype._loadBundle = function _loadBundle(id) {
  62. return this.load(id).then(function (bundle) {
  63. return vida.SmallMultipleGrid.extendVizBundle(bundle);
  64. }).catch(console.debug);
  65. };
  66. VidaResourceLoader.prototype._delay = function _delay() {
  67. var time = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 50;
  68. return new Promise(function (resolve) {
  69. return setTimeout(resolve, time);
  70. });
  71. };
  72. return VidaResourceLoader;
  73. }();
  74. return VidaResourceLoader;
  75. });
  76. //# sourceMappingURL=VidaResourceLoaderService.js.map