ContentAPISpec.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. 2019, 2020
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. /**
  9. * Create a public API to a decorator for the n-th vipr dataset
  10. *
  11. * @class DecoratorAPI
  12. * @hideconstructor
  13. * @classdesc
  14. */
  15. define([], function () {
  16. var Events = function () {
  17. function Events() {
  18. _classCallCheck(this, Events);
  19. }
  20. Events.prototype.getAPISpec = function getAPISpec() {
  21. var _this = this;
  22. if (!this.apiSpec) {
  23. this.apiSpec = {
  24. name: 'content API',
  25. events: {
  26. propagationInfo: {
  27. namespace: 'content',
  28. info: {
  29. contentId: this.getId()
  30. },
  31. callStack: {
  32. name: 'getContent',
  33. params: [this.getId()]
  34. }
  35. },
  36. actions: {
  37. addContent: {
  38. eventName: 'child',
  39. type: 'add',
  40. isResolvePostResponse: true,
  41. transactionAPI: this.transaction,
  42. transactionParamIndex: 1,
  43. autoCreateTransaction: true,
  44. getInfo: function getInfo(args, returnValue) {
  45. return {
  46. value: args[0],
  47. newContentId: returnValue.getId(),
  48. parentId: returnValue.getContainer().getId(),
  49. supportsUndoRedo: true
  50. };
  51. },
  52. getAction: function getAction(args, returnValue) {
  53. // TODO: ideally should not need to do a copy here, it should be supported by APIFactory
  54. // https://github.ibm.com/BusinessAnalytics/dashboard-common/blob/master/src/core/APIFactory.js#L89
  55. // or
  56. // https://github.ibm.com/BusinessAnalytics/dashboard-common/blob/master/src/core/APIFactory.js#L108
  57. var options = JSON.parse(JSON.stringify(args[0]));
  58. if (options.spec) {
  59. options.spec = returnValue.getFeature('Serializer').toJSON();
  60. }
  61. options.modelIdsValid = true;
  62. return {
  63. name: 'addContent',
  64. params: [options]
  65. };
  66. },
  67. getUndoActions: function getUndoActions(args, content) {
  68. void args;
  69. return [{
  70. name: 'removeContent',
  71. params: content ? [content.getId()] : []
  72. }];
  73. }
  74. },
  75. removeContent: {
  76. eventName: 'child',
  77. type: 'remove',
  78. isResolvePostResponse: false,
  79. transactionParamIndex: 1,
  80. transactionAPI: this.transaction,
  81. autoCreateTransaction: true,
  82. getInfo: function getInfo(args) {
  83. return {
  84. value: args[0],
  85. supportsUndoRedo: true
  86. };
  87. },
  88. getUndoActions: function getUndoActions(args) {
  89. var dashboardAPI = _this.dashboardFeatures.getFeature('API');
  90. var content = dashboardAPI.getCanvas().getContent(args[0]);
  91. if (content) {
  92. var param = {
  93. containerId: content.getContainer().getId(),
  94. spec: content.getFeature('Serializer').toJSON(),
  95. modelIdsValid: true
  96. };
  97. var position = _this.getContentPosition(args[0]);
  98. if (position !== -1) {
  99. param.position = position;
  100. }
  101. return [{
  102. name: 'addContent',
  103. params: [param]
  104. }];
  105. } else {
  106. return [];
  107. }
  108. }
  109. },
  110. setPropertyValue: {
  111. eventName: 'property',
  112. getEventName: function getEventName(args) {
  113. return 'property:' + args[0];
  114. },
  115. getInfo: function getInfo(args) {
  116. var info = {
  117. name: args[0],
  118. value: args[1],
  119. supportsUndoRedo: true
  120. };
  121. if (args[2]) {
  122. info.options = JSON.parse(JSON.stringify(args[2]));
  123. }
  124. var property = _this.getPropertyList().find(function (property) {
  125. return property.id === args[0];
  126. });
  127. if (property) {
  128. if (property.onPropertyChange && property.onPropertyChange.refresh) {
  129. info.refresh = property.onPropertyChange.refresh;
  130. } else {
  131. info.refresh = {};
  132. }
  133. }
  134. return info;
  135. },
  136. getUndoActions: function getUndoActions(args) {
  137. return [{ params: [args[0], _this.getPropertyValue(args[0])] }];
  138. }
  139. }
  140. }
  141. }
  142. };
  143. }
  144. return this.apiSpec;
  145. };
  146. return Events;
  147. }();
  148. return Events;
  149. });
  150. //# sourceMappingURL=ContentAPISpec.js.map