n10nController.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Licensed Materials - Property of IBM
  3. *
  4. * IBM Cognos Products: SHARE
  5. *
  6. * (C) Copyright IBM Corp. 2015, 2018
  7. *
  8. * US Government Users Restricted Rights - Use, duplication or disclosure
  9. * restricted by GSA ADP Schedule Contract with IBM Corp.
  10. */
  11. define([
  12. 'react',
  13. 'react-dom',
  14. 'ba-react-admin/ba-react-admin.min',
  15. 'bi/content_apps/utils/GlassContextHelper',
  16. 'bacontentnav/utils/ContentStoreObject',
  17. 'q',
  18. 'jquery',
  19. 'bi/sharecommon/utils/translator'
  20. ], function(React, ReactDOM, AdminReact, GlassContextHelper, ContentStoreObject, Q, $, t) {
  21. return {
  22. MAX_DISPLAY: 20, // Max number of notifications to fetch / display in the notification badge
  23. PREVIEW_PANE_WIDTH: '400px', // Width of the notification message pane
  24. /**
  25. * @param {Object} messageContext - An object with values to use for loading and displaying a notification
  26. * @param {String} messageContext.messageId - The Id of the notification to display
  27. * @param {Object} messageContext.messageListView - The current message list view object
  28. * @param {Object} messageContext.glassContext - The glassContext object
  29. * @param {function} messageContext.onHideCallback - A callback function to call when the slideout.hide function is executed
  30. */
  31. showNotificationContent: function(messageContext) {
  32. return messageContext.glassContext.getSvc('.Notification').then(function(notificationSvc) {
  33. return notificationSvc.getSpecificNotification(messageContext.messageId).then(function(messageDetails) {
  34. //render the view after getting the data
  35. var newSlideout = React.createElement(AdminReact.PreviewView, {
  36. onHide: messageContext.onHideCallback,
  37. data: messageDetails,
  38. glassContext: messageContext.glassContext,
  39. GlassContextHelper: GlassContextHelper,
  40. ContentStoreObject: ContentStoreObject,
  41. StringResource: t,
  42. messageList: messageContext.messageListView
  43. });
  44. //check unread -> read status change. If so, call PUT after showing the content
  45. if (messageDetails.unread) {
  46. notificationSvc.markRead(messageContext.messageId);
  47. }
  48. $('.flyoutPane.pane-right.active.shadow').append('<div class="notificationNewSlideout"></div>');
  49. ReactDOM.unmountComponentAtNode(document.getElementsByClassName('notificationNewSlideout')[0]);
  50. newSlideout && newSlideout.type.prototype.setOpen();
  51. ReactDOM.render(newSlideout, document.getElementsByClassName('notificationNewSlideout')[0]);
  52. }).catch(function() {
  53. // Catch exceptions
  54. });
  55. }.bind(this));
  56. },
  57. /**
  58. * @param {String} messageId - The notification's Id
  59. * @param {Object} context - Context object which contains the glassContext which is needed
  60. */
  61. deleteNotification: function(messageId, context) {
  62. return context.glassContext.getSvc('.Notification').then(function(notificationSvc) {
  63. return notificationSvc.deleteNotification(messageId);
  64. });
  65. },
  66. getNotificationState: function(reportId, context) {
  67. return context.glassContext.getSvc('.Notification').then(function(notificationSvc) {
  68. return notificationSvc.getNotificationState(reportId);
  69. });
  70. },
  71. updateNotificationState: function(descriptor, context) {
  72. return context.glassContext.getSvc('.Notification').then(function(notificationSvc) {
  73. return notificationSvc.updateNotificationState(descriptor);
  74. });
  75. },
  76. getObjectProperties: function(properties, context) {
  77. return context.glassContext.getSvc('.Content').then(function(contentSvc) {
  78. var server_URL = contentSvc.getBaseObjectsURL() + '/' + properties.reportId + '?fields=type,runInAdvancedViewer';
  79. return Promise.resolve(contentSvc.get(server_URL, {})).then(function(data) {
  80. if (data.data[0]) {
  81. var info = data.data[0];
  82. if ('runInAdvancedViewer' in info) {
  83. properties.runInAdvancedViewer = info.runInAdvancedViewer;
  84. }
  85. if ('type' in info) {
  86. properties.type = info.type;
  87. }
  88. return properties;
  89. } else {
  90. return Promise.reject();
  91. }
  92. }.bind(this));
  93. }.bind(this));
  94. }
  95. };
  96. });