QueryDataItem.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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, 2020
  8. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  9. */
  10. define(['underscore', '../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../../../api/DataItemAPI', './api/QueryDataItemAPI'], function (_, APIFactory, DataItemAPI, QueryDataItemAPI) {
  11. var QueryDataItem = function (_QueryDataItemAPI) {
  12. _inherits(QueryDataItem, _QueryDataItemAPI);
  13. function QueryDataItem(metadataColumn, dataItemId, dataItem) {
  14. _classCallCheck(this, QueryDataItem);
  15. var _this = _possibleConstructorReturn(this, _QueryDataItemAPI.call(this, metadataColumn, dataItem));
  16. if (!metadataColumn) {
  17. throw new Error('Missing parameter: MetadataColumnAPI');
  18. }
  19. _this.metadataColumn = metadataColumn;
  20. _this.dataItemId = dataItemId;
  21. // declare the defaults
  22. _this.projected = true;
  23. _this.commandList = [];
  24. // apply the spec to the data item instance
  25. if (dataItem) {
  26. _.extend(_this, dataItem);
  27. }
  28. return _this;
  29. }
  30. QueryDataItem.prototype.getAPI = function getAPI() {
  31. if (!this.api) {
  32. this.api = APIFactory.createAPI(this, [DataItemAPI, QueryDataItemAPI]);
  33. }
  34. return this.api;
  35. };
  36. ///////////////////////////////////
  37. // QueryDataItemAPI implementation
  38. QueryDataItem.prototype.getProjected = function getProjected() {
  39. return this.projected;
  40. };
  41. QueryDataItem.prototype.setProjected = function setProjected(projected) {
  42. this.projected = projected;
  43. };
  44. QueryDataItem.prototype.getCommandList = function getCommandList() {
  45. return this.commandList;
  46. };
  47. QueryDataItem.prototype.addCommand = function addCommand(command) {
  48. this.commandList.push(command);
  49. };
  50. QueryDataItem.prototype.setType = function setType(type) {
  51. this.type = type;
  52. };
  53. ///////////////////////////////////
  54. // DataItemAPI implementation
  55. QueryDataItem.prototype.getId = function getId() {
  56. return this.dataItemId;
  57. };
  58. QueryDataItem.prototype.getLabel = function getLabel() {
  59. return this.metadataColumn.getLabel();
  60. };
  61. QueryDataItem.prototype.getColumnId = function getColumnId() {
  62. return this.metadataColumn.getId();
  63. };
  64. QueryDataItem.prototype.getDataType = function getDataType() {
  65. return this.metadataColumn.getDataType();
  66. };
  67. QueryDataItem.prototype.isDateOrTimeType = function isDateOrTimeType() {
  68. return this.metadataColumn.isDateTimeDataType();
  69. };
  70. QueryDataItem.prototype.getType = function getType() {
  71. return this.type || this.metadataColumn.getType();
  72. };
  73. QueryDataItem.prototype.getAggregation = function getAggregation() {
  74. return typeof this.aggregation !== 'undefined' ? this.aggregation : this._getDefaultAggregation();
  75. };
  76. QueryDataItem.prototype.setAggregation = function setAggregation() {
  77. var aggregation = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
  78. this.aggregation = aggregation;
  79. };
  80. QueryDataItem.prototype.getSort = function getSort() {
  81. if (this.sort) {
  82. return this.sort;
  83. }
  84. var metadataColumnSortType = this.metadataColumn.getDefaultSortType();
  85. if (metadataColumnSortType) {
  86. return {
  87. type: metadataColumnSortType,
  88. priority: 1
  89. };
  90. }
  91. };
  92. QueryDataItem.prototype.getTopBottom = function getTopBottom() {
  93. return this.topBottom;
  94. };
  95. QueryDataItem.prototype.getMetadataColumn = function getMetadataColumn() {
  96. return this.metadataColumn;
  97. };
  98. QueryDataItem.prototype.getFormat = function getFormat(options) {
  99. return this.format || this.metadataColumn.getFormat(options);
  100. };
  101. QueryDataItem.prototype.getBinning = function getBinning() {
  102. return this.binning;
  103. };
  104. QueryDataItem.prototype.getDrillUpValue = function getDrillUpValue() {
  105. return this.drillUpValue;
  106. };
  107. QueryDataItem.prototype.getDrillDownValue = function getDrillDownValue() {
  108. return this.drillDownValue;
  109. };
  110. QueryDataItem.prototype.hasDefaultAggregation = function hasDefaultAggregation() {
  111. return typeof this.aggregation === 'undefined';
  112. };
  113. QueryDataItem.prototype.hasDefaultSort = function hasDefaultSort() {
  114. return !this.sort;
  115. };
  116. QueryDataItem.prototype.hasDefaultFormat = function hasDefaultFormat() {
  117. return !this.format;
  118. };
  119. QueryDataItem.prototype.setSort = function setSort(sortSpec) {
  120. this.sort = sortSpec;
  121. };
  122. QueryDataItem.prototype.setFormat = function setFormat(formatSpec) {
  123. this.format = formatSpec;
  124. };
  125. QueryDataItem.prototype.setTopBottom = function setTopBottom(topBottomInfo) {
  126. this.topBottom = topBottomInfo;
  127. };
  128. QueryDataItem.prototype.setBinning = function setBinning(binningSpec) {
  129. this.binning = binningSpec;
  130. };
  131. QueryDataItem.prototype.canDrillDown = function canDrillDown() {
  132. return false;
  133. };
  134. QueryDataItem.prototype.drillUp = function drillUp(value) {
  135. this.drillUpValue = value;
  136. };
  137. QueryDataItem.prototype.drillDown = function drillDown(value) {
  138. this.drillDownValue = value;
  139. };
  140. QueryDataItem.prototype.clearDrill = function clearDrill() {
  141. delete this.drillUpValue;
  142. delete this.drillDownValue;
  143. };
  144. //////////////////////////////
  145. //QueryDataItem private function(s)
  146. QueryDataItem.prototype._getDefaultAggregation = function _getDefaultAggregation() {
  147. return this.metadataColumn.getDefaultAggregation();
  148. };
  149. return QueryDataItem;
  150. }(QueryDataItemAPI);
  151. return QueryDataItem;
  152. });
  153. //# sourceMappingURL=QueryDataItem.js.map