VisDefinition.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  4. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  5. /**
  6. * Licensed Materials - Property of IBM
  7. * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2018, 2020
  8. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  9. */
  10. define(['underscore', '../VisDefinitionAPI', './VisDefinitionAPISpec', '../../lib/@waca/dashboard-common/dist/core/APIFactory', './SlotDefinition', './VisDefinitionState'], function (_, VisDefinitionAPI, VisDefinitionAPISpec, APIFactory, SlotDefinition, VisDefinitionStateImpl) {
  11. var DEFAULT_PREFERRED_SIZE = {
  12. width: 520,
  13. height: 400
  14. };
  15. var VisDefinitionImpl = function (_VisDefinitionAPISpec) {
  16. _inherits(VisDefinitionImpl, _VisDefinitionAPISpec);
  17. function VisDefinitionImpl(visSpec, visDefinitionManager) {
  18. _classCallCheck(this, VisDefinitionImpl);
  19. var _this = _possibleConstructorReturn(this, _VisDefinitionAPISpec.call(this));
  20. _this.visDefinitionManager = visDefinitionManager;
  21. _this.visSpec = visSpec;
  22. // We hold on to the impl so that we can destroy the objects.
  23. _this.slotDefinitionImpls = [];
  24. _this.slotDefinitionAPIs = [];
  25. _this._visDefinitionStateImpl = new VisDefinitionStateImpl();
  26. return _this;
  27. }
  28. VisDefinitionImpl.prototype.destroy = function destroy() {
  29. if (this.slotDefinitionImpls) {
  30. this.slotDefinitionImpls.forEach(function (def) {
  31. return def.destroy();
  32. });
  33. }
  34. this.slotDefinitionImpls = null;
  35. this.visDefinitionManager = null;
  36. this.visSpec = null;
  37. this.slotDefinitionAPIs = null;
  38. this._visDefinitionStateImpl = null;
  39. };
  40. VisDefinitionImpl.prototype.getAPI = function getAPI() {
  41. return APIFactory.createAPI(this, [VisDefinitionAPI]);
  42. };
  43. VisDefinitionImpl.prototype.getType = function getType() {
  44. return this.visSpec.type;
  45. };
  46. VisDefinitionImpl.prototype.getId = function getId() {
  47. return this.visSpec.id;
  48. };
  49. VisDefinitionImpl.prototype.getDatasetList = function getDatasetList() {
  50. return _.map(this.visSpec.datasets, function (dataset) {
  51. return {
  52. id: dataset.name,
  53. caption: dataset.caption,
  54. optional: dataset.optional,
  55. suppressMissing: dataset.suppressMissing,
  56. needsSorted: dataset.needsSorted,
  57. requiresValues: dataset.requiresValues
  58. };
  59. });
  60. };
  61. VisDefinitionImpl.prototype.getLabel = function getLabel() {
  62. return this.visSpec.label;
  63. };
  64. VisDefinitionImpl.prototype.getIcon = function getIcon() {
  65. return this.visSpec.icon;
  66. };
  67. VisDefinitionImpl.prototype.getIconUri = function getIconUri() {
  68. return this.visSpec.iconUri;
  69. };
  70. VisDefinitionImpl.prototype.getPlaceholderIconUri = function getPlaceholderIconUri() {
  71. return this.visSpec.placeholderIcon;
  72. };
  73. VisDefinitionImpl.prototype.getPreferredSize = function getPreferredSize() {
  74. return this.visSpec.preferredSize || DEFAULT_PREFERRED_SIZE;
  75. };
  76. VisDefinitionImpl.prototype.getSlot = function getSlot(id) {
  77. return this.getSlotList().find(function (slot) {
  78. return slot.getId() === id;
  79. });
  80. };
  81. VisDefinitionImpl.prototype.getSlotList = function getSlotList() {
  82. var _this2 = this;
  83. if (this.slotDefinitionAPIs.length === 0) {
  84. _.each(this.visSpec.dataSlots, function (slot) {
  85. var impl = new SlotDefinition(slot);
  86. _this2.slotDefinitionImpls.push(impl);
  87. _this2.slotDefinitionAPIs.push(impl.getAPI());
  88. });
  89. }
  90. return this.slotDefinitionAPIs;
  91. };
  92. VisDefinitionImpl.prototype.getMultiEdgeSort = function getMultiEdgeSort() {
  93. return this.visSpec.queryHints && this.visSpec.queryHints.multiEdgeSort;
  94. };
  95. VisDefinitionImpl.prototype.getDefaultDatasetId = function getDefaultDatasetId() {
  96. return this.visSpec.defaultDatasetId || undefined;
  97. };
  98. VisDefinitionImpl.prototype.getState = function getState() {
  99. return this._visDefinitionStateImpl.getAPI();
  100. };
  101. VisDefinitionImpl.prototype.setError = function setError(error) {
  102. this._visDefinitionStateImpl.setError(error);
  103. };
  104. VisDefinitionImpl.prototype.refresh = function refresh() {
  105. var _this3 = this;
  106. var visId = this.visSpec.id;
  107. return this.visDefinitionManager.refresh(visId).then(function (newDef) {
  108. _this3.visSpec = newDef;
  109. if (_this3.getState().getError() && !newDef.empty) {
  110. _this3.setError(undefined); //only if an error is undefined is treated as no error, ref livewidget=>isInvalidVisDefinition
  111. }
  112. //clear the slot def cache
  113. _this3.slotDefinitionAPIs = [];
  114. return newDef;
  115. });
  116. };
  117. VisDefinitionImpl.prototype.getProperty = function getProperty(id) {
  118. return this.visSpec[id];
  119. };
  120. return VisDefinitionImpl;
  121. }(VisDefinitionAPISpec);
  122. return VisDefinitionImpl;
  123. });
  124. //# sourceMappingURL=VisDefinition.js.map