SlotsAPISpec.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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, 2021
  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 APISpec = function () {
  17. function APISpec() {
  18. _classCallCheck(this, APISpec);
  19. }
  20. APISpec.prototype.getAPISpec = function getAPISpec() {
  21. var _this = this;
  22. if (!this.apiSpec) {
  23. this.apiSpec = {
  24. name: 'slots API',
  25. features: {
  26. 'Dashboard.Transaction': this.transaction
  27. },
  28. events: {
  29. propagationInfo: {
  30. namespace: 'slots',
  31. callStack: {
  32. name: 'getSlots'
  33. },
  34. info: {
  35. supportsUndoRedo: true,
  36. refresh: {
  37. predictSuggestions: true,
  38. keyDrivers: true,
  39. dataIfQueryChanged: true
  40. }
  41. }
  42. },
  43. actions: {
  44. 'createDataItems': {
  45. eventName: 'dataitems:create',
  46. isResolvePostResponse: true,
  47. getInfo: function getInfo(args) {
  48. return {
  49. dataItemList: args[0]
  50. };
  51. },
  52. getAction: function getAction(args, returnValue) {
  53. // Include the id of the created dataItem in the action params.. so that we can recreate with the same id
  54. var dataItems = [];
  55. args[0].forEach(function (dataItem, index) {
  56. dataItems.push({
  57. columnId: dataItem.columnId,
  58. id: returnValue[index].getId()
  59. });
  60. });
  61. return {
  62. params: [dataItems]
  63. };
  64. },
  65. getUndoActions: function getUndoActions(args, result) {
  66. var undoActions = [];
  67. var dataItemIds = result.map(function (dataItem) {
  68. return dataItem.getId();
  69. });
  70. undoActions.push({
  71. name: 'deleteDataItems',
  72. params: [dataItemIds]
  73. });
  74. return undoActions;
  75. }
  76. },
  77. 'deleteDataItems': {
  78. eventName: 'dataitems:delete',
  79. getInfo: function getInfo(args, result) {
  80. return {
  81. dataItemList: result
  82. };
  83. },
  84. getUndoActions: function getUndoActions(args) {
  85. var undoActions = [];
  86. var resultActions = [];
  87. var ids = args[0];
  88. var undoParam = [];
  89. ids.forEach(function (id) {
  90. var dataItem = _this.getDataItemImpl(id);
  91. if (dataItem) {
  92. undoParam.push({
  93. id: id,
  94. columnId: dataItem.getColumnId(),
  95. itemLabel: dataItem.getLabel(),
  96. navigationPathId: dataItem.getNavigationPathId()
  97. });
  98. resultActions.push(dataItem ? dataItem.serializeActions() : []);
  99. } else {
  100. //If the dataItem doesn't exist, the id should be eliminated - its a no-op.
  101. ids = ids.filter(function (thisId) {
  102. return thisId !== id;
  103. });
  104. }
  105. });
  106. if (undoParam.length) {
  107. var currentDataItems = _this.getDataItemList();
  108. var dataSource = _this.getDataSource();
  109. if (ids.length === currentDataItems.length && dataSource) {
  110. undoActions.push({
  111. callStack: [{
  112. name: '..'
  113. }],
  114. name: 'setDataSource',
  115. params: [dataSource.getId()]
  116. });
  117. }
  118. undoActions.push({
  119. callStack: [{
  120. name: 'getSlots'
  121. }],
  122. name: 'createDataItems',
  123. params: [undoParam],
  124. resultActions: resultActions
  125. });
  126. }
  127. return undoActions;
  128. }
  129. }
  130. }
  131. }
  132. };
  133. }
  134. return this.apiSpec;
  135. };
  136. return APISpec;
  137. }();
  138. return APISpec;
  139. });
  140. //# sourceMappingURL=SlotsAPISpec.js.map