/* *+------------------------------------------------------------------------+ *| Licensed Materials - Property of IBM *| IBM Cognos Products: Content Explorer *| (C) Copyright IBM Corp. 2015, 2018 *| *| US Government Users Restricted Rights - Use, duplication or disclosure *| restricted by GSA ADP Schedule Contract with IBM Corp. *+------------------------------------------------------------------------+ */ import { ContentStoreObject, ContentServiceUrls } from '@businessanalytics/content-nav'; import AjaxService from '../services/AjaxService'; class ListUtils { constructor(options) { const ajaxOptions = { glassContext: options.glassContext }; this.ajaxService = new AjaxService(ajaxOptions); } fetchData = (options) => { return this.ajaxService.getData(options.url, options.data) .then((response) => { return response; }) .catch((err) => { return err; }); } formatListData = (DateTimeUtils, glassContext, data) => { ContentStoreObject.setDateTimeUtils(DateTimeUtils); ContentStoreObject.setGlassContext(glassContext); const formattedData = []; let formattedDate; let groupType; for (let i=0; i 0) { groupType = data[i].tags[0]; } else { groupType = data[i].type; } } else { groupType = data[i].type; } formattedData.push({ defaultName: data[i].defaultName, type: data[i].type, groupType: groupType, date: formattedDate, disabled: data[i].disabled, hidden: data[i].hidden, id: data[i].id, tags: data[i].tags || null, defaultScreenTip: data[i].defaultScreenTip || null, modificationTime: data[i].modificationTime, groups: data[i].groups, groupByFolder: data[i].groupByFolder, groupByType: data[i].groupByType, tenantID: data[i].tenantID, target: data[i].target, _meta: data[i]._meta }); } return formattedData; } buildPayload = (oData, glassContext, contentView) => ({ 'glassContext': glassContext, 'target': { 'activeObject': { 'aSelectedContext': [oData], 'oListControl': { 'contentView': contentView, 'renderFromReact': true } }, 'itemId': this.getActionId(oData) } }); getActionId = (oData) => { const objType = ContentStoreObject.getType(oData); return objType ? 'com.ibm.bi.contentApps.defaultAction.' + objType : null; } getOptions = (url) => { return { url: url, data: { 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', nav_filter: 'true' } }; } navBreadcrumb = (index, ancestors) => { const lastElem = index + 1; const newAncestors = ancestors.slice(0, lastElem); return newAncestors; } navBackBreadcrumb = (ancestorsStack) => { if (ancestorsStack.length > 1) { ancestorsStack.pop(); } return [...ancestorsStack]; } getItemsURL = url => url ? url + '/items' : null; getMyContentURL = () => ContentServiceUrls.getMyFoldersURL(); getTeamContentURL = () => ContentServiceUrls.getPublicFoldersURL(); } export default ListUtils;