ContentServiceabilityImpl.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 ContentServiceabilityImpl
  10. * @hideconstructor
  11. * @classdesc Widget Service Implementation class
  12. */
  13. define(['../../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../../../../api/DashboardAPI', '../ContentInfoAPI', './ContentInfoImpl', '../../../../features/dashboard/dashboardServiceability/view/ServiceabilityContent', 'react', 'react-dom'], function (APIFactory, DashboardAPI, ContentInfoApi, ContentInfoImpl, ServiceabilityContent, React, ReactDOM) {
  14. var ContentServiceabilityImpl = function () {
  15. function ContentServiceabilityImpl(options) {
  16. _classCallCheck(this, ContentServiceabilityImpl);
  17. this.getDashboardAPI = function () {
  18. return options.dashboardAPI;
  19. };
  20. this.getContentAPI = function () {
  21. return options.content;
  22. };
  23. var logger = options.dashboardAPI.getService(DashboardAPI.GLOBAL_SERVICES.LOGGER);
  24. this.getLogger = function () {
  25. return logger;
  26. };
  27. this._contentInfo = APIFactory.createAPI(new ContentInfoImpl(this.getContentAPI(), this.getLogger()), [ContentInfoApi]);
  28. this._contentInfo.setData('generalInfo', {});
  29. this._isInfoVisible = false;
  30. }
  31. ContentServiceabilityImpl.prototype.getContentInfo = function getContentInfo() {
  32. return this._contentInfo;
  33. };
  34. ContentServiceabilityImpl.prototype.isInfoVisible = function isInfoVisible() {
  35. return this._isInfoVisible;
  36. };
  37. /**
  38. * @description Currently we only fetch and process the info of Performance section.
  39. * But it should be more generic.
  40. * @todo `showInfo` will have an argument to indicate what sections we're going to display so
  41. * that we don't have to hardcode 'Performance'. Then, we fetch the sections and process them.
  42. */
  43. ContentServiceabilityImpl.prototype._fetchUIJSON = function _fetchUIJSON() {
  44. var UIJson = this._contentInfo.toUIJSON().filter(function (section) {
  45. return section.sectionName === 'Performance';
  46. });
  47. UIJson.forEach(function (section) {
  48. section.sectionName = '';
  49. section.sectionValues.forEach(function (field) {
  50. field.fieldName = '';
  51. });
  52. });
  53. return UIJson;
  54. };
  55. ContentServiceabilityImpl.prototype.showInfo = function showInfo() {
  56. this._isInfoVisible = true;
  57. var contentViewDOM = this.getContentAPI().getFeature('ContentViewDOM');
  58. if (contentViewDOM) {
  59. var overlayID = 's12yOverlay_' + this.getContentAPI().getId();
  60. var contentNode = contentViewDOM.getNode();
  61. var overlayNode = contentNode.querySelector('#' + overlayID);
  62. if (!overlayNode) {
  63. overlayNode = document.createElement('div');
  64. overlayNode.id = overlayID;
  65. overlayNode.className = 's12yOverlay';
  66. contentNode.appendChild(overlayNode);
  67. var UIJson = this._fetchUIJSON();
  68. var infoNode = React.createElement(
  69. React.Fragment,
  70. null,
  71. React.createElement('div', { className: 's12yOverlayBackground' }),
  72. React.createElement(ServiceabilityContent, {
  73. widgetInfo: this._contentInfo,
  74. dashboardApi: this.getDashboardAPI(),
  75. UISpec: UIJson,
  76. showButtons: false
  77. })
  78. );
  79. ReactDOM.render(infoNode, overlayNode);
  80. }
  81. } else {
  82. this.getLogger().warn('cannot find ContentViewDOM feature');
  83. }
  84. };
  85. ContentServiceabilityImpl.prototype.hideInfo = function hideInfo() {
  86. this._isInfoVisible = false;
  87. var contentViewDOM = this.getContentAPI().getFeature('ContentViewDOM');
  88. if (contentViewDOM) {
  89. var overlayID = 's12yOverlay_' + this.getContentAPI().getId();
  90. var contentNode = contentViewDOM.getNode();
  91. var overlayNode = contentNode.querySelector('#' + overlayID);
  92. if (overlayNode) {
  93. ReactDOM.unmountComponentAtNode(overlayNode);
  94. contentNode.removeChild(overlayNode);
  95. }
  96. } else {
  97. this.getLogger().warn('cannot find ContentViewDOM feature');
  98. }
  99. };
  100. return ContentServiceabilityImpl;
  101. }();
  102. return ContentServiceabilityImpl;
  103. });
  104. //# sourceMappingURL=ContentServiceabilityImpl.js.map