LiveWidgetSegment.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. 'use strict';
  2. var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  3. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4. /**
  5. * Licensed Materials - Property of IBM
  6. * IBM Business Analytics (C) Copyright IBM Corp. 2020
  7. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  8. */
  9. /**
  10. * @class LiveWidgetSegmentImpl
  11. * @hideconstructor
  12. * @classdesc
  13. */
  14. define(['../../../lib/@waca/dashboard-common/dist/core/APIFactory', './api/LiveWidgetSegmentAPI'], function (APIFactory, LiveWidgetSegmentAPI) {
  15. var LiveWidgetSegment = function () {
  16. function LiveWidgetSegment(options) {
  17. _classCallCheck(this, LiveWidgetSegment);
  18. this.dashboard = options.features['API'];
  19. this.visDefinitions = options.features['VisDefinitions'];
  20. this.logger = options.features['Logger'];
  21. this._api = APIFactory.createAPI(this, [LiveWidgetSegmentAPI]);
  22. }
  23. LiveWidgetSegment.prototype.getAPI = function getAPI() {
  24. if (!this.api) {
  25. this.api = APIFactory.createAPI(this, [LiveWidgetSegmentAPI]);
  26. }
  27. return this.api;
  28. };
  29. LiveWidgetSegment.prototype.track = function track() {
  30. var event = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  31. var supportedTrackActions = ['fromRecommendation', 'Recommended', 'Other', 'colorPalette'];
  32. if (supportedTrackActions.indexOf(event.category) === -1) {
  33. return;
  34. }
  35. var segment = this.dashboard.getFeature('segment');
  36. if (!segment) {
  37. this.logger.error('Invalid segment object');
  38. return;
  39. }
  40. var widgetType = event.visualization ? event.visualization.getDefinition().getLabel() : null;
  41. var payload = void 0,
  42. action = void 0;
  43. if (!widgetType && event.category === 'fromRecommendation') {
  44. // Dragged a slot to the canvas
  45. widgetType = event.recommendation;
  46. action = 'created';
  47. payload = {
  48. type: 'Created Object',
  49. widgetSource: 'fromRecommendation',
  50. details: {
  51. widgetSource: 'fromRecommendation',
  52. 'widgetType': event.recommendation
  53. }
  54. };
  55. } else if (event.category === 'fromRecommendation' || event.category === 'Recommended' || event.category === 'Other') {
  56. // Modified the type
  57. action = 'modified';
  58. // The visChangerFlyoutView passes the type or the id depending the type or id for JQGrid or Crosstabs
  59. var visDef = this.visDefinitions.getByType(event.info.visId) || this.visDefinitions.getById(event.info.visId) || null;
  60. var newWidgetType = visDef && visDef.getLabel();
  61. payload = {
  62. type: 'Updated Object',
  63. details: {
  64. 'propertyId': event.category,
  65. 'property.newValue': newWidgetType,
  66. 'property.oldValue': widgetType
  67. }
  68. };
  69. } else if (event.category === 'colorPalette') {
  70. // Modified the colorPalette property
  71. action = 'modified';
  72. payload = {
  73. type: 'Updated Object',
  74. details: {
  75. 'propertyId': event.category,
  76. 'property.newValue': event.info.newValue,
  77. 'property.oldValue': event.info.previousValue
  78. }
  79. };
  80. }
  81. if (payload) {
  82. var result = _extends({}, payload, {
  83. details: _extends({}, payload.details, {
  84. 'widgetType': widgetType,
  85. 'assetType': this.dashboard.getApplicationName()
  86. }),
  87. trackType: 'data_widget',
  88. 'custom.widgetType': widgetType
  89. });
  90. if (event.content) {
  91. result.object = event.content.getId();
  92. }
  93. var assetId = this.dashboard.getDashboardInfo().boardId;
  94. if (assetId) {
  95. result.details.assetId = assetId;
  96. }
  97. segment.track(action, function () {
  98. return result;
  99. });
  100. }
  101. };
  102. return LiveWidgetSegment;
  103. }();
  104. return LiveWidgetSegment;
  105. });
  106. //# sourceMappingURL=LiveWidgetSegment.js.map