ServiceabilityDataSource.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. define(['./nls/StringResources'], function (ServiceabilityStringResources) {
  9. var ServiceabilityDataSource = function () {
  10. function ServiceabilityDataSource(visualizationAPI) {
  11. _classCallCheck(this, ServiceabilityDataSource);
  12. this._visualizationAPI = visualizationAPI;
  13. this._dataSource = this._visualizationAPI.getDataSource();
  14. this._initializeInfo();
  15. }
  16. /**
  17. * @returns {object} The result of this result should be an object which will
  18. * be stringfied later.
  19. * @description this method will fetch the data source info of a live widget
  20. * through the APIs.
  21. */
  22. ServiceabilityDataSource.prototype.toJSON = function toJSON() {
  23. this._dataSource = this._visualizationAPI.getDataSource();
  24. this._updateInfo();
  25. return this._json;
  26. };
  27. /**
  28. * @description this method will fetch the data mapping info and construct a UI spec which defined
  29. * how the Data Mapping section will be displayed
  30. * @returns {object} The UI spec which will be consumed by ContentInfoAPI
  31. */
  32. ServiceabilityDataSource.prototype.toUIJSON = function toUIJSON() {
  33. var json = this.toJSON();
  34. return [{
  35. fieldName: ServiceabilityStringResources.get('dataSourceName'),
  36. fieldValue: json.dataSourceInfo.name
  37. }, {
  38. fieldName: ServiceabilityStringResources.get('dataSourceId'),
  39. fieldValue: json.dataSourceInfo.id
  40. }, {
  41. fieldName: ServiceabilityStringResources.get('dataSourcePath'),
  42. fieldValue: json.dataSourceInfo.path
  43. }, {
  44. fieldName: ServiceabilityStringResources.get('dataSourceType'),
  45. fieldValue: json.dataSourceInfo.type
  46. }];
  47. };
  48. ServiceabilityDataSource.prototype._initializeInfo = function _initializeInfo() {
  49. this._resetInfo();
  50. this._updateInfo();
  51. };
  52. ServiceabilityDataSource.prototype._resetInfo = function _resetInfo() {
  53. this._json = {
  54. dataSourceInfo: {
  55. name: ServiceabilityStringResources.get('infoNotAvailable'),
  56. id: ServiceabilityStringResources.get('infoNotAvailable'),
  57. path: ServiceabilityStringResources.get('infoNotAvailable'),
  58. type: ServiceabilityStringResources.get('infoNotAvailable')
  59. }
  60. };
  61. };
  62. ServiceabilityDataSource.prototype._updateInfo = function _updateInfo() {
  63. if (this._dataSource) {
  64. if (this._dataSource.getAssetId() !== this._json.dataSourceInfo.id) {
  65. this._fetchAttributes();
  66. }
  67. } else {
  68. this._resetInfo();
  69. }
  70. };
  71. /**
  72. * Fetch async values that we want to show in the serviceability panel
  73. * Note: These will be populated when available. If not available and user opens
  74. * the serviceability panel, they will see blank value
  75. */
  76. ServiceabilityDataSource.prototype._fetchAttributes = function _fetchAttributes() {
  77. var _this = this;
  78. this._json.dataSourceInfo.id = this._dataSource.getAssetId();
  79. this._json.dataSourceInfo.type = this._dataSource.getType();
  80. this._dataSource.getLocalizedName().then(function (name) {
  81. _this._json.dataSourceInfo.name = name;
  82. });
  83. this._dataSource.getSearchPath().then(function (path) {
  84. _this._json.dataSourceInfo.path = path;
  85. });
  86. };
  87. return ServiceabilityDataSource;
  88. }();
  89. return ServiceabilityDataSource;
  90. });
  91. //# sourceMappingURL=ServiceabilityDataSource.js.map