VisualizationAPISpec.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. 2020
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. define([], function () {
  9. var APISpec = function () {
  10. function APISpec() {
  11. _classCallCheck(this, APISpec);
  12. }
  13. APISpec.prototype.getAPISpec = function getAPISpec() {
  14. var _this = this;
  15. if (!this.apiSpec) {
  16. var lockReverseAction = function lockReverseAction() {
  17. var name = void 0;
  18. if (_this.isTypeLocked()) {
  19. name = 'lockType';
  20. } else {
  21. name = 'unlockType';
  22. }
  23. return [{
  24. name: name
  25. }];
  26. };
  27. this.apiSpec = {
  28. name: 'visualization API',
  29. features: {
  30. 'Dashboard.Transaction': this.transaction
  31. },
  32. events: {
  33. propagationInfo: {
  34. info: {
  35. supportsUndoRedo: true,
  36. refresh: {
  37. dataIfQueryChanged: true
  38. }
  39. }
  40. },
  41. actions: {
  42. setDataSource: {
  43. eventName: 'dataSource',
  44. getUndoActions: function getUndoActions() {
  45. var dataSource = _this.getDataSource();
  46. return [{ params: [dataSource ? dataSource.getId() : null] }];
  47. },
  48. isTriggerEvent: function isTriggerEvent(action, undoActions, returnValue) {
  49. return returnValue;
  50. }
  51. },
  52. setType: {
  53. info: {
  54. supportsUndoRedo: true,
  55. refresh: {
  56. all: true, // need to refresh all so that we can refresh the visView
  57. propertiesPane: true
  58. }
  59. },
  60. eventName: 'type',
  61. getUndoActions: function getUndoActions(args) {
  62. var actions = [];
  63. actions.push({
  64. name: 'setType',
  65. params: [_this.getType()]
  66. });
  67. // Get the dataitem that are mappedn to slots that do not exist in the new definition
  68. var newDefinition = _this.visDefinitions.getByType(args[0]);
  69. if (newDefinition) {
  70. var newSlots = newDefinition.getSlotList();
  71. var slotsToBeRemoved = _this.slotsImpl.getSlotList().filter(function (slot) {
  72. return !newSlots.find(function (newSlot) {
  73. return newSlot.getId() === slot.getId();
  74. });
  75. });
  76. slotsToBeRemoved.forEach(function (slotToBeRemoved) {
  77. // Use the internal getDataItemList method and include the option to ignore default slot dataitems
  78. // default data items don't need to be tracked in here.
  79. var dataItems = _this.slotsImpl.getSlotImpl(slotToBeRemoved.getId()).getDataItemList(true);
  80. if (dataItems.length > 0) {
  81. actions.push({
  82. callStack: [{
  83. name: 'getSlots',
  84. params: []
  85. }, {
  86. name: 'getSlot',
  87. params: [slotToBeRemoved.getId()]
  88. }],
  89. name: 'addDataItemsMapping',
  90. params: [dataItems.map(function (dataItem) {
  91. return dataItem.getId();
  92. }), 0]
  93. });
  94. }
  95. });
  96. }
  97. return actions;
  98. }
  99. },
  100. lockType: {
  101. eventName: 'lockType',
  102. getUndoActions: lockReverseAction
  103. },
  104. unlockType: {
  105. info: {
  106. supportsUndoRedo: true,
  107. refresh: {
  108. all: true // Refresh everything including the visView.. unlocking might change the visType
  109. }
  110. },
  111. eventName: 'unlockType',
  112. getUndoActions: lockReverseAction
  113. }
  114. }
  115. }
  116. };
  117. }
  118. return this.apiSpec;
  119. };
  120. return APISpec;
  121. }();
  122. return APISpec;
  123. });
  124. //# sourceMappingURL=VisualizationAPISpec.js.map