DataQueryResultItem.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. 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; }
  4. 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; }
  5. /**
  6. * Licensed Materials - Property of IBM
  7. * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2019
  8. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  9. */
  10. define(['../../dashboard/queryService/ResultItem', '../../dashboard/queryService/QueryResultColumn', '../../../widgets/livewidget/nls/StringResources', 'underscore', '../../../apiHelpers/SlotAPIHelper'], function (ResultItem, QueryResultColumn, StringResources, _, SlotAPIHelper) {
  11. var DataQueryResultItem = function (_ResultItem) {
  12. _inherits(DataQueryResultItem, _ResultItem);
  13. function DataQueryResultItem(dataItemObject, slots) {
  14. _classCallCheck(this, DataQueryResultItem);
  15. var _this = _possibleConstructorReturn(this, _ResultItem.call(this, dataItemObject));
  16. _this._slots = slots;
  17. _this.getRowCount = _this.getTupleCount.bind(_this);
  18. return _this;
  19. }
  20. DataQueryResultItem.prototype.getDataItemList = function getDataItemList() {
  21. if (!this._dataItemList) {
  22. this._dataItemList = [];
  23. var id = this.getTupleHeaderId();
  24. var dataItemInfo = this._slots.getMappingInfo(id);
  25. if (!dataItemInfo) {
  26. var _dataItemList;
  27. // Could be a slot with nested data items in result item, otherwise skip
  28. var slot = this._slots.getSlot(id);
  29. var dataItemList = slot && slot.getDataItemList();
  30. if (dataItemList && this.isMultiMeasureValue(dataItemList)) {
  31. // TODO Temporary solution for multiMeasureValue data item.
  32. dataItemList = [new QueryResultColumn({
  33. u: SlotAPIHelper.MULTI_MEASURES_VALUE,
  34. d: StringResources.get('ValuesCaption')
  35. }).getAPI()];
  36. }
  37. if (!dataItemList) {
  38. // Handle data item generated internally, such as contextual grid to get data with columns referenced by tab filters
  39. var columnHeaders = this.getTupleHeaders()[0];
  40. dataItemList = columnHeaders && _.map(columnHeaders, function (columnHeader) {
  41. return new QueryResultColumn(columnHeader).getAPI();
  42. });
  43. }
  44. (_dataItemList = this._dataItemList).push.apply(_dataItemList, dataItemList);
  45. } else {
  46. this._dataItemList.push(dataItemInfo.dataItem);
  47. }
  48. }
  49. return this._dataItemList;
  50. };
  51. DataQueryResultItem.prototype.isMultiMeasureValue = function isMultiMeasureValue(dataItemList) {
  52. if (dataItemList.length < 2) {
  53. return false;
  54. }
  55. var list = _.filter(dataItemList, function (dataItem) {
  56. return dataItem.getType() === 'fact';
  57. });
  58. return list.length > 1;
  59. };
  60. return DataQueryResultItem;
  61. }(ResultItem);
  62. return DataQueryResultItem;
  63. });
  64. //# sourceMappingURL=DataQueryResultItem.js.map