QueryResultObject.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. 'use strict';
  2. /*
  3. *+------------------------------------------------------------------------+
  4. *| Licensed Materials - Property of IBM
  5. *| IBM Cognos Products: BI Dashboard
  6. *| (C) Copyright IBM Corp. 2017, 2019
  7. *|
  8. *| US Government Users Restricted Rights - Use, duplication or disclosure
  9. *| restricted by GSA ADP Schedule Contract with IBM Corp.
  10. *+------------------------------------------------------------------------+
  11. */
  12. /**
  13. * This Class encapsulates raw query result data returned from DSS and provides its accessors and iterators
  14. **/
  15. define(['../../../lib/@waca/core-client/js/core-client/ui/core/Class', '../../../lib/@waca/dashboard-common/dist/query/FacetDataObject', 'underscore'], function (BaseClass, FacetData, _) {
  16. 'use strict';
  17. var SingleQueryResult = BaseClass.extend({
  18. _facetData: null, /*QueryResultData Object*/
  19. _queryThreshHold: 3000,
  20. _attachedPayload: null,
  21. _dataViewId: null,
  22. init: function init(dataViewId, queryResultData, queryThreshold, attachedPayload, queryResultAPI) {
  23. this._queryThreshHold = queryThreshold;
  24. this._facetData = queryResultData;
  25. this._attachedPayload = attachedPayload;
  26. this._dataViewId = dataViewId;
  27. this.data = queryResultData; //TODO: Remove this in Endor
  28. this._queryResultAPI = queryResultAPI;
  29. },
  30. getFacetData: function getFacetData() {
  31. return this._facetData;
  32. },
  33. getQueryThreshhold: function getQueryThreshhold() {
  34. return this._queryThreshHold;
  35. },
  36. getTopBottomMappings: function getTopBottomMappings() {
  37. return this._attachedPayload ? this._attachedPayload.topBottomMappings : {};
  38. },
  39. setTopBottomMappings: function setTopBottomMappings(topBottomMappings) {
  40. this._attachedPayload = this._attachedPayload || {};
  41. this._attachedPayload.topBottomMappings = topBottomMappings;
  42. },
  43. getAttachedPayload: function getAttachedPayload() {
  44. return this._attachedPayload;
  45. },
  46. getHasMoreData: function getHasMoreData() {
  47. return this._facetDdata ? this._faectData.hasMoreData() : false;
  48. },
  49. getDataViewId: function getDataViewId() {
  50. return this._dataViewId;
  51. },
  52. // TODO temporarily provide an API to get the new QueryResultAPI
  53. getQueryResult: function getQueryResult() {
  54. return this._queryResultAPI;
  55. }
  56. });
  57. var QueryResultObject = BaseClass.extend({
  58. _renderContext: null,
  59. hasMoreData: false,
  60. queryThreshold: Number.MAX_VALUE,
  61. init: function init(renderContext) {
  62. this._aQueryResults = [];
  63. this._renderContext = renderContext;
  64. },
  65. addQueryResultObject: function addQueryResultObject(dataViewId, queryResultData, queryThreshold, attachedPayload, queryResultAPI) {
  66. this._aQueryResults.push(new SingleQueryResult(dataViewId, queryResultData, queryThreshold, attachedPayload, queryResultAPI));
  67. // summarize the clipping information among multiple query results
  68. this.hasMoreData = this.hasMoreData || queryResultData.hasMoreData();
  69. this.queryThreshold = Math.min(this.queryThreshold, queryThreshold);
  70. },
  71. getQueryResultByDataViewId: function getQueryResultByDataViewId(dataViewId) {
  72. return _.find(this._aQueryResults, function (entry) {
  73. return entry.getDataViewId() === dataViewId;
  74. });
  75. },
  76. getQueryResultByIndex: function getQueryResultByIndex(index) {
  77. return this._aQueryResults[index];
  78. },
  79. getDefaultQueryResult: function getDefaultQueryResult() {
  80. return this._aQueryResults[0];
  81. },
  82. getQueryResults: function getQueryResults() {
  83. return this._aQueryResults;
  84. },
  85. getRenderContext: function getRenderContext() {
  86. return this._renderContext;
  87. },
  88. /**
  89. * set top bottom mapping from top bottom spec
  90. * @param {Object} topBottomSpec
  91. * @param {int} index - optional. default to 0 if not set
  92. * eg. { Quantityavg: {
  93. * max: xx,
  94. * min: xx
  95. * }, {
  96. * UnitCostsum: {
  97. * max: xx,
  98. * min: xx }
  99. * } }
  100. */
  101. setTopBottomMappings: function setTopBottomMappings(topBottomSpec, index) {
  102. var topBottomMapping = {};
  103. _.each(topBottomSpec, function (value, key) {
  104. var facetDataItemMax = new FacetData({ u: value.max });
  105. var facetDataItemMin = new FacetData({ u: value.min });
  106. topBottomMapping[key] = {
  107. bottomResult: facetDataItemMin,
  108. topResult: facetDataItemMax
  109. };
  110. });
  111. var queryResult = this.getQueryResultByIndex(index || 0);
  112. queryResult.setTopBottomMappings(topBottomMapping);
  113. }
  114. });
  115. return QueryResultObject;
  116. });
  117. //# sourceMappingURL=QueryResultObject.js.map