ServiceabilityDataMapping.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. 2018, 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 ServiceabilityDataMapping = function () {
  10. function ServiceabilityDataMapping(visualizationAPI) {
  11. _classCallCheck(this, ServiceabilityDataMapping);
  12. this._visualizationAPI = visualizationAPI;
  13. }
  14. /**
  15. * @returns {object} The result of this result should be an object which will
  16. * be stringfied later.
  17. * @description this method will fetch the data mapping info of a live widget
  18. * through the APIs.
  19. */
  20. ServiceabilityDataMapping.prototype.toJSON = function toJSON() {
  21. var slotAPIs = this._visualizationAPI.getSlots().getSlotList();
  22. var jsonResult = slotAPIs.map(function (slotAPI) {
  23. var _ref;
  24. var slotDefinitionAPI = slotAPI.getDefinition();
  25. var dataItemAPIs = slotAPI.getDataItemList();
  26. return _ref = {}, _ref[slotDefinitionAPI.getId()] = {
  27. 'caption': slotDefinitionAPI.getCaption(),
  28. 'mandatory': !(slotDefinitionAPI.isOptional() === true),
  29. 'mapping': dataItemAPIs.map(function (dataItemAPI) {
  30. return dataItemAPI.getColumnId();
  31. })
  32. }, _ref;
  33. });
  34. return jsonResult;
  35. };
  36. /**
  37. * @description this method will fetch the data mapping info and construct a UI spec which defined
  38. * how the Data Mapping section will be displayed
  39. * @returns {object} The UI spec which will be consumed by ContentInfoAPI
  40. */
  41. ServiceabilityDataMapping.prototype.toUIJSON = function toUIJSON() {
  42. var headerData = {
  43. 0: ServiceabilityStringResources.get('slotDataMapping'),
  44. 1: ServiceabilityStringResources.get('slotID'),
  45. 2: ServiceabilityStringResources.get('slotCaption'),
  46. 3: ServiceabilityStringResources.get('slotMandatory')
  47. };
  48. var info = this.toJSON();
  49. var cellData = info.map(function (mappingSpec) {
  50. var id = Object.keys(mappingSpec)[0];
  51. return [mappingSpec[id].mapping.join(', '), id, mappingSpec[id].caption, mappingSpec[id].mandatory ? ServiceabilityStringResources.get('slotIsMandatory') : ServiceabilityStringResources.get('slotIsNotMandatory')];
  52. });
  53. return [{
  54. fieldName: ServiceabilityStringResources.get('slotMappingField'),
  55. fieldValue: {
  56. headerValue: function headerValue(col) {
  57. return headerData[col];
  58. },
  59. cellValue: function cellValue(row, col) {
  60. return cellData[row][col];
  61. },
  62. columnLength: 4,
  63. rowLength: info.length
  64. },
  65. type: 'SimpleTable'
  66. }];
  67. };
  68. return ServiceabilityDataMapping;
  69. }();
  70. return ServiceabilityDataMapping;
  71. });
  72. //# sourceMappingURL=ServiceabilityDataMapping.js.map