'use strict'; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /** * Licensed Materials - Property of IBM * IBM Business Analytics (C) Copyright IBM Corp. 2019 * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ /** * @class ServiceabilityRenderingInfoImpl * @hideconstructor * @classdesc Render Service Implementation class */ define(['../../../../api/impl/serviceability/nls/StringResources'], function (StringResources) { var ServiceabilityRenderingInfo = function () { function ServiceabilityRenderingInfo(logger) { _classCallCheck(this, ServiceabilityRenderingInfo); this._logger = logger; this._renderingInfo = undefined; } /** * @returns {RenderingInfo} the current rendering info object */ ServiceabilityRenderingInfo.prototype.getCurrentRendering = function getCurrentRendering() { return this._renderingInfo; }; /** * @param {RenderingInfo} renderingInfo the info of a rendersequence which is being executed */ ServiceabilityRenderingInfo.prototype.setCurrentRendering = function setCurrentRendering(renderingInfo) { this._renderingInfo = renderingInfo; }; /** * @returns {RenderingInfo} A RenderingInfo object represent the latest valid rendering info */ ServiceabilityRenderingInfo.prototype.getLastRendering = function getLastRendering() { return this._lastRendering; }; /** * @description set the latest valid rendering info object * @param {RenderingInfo} lastRendering An object of class RenderingInfo */ ServiceabilityRenderingInfo.prototype.setLastRendering = function setLastRendering(lastRendering) { this._lastRendering = lastRendering; }; ServiceabilityRenderingInfo.prototype.toJSON = function toJSON() { return { renderingInfo: { current: this._renderingInfo ? this._renderingInfo.toJSON() : {}, last: this._lastRendering ? this._lastRendering.toJSON() : {} } }; }; /** * @description Returns a json which currently will be consumed by Serviceability feature * @returns a json represent the desired UI */ ServiceabilityRenderingInfo.prototype.toUIJSON = function toUIJSON() { var request_durations = [], total_duration = void 0; if (this.getLastRendering() === undefined) { total_duration = this.getCurrentRendering().getDuration(); var taskInfo = this.getCurrentRendering().getRenderSequenceWithData(); if (taskInfo === undefined) { total_duration = total_duration + ' ' + StringResources.get('renderInProgress'); } else { request_durations = taskInfo.getTaskInfo('data').getRequestDurations(); total_duration = total_duration + ' ' + StringResources.get('renderInProgress'); } } else { total_duration = this.getLastRendering().getDuration(); var _taskInfo = this.getLastRendering().getRenderSequenceWithData(); request_durations = _taskInfo.getTaskInfo('data').getRequestDurations(); } var cellData = [[StringResources.get('liveWidgetTotalTime'), total_duration]]; this._addRequestDurations(cellData, request_durations); return [{ sectionName: StringResources.get('performanceSection'), sectionValues: [{ fieldName: StringResources.get('durationField'), fieldValue: { cellValue: function cellValue(row, col) { return cellData[row][col]; }, columnLength: 2, rowLength: cellData.length }, type: 'SimpleTable' }] }]; }; ServiceabilityRenderingInfo.prototype._addRequestDurations = function _addRequestDurations(cellData, requestDurations) { if (requestDurations.length === 0) { cellData.push([StringResources.get('singleQueryTime'), StringResources.get('infoNotAvailable')]); } else { requestDurations.forEach(function (duration, index) { var label = ''; if (requestDurations.length === 1) { label = StringResources.get('singleQueryTime'); } else { label = StringResources.get('multipleQueryTime', { name: index + 1 }); } if (isNaN(duration)) { cellData.push([label, StringResources.get('infoNotAvailable')]); } else { cellData.push([label, duration]); } }); } return cellData; }; return ServiceabilityRenderingInfo; }(); return ServiceabilityRenderingInfo; }); //# sourceMappingURL=ServiceabilityRenderingInfo.js.map