VisDnD.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 Business Analytics (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. * @class VisDnD
  10. * @hideconstructor
  11. *
  12. * @classdesc Handles drag and drop of metadata to create a visualization.
  13. */
  14. define(['./api/VisDnDAPI', '../../../lib/@waca/dashboard-common/dist/core/APIFactory', './VisDnDProviderSet'], function (DnDProviderAPI, APIFactory, VisDnDProviderSet) {
  15. return function () {
  16. function VisDnD(_ref) {
  17. var content = _ref.content,
  18. features = _ref.features;
  19. _classCallCheck(this, VisDnD);
  20. this.content = content;
  21. this.dashboardAPI = features['API'];
  22. this.dashboardDnD = features['Dashboard.DashboardDnd'];
  23. this.visualization = features['Visualization'];
  24. this.providerSets = {};
  25. }
  26. //to fix the problem that constructor won't be invoked when vidDnd feature is loaded
  27. VisDnD.prototype.initialize = function initialize() {};
  28. VisDnD.prototype.getAPI = function getAPI() {
  29. if (!this.api) {
  30. this.api = APIFactory.createAPI(this, [DnDProviderAPI]);
  31. }
  32. return this.api;
  33. };
  34. VisDnD.prototype.destroy = function destroy() {
  35. var _this = this;
  36. this.dashboardAPI = null;
  37. this.content = null;
  38. this.utils && this.utils.destroy();
  39. this.utilsApi = null;
  40. this.api = null;
  41. Object.keys(this.providerSets).forEach(function (providerKey) {
  42. _this.providerSets[providerKey].destroy();
  43. });
  44. this.providerSets = null;
  45. };
  46. VisDnD.prototype.registerProviders = function registerProviders(type) {
  47. var providers = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  48. var containedTargetsToIgnore = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
  49. if (type && providers && providers.length) {
  50. var providerSet = this.providerSets[type];
  51. if (providerSet) {
  52. providerSet.addProviders(providers);
  53. } else {
  54. this.providerSets[type] = new VisDnDProviderSet({
  55. dashboardAPI: this.dashboardAPI,
  56. dashboardDnD: this.dashboardDnD,
  57. content: this.content,
  58. targetType: type,
  59. dndProviderList: providers,
  60. containedTargetsToIgnore: containedTargetsToIgnore
  61. });
  62. }
  63. }
  64. };
  65. VisDnD.prototype.accepts = function accepts(source, target) {
  66. if (this.providerSets[target.type] && this.providerSets[target.type].accepts) {
  67. return this.providerSets[target.type].accepts(source, target);
  68. }
  69. return false;
  70. };
  71. VisDnD.prototype.onDrop = function onDrop(source, target) {
  72. if (this.providerSets[target.type] && this.providerSets[target.type].onDrop) {
  73. this.providerSets[target.type].onDrop(source, target);
  74. }
  75. };
  76. return VisDnD;
  77. }();
  78. });
  79. //# sourceMappingURL=VisDnD.js.map