QueryResultData.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. 'use strict';
  2. /*
  3. *+------------------------------------------------------------------------+
  4. *| Licensed Materials - Property of IBM
  5. *| IBM Cognos Products: BI Dashboard
  6. *| (C) Copyright IBM Corp. 2016, 2017
  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 the raw query result data rows,its related information and
  14. * functions
  15. **/
  16. define(['../../lib/@waca/core-client/js/core-client/ui/core/Class', 'underscore', '../../lib/@waca/dashboard-common/dist/query/FacetDataObject'], function (BaseClass, _, FacetClass) {
  17. var QueryResultData = BaseClass.extend({
  18. _dataRows: [],
  19. init: function init(data) {
  20. QueryResultData.inherited('init', this, arguments);
  21. this._dataRows = data;
  22. },
  23. /**
  24. * @return a JSON object that has attributes of 'display' and 'use'
  25. * for the given raw array element's index
  26. **/
  27. getDataItemByIndex: function getDataItemByIndex(nRow, nCol) {
  28. return QueryResultData.toDataItem(this._dataRows[!nRow ? 0 : nRow][!nCol ? 0 : nCol]);
  29. },
  30. /**
  31. * @return an array of JSON objects that has attributes of 'display' and 'use'
  32. * for the given a row index
  33. **/
  34. getDataItemsByRowIndex: function getDataItemsByRowIndex(nRow) {
  35. var dataItems = [];
  36. _.each(this._dataRows[!nRow ? 0 : nRow], function (data) {
  37. dataItems.push(QueryResultData.toDataItem(data));
  38. }.bind(this));
  39. return dataItems;
  40. },
  41. getRowsSize: function getRowsSize() {
  42. return this._dataRows ? this._dataRows.length : 0;
  43. },
  44. getColsSizeByRowIndex: function getColsSizeByRowIndex(index) {
  45. var aRow = this._dataRows[index];
  46. return aRow ? aRow.length : 0;
  47. },
  48. //TODO: Keep this function for RAVE2 for now
  49. getDataRows: function getDataRows() {
  50. return this._dataRows;
  51. }
  52. });
  53. /**
  54. *@return a JSON object that has attributes of 'display' and 'use'
  55. * for a given raw array's row object and its column's index
  56. */
  57. QueryResultData.getDataItemByColumnIndex = function (oRow, nCol) {
  58. if (oRow && nCol >= 0) {
  59. return QueryResultData.toDataItem(oRow[nCol]);
  60. }
  61. return null;
  62. };
  63. /**
  64. * Generally a 'use' value is used to populate a data query while a 'display'
  65. * value is used to render UI
  66. *
  67. * @param {Object} data, raw data that could be a String, Number or Object
  68. * @return a JSON object that has both 'display' and 'use' attribute
  69. **/
  70. QueryResultData.toDataItem = function (data) {
  71. return new FacetClass(data);
  72. };
  73. /**
  74. * Create a raw data object with the given use and display value
  75. *
  76. * @param u use value
  77. * @param d display value
  78. * @return raw data object
  79. */
  80. QueryResultData.createDataObject = function (u, d) {
  81. var dataObj = {};
  82. if (u) {
  83. dataObj.u = u;
  84. }
  85. if (d) {
  86. dataObj.d = d;
  87. }
  88. return dataObj;
  89. };
  90. return QueryResultData;
  91. });
  92. //# sourceMappingURL=QueryResultData.js.map