QueryResultData.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. 'use strict';
  2. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  3. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  5. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  6. /**
  7. * Licensed Materials - Property of IBM
  8. * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2018, 2020
  9. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  10. */
  11. define(['@waca/dashboard-common/js/core/APIFactory', '@waca/dashboard-livewidget/js/features/dashboard/queryService/api/QueryResultAPI', './ResultItem', '@waca/dashboard-livewidget/js/widgets/livewidget/query/QueryResultData'], function (APIFactory, QueryResultAPI, ResultItem, QueryResultData) {
  12. var QueryResultDataImpl = function (_QueryResultData) {
  13. _inherits(QueryResultDataImpl, _QueryResultData);
  14. function QueryResultDataImpl(queryResultObj) {
  15. _classCallCheck(this, QueryResultDataImpl);
  16. var _this = _possibleConstructorReturn(this, _QueryResultData.call(this, queryResultObj));
  17. _this.getResultItemList = _this.getResultDataItems.bind(_this);
  18. _this.getDataPointValueList = _this.getDatapoints.bind(_this);
  19. _this.getRowCount = _this.getDatapointCount.bind(_this);
  20. _this.properties = {};
  21. return _this;
  22. }
  23. QueryResultDataImpl.prototype.getPropertyValue = function getPropertyValue(name) {
  24. return this.properties[name];
  25. };
  26. QueryResultDataImpl.prototype.setPropertyValue = function setPropertyValue(name, value) {
  27. if (typeof name !== 'string') {
  28. throw new Error('Name must be a string');
  29. }
  30. if (value !== null && typeof value !== 'string') {
  31. throw new Error('Value must be a string');
  32. }
  33. this.properties[name] = value;
  34. };
  35. QueryResultDataImpl.prototype.getAPI = function getAPI() {
  36. if (!this.queryResultAPI) {
  37. this.queryResultAPI = APIFactory.createAPI(this, [QueryResultAPI]);
  38. }
  39. return this.queryResultAPI;
  40. };
  41. QueryResultDataImpl.prototype._generateDataItemArray = function _generateDataItemArray() {
  42. var _this2 = this;
  43. this._aQueryResultDataItems = [];
  44. if (this._resultData && this._resultData.dataItems && this._resultData.dataItems.length > 0) {
  45. this._resultData.dataItems.forEach(function (dataItem) {
  46. if (_this2._isValidDataItem(dataItem)) {
  47. _this2._aQueryResultDataItems.push(new ResultItem(dataItem).getAPI());
  48. }
  49. });
  50. }
  51. };
  52. QueryResultDataImpl.prototype.getResultItem = function getResultItem(resultDataItemID) {
  53. return this.getResultItemList().find(function (resultDataItemAPI) {
  54. return resultDataItemID === resultDataItemAPI.getId();
  55. });
  56. };
  57. //TODO: delete value.v when when all consumers are ready to new qeury APIs
  58. QueryResultDataImpl.prototype.getValue = function getValue(rowIndex, resultDataItemIndex) {
  59. var value = undefined;
  60. var dataPointValueList = this.getDataPointValueList();
  61. var dataPoint = dataPointValueList && dataPointValueList[rowIndex];
  62. if (dataPoint) {
  63. value = dataPoint.pt[resultDataItemIndex];
  64. if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object' && (value.v !== undefined || value.value !== undefined)) {
  65. // result is a value of a measure column
  66. if (value.value === undefined) {
  67. value.value = value.v;
  68. }
  69. } else {
  70. // value is the row index of resultItemList
  71. var resultItemList = this.getResultItemList();
  72. value = resultItemList && resultItemList[resultDataItemIndex].getValue(value);
  73. }
  74. }
  75. return value;
  76. };
  77. QueryResultDataImpl.prototype.getValueIndex = function getValueIndex(rowIndex, resultDataItemIndex) {
  78. //Similar to getValue for categoricals except that it returns the index in the 'edge' where the tuple value is found.
  79. var value = undefined;
  80. var dataPointValueList = this.getDataPointValueList();
  81. var dataPoint = dataPointValueList && dataPointValueList[rowIndex];
  82. if (dataPoint) {
  83. value = dataPoint.pt[resultDataItemIndex];
  84. if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object') {
  85. throw new Error('getValueIndex is only supported for categorical items.');
  86. }
  87. }
  88. return value;
  89. };
  90. return QueryResultDataImpl;
  91. }(QueryResultData);
  92. return QueryResultDataImpl;
  93. });
  94. //# sourceMappingURL=QueryResultData.js.map