ListUtils.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. *+------------------------------------------------------------------------+
  3. *| Licensed Materials - Property of IBM
  4. *| IBM Cognos Products: Content Explorer
  5. *| (C) Copyright IBM Corp. 2015, 2018
  6. *|
  7. *| US Government Users Restricted Rights - Use, duplication or disclosure
  8. *| restricted by GSA ADP Schedule Contract with IBM Corp.
  9. *+------------------------------------------------------------------------+
  10. */
  11. import { ContentStoreObject, ContentServiceUrls } from '@businessanalytics/content-nav';
  12. import AjaxService from '../services/AjaxService';
  13. class ListUtils {
  14. constructor(options) {
  15. const ajaxOptions = {
  16. glassContext: options.glassContext
  17. };
  18. this.ajaxService = new AjaxService(ajaxOptions);
  19. }
  20. fetchData = (options) => {
  21. return this.ajaxService.getData(options.url, options.data)
  22. .then((response) => {
  23. return response;
  24. })
  25. .catch((err) => {
  26. return err;
  27. });
  28. }
  29. formatListData = (DateTimeUtils, glassContext, data) => {
  30. ContentStoreObject.setDateTimeUtils(DateTimeUtils);
  31. ContentStoreObject.setGlassContext(glassContext);
  32. const formattedData = [];
  33. let formattedDate;
  34. let groupType;
  35. for (let i=0; i<data.length; i++){
  36. formattedDate = ContentStoreObject._getFormattedDateTime(data[i], true, 'short', 'modificationTime', true);
  37. if (data[i].type === 'exploration') {
  38. if(data[i].tags && data[i].tags.length > 0) {
  39. groupType = data[i].tags[0];
  40. } else {
  41. groupType = data[i].type;
  42. }
  43. } else {
  44. groupType = data[i].type;
  45. }
  46. formattedData.push({
  47. defaultName: data[i].defaultName,
  48. type: data[i].type,
  49. groupType: groupType,
  50. date: formattedDate,
  51. disabled: data[i].disabled,
  52. hidden: data[i].hidden,
  53. id: data[i].id,
  54. tags: data[i].tags || null,
  55. defaultScreenTip: data[i].defaultScreenTip || null,
  56. modificationTime: data[i].modificationTime,
  57. groups: data[i].groups,
  58. groupByFolder: data[i].groupByFolder,
  59. groupByType: data[i].groupByType,
  60. tenantID: data[i].tenantID,
  61. target: data[i].target,
  62. _meta: data[i]._meta
  63. });
  64. }
  65. return formattedData;
  66. }
  67. buildPayload = (oData, glassContext, contentView) => ({
  68. 'glassContext': glassContext,
  69. 'target': {
  70. 'activeObject': {
  71. 'aSelectedContext': [oData],
  72. 'oListControl': {
  73. 'contentView': contentView,
  74. 'renderFromReact': true
  75. }
  76. },
  77. 'itemId': this.getActionId(oData)
  78. }
  79. });
  80. getActionId = (oData) => {
  81. const objType = ContentStoreObject.getType(oData);
  82. return objType ? 'com.ibm.bi.contentApps.defaultAction.' + objType : null;
  83. }
  84. getOptions = (url) => {
  85. return {
  86. url: url,
  87. data: {
  88. fields: 'userInterfaces,defaultName,owner.defaultName,contact,creationTime,disabled,hidden,permissions,runInAdvancedViewer,modificationTime,canBurst,iconURI,defaultScreenTip,searchPath,defaultPortalAction,base.defaultName,tags,target.searchPath,effectiveUserCapabilities,base.permissions,defaultDescription,options,base.options',
  89. nav_filter: 'true'
  90. }
  91. };
  92. }
  93. navBreadcrumb = (index, ancestors) => {
  94. const lastElem = index + 1;
  95. const newAncestors = ancestors.slice(0, lastElem);
  96. return newAncestors;
  97. }
  98. navBackBreadcrumb = (ancestorsStack) => {
  99. if (ancestorsStack.length > 1) {
  100. ancestorsStack.pop();
  101. }
  102. return [...ancestorsStack];
  103. }
  104. getItemsURL = url => url ? url + '/items' : null;
  105. getMyContentURL = () => ContentServiceUrls.getMyFoldersURL();
  106. getTeamContentURL = () => ContentServiceUrls.getPublicFoldersURL();
  107. }
  108. export default ListUtils;