UNPKG

cluedin-widget

Version:

This project contains all the pages needed for browsing entities and searching them. The aim is to replace the CluedIn.Webapp project with this one when all the pages ( including the Admin page ) will be ported to REACT.

79 lines (61 loc) 3.26 kB
import { extractImportant, extractSocial, extract, getPropertyToKeep, exactProp } from './property'; import moment from 'moment'; import { findFromKeyValue } from '../../core/helpers/properties.jsx'; import { addTokenToImage } from '../image'; var toVM = function (item, small, token, fetchAllProperties) { var mainItem; mainItem = small ? item.entity : ( item.Entity ? item.Entity.entity : item.entity.entity); mainItem.data = mainItem.processedData; mainItem.name = mainItem.data.displayName || mainItem.data.name; mainItem.id = mainItem['attribute-id']; delete mainItem['attribute-id']; delete mainItem['attribute-organization']; delete mainItem['attribute-culture']; delete mainItem.processedData; var hasDescription = ( mainItem.data.description ) ? true : false; var differentNameAndDescription = !(mainItem.data.description === mainItem.name); mainItem.showDescription = (differentNameAndDescription && hasDescription); mainItem.providers = mainItem.data['provider-origins']; if (mainItem.showDescription && mainItem.data.description.length > 200) { mainItem.descriptionFormatted = ( mainItem.data.description.substring(0, 200) + '...'); } if (mainItem.data.previewImage) { if (mainItem.data.previewImage['attribute-uri']) { mainItem.hasLogo = true; mainItem.logoUrl = addTokenToImage(mainItem.data.previewImage['attribute-uri'], token, true); mainItem.largeLogoUrl = addTokenToImage(mainItem.data.previewImage['attribute-uri'], token, false, 'medium'); } } if (mainItem.data.previewImage) { if (mainItem.data.previewImage['attribute-uri']) { mainItem.previewUrl = addTokenToImage(mainItem.data.previewImage['attribute-uri'], token); mainItem.hasPreview = true; } } if (mainItem.name && mainItem.name.length > 100) { mainItem.name = ( mainItem.name.substring(0, 100) + '...' ); } mainItem.FollowersCount = mainItem.NumberOfFollowers = mainItem.NumberOfFollowers || 0; mainItem.path = void 0; mainItem.SuggestedSearches = item.SuggestedSearches; mainItem.properties = fetchAllProperties ? extract(mainItem) : extractImportant(mainItem); mainItem.notManagerProperties = fetchAllProperties ? getPropertyToKeep(mainItem) : []; if (mainItem.data) { if (mainItem.data.properties) { mainItem.social = extractSocial(mainItem.data.properties); mainItem.embedUrl = mainItem.data.properties['property-file.embedUrl'] || ''; mainItem.editUrl = mainItem.data.properties['property-file.editUrl'] || ''; } mainItem.data.uri = mainItem.data.uri ? mainItem.data.uri.replace(/\+/g, '%20') : ''; mainItem.data.lastChangedBy = mainItem.data.lastChangedBy || findFromKeyValue(mainItem.properties, 'lastmodifiedby'); mainItem.data.modifiedDateFormatted = mainItem.data.modifiedDate ? moment(mainItem.data.modifiedDate).fromNow() : void 0; mainItem.data.createdDateFormatted = mainItem.data.createdDate ? moment(mainItem.data.createdDate).fromNow() : void 0; mainItem.data.discoveryDate = mainItem.data.discoveryDate ? moment(mainItem.data.discoveryDate).fromNow() : void 0; } return mainItem; }; module.exports = { toVM: toVM, filter: require('./filter'), format: require('./property/format') };