ServiceabilityRenderingInfo.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. /**
  9. * @class ServiceabilityRenderingInfoImpl
  10. * @hideconstructor
  11. * @classdesc Render Service Implementation class
  12. */
  13. define(['../../../../api/impl/serviceability/nls/StringResources'], function (StringResources) {
  14. var ServiceabilityRenderingInfo = function () {
  15. function ServiceabilityRenderingInfo(logger) {
  16. _classCallCheck(this, ServiceabilityRenderingInfo);
  17. this._logger = logger;
  18. this._renderingInfo = undefined;
  19. }
  20. /**
  21. * @returns {RenderingInfo} the current rendering info object
  22. */
  23. ServiceabilityRenderingInfo.prototype.getCurrentRendering = function getCurrentRendering() {
  24. return this._renderingInfo;
  25. };
  26. /**
  27. * @param {RenderingInfo} renderingInfo the info of a rendersequence which is being executed
  28. */
  29. ServiceabilityRenderingInfo.prototype.setCurrentRendering = function setCurrentRendering(renderingInfo) {
  30. this._renderingInfo = renderingInfo;
  31. };
  32. /**
  33. * @returns {RenderingInfo} A RenderingInfo object represent the latest valid rendering info
  34. */
  35. ServiceabilityRenderingInfo.prototype.getLastRendering = function getLastRendering() {
  36. return this._lastRendering;
  37. };
  38. /**
  39. * @description set the latest valid rendering info object
  40. * @param {RenderingInfo} lastRendering An object of class RenderingInfo
  41. */
  42. ServiceabilityRenderingInfo.prototype.setLastRendering = function setLastRendering(lastRendering) {
  43. this._lastRendering = lastRendering;
  44. };
  45. ServiceabilityRenderingInfo.prototype.toJSON = function toJSON() {
  46. return {
  47. renderingInfo: {
  48. current: this._renderingInfo ? this._renderingInfo.toJSON() : {},
  49. last: this._lastRendering ? this._lastRendering.toJSON() : {}
  50. }
  51. };
  52. };
  53. /**
  54. * @description Returns a json which currently will be consumed by Serviceability feature
  55. * @returns a json represent the desired UI
  56. */
  57. ServiceabilityRenderingInfo.prototype.toUIJSON = function toUIJSON() {
  58. var request_durations = [],
  59. total_duration = void 0;
  60. if (this.getLastRendering() === undefined) {
  61. total_duration = this.getCurrentRendering().getDuration();
  62. var taskInfo = this.getCurrentRendering().getRenderSequenceWithData();
  63. if (taskInfo === undefined) {
  64. total_duration = total_duration + ' ' + StringResources.get('renderInProgress');
  65. } else {
  66. request_durations = taskInfo.getTaskInfo('data').getRequestDurations();
  67. total_duration = total_duration + ' ' + StringResources.get('renderInProgress');
  68. }
  69. } else {
  70. total_duration = this.getLastRendering().getDuration();
  71. var _taskInfo = this.getLastRendering().getRenderSequenceWithData();
  72. request_durations = _taskInfo.getTaskInfo('data').getRequestDurations();
  73. }
  74. var cellData = [[StringResources.get('liveWidgetTotalTime'), total_duration]];
  75. this._addRequestDurations(cellData, request_durations);
  76. return [{
  77. sectionName: StringResources.get('performanceSection'),
  78. sectionValues: [{
  79. fieldName: StringResources.get('durationField'),
  80. fieldValue: {
  81. cellValue: function cellValue(row, col) {
  82. return cellData[row][col];
  83. },
  84. columnLength: 2,
  85. rowLength: cellData.length
  86. },
  87. type: 'SimpleTable'
  88. }]
  89. }];
  90. };
  91. ServiceabilityRenderingInfo.prototype._addRequestDurations = function _addRequestDurations(cellData, requestDurations) {
  92. if (requestDurations.length === 0) {
  93. cellData.push([StringResources.get('singleQueryTime'), StringResources.get('infoNotAvailable')]);
  94. } else {
  95. requestDurations.forEach(function (duration, index) {
  96. var label = '';
  97. if (requestDurations.length === 1) {
  98. label = StringResources.get('singleQueryTime');
  99. } else {
  100. label = StringResources.get('multipleQueryTime', { name: index + 1 });
  101. }
  102. if (isNaN(duration)) {
  103. cellData.push([label, StringResources.get('infoNotAvailable')]);
  104. } else {
  105. cellData.push([label, duration]);
  106. }
  107. });
  108. }
  109. return cellData;
  110. };
  111. return ServiceabilityRenderingInfo;
  112. }();
  113. return ServiceabilityRenderingInfo;
  114. });
  115. //# sourceMappingURL=ServiceabilityRenderingInfo.js.map