123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- 'use strict';
- /*
- *+------------------------------------------------------------------------+
- *| Licensed Materials - Property of IBM
- *| IBM Cognos Products: BI Dashboard
- *| (C) Copyright IBM Corp. 2017
- *|
- *| US Government Users Restricted Rights - Use, duplication or disclosure
- *| restricted by GSA ADP Schedule Contract with IBM Corp.
- *+------------------------------------------------------------------------+
- */
- define(['../../../lib/@waca/core-client/js/core-client/ui/core/Class', './QueryResultDataUtils', 'underscore'], function (BaseClass, Utils, _) {
- 'use strict';
- /**
- * QueryResultDataItem Class that stores information about one Query Result Data Item
- **/
- var DataItemClass = BaseClass.extend({
- /**
- * @private internal query data item
- */
- _dataItem: null,
- /**
- * @private internal flag to indicate if the tuple header has been normalized
- */
- _bTupleHeaderNormalized: false,
- /**
- * @constructor
- * @param {Object} dataItemObject Raw data item JSON object returned from dataset query service
- */
- init: function init(dataItemObject) {
- DataItemClass.inherited('init', this, arguments);
- this._dataItem = dataItemObject;
- this._aTuplePartNormalized = []; // internal flag to indicate if the tuple has been normalized
- this._bTupleHeaderNormalized = false;
- },
- getDecoration: function getDecoration() {
- return this._dataItem && this._dataItem.deco ? this._dataItem.deco : null;
- },
- /**
- * @return {Integer} Length of the data item tuples array
- **/
- getTuples: function getTuples() {
- return this._dataItem.items || [];
- },
- /**
- * @return {Integer} Length of the data item tuples array
- **/
- getTupleCount: function getTupleCount() {
- if (!this._dataItem || !this._dataItem.items) {
- return 0;
- }
- return this._dataItem.items.length;
- },
- /**
- * @return {Array} an array of normalized tuple parts
- **/
- getTuple: function getTuple(tupleIndex) {
- var aResult = this._dataItem && this._dataItem.items ? this._dataItem.items[tupleIndex].t : [];
- if (this._aTuplePartNormalized[tupleIndex] !== true) {
- //Normalize the tuple part if it has not been normalized
- _.each(aResult, function (oPart, index) {
- if (Utils.isRectifyNeeded(oPart)) {
- aResult[index] = Utils.getRectifiedData(oPart);
- Utils.normalizeData(aResult[index]);
- } else {
- Utils.normalizeData(oPart);
- }
- }.bind(this));
- this._aTuplePartNormalized[tupleIndex] = true; //Cache the normalized flag
- }
- return aResult;
- },
- getTupleHeader: function getTupleHeader() {
- return this.getTupleHeaders()[0]; /*backwards compatible legacy API*/
- },
- /**
- *Normally there is only one itemClassSet in one QueryResultDataItem object,
- *However, when there are multiple itemClassSets, each data item tuple should
- *have a itemClassSetIndex field that indicates its corresponding itemClassSet
- *@return {Number} 0 or +N, The index of the itemClassSet
- **/
- getTupleItemClassSetIndex: function getTupleItemClassSetIndex(tupleIndex) {
- if (this._dataItem && this._dataItem.items) {
- var nItemClassSetIndex = this._dataItem.items[tupleIndex].itemClassSetIndex;
- return nItemClassSetIndex !== undefined && nItemClassSetIndex !== null ? nItemClassSetIndex : 0;
- }
- return 0;
- },
- /**
- *@return {Array} of array of normalized tuple hearer
- **/
- getTupleHeaders: function getTupleHeaders() {
- var oResult = [];
- _.each(this._getTupleHeaderObjects(), function (entry) {
- oResult.push(entry ? entry.h || [] : []);
- });
- return oResult;
- },
- /**
- * @return {String} the ID of the tuple header which maps to the ProjectID in the DSS Query request
- */
- getTupleHeaderId: function getTupleHeaderId(index) {
- var oHeaderObject = this._getTupleHeaderObjects()[index || 0];
- return oHeaderObject ? oHeaderObject.id : null;
- },
- getAggregate: function getAggregate() {
- return this._getTupleHeaderObjects()[0].h[0].aggregate;
- },
- _getTupleHeaderObjects: function _getTupleHeaderObjects() {
- if (!this._dataItem || !this._dataItem.itemClass) {
- return null;
- }
- var itemClasses = this._getNormalizeItemClasses();
- if (this.isTupleHeaderNormalized !== true) {
- //Normalize each entry of the header if the whole header has not been normalized
- _.each(itemClasses, function (itemClassEntry) {
- this._getSingleTupleHeaderObject(itemClassEntry);
- }.bind(this));
- this.isTupleHeaderNormalized = true;
- }
- return itemClasses;
- },
- /**
- * Get the normalized array of itemClasses
- * @return {Object[]} array of itemClasses
- */
- _getNormalizeItemClasses: function _getNormalizeItemClasses() {
- // TODO Not sure why returns an array
- return _.isObject(this._dataItem.itemClass) && !_.isArray(this._dataItem.itemClass) ? [this._dataItem.itemClass] : this._dataItem.itemClass;
- },
- _getSingleTupleHeaderObject: function _getSingleTupleHeaderObject(itemClass) {
- _.each(itemClass.h, function (tuple) {
- if (Utils.isRectifyNeeded(tuple)) {
- tuple = Utils.getRectifiedData(tuple); //Only Create Object if tuple is not an Object
- }
- Utils.normalizeData(tuple);
- });
- },
- /**
- * Clip tuples array to the specified length
- * @param {Integer} the length limit of the tuples
- **/
- clipTuples: function clipTuples(limit) {
- if (this._dataItem && this._dataItem.items.length > 0 && this._dataItem.items.length > limit && limit >= 0) {
- this._dataItem.items.splice(limit, this._dataItem.items.length - limit);
- }
- },
- /**
- * Returns the number of dataitems in this result
- **/
- getNestedResultItemCount: function getNestedResultItemCount() {
- var count = 0;
- if (this._dataItem && this._dataItem.itemClass && this._dataItem.itemClass.h) {
- count = this._dataItem.itemClass.h.length;
- }
- return count;
- }
- });
- return DataItemClass;
- });
- //# sourceMappingURL=QueryResultDataItem.js.map
|