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.
72 lines (55 loc) • 3.23 kB
JavaScript
import { extractImportant, extractSocial, extract, getPropertyToKeep, fextract} from './property';
import { addTokenToImage } from '../image';
import moment from 'moment';
import { findFromKeyValue } from '../../core/helpers/properties.jsx';
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 );
}
}
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.social = extractSocial( mainItem.data.properties );
mainItem.embedUrl = mainItem.data.properties[ 'property-file.embedUrl' ] || '';
mainItem.properties = fetchAllProperties ? extract( mainItem ) : extractImportant( mainItem );
mainItem.notManagerProperties = fetchAllProperties ? getPropertyToKeep( mainItem ) : [];
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;
//delete mainItem.data.properties;
return mainItem;
};
module.exports = {
toVM: toVM,
filter: require( './filter' ),
format: require( './property/format' )
};