QueryDefinition.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. 2019, 2020
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. define(['underscore', '../../../lib/@waca/dashboard-common/dist/core/APIFactory', './api/QueryDefinitionAPI', './QueryDataItemSet'], function (_, APIFactory, QueryDefinitionAPI, QueryDataItemSet) {
  9. var reducer = function reducer(accumulator, currentValue) {
  10. accumulator[currentValue.columnId] = currentValue;
  11. return accumulator;
  12. };
  13. var QueryDefinition = function () {
  14. function QueryDefinition(_ref) {
  15. var id = _ref.id,
  16. type = _ref.type;
  17. _classCallCheck(this, QueryDefinition);
  18. this.id = id;
  19. this.type = type;
  20. this.dataSource = null;
  21. this.dataItemSets = [];
  22. this.filters = [];
  23. this.summariesEnabled = true; //Summaries are enabled by default.
  24. this.queryHints = [];
  25. this.expandEnabled = true;
  26. this.suppressionEnabled = true; //suppression is enabled by default.
  27. this.supportsNonContextualTopBottom = true; //Non contextual top bottom is supported by default.
  28. this.properties = {};
  29. }
  30. QueryDefinition.prototype.getId = function getId() {
  31. return this.id;
  32. };
  33. QueryDefinition.prototype.getType = function getType() {
  34. return this.type;
  35. };
  36. QueryDefinition.prototype.getAPI = function getAPI() {
  37. if (!this.api) {
  38. this.api = APIFactory.createAPI(this, [QueryDefinitionAPI]);
  39. }
  40. return this.api;
  41. };
  42. QueryDefinition.prototype.setDataSource = function setDataSource(source) {
  43. this.dataSource = source;
  44. };
  45. QueryDefinition.prototype.getDataSource = function getDataSource() {
  46. return this.dataSource;
  47. };
  48. QueryDefinition.prototype.setSummariesEnabled = function setSummariesEnabled(flag) {
  49. this.summariesEnabled = flag;
  50. };
  51. QueryDefinition.prototype.getSummariesEnabled = function getSummariesEnabled() {
  52. return this.summariesEnabled;
  53. };
  54. QueryDefinition.prototype.setSuppressionEnabled = function setSuppressionEnabled(flag) {
  55. this.suppressionEnabled = flag;
  56. };
  57. QueryDefinition.prototype.getSuppressionEnabled = function getSuppressionEnabled() {
  58. return this.suppressionEnabled;
  59. };
  60. QueryDefinition.prototype.createDataItemSet = function createDataItemSet(dataItems) {
  61. var dataItemSet = new QueryDataItemSet();
  62. dataItemSet.addDataItemList(dataItems);
  63. this.dataItemSets.push(dataItemSet);
  64. return dataItemSet.getAPI();
  65. };
  66. QueryDefinition.prototype.getDataItemSetList = function getDataItemSetList() {
  67. return this.dataItemSets.slice();
  68. };
  69. QueryDefinition.prototype.getAllDataItemsList = function getAllDataItemsList() {
  70. return _.flatten(this.dataItemSets.map(function (dataItemSet) {
  71. return dataItemSet.getAllDataItemsList();
  72. }));
  73. };
  74. QueryDefinition.prototype.addFilters = function addFilters(filters) {
  75. var _filters;
  76. (_filters = this.filters).push.apply(_filters, filters);
  77. };
  78. QueryDefinition.prototype.removeFilters = function removeFilters() {
  79. var _this = this;
  80. var filtersToRemove = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  81. if (filtersToRemove.length > 0) {
  82. var removeFiltersMap = filtersToRemove.reduce(reducer, {});
  83. var currentFilters = this.filters.reduce(reducer, {});
  84. var currentKeys = Object.keys(currentFilters);
  85. this.filters.length = 0;
  86. currentKeys.forEach(function (key) {
  87. if (!removeFiltersMap[key]) {
  88. _this.filters.push(currentFilters[key]);
  89. }
  90. });
  91. }
  92. };
  93. QueryDefinition.prototype.getFilters = function getFilters() {
  94. return this.filters;
  95. };
  96. QueryDefinition.prototype.addQueryHint = function addQueryHint(queryHint) {
  97. this.queryHints.push(queryHint);
  98. };
  99. QueryDefinition.prototype.getQueryHints = function getQueryHints() {
  100. return this.queryHints;
  101. };
  102. QueryDefinition.prototype.setExpandEnabled = function setExpandEnabled(flag) {
  103. this.expandEnabled = flag;
  104. };
  105. QueryDefinition.prototype.getExpandEnabled = function getExpandEnabled() {
  106. return this.expandEnabled;
  107. };
  108. QueryDefinition.prototype.setSupportsNonContextualTopBottom = function setSupportsNonContextualTopBottom(flag) {
  109. this.supportsNonContextualTopBottom = flag;
  110. };
  111. QueryDefinition.prototype.getSupportsNonContextualTopBottom = function getSupportsNonContextualTopBottom() {
  112. return this.supportsNonContextualTopBottom;
  113. };
  114. QueryDefinition.prototype.getPropertyValue = function getPropertyValue(name) {
  115. return this.properties[name];
  116. };
  117. QueryDefinition.prototype.setPropertyValue = function setPropertyValue(name, value) {
  118. if (name) {
  119. if (value === undefined) {
  120. delete this.properties[name];
  121. } else {
  122. this.properties[name] = value;
  123. }
  124. }
  125. };
  126. return QueryDefinition;
  127. }();
  128. return QueryDefinition;
  129. });
  130. //# sourceMappingURL=QueryDefinition.js.map