SummaryProxyView.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2019
  5. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  6. */
  7. define(['jquery', 'underscore', '../VisView', '../../../util/DashboardFormatter', '../kpi/KpiView', '../infographic/InfographicView', '../../../DynamicFileLoader', '../../../lib/@waca/dashboard-common/dist/utils/MemUtil'], function ($, _, VisView, Formatter, KpiView, InfographicView, DynamicFileLoader, MemUtil) {
  8. 'use strict';
  9. var SummaryProxyView = VisView.extend({
  10. className: '',
  11. init: function init(options) {
  12. var _this = this;
  13. SummaryProxyView.inherited('init', this, arguments);
  14. this._content = options.content;
  15. this._colorsService = this.dashboardApi.getFeature('Colors');
  16. this._visualizationAPI = this._content.getFeature('Visualization');
  17. var proxiedOptions = _.extend({}, options, { proxiedView: true });
  18. this._kpiView = new KpiView(proxiedOptions);
  19. this._infographicView = new InfographicView(proxiedOptions);
  20. this.updateActiveView();
  21. ['resize', 'animate', '_renderIconView', 'removeIconView', 'getDescription', 'onVisible', 'renderIconView'].forEach(function (property) {
  22. _this._createProxyFunction(property);
  23. });
  24. },
  25. /**
  26. * expose this to summaryPropertyCallbacks
  27. */
  28. getSubView: function getSubView(name) {
  29. if (name === 'kpiView') {
  30. return this._kpiView;
  31. } else if (name === 'infographicView') {
  32. return this._infographicView;
  33. }
  34. },
  35. _createProxyFunction: function _createProxyFunction(functionName) {
  36. this[functionName] = function () {
  37. return this._activeView[functionName].apply(this._activeView, arguments);
  38. };
  39. },
  40. reveal: function reveal() {
  41. if (this._activeView && this._activeView.summaryReveal) {
  42. this._activeView.summaryReveal();
  43. }
  44. },
  45. remove: function remove() {
  46. var finalRemove = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
  47. // todo livewidget_cleanup -- it is weird that we pass a finalRemove
  48. // It seems to be used to delayed the destruction of a vipr widget
  49. // but we could handle this in a better way
  50. this._kpiView.remove(finalRemove);
  51. this._infographicView.remove(finalRemove);
  52. if (finalRemove) {
  53. MemUtil.destroy(this);
  54. }
  55. },
  56. /**
  57. * Loads and creates the control. Returns a promise which is resolved when the control
  58. * is created and ready to render
  59. */
  60. whenVisControlReady: function whenVisControlReady() {
  61. var _this2 = this;
  62. //Initialize proxied view controls
  63. var controlPromises = [this._kpiView.whenVisControlReady(), this._infographicView.whenVisControlReady()];
  64. return Promise.all(controlPromises).then(function () {
  65. if (_this2.visControl) {
  66. return _this2.visControl;
  67. } else {
  68. return DynamicFileLoader.load(['dashboard-analytics/visualizations/renderer/summary/control/SummaryControl']).then(function (modules) {
  69. var VisControl = modules[0];
  70. _this2.visControl = new VisControl({
  71. domNode: _this2.$el[0]
  72. });
  73. return _this2.visControl;
  74. });
  75. }
  76. });
  77. },
  78. placeAt: function placeAt(element) {
  79. this._containingElement = element;
  80. if (this._activeView) {
  81. this._activeView.placeAt(element);
  82. }
  83. },
  84. updateActiveView: function updateActiveView() {
  85. if (this._activeView) {
  86. this._activeView.$el.detach();
  87. }
  88. var isInfographic = this.isInfographic(true);
  89. if (isInfographic) {
  90. this._activeView = this._infographicView;
  91. } else {
  92. this._activeView = this._kpiView;
  93. }
  94. this.$el = this._activeView.$el;
  95. if (this._containingElement) {
  96. this._activeView.placeAt(this._containingElement);
  97. }
  98. },
  99. getActiveView: function getActiveView() {
  100. return this._activeView;
  101. },
  102. render: function render(renderInfo) {
  103. this.updateActiveView();
  104. return this._activeView.render(renderInfo);
  105. },
  106. isInfographic: function isInfographic() {
  107. var updateValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  108. if (this._isInfographic === undefined || updateValue) {
  109. var graphicData = this.content.getPropertyValue('value.graphic.content');
  110. this._isInfographic = !!graphicData;
  111. }
  112. return this._isInfographic;
  113. },
  114. getDecoratorAPI: function getDecoratorAPI() {
  115. if (this._activeView.getDecoratorAPI) {
  116. return this._activeView.getDecoratorAPI();
  117. } else {
  118. return null;
  119. }
  120. }
  121. });
  122. return SummaryProxyView;
  123. });
  124. //# sourceMappingURL=SummaryProxyView.js.map