'use strict'; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /** * Licensed Materials - Property of IBM * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2016, 2018 * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ define(['../../../widgets/livewidget/nls/StringResources'], function (StringResources) { 'use strict'; var PROCESSING = StringResources.get('processing'); var NOT_AVAILABLE = StringResources.get('value_is_not_available'); var Summary = function () { function Summary(mappingInfo, isLocalSummary) { _classCallCheck(this, Summary); this._numberOfValues = 0; this._formatSpec = mappingInfo.formatSpec; this._aggregationType = mappingInfo.aggregationType; this._isLocalSummary = isLocalSummary; this._uniqueId = mappingInfo.id; } /** * Add call back functions and required parameters when summary is local supported type * @param {object} cbContext - * categoryUIds: used as query Key to find the corresponding summary query result * tupleUIds: used as tuple key to find the value from the right summary query result * cbGetSummary: callback to invoke getSummary in SummaryFeature * cbOnCellDataChange: callback when summary value is ready */ Summary.prototype.addCallBackContext = function addCallBackContext(cbContext) { this.categoryUIds = cbContext.categoryUIds; this.tupleUIds = cbContext.tupleUIds; this.getSummary = cbContext.cbGetSummary; this.onCellDataChange = cbContext.cbOnCellDataChange; this.addSummaryValuePromise = cbContext.cbAddSummaryValuePromise; }; Summary.prototype.addValue = function addValue(value) { if (!this._isLocalSummary) { // Just return if local summary does not support the aggregation type return; } var newValue = value; if (value && (typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object') { newValue = value.getSummarizedValue(); } if (typeof newValue !== 'number') { return; } if (typeof this.value !== 'number') { this.value = newValue; return; } switch (this._aggregationType) { case 'min': this.value = Math.min(this.value, newValue); break; case 'max': this.value = Math.max(this.value, newValue); break; default: this.value += newValue; } }; Summary.prototype.getSummarizedValue = function getSummarizedValue(rowIdx, colIdx) { var _this = this; if (!this._isLocalSummary) { if (this.getSummary) { this.valuePromise = this.getSummary(this.categoryUIds, this._uniqueId, this.tupleUIds).then(function (value) { _this.onCellDataChange(rowIdx, colIdx, value, _this._formatSpec); }); if (this.addSummaryValuePromise) { this.addSummaryValuePromise(this.valuePromise); } return PROCESSING; } else { return NOT_AVAILABLE; } } return this.getValue(); }; Summary.prototype.getValue = function getValue() { return typeof this.value === 'number' ? this.value : null; }; Summary.prototype.getFormatSpec = function getFormatSpec() { return this._formatSpec; }; return Summary; }(); return Summary; }); //# sourceMappingURL=Summary.js.map